Skip to content

drm/asahi: g17: keep M5 work nodes firmware-cached - #3389

Open
satchlj wants to merge 9 commits into
mainfrom
satchlj/g17-m5-cached-work-nodes
Open

satchlj wants to merge 9 commits into
mainfrom
satchlj/g17-m5-cached-work-nodes

Conversation

@satchlj

@satchlj satchlj commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

What:
Restores the firmware-cached mapping for the M5 Family::WorkState node page (UAT_PGSZ), matching G17P (#3186), and hardens cached-object reuse across stampless render, unstamped drains, kill and recovery. M5 compute descriptors stay on main's rule, uncached on M5 and cached on G17P: caching them as well made light compute at queue depth 4 slower (see Performance).

  • Stampless render (Active::stamps_owed_work): retire_front_command() keeps the Arc<WorkStateLease> on Active before deferring Deferred::Retired whenever stampless is true. The cached WorkNode slot can't be rewritten until post-maintenance completion stamps pop the Active entry.
  • Same-context and cross-context pinning on every unstamped render drain (WorkStates::pin() and WorkStateLease::pin_until_stop()). An active render group released without per-node post-maintenance stamps pins its slot index out of WorkStates::allocate() for the rest of the context's life. Those paths are release_witnessed(), fail_dropped(), settle_interrupted_front(), fail_after_observation() and the failing branch of replay_abandoned(). Pinning clears live[index] so older_live() never stalls, releases held[engine] and shared claims, and makes acquire() return EIO if all 63 slots are pinned. It also calls Context::note_stampless_drain(), so retain_linked_work() holds the context's work state out of pool reuse until firmware stop.
  • WorkStates::used() reads the live words (or shared claims) before the pin mask. A pin landing between the reads can't make its slot look free, which would let may_take() give an engine its peer's last node.
  • Context::retain_linked_work keeps a context's work state until firmware stop whenever linked || kill_published() || stampless_drained() || status.get() != 0.
  • Firmware::service_compute_pools keeps a recycled (killed or quarantined) compute queue's descriptor ring until firmware stop.
  • Objects rewritten in place while their queue may run stay uncached everywhere (Family::QueueState, the compute graph, the M5 Family::Scheduler).
  • Cross-owner reuse relies on main's pool rule (drm/asahi: g17: keep pooled objects mapped until their control fence #2959): no family reuses a returned object before its fence.
  • Tests: tools/asahi/g17-object-fence-tests.py, g17-quarantine-drain-tests.py, run-host-tests.py and the identity.rs KUnit tests compile the real WorkStates and enforce the cache policy and both reuse invariants. That includes a deterministic interleaving test of used() against a concurrent pin() and the mutations drop-stampless-drain-pin, same-context-reuse-pinned-slot, used-pin-first, used-pin-first-shared and m5-cached-descriptors.

Performance (J775c, M5 Max, G17C B1). One-shot trial kernels from one tree and config, aurora.ko built in, ABBA. µs per submit, mean of all runs; Bn is this PR's cache policy:

Test Depth main this PR Change
render.light tri 1 130.20 130.12 0%
2 40.21 47.39 +18%
4 27.52 23.80 −13.5%
8 23.20 19.65 −15.3%
16 23.07 19.62 −14.9%
compute.light 1 126.59 120.91 −4.5%
2 57.86 64.72 +12%
4 18.12 17.36 −4.2%
8 14.76 13.54 −8.3%
16 13.85 13.47 −2.7%

Depth 2 is slower: traces show the firmware starting every other job late while the previous one runs. The doorbell is rung in time with the same power state, and the host side is identical. Main shows the same mode at a lower and varying rate: 1–2.6% of jobs on most boots, 15% on one, against 17–35% here. Spacing consecutive nodes 512 B or 1 KB apart changed nothing, so it is not false sharing within the node page. Caching is fixed when a context's work state is allocated and can't follow a queue's depth, so this PR takes the depth ≥ 4 gain with the depth-2 cost stated here. Caching the M5 compute descriptors too made compute.light d4 +14% (20.42 vs 17.87 µs), so that part was dropped.

Tested: J813 (M5, G17G C0) at exact head ad4234d03725 against main de965eb5, from sithglan (comment 7262555116): render.light −8.4% at depth 2 and −16.6% at depth 8, compute.light −10.1% / −19.5%, output CRCs valid, 0 GPU faults, 0 failed units. There's no depth-2 regression on J813. J775c rows are in the PR comments. Host tests at the current head: g17-object-fence-tests.py passes with all 23 listed mutations killed, and g17-quarantine-drain-tests.py and g17-compute-owed-stamp-tests.py pass. CI's host-tests failures in g17-output-fence-tests and apple-scaler-recovery-tests are inherited from main. Performance rows above: Bn (efde264bcfb7 + used() fix + main's descriptor rule), whose drivers/gpu/drm/asahi matches this head apart from main's later commits; 8 boots of 0 GPU fault lines and 0 failed units.

Risk: two-way · M5 (drm/asahi/g17 only; reverting restores the uncached M5 WorkState allocation).

Not yet: a second M5 board row at this head.

…ached

linux#3170 made every firmware-mutable pooled G17 object uncached after a
J716c (T6050) compute queue record rebound in place had a dirty firmware
line revert the host's owner fields. linux#3186 restored firmware caching
for WorkState node pages and compute DescriptorRings on G17P only, leaving
M5 uncached.

On M5 Max (J775c, T6050), keeping WorkState node pages and compute
DescriptorRings uncached regressed light submission throughput by ~17-20%
(render.light queue d8 18.01 -> 23.19-23.48 us). Both objects obey the
same lifetime invariants on M5 as on G17P:

- Work nodes are rewritten only after WorkStorage::drained() has observed
  the firmware's final completed count from memory, and returned work
  states are zeroed only once their pool fence is met.
- Compute descriptor slots are rewritten only after the kick that last
  used the slot has retired (at most DESCRIPTORS kicks are in flight).

Objects the host rewrites in place while their queue may run keep
linux#3170's uncached mappings everywhere: render queue records
(Family::QueueState), the compute graph, and M5 scheduler pages
(Family::Scheduler).

Restore firmware caching for Family::WorkState (node page, UAT_PGSZ) and
compute Family::Descriptor (size) on M5 as well, and update the cache
policy checks and mutations in tools/asahi/g17-object-fence-tests.py.

Verified on J775c (M5 Max, lobata, one-shot trial boot on 88ddea8):
- render.light queue d4/d8/d16/d32: 27.92/23.48 -> 23.61/19.35/19.17/18.79 us (-15.4%/-17.6% at d4/d8)
- compute.light queue d8/d16/d32: 13.78 -> 12.45/12.43/12.44 us (-9.7% at d32)
- copy.bw queue d8: 412.6 -> 421.2 GB/s
- dEQP-VK.synchronization2.op.multi_queue.*: 16680/16680 pass, 0 fail (7080 not supported)
- Concurrent render.light+compute.light+copy.bw stress, queues mode (d2/d4/d8),
  sync.signal, and 60x rapid context create/destroy cycles: 0 errors, 0 GPU faults,
  0 kernel WARNs.
- tools/asahi/g17-object-fence-tests.py + all 9 mutations pass.

Signed-off-by: Satya Benson <[email protected]>
@satchlj
satchlj requested review from a team and DjDeveloperr as code owners November 27, 2026 14:01
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 27, 2026
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Merge readiness at ad4234d0: not ready yet

Check Detail
CI at head no failing: KUnit asahi, KUnit spi-hid-apple, KUnit avd, KUnit ave, KUnit isp, KUnit jpeg
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes no requested by erikwb
Hardware row at head ok in the PR body at ad4234d0
Conflicts no merge conflicts with main: merge it in (no force push)
PR text ok Risk: two-way · M5 (drm/asahi/g17 only; reverting restores the uncached M5 WorkState allocation).

Areas: area:gpu

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The measured throughput and healthy context churn support the optimization, but the safety argument treats descriptor retirement and the final completed count as evidence that every firmware cache line the host will rewrite is clean. The prior M5 bug was a delayed writeback across reuse. Identify the writeback or ownership guarantee for both object classes, including forced stop or recovery, and add a reuse-after-recovery test with the cached mappings and a current-head M5 peer. Keep required CI green before merge.

…ecovery and stop

Close the forced-stop, recovery, and full-pool fence-overrun gaps for firmware-cached Family::WorkState and compute Family::Descriptor objects:

1. Never overrun a pool fence for firmware-cached objects (prefix != 0)
   in Pool::allocate: when all 64 slots of a cached family are active or
   waiting behind their control-ring fence, allocate a fresh unpooled
   (uncached) object instead of zeroing a cached object whose prior
   owner's release the firmware has not yet consumed.
2. In Context::retain_linked_work, retain the cached WorkState via
   retain_until_stop(pool) whenever the context was killed
   (kill_published) or its VM failed (status != 0), even if the work
   list head is empty, so aborted work without stamped completion never
   returns its cached node page to the reuse pool before firmware stop.
3. In Firmware::service_compute_pools, retain a compute queue's cached
   DescriptorRing via Queue::retain_ring_until_stop(&self.pool) whenever
   recycle_killed or recycle_quarantined_idle recycles a queue after a
   kill or quarantine, so its ring leaves the reuse cache until firmware
   stop instead of returning to Pool on vacate.
4. Sync tools/asahi/run-host-tests.py with the g17-object-fence-tests.py
   mutation names and add host unit and mutation coverage for cached
   fence overruns, killed/failed work-state retention, and recycled
   compute descriptor-ring retention.

Signed-off-by: Satya Benson <[email protected]>

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I verified that failed and killed WorkState objects and recycled compute DescriptorRing objects are retained outside the reuse pool, and cached allocations cannot overrun a waiting pool fence. The remaining normal reuse exception is stampless render: WorkStorage::drained() reads an uncached counter, while the reused node is now firmware-cached. Please identify the ordering guarantee that puts node cache writeback before the observed counter, or keep the node uncached when retirement can be stampless. The new host policy checks cover retention and allocation but cannot establish that firmware ordering. Keep the current head held for exact recovery reuse on J775c and a second M5 row.

@satchlj

satchlj commented Nov 27, 2026

Copy link
Copy Markdown
Member Author

Addressed the writeback/ownership review comments in f8e1fa4349c4 and ran live J775c reuse-after-recovery verification on that exact head:

Ownership & writeback hardening (f8e1fa4349c4)

  1. No pool-fence overruns for firmware-cached objects (g17/object.rs): Pool::allocate sets no_overrun = marked || prefix != 0 so firmware-cached WorkState and compute Descriptor objects never bypass a waiting control-ring fence when POOL_SLOTS is full (falling back to a fresh unpooled/uncached object instead). Uncached pooled objects (prefix == 0) keep exact BASE behavior.
  2. Killed/failed WorkState retained until firmware stop (g17/context.rs): Context::retain_linked_work retains the WorkState in firmware_linked_objects via retain_until_stop(pool) whenever linked || self.kill_published() || self.status.get() != 0, closing the kill/recovery-failure gap even when work_head is already empty.
  3. Recycled compute DescriptorRing retained until firmware stop (g17/queue/compute.rs, g17/runtime.rs): Firmware::service_compute_pools calls Queue::retain_ring_until_stop(&self.pool) whenever recycle_killed() or recycle_quarantined_idle() recycles a compute queue.
  4. Intra-owner reuse: Normal WorkNode slot re-initialization waits for every Arc<WorkStateLease> on the node to retire (M5 compute never retires stampless; normal render retires on post-maintenance TA+3D completion stamps, and stampless render fallback checks WorkStorage::drained() from the uncached counter page). Normal compute DescriptorRing slot reuse (kick % 32) requires the kick 32 slots earlier to have retired via post-maintenance stamp + cursors.consumed (IN_FLIGHT <= 32).
  5. Host tests & mutations: Synced all 13 mutations in tools/asahi/run-host-tests.py and added 4 new policy mutations (overrun-cached-prefix, reuse-killed-work-state, reuse-failed-work-state, reuse-recycled-descriptor-ring) + Context killed/failed retention unit tests. Native Linux python3 -I tools/asahi/run-host-tests.py --only g17-object-fence passed 14/14.

Live J775c (M5 Max, T6050) reuse-after-recovery verification at f8e1fa4349c4 (boot 43adcd30)

  • Triggered 2x compute-hang watchdog kills (ETIMEDOUT -> VK_ERROR_DEVICE_LOST) and 2x render-hang GPU fault recoveries (recovery gen 0/gen 1, EIO -> VK_ERROR_DEVICE_LOST) while concurrent innocent compute clients ran 400/400 verified dispatches each without error.
  • Ran interleaved post-recovery churn: 160 fresh contexts x 70 verified dispatches = 11,200/11,200 verified dispatches (wrapping all 32 DescriptorRing slots and 63 WorkNode slots per context) with 0 mismatches and 0 unexpected faults.
  • /sys/kernel/debug/aurora-g17/capacity confirmed firmware_linked_objects incremented 0 -> 1 (524,288 B) -> 2 (557,056 B) -> 4 (622,592 B) -> 8 (1,245,184 B) across the recoveries, with cached_objects_0 (Descriptor) returned=11 overruns=0, cached_objects_1 (WorkState) returned=4 overruns=0, and cached_objects_fenced overruns=0.
  • Immediately followed on the same post-recovery boot by:
    • dEQP-VK.synchronization2.op.multi_queue.*: 16,680/16,680 PASS, 0 failed, 7,080 not supported, 0 warnings.
    • gpubench-vk: render.light QD8 19.24 us (-18.1% vs uncached 23.48 us), QD32 18.65 us; compute.light QD8 12.57 us, QD32 12.43 us (-9.8%); copy.bw QD8 423.9 GB/s (+2.7%); render.heavy QD8 60.05 us (552.5 Gpix/s); compute.heavy QD8 135.65 us (15,831 GFLOP/s).
    • 0 kernel WARNING/BUG/Oops, failed_units=0.

Waiting on queued GitHub Actions CI at f8e1fa4349c4 and a second M5 board peer row.

@gig3m

gig3m commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

J813 (MacBook Air 13" M5, G17G) at 1cef4f208efe: light Vulkan compute submits are 23–29 % faster at queue depth 8 and 32. GL load is unchanged, with no GPU faults.

Kernel: this head plus our local XRGB8888 primary-plane patch for Hyprland, LLVM, booted once behind a Stage 2 carrying this tree's J813 DTB. GPU firmware 26B123. A/B on the same kernel, one boot per arm: aurora.ko from this head, and the same tree with 1cef4f2's two driver hunks reverted.

Check This head 1cef4f2 reverted
Boot Initialized aurora, Hyprland desktop, 0 failed units same
Light compute, queue depth 8 (µs per submit, 3 runs) 19.13 / 19.49 / 19.37 24.96 / 25.52 / 25.26
Light compute, queue depth 32 (µs per submit, 3 runs) 16.75 / 16.80 / 17.05 23.82 / 24.02 / 23.54
Light compute, queue depth 1 (µs per submit, 3 runs) 392 / 397 / 378 392 / 393 / 388
GL: glmark2-es2-drm --off-screen at 2560x1664, 2 full runs 1255, 1244 1244, 1229
GL: 3 runs of terrain/refract/jellyfish/shadow/build at 15 s each 709, 702, 695 707, 706, 703
GPU fault, timeout or recovery lines in the kernel log 0 0

Means: depth 8 25.25 → 19.33 µs (−23.4 %), depth 32 23.79 → 16.87 µs (−29.1 %). Depth 1 is the same on both arms; it is dominated by the host's fence wait, not by the submit.

The light-compute numbers come from a small Vulkan program of ours, not gpubench-vk. Each submit is one command buffer holding a single 1×1×1 dispatch of an atomicAdd on one storage-buffer word, run as a ring of N fences (wait on the oldest, reset, resubmit). Each depth has a 2,000-submit warm-up, then 20,000 timed submits. The final counter matched the submit count on every run.

tools/asahi/g17-object-fence-tests.py passes at this head, and all 9 --mutation runs fail as they should.

Not run: a render-light Vulkan workload, dEQP-VK, or a multi-client stress test.

Assisted-by: LLM (Claude:Opus 5.5)

@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) and removed needs-hw-row No hardware row at the PR head (bot) labels Nov 27, 2026
@github-actions github-actions Bot added blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) and removed needs-template PR body lacks Tested or Risk (bot) labels Nov 27, 2026
…ement

On stampless render retirement, retiring the submission via
Deferred::Retired releases Submission::state.work while Active still
keeps the descriptor slot with stamps_owed = true waiting for
post-maintenance completion stamps. With firmware-cached WorkNode pages,
releasing WorkStateLease early allows the same context to rewrite the
node slot before firmware completion stamps witness cache writeback; the
host cannot rely on WorkStorage::drained() (which reads WorkNode.completed
on the cached node page) to order writeback of the rest of the 0xc8-byte
node.

Keep WorkStateLease on Active::stamps_owed_work before deferring
Deferred::Retired when stampless is true so the work-node slot stays
pinned until post-maintenance completion stamps pop the Active entry. If
a stamps_owed group is instead released through pair-wide drain in
release_witnessed(), mark the context stampless_drained so
Context::retain_linked_work() retains the work storage via
retain_until_stop() until firmware stop.

Update the Context::new comment to reflect that cached work-node reuse is
always gated by post-maintenance completion stamps or firmware stop, and
extend g17-object-fence-tests.py, g17-quarantine-drain-tests.py, and
run-host-tests.py with host checks and mutations covering both invariants.

Signed-off-by: Satya Benson <[email protected]>
@satchlj

satchlj commented Nov 27, 2026

Copy link
Copy Markdown
Member Author

Addressed the stampless-render ordering blocker in 0c63d8292439:

  • Eliminated reliance on WorkStorage::drained() for cached-node reuse: WorkStorage::drained() reads WorkNode.completed on page 0 (the cached node page), not the uncached counter page (our earlier PR description misstated that). Even with completed on page 0, releasing WorkStateLease inside Deferred::Retired while Active::stamps_owed is true could let the context rewrite the 0xc8-byte node before post-maintenance completion stamps witness writeback.
  • Pin WorkStateLease across stamps_owed: retire_front_command() now stores front.stamps_owed_work = Some(front.packet.completion.work_state()?) before deferring Deferred::Retired when stampless is true, so the WorkNode slot stays pinned until post-maintenance completion stamps arrive and pop front.
  • Retain on pair-wide drain: if release_witnessed() instead pops a stamps_owed entry, it calls active.packet.context.note_stampless_drain(), and Context::retain_linked_work() now retains WorkState via retain_until_stop(pool) whenever linked || kill_published() || stampless_drained() || status.get() != 0.
  • Verified at exact head 0c63d8292439:
    • Host tests: run-host-tests.py --only g17-object-fence 17/17 PASS (3 new mutations killed: reuse-stampless-drained-work-state, drop-stampless-work-lease, drop-stampless-drain-mark), full run-host-tests.py --only g17- 238/238 PASS, checkpatch.pl --strict 0/0/0.
    • Live J775c (7.3.0-pr3389-r3+, boot 4d22031a): 2× compute-hang watchdog kills with 400/400 innocent survivor PASS, 100×70 = 7,000/7,000 post-recovery multi-context churn PASS, firmware_linked_objects kept=6 (1,179,648 B), overruns=0 across all cached/fenced pools, dEQP-VK.synchronization2.op.multi_queue.* 16,680/16,680 PASS, gpubench-vk clean (render.light QD4 23.59 µs / QD8 19.61 µs, compute.light QD32 11.95 µs), 0 kernel warnings/faults.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: FINISH, then merge.

Blocker: The new lease covers the normal wait for post-maintenance stamps. On pair-wide drain, release_witnessed() drops the Active entry and its lease after setting stampless_drained. The new flag is consumed in retain_linked_work(), which protects pool reuse when the context closes. Please prove that every unstamped drain path also prevents a later submission in the same context from acquiring that slot, or keep the lease pinned until firmware stop on that path. Cover the same-context case in the host fixture and attach the exact recovery/reuse rows.

Checked: The fast path takes the lease before deferred retirement can release the original. The added drain test and context flag address the cross-context pool lifetime. The posted older J813 performance row does not exercise the new drain path.

…ontext reuse

When an unstamped render drain (pair-wide drain in release_witnessed(),
fail_dropped(), settle_interrupted_front(), fail_after_observation(), or
failing replay_abandoned()) releases an active group without per-node
post-maintenance completion stamps, setting stampless_drained on the
context protects cross-context pool reuse in retain_linked_work() but
still let Drop for WorkStateLease return the slot index to WorkStates
for a later submission in the same context.

Add WorkStates::pin() and WorkStateLease::pin_until_stop() so every
unstamped drain path permanently keeps that slot index out of
WorkStates::allocate() for the rest of the context's life (while
clearing live[index] to FREE so older_live() never stalls, decrementing
held[engine] to avoid may_take() starvation, releasing shared claims for
sibling contexts, and returning EIO from acquire() if all 63 slots are
ever pinned) and still sets stampless_drained for cross-context
retention until firmware stop.

