Repository navigation
drm/asahi: m3: let queued compute submissions share a firmware batch - #2849
RyanTheTide wants to merge 4 commits into
Conversation
The M3 runtime publishes one compute batch at a time and publishes the next one only after the previous one fully retired. Later pending packets could join render batches only, so every queued compute submission paid its own firmware round trip. On a J615 (M3, 27.2 firmware) that round trip is about 260 us for a 182 ns shader, so a light compute job costs ~390 us per vkQueueSubmit even at queue depth 8. Let later packets of the same VM and urgency join a compute batch from their first command, as render batches already do, and bound compute batches by the same GPU-time budget as render batches, using a per-VM measured GPU time per compute command. The compute batch size now defaults to the compute storage's slot count; the budget and the pending queue bound the batch in practice. The runtime knob m3_compute_batch_override still wins when set. On the J615 (one-shot kernel, in-boot ABAB of the batch size 1/8/1/8): compute.light at depth 8 goes from 394 to 174 us per submit, a light render clear from 363 to 173 us, heavy ALU compute from 1180 to 857 us, with 0 firmware error events. gpubench-stress-vk passes every test that does not inject a GPU fault. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
|
Review at a700462. Thanks, the cross-packet join is small and the J615 data is convincing. A few problems before this becomes the default:
Rows owed at this head: J613 (see 1). The other admitted T8122 boards, if any beyond J613/J615, need a boot plus the gpubench compute row. |
Review follow-up for the compute batching change: - Each batched command keeps the 2 s completion deadline it had when it was published alone: the batch deadline is now 2 s per command. Before, a batch of several long dispatches could exceed one 2 s deadline and fail the GPU although every command was in time. - A compute batch grows past one command only under a GPU-time budget and once the VM's compute cost is measured, whether the commands come from the front packet or from later packets. Without a budget every compute batch is one command, as before. An explicit m3_compute_batch_override still bounds the front packet's own commands alone, as before; it never lets other packets join without the budget. - If a batch that joined later packets fails before anything reached the firmware, the joined packets are marked unpublished again and the front packet is retried alone before it is failed, so it does not take the blame for a joined packet. Host tests cover the admission rule and the deadline. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
DjDeveloperr
left a comment
There was a problem hiding this comment.
Pre-PR Checklist Review (§1–§6) — a700462ffa129c54018dcd7798bed7ccb056faa1
The cross-packet compute batch join is concise and the J615 A/B improvement (~56% latency reduction on queued compute.light) is solid, with clean §4 attribution (human author/committer + human Signed-off-by:, zero AI trailers in commit) and green host-tests CI. However, there are concrete safety/failure-mode blockers and missing §5 hardware coverage that need to be resolved before making multi-slot compute batching the default.
Blockers
-
Fixed 2 s per-batch completion timeout vs. predictive
compute_costcan fatally fault valid workloads (§2 / §3):poll_active()(drivers/gpu/drm/asahi/m3/m3_runtime.rs:737, :813) enforces a fixed 2 s deadline per batch (batch.start.elapsed() >= Delta::from_secs(2)), and expiration triggersfail_active(ETIMEDOUT)->capture_fault(), taking the GPU down unrecoverably for the rest of the boot.next_batch()(m3_runtime.rs:261-274) bounds the batch usingcompute_cost(m3_runtime.rs:912), which is a smoothed historical per-VM mean. Previously (M3_COMPUTE_BATCH_SIZE = 1), every compute dispatch had its own 2 s timeout. With the default raised toSLOTS(16), a VM whose prior light dispatches establish a lowcompute_cost(e.g., ~100 µs) and that then queues heavier dispatches (e.g., 16 × 200 ms) passeswithin_budget()(16 × 100 µs = 1.6 ms <= 4 ms), lands all 16 commands in one batch, trips the fixed 2 s timeout, and permanently kills the GPU.- Scale the batch completion deadline with
entries.len(), or track/extend the deadline on per-slot progress, so a stale cost estimate cannot turn valid compute submissions into a fatal GPU fault.
-
Pre-publication failure misattribution and leaked VM quarantine (
m3_runtime.rs:413, :431-452, :380) (§2 / §3):publish()marks every packet inentrieswithp.mark_published()atm3_runtime.rs:413before encoding any compute command (Compute::new/replay/append/prepare_completion/set_user_timestamps/set_attachments, lines418-446).- If a joined packet (
slot > 0) fails during encoding,publish()rolls back viaj.abort_batch()and returnsErr((error, false)), andpublish_next()(m3_runtime.rs:380) callsself.fail_front(error). That failspending[0](a valid packet) while leaving the failing joined packet inpending, and leaves all joined packets permanently markedpublished = true(Packet::publishedis never cleared). - If a later unpublished failure hits
fail_pending(),policy::release_unpublished(packet.may_be_published())returnsfalsefor those never-published packets, permanently quarantining their VM job guards even though firmware never saw them. - Defer
mark_published()on non-overlapping batches until after encoding succeeds (right before firmware-visible publication), and attribute pre-publication encoding failures to the failing packet rather than unconditionally failingpending[0].
-
Missing J613 (
Profile::Extended) hardware evidence before changing its default (§1 / §5):- Raising
M3_COMPUTE_BATCH_SIZE(drivers/gpu/drm/asahi/m3/m3_params.rs:213) from1toSLOTS(16) also changes the default on J613, which runsProfile::Extended(t8122_admission.rs:60). - Until now J613 only ever exercised compute slot 0 by default; this change immediately puts J613 onto slots
1..15,Compute::append()(m3_compute.rs:252), and the Extended slot offsets (m3_compute.rs:303, :307, :314;m3_compute_storage.rs:106-110) with zero hardware runs onProfile::Extended. - Per §1 and §5, please provide a J613 hardware row at the updated head (
gpubenchcompute.light/heavydepth 8 A/B,gpubench-stress-vk,dEQP-VK.compute.*, 0 AVC / 0 failed units / 0 new kernel errors) before enabling multi-slot compute batching by default there.
- Raising
Non-blocking / Cleanup Items
- Commit message numbers vs. PR measurements: The commit message still cites the earlier dev-kernel numbers (
in-boot ABAB of the batch size 1/8/1/8,light render clear from 363) rather than this commit's actual0/1/0/1measurements reported in the PR body. Also, the PR body's "Still to run" still lists a Vulkan CTS compute subset even though the Testing section reportsdEQP-VK.compute.*(17,583 cases, 3,745 Pass, 0 Fail). - Stale doc clause (
m3_params.rs:489-490):m3_render_batch_budget_usstill saysdisabled on Pro, even though the M3 runtime only probes on T8122 (driver.rs:363-364). Please drop that clause rather than extending it to compute. - Host test coverage (
tools/asahi/m3-batching-tests.rs): Onlymay_joinwas updated; please add a test covering the compute budget path (unmeasuredcompute_costadmits 1 command; measured cost caps the batch count).
Assisted-by: LLM (Gemini 4 Neon)
|
Adversarial review record (independent reviewer, code only, before and after the fix commit).
Verdict from our side: ready for Dj's review. Still needed before merge: a J613 row. Assisted-by: LLM (Claude:Opus 5.5) |
publish() marked every packet of a batch published before it encoded any command. When the encoding of a joined packet failed, nothing had reached the firmware, but the packet stayed pending and marked. A later failure of the pending queue then kept its VM job guard, and its VM stayed quarantined for work the firmware never saw. The previous commit unmarked joined packets on that path. Do it at the source instead: - With nothing in flight, the batch's packets are marked only once every command is encoded, just before the firmware is told about the batch. Behind a running batch the firmware can consume an append without a doorbell, so there they are still marked first. - If a batch fails before anything reached the firmware, every packet whose first command was in it is unmarked again, also when a batch behind a running one has to wait (EBUSY). A continuation keeps its mark. - An error that may have been published marks the batch's packets in publish_next(), because it can now come from before the marking. A failure of a batch with joined packets still retries the front packet alone, so a packet is failed only when it fails as a batch of its own: the front packet no longer takes the blame for a joined one, and a joined one is tried as the front before it is failed. Also drop "disabled on Pro" from the m3_render_batch_budget_us text: this runtime only probes on T8122. The first commit of this series quotes an earlier development kernel (batch size 1/8/1/8, a light render clear from 363 us). Measured with that commit itself on the J615, default command line, with m3_compute_batch_override flipped 0/1/0/1 in one boot (0 is the new default, 1 the old behaviour), in us per submit at depth 8: compute.light 178.2/394.9/173.6/396.8, the light render clear 174.8/396.8/173.6/397.5, heavy ALU compute 856.2/1207.7/844.6/1184.8. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
m3-batch-select-tests.py runs the production next_batch() and batch policy on queues of host packets: a VM without a measured compute cost gets one command per batch, a measured cost caps the count at the GPU-time budget, without a budget every batch is one command, and only packets of the batch's VM and urgency join, from their first command. It also covers the override, the solo retry and a stale cost: the batch that a too low estimate admits stays within its deadline, and its retirement corrects the estimate. A mutation that drops the admission check must fail. m3-batching-tests.rs gains the same budget cases on the policy alone, and the rule that a batch which fails before publication leaves its new packets unpublished. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
|
Thanks for the review. 9f4e653 and 79d1535 are pushed as new commits on top of 8eaf761 (no rewrite).
J615 at the head (79d1535): override 0/1/0/1 gives compute.light depth 8 at 174.6 / 396.8 / 174.9 / 393.7 µs. gpubench-stress-vk passes 10/10 on the non-fault tests with 0 firmware error lines. Details are in the updated body. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Formal §1–§6 pre-PR checklist re-review at 79d1535a7a5452c531506050f3ec6cba8cb51b97 (host-tests: green; mergeStateStatus: CLEAN).
Code & Safety Assessment — Prior Blockers 1 & 2 Resolved (0 code blockers)
- Prior Blocker 1 (batch completion deadline & budget admission) — Resolved:
policy::batch_deadline_secs()(drivers/gpu/drm/asahi/m3/m3_batch_policy.rs:35-37) scales the completion deadline to2 s × commandsat bothpoll_active()sites (m3_runtime.rs:758, :834), preventing a stalecompute_costestimate from tripping a fatalETIMEDOUT.policy::admits()(m3_batch_policy.rs:26-31) ensures compute batches grow past 1 command only with a budget and a measured per-VMcompute_cost, while preservingm3_compute_batch_overridefor the front packet alone. - Prior Blocker 2 (pre-publication failure attribution & VM guard quarantine) — Resolved: Non-overlapping
publish()defersmark_published()until after command encoding (m3_runtime.rs:435, :528).publish_next()marks all entries on published errors (:375), clearsfirst_publicationpackets on unpublished errors (:385), and retries the front packet alone viasolo_next(:390-395) so joined-packet failures neither misattribute blame nor leak quarantined VM guards. - Prior nits & J615 re-verification — Resolved:
m3_render_batch_budget_usdrops the stale"disabled on Pro"clause, commit9f4e653brecords the0/1/0/1measurements,m3-batch-select-tests.py(withunbudgetedmutation check) andm3-batching-tests.rs(17 tests) cover the productionnext_batch()budget/deadline/publication paths, and J615 was re-tested at head79d1535a(compute.lightdepth 8:174.6 / 396.8 / 174.9 / 393.7 µs,gpubench-stress-vk10/10, 0 FW errors, 0 AVC, 0 failed units).
Remaining §1 / §5 Blocker Holding APPROVE / MERGETRAIN-LINUX4
- Prior Blocker 3 — Missing J613 (
Profile::Extended) hardware row: RaisingM3_COMPUTE_BATCH_SIZEfrom1toSLOTS(16) puts J613 (Profile::Extended) onto compute slots1..15,Compute::append(), and Extended slot offsets by default with zeroProfile::Extendedhardware runs. Still open under## Still to run. HoldingAPPROVE(priorCHANGES_REQUESTEDremains active) until a J613 hardware + regression row lands.
Checklist Summary
- §1 No model gating / multi-board coverage: Code clean; J613 (
Profile::Extended) hardware coverage still owed. - §2 Production-ready: Pass — default cmdline, clean deadline/publication handling.
- §3 Safety: Pass — stale cost cannot cause fatal timeout; unpublished failures do not misattribute or leak guards.
- §4 Clean-room & attribution: Pass — all 4 commits carry human author/committer (
Ryan Murray <ryan@aurorasilicon.org>) + humanSigned-off-by:only, zero AI trailers in commits;Assisted-by:in PR body. - §5 Evidence: J615 head row + host tests green; withholding
APPROVEstrictly on the open J613 (Profile::Extended) hardware row. - §6 Naming: Pass.
Assisted-by: LLM (Gemini 4 Neon)
|
Review at 79d1535. Three commits were added on top of a700462, with no rewrite. 8eaf761 adds Our points:
No new issues beyond those notes. There are no new parameters, the budget/override params already exist, there is no SoC gate in the new code, and there are no agent trailers. Verdict: NITS on the code (5, plus the hang-latency note). Merge stays blocked on the J613 row (point 1); owner TBD via Dj. The J615 rows at this head are done (compute.light d8 174.6 vs 396.8 µs, stress 10/10, 0 fw errors). |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Formal §1–§6 pre-PR checklist re-review at 79d1535a7a5452c531506050f3ec6cba8cb51b97 (host-tests: green; mergeStateStatus: CLEAN; not superseded on integration/aurora).
Code, Safety & Attribution Assessment (0 code blockers)
- §2 / §3 Correctness & Safety: Pass — all prior code blockers are resolved on
79d1535a7a54:policy::batch_deadline_secs()scales completion deadlines to2 s × commandsat bothpoll_active()sites (m3_runtime.rs:758, :834),policy::admits()gates compute batch growth on budget + measured per-VMcompute_costwhile preserving explicitm3_compute_batch_overridefor the front packet alone, non-overlappingpublish()defersmark_published()until after encoding (:435, :528),first_publicationclears unpublished packets on early error (:385), andsolo_nextretries the front packet alone (:390-395).m3-batch-select-tests.py(withunbudgetedmutation) andm3-batching-tests.rs(17 tests) pass,host-testsis green, and exact-head J615 A/B +gpubench-stress-vk(10/10, 0 FW errors, 0 AVC, 0 failed units) is verified. - §4 Clean-room & attribution: Pass — all 4 commits carry human author/committer (
Ryan Murray <ryan@aurorasilicon.org>) and humanSigned-off-by:only, zero AI commit trailers;Assisted-by:is at the end of the PR body. - §6 Naming: Pass.
Remaining §1 / §5 Blocker Holding APPROVE / MERGETRAIN-LINUX4
- Missing J613 (
Profile::Extended) exact-head hardware row: RaisingM3_COMPUTE_BATCH_SIZEdefault (drivers/gpu/drm/asahi/m3/m3_params.rs:213) from1toSLOTS(16) moves J613 (Profile::Extended) onto compute slots1..15,Compute::append(), and Extended slot offsets by default with zeroProfile::Extendedhardware runs. Still open under## Still to run. - Required before approval: Exact-head (
79d1535a7a54, default cmdline) J613 (Profile::Extended) hardware + regression row (gpubenchcompute.light/heavydepth 8 A/B,gpubench-stress-vk,dEQP-VK.compute.*, 0 firmware errors, 0 SELinux denials, 0 failed units, 0 new kernel errors).
Assisted-by: LLM (Gemini 4 Neon)
|
Merge readiness at
Areas: Updated by pr-readiness on every push, edit and review, and every 30 minutes. Rules: merge policy · labels. |
Problem
On the M3 runtime (J613/J615), queued compute submissions never share a firmware batch. Later pending packets may join render batches only, so each
vkQueueSubmitof compute work pays a full firmware round trip. The kernel then publishes the next batch only after full retirement. On a J615 (15-inch M3 Air, 27.2 firmware) that round trip is about 260 µs for a 182 ns shader, so a light compute job costs ~390 µs per submit even at queue depth 8. The Neo (A18 Pro) needs about 17 µs, on Linux and on macOS.Change
may_join()no longer requires a render batch. A later packet of the same VM and urgency may extend a compute batch from its first command, as render batches already allow.m3_render_batch_budget_us) and with a measured per-VM GPU time per compute command (compute_cost, recorded at retirement likepass_cost). With no measurement yet, or with no budget, a batch is one command.m3_compute_batch_sizenow defaults to the compute storage's slot count (m3_compute_storage::SLOTS) instead of 1. An explicitm3_compute_batch_overridestill bounds a packet's own commands, as before.No new parameters, no chip or board gate. It works on the default command line.
Testing
J615, one-shot kernel = fleet81 (
1b940c26, the J615 default, which carries #2781) + the first commit, default command line, gpubenchae90a40, system Mesa, headless, silent.In one boot,
m3_compute_batch_overridewas flipped 0 / 1 / 0 / 1. At 0 the runtime uses this PR's default; 1 is the old behaviour, one command per batch. Microseconds per submit, lower is better:gpubench-stress-vk --kernel-logat the default: all 10 tests that don't inject a GPU fault pass, about 940k checks, 0 firmware error lines.dEQP-VK.compute.*case of our 636k-case lab sample (17,583 cases): 3,745 Pass, 13,838 NotSupported, 0 Fail. That matches the same sample on the previous J615 kernel exactly.8eaf7613) on the J615: compute.light at depth 8 was 173.6 / 396.8 / 175.1 / 383.4 µs, gpubench-stress 10/10, 0 firmware error events.79d1535a, one-shot kernel = fleet81 + all four commits, default command line), override 0 / 1 / 0 / 1 in one boot: compute.light depth 8 174.6 / 396.8 / 174.9 / 393.7 µs, compute.heavy alu depth 8 853.2 / 1179.2 / 853.2 / 1201.9 µs, compute.heavy bw depth 8 1644.7 / 1968.5 / 1644.7 / 1968.5 µs, render.light clear depth 8 174.6 / 374.3 / 176.6 / 393.7 µs. On a fresh boot of the same kernel, gpubench-stress-vk--kernel-logwith the 10 non-fault tests: 10/10 pass (~704k checks), 0 firmware error lines. 0 AVC, 0 failed units; the J615 went back to its default kernel afterwards.Host tests, at the head:
run-host-tests.py --only m3: 11/11 pass.m3-batch-select-tests.pyruns the productionnext_batch()on host packets: an unmeasured compute cost gives one command, a measured cost caps the count at the budget, and a mutation without the admission check fails.m3-batching-tests.rs: 17 tests, with the budget, deadline and publication cases.Still to run
dEQP-VK.compute.*.compute.longandlife.faultin gpubench-stress-vk take the GPU down on the J615 with or without this change (firmware event 4, no recovery after a fault). That is the open fault-recovery item on drm/asahi: m3: run the M3 (T8122 G15G) GPU on the macOS 27.2 firmware #2781, not part of this PR.Review points and where they are answered
2 s x commandsat both sites inpoll_active()(policy::batch_deadline_secs). The example of a VM measured at ~100 µs that queues 16 x 200 ms still lands in one batch, which now has 32 s and needs 3.2 s. Its retirement corrects the estimate. Both steps are host tests.mark_published()before encoding: with nothing in flightpublish()marks after the last command is encoded, directly before the firmware is told. Behind a running batch it still marks first, because the firmware can consume an append without a doorbell. Errors that may have been published mark the batch inpublish_next(). Unpublished errors unmark every packet whose first command was in the batch, sorelease_unpublisheddrops exactly the guards of packets the firmware never saw.m3_render_batch_budget_ustext: "disabled on Pro" is gone.mark_binding_published()comes after the compute append and has no rollback. It predates this PR.Method and raw data
7.3.0-aurora-pub4cjp= fleet811b940c26+ the first commit (tree identical to a700462), a J615-only module set, default command line,grub2-rebootone-shot.completion_wait1000 / 25 / 1000 / 25: compute.light at depth 8 was 396 / 368 / 372 / 369 µs. Noise.apple,idleoff-standby-timer = <2500>to the GPU node, run as A/B/A. compute.light at depth 8 was 396.8 / 396.8 / 388.8 µs. No effect.compute.longandlife.faulttake the GPU down on this J615 at the old setting too: firmware event 4 or a lost device, then no recovery for the rest of the boot. With the old behaviour selected they fail identically.traces/gpu/20261123-j615-gpu-rtt(cjoin/, cjoin-pr/, cwait/, idleoff/).