Skip to content

drm/asahi: g17: batch report-ring drains and skip redundant render re-observe - #3428

Merged
RyanTheTide merged 2 commits into
mainfrom
perf/g17-batch-report-drain-fast-hk
Nov 28, 2026
Merged

RyanTheTide merged 2 commits into
mainfrom
perf/g17-batch-report-drain-fast-hk

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

What:
Cut device-mutex hold time in the G17 event worker's housekeeping passes.

  • Rings::consume_report() (channel.rs, trace.rs) now advances the write-combined consumer_word once per drain, between two SeqCst barriers, instead of a barrier plus an uncached store for every trace or statistics record. On an invalid record tag the valid prefix already drained is flushed before Err(EIO) is returned.
  • With the asahi_g17_report tracepoint off, trace records read only their 1-word tag (trace::report_enabled(), status_read_words::<1>) instead of copying 18 uncached payload words that are thrown away.
  • runtime/events.rs: try_fast_observe_render() now runs before unlocking even when housekeeping was requested (requested is passed into housekeeping_due()), so ready renders retire and signal their fences at deferred.finish() before housekeeping. When render_clean && !recover, the handled masks are cleared so the slow path does not re-enter drain_render_deferred() / observe_renders() for renders already retired; render_rescan poll arming is kept.
  • New host test tools/asahi/g17-report-drain-tests.py (4 contract mutations).

Tested:

  • J714s M5 Pro (G17S B1), candidate 7.3.0-m5-pr67 that carries 6481baa unchanged (same patch-id), stacked with drm/asahi: g17: expand single-pair M5 render depth to 64 #3411 and the first commit of drm/asahi: g17: allow compute_direct() on mixed render/compute contexts #3429, origin/main DTB: VK CTS 594/594 passed, 0 failed (occlusion_query 152/159 with 7 not supported, synchronization2 *read_image_compute* 412/412, synchronization smoke 12/12, multiview queries 16/16, concurrent_queries 2/2); gpubench-vk compute.cull_mdi CRC valid, d2 submit CPU time 26.85 -> 23.48 us; GTA V Enhanced 3024x1964 Very High TAA, 10 s trace: GPU busy 97.658% -> 97.765% (idle 234.25 -> 223.49 ms), P4 57.92 -> 58.03 FPS; 0 GPU faults, WARNs or errors.
  • J700 MacBook Neo (G17P B1) at exact head 6481baa: VK CTS 31,611 passed, 6,275 not supported, 0 failed, 0 recoveries (row in the comments).
  • Host tests 243/243 g17-* passed; checkpatch.pl --strict 0 errors, 0 warnings, 0 checks.

Risk: two-way · G17 Macs (M5 Pro, Neo)

Not yet:

  • The J714s row above used origin/main DTBs, which boot with the SLC off on that Mac; the FPS and GPU-busy deltas are relative to a base taken the same way.

…-observe

Rings::consume_report() drains firmware trace (up to 512 slots) and
statistics (up to 256 slots) rings from write-combined firmware memory
while holding the device mutex during periodic housekeeping. Currently it
copies all 18 words per trace record even when asahi_g17_report tracing is
disabled (discarding words 1..18 after validating words[0]) and issues a
full SeqCst barrier and write-combined consumer store (plus a second
SeqCst barrier on trace rings) for every individual record. Under
render-heavy workloads after >= 1 ms passes, a single housekeeping turn
can hold the device mutex and stall the event worker for 180-570 us.

Batch consumer advancement in consume_report() to a single SeqCst-bracketed
consumer_word store per drain (flushing any drained valid prefix before
returning EIO on a bad tag), and read only the single tag word for trace
records when asahi_g17_report is disabled.

In runtime_event_turn(), run try_fast_observe_render() before unlocking for
deferred.finish() even when requested housekeeping is set, and clear the
consumed render masks when try_fast_observe_render() succeeds so the slow
housekeeping path skips redundant drain_render_deferred() and
observe_renders() device-mutex round-trips while preserving rescan poll
arming.

Add compiled host contract tests and mutations in
tools/asahi/g17-report-drain-tests.py.

Signed-off-by: DjDeveloperr <[email protected]>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 27, 2026 18:50
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 27, 2026
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Merge readiness at c7e48c24: not ready yet

Check Detail
CI at head no failing: pr-text / pr-text
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok comment at c7e48c24
Conflicts ok not computed yet
PR text ok Risk: two-way · G17 Macs (M5 Pro, Neo)

