Repository navigation
drm/asahi: g16: ray-query/AS build support, quarantine-aware SCS routing, SCS stage flags, and firmware-cached render records - #3044
Conversation
…and hot paths Kernel VMAP_STACK (32 KiB with 16 KiB pages) overflowed in g16::Firmware::start_backend (22,688 B frame) during probe. Keep large G16 boot, backend, scrub, and command-validation structures off the kernel stack: - Allocate ComputeOwners, RenderOwners, Pools, ScrubQueue, GpuAdt, Admitted, Booted, Stats, Prof, Scratch, Firmware, and SpanProof in- place on the heap (KBox::init / KBox::try_init / KBox::zeroed / write_init). - Retain failed Booted/Firmware sessions directly as KBox variants instead of unpacking Firmware back onto the stack with KBox::into_inner. - Bound stack-resident ScrubBatch to 8 displaced slots per pass and drain ScrubQueue entries one-by-one in join_workers. - Reuse heap-resident ValidateScratch inside SpanProof for Prepared::validate and SpanBatch::flush_with_proof. - Mark probe/boot/engine phase boundaries #[inline(never)] so unrelated large frames do not merge. Signed-off-by: Diljit Singh <[email protected]>
…iers Cross-queue Vulkan binary and timeline semaphore waits on the same G16 device and VM previously fell through to drm_sched, forcing the producer job to retire on the CPU and wake the scheduler worker before the consumer could enter the engine. Tag G16 queue output fences with their originating GPU, VM, queue, and per-engine ordinals (FenceOrigin), and mark the origin enqueued once Firmware::enqueue accepts the job. On submission, walk the input fence tree via g17::sync_input::collect and, when every unsignalled leaf is an already-enqueued same-GPU same-VM G16 fence (bounded to 8 waits), convert them into job.fw_waits so try_start_inline hands the consumer straight to the firmware engine. Extend dependency checking, timestamp-query serialization, compute and render stamp resolution, single-pipe compute selection, and transitive failure doom propagation in poll.rs to cover job.fw_waits, while keeping horizon folding disabled when cross-queue waits are present. Signed-off-by: Diljit Singh <[email protected]>
Timeline semaphores on G16 attach each submitted JobFence into a dma_fence_chain across participating queues. Previously, two issues forced alternating cross-queue timeline ping-pongs permanently onto drm_sched after the first few hops: 1. asahi_g17_collect_fences() emitted every leaf in the chain without skipping signalled leaves or coalescing same-context leaves, hitting -ENOSPC once chain depth grew past the buffer capacity. 2. FwWaits::push_unique() deduplicated only identical FenceOrigin allocations instead of coalescing per logical queue, overflowing MAX_FW_WAITS (8) by hop 9 and cascading every subsequent hop onto drm_sched because the bounced producer stayed !is_enqueued(). Add asahi_g17_collect_fences_coalesced() (skipping already-signalled non-error leaves and keeping only the latest unsignalled leaf per dma_fence context while preserving every status < 0 error leaf), record cumulative accepted render/compute ordinals in FenceOrigin::last_ordinal so coalescing to a queue's newest fence retains earlier unretired work on both engines, coalesce FwWaits per logical queue, and check that a cross-queue render wait is still unretired before clearing fragment barriers. Add host unit tests covering 256-hop 2-queue timeline chain coalescing, error leaf preservation, and per-queue FwWaits ordinal merging. Signed-off-by: Diljit Singh <[email protected]>
When multiple processes interleave compute submissions on G16, pure round-robin compute-unit claiming rotates each VM onto another VM's recently retired unit, forcing a full WC scrub, 160-byte WC descriptor read-back, and 8 KiB full work write on every dispatch. Update Slots::claim_compute_for_pipe() to prefer a displaced warm unit already owned by the requesting VM (!scrub_full), then an unowned unit, before falling back to round-robin over the pipe's eligible range. This keeps concurrent multi-VM compute workloads on their own warm units while preserving base-unit pipe-0 isolation and quarantine fallback. Signed-off-by: Diljit Singh <[email protected]>
…ots VM-affine Multi-process render workloads with d=4, 8, or 16 concurrent VMs thrashed the two shared base PB/UMA allocator slots, forcing full engine drains and InitBM epoch reinitializations on every cross-VM handoff as well as cross-VM full pass-slot scrubs. Expand the device-wide warm PB/UMA allocator pool to 16 slots (WARM_PB_SLOTS = 16, hardware UMA slots 33..48) plus 4 lazy quarantine spares (EXT_PB_SLOTS = 4, hardware UMA slots 49..52) while keeping every VM's client VA footprint unchanged at 2 base units (local indices 0..2, assigned rotating [home, alt] pairs) and up to 4 lazy recovery spares (local indices 2..6). Add mask-based Pools selection that prefers a VM's unused home slot so 16 concurrent VMs bind 16 disjoint warm slots regardless of arrival order and pipeline with zero InitBM after warmup. Add VM-affine render pass selection (Slots::pick_pass_in_for) and scale bursting VMs to Tier 1 pass headroom (18 slots) when active_render_vms >= 8 while keeping PB_HEAP_EXT_TIERS gated on single-VM pass demand so concurrent light renders do not expand to 256 MiB PB heaps. Also trim PbEpoch::prepare WC list seeding to the active heap_blocks prefix (plus any shrink tail on unpublished retries). Verified with asahi-m4 (25/25) and asahi-g15 (81/81) host selftests and checkpatch.pl (0 errors, 0 warnings). Signed-off-by: Diljit Singh <[email protected]>
…mware PB/UMA records After a DRM client closes, Gpu::vm_closed() drops its registry and cache references, but device-wide slot tables (Pools::owners/owner_vms and owner_arenas across PB_SLOTS, Slots::render across 48 pass slots, and Slots::compute across 24 compute units) continued holding strong Arc<VmState> and arena leases indefinitely until later traffic overwrote every slot. Under multi-process render and compute workloads, dead VMs stayed pinned after exit (multi-GiB Unevictable/Shmem and live TTBAT ASIDs), starving subsequent allocations with VK_ERROR_OUT_OF_DEVICE_MEMORY. At the same time, 26B123 RTKit firmware stores per-slot context-0 pointers in pb_mgr_table[0..15] and uma_mgr_table[1..48] that persist across subsequent work on other slots and are walked during GPU timeout recovery, so dropping the tiny firmware-owned metadata records before that exact hardware slot is overwritten would leave dangling firmware table pointers across timeout recovery. Reclaim displaced closed-VM leases cleanly without violating hardware displacement or firmware recovery contracts: - Add Lifetime::is_quarantined() so quarantined slots stay pinned forever without keeping reclaim armed. - Split the tiny firmware-owned metadata records (PbEpoch's pb_manager + counter, render Allocator's UMA descriptor + submitted, and ComputeSlot's kernel-lower work + counter) into VM-free FwLease objects allocated via Factory::fw_objects() without a Vm reference, and retain one FwLease per hardware slot in Pools and Slots until a later retired publication overwrites that exact hardware slot index. - Add Pools::reclaim_closed() and Slots::reclaim_closed() to drop owners, owner VMs, and owner arenas (Deferred-backed, safe under Shared::state) only for displaced, idle, non-pending, non-scrubbing, non-quarantined slots whose VM is closed via lock-free Vm::is_closed(). - Skip closed VMs in Slots::stage_displaced_pass_scrubs(), and arm ScrubState::waiter if a closed VM's displaced pass slot is mid-scrub. - Gate scanning behind Shared::closed_vm_reclaim (read-only Acquire load on the hot path), set in Gpu::vm_closed() and checked in idle/active poll_step(), submit_locked(), and run_housekeeping(). - Add host selftest coverage in test-resources.py and test-poll-retire.py. Signed-off-by: Diljit Singh <[email protected]>
With two independent CDM pipes (COMPUTE_PIPES = 2), multi-process
compute leaves one undisplaced last-retired compute unit on pipe 0 and
one on pipe 1 (22 of 24 units reusable). Because firmware may still
reference each pipe's last-retired unit until a later retired
publication on that same pipe displaces it, those two owner leases must
remain pinned.
Previously, Ready::compute_ext backed all 22 extension compute units
(2..24) inside a single monolithic Arc<ComputeArena> (~713 MiB). Holding
a lease on one undisplaced extension unit pinned all 22 units of its
closed VM; across two CDM pipes that retained ~1.40 GiB (+1,464 MiB
Unevictable) instead of 2 x ~32.4 MiB (~65 MiB).
Split compute unit backing so each ComputeArena owns a single
self-contained ComputeSlot and introduce ComputeUnitSet (a KVec of
per-unit Arc<ComputeArena>) for Ready::{compute, compute_ext} and
Prepared::{compute, compute_ext}:
- Prepared::compute_arena(k) returns only unit k's Arc<ComputeArena>,
keeping zero-alloc Cache::prepare() cloning intact.
- When a VM closes, Cache::close() and Slots::reclaim_closed() drop
every unused or displaced unit immediately while each pipe's
undisplaced (or quarantined) slot pins only its own ~32.4 MiB unit
(~22x reduction).
- Add dual-pipe per-unit closed-VM reclamation coverage in
test-resources.py.
Signed-off-by: Diljit Singh <[email protected]>
Commit c12278d5c9aa ("drm/asahi/g16: reclaim displaced closed-VM slot
leases and retain firmware PB/UMA records") lets Pools::reclaim_closed()
drop the owner epoch of a closed VM's PB slot as soon as a render
retires on any other slot while keeping the manager record mapped. That
epoch maps the page list of its manager in the VM's DYNAMIC client
window and its block list, and it holds the VM's TTBAT slot.
Because the firmware keeps pb_mgr_table[k] naming the manager across
work on other slots, dropping the epoch releases the page and block
lists and the VM's ASID while the firmware can still reference that
manager.
A light render workload run repeatedly with sixteen concurrent client
processes faulted with no compute or ray-query work active:
fault bank 1: status 0x8b81ddc021 va 0x704000cb40
(write unmapped level 0 unit 0xe0 ctx 46)
attribution: busy=0 ctx=46 flight_matches=1 live_vm=Some(110)
event=0xffffffff flights=1
Unit 0xe0 is gPM_SP(0), the parameter manager. Only PB page lists are
placed in the DYNAMIC window: 0x704000cb40 is entry 720 of a VM's second
page list. No TA, FS or compute slot was running for ctx 46, so the
firmware attributed the fault to no stage. The parameter manager wrote a
PB page list that ctx 46 did not map. Reclaim releases exactly such a
list, together with the VM context, while pb_mgr_table[k] still names
its manager.
Keep the owner epoch until a newer epoch retires on the same slot, as
before reclaim existed; retire_flight() already replaces it then.
Reclaim still releases the closed VM's render arena, PB heap and the
slot's VM references. A closed VM then keeps only its two 32 KiB lists,
its records and its context until its slot is reused, and each PB slot
pins at most one such VM. A slot holding nothing but that epoch no
longer keeps reclaim armed.
Add a host regression test for this sequence and update the two reclaim
tests, which expected the epoch and the VM's TTBAT slot to be released
at reclaim.
Fixes: c12278d5c9aa ("drm/asahi/g16: reclaim displaced closed-VM slot leases and retain firmware PB/UMA records")
Signed-off-by: Diljit Singh <[email protected]>
Implement cleanroom G16G (M4) hardware ray tracing support on top of the
M4 production tree, advertising DRM_ASAHI_FEATURE_RENDER_RAY_QUERY and
DRM_ASAHI_FEATURE_BOUNDED_AS_BUILD:
- Add pure RT validation, Gen1 SCS sizing, and intersection table helpers
in g16/rt.rs (with TAIL_ENABLED = 0x2c), plus UAPI flags/reservations in
asahi_drm.h and params.rs.
- Extend command.rs stream parsing and SpanBatch VM admission for render
ray-query stages, compute ray/SCS requests, and AS-build flags without
reintroducing per-span VM locks.
- Add demand-sized SCS UMA pools and freelist placement (0x80000 records
in dedicated SCS windows) across slots.rs, pools.rs, resources.rs,
hw.rs, and fw/buffer.rs, isolating SCS vs base arenas on reuse while
retaining firmware PB/UMA leases across closed-VM reclaim.
- Wire RT register encoding and J773g SCS bracketing (0x017e1 = 1 first,
0x017d9 = 1 last) in encode/{compute,render}.rs and engine.rs, pinning
RT/SCS compute jobs to pipe 0, guarding horizon batching, and applying
the 10 s long-job deadline allowance in recovery/logic.rs. Non-RT
submits remain byte-identical.
- Add test-ray-tracing.py and update asahi-m4 host selftests.
Signed-off-by: Diljit Singh <[email protected]>
…d slots After a firmware compute recovery permanently quarantines compute unit 0, brand-new VMs using the 2-unit SCS compute layout previously pinned themselves to hardware slots 0..2. Their first compute submission claimed and retired on unit 1 (the sole healthy slot in 0..2), leaving unit 1 as pipe 0's undisplaced latest retired lease so the second compute submission saw compute_exhausted_within(2) == true and immediately failed with ECANCELED, poisoning every subsequent fresh process. Track the live quarantined compute mask in Shared::quarantined_compute_mask and route ComputeUnitSet::new_scs onto two healthy hardware slots, preferring the pipe-0-reserved 0..PIPE1_COMPUTE_START range so pipe 1 cannot pin an undisplaced lease on SCS slots, then falling back across the remaining units. Apply the matching quarantined-slot skip when picking base warm PB slots for new render arenas. Signed-off-by: Diljit Singh <[email protected]>
Commit 7a8472835197 ("drm/asahi: g16: route SCS compute and base PB
slots around quarantined slots") replaced the [home, home + 1] warm PB
pair of a new render arena with a quarantine-aware picker.
Verify that with nothing quarantined the picker returns the contiguous
[home, home + 1] pair for every start, and that sixteen render-only VMs
use every warm slot once as home and once as alternate regardless of
earlier round-robin cursor motion.
Signed-off-by: Diljit Singh <[email protected]>
The 26B123 G16G firmware learns which slots run shader-context scratch (SCS) work from a u32 in each start command: StartCompute +0x40, StartTA +0x60 and StartFS +0x78. It ORs the slot into a per-engine SCS mask, appends 0x017d9 = 1 to that kick's register list for masked slots, and when its scheduler goes idle it tears the SCS state down (0x017e0 = 0, the compute and TA windows 0x107a0/0x10798 = 0xff0000, 0x100e8/0x100f0/0x10408/0x10410 = 0x100) unless a masked slot is still busy. The G16 encoders always left the three words zero, so the teardown ran at the first idle after every ray-query kick, while the dispatch was still executing. Compute and ray-generation ray queries then lost traversal mid-dispatch and returned misses without a fault, and fragment and tiling ray queries stalled their stage until the firmware recovered it (events 0x71 and 0x70). macOS 27.2 on Apple M4 sets StartCompute +0x40 on every compute item whose register list opens with 0x017e1 and leaves it clear on all others. This is the M4 counterpart of the G17P kick header's SCS bit (bit 61), which g17 sets for compute and per render stage. Set each word exactly when the stage's register list enables SCS. Non-ray-tracing work is byte-identical. The host check now also requires the flag on ray-query compute, TA and FS sequences and nothing else to change there. Signed-off-by: Diljit Singh <[email protected]>
A render pass slot index is device-global and claimed by one flight at a time, so render microsequences and barrier records need not be allocated per VM. Mapping them with firmware-cached leaf 0x443 inside a per-VM render arena is unsafe on client teardown because KernelMapping::drop() fail-stops an ASC-cached M4 mapping that has no qualified teardown. Allocate render microsequences and barrier records once per pass slot index, on first use, from a device-lifetime allocator that is never dropped (resources::RenderCmds, reached through Factory), and let every VM's PassSlot of that index share them. Each microsequence keeps its own page and the barrier records share one page, matching compute unit barriers: 48 KiB per index (at most 2.25 MiB per boot) instead of 128 KiB per pass slot of every VM. Class::FwCoherent (firmware leaf 0x443 behind a cacheable host mapping, matching macOS 26B123 per-queue command objects) is accepted only by this device-lifetime allocator and never with a client or lower alias. Per-VM arenas and the session allocator reject it, so closing a client can never drop a firmware-cached mapping. Extend the host resource tests to verify that two VMs' pass slot k share one set, no VM arena owns a firmware-cached object, dropping a VM retains the set, and other allocators reject Class::FwCoherent. Pass slot backing drops from 608 to 480 KiB of metadata per VM. Signed-off-by: Diljit Singh <[email protected]>
Move the TA and FS work images, the larger part of what the firmware reads per render, into the per-index device-lifetime RenderCmds records. macOS 26B123 maps its per-queue command objects, work items included, with the firmware-cached leaf 0x443 and maps the same pages into GPU context 0 with the uncached leaf 0xc8b. The work images keep that uncached kernel GPU task lower alias. Because the host writes to the work images through a cacheable mapping while the GPU reads their register lists through the uncached alias, FwObject cleans each store to such an object to the point of coherency (dc cvac, then dsb sy). Only a firmware-cached object with a lower alias performs this clean; the microsequences and barriers, which only the firmware reads, are unchanged. Each pass slot index now holds five device-lifetime pages (80 KiB, at most 3.75 MiB per boot) and every VM pass slot sheds two more pages (448 KiB of metadata). Compute command objects are unchanged because the host reads firmware-written descriptor counters from the compute work image. Signed-off-by: Diljit Singh <[email protected]>
ee2bc3a to
e6d8e0a
Compare
|
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: this PR's own 6 commits against its base, with most attention on the ray-query command validation in Note and row
|
What: G16 (M4) ray queries and bounded acceleration-structure builds (
RENDER_RAY_QUERY,BOUNDED_AS_BUILD), stacked on #3043, with SCS scratch sizing, SCS stage marking in StartCompute/StartTA/StartFS, SCS and base PB slot routing around quarantined slots, and device-lifetime firmware-cached render records and work images.Tested: M4 Mac mini (J773g, G16G B0, 26B123) with the full stacked series on an earlier build, not this head: vk-rt gpubench 98/98,
dEQP-VK.ray_query.*1,382/1,382, gpubench 440/440, 4,670/4,670 supported CTS cases, deep sleep. Host tests pass.Risk: two-way · M4 (J773g, J713)
Not yet: known problem: ray-query compute may run beside other compute here, which leaves its results unwritten and can stop the GPU (measured and fixed in #3045), so this PR must land together with #3045. Also: a row at the current head; CI, which runs once the base lands and this PR targets
main.Details (original description)
Summary
Enables ray-query and bounded acceleration-structure build support on Apple M4 (
G16G), routes SCS compute and base PB slots cleanly around quarantined slots, marks SCS stages in firmware start commands, and moves firmware-cached render records and work images to device-lifetime shared allocations:RENDER_RAY_QUERYandBOUNDED_AS_BUILDadmission, Gen1 section scratch sizing, register-slot placement, and host selftests (test-ray-tracing.py).StartCompute,StartTA, andStartFSwhenever a command uses shader-context scratch.Class::FwCoherent): allocates render microsequences, barrier records, andta_work/fs_workimages once per pass slot index from a never-dropped device-lifetime allocator, cleaning PoC after host writes on GPU-lower-aliased work images. Prevents client teardown from ever dropping an ASC-cached mapping while reducing per-VM pass slot metadata from 608 KiB to 448 KiB.Verification
tools/testing/selftests/drivers/gpu/asahi-m4/test-resources.py— 66 passed, 0 failed.tools/testing/selftests/drivers/gpu/asahi-m4/test-ray-tracing.py— 21 passed, 0 failed.scripts/checkpatch.pl --strict: 0 errors across all 6 commits (1 standard informational MAINTAINERS warning on newrt.rs/test-ray-tracing.pyfiles; 0 warnings on the remaining 5 commits).G16G B0,26B123) silicon:vk-rtgpubench: 98/98 PASS (1.127×vs Metal 4;asbuild 1.638×,rays 1.226×,scene 0.965×).gpubenchsuite: 440/440 PASS across 4.00M GPU jobs (0faults,0recoveries,0bad CRCs,0kernel log errors).dEQP-VK.ray_query.*): 1,382/1,382 PASS (26/26 stress,516/516 builtin,180/180 position_fetch,480AS ops, watertightness,traversal_control,ray_flags).0failures,0faults,0recoveries).177.7 ms, resume346.5 ms, firmware back in644 µs,0errors.