Skip to content

drm/asahi: g17: signal G17P completions before draining reports; skip the core power read on back-to-back work - #2909

Merged
DjDeveloperr merged 2 commits into
aurora-silicon:mainfrom
jgoyvaerts:m4pro/g17-submit-latency
Nov 24, 2026
Merged

DjDeveloperr merged 2 commits into
aurora-silicon:mainfrom
jgoyvaerts:m4pro/g17-submit-latency

Conversation

@jgoyvaerts

@jgoyvaerts jgoyvaerts commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

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 vkQueueSubmit p50 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 the report_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 unsupported until #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-role Transport hooks 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 after power::FIRMWARE_IDLE_OFF_MS of 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 in feed.rs and 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() and report_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.ko offsets (about 250 ns per probe hit, subtracted) and with the driver's counter-stamped asahi_g17 tracepoints.

before after
Event pass order trace drain, power read, statistics drain, power read, then the completion record (~1.5 us gross) output fence 2.4 us after pass entry, the drains after it (99% of 21,700 passes)
Event pass entry -> first completion record (tracepoint counters) 2,542 ns 2,375 ns
Port::note_gpu_activity called from compute_direct ~0.38 us net ~0.08 us net
Core-power register reads per direct publication 1 5 in 18,594 (the first after idle)

The 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.

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]>
@AxxzyWasTaken

Copy link
Copy Markdown
Contributor

J616C (MacBook Pro 16" M4 Max, T6041, 32-core 25G83) same-machine headless depth-1 Vulkan compute latency A/B at 99b0b4cd5fea (7.3.0-j616c-pr2909+) vs integration/aurora (e0a9448a75df, 7.3.0-j616c-int-aurora), identical Borealis Vulkan 1.4 (Mesa 26.3.0-devel git-1fa0b69be2), pinned to P-core cpu0, untraced (4,000 iters + 200 warmup; ssbo_count_ok: true on all runs):

Metric Base (int-aurora) #2909 (99b0b4cd5fea) Delta
Untraced vkQueueSubmit p50 17,042 ns 11,708 ns -5,334 ns (-31.3%)
Untraced vkQueueSubmit mean 16,720.5 ns 11,911.0 ns -4,809.4 ns (-28.8%)
Untraced vkWaitForFences p50 554,566 ns 562,834 ns +8,268 ns (+1.5%) (low-P-state jitter)
Untraced depth-1 RTT p50 571,108 ns 574,126 ns +3,018 ns (+0.5%)

Idle-gap vkQueueSubmit p50 sweep (300 iters/step across FIRMWARE_IDLE_OFF_MS = 2 ms):

Inter-submit gap Base vkQueueSubmit p50 #2909 vkQueueSubmit p50 Delta
0 µs 16,559 ns 13,850 ns -2,709 ns (-16.4%)
500 µs 18,017 ns 12,392 ns -5,625 ns (-31.2%)
1500 µs 25,208 ns 20,000 ns -5,208 ns (-20.7%)
3000 µs 26,267 ns 22,602 ns -3,665 ns (-14.0%)
5000 µs 25,708 ns 22,792 ns -2,916 ns (-11.3%)
  • Health: 0 failed systemd units, 0 GPU dmesg errors across all 5,500 dispatches. (Note: agx_stats reports unsupported on T6041 until #2864 lands, so the agx_stats validity check across 0..5 ms gaps wasn't exercised here.)

Assisted-by: LLM (Google:Gemini 4 Neon)

DjDeveloperr added a commit that referenced this pull request Nov 23, 2026
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]>
DjDeveloperr added a commit that referenced this pull request Nov 23, 2026
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]>
DjDeveloperr added a commit that referenced this pull request Nov 24, 2026
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]>
@jgoyvaerts
jgoyvaerts marked this pull request as ready for review November 24, 2026 16:04
@jgoyvaerts
jgoyvaerts requested review from a team and DjDeveloperr as code owners November 24, 2026 16:04
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Merge readiness at 99b0b4cd: ready to merge

Check Detail
CI at head ok 2 checks passed
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok in the PR body at 99b0b4cd
Conflicts ok none
PR text ok Risk: two-way · M4 (G17P) and M5 (G17M5): drivers/gpu/drm/asahi/g17/ only; G13-G16, G18 and M3 untouched.