Areas: area:gpu

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

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J700 (MacBook Neo, Apple A18 Pro T8140 / G17P B1, second generation) exact-head kernel verification row at 6481baa33c340f9abc071434c69c454b089c240e: PASS (no regression, 0 failures, 0 GPU faults/recoveries).

  • Tree & host tests (7.3.0-neo-pr3428, exact head 6481baa33c340f9abc071434c69c454b089c240e):
    • python3 tools/asahi/run-host-tests.py --only g17- passed 243/243 (13 s), including g17-report-drain-tests and all 4 mutations (per-record-store, always-read-full-trace, drop-partial-error-flush, keep-stale-render-masks).
  • Setup & identity:
    • Built from exact head 6481baa33c340f9abc071434c69c454b089c240e with stock 7.3.0-41 config + LOCALVERSION=-neo-pr3428 (0 build errors, 2,002 modules).
    • Booted via one-shot grub2-reboot only with a 10-minute fallback timer; default entry remained 7.3.0-41.fc44.aurora.aarch64. System Mesa, stock kernel command line (0-byte diff vs stock).
    • Verified on boot (f7085e46): uname -r = 7.3.0-neo-pr3428, kernel build ID a8b9f58497914c785e99b404e34f911847218304 (MATCH), aurora.ko build ID 3f5283af41f43c325a381e3cf1f6e11431321639 (MATCH).
  • VK CTS (6 jobs, 37,886 cases in 184 s): 31,611 Pass, 6,275 NotSupported, 0 Fail, 0 recoveries (gate rc 0):
    • dEQP-VK.synchronization{,2}.* (basic, smoke, single-queue, timeline semaphore, implicit, none_set_reset, internally synchronized objects, plus all synchronization2.*_read_image_compute*): 31,242 Pass, 6,178 NotSupported, 0 Fail (of which synchronization2.*_read_image_compute* is 5,100 Pass, 5,806 NotSupported, 0 Fail).
    • dEQP-VK.compute.pipeline.basic.*: 79 Pass, 2 NotSupported, 0 Fail.
    • dEQP-VK.api.command_buffers.*: 65 Pass, 66 NotSupported, 0 Fail.
    • dEQP-VK.renderpass{,2}.suballocation.subpass_dependencies.*: 73 Pass, 22 NotSupported, 0 Fail.
    • dEQP-VK.query_pool.occlusion_query.copy_*: 152 Pass, 7 NotSupported, 0 Fail.
  • gpubench-vk (fdf4dd6, system Mesa, 21/21 rows ok, all CRCs matched same-slot stock 7.3.0-41 pre-boot baseline):
    • render.light d1/d8/d32: ok, us/sub 131.6 / 31.1 / 29.2 µs, submit_cpu 18.9 / 16.7 / 15.6 µs (stock 111.6 / 30.5 / 29.2 µs).
    • render.deferred (tile msaa=4 1080p d1/d2): 5e4130ce (match), GPU 10610.3 / 10531.2 µs (stock 10828.5 / 10932.0 µs).
    • render.postfx (msaa=4 1080p d1/d2): 668d6f0a (match), us/sub 773.2 / 569.3 µs (stock 781.2 / 598.8 µs).
    • render.pass_chain (all_bar d1/d4): 93411763 (match), us/sub 551.5 / 370.8 µs (stock 519.0 / 453.9 µs).
    • render.pass_chain (oq_bar d1/d4): 93411763 (match), us/sub 849.9 / 1293.1 µs (stock 785.3 / 835.7 µs).
    • render.mdi (draws=1024 bindless=1024 d1/d4): 3ba813b3 (match), us/sub 509.3 / 143.3 µs (stock 462.2 / 160.4 µs).
    • compute.heavy (alu d1/d4): ok, us/sub 1351.4 / 1181.1 µs (stock 1363.6 / 1234.6 µs).
    • compute.light d1/d8: ok, us/sub 107.6 / 16.9 µs (stock 104.8 / 19.8 µs).
    • compute.cull_mdi d1/d2/d4: 57276de2 (match), us/sub 9677.4 / 1973.7 / 1886.8 µs, submit_cpu 67.1 / 8.3 / 10.7 µs (stock 5172.4 / 2127.7 / 2000.0 µs).
    • sync.signal (compute.light d1): ok, latency p5/med/p95 137.9 / 152.5 / 163.8 µs (stock 133.2 / 142.9 / 154.0 µs).
    • Note: stock 7.3.0-41 predates the PR base (aa3351bc8e6f2), so this row serves as a second-generation correctness/CRC/stability verification rather than a merge-base perf A/B.
  • Kernel health & restore:
    • 0 GPU faults/recoveries, 0 MMU faults, 0 WARN/BUG/Oops/stack-overflow/KASAN/lockup/RCU-stall/timeout lines, 0 new kernel error lines, 0 AVC denials, 0 failed units, 0 core dumps.
    • Restored cleanly to stock 7.3.0-41.fc44.aurora.aarch64 (boot 796600ae, PMU f701/f702 = 30 00); trial /boot, /lib/modules, BLS entry, and fallback timer removed, stock.sh POST vs PRE diff = 0 bytes.

