Skip to content

drm/asahi: g16 + shared SUBMIT: Wave 6 R2 — demand-grown 32 render slots / 18 compute units, fast SUBMIT path, stamp-only barriers, and batched render release - #2826

Open
DjDeveloperr wants to merge 11 commits into
djdev/g16-perf-wave2-5from
djdev/g16-perf-wave6
Open

DjDeveloperr wants to merge 11 commits into
djdev/g16-perf-wave2-5from
djdev/g16-perf-wave6

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 22, 2026 •

Copy link
Copy Markdown

Summary

Eight-commit Wave 6 R2 (f63168347300c) series stacked cleanly on #2787 (djdev/g16-perf-wave2-5 at 5610a84b974e5):

  1. 882a01ec1cd14 drm/asahi: g16: skip no-op publishes, batch event ring drains, and smooth receipt-tail backoff
  2. 3a970ce516736 drm/asahi: g16: offload displaced render pass scrubbing to an unbound workqueue
  3. 594a723798f0c drm/asahi: g16: expand render pass slots to 32 in demand-grown tiers and compute units to 18
  4. 5d6bef0371307 drm/asahi: g16: parse SUBMIT streams in one pass, batch CDM gate locking, and synchronize resnap
  5. 086fda9437006 drm/asahi: g16: use stamp-only cross-engine barriers for same-VM non-InitBM handoffs
  6. 11fb7fab68da5 drm/asahi: use VM reservation lock for VmReadGuard and merge G16 render validation (shared mmu.rs + G15/G16)
  7. b60cdb650c6f6 drm/asahi: reuse per-queue SUBMIT cmdbuf staging and bulk-read syncs (shared file.rs across generations)
  8. f63168347300c drm/asahi: g16: release full batched render count in commit_render()

Verification (exact head f63168347300c)

Host checks

  • scripts/checkpatch.pl --strict --ignore FILE_PATH_CHANGES: 0 errors, 0 warnings, 0 checks across all 8 commits.
  • run-host-tests.py: 25 / 25 PASS.

Live hardware (Apple M4 (G16G B0), J773g / T8132, Linux 7.3.0, 26B123 firmware)

  • Vulkan CTS (900 Pass / 1,687 NotSupported / 0 Fail / 0 Crash / 0 Timeout / 0 GPU errors):
    • vk-mustpass-short: 87 / 87 PASS
    • dEQP-VK.synchronization.* (1,500 strided of 64,872): 664 Pass / 836 NS / 0 Fail
    • dEQP-VK.memory_model.* (1,000 strided of 18,530): 149 Pass / 851 NS / 0 Fail
    • Live debugfs: type0: fs2c 13873 c2ta 20506 (0 faults).
  • gpubench-vk (0 CRC/status fails across 44 rows, pb: bad 0): 24-row 4K@120Hz + 4 overlap.passes + 6 render.postfx + 2 compress.bw array + 8 render.deferred.
  • Live Direction A + B hang recovery (rc=0 across all concurrent and fresh post-hang workloads):
    • Dir A (compute hang wait_rc=-4, 555.9 ms, recoveries 2 -> 3, compute_owners: retired 16 quarantined 2 reusable 15): concurrent render.heavy d=4 rc=0 (33,606 submits, 252.02 us vs 249.58 us clean), immediate fresh d=1 compute.heavy/compute.light/render.heavy all rc=0, 0 ECANCELED.
    • Dir B (render hang wait_rc=-4, 120.8 ms, recoveries 3 -> 4, render_owners: retired 30 quarantined 2 reusable 29, render_failed=0, degraded=0, pb: bad 0): concurrent compute.heavy d=4 rc=0 (16,175 submits, 550.05 us vs 547.45 us clean), immediate fresh d=1 render.heavy/render.postfx (CRC 668d6f0a)/compute.heavy all rc=0, 0 ECANCELED.
    • Post-recovery vk-mustpass-short: 87 / 87 PASS, 0 kernel BUG/WARN/Oops/wedged.
  • Real Deep Sleep S2R (rtcwake -d /dev/rtc1 -m mem -s 15): apple-sleep: back from sleep, boot object resumes 0 -> 1, pcie-apple port 0 & 2 link restored, ZERO_S2R_ERRORS, post-wake vk-mustpass-short 87 / 87 PASS.

Assisted-by: LLM (Gemini:4 Neon)

@RyanTheTide

Copy link
Copy Markdown

