Skip to content

drm/asahi: g16: Wave 7 — barrier elision, timestamp-free render microsequences, and 48 render pass slots - #2852

Open
DjDeveloperr wants to merge 5 commits into
djdev/g16-perf-wave6from
djdev/g16-perf-wave7
Open

DjDeveloperr wants to merge 5 commits into
djdev/g16-perf-wave6from
djdev/g16-perf-wave7

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 22, 2026 •

Copy link
Copy Markdown

Summary

Three-commit G16 (M4 / T8132, 26B123 firmware) Wave 7 series (Revision 3, head 1b85b1e25122e) stacked directly on #2826 (djdev/g16-perf-wave6 R4 at ec6afbe19af9b):

  1. 28ccd5e53a99d drm/asahi: g16: elide redundant independent FS and TA-FS render barriers
    • Resolves exact in-flight render wait stamps (fs_wait_render) in prefix_render() / plan_render_barriers(), preserves TA(N-1)→TA(N) prev_barrier on the shared PB / RENDER_UMA_SLOT epoch whenever plan.ta_fs_wait does not already serialize TA behind prev_fs, emits ta_fs_barrier / fs_dep only when needed and not already dominated, and pre-checks wait_stamp_for_with() in the multi-pass render batch fold loop. Independent multi-pass renders drop fs_dep (from 3 barrier records / 5 ring entries per pass to 2 barrier records / 4 ring entries).
  2. b335109318775 drm/asahi: g16: omit render TA microsequence timestamps and retirement reads when unused
    • Adds compact timestamp-free TA microsequence variants (SEQ_SIZE_NOTS, FINALIZE_NOTS, END_NOTS) keeping WaitForIdle (1) and rebased FINALIZE / has_attachments offsets, tracks full-timestamp emission in Flight::stage_ts_mask, and writes only the active TA microsequence length to WC memory.
    • Retains the paired internal FS start/end timestamp writes (user_pair == 0, 0x380-byte FS microsequence) as a zero-hot-path-cost execution proof so innocent concurrent compact renders still retire Retirement::Full during another client's hang recovery (recovery_suspect), while truly firmware-aborted passes (zeros) retire Retirement::Aborted after the 20 ms grace window.
    • Skips all WC scene timestamp reads on normal !recovery_suspect retirement (0 WC scene reads on the steady-state hot path) and falls back to published_ticks..counter_ticks() converted via CNTFRQ_EL0 (counter_hz(), documented as an upper bound) so DRM fdinfo engine-time counters remain active.
  3. 1b85b1e25122e drm/asahi: g16: raise render pass slots to 48 and tighten slot-wait repoll
    • Raises hw::sizes::RENDER_SLOTS from 32 to 48 (47 in-flight passes + 1 displacement slot) and widens pass bitmasks (pass_busy, pass_mask, clean_mask, scrubbing) in g16/slots.rs from u32 to u64, with params::render_flights() clamped to (QUEUE_CAP - 1) / MAX_RENDER_RING_ENTRIES (63).
    • Splits EXT_RENDER_TIERS in g16/resources.rs into four demand-grown tiers (Base 0..2, Tier 0 2..8, Tier 1 8..18, Tier 2 18..32, Tier 3 32..48) so 20–31 pass workloads do not pay for 48 slots upfront.
    • Adds Engine::slot_wait and Firmware::blocked_on_slot_headroom() so poll_step() arms short_repoll (repoll_us) specifically when pending work blocks on same-VM flight, pass/compute slot, or work-ring headroom.

Verification

Revision 3 (1b85b1e25122e) host gates & build

  • scripts/checkpatch.pl --strict --no-signoff (ec6afbe19af9b..1b85b1e25122e): 0 errors, 0 warnings, 0 checks (0/0/0).
  • run-host-tests.py: 25 / 25 PASS (including check-abi-26b123.rs, test-stamp-wrap.py, test-publication.py, test-poll-retire.py, test-resources.py).
  • drivers/gpu/drm/asahi/ (aurora.o): compile-verified with 0 new warnings.
  • Live hardware run for exact R3 head 1b85b1e25122e on J773g (v21) is queued next (and ready for DJ-GPU-STACK J713).

Prior Revision 2 (71daf4f3f7ea0) live hardware baseline (Apple M4 (G16G B0), J773g / T8132, Linux 7.3.0, /opt/mesa-v10-tc)

Vulkan CTS (1,104 Pass / 233 NotSupported / 0 Fail / 0 Crash / 0 Timeout / 0 GPU errors)

Subset Cases Pass NotSupported Fail
vk-mustpass-short 87 87 0 0
*timestamp* (strided of 1,094) 350 340 10 0
dEQP-VK.query_pool.statistics_query.* (strided of 18,775) 250 250 0 0
dEQP-VK.synchronization.op.single_queue.* (strided of 7,324) 300 291 9 0
dEQP-VK.renderpasses.renderpass2.* (strided of 32,680) 350 136 214 0