Areas: area:gpu
Merge: gh pr merge 2909 --merge (Owners and Core through the bypass: add --admin).

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: HOLD at 99b0b4cd
Blockers:

  1. 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: and Risk: lines per policy/pr-structure.md).
  2. Hardware evidence (§5): drivers/gpu/drm/asahi/g17/port.rs and drivers/gpu/drm/asahi/g17/runtime/events.rs are shared across M4 (G17P) and M5 (G17M5), and commit 99b0b4cd applies the 2 ms FIRMWARE_IDLE_OFF_MS skip rule on M5 where agx_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 at 99b0b4cd, but a second-generation M5 regression row at 99b0b4cd (0 failed units, 0 new kernel errors, 0 SELinux denials, plus agx_stats behavior 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 the is_m5() gate (reports_after_signal) and dead event::Transport::{trace,statistics} hooks so all G17 variants signal compute completions (deferred.finish()) before Firmware::drain_reports(). Verified runtime_event_turn is the sole caller of service_runtime_events; drain_reports() runs under self.state.lock() after checking detachment and self.crashed, only accesses Firmware-owned status/ring memory (no client/VM/BO lifetime hazards), runs before service_runtime_recovery(), and remains serialized with stats::Reader::read_firmware(). Running drain_reports() on control-ring backpressure early returns is safe and avoids report-ring buildup.
    • 99b0b4cd (drivers/gpu/drm/asahi/g17/port.rs): skips the g17_core_power() MMIO read in Port::note_gpu_activity() when now.saturating_sub(previous) < FIRMWARE_IDLE_OFF_MS * 1_000_000. Verified statistics_epoch is consumed only by agx_stats telemetry (observe_statistics_power), never scheduling, fences, or power-domain control; demand.set_active(true) and report_busy(now) still run unconditionally; sleep/wake (sleep_up bumps statistics_epoch and invalidates telemetry, and sleep_quiet requires idle past IDLE_HOLD_NS = 16 ms) and recovery (service_runtime_recovery invalidates 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,664 uses Ordering::Relaxed for last_submission_ns around statistics_epoch.fetch_add(1, Ordering::Release); Acquire/Release on last_submission_ns would strictly order the epoch bump before a concurrent lockless publisher observes recent == true (worst case is at most one statistics sample, not a blocker).
  • Commits & naming: c56132f4 and 99b0b4cd both carry human author/committer (Jonathan Goyvaerts) and human Signed-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): vkQueueSubmit p50 -31.3% (17,042 ns -> 11,708 ns), 0 failed units, 0 GPU dmesg errors across 5,500 dispatches.
    • Author J616s (M4 Pro / T6040) segment measurements and dEQP-VK sync/sync2 conformance (5,779 Pass, 0 diffs) were collected on composite kernels (m4.179/m4.185) rather than exact head 99b0b4cd.
    • M5: untested at 99b0b4cd.

@github-actions github-actions Bot added changes-requested A reviewer requested changes (bot) blast:m3 Macs affected, from Merge risk (bot) blast:m4 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) and removed needs-template PR body lacks Tested or Risk (bot) labels Nov 24, 2026

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@DjDeveloperr
DjDeveloperr dismissed their stale review November 24, 2026 21:01

Superseded by the review at 99b0b4c

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed changes-requested A reviewer requested changes (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 24, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor

J714s (M5 Pro, T6050) row at 99b0b4cd5fea: PASS

Kernel: one combined candidate 94ea5d0cb4ec (tree 3c2a50b08e3c) = main 065904c137fa + PRs 2909, 2227, 2217, 2068, 2870 and 2954 at their exact heads, merged in that order with no conflicts and the PR commits unchanged. Built natively on the M5 as 7.3.0-m5-fb4 and booted with the default's DTB, Stage 2 and command line (MTE on, SEP writes on). Baseline: the M5 default 7.3.0-m5-cdirect14, same Mesa.

Submit A/B, default vs candidate: gpubench-vk, headless, pinned to CPU 12, untimed, compute.light depth 1, 5 windows of 400 ms.

default candidate
time inside vkQueueSubmit (submit_cpu_us), median 11.12 us (p5 9.83, p95 11.96, n 18,293) 9.54 us (p5 9.27, p95 9.92, n 18,535)
round trip (latency_us), median 102.31 us 102.34 us
us_per_submit 109.29 107.93
idle.wake, 1 ms gap (below the 2 ms rule) 81.6 us 88.1 us
idle.wake, 3 ms gap (above it) 353.1 us 369.7 us
  • vkQueueSubmit -1.58 us (-14%), round trip unchanged. The idle.wake rows are single runs.
  • agx_stats across the gaps read the same on both kernels at every step: valid with 0 utilisation before and after compute.light, utilisation_status unavailable (pstate 13, 1.62 GHz) right after the 1 ms-gap run, valid again after the 3 ms run. The 2 ms rule changed nothing there.
  • 0 GPU kernel lines during the runs.
  • The baseline is the M5 default kernel, not main without this PR.

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 tailscaled.service, which fails on the default too. LSMs capability,landlock: no SELinux or AppArmor, 0 avc: lines.

@DjDeveloperr
DjDeveloperr merged commit 4f3cd6f into aurora-silicon:main Nov 24, 2026
7 checks passed
DjDeveloperr added a commit that referenced this pull request Nov 25, 2026
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]>
funkzy pushed a commit to funkzy/linux that referenced this pull request Nov 25, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gpu Area from CODEOWNERS (bot) blast:m3 Macs affected, from Merge risk (bot) blast:m4 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants