Skip to content

drm/asahi: g16: map the compute notifier records ASC-cached - #3285

Merged
RyanTheTide merged 2 commits into
mainfrom
perf/g16-compute-notifier-cached
Nov 28, 2026
Merged

RyanTheTide merged 2 commits into
mainfrom
perf/g16-compute-notifier-cached

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What: on the M4 (G16G, 26B123 firmware), map the compute notifier records ASC-cached, as macOS does.

The firmware reads and updates a compute queue's notifier record around every finished command. G16 mapped the compute notifier page uncached, so each command paid for about 40 uncached firmware loads and stores.

  • Change:
    • The compute notifier page is now mapped ASC-cached. The host writes it only before the firmware first sees it. The firmware already cleans and invalidates the record itself.
    • The compute service stamp moves from that page to the queue's own uncached user-stamp cell, which the host reads for completions.
    • The compute receipt no longer reads the record's context word. The firmware writes the record back to memory only when it unlinks it, i.e. when the count reaches the threshold. In a steady stream that word is therefore stale for the host.
    • The service stamp alone authenticates the receipt: its target is the pipe's own ordinal, and the firmware stores it only after its last access to the command's work item, microsequence and UMA descriptor.
  • Basis:
    • A hypervisor memory dump of live Metal compute queues under macOS 26B123 on the J773g shows per-command-buffer notifier records mapped ASC-cached (0x443), with the service stamps in separate uncached cells.
    • The 26B123 firmware's retire path confirms the ordering:
      • the clean+invalidate of the record happens only on unlink;
      • the service stamp is stored only after the firmware's last access to the item.
  • Not changed: render notifier records. A separate PR stacked on this one does that.

Tested: J773g (M4 Mac mini) and J516s (M3 Pro). The current head 32e089fecee2 merges main 9e38a276dcb4 into the tested branch without conflicts. The notifier change remains commit 761bc4168404.

  • Setup:
    • Kernels: main b14959b819cf vs this change, both native warm builds on the J773g. The measured kit is e9873471e1bc; the tested PR commit 761bc4168404 adds only a host selftest fix and has the same drivers/ tree as the kit.
    • Mesa 15c5bb524162, gpubench-vk 13.
    • ABBA across four one-shot boots (main, fix, fix, main), 6 passes per arm. Each value below is the median of the pass medians.
