Repository navigation
drm/asahi: g17: one CPU feed policy per generation; mailbox: key the RX clamp on a threaded handler - #2393
Conversation
The G17 CPU feed detector took its refill threshold from hw::t8140::qos::CLOCK_HZ, a T8140 constant, on every G17 SoC, and its per-generation differences were scattered: the CPU floor was chosen by an m5 flag inside the request code (100% vs 50%), the syncobj wait hint and the receive-thread level were file constants, and the M5 exclusion from the receive-thread clamp was a separate flag passed to the port. - The detector now takes the rate of the timestamps it is fed at creation, from the architected system counter (CNTFRQ_EL0) that the firmware command timestamps count and that the driver already reports as the timestamp frequency, and keeps its 2 ms refill limit in time. A zero rate disables refill detection instead of dividing by zero. - feed::Policy holds the floor, the wait hint and the receive-thread level while the GPU is the bottleneck, each with the commit that measured or introduced it. Policy::DEFAULT is the G17P policy (J700); Policy::M5 overrides only the two values the M5 work changed (full floor; receive thread left at its default, J775D). The port reads the receive-thread level from the policy instead of taking a flag. No value changes on any SoC. Fixes: d7d7747 ("drm/asahi: request temporary CPU capacity for sustained GPU feeds") Signed-off-by: Ryan Murray <[email protected]>
apple_mbox_set_rx_util_min() and the handler that applies it checked for the G17 GPU mailbox roles. What they need is a receive handler that runs in an IRQ thread: only then is there a thread whose minimum utilization can be set. Record that at probe in apple_mbox::rx_threaded and check it instead. Today only the G17 GPU coprocessors get a threaded handler (for their bounded receive batch), so behaviour is unchanged; any mailbox that is given a threaded handler later supports the clamp without another role check. The G13-G16 GPU mailboxes receive in hard IRQ context and hand GPU events to a driver work item that already sets its own minimum utilization, so they have no receive thread to clamp. Fixes: 564d91c ("soc: apple: mailbox: let a consumer set the receive thread's minimum utilization") Signed-off-by: Ryan Murray <[email protected]>
|
No blockers. I checked that no value changes. G17P keeps floor 50, the 512/8 ms wait hint and receive-thread level 256. M5 keeps floor 100 and the receive thread at its default: the port now always attaches the handle, and Nit: drivers/gpu/drm/asahi/g17/feed.rs:497-506: HW row: J616s and Neo, this branch on the default command line: gpubench 0dae261 Assisted-by: LLM (Claude:Opus 5.5) |
|
Merge-train note: this branch now conflicts in |
Conflicts: drivers/gpu/drm/asahi/g17/feed.rs (keep the PR's Policy and counter-rate Detector, integration's busy runs and firmware clock; the CLOCK_HZ import stays for the busy runs until the follow-up). Signed-off-by: Ryan Murray <[email protected]>
The busy runs integration added to the feed (note_work(), busy_run()) convert the firmware idle-off delay and the effort hold to ticks with hw::t8140::qos::CLOCK_HZ and read the clock at that rate. The feed now takes the rate of the firmware command timestamps at creation (the architected system counter); use it there as well, so no T8140 constant is left in the feed. Without a counter rate no run is reported busy, as the detector then detects no refill. No value change: every Apple SoC's system counter runs at 24 MHz. Signed-off-by: Ryan Murray <[email protected]>
|
Merged integration/aurora (f5f023b); conflict in drivers/gpu/drm/asahi/g17/feed.rs resolved (PR's Policy and counter-rate Detector kept alongside #2607's busy runs), plus a follow-up commit moving the busy runs from hw::t8140::qos::CLOCK_HZ to the feed's counter rate; drivers/gpu/drm/asahi/ and drivers/soc/apple/ (Rust, arm64 fleet config, LLVM) build with no new warnings. |
|
Rebased onto #2607 and CI is green. Still needed on this head: a Neo GPU row (dEQP-VK smoke plus the busy-run check), the J616s and Neo gpubench A/B against the base, and the feed detector and mailbox KUnit suites; also move gpu_bound_rx_util_min() above the gpu_bound() doc comment. |
There was a problem hiding this comment.
Formal pre-PR review (§1–§6) at 24be2afb988f7bd6ce71e7e4115815fefee56aef: REQUEST_CHANGES.
Blockers
- Correctness (§1/§2 — 41.67× clock-domain mismatch on every G17 SoC):
drivers/gpu/drm/asahi/g17/mod.rs:1728passesqos::clock().1(CNTFRQ_EL0) ascounter_hztofeed::Feed::new(), and the commits/PR body claim "every Apple SoC's system counter runs at 24 MHz" and "firmware command timestamps count the architected system counter (CNTFRQ_EL0)".- This is false on G17 SoCs (ARMv8.6+ Apple Silicon: T6040/T6041 M4, T8140 A18 Pro, T8142/T6050 M5):
CNTFRQ_EL0runs at 1 GHz (1_000_000_000Hz), whereas GPU firmware command timestamps passed toFeed::note_pass()andFeed::note_work()(g17/completion.rs:96,851,864-871) are stamped in the 24 MHz (24_000_000Hz) firmware clock domain. Bothdrivers/gpu/drm/asahi/g17/trace.c:109-115("24 MHz, while the CPU counter runs at 1 GHz on T6040 and T8140") anddrivers/gpu/drm/asahi/g17/qos.rs:379-389("Firmware accounting uses a 24 MHz domain independent of host timer speed") explicitly document and scale between these two domains. - Passing
CNTFRQ_EL0= 1 GHz breaks all three timing paths indrivers/gpu/drm/asahi/g17/feed.rsby 41.67×:Detector::max_refill_ticks = counter_hz / 500(feed.rs:104):2_000_000ticks = 83.33 ms (at 24 MHz) instead of 2 ms, misclassifying 60/120 Hz paced frames as refill-bound bursts.Feed::note_work()(feed.rs:188):idle_ticks = FIRMWARE_IDLE_OFF_MS * (self.counter_hz / 1000)becomes2_000_000ticks (83.33 ms instead of 2 ms).Feed::busy_run()(feed.rs:202-207):hold_ticks = IDLE_HOLD_NS * hz / 1_000_000_000becomes16_000_000ticks (666.7 ms at 24 MHz instead of 16 ms), ANDasahi_g17_firmware_clock(1_000_000_000)returns raw 1 GHzCNTVCT, whichBusyRuns::bound()(g17/power.rs:259) subtracts from 24 MHzrun.last_end— makingnow.saturating_sub(run.last_end)immediately exceedrun.last_busy + idle_ticksand permanently breakingbusy_run()after a few ms of uptime.
- Fix: Pass the firmware timestamp domain frequency (24 MHz — e.g., a G17 firmware timestamp frequency constant/config field rather than
CNTFRQ_EL0), and keep the compile-time/runtime domain invariant explicit.
- Doc-comment misplacement:
drivers/gpu/drm/asahi/g17/feed.rs:540-548insertsgpu_bound_rx_util_min()in the middle ofgpu_bound()'s doc comment, detachinggpu_bound()'s rustdoc ontogpu_bound_rx_util_min(). Movegpu_bound_rx_util_min()abovegpu_bound()'s doc block. - §5 (Missing exact-head hardware, perf A/B & KUnit evidence): Live head
24be2afb988f(post-#2607merge and commit24be2afb988f) has not been booted on hardware. After fixing the 24 MHz vsCNTFRQ_EL0bug above, provide on the new exact head (default cmdline):- Neo (T8140) and J616s (T6040): boot, dEQP-VK smoke + busy-run verification, same-machine
gpubenchA/B against base (within noise),asahi_g17_feed_detectorand mailbox KUnit passes, and regression gate (0 SELinux denials / 0 failed units / 0 new kernel errors).
- Neo (T8140) and J616s (T6040): boot, dEQP-VK smoke + busy-run verification, same-machine
Verified Clean
- Mailbox RX clamp (
drivers/soc/apple/mailbox.c,mailbox.h,mailbox-g17-test.h): Keyingapple_mbox_set_rx_util_min()andapple_mbox_recv_irq()onmbox->rx_threaded(set inapple_mbox_probe()exactly wheredevm_request_threaded_irq()is chosen) is clean and eliminates the G17 role gate in the clamp path. - §4 Attribution / §6 Naming / CI: All four commits carry human author/committer and
Signed-off-by:only (zero AI commit trailers); live CI (Host tests+SEP source checks) is green on24be2afb988f.
|
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: FINISH, then merge at 24be2afb988f
Blockers:
drivers/gpu/drm/asahi/g17/mod.rs:1728:feed::Feed::new(..., qos::clock().1)passesCNTFRQ_EL0as the counter rate for firmware command timestamps. On T6040 and T8140 that's 1 GHz, but the firmware stamps commands at 24 MHz; the tree says so itself ing17/trace.c:108-111("24 MHz, while the CPU counter runs at 1 GHz on T6040 and T8140"). So every durationnote_pass()/note_work()computes is off by about 41.7x on those SoCs. Fix: pass the firmware's 24 MHz time base (the rateasahi_g17_firmware_clock()converts to), and correct the commit message and body, which say every SoC's counter runs at 24 MHz.
Checked: no Apple material. One CPU feed policy per generation instead of per-chip copies, and the mailbox RX clamp keyed on a threaded IRQ. The J700 and J616s combined-kernel boots (GPU bound, 3 s2idle cycles, no drm/asahi or mailbox errors) show no crash. CI green. This replaces my earlier review.
Evidence
Checked qos::clock() (g17/qos.rs:325, it reads CNTFRQ_EL0) and asahi_g17_firmware_clock() at this head. After the fix, the row is one G17 Mac with the feed's computed pass times matching the firmware's.
Superseded by the review at 24be2af
Review follow-up. The feed was created with qos::clock().1, the CPU counter rate from CNTFRQ_EL0, as the rate of the firmware command timestamps. On T6040 and T8140 that counter runs at 1 GHz, but the firmware stamps commands at 24 MHz (see asahi_g17_firmware_clock()), so every pass and work duration note_pass() and note_work() computed was off by about 41.7x there. The earlier commit's "every Apple SoC's system counter runs at 24 MHz" was wrong for those SoCs. Pass COMMAND_TIMESTAMP_HZ, the 24 MHz the G17 completion path already converts firmware timestamps with. busy_run() reads the clock through asahi_g17_firmware_clock() at the same rate, so both sides agree again. Signed-off-by: Ryan Murray <[email protected]>
# Conflicts: # drivers/gpu/drm/asahi/g17/feed.rs # drivers/gpu/drm/asahi/g17/port.rs # drivers/soc/apple/mailbox.c
|
Row at No-change row on G13/G14. The G17 (Neo) pass-time row is still owed. DetailBoth rows ran on the default cmdline with the kernel booted once as a non-default entry, then back to fleet89, which was verified afterwards (saved entry, empty next_entry, kernel removed, 0 failed, Enforcing). Per Mac: SELinux Enforcing, 0 failed units, 0 AVC, 0 err-level kernel lines, 0 oops; Wi-Fi ping OK; s2idle (rtc1, 15 s) rc=0 with ping and a 64 MiB direct NVMe read after the wake; Apple SoC watchdog armed with time left counting (44 s and 58 s of systemd's 60 s); dEQP-VK |
|
Row at G17P at this head: GPU bound, dEQP-VK smoke pass, no mailbox/G17 error or recovery line. Still owed: the feed's computed pass times against the firmware's, which needs a feed trace this row didn't take. DetailNeo (J700, T8140/G17P), fixa2 booted once as a non-default BLS entry, then back to fleet89, verified afterwards (saved entry, empty next_entry, kernel removed, 0 failed, Enforcing). SELinux Enforcing, 0 failed units, 0 AVC, 0 oops, 0 err-level kernel lines; Wi-Fi up; G17P Vulkan device; dEQP-VK api.smoke 8/8 and draw.renderpass.simple_draw 4/4; watchdog armed (57 s left of 60); s2idle on rtc0 rc=0 with a 64 MiB direct NVMe read after the wake. Two lines are the same on fleet89 (baseline traced): the boot-time "G17: crash logs from the firmware data segment" note, and Wi-Fi needing ~9 s after the wake before ping answers. Logs: traces/kernel/20261127-fixa2-rows/neo/ (store). |
This branch makes Detector::new() take the command timestamp rate. Two tests that came with the main merge (gpu_bound_long_pass_lingers_ for_full_frame and the 60 Hz case of paced_or_short_runs_are_neither) still called it without one, so every KUnit build of asahi_core failed (E0061), which the fleet build does not compile. Pass CLOCK_HZ as the other tests do. Signed-off-by: Ryan Murray <[email protected]>
|
CI fix at 30a39db: the SEP and asahi KUnit jobs failed to build Tested: KUnit arm64 |
|
G17P row at this head (30a39db): A18 Pro (T8140, J700). The kernel was the combined fixa5 test kernel, linux main fca33ed plus the heads of #2887 #2959 #3384 #2919 #2393 #2895. Every file this PR changes is byte-identical to this head there, except Smoke:
Feed pass times: gpubench 0dae261
This compares against the default kernel, as the row asked, so it does not isolate this PR. fleet89 is main 645f7cd, 1100 commits (59 of them in g17/ or the mailbox) behind the fixa5 base fca33ed. The large shallow-queue gains and the small deep-queue costs fit those main changes. The feed policy values and the 24 MHz rate this PR uses are unchanged. I see nothing here that points at the feed change. Isolating the deep-queue +5-8 % would need a main-only kernel against main plus this PR. The on-device The Neo was restored to fleet89 and verified. Evidence (lab store): |
There was a problem hiding this comment.
Verdict: MERGE at 30a39db8
Blockers: none (re-run the cancelled readiness check before landing; 26/26 build/host/KUnit/pr-text checks green).
Checked:
drivers/gpu/drm/asahi/g17/feed.rs&g17/mod.rs: commit27766d38resolves the prior 41.67x clock-domain mismatch blocker by passing the firmware's 24 MHz timestamp rate (COMMAND_TIMESTAMP_HZ) rather thanCNTFRQ_EL0(1 GHz) intoFeed::new()/Detector::new(), and30a39db8updatesmain's new detector tests cleanly.- Per-generation
Policy(Policy::DEFAULTvsPolicy::M5) consolidatesfloor_percent,wait_util_min,wait_hint_ms, andgpu_bound_rx_util_minwith documented provenance; mailbox RX clamp keys on threaded handler capability instead of a chip gate. - Hardware rows & CI: exact-head J700 (G17P / A18 Pro) row plus M1 Pro and M2 Air regression rows PASS (
fixa5/fixa2); 26/27 CI green (MERGEABLEonmain). - Checked for Apple material, tool attribution, private serials, and gating: clean; human
Signed-off-bypresent.
Evidence
- Head:
30a39db8572b(base: main,mergeable: MERGEABLE,+144/-54across 6 files).
|
code-owner ping <@422957901716652033> / @DjDeveloperr: merge train at |
|
Merging under the 6-point rule (Ryan 09:29, permanent), at |
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]>
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]>
Problem
drivers/gpu/drm/asahi/g17/feed.rs:12-41(d7d7747) uses the T8140 constanthw::t8140::qos::CLOCK_HZas the timebase of the G17 CPU feed detector on every G17 SoC.m5flag inside the request code (feed.rs:165, d4879a4).port.rs:37(d266c70).clamp_rxflag (a48bc83).drivers/soc/apple/mailbox.c:919-945,979(564d91c) allows the receive-thread clamp only for the G17 GPU mailbox roles.Change
drm/asahi: g17: make the CPU feed one policy per generationCOMMAND_TIMESTAMP_HZ, 24 MHz, the rate the G17 completion path converts them with (not CNTFRQ_EL0, which is 1 GHz on T6040 and T8140). The 2 ms refill limit is now kept in time. A zero rate turns refill detection off.feed::Policyholds the floor, the syncobj wait hint and the receive-thread level used while the GPU is the bottleneck. A comment on each value names the commit that measured or introduced it.Policy::DEFAULTis the G17P policy, measured on J700.Policy::M5overrides only the two values the M5 work changed: a 100 % floor, and the receive thread left at its default (measured on J775D).soc: apple: mailbox: key the receive-thread clamp on a threaded handlerapple_mbox::rx_threaded. Probe sets it when the receive handler runs in an IRQ thread, and only such a handler has a thread whose minimum utilization can be set.No value changes on any SoC.
G13-G16 and per-SoC safety
legacy_rx_util_min). The mailbox option has no G13-G16 consumer, and this change adds none.clamp_rxexclusion.Testing
make LLVM=1 ARCH=arm64 drivers/gpu/drm/asahi/ drivers/soc/apple/on the release config: builds. No new warnings.W=1 drivers/soc/apple/mailbox.o: clean.rustfmt: no new diffs in the touched files.
Hardware (one-shot test kernel 7.3.0-aurora-swl1 = integration 0abc2f3 + this and the other open sweep PRs, 2026-11-20):
Still to run
No change is expected. gpubench 0dae261
perf.listand theasahi_g17_feed_detectorand mailbox KUnit suites:The feed, the receive-thread clamp and the M5 policy are the work of Diljit Singh and Jeff Queisser.