Repository navigation
drm/asahi: g17: signal G17P completions before draining reports; skip the core power read on back-to-back work - #2909
Conversation
Every G17P event pass drained the trace and statistics rings before it read the event rings, so each completion's fence waited for the reports the firmware queued ahead of it. On the M4 Pro (T6040, 25G83) a compute completion pass carries a trace and a statistics drain with two core-power observations (an MMIO read of about 0.3 us each), about 0.6 us before the fence is signalled. M5 already reads the event rings first and drains the reports in the worker's next locked step (47f1155, "drm/asahi: g17: Reduce M5 job completion latency"): the reports are not scheduling inputs. Do the same on every G17, which also shares one power observation between the two drains, and drop the per-role Transport hooks that only the old order used. Signed-off-by: Jonathan Goyvaerts <[email protected]>
Every G17 publication read the GPU's core power register to notice a gating before its work woke the cores. On the M4 Pro that MMIO read takes about 0.3 us of the ~6 us submit ioctl, ahead of the doorbell. The firmware gates the cores only after they have been idle for its idle-off delay (power::FIRMWARE_IDLE_OFF_MS), counted from the last job, which completes after its own publication. A publication less than that delay after the previous one therefore cannot follow a gating. Read the register only when the gap since the last publication reaches the delay. The publication time was already kept for the firmware_reports view; sleep and recovery still invalidate the statistics on their own. Signed-off-by: Jonathan Goyvaerts <[email protected]>
|
J616C (MacBook Pro 16" M4 Max, T6041, 32-core 25G83) same-machine headless depth-1 Vulkan compute latency A/B at
Idle-gap
Assisted-by: LLM (Google:Gemini 4 Neon) |
Each completion pass in run_runtime_events() / runtime_event_turn() previously took the global device mutex (shared.state) up to five times and ran M5 firmware.drain_reports() (trace/statistics rings plus GPU power register reads) on every completion interrupt, even during tight compute loops where no render mask was pending. Coalesce the worker_deferred take and empty-batch restore into the existing device-mutex holds, avoid dropping and immediately re-acquiring shared.state around a no-op observe_renders() when render masks are zero, and throttle M5 post-signal report draining (drain_post_signal_reports()) to the HOUSEKEEPING_NS (1 ms) cadence while work remains in flight. On recovery passes, drain post-signal reports before service_runtime_recovery() resets firmware rings (matching the unthrottled post-signal ordering and #2909) without double-draining in housekeeping. Add host tests (g17-m5-direct-compute-tests.py) covering mixed render/compute ring wrap, generation-change queued-claim handling, concurrent direct/scoped credit safety, and post-signal/pre-recovery report ordering. Signed-off-by: Diljit Singh <[email protected]>
Each completion pass in run_runtime_events() / runtime_event_turn() previously took the global device mutex (shared.state) up to five times and ran M5 firmware.drain_reports() (trace/statistics rings plus GPU power register reads) on every completion interrupt, even during tight compute loops where no render mask was pending. Coalesce the worker_deferred take and empty-batch restore into the existing device-mutex holds, avoid dropping and immediately re-acquiring shared.state around a no-op observe_renders() when render masks are zero, and throttle M5 post-signal report draining (drain_post_signal_reports()) to the HOUSEKEEPING_NS (1 ms) cadence while work remains in flight. On recovery passes, drain post-signal reports before service_runtime_recovery() resets firmware rings (matching the unthrottled post-signal ordering and #2909) without double-draining in housekeeping. Add host tests (g17-m5-direct-compute-tests.py) covering mixed render/compute ring wrap, generation-change queued-claim handling, concurrent direct/scoped credit safety, and post-signal/pre-recovery report ordering. Signed-off-by: Diljit Singh <[email protected]>
Each completion pass in run_runtime_events() / runtime_event_turn() previously took the global device mutex (shared.state) up to five times and ran M5 firmware.drain_reports() (trace/statistics rings plus GPU power register reads) on every completion interrupt, even during tight compute loops where no render mask was pending. Coalesce the worker_deferred take and empty-batch restore into the existing device-mutex holds, avoid dropping and immediately re-acquiring shared.state around a no-op observe_renders() when render masks are zero, and throttle M5 post-signal report draining (drain_post_signal_reports()) to the HOUSEKEEPING_NS (1 ms) cadence while work remains in flight. On recovery passes, drain post-signal reports before service_runtime_recovery() resets firmware rings (matching the unthrottled post-signal ordering and #2909) without double-draining in housekeeping. Add host tests (g17-m5-direct-compute-tests.py) covering mixed render/compute ring wrap, generation-change queued-claim handling, concurrent direct/scoped credit safety, and post-signal/pre-recovery report ordering. 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. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict: HOLD at 99b0b4cd
Blockers:
- PR description (§4): remove the attribution footer at the bottom of the PR body (no attribution lines in PR text; while editing, please also add
Tested:andRisk:lines perpolicy/pr-structure.md). - Hardware evidence (§5):
drivers/gpu/drm/asahi/g17/port.rsanddrivers/gpu/drm/asahi/g17/runtime/events.rsare shared across M4 (G17P) and M5 (G17M5), and commit99b0b4cdapplies the 2 msFIRMWARE_IDLE_OFF_MSskip rule on M5 whereagx_stats(Protocol::M5) is active and the idle-off delay has not been measured. J616C (M4 Max / T6041) has a same-machine A/B row at99b0b4cd, but a second-generation M5 regression row at99b0b4cd(0 failed units, 0 new kernel errors, 0 SELinux denials, plusagx_statsbehavior across idle gaps) is still needed.
Checked: §1–§3 pass (0 code/safety blockers), §4 fails (PR body footer; commits c56132f4 and 99b0b4cd pass with human author/committer and Signed-off-by:), §5 partial (J616C row at 99b0b4cd; M5 row missing; Tested:/Risk: lines missing), §6 pass (uses Borealis, no banned names), CI green (host-tests, pr-readiness), mergeable.
Evidence
- Code & safety audit (0 blockers):
c56132f4(drivers/gpu/drm/asahi/g17/event.rs,drivers/gpu/drm/asahi/g17/runtime/events.rs): removes theis_m5()gate (reports_after_signal) and deadevent::Transport::{trace,statistics}hooks so all G17 variants signal compute completions (deferred.finish()) beforeFirmware::drain_reports(). Verifiedruntime_event_turnis the sole caller ofservice_runtime_events;drain_reports()runs underself.state.lock()after checking detachment andself.crashed, only accessesFirmware-owned status/ring memory (no client/VM/BO lifetime hazards), runs beforeservice_runtime_recovery(), and remains serialized withstats::Reader::read_firmware(). Runningdrain_reports()on control-ring backpressure early returns is safe and avoids report-ring buildup.99b0b4cd(drivers/gpu/drm/asahi/g17/port.rs): skips theg17_core_power()MMIO read inPort::note_gpu_activity()whennow.saturating_sub(previous) < FIRMWARE_IDLE_OFF_MS * 1_000_000. Verifiedstatistics_epochis consumed only byagx_statstelemetry (observe_statistics_power), never scheduling, fences, or power-domain control;demand.set_active(true)andreport_busy(now)still run unconditionally; sleep/wake (sleep_upbumpsstatistics_epochand invalidates telemetry, andsleep_quietrequires idle pastIDLE_HOLD_NS = 16 ms) and recovery (service_runtime_recoveryinvalidates statistics) remain intact.- Cross-generation scope: touches only
drivers/gpu/drm/asahi/g17/(M4/A18 Pro G17P and M5 G17M5). G13/G14/G15/G16/G18/M3 are untouched. - Non-blocking nit:
drivers/gpu/drm/asahi/g17/port.rs:651,664usesOrdering::Relaxedforlast_submission_nsaroundstatistics_epoch.fetch_add(1, Ordering::Release);Acquire/Releaseonlast_submission_nswould strictly order the epoch bump before a concurrent lockless publisher observesrecent == true(worst case is at most one statistics sample, not a blocker).
- Commits & naming:
c56132f4and99b0b4cdboth carry human author/committer (Jonathan Goyvaerts) and humanSigned-off-by:, with clean commit messages and no banned naming. - CI at
99b0b4cd:Host tests / host-tests(SUCCESS),pr-readiness / readiness(SUCCESS),mergeable: MERGEABLE. - Hardware evidence:
- J616C (M4 Max / T6041, 25G83) same-machine A/B at
99b0b4cd5fea(comment):vkQueueSubmitp50-31.3%(17,042 ns->11,708 ns),0failed units,0GPUdmesgerrors across 5,500 dispatches. - Author J616s (M4 Pro / T6040) segment measurements and dEQP-VK sync/sync2 conformance (
5,779 Pass,0diffs) were collected on composite kernels (m4.179/m4.185) rather than exact head99b0b4cd. - M5: untested at
99b0b4cd.
- J616C (M4 Max / T6041, 25G83) same-machine A/B at
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge at 99b0b4cd5fea: the code is ready; it needs one more row.
Blockers: none in the code. Missing row: this is G17 code shared by the M4 and M5 generations, so before it merges it also needs one M5 run at this head (where agx_stats is active and the same 2 ms rule applies): the same submit A/B with 0 GPU errors. We'll run it on our J714s.
Checked: no Apple material, no gates. The J616C (M4 Max) A/B at this head: vkQueueSubmit p50 17,042 → 11,708 ns, round trip unchanged, 0 GPU errors over 5,500 dispatches.
Superseded by the review at 99b0b4c
|
J714s (M5 Pro, T6050) row at Kernel: one combined candidate Submit A/B, default vs candidate: gpubench-vk, headless, pinned to CPU 12, untimed, compute.light depth 1, 5 windows of 400 ms.
Health on the candidate boot: 0 oops or WARN, 0 GPU recoveries over the whole boot, 0 DART faults. Its err-level lines at boot are the default's set minus one line (the lane-count message that 2068 removes), so 0 new. Failed units: only |
Bring in main up to a73023b (among others the G17 submit-latency, compute completion fast path, completion cluster and page-fault blame work). Conflict: - drivers/gpu/drm/asahi/g17/runtime/events.rs: main now drains the trace and statistics reports after the pass's completions are signalled on every G17 (c56132f, from #2909), where it was M5 only. This branch throttles that post-signal drain to the housekeeping cadence while work is in flight and drains first on a recovery pass, through drain_post_signal_reports(), which drained on M5 only because only M5 deferred the reports. As every G17 defers them now, the helper and its is_m5() check go away and the throttled sites call drain_reports() directly, as planned when this branch was reconciled with #2909. g17-m5-direct-compute-tests.py checks the same order under the new name. Signed-off-by: Diljit Singh <[email protected]>
Each completion pass in run_runtime_events() / runtime_event_turn() previously took the global device mutex (shared.state) up to five times and ran M5 firmware.drain_reports() (trace/statistics rings plus GPU power register reads) on every completion interrupt, even during tight compute loops where no render mask was pending. Coalesce the worker_deferred take and empty-batch restore into the existing device-mutex holds, avoid dropping and immediately re-acquiring shared.state around a no-op observe_renders() when render masks are zero, and throttle M5 post-signal report draining (drain_post_signal_reports()) to the HOUSEKEEPING_NS (1 ms) cadence while work remains in flight. On recovery passes, drain post-signal reports before service_runtime_recovery() resets firmware rings (matching the unthrottled post-signal ordering and aurora-silicon#2909) without double-draining in housekeeping. Add host tests (g17-m5-direct-compute-tests.py) covering mixed render/compute ring wrap, generation-change queued-claim handling, concurrent direct/scoped credit safety, and post-signal/pre-recovery report ordering. Signed-off-by: Diljit Singh <[email protected]>
What: Two cuts on the G17 depth-1 submit -> completion path. G17P now signals completions before it drains the firmware's trace and statistics reports, which M5 already does. And a publication skips the core-power MMIO read when the previous one was less than the firmware's 2 ms idle-off delay ago.
Tested: J616C M4 Max (T6041) at 99b0b4c, thanks to @AxxzyWasTaken: same-machine A/B vs integration/aurora, untraced
vkQueueSubmitp50 17,042 -> 11,708 ns, depth-1 round trip unchanged (+0.5%), 0 failed units, 0 GPU dmesg errors over 5,500 dispatches. J616s M4 Pro (T6040) on test kernels carrying the same two patches (commit 1 identical; commit 2 without thereport_busy()merge line): the drains now follow the fence, 5 core-power reads in 18,594 direct publications, dEQP-VK synchronization + synchronization2 6,213 cases with 0 differences from baseline, 0 GPU recoveries, 0 failed units, 0 new kernel errors. No SELinux or AppArmor is loaded on these kernels.Risk: two-way door · M4 (G17P) and M5 (G17M5):
drivers/gpu/drm/asahi/g17/only; G13-G16, G18 and M3 untouched.Not yet: an M5 row at 99b0b4c (0 failed units, 0 new kernel errors, and agx_stats behaviour across idle gaps around 2 ms, since commit 2 applies the 2 ms rule there and M5's idle-off delay has not been measured); agx_stats across idle gaps on an M4 that reports it (T6041 reports
unsupporteduntil #2864).Details
1. drm/asahi: g17: signal G17P completions before draining reports
Every G17P event pass drained the trace and statistics rings, with a core-power observation (an MMIO read) around the statistics drain, before it read the event rings, so every completion's fence waited for that work. M5 already reads the event rings first and drains the reports in the worker's next locked step (47f1155, "drm/asahi: g17: Reduce M5 job completion latency"): the reports are not scheduling inputs. This drops the
is_m5()gate so every G17 uses that order, and removes the per-roleTransporthooks only the old order used (-38/+6).2. drm/asahi: g17: read the core power register only after an idle-off gap
Every publication read
G17_CORE_POWER(about 0.3 us, ahead of the doorbell) to notice a core gating before its work wakes the cores. The firmware gates the cores only afterpower::FIRMWARE_IDLE_OFF_MSof idle after the last job, and that job completes after its own publication, so a publication within that gap of the previous one cannot follow a gating; the read is now skipped then. The same constant already models the firmware's idle-off infeed.rsand the idle hold; the firmware does not report it, so there is no machine property to read instead. Only the statistics decoder (agx_stats) consumes this epoch;demand.set_active()andreport_busy()still run on every publication. Known limit, named in a code comment: a direct publisher notes itself before it may fall back to its scheduler, so a fallback published past the delay can miss one gating, costing one statistics sample.Evidence
J616s (M4 Pro, T6040, 25G83), gpubench compute.light depth 1 pinned to a P-core. The "before" kernel had no CPU PMU, so the costs are timed with kprobes at raw
asahi.kooffsets (about 250 ns per probe hit, subtracted) and with the driver's counter-stampedasahi_g17tracepoints.Port::note_gpu_activitycalled fromcompute_directThe two J616s test kernels also carry other submit-path changes, so their end-to-end numbers are not compared; the J616C A/B above is the same-machine end-to-end row (its idle-gap sweep across 0-5 ms gaps is in its comment).
Conformance (J616s, same two patches, with the bystander-blame recovery fix): dEQP-VK synchronization + synchronization2, all 6,213 cases, one deqp-vk process per chunk: 5,779 Pass, 434 NotSupported, 0 cases differ from the stored baseline of the same Borealis build (m4/next c356a1498), 0 GPU recoveries.
KUnit (arm64 qemu, asahi + SEP + ISP suites) on this branch: 741/742, 1 skip as before. checkpatch: 0 errors, 0 warnings.