row (µs, lower is better) main fix fix vs main Metal 4 main / Metal fix / Metal
compute.light queue d4 45.89 43.48 +5.5 % 37.31 0.813× 0.858×
compute.light queue d16 28.17 26.44 +6.6 % 23.89 0.848× 0.904×
compute.light queue d32 28.05 26.59 +5.5 % 21.90 0.781× 0.824×
compute.light queue d64 28.58 26.89 +6.3 % 21.46 0.751× 0.798×
compute.light procs d4 48.05 46.73 +2.8 % 39.59 0.824× 0.847×
compute.light procs d16 43.16 40.01 +7.9 % 32.38 0.750× 0.809×
sync.signal queue binary 30.46 28.83 +5.7 % 25.00 0.821× 0.867×
sync.signal queue timeline 30.69 28.93 +6.1 % 25.28 0.824× 0.874×
concurrent.cr interleave d4 66.51 64.74 +2.7 % 57.10 0.859× 0.882×
compute.heavy alu d2 639.66 632.91 +1.1 % 538.79 0.842× 0.851×
render.light tri d16 58.99 58.08 +1.6 % 48.29 0.819× 0.831×
render.mdi 1024 draws d4 129.79 125.31 +3.6 % 86.27 0.665× 0.688×
  • Full gpubench-vk suite (202 rows), one run per arm:
    • Both arms: 202/202 ok, 84/84 CRCs correct.

    • vs Metal 4: main 1.200× geomean (130/202 rows faster), fix 1.198× (129/202). Fix vs main is 0.994×, within single-run noise.

    • Every row that read 5 % or more worse in the single runs was rechecked with 3 interleaved passes per arm:

      row fix vs main on recheck
      render.light clear d1 +7.0 %
      render.light clear d8 −1.8 %
      render.light tri d2 +1.1 %
      mem.image 4096 +4.9 %
      render.postfx 1440p msaa4 d1 +0.3 %
      render.heavy fill d1 +0.5 %
      compile.pso −7 % (CPU shader compile time, not touched by this change)
      compute.light queue d2 −5.0 %, 62.5 → 65.7 µs (see Risk)
    • The query-overhead rows are differences of two ~100 µs numbers. In absolute terms the fix is faster both with and without queries.

  • Vulkan CTS subset, single worker, fix:
    • Scope: synchronization (basic, smoke, timeline, implicit, none_stage, signal_order, cross_instance, single_queue op), compute, command buffers, pipeline barriers and draw. The multi_queue cases are excluded (issue drm/asahi g16: dEQP-VK.synchronization*multi_queue* faults the GPU and fail-stops it on J773g (main 61c7b88a) #3201).
    • Result: 99,000 of the 103,127 listed cases ran within the 600 s cap. 38,840 pass, 60,159 not supported, 1 fail, 0 recoveries.
    • The fail was dEQP-VK.synchronization2.cross_instance.suballocated.write_ssbo_vertex_read_ssbo_vertex.buffer_262144_timeline_semaphore_dma_buf (memory contents mismatch). On recheck it passed 30/30 on both fix and main, and its group passed 10/22 with 0 fail and 12 not supported on both, so it was a one-off.
    • Main ran the same sorted list with a 120 s cap: 11,773 pass, 19,727 not supported, 0 fail.
  • concurrent.cr ×10 on the fix, interleave and queues: 20/20 ok, 0 faults.
  • One s2idle cycle on the fix:
    • Woke after 13 s, suspend success +1, no new kernel errors.
    • The post-wake gpubench smoke passed 7/7 rows with correct CRCs.
  • Faults: 0 GPU faults, 0 recoveries and 0 hangs on all 9 boots.
  • Host: the asahi-m4 host selftests pass, 26/26 files. test-stamp-wrap.py and test-resources.py are updated for the moved stamp and the new page class.

Risk: two-way · Macs on the g16 backend (M4 G16G; M3 G15S and G15G). A plain revert undoes it.

  • Scope: only the compute notifier page's mapping, and where the host reads the compute completion stamp.
  • If the firmware didn't maintain the record: if it didn't clean or invalidate the record the way 26B123 does, compute completions would stall. That shows up as missing stamps and a hang, not wrong results. The CTS and stress runs above cover it.
  • compute.light at depth 2 is about 5 % slower (62.5 → 65.7 µs). It is still 1.20× faster than Metal 4, which is 78.7 µs there.
    • Likely cause: at depth 2 the queue drains after almost every flight, and the firmware then cleans and invalidates the cached record. Deep queues rarely drain.
    • Depths 4 to 64 are 5.5–6.6 % faster.

Not yet:

  • A row on a G15G Mac (M3, T8122). The J516s (M3 Pro, G15S) row is posted on this PR.
  • The render notifier page stays uncached here; caching it is a separate PR stacked on this one.

The firmware reads and updates a compute queue's notifier record around
every finished command: the post-callback inserts the command, bumps its
count and stores its context, and the notifier walk reads the record
again before it stores the command's service stamp. It cleans and
invalidates the record itself. macOS 26B123 maps these records
ASC-cached (seen in a hypervisor dump of a live Metal compute queue on
the J773g) and keeps the service stamps in separate uncached cells. G16
mapped the whole compute notifier page uncached, so every finished
command paid for some 40 uncached firmware accesses.

Map the compute notifier page ASC-cached. The host writes it only
before the firmware first sees it. Move the compute service stamp from
that page to the queue's own uncached user-stamp cell, which the host
reads for completions. Drop the read of the record's context word from
the compute receipt: the firmware writes that word back only when it
unlinks the record, so the host cannot read it reliably, and the
service stamp already authenticates the receipt. Its target is the
pipe's own ordinal, and the firmware stores it only after its last
access to the command's work item, microsequence and UMA descriptor.

Render notifier records are unchanged.

Signed-off-by: DjDeveloperr <[email protected]>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 26, 2026 17:23
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J516s (M3 Pro, G15S) row at 761bc4168404: PASS. One-shot boot of the exact head (main b14959b819cf + this PR, default cmdline, main's own DTB in Stage 2). 0 GPU faults, 0 recoveries or hang kills, no "completion-stamp" lines, 0 failed units, no new kernel errors (only the J516s's per-boot MTP HID line). CTS sync/compute subset in one process, no multi_queue: 467 cases, 374 Pass, 93 NotSupported, 0 Fail. gpubench-vk against main (same aurora-wip 69179743d9ae kit, same Stage 2, 2 passes per kernel, GPU at S8 in 94 % of busy samples): compute.light queue d4 +8.9 %, d16 +12.5 %, d64 +8.4 %, procs d16 +8.6 %; sync.signal queue binary +8.0 %, timeline +8.0 %. concurrent.cr interleave d4 and compute.light queue d2 are unchanged: one head pass sat in the slow mode of these two-mode rows (48.4 vs 42.5 µs), and the other matched main (42.5 vs 42.2–43.2 µs). m3 is back on its baseline.

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Verdict at 761bc4168404: ready

Blockers: none

Checked:

  • Only the compute page changes. ComputeGraphSession::new() allocates the compute notifier page as Class::FwCached (PTE 0x443). The render page, the threshold cells and user_stamp (Class::Shared) keep their classes, and the render receipts in poll.rs still read their stamps and context word from the uncached render page.
  • The host writes the page only before the firmware sees it. init_notifier() and the record's threshold pointer are written in ComputeGraph::init(), called only from init_graphs() at backend start. A failed start leaves the firmware at READY until reboot, so there is no later host write that cached lines could hide. The page lives for the whole firmware session, so there's no free while the firmware could still hold dirty lines.
  • The stamp move is consistent. ComputeRefs.user_stamp (work item +0x800) now names the queue's own uncached cell, and both receipt paths read that cell. The encoder is shared by every g16 firmware layout, so the firmware stores the stamp where the host reads it on 25G83 as well as 26B123.
  • Dropping the context word.
    • Targets are per-pipe ordinals that only increase.
    • stamp_reached(…, tail) keeps its wrap handling on the behind-pipe path, and the exact-match path still needs fw_stamp, the queue ring receipt and the channel receipt first.
    • So a stamp equal to the target identifies this command without the record's context word, which under a cached mapping would be stale anyway.
  • Which chips this reaches: only the g16 backend changes, which serves T8132 (G16G), T6030 (G15S) and T8122 (G15G). G13/G14, the other G15 backends and G17 are untouched.
  • Merged-code rules: no runtime switch and no SoC gate. The mapping class has a stated basis: the macOS 26B123 dump of compute notifier records at 0x443, with the service stamps in separate uncached cells.
  • Post-merge checks, not blocking:
    • G15G (T8122, 26B123): also served by g16 and not yet run.
    • G16G booted with the 25G83 firmware (FW_25G83 is still accepted on T8132): the cached-record basis is the 26B123 retire path only.
    • The J773g (G16G, 26B123) and J516s (G15S) rows already cover the two generations the gate needs. If either of the other two stalled, it would show as missing compute stamps, not wrong results. A note in "Not yet" would keep them on the list.
    • "Not yet" fix: the T6040/T6041 entry can go, because this backend has no configuration for those chips.
Evidence
  • Build at 761bc4168404 with the asahi profile (LLVM, Rust): rust/ and drivers/gpu/drm/asahi/, exit 0. No warning on a changed line (the one in g16/poll.rs is at line 1188, unchanged).
  • run-host-tests.py --only asahi-m4: ok. That covers the updated test-stamp-wrap.py and test-resources.py.
  • g16/hw.rs configurations: t8132 (FW_25G83, FW_26B123), t6030 (26B123), t8122 (26B123). t8122 reaches g16 through crate::g16::claims() in driver.rs.
  • Rows: J773g, an ABBA over four boots (compute.light +5.5 to +7.9 % at depth ≥ 4, −5 % at depth 2) and a CTS subset; J516s (comment above), CTS 374 Pass, 0 Fail, and compute.light / sync.signal +8 to +12.5 %. CI was still queued at this head.

@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Merge readiness at 32e089fe: not ready yet

Check Detail
CI at head ok 20 checks passed
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok in the PR body at 32e089fe
Conflicts ok none
PR text ok Risk: two-way · Macs on the g16 backend (M4 G16G; M3 G15S and G15G). A plain revert undoes it. - Scope: only the compute notifier page's mapping, and where the host reads the compute completion stamp. - If the firmware didn't maintain the record: if it didn't clean or invalidate the record the way 26B123 does, compute completions would stall. That shows up as missing stamps and a hang, not wrong results. The CTS and stress runs above cover it. - compute.light at depth 2 is about 5 % slower (62.5 → 65.7 µs). It is still 1.20× faster than Metal 4, which is 78.7 µs there. - Likely cause: at depth 2 the queue drains after almost every flight, and the firmware then cleans and invalidates the cached record. Deep queues rarely drain. - Depths 4 to 64 are 5.5–6.6 % faster.

Areas: area:gpu

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

@github-actions github-actions Bot added blast:m3 Macs affected, from Merge risk (bot) blast:m4 Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) and removed needs-template PR body lacks Tested or Risk (bot) labels Nov 26, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J516s (MacBook Pro 16" M3 Pro, G15S) row at 32e089fecee2: PASS. One-shot boot of the exact head (this PR with main 9e38a276dcb4 merged), default cmdline, the head's own J516s DTB, 27.2 firmware.

  • GPU health: 0 GPU faults, 0 recoveries or hang kills, no completion-stamp lines, 0 failed units, about 3.47 million jobs. No new kernel errors from the GPU; the only new lines are this Mac's per-boot MTP HID line and a Wi-Fi ring line at 12 s, before any GPU work, also seen on earlier rows.
  • CTS (one process, multi_queue and cross_instance excluded): compute and synchronization subsets (basic, smoke, timeline_semaphore, op, signal_order, implicit, compute), 1,188 cases, 914 Pass, 274 NotSupported, 0 Fail. signal_order.shared_binary_semaphore.write_ssbo_vertex_read_copy_buffer_to_image.buffer_262144_opaque_fd: 20/20 Pass.
  • gpubench-vk (same aurora-wip 69179743d9ae kit as the 761bc4168404 row; compute.light, compute.heavy, sync.signal, concurrent.cr; 2 passes): 78/78 rows ok. Against the 761bc4168404 row, every shared row is within 2.5 %, except three that got faster: compute.light queue d8 20.8 → 19.5 µs, d32 17.3 → 16.6 µs, and sync.signal host d1 103 → 98 µs. compute.heavy alu queue d2 is 350 µs, the same as earlier rows on this Mac. There was no main boot at 9e38a276dcb4 in this window, so this is a no-regression check, not a new speedup.
  • Restored to stock.

@github-actions github-actions Bot removed the ci-failing A check failed at the PR head (bot) label Nov 27, 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 32e089fe

Blockers: none.

Checked:

  • drivers/gpu/drm/asahi/g16/graph.rs, engine.rs, fw/graph.rs, poll.rs: verified only the compute notifier page changes to Class::FwCached (render notifier, thresholds, and user_stamp remain uncached), compute user_stamp moves to g.user_stamp.va (Class::Shared), and poll.rs authenticates compute receipts via g.user_stamp without reading stale cached COMPUTE_CONTEXT.
  • test-resources.py and test-stamp-wrap.py: verified updated resource class and receipt expectations.
  • Verified 22/22 CI green and hardware rows on both J773g (M4 mini: ABBA +5.5..+7.9% compute, 202/202 gpubench 84/84 CRCs, 99k CTS) and J516s (M3 Pro, G15S: exact head 32e089fecee2, 3.47M jobs, 0 faults).
Evidence
  • Diff reviewed at 32e089fe (all 6 files, 189 lines).
  • CI: 22/22 PASS.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merge-train status at 32e089fe (App approval noted; rows: 22/22 CI green; G16 compute notifier ASC-cached; J773g ABBA + J516s PASS). @DjDeveloperr code-owner ping (6-point rule, point 6): merge earliest 17:15 AEDT once full CI is green (I re-ran cancelled jobs) and the second-family row point holds. Revert: git revert -m 1 <merge>.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merging under the 6-point rule (Ryan 09:29, permanent), at 32e089fe. (1) The review App approved at this head. (2) Full CI is green. (3/4) Rows: J773g+J516s. (5) There's no blocking review. (6) Dj was pinged here 61 min ago with no objection. Revert: git revert -m 1 <merge>.

@RyanTheTide
RyanTheTide merged commit 219544e into main Nov 28, 2026
23 of 25 checks passed
@RyanTheTide
RyanTheTide deleted the perf/g16-compute-notifier-cached branch November 28, 2026 06:12
RyanTheTide added a commit that referenced this pull request Nov 29, 2026
Forward-merge main after #3285. Only the asahi-m4 selftests conflicted:
test-resources.py takes main's Registry::release(file, process) and
LiveToken process field in the new test_live_token() helper;
test-stamp-wrap.py keeps the PR's pub manager/fw::graph alias and adds
main's user_stamp cell, and the shared compute UMA test now marks pipe 1
done through user_stamp like the other compute cases on main.

Signed-off-by: Ryan Murray <[email protected]>
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:m3 Macs affected, from Merge risk (bot) blast:m4 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (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.

2 participants