Extend g17-object-fence-tests.py, g17-quarantine-drain-tests.py,
run-host-tests.py, and identity.rs KUnit tests to cover same-context
pinning and its negative-control mutations.

Signed-off-by: Satya Benson <[email protected]>
@satchlj

satchlj commented Nov 27, 2026

Copy link
Copy Markdown
Member Author

Addressed the same-context unstamped-drain blocker in 2ddf78f16eca (non-force push):

  1. Same-context slot pinning (WorkStates::pin() + WorkStateLease::pin_until_stop()):
    • Added a pinned: AtomicU64 slot mask to WorkStates (drivers/gpu/drm/asahi/g17/context/identity.rs) and WorkStateLease::pin_until_stop() (drivers/gpu/drm/asahi/g17/context.rs).
    • On Drop for WorkStateLease, a pinned lease calls WorkStates::pin(word, engine), which sets pinned |= 1 << index before clearing live[index] to FREE (preventing concurrent allocate() races, keeping older_live() unblocked, decrementing held[engine] so may_take() cannot deadlock, releasing shared claims for sibling contexts while keeping used() accurate, and returning EIO from acquire() if all 63 slots are ever pinned). pin_until_stop() also sets stampless_drained for cross-context pool retention in retain_linked_work().
  2. All unstamped render drain paths covered (drivers/gpu/drm/asahi/g17/queue/render.rs):
    • release_witnessed() (both stamps_owed via stamps_owed_work and drained entries), fail_dropped(), settle_interrupted_front(), fail_after_observation(), and the failing branch of replay_abandoned() all call pin_until_stop() before releasing the Active entry.
    • (compute::release_witnessed_inner() already requires retirement::quarantined_retired() -> stamp_covers(stamp, newest.kick), and stopped() runs only after both processors have halted.)
  3. Host tests & live J775c exact-head 2ddf78f16eca verification:
    • tools/asahi/g17-object-fence-tests.py compiles and exercises the real WorkStates from g17/context/identity.rs (same-context non-reuse over 4 * STATE_COUNT cycles, older_live(), may_take(), shared claims, 63-slot exhaustion) + negative-control mutations drop-stampless-drain-pin and same-context-reuse-pinned-slot; g17-quarantine-drain-tests.py asserts release_witnessed() pins stamps_owed_work.
    • python3 tools/asahi/run-host-tests.py --only g17: 239/239 PASS; ./scripts/checkpatch.pl --strict: 0 errors, 0 warnings, 0 checks.
    • Live J775c (7.3.0-pr3389-r4+): 0 failed units, 0 Oops/WARN; 2× compute-hang watchdog kills (failed_kill_waits under_10ms=2) with concurrent innocent survivor 180/180 PASS + 100-context post-recovery pool churn 400/400 PASS; /sys/kernel/debug/aurora-g17/capacity: crashed=0, render_slots quarantined=0, cached_objects_0..4 all poisoned=0 overruns=0, firmware_linked_objects kept=6 bytes=1179648, all refusal sites 0; dEQP-VK.synchronization2.op.multi_queue.* 16,680/16,680 runnable PASS (0 fail); gpubench-vk render.light d=8 19.5 µs / compute.light d=8 12.7 µs.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: FINISH, then merge at 2ddf78f16eca.