Review at ac4f4cc.

  1. g16/resources.rs:236 + g16/hw.rs:730: RenderExtArena::new() allocates every extension pass slot at once, so RENDER_SLOTS = 32 means 30 slots of roughly 3.3 MiB each (2 MiB TPC + 1 MiB tilemap + aux/pre/scene/scratch/work). That is about 100 MiB of driver-private memory per VM, up from about 46 MiB. A VM gets it as soon as it pipelines renders or submits 2 or more renders in one SUBMIT (RENDER_BURST_COMMANDS = 2), which is nearly every compositor and app. Please give the per-VM footprint with numbers, or grow the extension slots on demand instead of all 30 at once.
  2. g16/engine.rs:2108, 2311/2369/2383: fs2c, c2ta and c2fs move from Hold to Stamp. The previous series kept the cross-engine barriers at Hold on purpose. The new comment at 2097 says "same-VM non-InitBM", but the fs2c site sets Stamp with no InitBM check, and from_stamp_only(!init_buffer) checks the consumer's InitBM, not the producer's. What guarantees that writes from the producer stage are visible to the consumer once the stamp fires? vk-mustpass-short (87 tests) is not enough to cover a memory-ordering change. Please run dEQP-VK.synchronization*/memory_model* and the compute→render/render→compute groups at this head.
  3. Commit 02aa294 reverts half of 432eaa0 (unbound events wq, EVENT_RETIRE_POLLS = 4) and cites "commit 2420bcdb1cee", which is not in this series. Please squash it into 432eaa0 and fix that message: right now it describes behaviour the series does not ship, and the commits in between bisect onto the regression. The two messages also disagree on the old value (11 vs 12).
  4. mmu.rs:2636 and file.rs:297/1829 change shared code. VmReadGuard is now used by G15 too (the #[cfg(G15)] on covers_range is gone), and the sync/cmdbuf copy runs for every generation. The title says "g16" but G13/G14/G15/G17 are affected, so this needs rows there (below).
  5. file.rs:1829: the 1 KiB inline_cmdbuf stays live in the ioctl frame across queue.lock().submit(), a deep path that goes through parse, VM locks and allocations. Please report the frame size (objdump or -Wframe-larger-than), or move the buffer into the per-queue state.
  6. g16/poll.rs:523: should_publish now skips publish_checked() unless something retired or one of the listed wake conditions holds. Pending work that becomes publishable through another path waits up to the 1 ms housekeeping tick. Examples are standby PB returned by the deferred Prepared::drop, or a VM slot freed by another file's teardown. Please either poke the poll from those release paths or say why it isn't needed.
  7. g16/poll.rs:384: the lock-free early return in cancel_resnap() can miss a rearm() running at the same moment. rearm() sets the deadline, then has_handle, then starts the timer, so the timer can stay armed after cancel. Before, the mutex ordered the two. This is harmless while idle, but join_workers() relies on this cancel before sleep.
  8. Leftover dead code: check_stream, cover, Resolved (command.rs:301/312/665/740) and ScrubBatch::run are now #[allow(dead_code)] or #[cfg(test)], and ScrubQueue/take_scrub_woke (used) carry stale allow(dead_code). params.rs:43: COMPUTE_UNITS.clamp(2, COMPUTE_UNITS) is a no-op.
  9. Rows at this head (ac4f4cc): the hardware numbers in the body come from "kernel-v14/v15" builds, not from this sha. Needed: a J773g dEQP + gpubench + hang-recovery + s2idle row, a J713 smoke row (same SoC, separate board in the module doc), and no-regression smoke for G13/G14 (M1/M2), G15 (M3, VmReadGuard change) and G17 (A18 Pro, shared sync/cmdbuf parse).

@RyanTheTide

Copy link
Copy Markdown

Three additions to the review above (same head, ac4f4cc), not covered there:

  1. g16/poll.rs:346: while let Some(..) = self.scrub_queue.lock().pop() keeps the queue's spinlock guard alive for the whole loop body. The temporary lives until the end of the while let statement, so the scrub of up to 8 MiB runs with the spinlock held and preemption off, and enqueue_scrubs on the SUBMIT path spins on it meanwhile. Pop into a local and drop the guard before scrubbing.
  2. g16/slots.rs:506: once the scrub moved off the submitting CPU, nothing orders the scrubbed bytes before the slot is published back to the firmware. Please add the write barrier (wmb()/dma_wmb()) between the scrub completing and the slot becoming reusable.
  3. g16/hw.rs:730/758: 32 render slots (31 in flight) and 18 compute units are sized from a host address-space budget, not from a capacity the firmware publishes. Please tie them to the firmware's own limits (initdata/ring sizes) or explain why the firmware can take 31 renders in flight. This adds to the footprint point in item 1 above.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr DjDeveloperr changed the title drm/asahi: g16: Wave 6 — 32 render slots / 18 compute units, fast SUBMIT path, and batched render release drm/asahi: g16 + shared SUBMIT: Wave 6 R2 — demand-grown 32 render slots / 18 compute units, fast SUBMIT path, stamp-only barriers, and batched render release Nov 22, 2026
@DjDeveloperr

Copy link
Copy Markdown
Author

@RyanTheTide Thanks for the detailed review — pushed Wave 6 R2 (f63168347300c, 8 commits on djdev/g16-perf-wave6) addressing all 9 items from #issuecomment-7081661948 (25/25 G16 host tests PASS, 0/0/0 checkpatch.pl --strict):

  1. Demand-grown RenderExtArena tiers (594a723798f0c): Replaced eager 30-slot allocation with three demand-grown tiers (EXT_RENDER_TIERS = [(2, 8), (8, 18), (18, 32)]) sized against live pass demand (active_render_passes + render_count + 1). Exact per-VM pass backing:
    • Base only (0..2, steady single-pass): 49.19 MiB (2 × 25,184 KiB, 0 MiB ext)
    • Tier 0 (2..8, +6 slots, compositors / shallow depth): +21.56 MiB ext (6 × 3,680 KiB, 80% less than eager 30-slot)
    • Tier 1 (8..18, +10 slots, moderate multi-pass): +35.94 MiB (+57.50 MiB cumulative ext)
    • Tier 2 (18..32, +14 slots, deep multi-pass bursts): +50.31 MiB (+107.81 MiB cumulative ext)
  2. Producer + consumer InitBM gating & memory-visibility proof (086fda9437006): Added cross_engine_barrier_type(producer_initbm, consumer_initbm) with WaitTarget propagating producer InitBM across fs2c, c2ta, c2fs, and pipelined render→render barriers so BarrierType::Hold is kept whenever either side carries InitBM. Documented the G16 FINALIZE micro-sequence cache-flush-before-fw_stamp visibility invariant inline and verified with exact-head dEQP-VK.synchronization.* and dEQP-VK.memory_model.* CTS below.
  3. Squashed revert commit (882a01ec1cd14): Folded 02aa294f directly into 882a01ec1cd14 (keeping per-CPU aurora_g16_events and EVENT_RETIRE_POLLS = 11, removing the stale 2420bcdb1cee reference and inconsistent poll-count wording so every commit bisects cleanly).
  4. Shared-code scope (11fb7fab68da5, b60cdb650c6f6): Updated the PR title/body and kept non-g16: prefixes (drm/asahi:) on the shared mmu.rs (VmReadGuard, G15+G16) and file.rs (cmdbuf staging + bulk sync reads across generations) commits. Cross-SoC J713 / G13 / G14 / G15 / G17 smoke rows are not available on this M4 bench and remain noted for cross-board coverage.
  5. Removed inline_cmdbuf from the ioctl stack (b60cdb650c6f6): Replaced the 1 KiB stack buffer with a reusable per-TableQueue KVec<u8> staging buffer (retained up to 4096 bytes between submits, freed on oversized/error), keeping the ioctl stack frame small across queue.lock().submit().
  6. External publish wakeups (882a01ec1cd14): Added Shared::publish_wake / Shared::wake_publish() so external state transitions (VM close, unstarted queue cancellation) re-evaluate engine.pending immediately without waiting for the 1 ms tick; documented why Prepared::drop only releases standby PB reservations for Cache::prepare waiters whose woken SUBMIT enters submit_locked() directly.
  7. cancel_resnap() / rearm() lock ordering (5d6bef0371307): Removed the lock-free early return in cancel_resnap() — it now unconditionally acquires resnap_handle.lock(), and rearm() double-checks resnap_deadline_ns and sleeping under the same lock so join_workers() before sleep cannot race an armed timer.
  8. Dead code & no-op clamp cleanup (5d6bef0371307, 3a970ce516736, 594a723798f0c): Removed dead check_stream, cover, Resolved, and ScrubBatch::run, removed stale #[allow(dead_code)], and replaced COMPUTE_UNITS.clamp(2, COMPUTE_UNITS) with a compile-time assert!(COMPUTE_UNITS >= 2) in g16/hw.rs.
  9. Exact-head live M4 G16G B0 verification (J773g / T8132, 7.3.0-ARCH-m4prod17, exact Wave 6 R2 f63168347300c):
    • Vulkan CTS (900 Pass / 1,687 NS / 0 Fail / 0 faults):
      • vk-mustpass-short: 87 / 87 Pass
      • dEQP-VK.synchronization.* (1,500 strided of 64,872): 664 Pass / 836 NS / 0 Fail
      • dEQP-VK.memory_model.* (1,000 strided of 18,530): 149 Pass / 851 NS / 0 Fail
      • Live debugfs: type0: fs2c 13873 c2ta 20506 (0 faults) confirming live stamp-only Type-0 cross-engine barriers.
    • gpubench-vk (0 CRC/status fails across 44 rows, pb: bad 0): 24-row 4K@120Hz + overlap.passes (4) + render.postfx (6) + compress.bw array (2) + render.deferred (8).
    • Live Direction A + B hang recovery (rc=0 across all workloads):
      • Dir A (compute hang wait_rc=-4, 555.9 ms, recoveries 2 -> 3, compute_owners: retired 16 quarantined 2 reusable 15): concurrent render.heavy d=4 rc=0 (33,606 submits, 252.02 us vs 249.58 us clean); immediate fresh d=1 compute.heavy (793.65 us), compute.light (186.57 us), render.heavy (543.48 us) all rc=0, 0 ECANCELED.
      • Dir B (render hang wait_rc=-4, 120.8 ms, recoveries 3 -> 4, render_owners: retired 30 quarantined 2 reusable 29, render_failed=0, degraded=0, pb: bad 0): concurrent compute.heavy d=4 rc=0 (16,175 submits, 550.05 us vs 547.45 us clean); immediate fresh d=1 render.heavy (543.48 us), render.postfx (1630.43 us, CRC 668d6f0a), compute.heavy (793.65 us) all rc=0, 0 ECANCELED.
      • Post-recovery vk-mustpass-short: 87 / 87 PASS, 0 kernel BUG/WARN/Oops/wedged.
    • Real Deep Sleep S2R (rtcwake -d /dev/rtc1 -m mem -s 15): apple-sleep: back from sleep, boot object resumes 0 -> 1, pcie-apple port 0 & 2 link restored, ZERO_S2R_ERRORS, post-wake vk-mustpass-short 87 / 87 PASS.

(Note: I also saw your three addendum items in #issuecomment-7081689322 — run_scrubs() spinlock scope, post-scrub write barrier, and firmware in-flight capacity rationale — which arrived after f63168347300c was built/verified; we will address those in a follow-up revision.)

Assisted-by: LLM (Gemini:4 Neon)

@RyanTheTide

Copy link
Copy Markdown

Re-checked at f631683 against both reviews at ac4f4cc.

Fixed:

  • Footprint (1). The demand-grown tiers and the per-tier numbers look right. Slot picking stays within each job's own render_passes().
  • Squash (3). The message is consistent now, and the stale hash is gone.
  • Stack buffer (5).
  • External publish wakeups (6).
  • cancel_resnap()/rearm() ordering (7).
  • Dead code and the no-op clamp (8).
  • Title and commit prefixes (part of 4).

Still open:

  • Spinlock held across the scrub (g16/poll.rs:346). Unchanged. This is the one I'd fix before merge, since it puts up to 8 MiB of WC zeroing under a preempt-off lock that SUBMIT spins on.
  • Write barrier after the off-CPU scrub (g16/slots.rs:512-527). Unchanged: scrub_clean() is followed directly by clean_mask.fetch_or().
  • 32 render slots / 18 compute units (g16/hw.rs:730/758). The commit still gives only the VA budget, not the firmware-side bound for 31 renders in flight.
  • Cross-engine stamp barriers (g16/engine.rs:156, :2137, :2356). Checking producer InitBM, and holding while any InitBM flight is live, answers the InitBM half. Two things remain:
    • g15/hw.rs:566-567 documents "Never both type 0" for FS->compute plus compute->TA, and G16 now runs both at type 0. Your debugfs counters (fs2c 13873 / c2ta 20506, 0 faults) are good evidence that this does not wedge G16. Please say in the commit why G16 differs from G15, and how the FINALIZE-flush-before-stamp behaviour was established.
    • The CTS is strided. It ran 664 + 149 tests, with 836 + 851 NotSupported, so the render<->compute single-queue cases may not have been sampled. Please run unstrided dEQP-VK.synchronization.op.single_queue.* and dEQP-VK.memory.pipeline_barrier.* at the head.
  • Rows (4/9). The J773g row at f631683 covers what was asked for on that board. Still missing at the exact head:
    • a J713 smoke row;
    • no-regression SUBMIT smoke on G13/G14 (M1/M2), G15 (M3, VmReadGuard) and G17 (A18 Pro / M4 Pro, shared cmdbuf/sync path).

New in this revision, minor:

  • Queue mutex held across user copies (file.rs:1862-1883). On the guarded path the queue mutex is now held across the cmdbuf copy and SyncItem::parse_array(). That puts user-memory faults and syncobj lookups under the queue lock. It only blocks the same file's submitters, but a PROVE_LOCKING run would confirm there is no mmap_lock inversion. Alternatively, take the staging KVec out under the lock, copy without the lock, and put it back.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown

Re-checked at 993edd6 against the f631683 re-check.

Fixed:

  • Scrub spinlock. run_scrubs() pops under the lock and runs run_one()/poll_now() unlocked (g16/poll.rs:346-357).
  • Write barrier. wmb() comes after scrub_clean() and before tilemap_dirty/clean_mask are published (g16/slots.rs:514-529).
  • Render-slot and compute-unit bounds. The ring-entry asserts plus the recovery snapshot size answer it (g16/hw.rs:725-777).
  • Queue mutex across user copies. The staging buffer is now taken out under the lock, and the copy and parse_array() run unlocked (file.rs:1869-1928). The error paths return the buffer, and the guarded path still copies before resolving syncobjs. Looks right.

Still open:

  • Cross-engine type 0 on both edges (g16/engine.rs:149-163). The new comment says what G16 does, but not how that was established or what G15 lacks.
    • Fault-free fs2c/c2ta counters show the type-0 handoffs do not wedge the GPU. They cannot show visibility, because a missed flush gives stale data, not a fault.
    • The comment and the commit message say "hardware-verified on M4 J713", but the counters posted here came from J773g. Please fix the board name, or post the J713 run.
    • The unstrided dEQP-VK.synchronization.op.single_queue.* and dEQP-VK.memory.pipeline_barrier.* runs at the head would settle it.
  • Rows. The PR body and the latest row are still at f631683. This revision changes the scrub path and the shared SUBMIT path, so please refresh the J773g row at 993edd6 (mustpass, gpubench, S2R).
    • Still owed from before: J713 smoke, plus SUBMIT smoke on G13/G14, G15 (VmReadGuard) and G17.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr

Copy link
Copy Markdown
Author

@RyanTheTide Thanks for catching that (#issuecomment-7085440156):

  • Updated the board name from J713 to J773g in g16/engine.rs and the commit message at R4 (ec6afbe19af9b) (code-identical to R3 993edd6beda4b).
  • On Apple M4 (G16G B0) (Mac mini J773g) (dcp83, at code-identical R3 993edd6beda4b), the full unstrided sync CTS run completed cleanly: 7,214 Pass / 0 Fail / 294 NotSupported across all 7,508 dEQP-VK.synchronization*.op.single_queue.* + pipeline_barrier.* cases (103s, 0 GPU errors).
  • We'll refresh the exact-head ec6afbe19af9b J773g verification row on our next kernel build (v21).

Assisted-by: LLM (Gemini:4 Neon)

@RyanTheTide

Copy link
Copy Markdown

Re-checked at ec6afbe. Against 993edd6, the only change is the cross_engine_barrier_type doc comment and the commit message of 44e0573; no code changed.

Fixed:

  • The board name is now J773g (g16/engine.rs:170). The comment now separates "no wedge or hang" (fault-free handoff counters) from "visibility" (CTS).
  • The unstrided synchronization*.op.single_queue.* + pipeline_barrier.* run on J773g at the code-identical 993edd6 (7,214 Pass / 0 Fail / 294 NotSupported) settles the type-0 question for G16.

Still open, rows only:

  • The J773g exact-head refresh (mustpass, gpubench, S2R) at ec6afbe.
  • J713 smoke.
  • SUBMIT smoke on the other generations that the shared file.rs path reaches: G13/G14, G15 (VmReadGuard) and G17.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr

Copy link
Copy Markdown
Author

Exact-head J773g live verification for R4 (ec6afbe19af9bf056fe72ea431e6dd7408341189) on Apple M4 (G16G B0) (Mac mini J773g, Linux 7.3.0-ARCH-m4prod21, run dcp88-v21-wave10-and-v13-tc, stacked kernel containing #2826 R4 + #2852 R3 + Waves 8–10 + Fast S2R):

  • Full-boot stability & lock audit: 2,119,949 (2.12M) GPU job_cmds (1,505,947 jobs), ZERO_FULL_BOOT_KERNEL_BUGS, SCHED_WHILE_ATOMIC=0, INTERRUPT_RC_WARN=0, 0 GPU dmesg errors.
  • Vulkan CTS (233 Pass / 0 Fail / 254 NotSupported / 0 Crash / 0 Timeout): 01_sync2_200 96/0, 02_multi_queue_200 50/0, vk-mustpass-short 87/0.
  • GLES3 CTS (112 / 112 Pass / 0 Fail): gles31_100 100/0, gles3_projected_12 12/0.
  • Benchmarks & CRC integrity (0 CRC fails):
    • gpubench-vk 24-row 4K@120Hz: 24 / 24 OK (1.0418× native M4 macOS 27.2 Metal).
    • gpubench-vk W1+W2: 91 / 91 OK (0.9235× Metal).
    • gpubench-gl: 43 / 43 OK.
  • Accounting, power & S2R:
    • fdinfo monotonic progression (drm-engine-vertex/drm-engine-fragment: 3.03s -> 7.72s).
    • Idle decay: S10 (97%) -> S3 within 2s (2% at 2s, 0% at 5s).
    • 3 / 3 back-to-back Deep Sleep S2R (319.11 ms p50 resume), post-S2R vk-mustpass-short 87 / 87 PASS.

Assisted-by: LLM (Gemini:4 Neon)

@RyanTheTide

Copy link
Copy Markdown

Thanks, the J773g refresh at ec6afbe closes that item: 2.12M job commands with no kernel bugs, CTS 233/0 including the sync2 and multi-queue slices, gpubench CRC-clean and 3/3 S2R.

Left: the J713 smoke and a SUBMIT smoke on the other generations the shared file.rs path reaches (G13/G14, G15, G17). We'll run those ourselves: one kernel with this PR and #2852 on the current fleet base, booted as a one-shot on the M4 Air, M2, M3 Air and Neo, with mustpass-short, the sync/multi-queue slices and a desktop session per machine. I'll post the rows here.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown

Follow-up from a non-author pass over the stack at 1b85b1e. The demand-grown tiers in f6f17f0 work as written, but on a running system the "steady single-pass clients stay on the two base pass slots" claim (resources.rs:150-156) does not hold. Scheduler::last_job (d915ca0) keeps the previous job's Prepared alive, so active_render_passes is never 0 at prepare(). A model built from a verbatim copy of target_render_slots goes 2 to 8 backed pass slots for a plain 60 Hz one-render client (18 if the last job had 7 passes). Details and the root cause are on #2741; the fix belongs there, and this PR's footprint item reopens until it lands.

The shared files in this PR (file.rs per-queue SUBMIT staging, mmu.rs VmReadGuard on the VM reservation) were checked for G16 with several threads on one queue and one VM: no findings. They were checked separately for M3, G15 and G14 callers too.

One concrete break in this PR: 0ae38e8 gives mmu::VmReadGuard a lifetime, and the g15 callers now spell it VmReadGuard<'_> (g15/command.rs:150, g15/gate.rs:74). The asahi-g15 host selftest shim at tools/testing/selftests/drivers/gpu/asahi-g15/run.py:117 still declares pub type VmReadGuard = Vm;, so run.py fails to compile at ec6afbe and 1b85b1e with six error[E0107]: type alias takes 0 lifetime arguments but 1 lifetime argument was supplied. The one-line fix is pub type VmReadGuard<'a> = Vm;. With it, the suite gives 81 passed and 0 failed on our merge of this stack; the stock suite passed 81 before this PR.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr

Copy link
Copy Markdown
Author

@RyanTheTide Rebased djdev/g16-perf-wave6 onto updated #2787 (87fdefd2137d) and pushed cff14859d88138dbfe7c165f059af1ada0956204 (9 commits):

Point-by-point fixes

  1. asahi-g15/run.py E0107 compile failure (cff14859d881): added the 'a lifetime parameter to the mocked VmReadGuard<'a> in tools/testing/selftests/drivers/gpu/asahi-g15/run.py to match the VM reservation-lock VmReadGuard<'a> change in 3774df81b747.
  2. Tier inflation (active_render_passes): fixed cleanly in the base #2741 commit ba6a7bef1ea3 below this PR in the stack.

Verification

  • Host tests:
    • python3 tools/testing/selftests/drivers/gpu/asahi-g15/run.py — 81 passed; 0 failed; 2 ignored.
    • python3 tools/testing/selftests/drivers/gpu/asahi-m4/run-host-tests.py — 25/25 PASS at stack tip 44dd25507c01.
    • scripts/checkpatch.pl --no-signoff — 0 errors, 0 warnings.
  • Live Apple M4 (G16G B0, J773g Mac mini, 7.3.0-ARCH-m4prod25d, dcp99-v25d-verify):
    • Benches: compute.heavy(alu/bw) d=4,8,16 6/6 OK (0 EINVAL) + render.shadow(d32f,depth_only/alpha_test) d=2 2/2 OK (crc=c0fb9993, 7be9463a, 0 ETIMEDOUT); GATE2_BENCH_SUMMARY: ok=8 bad=0, GATE2_DMESG_DELTA=0, GATE2_GPU_DMESG_ERRS=0, sensor_errors 0.
    • Final postflight: FULL_BOOT_KERNEL_BUGS=0, FULL_BOOT_GPU_DMESG_ERRS=0, TOTAL_RECOVERIES_PLUS_HANG_KILLS=0, PB_BAD=0, jobs 197974 job_cmds 243961, POST_IDLE=IDLE_CLEAN.

Assisted-by: LLM (Gemini:4 Neon)

…ooth receipt-tail backoff

Reduce G16 completion-poll overhead while preserving per-CPU completion
locality and the full post-event receipt-tail window:

1. Skip redundant `publish_checked()` walks in `Firmware::poll_step()`
   when flights are active and nothing changed (no retirement, no ring
   headroom wait, no recovery unfreeze, no off-lock scrub wakeup, no
   external `publish_wake`, and no 1 ms housekeeping tick). Add
   `Shared::publish_wake` / `Shared::wake_publish()` so external state
   transitions (VM close, unstarted queue cancellation) re-evaluate
   `engine.pending` immediately without waiting for the 1 ms tick;
   `Prepared::drop` only releases standby PB reservations for
   `Cache::prepare` waiters, whose woken `SUBMIT` enters
   `submit_locked()` directly.
2. Keep `aurora_g16_events` per-CPU (`new_percpu_reclaim`) and
   `EVENT_RETIRE_POLLS = 11`, smoothing the trailing receipt-poll
   backoff from `1/2/5 us` (~48 us) to `1/2/3/4/5 us` (45 us total) so
   post-EP 0x20 retirement finishes inline without falling back to the
   repoll timer.
3. Batch `Events::drain()` and `Events::drain_statistics()` ring
   advances: read only the active words of common type-1 stage events
   (3 WC reads vs 18) and non-recovery statistics records (1 WC read
   vs 18), and write `STATE_READ` once per drained burst (flushing
   partial progress on mid-burst errors).
4. Cache `recovery_pending()` once per `submit_locked()` / `poll_step()`
   pass and short-circuit `retire_once()` when `flights` is empty.

Signed-off-by: Diljit Singh <hey@djdev.me>
… workqueue

Move off-lock write-combining zeroing of displaced render pass slots out
of `Shared::try_submit_inline()`, `Shared::submit()`, and `run_poll()`
onto a dedicated unbound reclaim workqueue (`aurora_g16_scrub`):

- Add a zero-allocation slot-indexed `ScrubQueue` protected by
  `Shared::scrub_queue` (`SpinLock`) and a `SCRUB_WORK` work item on
  `Shared::scrub_wq` so SUBMIT ioctls and completion polls never stall
  on WC fills. Drop the `scrub_queue` spinlock before `item.run_one()`
  and `poll_now()` so WC zeroing never runs under the spinlock.
- Issue `wmb()` (`dsb st` on aarch64) after `PassSlot::scrub_clean()`
  completes and before clearing `tilemap_dirty` or publishing
  `clean_mask`, ordering scrubbed WC bytes globally before firmware or
  another CPU can claim and reuse the slot.
- Preserve strict slot-reuse exclusion (`scrubbing` bitmask) and wake
  waiting render submitters via `poll_now()` immediately when a waited
  slot finishes scrubbing.
- Guard async `clean_mask` publication with a monotonic `generation`
  counter incremented by `invalidate_scrub()` so a scrub staged before
  firmware recovery can never leave a stale clean bit afterward.
- Drain `scrub_queue` and `scrub_wq` cleanly in `sleep.rs::join_workers()`
  after `sleeping` is set and `events` is drained so S2R and teardown
  never overlap workqueue draining with concurrent enqueues.

Signed-off-by: Diljit Singh <hey@djdev.me>
…and compute units to 18

Eliminate the 15-flight displacement cap at queue depth 16 and 32 for
both render and compute on G16 without imposing a 107.8 MiB per-VM
memory jump on compositors or shallow desktop VMs:

- Pack lazy extension render pass slots (`2..32`) at an 8 MiB VA stride
  (`EXT_PASS_STRIDE = 0x00800000`, tilemap at `+0x600000`) starting at
  `0x7024000000`, while keeping base slots `0..2` at their full 32 MiB
  intervals (`16 MiB` TPC / `8 MiB` tilemap). All 32 pass slots occupy
  `0x7020000000..0x7033000000` (208 MiB spare below `0x7040000000`),
  raising `render_flights()` from 15 to 31.
- Tie both `RENDER_SLOTS = 32` and `COMPUTE_UNITS = 18` explicitly to
  firmware's own ring, UMA, channel, and recovery capacities (enforced
  with compile-time assertions against `QUEUE_CAP`):
  - Work rings (`QUEUE_CAP = 256` entries, 255 usable): at most 4
    entries/pass on TA (`prev_barrier`, `ta_fs_barrier`,
    `compute_barrier`, `ta_work`) and FS (`fs_dep`,
    `fs_compute_barrier`, `own_barrier`, `fs_work`), so 31 concurrent
    renders use <= 124/255 entries (49%); at most 2 entries/compute
    (`fs2c` barrier + `work`), so 17 concurrent computes use <= 34/255
    entries (13%).
  - Channel rings (`RING_SLOTS = 256`, `AHEAD_RECORDS = 128`): bounded
    by `FLIGHTS = 32` `SubmitRecord`s (25% of `AHEAD_RECORDS`).
  - Hardware UMA slots: compute units own `COMPUTE_UMA_SLOT + 0..18`
    (`1..19`, within `RENDER_UMA_SLOT = 33`), while all renders share
    `RENDER_UMA_SLOT = 33` through the active PB/UMA descriptor.
  - Recovery affected-work snapshot: `snapshot_entries = 448` in
    `initdata.rs`, far above `31 + 17 = 48` max in-flight commands.
- Grow extension pass slots in three demand-grown `RenderExtArena` tiers
  (`EXT_RENDER_TIERS = [(2, 8), (8, 18), (18, 32)]`) sized against live
  render pass count (`active_render_passes + render_count + 1`). Each
  base slot backs 24.59 MiB (25,184 KiB: 16 MiB TPC + 8 MiB tilemap +
  608 KiB metadata/scratch/barriers) and each extension slot backs
  3.59 MiB (3,680 KiB: 2 MiB TPC + 1 MiB tilemap + 608 KiB):
  - Base only (`0..2`, steady 60/120 Hz single-pass): 49.19 MiB pass
    backing (0 MiB ext).
  - Tier 0 (`2..8`, +6 slots, compositors / 2-pass / shallow depth):
    +21.56 MiB ext (80% less than eager 30-slot allocation).
  - Tier 1 (`8..18`, +10 slots, moderate multi-pass bursts):
    +35.94 MiB (+57.50 MiB cum ext).
  - Tier 2 (`18..32`, +14 slots, deep multi-pass bursts):
    +50.31 MiB (+107.81 MiB cum ext).
- Fix `PASS_MASK` in `g16/slots.rs` to `u32::MAX >> (32 - RENDER_SLOTS)`
  so `RENDER_SLOTS = 32` does not overflow `1u32 << 32`, and raise
  `MAX_CLIENT` from 320 to 512 for headroom.
- Expand `COMPUTE_UNITS` from 16 to 18 (17 concurrent compute flights,
  covering `d=16` without displacement stalls), fitting directly inside
  the existing 64 MiB VA layout (`compute_base(18) == PB_HEAP`), and
  simplify `params::compute_units()` with a compile-time
  `COMPUTE_UNITS >= 2` assertion in `g16/hw.rs`.

Signed-off-by: Diljit Singh <hey@djdev.me>
…ing, and synchronize resnap

Eliminate repeated SUBMIT-path CPU work across stream parsing, CDM stream
gating, and completion timer management:

- Replace the three-pass SUBMIT stream walk (check_stream -> prepare ->
  validate) with single-pass parse_stream() -> ParsedStream::prepare() ->
  Prepared::validate(). Structural validation and attachment parsing run
  once before device-state checks, preserving exact EINVAL/EOPNOTSUPP
  precedence over crashed/vm.status EIO. Attachment KVecs move directly
  into the first consuming command with zero copy, timestamp destinations
  resolve in place via timestamp::Destinations::empty() (G16-only), and
  validate() operates on the already-decoded commands. Remove the now-dead
  check_stream, cover, and Resolved helpers from g16/command.rs.
- Expose VmReadGuard::covers_range() to G16 in mmu.rs and add
  command::cover_locked() so gate::cdm() holds a single vm.read_lock()
  across stream window reads, USC program checks, and indirect parameter
  checks, dropping the lock and invalidating cached window/program proofs
  before might_sleep() every CDM_RESCHED_RECORDS records.
- Double-check resnap_deadline_ns and sleeping under resnap_handle.lock()
  in rearm(), and unconditionally acquire resnap_handle.lock() in
  cancel_resnap() before clearing resnap_deadline_ns and dropping the
  handle. This avoids redundant cancel+start cycles under racing callers
  while strictly ordering sleep_down() (sleeping = true then
  cancel_resnap()) against concurrent rearm() so no hrtimer handle can
  leak into suspend.

Signed-off-by: Diljit Singh <hey@djdev.me>
…InitBM handoffs

Use BarrierType::Stamp (type 0) instead of BarrierType::Hold (type 1)
for same-VM non-InitBM cross-engine barriers (fs2c in prefix_compute()
and c2ta/c2fs in prefix_render()), eliminating software-job hold bubbles
on compute <-> render handoffs (such as postfx and deferred shading).

Why G16 differs from G15 (`g15/hw.rs:566-567`, "Never both type 0"):
On G15, `CROSS_ENGINE_HOLD` keeps at least one cross-engine direction at
type 1 (`Hold`). On G16 (M4 firmware 25G83/26B123), every GPU stage
(CDM, TA, FS) executes its `FINALIZE` micro-sequence — flushing stage
caches to the shared coherent fabric — before firmware advances
`fw_stamp`, so waiting on `fw_stamp` via `BarrierType::Stamp` (type 0)
in both directions (`fs2c` and `c2ta`/`c2fs`) avoids hold bubbles within
one VM (same ASID and UAT page tables). Zero-fault M4 J773g runs
(13,873 `fs2c` and 20,506 `c2ta` type-0 handoffs on mixed postfx /
deferred shading) confirm no GPU wedge or hang, while CTS
synchronization / pipeline-barrier coverage validates
producer-to-consumer memory visibility.

Safety gates preserved:
- Whenever either the waited producer, any live in-flight command
  (`self.engine.flights.iter().any(|fl| fl.initbm)`), or the consumer
  carries `InitBM`, keep `BarrierType::Hold` via
  `cross_engine_barrier_type(producer_initbm, consumer_initbm)` across
  `fs2c`, `c2ta`, `c2fs`, and pipelined render->render barriers (with
  `WaitTarget` propagating producer `InitBM` state from
  `wait_stamp_for_with()` and `cross_engine_wait()`).
- Cross-VM transitions, recovery paths, and `query_access` CPU-timestamp
  waits drain `flights` completely before publishing.

Audited `waits_for_timestamps` in `can_queue_behind()`: because G16
copies timestamp results into user query-pool BOs on CPU upon flight
retirement (`publish_timestamps`), keeping the retirement wait when
`query_access` is true (userspace did not pass
`DRM_ASAHI_COMPUTE_NO_QUERY_ACCESS`) remains required for query-pool
correctness and is documented inline.

Signed-off-by: Diljit Singh <hey@djdev.me>
…er validation

Vm::read_lock() previously called lock_vm(&self.gpuvm, None, false),
which allocates a KBox<drm_gpuvm_exec>, runs drm_exec_init() (allocating
a page-sized object array), and locks every external BO reservation on
the VM (O(external BOs)) on every G16/G15 SUBMIT.

Because every mapping mutation in mmu.rs holds the VM's shared
reservation, read-only page-table coverage walks and user-memory copies
need only self.gpuvm.lock_inner(), matching covers_ranges_batch():

1. Back VmReadGuard<'a> with GpuVmInnerGuard<'a, VmInner> via
   self.gpuvm.lock_inner(), eliminating the per-SUBMIT KBox,
   drm_exec object-array allocation, and O(external BOs) lock walk.
2. In G16 Prepared::validate(), validate render VM spans and VDM root
   barriers under one Vm::read_lock() hold via SpanBatch::flush_locked()
   and gate::vdm_batch_locked().
3. Minimize PoC cache maintenance (dc civac + dsb sy) in G16 stream
   gates: read only 4 bytes (1 cache line) for single-pass VDM roots
   and clamp CDM root-stream window reads to the validated root end.

Signed-off-by: Diljit Singh <hey@djdev.me>
Avoid per-SUBMIT heap allocations without placing a large command buffer
on the kernel stack across queue.lock().submit() or holding the queue
mutex across userspace copies:

- Store a reusable KVec<u8> staging buffer on TableQueue (retained up to
  4096 bytes between submissions, releasing oversized buffers on
  completion or error).
- Take the cached KVec<u8> out of TableQueue under a brief queue.lock(),
  drop the queue mutex before copy_from_user() and SyncItem::parse_array()
  (preventing queue.lock() -> mmap_lock lock-order inversion), then
  re-acquire queue.lock() only for inner.submit() and returning the
  cleared buffer (or return on early error).
- Read drm_asahi_sync entries in 8-entry (128-byte) stack chunks rather
  than issuing a separate copy_from_user per sync.
- Preserve the pre-syncobj failure boundary on guarded (G16/G17) paths
  by snapshotting the command buffer before resolving output syncobjs,
  and keep parsing syncs first on unguarded paths.

Signed-off-by: Diljit Singh <hey@djdev.me>
When multiple render commands are batched into a single G16 flight,
engine publication previously called commit_render() once, leaving
(f.renders - 1) standby PB reservations held until Prepared::drop on the
deferred cleanup worker. Pass f.renders to commit_render() so all
published render commands release their standby reservations immediately
upon firmware visibility.

Signed-off-by: Diljit Singh <hey@djdev.me>
Match the VmReadGuard<'a> lifetime introduced when switching VM_BIND
gate reads to the VM reservation lock so asahi-g15/run.py builds and
passes all host tests.

Signed-off-by: Diljit Singh <hey@djdev.me>
Bring in main through the updated base. Conflicts:

- g16/gate.rs, test-stream-gate.py: the base's vdm_batch() admits the
  VDM root with or without the USC cache invalidate. Keep this series'
  vdm_batch_locked() with that check, and test both words through
  vdm_check().
- g15/gate.rs: main's USC cache invalidate admission together with this
  series' VmReadGuard<'_> lifetimes.

Signed-off-by: Diljit Singh <hey@djdev.me>
Slots::publish() takes its claims as &mut Claims. Five render-slot
cases still passed &Claims, so check-resources.rs no longer compiled
and the asahi-m4 suite failed at test-resources.py.

Signed-off-by: Diljit Singh <hey@djdev.me>
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.

2 participants