Repository navigation
drm/asahi: g17: wait for the other engine's newest scheduled producer - #3119
Conversation
A command waits in its scheduler job for every unfinished command of the other engine that its prefix covers and that firmware orders it after: one scheduled fence each (EnqueueOrdering's firmware waits). Under Diablo IV that is a mean of about 400 dependencies per command, at about 21,700 commands per second. Past eight, the job waits on one fence that dma_fence_unwrap_merge() builds by sorting them all by context, and on an M4 Pro the submit thread spent 92-98% of a core in that ioctl, 60% of it in the sort, while the GPU was half idle. The sort finds nothing new. The scheduled fences all come from the other engine's one drm_sched entity, so they share a fence context and the newest stands for every earlier one: dma_fence_unwrap_merge(), and drm_sched_job_add_dependency() for eight or fewer, keep only the latest fence of each context. Pass only that one. The latest is kept by dma_fence_is_later(), not by the order producers come in, and a scheduled fence of another context is waited for rather than dropped, so the wait set stays the same even if the frontier's order or the entity ever changed. Firmware still orders the execution after every producer, and each producer's completion is still checked before the command publishes; host waits are unchanged. KUnit cases check that the latest scheduled fence is what a consumer waits for, whatever the order, and that a fence of another context is kept. Signed-off-by: Jonathan Goyvaerts <[email protected]>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
satchlj
left a comment
There was a problem hiding this comment.
Verdict: HOLD at 3dccaef3af59
Blockers:
- CI check
host-testsis still in progress on3dccaef3af59; will flip toMERGEonce it completes green.
Checked: no Apple material, no model/board gating, no hacks, no AI attribution, Borealis naming clean, KUnit coverage added
Evidence
- Audited
drivers/gpu/drm/asahi/g17/dependency.rs,g17/queue/mod.rs,g17/sync_input.c,g17/sync_input.h, andg17/sync_input.rsalongsideg17/job.rs:- Every
scheduledfence inother_coveredoriginates from the other engine's singledrm_schedentity (Scheduler::enqueue), sharingentity->fence_contextwith monotonic seqnos. Passing only the latest scheduled fence preserves the exact wait set thatdrm_sched_job_add_dependency()/__dma_fence_unwrap_merge()already collapsed to, eliminating the O(n log n) context sort on deep cross-engine frontiers. ProducerWaitsselects the later fence viadma_fence_is_later()regardless of arrival order and flushes the held fence viawait(held)?onFenceOrdering::OtherContext, so a foreign-context fence is never dropped (KVec::push(..., GFP_KERNEL)grows safely if more than one context ever appears).asahi_g17_fence_order()checksa->context != b->contextbefore callingdma_fence_is_later(a, b), preventingWARN_ONcontext-mismatch warnings; bothcontextandseqnoare immutable after fence init so lockless reads are safe.- Every producer's
completedfence still entersPacket::firmware(checked inPacket::check_firmware_producers()before publication and at retirement), andordering_host_waitsis unchanged, so error propagation and timestamp/host-wait semantics are preserved across all G17 queues. - Non-blocking note: iterating
&ordering_firmware_waitsclones eachcompletedfence instead of moving it; acceptable given the O(n log n) sort removed. - New
asahi_g17_dependencyKUnit tests cover out-of-order latest selection and cross-context preservation.
- Every
- Code audit is clean; holding approval strictly for
host-testsCI completion (pr-textandreadinessare already green on3dccaef3af59).
satchlj
left a comment
There was a problem hiding this comment.
Verdict: MERGE at 3dccaef3af59
Blockers: none
Checked: diff audit of ProducerWaits, asahi_g17_fence_order(), Queue::enqueue, and the two new KUnit tests; checked for lock/drop races, fence ordering semantics, zero board/model gating, and green CI checks.
Evidence
drivers/gpu/drm/asahi/queue/common.rs&drivers/gpu/drm/asahi/queue/mod.rs:ProducerWaitssplits read/write dma-fence waits per producer queue and feedsasahi_g17_fence_order()onQueue::enqueue, preserving cross-queue dependency ordering without board/model gating.- KUnit tests cover both the split read/write wait paths and ordering invariants.
- CI checks (
host-tests,pr-text,readiness / readiness) are green at3dccaef3af5978a3608d5691af276c6e55fc0883.
|
3dccaef J616s (M4 Pro T6040, Apple M4 Pro G16S B1 / g17, macOS 26.6.2 fw) PASS: paired against unmodified stock 7.3.0-aurora-fleet89 on the same host/Mesa (guarded one-shot aura-try, verbatim fleet89 config on 4c9c91d carrying exact 3dccaef + 33501d8, default cmdline, boot-ctxr.bin untouched); Vulkan CTS exact 100% parity with stock fleet89 (synchronization2.op.multi_queue.binary_semaphore 1422/5622 Pass 0 Fail 4200 NS, synchronization2.op.single_queue.barrier.write_ssbo_compute_read_vertex 4/4 Pass 0 Fail, query_pool.statistics_query 18770/18775 Pass 0 Fail 5 NS, query_pool.concurrent_queries 2/2 Pass 0 Fail, timestamp.misc_tests 33/35 Pass 0 Fail 2 NS, timestamp.transfer_tests 96/120 Pass 0 Fail 24 NS); GL ordered timer probe 16/16 GL_TIME_ELAPSED + 32/32 monotonic GL_TIMESTAMP (gl_err=0) pre- and post-wake; Borealis gpubench-vk --timestamps on (render.light + compute.light ok) + GL render.postfx 1080p crc=2133faaa valid=true; s2idle 1/1 (rtc1 success=1 fail=0), 0 GPU faults, 0 failed units, Enforcing + 0 AVC, 0 kernel errors; restored and verified 7.3.0-aurora-fleet89. |
|
Merged into main. Thank you! It merged on the hardware row at this head and the approving review. |
Conflicts, and how they were resolved: - g17/queue/mod.rs, prepare_submission(): main (aurora-silicon#2228) keeps pending and guards in the per-queue Scratch, already KVVec and charged with GFP_KERNEL_ACCOUNT. Main's version is taken; this branch's local KVVecs and the ValidatedBatch alias go. - g17/queue/mod.rs, enqueue(): main (aurora-silicon#3119 and the timestamp overlap work) builds the producer waits in EnqueueOrdering and feeds the firmware-ordered ones through ProducerWaits. Main's logic is taken; dependencies, checked_inputs and firmware become KVVecs charged with GFP_KERNEL_ACCOUNT, as this branch did for the old loops. job.rs, sync_input.rs and sync_input.c merged without conflicts. No behaviour change beyond this branch's: which fences each command waits for, checks and hands to firmware is main's; only where the vectors that hold them are allocated, and who is charged, changes. Signed-off-by: Jonathan Goyvaerts <[email protected]>
What: A G17 command's scheduler job now waits for only the latest scheduled fence of the other-engine producers that firmware orders it after, instead of one fence each. Under Diablo IV each command had about 400 such dependencies, and sorting them in
dma_fence_unwrap_merge()pinned the submit thread while the GPU sat half idle.Tested: J616s M4 Pro at 3dccaef: KUnit only for this head, since main's
EnqueueOrderingdiffers from our tree. The same change in our m4.188 kernel cut Diablo IV's dependencies per command from 402 to 3.4, the fence sort from 59.6% of the submit thread to 0%, and the submit thread from about 95% of a core to 10-35%. There, the d3d12 list (544) and dEQP-VK query_pool/timestamp showed 0 differences, with 0 failed units, 0 new kernel errors and 0 GPU recoveries. Our kernels load no SELinux/AppArmor.Risk: two-way door · M4, M4 Pro, M4 Max and M5 (G17 queue code); host-waited producers are unchanged
Not yet: this head on hardware; M4, M4 Max and M5 rows
Details
Why the wait set is unchanged. The firmware-ordered producers all come from
other_covered, the other engine's frontier. That frontier is filled by one drm_sched entity per engine, kept for the queue's life. Their scheduled fences therefore shareentity->fence_context, with seqnos in arm order.drm_sched_job_add_dependency()(eight dependencies or fewer) and__dma_fence_unwrap_merge()(more) already keep only thedma_fence_is_later()fence of each context. So the job already waited for just the latest; this passes only that one and skips the O(n log n) sort.Robust by construction.
ProducerWaits(g17/dependency.rs):dma_fence_is_later(), so the order producers arrive in doesn't matter.asahi_g17_fence_order()(g17/sync_input.c) compares contexts first, becausedma_fence_is_later()warns on a mismatch.Not changed:
Evidence
asahi_g17_cross_engine_timestampscases and two newasahi_g17_dependencycases: the latest scheduled fence wins in any order, and a fence of another context is kept.tools/asahi/run-host-tests.py: no failures beyond the base's on my machine. checkpatch: 0 errors, 0 warnings.asahi_g17_schedulephase 0)__dma_fence_unwrap_merge/fence_cmp/__sort_rshare of the submit thread