gpubench-vk (v18 Wave 7 R2 vs v17 Wave 6 R2 f63168347300c on identical /opt/mesa-v10-tc; 0 CRC/status fails across 44 rows)

  • render.light(kind=tri): d=1 273.82 -> 262.61 us (+4.27%), d=2 209.73 -> 196.08 us (+6.96%), d=4 173.13 -> 157.83 us (+9.70%), d=8 138.27 -> 127.10 us (+8.79%), d=16 132.56 -> 121.48 us (+9.12%).
  • render.postfx (6 rows): +7.91% geomean (1080p msaa=4 d=2 1388.89 -> 1269.04 us +9.44%, 1440p msaa=1/4 d=2 1428.57 -> 1322.75 us +8.00%).
  • compress.bw(kind=array,res=1440p) (2 rows): +8.11% geomean (d=1 +6.67%, d=4 886.52 -> 809.06 us +9.57%).
  • 24-row 4K@120Hz: +1.68% geomean vs v17 (0.8773× M4 Metal).
  • overlap.passes (4 rows): 1.1853× M4 Metal (+0.54% vs v17; render_render d=2 1.38 -> 1.44 +4.24%).
  • render.deferred (8 rows): +1.20% geomean vs v17 (0.7149× M4 Metal).
  • Live debugfs: render_owners: fresh 3 retired 45 quarantined 0 reusable 47 (48 slots), slot_sync 0, ct_sync 0, pass_sync 0, pb: bad 0, type0: fs2c 759 c2ta 7454.

Real Deep Sleep S2R

  • apple-sleep: back from sleep, boot object resumes 0 -> 1, pcie-apple port 0 & 2 link restored, GPU firmware back in 5083 us, ZERO_S2R_ERRORS, post-wake vk-mustpass-short 87 / 87 PASS.

Assisted-by: LLM (Gemini:4 Neon)

@RyanTheTide

Copy link
Copy Markdown

Review at 71daf4f.

