Chasing 2.94ms: barrier drains, driver arms, and an accidental rebuild win
The 2.94 ms per token gap to macOS Metal is attributed to 471 barrier drains on the GPU's compute command processor. Four candidate fixes failed, and a stale binary was hiding about 0.7 ms.

Qwen3-4B Q4_0 decode runs directly on the AGX GPU of an M2 Ultra under Asahi Linux, bypassing Mesa's stack. A replay runner submits raw CDM command streams to the driver. CDM is the Compute Data Master, the block on the AGX GPU that reads a stream of compute commands and launches the kernels in it. This note covers one measurement session against that runner. The starting scoreboard:
| path | ms/token | tok/s |
|---|---|---|
| Metal (macOS, reference) | 7.71 | 129.7 |
| Direct runner (pinned binary) | 10.65 | 93.9 |
| Vulkan (honeykrisp) | 11.66 | 85.8 |
The question was where the missing 2.94 milliseconds (10.65 − 7.71) go and whether any can be recovered. Four attempts failed, one of them by panicking the host. The only gain came from a stale binary.
Attribution: 471 barriers at about 6µs
The production graph has 725 ops. A dependency analysis keeps 471 CDM barriers between them and elides 254 as safe. Within one CDM stream, launches start in order and overlap by default, so a barrier does not order anything. It drains the whole pipeline. With every barrier elided the runner measures 7.80 ms/token:
That accounts for essentially the whole gap. On macOS the same barrier word drains in ~2.3µs. Under Asahi it takes ~8µs on the ladder fixture, on the same GPU with the same word. The drain cost therefore appears to be set by firmware or driver configuration, and the session targeted the driver configuration.
Method: live rmmod panics the host
Testing a modified asahi.ko requires loading it. Running rmmod asahi, swapping the file and calling modprobe panics the host. The GPU takes an unmapped-read fault during teardown, the driver attempts recovery while holding locks, and the kernel halts. The machine was down for ~20 minutes before it rebooted itself.
Every module swap now goes through a staged-boot protocol:
The dead-man switch returns a wedged boot to the stock module within three minutes. Anyone A/B-testing kernel modules on a remote machine needs an equivalent before the first swap.
Driver arms: no gain
Each of the two top-ranked driver-configuration arms got one boot, measured on the fused production runner:
| arm | ms/token | verdict |
|---|---|---|
| stock baseline | 10.64–10.70 | reference |
| C3-clear-0x4200 | 10.67 | no gain |
| C1a (preemption config) | 11.06 | worse |
C3 is the informative negative. A fixture-level measurement had shown +2.7% for clearing bit 0x4200 from a firmware init value, over three ABBA rounds and byte-exact. An ABBA round runs the baseline (A), then the change twice (B, B), then the baseline again, so slow drift in the machine affects both arms equally. On the production path the effect is zero. The ladder fixture uses a different submission shape from the fused 725-op stream, and the firmware apparently ignores this bit on the production path. A fixture result does not carry over to production.
Apple's five-word barrier token: 64× slower
Static analysis of Apple's encodeBarrier in the AGXMetalG14X kext shows that its dependent-dispatch pattern is not the single stock barrier word. It is a 20-byte token of five 32-bit words: 0x600000d4, 0x00886000, 0x60000120, 0x600010d4, 0x04886000. The hypothesis was that Metal's cheaper drains come from this richer encoding.
The fused runner was patched to emit verbatim barrier words from an environment variable (FUSED_BARRIER_SEQ), so each arm needs a re-run and not a rebuild. The full token gave:
That is 64× slower. The five words are five separate CDM packets, each needing its own retirement, so they do not behave as one fused barrier. The single word 0x6000017c is the only viable encoding found.
The 7.80ms floor is a race
The all-barriers-elided figure of 7.80ms would put the runner at parity with Metal if it were real. Baseline and no-barrier runs were regenerated back to back and every validation row was diffed:
- All 492 validated ops are q4 reference checks (state 2 is the known deterministic reference-check noise, present in both runs).
- 350 rows differ between the runs, all q4, with different max_error magnitudes. This is a genuine race, with q4 ops reading rms output before it lands.
- Every non-q4 op is byte-identical.
The 471-barrier dependency map is therefore required for correctness, and 7.80ms is not an achievable target.
Rebuild: about 0.7ms faster
The environment-variable patch required rebuilding the runner from the current mesa-26.1.5 tree. With the knob unset, so that barrier emission matches stock byte for byte, the rebuilt binary measured:
The runs were interleaved, three rounds each, on the same GPU state. The rebuilt binary is faster in every round, by 0.72, 0.63 and 0.74 ms (mean 0.70 ms, 6.5%). The CDM word streams from the two binaries (FUSEDUMP g0 words) were byte-identical, so the GPU receives the same commands. Validation showed 1240 q4 reference-noise lines identical to baseline and zero non-q4 failures.
The pinned production binary was an older, slower build, and the difference lies entirely in the host-side submit and wait loop. The updated scoreboard:
| path | ms/token | tok/s |
|---|---|---|
| Metal (macOS, reference) | 7.71 | 129.7 |
| Direct runner (rebuilt) | 9.98 | 100.2 |
| Direct runner (pinned) | 10.65 | 93.9 |
| Vulkan (honeykrisp) | 11.66 | 85.8 |
The gap to Metal is 2.27ms, down from 2.94ms, and the runner passes 100 tok/s.
Lessons
- Pin binaries to a build, not a file. The stale "production" binary inflated earlier measurements by about 0.7ms. Each baseline should trace to a commit and a build configuration.
- Attribute before optimizing. With the gap established as 471 drains at about 6µs, scheduling fixes could be rejected quickly: the longest dependency path is 436 ops, which leaves only ~0.21ms of slack.
- Fixtures can mislead. The +2.7% from C3 did not survive on the production path.
- Diff the GPU-side bytes. The identical CDM streams showed that the host path got faster while the GPU work stayed the same.
Open
The remaining 2.27ms is still barrier drain. Matching Metal needs the drain cost to fall from ~6µs to macOS's ~2.3µs. The barrier word, the five-word token and the top two driver-config arms are ruled out. Still to do are a full firmware-init diff against the values macOS sets, and restructuring the rms_norm ops (two internal barriers across 145 ops, about 1.4ms of the floor).
Corrected 2026-10-10: the gap was stated as 2.89 ms; the post's own figures give 10.65 − 7.71 = 2.94 ms. The per-drain cost was stated as 5.9 µs; 2.85 ms over 471 barriers is 6.05 µs. The rebuild gain was stated as ~0.75 ms; the three interleaved rounds shown differ by 0.72, 0.63 and 0.74 ms, a mean of 0.70 ms. The Vulkan row read 85.7 tok/s; 1000 / 11.66 is 85.8. CDM and ABBA are now defined where they first appear.
Corrected 2026-10-21: Apple's barrier token was called a 12-byte token. It is five 32-bit words, which is 20 bytes. The rebuilt runner was given as 10.02 ms/token, a "5-pass median"; the run shown has three rounds, [9.98, 10.02, 9.92], whose median is 9.98 ms. The scoreboard, the throughput (1000 / 9.98 = 100.2 tok/s) and the gap to Metal (9.98 − 7.71 = 2.27 ms) now use that median.
Updated 2026-10-19: the campaign later measured the unconditional barrier cost
on identical bytes at ~6.8 µs (Asahi) versus ~0.3 µs (Apple's no-hazard
path) — clock-independent and raising no host interrupt — which is consistent
with this post's 6.05 µs per-drain arithmetic (receipt:
docs/honeykrisp/kb/ELIMINATION.md §4, "The barrier finding").
