Skip to content

drm/asahi: g16: firmware-cached compute records and work rings, aligned compute retirement reads - #3057

Merged
DjDeveloperr merged 3 commits into
mainfrom
djdev/g16-compute-overlap-persistent-rings
Nov 25, 2026
Merged

DjDeveloperr merged 3 commits into
mainfrom
djdev/g16-compute-overlap-persistent-rings

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What: G16 (M4) compute path, stacked on #3045: per-unit compute records and the compute/render work rings move to device-lifetime firmware-cached mappings, and compute retirement reads its 4-byte-aligned receipt words as aligned 32-bit pairs instead of byte loads.
Tested: Host tests 26/26. M4 Mac mini (J773g, G16G B0, 26B123) A/B on the M4 integration tree with and without these two commits (not this branch): 202 Vulkan rows +1.55 % geomean, long ray-query compute 5/5, 16-process render 3/3.
Risk: two-way · M4 (J773g, J713)
Not yet: a row at the current head; CI, which runs once the base lands and this PR targets main.

Details (original description)

Stacked on #3045 (djdev/g16-scs-compute-isolation).

Two changes to the G16 (M4, J773g) compute path:

  • Firmware-cached compute records and work rings. Every VM's compute unit allocated its own uncached microsequence and barrier pages, and the firmware read each compute command's sequence from the uncached work image. Each hardware compute ledger index is device-global and claimed by one flight at a time, so its microsequence and barrier records now live in device-lifetime Class::FwCoherent mappings (resources::ComputeCmds), shared by every VM's unit of that index. SCS units use the hardware index they are bound to.
    • The two compute and two render work rings, which the host writes and never reads, move to the same kind of never-dropped allocator.
    • Work images stay Class::Shared, so the host's retirement reads of DESCRIPTOR_COMPLETED and the 26B123 work ticks keep reading uncached memory.
    • A clean same-VM submit now writes work[0x720..0x900] instead of the whole body.
  • Aligned compute retirement reads.
    • FwObject::r64() gets a 4-byte-aligned fast path: two 32-bit reads, kept tear-free. DESCRIPTOR_COMPLETED and DESCRIPTOR_COUNTER are 4-byte aligned and used to fall through to the byte loop, 16 byte loads per check.
    • On 26B123, compute ticks are read from the work image first, where that firmware puts them, before the always-zero ITS pair.

A follow-up change that keeps shallow heavy compute on one CDM pipe depends on both this stack and #3047, so it is not part of this PR.

Testing

Host.

  • tools/testing/selftests/drivers/gpu/asahi-m4/run-host-tests.py: 26/26 at this head. test-resources.py pins the shared records, the hardware-index keying of SCS units, and the device-lifetime ownership.
  • scripts/checkpatch.pl --strict: 0 errors, 0 warnings, 0 checks per commit. git diff --check is clean.

Hardware. Mac mini M4 (J773g, G16G B0), macOS 27.2 GPU firmware (26B123), Borealis from the same Mesa build in both arms.

  • The A/B is one tree with and without these changes. That tree is our M4 integration tree, which carries both commits of this PR together with the single-pipe follow-up, drm/asahi: mmu: publish a binding without the VM reservation #2799 and drm/asahi: mmu: cache dcache line size and stream scatterlist page-table maps #3032. So these numbers are for that set, not for this PR alone.

  • Results against the tree without them (202 Vulkan benchmark rows):

    Row Change
    Geomean, all rows +1.55 %
    Geomean, 111 standard rows +2.90 %
    compute.light d4–d64 +3.8 to +6.2 %
    compute.heavy ALU d2 +17 %
    sync.signal cross-queue d2 +5 %
    mem.buffer 1 MiB d1 +25 %
    overlap.passes async_cr d4 −14 %
    overlap.passes comp_comp d2 −10 %
    concurrent.cr heavy ALU + fill d4 −10 %
  • Health:

    • long ray-query compute 5/5 and the 16-process render row 3/3;
    • 2.5 M GPU jobs over the Vulkan suite with 0 GPU faults, 0 recoveries and no new kernel messages.

    SELinux does not apply (Arch Linux ARM), and failed units were not recorded.

Ray-query compute on G16G runs with shader-context scratch (SCS). Each
compute work item sets the compute engine's SCS state in its register
list: a ray-query item enables the SCS window, and every other item
writes it disabled.

The engine pins ray-query compute to pipe 0 and holds it while compute
runs on pipe 1. It still lets another VM's compute, or the same VM's
non-SCS compute, queue behind a ray-query item on pipe 0, and lets a
ray-query item queue behind such compute.

Such an overlapped ray-query dispatch is reported complete before its
results reach memory. With a ray-query process and a long-ALU process
sharing the GPU, 33,091 to 35,419 of 131,072 rays still held the
buffer's fill pattern when the fence signalled, with every Mesa build
tried. Once the ray-query process exited, the rest of its stores were
written back from the shader cores' L1 cache into its closed VM:

  fault bank 4: status 0x283a03a1 va 0x5bf27c5180
    (write unmapped level 3 unit 0x1 ctx 29)
  attribution: busy=1 ctx=29 flight_matches=0 live_vm=None flights=9

When those writes filled all eight fault banks, the firmware did not
finish the recovery and the GPU stopped.

Let SCS compute (ray queries, and every compute command of a job with
SCS scratch) share the compute engine only with SCS compute of its own
VM. Other compute neither queues behind it nor runs while it is
published; each waits for the other to retire. One ray-query queue
still pipelines its own commands, and renders are not affected.

Signed-off-by: Diljit Singh <[email protected]>
… and work rings

Match the render pass-slot command-record layout on Apple G16 by moving
per-unit compute microsequences and barrier records, together with the
four compute/render firmware work rings, into device-lifetime
Class::FwCoherent mappings owned outside per-VM arenas.

Each hardware compute unit index (0..COMPUTE_UNITS) is device-global and
claimed by one flight at a time. Previously every VM's ComputeSlot
allocated its own uncached seq and barrier pages, while prefix_compute
hardcoded ComputeRefs::seq to the embedded sequence inside the uncached
compute work image (work + 0x900) and wrote 1248 bytes of write-combined
body per clean same-VM submit. The work image already names its
microsequence by address (+0x760) and size (+0x768), and
encode_compute_rt already emits every microsequence self-reference
relative to ComputeRefs::seq.

Share device-lifetime UnitCmds (seq and barrier) per hardware compute slot
via resources::ComputeCmds (indexed by hw_slot so SCS sets map to the
exact hardware ledger slot they claim), point ComputeRefs::seq to
s.seq.va, write the 768-byte microsequence into cacheable s.seq, and
shrink clean same-VM WC work writes to work[0x720..0x900]. Likewise
allocate the two compute and two render work rings (host-written VA
arrays, never host-read) from a ManuallyDrop device-lifetime
Factory::persistent_objects_probe allocator after sealing session
allocations; because Graphs::finish() runs during platform probe() before
drm_dev_register(), the probe-only allocator prepares its backing against
the bound platform device while non-probe private allocations keep
requiring registration_guard(). Keep ComputeSlot::work in Class::Shared so
host retirement reads of DESCRIPTOR_COMPLETED and 26B123 work_ticks stay
strictly coherent without relying on ASC-to-AP cache clean ordering.

Signed-off-by: Diljit Singh <[email protected]>
Compute retirement checks DESCRIPTOR_COMPLETED (0xe54) and
DESCRIPTOR_COUNTER (0xe4c) via FwObject::r64(). Both packed fields are
4-byte aligned (offset % 8 == 4), which previously bypassed the 8-byte
fast path and fell through to FwObject::read()'s byte loop, issuing 16
single-byte write-combined loads and 4 read barriers per call (32 byte
loads and 8 barriers per retired compute command).

Add a 4-byte-aligned fast path in FwObject::r64() that reads matched
aligned 32-bit word pairs separated by rmb(), preserving the exact
tear-free double-snapshot and EAGAIN retry semantics while cutting each
4-byte-aligned receipt check to 4 aligned 32-bit loads.

In Firmware::compute_ticks_with(), also read ABI-defined work_ticks
before falling back to unit.its. On 26B123, firmware leaves unit.its
zeroed and records compute GPU ticks in work_ticks, so probing work_ticks
first avoids two always-zero WC r64 reads and two read barriers per
compute command while preserving the ITS fallback and 25G83 behavior.

Signed-off-by: Diljit Singh <[email protected]>
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) blast:m4 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) and removed needs-template PR body lacks Tested or Risk (bot) labels Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Merge readiness at 3e0e4f6d: not ready yet

Check Detail
CI at head ok no CI for this change (the hardware row is the gate)
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head no no line with the head SHA 3e0e4f6d, a Mac and a result in the PR body or a comment
Conflicts ok not computed yet
PR text ok Risk: two-way · M4 (J773g, J713)

Areas: area:gpu

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

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Verdict at 3e0e4f6d4f: FINISH, then merge. No code blockers; one row is missing.

Blockers:

  1. No hardware row at this head. The A/B ran on the M4 integration tree with and without these commits, not on this branch. Fix: one J773g run at this head, or on a candidate that contains this head unchanged (see below).

Checked: both commits against the base; the device-lifetime records are never dropped, which is safe because the module is pinned and never unloads; the aligned 32-bit pair read keeps the double-read and retry behaviour; no Apple material in code or commit messages; no chip or board gates; no new parameters; only bounded waits; commits carry human authors and Signed-off-by, no AI attribution; CI does not run on a stacked base and will run once this PR targets main. This branch still carries the cross-VM compute overlap from #3042, so it should merge only in the same train as #3087. I reformatted the PR body to What / Tested / Risk / Not yet, with the original kept folded.

Row

One J773g run on a candidate that contains the heads of #3087, #3057 and #3046 unchanged (boot, idle/wake, deep sleep, vk-mustpass-short, gpubench vk-full, compute.long, 0 GPU faults) counts for every non-draft PR in this stack at once.

@DjDeveloperr
DjDeveloperr requested a review from a team as a code owner November 25, 2026 01:37
@DjDeveloperr
DjDeveloperr merged commit a1ef7e3 into main Nov 25, 2026
2 checks passed
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:m4 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (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.

1 participant