Blockers: The earlier same-context reuse finding is addressed in source. Please attach the second M5 recovery/regression row at this commit and wait for hosted checks.
Checked: The slot pin is published before its live word returns to FREE; allocation checks the pin again after claiming the live word. Pinned slots retire from ordinal tracking and still count against capacity. I traced the retained lease through pair-wide drain and the other unstamped render retirement paths. The author reports 239/239 host tests, including same-context reuse and drain-pin negative controls, plus exact-head J775c recovery and churn. The second M5 row remains outstanding.

#3389 (comment)

@gig3m

gig3m commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Second M5 row, J813 (MacBook Air 13" M5, G17G) at 2ddf78f16eca: two compute-hang watchdog kills with innocent clients running alongside, then 100 fresh clients churning the pools. No failures, no GPU faults, and light compute submits stay 23–30 % faster than main.

Kernel: main cec0503a5a02 plus this PR plus our local XRGB8888 primary-plane patch for Hyprland, LLVM, GPU firmware 26B123. The commits after 1cef4f208efe change only drivers/gpu/drm/asahi and tools/asahi, so the aurora.ko arms run on the kernel from our 1cef4f208efe row. Its drivers/gpu/drm/asahi is byte-identical to this head. A/B on the same kernel, one boot per arm, same day: aurora.ko at this head, and aurora.ko from main.

Check This head main
Compute-hang kills (VK_ERROR_DEVICE_LOST after 2.0 s, failed_kill_waits under_10ms) 2 / 2 2 / 2
Innocent clients during the kills: back-to-back verified vklight runs (depth 8, depth 1) 167 + 23 pass, 0 fail 131 + 18 pass, 0 fail
firmware_linked_objects after the kills kept=3 (1,081,344 B) kept=0
Post-recovery churn: 100 fresh clients × 154 verified submits 100 / 100 100 / 100
cached_objects_* / cached_objects_fenced overruns, poisoned, crashed 0 / 0 / 0 0 / 0 / 0
Light compute, queue depth 8 (µs per submit, 3 runs) 19.97 / 19.17 / 19.35 25.13 / 25.28 / 25.15
Light compute, queue depth 32 (µs per submit, 3 runs) 17.48 / 16.46 / 16.75 24.22 / 23.88 / 24.16
Light compute, queue depth 1 (µs per submit, 3 runs) 390 / 388 / 379 389 / 392 / 375
GL: glmark2-es2-drm --off-screen at 2560x1664, 2 full runs 1230, 1249 1235, 1238
GL: 3 runs of terrain/refract/jellyfish/shadow/build at 15 s each 695, 710, 712 707, 714, 699
GPU kernel log lines other than the two deliberate kills 0 0
Boot: Initialized aurora, Hyprland, failed units yes, alive after the test, 0 same

Means: depth 8 25.19 → 19.50 µs (−22.6 %), depth 32 24.09 → 16.90 µs (−29.8 %), in line with our 1cef4f208efe row.

The hang client is one 1×1×1 compute dispatch that loops until a storage-buffer word the host never sets is non-zero. Each kill shows as "watchdog gave up on a compute command … allowance 2000 ms", and the client gets a lost device. Survivors and churn use the light-compute program from our earlier row: a ring of fences over a 1×1×1 atomicAdd dispatch, with the counter checked against the submit count after every run. Each churn client creates its own instance and device, then runs 77 submits at depth 1 and 77 at depth 8.

tools/asahi/g17-object-fence-tests.py and tools/asahi/g17-quarantine-drain-tests.py pass at this head. I did not run their --mutation variants.

Not run: a render-hang GPU fault recovery, dEQP-VK, or a multi-queue stress test.

Assisted-by: LLM (Claude:Opus 5.5)

@m0d16l14n1

m0d16l14n1 commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

J815 (MacBook Air 15" M5, G17G) row: light render and light compute submits are 10–26 % faster at queue depth 4 and 16. dEQP-VK and the Godot TPS demo are unchanged. The multi-queue stress test fails as it does without this PR.

Kernel: the four commits of this PR (1cef4f208efe, f8e1fa4349c4, 0c63d8292439, 2ddf78f16eca) cherry-picked onto our J815 tree. That tree's drivers/gpu/drm/asahi is main at 96ef580d6199 plus our local J815 commits, so it is not byte-identical to this head. The picks applied cleanly in drivers/gpu/drm/asahi; the only conflicts were in tools/asahi. Both arms ran on the same Image and initramfs with the same module parameters; only aurora.ko differs (with and without the four commits). One boot per arm, same day, GPU firmware 26B123, Mesa aurora-wip (Borealis).

gpubench-vk medians in µs per submit, defaults (5 × 250 ms), two rounds:

Test Queue depth This PR Without
compute.light 16 17.5 / 17.7 23.7 / 24.0
compute.light 4 23.2 / 24.2 29.4 / 31.6
compute.light 1 401 / 398 422 / 429
render.light kind=tri 16 39.0 / 38.5 45.1 / 45.3
render.light kind=tri 4 46.1 / 45.5 50.6 / 50.9
render.light kind=tri 1 434 / 444 460 / 462
render.heavy kind=geom res=1080p 4 213 / 204 218 / 205
render.heavy kind=fill res=1080p 4 253 / 255 265 / 260

Means: compute depth 16 23.85 → 17.60 µs (−26.2 %), depth 4 30.5 → 23.7 µs (−22.3 %); render depth 16 45.2 → 38.75 µs (−14.3 %), depth 4 50.75 → 45.8 µs (−9.8 %). The per-submit GPU time is the same on both arms (compute 1.9 vs 2.0 µs, triangle 4.5 vs 4.8 µs), so the gain is in submission and retirement, not in the work itself.

Check at this PR Result
dEQP-VK 1.4 gate list, 15,958 cases sampled across groups (largest: pipeline, tessellation, conditional rendering, api, multiview, shader object) 11,198 Pass, 4,760 NotSupported, 0 Fail/Crash/Timeout, the same as without; 0 GPU kernel lines
Godot TPS demo, 1920×1080, short run 57.6 fps, GPU p50 17.07 ms in play; without: 57.3–57.6 fps, 17.07–17.12 ms over 4 runs
gpubench-stress-vk, 17 tests, 300 s 15 pass, 1 fail (queue.depth), 1 skip (ray query)
queue.depth standalone 4 / 4 fail with VK_ERROR_DEVICE_LOST
Kernel log all GPU lines this boot come from the 5 queue.depth runs; failed units 0

queue.depth (3 clients × 4 queues, mixed global priorities) is not caused by this PR. The same test fails the same way on our earlier J815 trees that do not have it, including one with #3170 reverted. The kernel line is "watchdog gave up on a compute command … allowance 2000 ms … no sharing renewals on this GPU": on M5, renews_shared() is false, so a low-priority client's command that is only waiting behind later higher-priority work is killed after 2 s. That needs its own change to the M5 watchdog. With such a change (renewing only while work published after the job keeps retiring), queue.depth passed 4 / 4 on our tree.

Not run: the --mutation variants of tools/asahi/g17-object-fence-tests.py (the plain run passes 18 / 18 on our tree), and a render-hang recovery test.

@satchlj

satchlj commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Addendum from the same traces: the doorbell is not the cause. For jobs before a long GPU gap it is rung 100% of the time, sooner after publish than for normal jobs (median 19–21 vs 28–34 µs), with the same power word (0xd). In 75% of long-gap jobs on Bn the previous job was still running when this one was published. So the firmware has the job and its doorbell in time and still starts it late, every other job in a streak. That points into the firmware's handling of the cached work node. The host-visible tracepoints can't go further.

With cached work nodes, also caching the M5 compute descriptor ring made
light compute submits at queue depth 4 slower on J775c: 17.9 µs on main,
17.5 µs with nodes alone, 20.4 µs with both. It added nothing at the
depths where cached nodes help. Return M5 descriptors to main's rule:
uncached on M5, firmware-cached on G17P. A queue recycled after a kill or
quarantine still retains its ring until firmware stop.

g17-object-fence-tests.py again requires main's descriptor rule. Its
uncached-descriptors mutation is replaced by main's m5-cached-descriptors.

Signed-off-by: Satya Benson <[email protected]>
@satchlj satchlj changed the title drm/asahi: g17: keep M5 work nodes and compute descriptors firmware-cached drm/asahi: g17: keep M5 work nodes firmware-cached Nov 29, 2026
@satchlj

satchlj commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Pushed 730f85a54126: M5 compute descriptors return to main's rule (uncached on M5, cached on G17P), and the PR now caches work nodes only. The title and body are updated with the performance table.

Variant row for the depth-2 late starts, 8 one-shot boots (A Bn Bn2 Bn4 Bn4 Bn2 Bn A), all with 0 GPU fault lines and 0 failed units. Bn2 and Bn4 space consecutive work-node allocations 512 B and 1 KB apart (next.fetch_add(2|4)) to test false sharing in the cached node page:

Boot Jobs with a late start (GPU gap > 3× median) Share of GPU idle
1A 1.7% 8%
2Bn 35.0% 87%
3Bn2 32.2% 84%
4Bn4 17.8% 59%
5Bn4 33.3% 85%
6Bn2 33.5% 86%
7Bn 35.4% 87%
8A 15.0% 51%

Spacing changes nothing, so it is not false sharing. Holding a node for an extra completion or alternating two pools wouldn't change what the firmware sees either: a node is already reused only after the other 62. Main reaches the same mode on some boots (8A, 15%), so caching makes an existing firmware mode more frequent. Throughput is in the body: depth ≥ 4 render −13.5 to −15%, compute −3 to −8%; depth 2 +12 to +18%. Converting back from draft: the change is now what it should be, with its cost stated.

@satchlj
satchlj marked this pull request as ready for review November 29, 2026 19:45

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: HOLD at 730f85a5

Blockers:

  1. Hosted CI at 730f85a5 is still queued (apple-build, host-tests, pr-text, readiness, and KUnit suites pending).
  2. A second M5 / G17 hardware row at 730f85a5 (including the shared-context path) is still outstanding, as noted in the PR description.
  3. Prior human CHANGES_REQUESTED remains open for re-verification of the fixes and sign-off on the documented depth-2 latency tradeoff (+12% compute.light, +18% render.light vs -3..15% at depth >= 4).

Checked:

  • Verified ae0f996a (drivers/gpu/drm/asahi/g17/context/identity.rs:345-358): WorkStates::used() now reads claims.load(Ordering::Acquire) (shared contexts) or self.live[i].load(Ordering::Acquire) (private contexts) before self.pinned.load(Ordering::Acquire). Verified against WorkStates::pin() (:120-141), which publishes self.pinned.fetch_or(mask, Ordering::AcqRel) before clearing self.live[index] and claims, eliminating the window where a concurrently pinned slot could be counted as free. New used-pin-first and used-pin-first-shared host-test mutations cover both paths.
  • Verified 730f85a5 (drivers/gpu/drm/asahi/g17/queue/compute.rs): restores M5 compute descriptors to uncached (if alloc.uat.is_m5() { 0 } else { size }) while keeping G17P cached and retaining descriptor rings across kill/quarantine (retain_ring_until_stop), resolving the depth-4 compute.light regression (17.36 vs 18.12 us on J775c). Updated g17-object-fence-tests.py and run-host-tests.py (m5-cached-descriptors) match.
  • Verified DCO sign-off is now present on all 8 commits in the branch (f207315d..730f85a5).
  • Reviewed the J775c depth-2 trace and spacing-variant (Bn/Bn2/Bn4) evidence showing 0 GPU fault lines and 0 failed units across 8 boots.
Evidence
  • drivers/gpu/drm/asahi/g17/context/identity.rs:120-141 (WorkStates::pin), :345-358 (WorkStates::used).
  • drivers/gpu/drm/asahi/g17/context.rs:338-346 (Family::WorkState cached node page, uncached counter page), :559-564 (retain_linked_work).
  • drivers/gpu/drm/asahi/g17/queue/compute.rs: M5 compute descriptors uncached (if alloc.uat.is_m5() { 0 } else { size }).
  • tools/asahi/g17-object-fence-tests.py and tools/asahi/run-host-tests.py: used-pin-first, used-pin-first-shared, m5-cached-descriptors mutations present and wired.

@satchlj

satchlj commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

@erikwb ready for your re-review at 730f85a54126. Your three blockers:

  1. Depth-4 compute regression: isolated to caching both nodes and compute descriptors. Descriptors are back on main's rule (730f85a5), and compute d4 is now −4.2% against main. Depth 2 is a separate cost of node caching: +12% compute and +18% render. The PR takes that cost knowingly, with the trace evidence in the body (firmware every-other-job late start; host side identical; not false sharing; main hits the same mode on some boots). Please say whether you accept that tradeoff or want something else.
  2. The used()/pin() race: fixed in ae0f996a, with a deterministic interleaving test on private and shared contexts and the used-pin-first/used-pin-first-shared mutations.
  3. Missing sign-off on 1cef4f208efe: every commit now carries it (the first is now f207315d7ad6).

The second-G17-board row with the shared path is requested in #agents and still open.

@satchlj
satchlj requested a review from erikwb November 29, 2026 19:55
@github-actions github-actions Bot added changes-requested A reviewer requested changes (bot) ci-failing A check failed at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 29, 2026
@sithglan

Copy link
Copy Markdown
Contributor

Attempted the requested J813 (MacBook Air 13-inch M5, G17G C0, FW 27.2 / 26B123) A/B row at exact head 730f85a54126 against matched main merge-base de965eb5b26b (ARCH=arm64 LLVM=-19), but exact head 730f85a54126 fails to compile drivers/gpu/drm/asahi/asahi_core.o:

error[E0063]: missing field `pinned` in initializer of `WorkStateLease`
   --> drivers/gpu/drm/asahi/g17/context.rs:791:14
    |
791 |         Some(Self {
    |              ^^^^ missing `pinned`

Merge 0e013f4edce6 pulled in WorkStateLease::deferred_split() from main without initializing pinned: AtomicBool::new(false).

The matched main control arm (de965eb5b26b, 7.3.0-aurora-j813-ab-main+, aurora.ko sha256 102767bb1285, Mesa Borealis 26.3.0-devel libvulkan_asahi.so sha256 f983ee797c9b, gpubench 868b064) already ran cleanly on J813 (3 rounds × 5 × 250 ms, 0 GPU faults, 0 failed units; stock boot restored). Once deferred_split() is fixed and a buildable head is pushed, we can run the matched J813 A/B immediately.

The merge of main brought in deferred_split(), which builds a
WorkStateLease without the pinned field this series adds, so the
driver no longer compiled (E0063). Start it unpinned, as the other
constructor does.

Signed-off-by: Satya Benson <[email protected]>
@satchlj

satchlj commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

@sithglan thanks for catching that. The main merge brought in WorkStateLease::deferred_split(), which didn't initialise the new pinned field. Fixed in ad4234d0372580e05926c147e3a240a1afd0c6af (one line). Built from that head with the full drivers/gpu/drm/asahi driver and Image.gz (rustc 1.93.1), rc=0. It should be ready for your J813 arm now.

@github-actions github-actions Bot added needs-hw-row No hardware row at the PR head (bot) and removed ci-failing A check failed at the PR head (bot) labels Nov 29, 2026

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: HOLD at ad4234d0 — build break fixed; waiting on hosted CI, second M5 hardware row, and open review resolution.

Blockers:

  • Hosted CI is still pending at ad4234d0 (4 passed, 0 failed, 19 queued/pending).
  • Hardware coverage still has only a single M5 system (J815); a second M5/G17 system row (e.g. J813, currently being prepared) is still pending before merge.
  • Existing CHANGES_REQUESTED review from @erikwb on the prior head remains open and needs sign-off on the updated stack.

Checked:

  • Verified the single-line delta 730f85a5..ad4234d0 (drivers/gpu/drm/asahi/g17/context.rs:795): WorkStateLease::deferred_split() now initializes pinned: AtomicBool::new(false), resolving the E0063 missing-field compile error in drivers/gpu/drm/asahi/g17/context.rs.
  • Audited all WorkStateLease struct literals in drivers/gpu/drm/asahi/g17/context.rs (new at line 783 and deferred_split at line 795); both initialize pinned, and Drop checks self.pinned.load(Ordering::Acquire) as intended.
  • Confirmed DCO Signed-off-by is present on ad4234d0 and all prior commits in the PR.
Evidence
  • ad4234d0372580e05926c147e3a240a1afd0c6af: +1/-0 in drivers/gpu/drm/asahi/g17/context.rs (WorkStateLease::deferred_split adds pinned: AtomicBool::new(false)).
  • Only two WorkStateLease initializers exist in drivers/gpu/drm/asahi/g17/context.rs (lines 783 and 795); no other call sites construct WorkStateLease.
  • Author reports clean local drivers/gpu/drm/asahi + Image.gz build (rc=0) at ad4234d0.
  • Remaining merge gates are unchanged from 730f85a5: green hosted CI at ad4234d0, second M5/G17 hardware verification row, and @erikwb sign-off on the prior CHANGES_REQUESTED review.

@sithglan

Copy link
Copy Markdown
Contributor

Second M5 board A/B verification at exact head ad4234d03725 — MacBook Air (13-inch, M5, J813 / apple,t8142, G17G C0) — PASS

Configuration & Provenance (100% isolated drivers/gpu/drm/asahi/g17/ delta)

  • Delta verified: git diff de965eb5b26b..ad4234d03725 --stat touches only the 5 drivers/gpu/drm/asahi/g17/*.rs files (plus 3 tools/asahi/ host test files). Identical .config, identical ARCH=arm64 LLVM=-19, byte-identical t8142-j813.dtb (sha256: 17a035a33db1), one guarded one-shot aura-try boot per arm.
  • main control arm: de965eb5b26b1e4dd6cd4820ffd1bb0d63bd19fe (7.3.0-aurora-j813-ab-main+), Image.gz sha256: 5ac2da4849eb, aurora.ko sha256: 102767bb1285 (pre-run GPU temp 34.3 °C, post-run 49.5 °C, E/P clocks 4.46 / 2.35 GHz -> 3.52 / 1.99 GHz).
  • #3389 arm: ad4234d0372580e05926c147e3a240a1afd0c6af (7.3.0-aurora-j813-ab-pr3389+), Image.gz sha256: c6291b71322a, aurora.ko sha256: bd6c6c2d0c15 (pre-run GPU temp 32.3 °C, post-run 50.0 °C, E/P clocks 2.82 / 2.96 GHz -> 3.88 / 1.99 GHz).
  • GPU firmware: 27.2 (26B123), G17G C0.
  • Mesa: Mesa 26.3.0-devel, Borealis (driver_version: 0x6802063, libvulkan_asahi.so sha256: f983ee797c9b).
  • Benchmark: aurora-silicon/gpubench (868b064), 3 rounds × default 5 × 250 ms per depth (µs/submit, lower is better).

Results (µs/submit, mean of 3 round medians)

Test Depth main (de965eb5) #3389 (ad4234d0) Change main rounds #3389 rounds
render.light tri 1 463.25 145.01 −68.7%* [462.96, 463.82, 462.96] [89.13, 86.84, 259.07]
render.light tri 2 60.30 55.26 −8.4% [57.92, 60.96, 62.00] [53.53, 56.74, 55.49]
render.light tri 4 50.89 43.96 −13.6% [50.64, 50.79, 51.24] [44.48, 43.74, 43.66]
render.light tri 8 46.18 38.52 −16.6% [45.84, 45.93, 46.77] [38.77, 38.92, 37.88]
render.light tri 16 45.70 37.49 −18.0% [45.37, 45.47, 46.27] [37.72, 37.86, 36.89]
compute.light 1 415.52 413.68 −0.4% [416.67, 416.67, 413.22] [413.22, 414.59, 413.22]
compute.light 2 38.63 34.73 −10.1% [39.53, 37.08, 39.28] [34.04, 36.13, 34.02]
compute.light 4 28.86 24.94 −13.6% [28.84, 28.87, 28.87] [24.98, 24.85, 24.98]
compute.light 8 24.91 20.04 −19.5% [24.92, 24.90, 24.92] [20.03, 20.08, 20.02]
compute.light 16 23.68 18.64 −21.3% [23.69, 23.68, 23.66] [18.62, 18.68, 18.63]

*render.light d1 is bimodal on J813 (~87–89 µs vs ~463 µs idle-wake latency; an earlier main control boot also saw [462.96, 178.57, 462.96]).

  • Depth 2 note: Unlike J775c (G17C B1), J813 (G17G C0) showed no depth-2 regression — #3389 was faster on every single round at depth 2 for both render.light tri (−8.4%) and compute.light (−10.1%), and scaled to −13.6% to −21.3% across depths 4–16.

Checked Outputs, Health & Stock Return

  • Output checks (both arms): compute.chain (crc=8cec83c8, expected 8cec83c8, valid=true), render.postfx (crc=4707efa8, expected 4707efa8, valid=true).
  • Kernel & systemd health (both arms): 0 GPU fault lines, 0 kernel warnings/BUGs/SErrors, 0 failed systemd units. (queue.exhaust / #3645 and broader stress were intentionally excluded per request.)
  • Stock return: Removed /mnt/esp/aurora/boot-ab/, /mnt/esp/aura-try, and temporary module dirs; verified clean reboot back to stock 7.3.0-aurora-j813-full+ (0 failed units, 15M free on ESP).

@satchlj

satchlj commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Thanks @sithglan, that covers the second M5 board at the exact head. Notably, J813 shows no depth-2 cost: the late-start mode at depth 2 looks specific to J775c's G17C B1. I've added it to the Tested line. @erikwb, the remaining gate is your re-review: the depth-2 cost you asked about turns out to be J775c-only, and every other depth on both boards improves (J813 −8% to −21%).

@github-actions github-actions Bot removed the needs-hw-row No hardware row at the PR head (bot) label Nov 29, 2026
@satchlj

satchlj commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

J775c (M5 Max, G17C B1) at exact head ad4234d03725, one-shot trial boot, default command line (plus the standing arm64.nomte). Health: 0 failed units, 0 GPU fault lines, HDMI 2560x1440, Ethernet, Wi-Fi and Thunderbolt up. The reboot out returned to the default unaided.

Same session, same rows, against the J775c default kernel (main 88ddea8b, monolithic, same config family). One run each, Mesa 724e94ec:

row default #3389 head
render.light tri d1 130.14 µs 130.21 µs
render.light tri d8 23.39 µs 19.84 µs (−15%)
compute.heavy bw d1 / d4 / d8 345 / 780 / 809 GB/s 345 / 697 / 872 GB/s
compute.heavy alu d4 15.83 TFLOP/s 15.84 TFLOP/s
Llama-2-7B Q4_0 pp512 / tg128 3,085 / 104.9 tok/s 3,108 / 111.6 tok/s

The render d8 result matches the earlier J775c rows (19.7 µs). The bandwidth d4/d8 swings and the tg128 difference are single runs on different bases (the default is the Nov 27 main), so they aren't attributed to this PR.

@erikwb

erikwb commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

J716c (MacBook Pro 16" M5 Max, G17C B1) at ad4234d03725: render.light tri at depth 2 is about twice as slow as main (110.5 vs 53.6 µs), and compute.light at depth 4 picks up a slow mode (37.0 vs 23.9 µs). Render at depths 4–16 is 10–12% faster. Stress results match main, with no GPU faults.

Kernels: A = main dbfbced70b31. B = the same commit with this PR's head merged in, because the head predates #3662, which the J716c needs to boot. Same config for both. One-shot trial boots in A, B, A order. Borealis Mesa 26.3.0-devel (the same build in both arms), GPU firmware 27.2, on AC, desktop running, gpubench 868b064.

µs per submit: median of all runs, range in brackets. Depths 1–8: n = 15 per arm (one full core-a pass plus two repeats on each boot). Depths 16–64: n = 5.

Test Depth main this PR Change
render.light tri 1 201.8 190.7 −5.5%
2 53.6 (40.0–89.3) 110.5 (105.8–112.7) +106%
4 32.7 29.1 −11.0%
8 28.2 25.0 −11.5%
16 28.2 25.5 −9.6%
32 27.5 25.5 −7.3%
64 27.6 26.1 −5.2%
compute.light 1 174.1 173.4 −0.4%
2 94.1 90.5 −3.9%
4 23.9 (22.5–26.9) 37.0 (20.8–49.3) +55%
8 18.0 17.1 −5.3%
16 17.0 17.2 +1.2%
32 16.8 17.0 +1.2%
64 16.5 17.2 +4.2%

Main's depth-2 render is bimodal: 40–89 µs across runs and both boots. Every run with this PR is 106–113 µs, slower than every main run. With this PR, compute at depth 4 switches between about 21 and 49 µs, where main stays at 22.5–26.9.

gpubench-stress-vk --kernel-log: both arms 15 passed, 1 failed, 1 skipped. The failure is queue.exhaust, identical on main (#3645); the skip is rq.stress (no ray query). No GPU fault lines in the kernel log on either arm. The same two units fail on both arms, neither GPU-related (aurora-peripherals, systemd-networkd-wait-online).

@erikwb erikwb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: FINISH, then merge at ad4234d03725

Blockers:

  1. On the J716c (M5 Max, G17C B1), the cached work nodes slow render.light tri at depth 2 from 53.6 to 110.5 µs (+106%), and every run with this PR is slower than every main run. compute.light at depth 4 also falls into a ~49 µs mode (median 37.0 vs 23.9 µs). The depth-2 cost stated for the J775c (+12% compute, +18% render) is much larger on this G17C Mac, so it can't be taken as a small known cost. Fix the depth-2 slowdown and the depth-4 compute mode, then repeat the A/B on a G17C Mac. J716c row

Checked: My three earlier blockers are fixed. Compute descriptors are back on main's rule (730f85a5). used() now reads the live words or the shared claims before the pin mask (ae0f996a), with an interleaving test. pin() sets its bit before the compare-exchange that frees the word, so the order holds on private and shared contexts. f207315d carries the sign-off. ad4234d0 fixes the build break from the merge. No Apple material, no chip or firmware gates, no new safety values. CI is green at this head. The J813 row at this head shows no depth-2 cost, and the J716c row at this head is linked above.

Evidence
  • J716c A/B: main dbfbced70b31 against the same commit with ad4234d03725 merged in (the head predates #3662, which the J716c needs to boot). Same config, one-shot trial boots A, B, A, same Borealis build. Depths 1–8 have 15 runs per arm.
  • Main's depth-2 render is bimodal (40–89 µs). With this PR it is steady at 106–113 µs. Render at depths 4–16 improves 10–12%. Compute is −5% at depth 8 and +1 to +4% at depths 16–64.
  • gpubench-stress-vk --kernel-log gives the same result on both arms: 15 passed, queue.exhaust fails as on main (#3645), rq.stress skipped. No GPU fault lines on either arm.

@erikwb

erikwb commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

(my agent is currently investigating to see if it can tell where the slowdowns come from)

@satchlj

satchlj commented Nov 30, 2026 •

Copy link
Copy Markdown
Member Author

J775c (M5 Max) A/B: is the depth-2 cost tied to the system level cache? It looks like it is: with the SLC off, J775c shows the render depth-2 cost J716c reports; with it on, that cost is gone.

Two kernels from the same recipe and config, differing in one line: B is main e6c7b032 (+ the display carries) with this PR's Family::WorkState cache line, A is the same without it. B does not carry the PR's other changes (pinning, retain rules), which should not affect timing. Trial boots on the default command line, ABBA in each arm; SLC off = initcall_blacklist=apple_mcc_driver_init (apple-mcc never enables allocation; checked in each boot's log). gpubench --runs 15 --run-ms 300 --timestamps on, median µs per submit of the 15 runs, then the mean of the boots in each arm:

Test Depth SLC on: A (4 boots) SLC on: B (3) SLC off: A (2) SLC off: B (2)
render.light 1 130.2 130.1 203.8 191.6
2 65.1 68.7 64.2 103.2 (+61%)
4 27.9 25.0 (−10%) 33.1 29.4 (−11%)
compute.light 1 124.7 121.9 175.0 173.3
2 65.3 65.2 93.3 89.1
4 19.0 22.1 (+16%) 25.3 21.8
  • Render depth 2: without the line, every boot is bimodal: the 5th percentile of the 15 runs is 40–54 µs and the 95th is 70–90 µs. With the line and the SLC off it stays at the slow mode (p5 89–100, p95 105–106), so the fast mode disappears. With the SLC on, both kernels stay bimodal and the medians are close.
  • GPU time per job is the same in both kernels in every arm (render 6.0–6.5 µs SLC on, 6.9–7.4 off; compute 3.0–3.5). So the cost is in submission or completion around the job, not in its execution, which matches your traces of the firmware starting every other job late.
  • Compute depth 4 with the SLC on, +16%: this is the one row where the line costs more with the SLC on. It does not match the PR's −4.2%, and B's runs vary widely (p95 24–26 µs). Treat it as unconfirmed until a second set of boots repeats it.
  • Logs per boot: render/compute at depths 1, 2, 4, the SLC state, and 0 failed units in every boot. One B boot hung in the boot ROM before Stage 1 and was reset; the hang is before any kernel runs, so it is unrelated to the kernel under test.

Proposal: J716c's +106% looks like the SLC-off case. Could the J716c row's owner check: does J716c's kernel log apple-mcc ...: system level cache allocation enabled? It only appears once display-subsystem binds and the boot scanout retires. If not, J716c measured with the SLC off. In that case the gate is that hardware state, not a board: take the cached WorkState mapping only when apple-mcc has enabled SLC allocation, and keep main's uncached mapping otherwise. A context allocated before that point would keep the uncached mapping, which costs nothing. If J716c does have the SLC on, this table doesn't explain its row and I'll look further.

@RyanTheTide

Copy link
Copy Markdown
Contributor

G17P with firmware-cached work nodes (#3186, on main): does it show the every-other-job late start at depth 2? Measured on our M4 Pro (J616s) and A18 Pro Neo, using the same metric as your J775c analysis: GPU idle before each job from asahi_g17_complete gpu_start(n) - gpu_end(n-1), the share of gaps over 3× the median, and the spacing between long gaps.

Setup: saved 7.3.0-aurora-edge kernel (main, so #3186's cached nodes are live on G17P), installed Mesa, gpubench-vk --warmup-ms 300 --runs 5 --run-ms 400, asahi_g17 publish/complete tracepoints on. Userspace only, no reboot, 0 GPU fault lines.

Mac (SLC log at boot) test jobs gap median / p90 (ticks) gaps > 3× median share of idle long gaps at spacing 2
J616s M4 Pro ("system level cache allocation enabled on 16 planes") render.light d2 59,400 1332 / 1855 0.0% 0% n/a (14 long gaps)
render.light d4 96,500 718 / 1452 0.5% 2% 0%
Neo A18 Pro ("enabled on 4 planes") render.light d2 63,475 970 / 1698 1.4% 5% 60% (917 pairs)
render.light d4 87,448 1241 / 1765 0.0% 0% n/a

compute.heavy d2/d4 on both Macs: jobs overlap (each starts before the previous ends), so there's no idle gap to measure.

So on G17P the late-start tail is essentially absent on the M4 Pro (0.0% at depth 2, versus 10.5–16.9% on cached M5 Bn). On the Neo it's present but small: 1.4% of jobs and 5% of idle. Its spacing-2 bias (60% of pairs) does look like the same every-other-job signature, at about a tenth of M5's size. Both Macs have SLC allocation enabled, which fits the SLC lead: we see the pattern weakest where SLC has the most planes.

Not measured: an uncached G17P arm. That needs a one-line kernel change (map the node page uncached in g17/context.rs) and a one-shot boot per Mac; say if you want it and we'll run it. Traces (per-run trace_*.txt, gpubench JSON, SLC line) on our buildbox store: traces/gpu/20261201-gpu-ungate-g17pnodes.

@github-actions github-actions Bot added the ci-failing A check failed at the PR head (bot) label Dec 1, 2026

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MERGE at ad4234d03725

Converts this App's earlier review at the same head to an approval under the 12-01 merge bar (better than before and doesn't break; block only on a shown failure). No code blocker was found in it. The merge gate (a row on one Mac at this head + fast CI) is tracked by pr-readiness, not held here.

Checked: - Verified the single-line delta 730f85a5..ad4234d0 (drivers/gpu/drm/asahi/g17/context.rs:795): WorkStateLease::deferred_split() now initializes pinned: AtomicBool::new(false), resolving the E0063 missing-field compile error in drivers/gpu/drm/asahi/g17/context.rs.

  • Audited all WorkStateLease struct literals in drivers/gpu/drm/asahi/g17/context.rs (new at line 783 and deferred_split at line 795); both initialize pinned, and Drop checks self.pinned.load(Ordering::Acquire) as intended.
  • Confirmed DCO Signed-off-by is present on ad4234d0 and all prior commits in the PR.

Follow-ups (not blocking): hosted CI; erikwb's open CR (2nd M5 row not required)

@github-actions github-actions Bot added the merge-conflict Conflicts with the base branch (bot) label Dec 1, 2026
@erikwb

erikwb commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

We carry this PR in our J716c (M5 Max, T6050) daily kernel.

Leaving M5 Family::WorkState node pages uncached adds submission overhead on deeper render queues (firmware-cached work nodes improve render throughput at depths 4–16 by 10–12% while hardening slot reuse across stampless render, unstamped drains, kill, and recovery).

Running cleanly in daily desktop and GPU use on J716c with no GPU faults, while we continue investigating the depth-2/depth-4 light microbenchmark regression noted above.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gpu Area from CODEOWNERS (bot) blast:m5 Macs affected, from Merge risk (bot) changes-requested A reviewer requested changes (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) merge-conflict Conflicts with the base branch (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants