Skip to content

Add WCET measurement for O(1) validation#13

Merged
jserv merged 1 commit intomasterfrom
wcet
Feb 7, 2026
Merged

Add WCET measurement for O(1) validation#13
jserv merged 1 commit intomasterfrom
wcet

Conversation

@jserv
Copy link
Copy Markdown
Collaborator

@jserv jserv commented Feb 7, 2026

This introduces per-operation latency measurement under pathological scenarios to empirically bound the O(1) constant of TLSF malloc/free.

  • Four scenarios (malloc/free × worst/best case) with cycle-accurate timing (rdtsc on x86-64, cntvct_el0 on ARM64, mach_absolute_time on macOS).
  • Supports cold-cache mode (-C) with 64 MB thrash buffer to simulate interrupt-handler WCET.
  • Raw CSV output (-r) embeds the platform tick unit for correct plot labeling.

Summary by cubic

Adds a WCET measurement suite to validate TLSF’s O(1) malloc/free with worst/best case scenarios, plus plotting and CI automation. Runs on x86‑64, ARM64, and macOS to give clear latency bounds.

  • New Features

    • Added wcet tool (tests/wcet.c) for malloc/free worst/best with high‑resolution timers (rdtsc, cntvct_el0, mach_absolute_time; monotonic fallback).
    • Cold‑cache mode (-C, 64 MB thrash); CSV summary (-c); raw samples (-r) with unit; prints worst/best p99 ratio.
    • Plot script (scripts/wcet_plot.py) outputs box plots and histograms; prints a text summary when matplotlib is missing.
    • Makefile targets: wcet, wcet‑quick, wcet‑plot; check runs a short wcet.
  • Dependencies

    • CI adds a wcet job on x86‑64 and arm64, installs python3‑matplotlib, uploads CSV/plot artifacts, adds a job summary, and posts/updates a per‑arch comment on the PR with results.
    • Coding‑style tooling now installs black for Python formatting.

Written for commit bd05325. Summary will update on new commits.

cubic-dev-ai[bot]

This comment was marked as resolved.

This introduces per-operation latency measurement under pathological
scenarios to empirically bound the O(1) constant of TLSF malloc/free.
- Four scenarios (malloc/free × worst/best case) with cycle-accurate
  timing (rdtsc on x86-64, cntvct_el0 on ARM64, mach_absolute_time on
  macOS).
- Supports cold-cache mode (-C) with 64 MB thrash buffer to simulate
  interrupt-handler WCET.
- Raw CSV output (-r) embeds the platform tick unit for correct plot
  labeling.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 7, 2026

WCET Results (x86-64)

TLSF WCET Analysis
==================
Timer:      cycles
Cache:      hot
Pool:       4194304 bytes (4.0 MB)
Iterations: 5000 (warmup: 500)
Sizes:      16 64 256 1024 4096 bytes

--- malloc_worst (small alloc from single huge block) ---
    size        min        p50        p90        p99      p99.9        max       mean     stddev
      16         94         98        100        102        104        112       97.9        1.9
      64         92         96         98         98        100        102       96.8        1.0
     256         94        100        104        112        146        154       99.5        4.8
    1024         92         98         98         98        100        104       97.6        0.8
    4096         94         96         96         98        100        102       95.2        1.1

--- malloc_best (exact bin hit, no split) ---
    size        min        p50        p90        p99      p99.9        max       mean     stddev
      16         72         78         80         90         96      54984       88.1      776.5
      64         72         78         80         92         96         98       78.6        2.3
     256         74         78         80         90         94         98       77.5        2.5
    1024         72         78         80         92         96         98       78.3        2.4
    4096         74         76         80         92         96      15358       80.1      216.1

--- free_worst (sandwiched between two free blocks) ---
    size        min        p50        p90        p99      p99.9        max       mean     stddev
      16         72         80         84        112        144        152       81.2        6.1
      64         72         78         82         84         86       1342       79.2       18.1
     256         72         78         80         84         88         90       78.5        2.3
    1024         72         80         82         84         86         88       79.4        2.1
    4096         72         80         82         86         88         94       79.2        2.4

--- free_best (no merge (used neighbors)) ---
    size        min        p50        p90        p99      p99.9        max       mean     stddev
      16         54         60         62         66         70         90       59.8        1.9
      64         54         60         62         66         72         72       59.6        2.1
     256         54         58         60         62         64         70       58.5        1.6
    1024         54         58         60         62         64         66       58.6        1.5
    4096         54         58         60         62         66         66       58.6        1.4

--- worst/best ratio (p99) ---
    size     malloc       free
      16      1.11x      1.34x
      64      1.09x      1.34x
     256      1.24x      2.06x
    1024      1.06x      1.35x
    4096      1.09x      1.35x

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 7, 2026

WCET Results (arm64)

TLSF WCET Analysis
==================
Timer:      ticks
Cache:      hot
Pool:       4194304 bytes (4.0 MB)
Iterations: 5000 (warmup: 500)
Sizes:      16 64 256 1024 4096 bytes

--- malloc_worst (small alloc from single huge block) ---
    size        min        p50        p90        p99      p99.9        max       mean     stddev
      16         24         32         32         40         40         48       31.5        2.7
      64         24         32         32         40         40         40       32.0        2.0
     256         16         32         32         40         40       2992       31.8       42.0
    1024         16         32         32         32         40         40       30.9        2.9
    4096         16         32         32         40         40         48       32.1        2.1

--- malloc_best (exact bin hit, no split) ---
    size        min        p50        p90        p99      p99.9        max       mean     stddev
      16         16         24         32         32         32         32       25.4        3.0
      64         16         24         32         32         32      10312       27.4      145.5
     256          8         24         32         32         32         32       25.4        3.0
    1024         16         24         32         32         32         40       25.4        3.0
    4096         16         24         32         32         32         40       25.4        3.0

--- free_worst (sandwiched between two free blocks) ---
    size        min        p50        p90        p99      p99.9        max       mean     stddev
      16         16         24         32         32         32         40       25.7        3.3
      64         16         24         32         32         32         40       25.6        3.3
     256         16         24         32         32         32         32       25.7        3.3
    1024         16         24         32         32         32         32       25.7        3.3
    4096         16         24         32         32         32         32       25.6        3.2

--- free_best (no merge (used neighbors)) ---
    size        min        p50        p90        p99      p99.9        max       mean     stddev
      16         16         24         24         24         24         32       20.8        3.9
      64         16         24         24         24         24         32       20.4        4.0
     256          8         24         24         24         24         32       20.7        3.9
    1024         16         24         24         24         24       3952       21.2       55.7
    4096         16         24         24         24         24         32       20.6        4.0

--- worst/best ratio (p99) ---
    size     malloc       free
      16      1.25x      1.33x
      64      1.00x      1.33x
     256      1.00x      1.33x
    1024      1.00x      1.33x
    4096      1.25x      1.33x

@jserv jserv merged commit c43ceb5 into master Feb 7, 2026
9 checks passed
@jserv jserv deleted the wcet branch February 7, 2026 20:50
@jserv jserv restored the wcet branch February 7, 2026 20:51
@jserv jserv deleted the wcet branch February 8, 2026 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant