Repository navigation
drm/asahi: g16: firmware-cached compute records and work rings, aligned compute retirement reads - #3057
Conversation
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]>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
Verdict at Blockers:
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 |
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:
Class::FwCoherentmappings (resources::ComputeCmds), shared by every VM's unit of that index. SCS units use the hardware index they are bound to.Class::Shared, so the host's retirement reads ofDESCRIPTOR_COMPLETEDand the 26B123 work ticks keep reading uncached memory.work[0x720..0x900]instead of the whole body.FwObject::r64()gets a 4-byte-aligned fast path: two 32-bit reads, kept tear-free.DESCRIPTOR_COMPLETEDandDESCRIPTOR_COUNTERare 4-byte aligned and used to fall through to the byte loop, 16 byte loads per check.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.pypins 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 --checkis 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):
compute.lightd4–d64compute.heavyALU d2sync.signalcross-queue d2mem.buffer1 MiB d1overlap.passesasync_cr d4overlap.passescomp_comp d2concurrent.crheavy ALU + fill d4mem.bufferis probably drm/asahi: mmu: cache dcache line size and stream scatterlist page-table maps #3032.Health:
SELinux does not apply (Arch Linux ARM), and failed units were not recorded.