Review at 71daf4f (stacked on #2826 at f631683).

  1. g16/poll.rs:1065 + 1091: the TA/FS start/end check (ta_start != 0 && ta_end > ta_start ...) was the only per-pass proof that a render actually ran. recovery_prepare_suspects() (engine.rs:840) keeps unfinished flights of other VMs as suspects "until either its full receipt or its passed-abort proof". If the firmware aborts such a render during recovery, its stamps and queue pointers still pass. Before, the missing timestamps sent it to Retirement::Aborted after 20 ms. Now passes with no stage_ts_mask bit skip that check, so an aborted render retires as Full, i.e. reported as success. Please keep some execution evidence in the compact sequence, or fail suspect flights whose passes have no timestamp evidence, and rerun the render-hang recovery row (Dir A/B) at this head.
  2. g16/poll.rs:1564 / 1072 (stat_retire): the same timestamps feed queue.usage, which is fdinfo drm-engine-vertex/drm-engine-fragment (file.rs:470). With emit_ts false for every render that requests no timestamps (engine.rs:2322), normal apps report 0 ns render time in gputop/nvtop. Please keep fdinfo accounting working, for example from the FS end event time, or keep timestamps at least on the last pass of a flight.
  3. g16/poll.rs:599: short_repoll is now set whenever engine.pending is non-empty and flights are active, not only when pending work waits on slot headroom as the commit message says. Pending work that is blocked for a different reason, such as a cross-VM job (can_queue_behind refuses other VMs), the compute_flights() cap, or PB pool exhaustion, now repolls every 15 us (g16_repoll_us default) for the whole length of the in-flight render. A compositor plus one app hits this on every frame. Please key it on the slot or flight headroom condition that actually blocked the work.
  4. g16/resources.rs:96 + hw.rs:730: with 48 slots, Tier 2 (18..48) is 30 slots, +107 MiB allocated in one step. That is the same eager 30-slot allocation item 1 of the 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 review objected to. The worst case is about 214 MiB of driver-private memory per VM, and nothing in the tier code shrinks it. Please split Tier 2 (for example 18..32 and 32..48) and give the idle and steady footprint numbers.
  5. params.rs:54: render_flights() is no longer capped by FLIGHTS, so up to 47 renders can be in flight. The 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 follow-up question is still open: what firmware-published capacity (initdata or ring sizes) shows the firmware accepts 47 TA/FS works in flight? A host VA budget does not answer that.
  6. engine.rs:2425: the comment justifies removing TA->TA barriers by saying "the TA ring is FIFO". FIFO dispatch does not by itself mean TA(N) starts only after TA(N-1)'s FINALIZE. Before this change, two TAs sharing a PB never overlapped. Please say what orders them, or keep the barrier when both passes share a PB epoch. The cross-queue case looks sound: elision now applies only to same-queue wait_through, and other queues are ordered through signalled syncobjs.
  7. Still open from 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 and made larger by 48 slots: poll.rs:346 while let Some(..) = self.scrub_queue.lock().pop() still holds the spinlock across the scrub, and there is still no write barrier between scrub completion and slot reuse (slots.rs run_one).
  8. Rows at this head: the only sync coverage is synchronization.op.single_queue (300 strided). Needed: dEQP-VK.synchronization.op.multi_queue.*, synchronization2.* and memory_model.* at 71daf4f; a render and compute hang-recovery row (item 1); an fdinfo engine-time check (item 2); idle CPU wakeups or powertop with compositor plus app (item 3); and the J713 smoke row still owed from 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. This PR changes only g16/, but its base still carries the shared mmu.rs/file.rs changes, so the G13/G14/G15/G17 smoke rows owed on 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 stay open.

@RyanTheTide

Copy link
Copy Markdown

Re-checked at abb9cd7 against the 71daf4f review.

Fixed:

  • Suspect flights without timestamps now never retire as Full (g16/poll.rs:1067-1076).
  • The short repoll is keyed on real slot/flight/ring headroom through blocked_on_slot_headroom() (g16/engine.rs:1199-1240, poll.rs:602-606).
  • Tier 2 is split at 32 (g16/resources.rs:96-107).
  • render_flights() is clamped by the work-ring capacity (g16/params.rs:51-64).
  • The TA(N-1)->TA(N) prev_barrier is back whenever TA does not already wait on prev_fs (g16/engine.rs:221, :2507-2519).
  • The scrub lock scope and the wmb are fixed in the base.

New in this revision:

  • Innocent renders now fail on any recovery. recovery_prepare_suspects() (g16/engine.rs:844-866) marks every unfinished flight on every VM as suspect.
  • fdinfo fallback clock (g16/poll.rs:1608-1638). The fallback interval comes from CNTPCT_EL0 (counter_ticks(), engine.rs:63-75), but add_interval converts it with the fixed COMMAND_TIMESTAMP_HZ of 24 MHz (poll.rs:1535). Elsewhere the driver reads CNTFRQ_EL0 for the counter rate (mod.rs:714-719).
    • Please convert with CNTFRQ, or use now_ns() deltas.
    • The window also includes ring queueing and poll latency, and it is charged in full to both vertex and fragment. A short comment saying it is an upper bound would help.
    • A gputop/fdinfo comparison with timestamps on and off at this head would confirm it.
  • PR body. It still lists the 71daf4f commits, says prev_barrier is removed and gives "3 barrier records -> 1". Please update it.

Still open: rows. Nothing is posted at abb9cd7, and all three commits changed. Needed at this head:

  • vk-mustpass-short and gpubench;
  • dEQP-VK.synchronization.op.multi_queue.*, synchronization2.* and memory_model.*;
  • the hang-recovery row above;
  • the fdinfo check;
  • the idle-wakeup check with a compositor plus one app.

The J713 smoke row and the other-generation rows owed on #2826 still apply here.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr

Copy link
Copy Markdown
Author

@RyanTheTide Thanks for the R2 review (#issuecomment-7085440348) — both items are addressed in R3 (1b85b1e25122e), rebased cleanly on #2826 R4 (ec6afbe19af9b):

  1. Compact render execution proof & zero hot-path WC reads (b335109318775): retained the paired internal FS start/end timestamp writes in the compact render FS microsequence (0x380 bytes) so innocent concurrent timestamp-less renders still carry hardware execution proof and retire Full during another client's hang recovery (recovery_suspect), while skipping all WC scene timestamp reads on normal !recovery_suspect retirement (0 WC scene reads on the steady-state hot path).
  2. fdinfo fallback frequency & PR description (b335109318775): switched the fallback GPU-time interval conversion to CNTFRQ_EL0 (counter_hz()) instead of a fixed 24 MHz constant (with an upper-bound comment) and refreshed the PR description for R3.

R3 host & build verification:

  • scripts/checkpatch.pl --strict --no-signoff: 0/0/0
  • run-host-tests.py: 25 / 25 PASS
  • drivers/gpu/drm/asahi/ (aurora.o): builds cleanly with 0 new warnings

Ready for DJ-GPU-STACK J713 and our exact-head J773g hardware run (v21) next.

Assisted-by: LLM (Gemini:4 Neon)

@RyanTheTide

Copy link
Copy Markdown

Re-checked at 1b85b1e against abb9cd7.

Fixed:

  • Recovery proof. FS start/end timestamps are always encoded again, and only TA uses the compact sequence. The recovery-suspect path checks the FS pair (g16/poll.rs:1069-1083), and normal retirement still reads nothing.
    • The scene is rewritten from zeroed scratch on every publish (fill_scene, engine.rs:2486), so the pair cannot carry a previous pass's stamps. An aborted pass still reads zero. Looks right.
  • fdinfo fallback. It now converts with CNTFRQ_EL0 (counter_hz(), g16/poll.rs:1632), and the upper-bound comment is in.
  • PR body is updated.

New, minor:

  • Two clock domains in one accumulator. The host-window ticks (CNTFRQ rate) and firmware stamps (24 MHz) now go through the same add_interval:
    • The raw sums ta_ticks/fs_ticks/cdm_ticks and the lo/hi span (poll.rs:1546, 1662) are still printed as ticks/24 (poll.rs:1895).
    • usage::Lane keeps one raw-tick covered mark per engine (usage.rs:123-142). A queue that mixes timestamped and timestamp-less flights compares marks from both domains. On a 1 GHz counter, that breaks the overlap union and inflates the stats dump.
    • Rescaling the host window once into the 24 MHz domain (ticks * COMMAND_TIMESTAMP_HZ / counter_hz(), overflow-safe) and keeping a single rate would avoid both.

Still open: rows. Nothing live is posted at 1b85b1e, and the only rows are from 71daf4f. Needed at this head:

  • render- and compute-hang recovery with a concurrent timestamp-less render client (rc, ECANCELED count). This is the case the FS proof is for, and so far only host tests cover it.
  • an fdinfo/gputop comparison with timestamps on and off;
  • vk-mustpass-short, gpubench, and synchronization.op.multi_queue.*/synchronization2.*/memory_model.*;
  • J713 smoke.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr

Copy link
Copy Markdown
Author

Exact-head J773g live verification for R3 (1b85b1e25122e9023c4e566bdf6163a9d2339288) on Apple M4 (G16G B0) (Mac mini J773g, Linux 7.3.0-ARCH-m4prod21, run dcp88-v21-wave10-and-v13-tc), specifically verifying the R3 review fixes:

  • Dir A+B Hang Recovery (recovery_suspect innocent concurrent survival):
    • Dir A (compute hang + concurrent render.heavy d=4): DIRA_HANG_RC=0, DIRA_HEALTHY_RENDER_RC=0, POST_DIRA_COMPUTE_D1_RC=0, POST_DIRA_RENDER_D1_RC=0.
    • Dir B (render hang + concurrent compute.heavy d=4): DIRB_HANG_RC=0, DIRB_HEALTHY_COMPUTE_RC=0, POST_DIRB_RENDER_D1_RC=0, POST_DIRB_COMPUTE_D1_RC=0.
    • recovery_receipts: affected_full 0 aborted 2, ZERO_HANG_KERNEL_BUGS, post-hang vk-mustpass-short 87 / 87 PASS.
  • fdinfo CNTFRQ_EL0 fallback accounting: verified monotonic drm-engine-vertex / drm-engine-fragment progression (3,028,258,238 ns -> 7,715,444,488 ns) on compact renders with 0 WC scene timestamp reads on normal !recovery_suspect retirement.
  • Full-boot stability: 2,119,949 (2.12M) job_cmds (1,505,947 jobs), gpubench-vk 24/24 4K@120Hz + 91/91 W1+W2 + gpubench-gl 43/43 (0 CRC fails), VK CTS 233/0, GLES3 CTS 112/0, 3/3 Deep Sleep S2R (319.11 ms p50 resume, post-S2R 87/87 PASS), ZERO_FULL_BOOT_KERNEL_BUGS, SCHED_WHILE_ATOMIC=0, INTERRUPT_RC_WARN=0.

Assisted-by: LLM (Gemini:4 Neon)

@RyanTheTide

Copy link
Copy Markdown

Thanks for the J773g rows at 1b85b1e. They close the recovery item: render and compute hangs with a concurrent healthy client of the other kind all return 0, affected_full 0 aborted 2, and mustpass-short passes 87/87 after the hang. They also close mustpass, gpubench, the sync/multi-queue slices and S2R.

Still open:

  1. The two-clock-domain point from my last comment is unchanged at this head (same SHA). On the M4 the host counter runs at 24 MHz, so mixing host-window ticks and firmware stamps in one accumulator is invisible there. On a 1 GHz counter it breaks the overlap union in usage::Lane and inflates the raw-tick stats. The monotonic fdinfo row on J773g can't show it. Please rescale the host window into the 24 MHz domain once (or keep two accumulators), or say why the mixed case can't happen.
  2. The fdinfo comparison with timestamps on and off (same workload, both totals) is still missing. The row shows monotonic progress only.
  3. The J713 smoke, plus the other generations. We'll run that together with 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 (one stacked kernel, one-shots on the M4 Air, M2, M3 Air and Neo) and post it here.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown

Part of a non-author adversarial pass over the stack at 1b85b1e (lifetime, concurrency, firmware-shared memory, accounting). The J773g rows closed the recovery item for a concurrent healthy client whose commands finish within about a millisecond of resume. The first item below is a remaining case the rows do not reach, and a host repro built from the tree's own harness shows it.

1. An innocent suspect flight that finishes more than 20 ms after recovery started can be retired Aborted on a single unsettled poll (rule from base 24f6733; reachable more often with FLIGHTS 16 in b0b5e93, multi-flight in 3e3eee1, concurrent classes in 612dabb, 47-pass flights here).
recovery_prepare_suspects() (engine.rs:858-885) marks every unfinished flight on every VM recovery_suspect, with recovery_started_ns = now. retired_snapshot_at() then works in three steps:

  • the gate: stage stamp reached and queue/pipe passed (poll.rs:960-974, 1017-1023, 1039-1057), otherwise Pending;
  • full &= over the normal receipts: notifier stamp and context, PB/UMA completion, descriptor counters, the FS timestamps;
  • if not full, recovery_suspect && now - recovery_started_ns >= 20 ms, which returns Aborted with doomed = true (poll.rs:1108-1115).

The 20 ms runs from when the flight was marked, not from when its gate first passed, and one sample is enough. The gate words and the receipts are written at different times: the stage stamp at FINALIZE, the notifier stamp and COMPLETED by the completion handling afterwards. The series documents that tail: d915ca0 "absorb firmware's WC receipt tail", 70c082c "unsettled polls fail fast". There is also no read barrier between the gate loads and the receipt loads; the only rmb() is at poll.rs:943, before both.

So when an innocent flight's own work ends more than 20 ms after the mark, the first poll in the tail window gives Aborted:

  • examples are one long compute or fragment pass, a deep pipelined batch, or a recovery whose phase 2 to 3 takes long;
  • for a non-suspect flight the same sample is Pending, and the next poll retires it Full.

The result is EIO with a sticky VM error for the innocent client, its pass/compute slots and PB slot quarantined until reboot, and one step of the quarantine budget spent. Your Dir A/B rows show affected_full, because the healthy client's commands finish right after resume.

Host evidence: the case is added to the tree's own test-stamp-wrap.py harness, which compiles the production retired_snapshot_at(). A flight marked 25 ms ago, with its stage stamp and queue passed and the notifier stamp still at the previous command, returns Aborted, doomed=true for compute and for render (21/21 pass). The same sample is Pending with recovery_suspect = false and Full once the notifier stamp lands. The open link is firmware write order and window width on hardware.

Fix direction:

  • start the grace when the gate first passes (store a gate_passed_ns on the flight);
  • or require the unsettled state on two polls some tens of microseconds apart, the same tail the trailing polls already absorb;
  • and put an rmb() between the gate and the receipt reads.

A hardware check: Dir A/B with the healthy client's job sized to run more than 20 ms past resume, for example a long compute dispatch or a heavy fragment pass.

2. fdinfo render time for timestamp-less renders multiplies with pipeline depth (b335109).
G16 charges usage::Client directly: QueueState::usage is Arc<usage::Client> (queue.rs:52) and stat_retire does a plain saturating add (poll.rs:1544, usage.rs:69-84). usage::Lane, the overlap union, is used only by g17. Since this PR, a render without user timestamps charges published_ticks..counter_ticks() in full to Vertex and to Fragment, once per flight (poll.rs:1630-1650). Flights of one queue pipeline up to render_flights(), so at steady depth d each engine is charged about d times wall time, and other clients' work ahead on the ring is included. The comment at poll.rs:1628-1629 ("usage::Lane still deduplicates overlapping pipelined flights") does not hold on G16. Fix direction: charge through a per-queue Lane (flights of a queue retire in start order), together with the single-clock rescale.

Correction to our earlier comment here: the two-clock point mentioned an overlap union in usage::Lane. G16 has no Lane, so that half does not apply; the raw-tick stats half still does. The fdinfo comparison with timestamps on and off at depth 2 or more, already asked for, is the row that would show item 2.

Method and evidence
  • Read-only review at 1b85b1e, with findings attributed by blame. Asahi-m4 host suite at the tip: 25/25.
  • Repro script for item 1: repro-suspect-grace.py, a copy of test-stamp-wrap.py plus one case, repro_innocent_suspect_unsettled_poll_after_grace_is_aborted.
  • Output:
render=false: unsettled sample 25 ms after marking -> Ok(Some((0, Aborted))), doomed=true
render=true: unsettled sample 25 ms after marking -> Ok(Some((0, Aborted))), doomed=true
test result: ok. 21 passed; 0 failed
  • On the elision commits (28ccd5e, b335109): no path was found where an unfinished flight retires Full. That relies on firmware forcing stage targets only after the host's phase-2 answer (recovery.rs:438-439). The remaining risk runs the other way: innocent to aborted (item 1).
  • Firmware-shared reads: every object access goes through the bounded FwObject::ptr() (object.rs:114-126), and every firmware-written index the host uses is range-checked first. No kernel memory-safety finding at this boundary.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown

J713 (M4 Air, T8132 G16G, 27.2 GPU firmware) rows at R3 1b85b1e2, plus an M3 (J615) check of the shared files.

Setup: the same Mac, the same rows and the same system Mesa (26.3.0-devel d4ad4a4d) on both arms, with the default fleet cmdline and one-shot boots. Baseline = our fleet82 kernel, which carries the older #2676 head. Test arm = fleet82 + this stack (#2676 -> #2741 -> #2787 -> #2826 -> #2852 at 1b85b1e). It merged with one conflict: mmu.rs VmReadGuard, resolved to your reservation guard plus our M3 UAT_ADOPTION|G16 build gate.

row (J713) fleet82 + #2852 R3
GNOME on GPU yes yes
glmark2 terrain / full (off-screen 1080p) 47 / 1847 134 / 4189
vkmark (headless 1080p) 2471 4574
gpubench light (us/submit) baseline 0.42-0.78x time
gpubench heavy baseline compute ~0.88-1.00x, render fill 1080p 0.64x
Vulkan queues 1 (multi-queue rows skip) 2+ (xq.order/chain/exit pass)
deqp-vk spot 112 P / 11 NS / 0 F 116 P / 7 NS / 0 F
dEQP-GLES3 spot 795/795 795/795
gpubench-stress life.fault pass pass
clients after a firmware recovery all lost (ECANCELED/EIO, g16/job.rs lost device) fine (vkmark 4558, glmark2 5251 after the hang)
stress default set, 120 s 0 P / 12 F / 5 S 14 P / 1 F / 2 S
fw crash / oops 0 / 0 0 / 0 (only the 2 deliberate recoveries, both resumed)

The innocent-client-after-recovery fix works on J713: the baseline loses every later client, R3 keeps them.

Still open:

  1. compute.long fails on both arms. gpubench's calibration ramp sends a legitimate compute dispatch of about 1.5 s. The firmware treats it as a hang and recovers (event [4,0,0,0xf]), and the job gets EIO at g16/job.rs:196. So a long but legitimate compute job is killed on G16. Is that the firmware's own timeout, or one the kernel sets?
  2. fdinfo counts are too high. drm-engine-vertex and drm-engine-fragment show identical values. Each one grows 8.15 s per 5 s of wall time under vkmark (1.63x wall). It looks like render-job time is counted to both engines and overlapping jobs are summed, so busy time exceeds wall time.
  3. Idle power: 9263 -> 10982 mW. This is not attributed to the stack: the Stage 2 changed between the two arms, and each arm has one sample. An interleaved A/B on one Stage 2 is queued.

M3 (J615, T8122 G15G) shared-file check: the M3 runtime runs your mmu.rs/file.rs changes. Same rows on both arms on one Stage 2. The result is neutral: glmark2 47/1713 -> 46/1692, vkmark 1890 -> 1872, gpubench median 0.994x, deqp-vk 112 P / 0 F and GLES3 795/795 on both, and no new faults. The M3 hang row (one faulting client takes the GPU away for every client) is the same on both arms. That is an existing gap on our side: M3 has no resume-after-fault yet. It is not caused by this stack.

Method and raw data
  • Rows (run on the Mac as root, silent, each step under timeout): GNOME on renderD128 with no llvmpipe; idle = 30 s settle + 90 s of 1 Hz SMC system power; glmark2 terrain + full; vkmark; fdinfo = drm-engine deltas of a running vkmark over 5 s; gpubench ae90a40 core-a/core-b/multi; deqp-vk + dEQP-GLES3 spot sets (CTS 1.4.7.x); hang = gpubench-stress life.fault + compute.long, then fresh clients; stress = the default safe set for 120 s; then kernel-log GPU crash/fault counts, SELinux Enforcing, 0 failed units, 0 AVCs.
  • J713 boots: fleet82 edee6c50, fleet82dj e1cdd9ed. J615 boots: fleet82 d3756362, fleet82dj 8be5c9bc. All Macs were restored to the fleet default afterwards.
  • Host tests on the merge: asahi-m4 1/1 and m3 9/9 pass. asahi-g15 hits the E0107 shim issue already reported on 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.
  • Per-row gpubench tables and kernel logs are in our lab store; ask if you want any file.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr

Copy link
Copy Markdown
Author

@RyanTheTide Rebased djdev/g16-perf-wave7 onto updated #2826 (cff14859d881) and pushed 44dd25507c01d4fedfeeea264a7da768fbdafa7c (4 commits), resolving every review and live-gate item:

Point-by-point fixes

  1. Real per-stage firmware timestamps & per-DRM-file fdinfo union (b8e37e68234f + 44dd25507c01):
    • Dropped the TA-timestamp omission commit (b33510931877) completely so real firmware TA/FS/CDM stage timestamps are always emitted and drm-engine-vertex / drm-engine-fragment remain distinct.
    • Added usage::Client::add_union() (sharing union_mark() with Lane::add() while leaving existing Client::add() / Lane::add() semantics unchanged for other backends) and wired G16 QueueState directly to Arc<usage::Client>::add_union() so overlapping pipelined and sibling-queue intervals on the same DRM file union cleanly to <= 100% of wall time while keeping distinct files isolated.
    • Updated Documentation/gpu/asahi-usage-stats.rst and added host unit tests in usage.rs and test-poll-retire.py.
  2. Suspect-abort hardening (b8e37e68234f):
    • Added rmb() between stage/queue gate checks and receipt reads in retired_snapshot_at(), and required two consecutive unsettled polls spanning ABORT_GRACE_NS measured from gate_passed_ns (first gate-passed poll) before aborting a recovery_suspect flight so innocent flights completing >20 ms after recovery cannot falsely abort.
  3. DM2 watchdogs (b8e37e68234f) + MAIN +0x277e = 1 (in base #2676 8f43a11cb715):
    • Calibrated GLOBALS_FIXED 0x9c8 (26B123 0x9cc) 40 -> 750 and 0x9cc (26B123 0x9d0) 50 -> 800, and kept GLOBALS +0x9a4 untouched at stock 0 (with 26B123 USC progress monitoring properly enabled via MAIN +0x277e = 1 in #2676).
  4. Equal-tick 24 MHz timestamp acceptance (44dd25507c01):
    • Accepted end >= start (with start != 0) on 24 MHz (41.67 ns) compute ITS and render TA/FS stage timestamps while continuing to reject zero or reversed intervals, with regression coverage in test-stamp-wrap.py.

Verification

  • Host tests:
    • python3 tools/testing/selftests/drivers/gpu/asahi-m4/run-host-tests.py — 25/25 PASS.
    • python3 tools/testing/selftests/drivers/gpu/asahi-g15/run.py — 81 passed; 0 failed; 2 ignored.
    • scripts/checkpatch.pl --no-signoff — 0 errors, 0 warnings across all updated commits.
  • Live Apple M4 (G16G B0, J773g Mac mini, 7.3.0-ARCH-m4prod25d #31 SMP PREEMPT_DYNAMIC, Mesa /opt/mesa-v18-tc git-6b7b6a3c02, dcp99-v25d-verify):
    • Gate 1 compute.long (15 s w/ live kwin_wayland): COMPUTE_LONG_RC=0, 126/126 iterations/checks, solo_dispatch_ms=1491.1639 (1491.2 ms), longalu.long_dispatches=25, max_long_latency_ms=804.95 ms, COMPUTE_LONG_DMESG_DELTA=0, COMPUTE_LONG_GPU_DMESG_ERRS=0, COMPUTE_LONG_RECOVERIES_PLUS_HANG_KILLS=0.
    • Gate 2 fdinfo (1200.5 ms window):
      • render.deferred d=2: drm-engine-vertex 184.41 ms (15.4%), drm-engine-fragment 1181.02 ms (98.4%), drm-engine-compute 0.0% (distinct vertex != fragment, both <= 100%).
      • compute.heavy d=1: drm-engine-compute 839.43 ms (69.9%).
      • compute.heavy d=4: drm-engine-compute 1184.40 ms (98.7% <= 100%).
    • Gate 2 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.
    • Gate 3 P0 Memory Leak Gate (133,905 GPU jobs + 30 s idle soak): SUnreclaim 75,696 -> 76,592 -> 76,592 kB, MemAvailable 20,513,872 -> 19,680,080 -> 20,503,664 kB, vm_bindings: live 11 handles 9 (0 delta), drm_resident_kib 2,468,208 -> 2,370,288 -> 2,370,288 KiB, pb.bad=0, recoveries=0.
    • Gate 4 Deep Sleep S2R: S2R_CYCLE=1 PASS=True, RESUME_MS=346.3 (TOTAL_MS=346.3 < 350 ms, FW_US=521, ERRS=NONE), post-wake smoke C4_RC=0 SH_RC=0 NVME_DD_RC=0 HDMI=connected end0 UP, sensor_errors 0, recoveries 0.
    • Gate 5 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)

Previously prefix_render() unconditionally emitted a same-ring
FS(N-1)->FS(N) barrier (fs_dep) on every pipelined early render pass,
even when vdm_barrier was NONE or the render dependency had already
retired or been satisfied by TA.

Resolve the exact in-flight render wait stamp (fs_wait_render) in
prefix_render() and plan_render_barriers():
- Keep the TA(N-1)->TA(N) prev_barrier (matching G15) whenever a prior
  render is in flight and plan.ta_fs_wait does not already serialize TA
  behind prev_fs (which dominates prev_ta via own_barrier): consecutive
  pipelined renders share one parameter-buffer / UMA epoch
  (RENDER_UMA_SLOT), so TA(N) must still wait on TA(N-1) before writing
  into the shared PB.
- Emit cross-ring FS->TA (ta_fs_barrier) only when plan.ta_fs_wait
  names an in-flight FS stamp (legacy dependent renders, conservative
  early_tiling=false, or staged TA waits).
- Emit FS->FS (fs_dep) only when plan.fs_render_wait names an
  in-flight FS dependency not already dominated by plan.ta_fs_wait.
- Pre-check wait_stamp_for_with() for o2.wait_through[RENDER] in the
  multi-pass render batch fold loop so prefix_render() never defers
  after claiming a pass slot.

Independent multi-pass renders drop fs_dep (from 3 hardware barrier
records / 5 ring entries per pass to 2 barrier records / 4 ring entries)
while preserving TA->TA serialization on the shared PB epoch, exact
FS->FS coherence on dependent passes, and cross-VM / InitBM boundaries.

Expand test-publication.py to cover independent multi-pass renders,
dependent FRAGMENT_BARRIERS/STAGE_PREFIXES renders (including
TA-dominated waits and older-FS waits), legacy renders,
early_tiling=false, and cross-VM/InitBM boundaries.

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

Deep multi-pass render benchmarks (such as 11-pass render.postfx at
depth 3, 7-pass compress.bw array at depth 5, and 4-pass render.shadow
at depth 8) saturated the 32-slot pass cap (31 active + 1 displacement)
and stalled between passes waiting for the 100 us resnap timer to free
retired pass slots.

- Raise hw::sizes::RENDER_SLOTS from 32 to 48 (47 in-flight passes + 1
  displacement slot) and widen pass_busy/pass_mask/clean_mask/scrubbing
  in g16/slots.rs from u32 to u64. Both TA and FS work rings hold
  QUEUE_CAP = 256 entries (255 usable); at worst-case 4 ring entries per
  pipelined pass (MAX_RENDER_RING_ENTRIES = 4), 47 in-flight passes
  consume at most 188 entries (67 spare), bounded by compile-time
  assertion in hw.rs and clamped in params::render_flights() to
  (QUEUE_CAP - 1) / MAX_RENDER_RING_ENTRIES (63), well within
  AHEAD_RECORDS = 128, RING_SLOTS = 256, FLIGHTS = 32, and firmware
  recovery snapshot_entries = 448.
- Split EXT_RENDER_TIERS in g16/resources.rs into four demand-grown
  tiers so 20-31 pass workloads do not pay for 48 slots upfront (per
  base slot = 25,184 KiB / 24.59 MiB; per ext slot = 3,680 KiB /
  3.59 MiB):
  - Base   (0..2,   2 slots):  50,368 KiB (49.19 MiB), ext       0 KiB
  - Tier 0 (2..8,  +6 ext):   +22,080 KiB (+21.56 MiB), ext  21.56 MiB
  - Tier 1 (8..18, +10 ext):  +36,800 KiB (+35.94 MiB), ext  57.50 MiB
  - Tier 2 (18..32, +14 ext): +51,520 KiB (+50.31 MiB), ext 107.81 MiB
  - Tier 3 (32..48, +16 ext): +58,880 KiB (+57.50 MiB), ext 165.31 MiB
- Add Engine::slot_wait and Firmware::blocked_on_slot_headroom() so
  poll_step() arms short_repoll (repoll_us) when pending work is
  specifically blocked on same-VM flight, pass/compute slot, or
  work-ring headroom, without arming short_repoll for cross-VM drains,
  InitBM/PB-unprimed waits, external sync fences, or CPU timestamp
  waits.

Update host selftests in test-resources.py, test-publication.py, and
test-poll-retire.py to verify 48 pass slots, all four demand-grown tier
boundaries and exact byte footprints, blocked_on_slot_headroom()
filtering, and slot_wait-gated short_repoll behavior.

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

Wrap per-queue fdinfo engine accounting in crate::usage::Lane while
keeping real per-stage firmware TA/FS/CDM timestamps, preventing
pipelined double-counting and vertex==fragment skew.

Add an rmb() between stage/queue gate checks and receipt reads in
retired_snapshot_at(), and require two consecutive unsettled polls
spanning ABORT_GRACE_NS from the first gate-passed poll before aborting
a recovery_suspect flight so innocent flights finishing > 20 ms after
recovery cannot falsely abort.

Raise the firmware DM2 (compute) progress-watchdog thresholds (~4 ms
per tick) in GLOBALS_FIXED: secondary DM2 soft-preempt watchdog 0x9c8
(26B123 0x9cc) from 40 (~0.16 s) to 750 (~3.0 s) and primary DM2
recovery watchdog 0x9cc (26B123 0x9d0) from 50 (~0.20 s) to 800
(~3.2 s) so legitimate long/contended compute dispatches (such as 1.5 s
solo workloads) complete without premature firmware recovery while real
hangs still recover strictly below the 5 s host fail-stop deadline.

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

With sibling kernel queues sharing one DRM file (such as Borealis's
per-VkQueue sibling queues across multiple flights or dual CDM pipes),
usage::Lane only deduplicated intervals per queue, allowing concurrent
sibling queues on the same DRM file to exceed 100% of wall time in
drm-engine-*.

Add Client::add_union() backed by a per-engine atomic watermark on
usage::Client (sharing union_mark() with Lane::add() and preserving
existing Client::add() and Lane::add() semantics for other backends).
Have G16 QueueState hold Arc<usage::Client> directly and charge retired
stages via Client::add_union() so overlapping intervals on the same DRM
file union cleanly to <= 100% of wall time while keeping distinct files
isolated.

Also accept end >= start (with start != 0) on 24 MHz (41.67 ns) compute
ITS and render TA/FS stage timestamps so sub-tick draws or dispatches
retire cleanly instead of remaining pending while still rejecting zero
or reversed intervals.

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

- usage.rs: Client keeps this series' per-file union marks next to the
  base's engine ledger, both sized by main's NUM_ENGINES. add_union()
  still charges through add(), so main's ENGINE_NS busy share counts
  it too.
- test-resources.py: keep this series' 48-slot case (slot 47, 64-bit
  mask), which already publishes its claims mutably.

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