@github-actions github-actions Bot added blast:m5 Macs affected, from Merge risk (bot) blast:neo Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) and removed needs-hw-row No hardware row at the PR head (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 27, 2026
The org licenses its new tooling GPL-2.0-only; drop the MIT alternative
from the new host test's SPDX line.

Signed-off-by: DjDeveloperr <[email protected]>

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Verdict — hold for the J714s hardware row at c7e48c245f48. No blocking code findings. The only change since 6481baa33c34 corrects the host test's SPDX identifier. The J700 exact-head result at that parent carries forward (31,611 CTS passes, zero failures).

The recorded J714s candidate 7.3.0-m5-pr67 has tip 6bd9c511315f. It tested cherry-pick 39479d108938, which has the same patch ID and different surrounding code in drivers/gpu/drm/asahi/g17/runtime/events.rs. Please record a J714s run from the reviewed kernel or a candidate containing its head.

I checked producer bounds and wraparound, the barriers around consumer publication, the valid-prefix flush on a bad tag, and retained render masks across fallback, rescan and recovery. The report-drain host test passed locally. All 20 checks, including the replacement pr-text run, passed on 6481baa33c34.

@github-actions github-actions Bot added the needs-hw-row No hardware row at the PR head (bot) label Nov 28, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J714s (MacBook Pro M5 Pro, T6050 / G17S B1) exact-head correctness row at c7e48c245f4852579cf29d8a69e228097940e902: PASS, 0 failures, 0 GPU faults, 0 recoveries.

  • Kernel 7.3.0-m5-pr3428, built on the M5 from the exact head tree (f9af4f6331e4) with the default's config. One trial boot; the default 7.3.0-m5-cdirect16 was restored afterwards with all 253 ESP files byte-identical.
  • SLC on: the boot used this tree's own t6050-j714s.dtb with only the MCC node's status set to okay. The kernel log showed apple-mcc ... system level cache allocation enabled on 16 planes.
  • Vulkan CTS (deqp-vk 1.4.7.1, Mesa kit inst-A), 0 failed:
    • synchronization.smoke.* 12/12, synchronization.basic.* 29/29
    • synchronization2.op.single_queue.barrier.*_read_image_compute* 412/412
    • query_pool.occlusion_query.copy_* 152 passed, 7 not supported; query_pool.concurrent_queries.* 2/2
    • multiview.queries.* 16/16, pipeline.monolithic.timestamp.basic_graphics_tests.* 80/80
    • api.copy_and_blit.core.image_to_image.simple_tests.* 19 passed, 4 not supported
  • gpubench-vk (ae90a40, 3x500 ms): compute.cull_mdi CRC 07f6c861 valid at d1 and d2; chainbench_diag ran clean.
  • GPU health before and after: online, 0 crashed, 0 quarantined, drained render pairs 0 failures / 0 recovered, no render kills, no GPU fault or recovery lines in the kernel log.

@github-actions github-actions Bot removed the needs-hw-row No hardware row at the PR head (bot) label Nov 28, 2026

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: MERGE at c7e48c24

Blockers: none (re-run the cancelled pr-text and readiness checks before landing; 20/20 build/host/KUnit checks green and exact-head J700 + J714s rows PASS).

Checked:

  • c7e48c24 corrects only the host test's SPDX identifier (GPL-2.0-only) on top of 6481baa3 (batching G17 report-ring drains and skipping redundant render report reads).
  • Tests & exact-head hardware rows across two G17 generations: run-host-tests.py --only g17- 243/243 pass; J700 (A18 Pro / G17P) 31,611 CTS pass, 0 failures, 0 GPU faults; J714s (M5 Pro / G17S) exact-head c7e48c24 PASS, 0 failures, 0 GPU faults; 20/20 build/host/KUnit CI checks green.
  • Checked for Apple material, tool attribution, private serials, and gating: clean; MERGEABLE on main.
Evidence
  • Head: c7e48c245f48 (base: main, mergeable: MERGEABLE, +399/-30 across 6 files).

@RyanTheTide

Copy link
Copy Markdown
Contributor

code-owner ping <@422957901716652033> / @DjDeveloperr: merge train at c7e48c24. The review App approved this head (NEON-PR-REVIEW2's adversarial pass). Rows: J700+J714s. This merges under the 6-point rule 1 h from now, once hosted CI is green, unless you object.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merging under the 6-point rule (Ryan 09:29, permanent), at c7e48c24. (1) The review App approved at this head. (2) Full CI is green. (3/4) Rows: J700+J714s. (5) There's no blocking review. (6) Dj was pinged here 118 min ago with no objection. Revert: git revert -m 1 <merge>.

@RyanTheTide
RyanTheTide merged commit 1ce2809 into main Nov 28, 2026
21 of 24 checks passed
@RyanTheTide
RyanTheTide deleted the perf/g17-batch-report-drain-fast-hk branch November 28, 2026 14:01
Isaac-Duarte added a commit to Isaac-Duarte/linux that referenced this pull request Nov 28, 2026
On M5 Pro (J714s / T6050), ordinary desktop, browser, and video
workloads with <1% GPU utilization trigger the G17 CPU feed detector
and pin all CPU clusters at 100% max frequency (~4.38 GHz / ~4.61 GHz)
~33-74% of the time. Three interactions cause this:

1. Commit 6cfa2da ("drm/asahi: g17: provide syncobj wait hint on
   GPU-bound streams") raised the shared LINGER_NS constant from 8 ms to
   20 ms so bound_until covers a full 60 Hz frame. That also stretched
   the CPU-floor deadline (`until`) to 20 ms, longer than both 60 Hz
   (16.67 ms) and 120 Hz (8.33 ms) frame periods, so periodic frame
   bursts continuously renew a 100% CPU frequency floor across idle
   frames.

2. A single GPU-wide `last_end`/`streak` merges unrelated DRM contexts
   (e.g., compositor, browser, video player). Staggered paced clients
   whose individual bursts last 1-3 ms chain across each other into
   30-80+ pass global bursts without resetting `streak`.

3. `STREAK_ON = 8` fires on pass count alone regardless of elapsed run
   duration, so a short multi-pass UI redraw raises the CPU floor for
   20 ms.

Track refill-bound streaks per DRM context in a 16-slot LRU `Tracker`
under its own spinlock (updated in `Feed::note_pass(context, start,
end)` after fence signalling, off the wakeup critical path) while
keeping `Detector` deadline/worker state lock-free with monotonic
saturating `fetch_max` deadlines and `SeqCst` wake handoff:
- Split `LINGER_NS` into `FEED_LINGER_NS = 8_000_000` (8 ms for `until`)
  and `BOUND_LINGER_NS = 20_000_000` (20 ms for `bound_until`).
- Scale `Tracker::new(counter_hz)` thresholds from `Feed`'s firmware
  command timestamp rate (disabling detection when `counter_hz == 0`)
  and require a sustained per-context run spanning at least
  `FEED_MIN_RUN_PER_SEC` (`counter_hz / 125`, 8 ms) before emitting
  `Sample::RefillBound` so transient frame bursts stay unboosted.
- Measure `gpu_idle` against `global_last_end` while crediting actual
  busy duration on partially overlapping parallel waves (`start <
  global_prev && end > global_prev`), drop fully subsumed intervals
  (`end <= global_prev`), and use saturating arithmetic in `decay_add`.

Validation (rebased onto main across aurora-silicon#2393 Policy/counter_hz and aurora-silicon#3428):
- Host tests (`run-host-tests.py --only g17`, Rust 1.100.0): 255/255
  pass, including `g17-feed-burst-tests.py` and all 7 mutations.
- KUnit (`arm64` QEMU, `KUnit asahi`): `asahi_g17_feed_detector` 13/13
  pass (including `zero_counter_hz_never_detects_refill_or_bound`).
- Full driver build (`LLVM=1 ARCH=arm64 drivers/gpu/drm/asahi/`): passes
  with `CONFIG_CPU_FREQ=y` and `CONFIG_UCLAMP_TASK=y`.
- Hardware rows (run on earlier identical detector logic prior to main
  aurora-silicon#2393 Policy refactor): J714s M5 Pro (`7.3.0-124e30a`) quiet-desktop
  A/B (`policy12` boost 33.15% -> 0.14%, `paced60/120` 99.6%/99.8% ->
  0.64%/0.00%, `gpu_bound` 48.2% -> 0.00%, `refill_d1` 98.5%), 8-loop
  `gpubench` vk/gl soak (232/232 ok, 12/12 fresh VK clients,
  `gpubench-stress-vk` 3/3 pass); J700 MacBook Neo (`G17P`) peer row
  (8/8 `gpubench-vk` soak, 10/10 fresh VK clients, `s2idle` pass).

Fixes: 6cfa2da ("drm/asahi: g17: provide syncobj wait hint on GPU-bound streams")
Signed-off-by: Isaac Duarte <[email protected]>
Isaac-Duarte added a commit to Isaac-Duarte/linux that referenced this pull request Nov 30, 2026
On M5 Pro (J714s / T6050), ordinary desktop, browser, and video
workloads with <1% GPU utilization trigger the G17 CPU feed detector
and pin all CPU clusters at 100% max frequency (~4.38 GHz / ~4.61 GHz)
~33-74% of the time. Three interactions cause this:

1. Commit 6cfa2da ("drm/asahi: g17: provide syncobj wait hint on
   GPU-bound streams") raised the shared LINGER_NS constant from 8 ms to
   20 ms so bound_until covers a full 60 Hz frame. That also stretched
   the CPU-floor deadline (`until`) to 20 ms, longer than both 60 Hz
   (16.67 ms) and 120 Hz (8.33 ms) frame periods, so periodic frame
   bursts continuously renew a 100% CPU frequency floor across idle
   frames.

2. A single GPU-wide `last_end`/`streak` merges unrelated DRM contexts
   (e.g., compositor, browser, video player). Staggered paced clients
   whose individual bursts last 1-3 ms chain across each other into
   30-80+ pass global bursts without resetting `streak`.

3. `STREAK_ON = 8` fires on pass count alone regardless of elapsed run
   duration, so a short multi-pass UI redraw raises the CPU floor for
   20 ms.

Track refill-bound streaks per DRM context in a 16-slot LRU `Tracker`
under its own spinlock (updated in `Feed::note_pass(context, start,
end)` after fence signalling, off the wakeup critical path) while
keeping `Detector` deadline/worker state lock-free with monotonic
saturating `fetch_max` deadlines and `SeqCst` wake handoff:
- Split `LINGER_NS` into `FEED_LINGER_NS = 8_000_000` (8 ms for `until`)
  and `BOUND_LINGER_NS = 20_000_000` (20 ms for `bound_until`).
- Scale `Tracker::new(counter_hz)` thresholds from `Feed`'s firmware
  command timestamp rate (disabling detection when `counter_hz == 0`)
  and require a sustained per-context run spanning at least
  `FEED_MIN_RUN_PER_SEC` (`counter_hz / 125`, 8 ms) before emitting
  `Sample::RefillBound` so transient frame bursts stay unboosted.
- Measure `gpu_idle` against `global_last_end` while crediting actual
  busy duration on partially overlapping parallel waves (`start <
  global_prev && end > global_prev`), drop fully subsumed intervals
  (`end <= global_prev`), and use saturating arithmetic in `decay_add`.
- Keep the GPU-bound streak device-wide, as before: busy contexts that
  alternate each wait longer than a refill gap between their own passes
  while the GPU never idles, so per-context streaks alone would drop the
  syncobj wait hint. Per-context streaks only gate CPU-floor requests.

Validation (rebased onto main across aurora-silicon#2393 Policy/counter_hz and aurora-silicon#3428):
- Host tests (`run-host-tests.py --only g17`, Rust 1.100.0): g17 host tests
  pass, including `g17-feed-burst-tests.py` and all 8 mutations.
- KUnit (`arm64` QEMU, `KUnit asahi`): `asahi_g17_feed_detector` 13/13
  pass (including `zero_counter_hz_never_detects_refill_or_bound`).
- Full driver build (`LLVM=1 ARCH=arm64 drivers/gpu/drm/asahi/`): passes
  with `CONFIG_CPU_FREQ=y` and `CONFIG_UCLAMP_TASK=y`.
- Hardware rows (run on earlier identical detector logic prior to main
  aurora-silicon#2393 Policy refactor): J714s M5 Pro (`7.3.0-124e30a`) quiet-desktop
  A/B (`policy12` boost 33.15% -> 0.14%, `paced60/120` 99.6%/99.8% ->
  0.64%/0.00%, `gpu_bound` 48.2% -> 0.00%, `refill_d1` 98.5%), 8-loop
  `gpubench` vk/gl soak (232/232 ok, 12/12 fresh VK clients,
  `gpubench-stress-vk` 3/3 pass); J700 MacBook Neo (`G17P`) peer row
  (8/8 `gpubench-vk` soak, 10/10 fresh VK clients, `s2idle` pass).

Fixes: 6cfa2da ("drm/asahi: g17: provide syncobj wait hint on GPU-bound streams")
Signed-off-by: Isaac Duarte <[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:m5 Macs affected, from Merge risk (bot) blast:neo Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants