Repository navigation
arm64: idle: stop the Apple CPU PMU counters across WFI - #3010
Merged
RyanTheTide merged 1 commit intoNov 23, 2026
Merged
Conversation
On M4 and later Apple cores, some cycle counters keep counting during WFI (for example, M5 Max Sawtooth cores count at ~1.5 GHz while idle), which inflates CPU-wide perf cycle counts with idle time unlike other arm64 PMUs. The PMU registers themselves survive WFI unchanged, so saving and restoring the full counter state is not needed. While perf events are active on a CPU, have the Apple CPU PMU driver set a per-CPU flag so the Apple WFI idle path clears the counter enable and IMODE bits in PMCR0_EL1 before WFI and restores PMCR0_EL1 on exit. When no perf events are active, the idle path does no extra register writes. Signed-off-by: Satya Benson <[email protected]>
DjDeveloperr
approved these changes
Nov 23, 2026
DjDeveloperr
left a comment
Contributor
There was a problem hiding this comment.
Formal §1–§6 pre-PR checklist review at f0140e6ab816ab71e4c70943e714692905fef68d.
Clean, minimal fix:
apple_wfi()runs only insidecpu_do_idle()on the existingapple_wfi_needs_save()path with both IRQs and FIQs masked (arch/arm64/include/asm/irqflags.hmasks IRQ and FIQ together), so no PMU FIQ can preempt between reading and restoringPMCR0_EL1.pmcr0survivesapple_cpu_wfi()via AAPCS64 callee-saved registers / stack, and zero extra sysreg accesses occur whenapple_pmu_wfi_freezeis false.apple_pmu_wfi_freezeis properly toggled inm1_pmu_start(),m1_pmu_stop(), andm1_pmu_reset()(covering CPU offline andCPU_PM_EXIT), with clean!CONFIG_ARCH_APPLEstubs and safe behavior on non-Apple arm64.
§1–§6 Checklist
- §1 No model gating: Pass (no new chip/SoC/board gate; hooks existing
apple_wfi_needs_save()and per-CPU active-event flag). - §2 Production-ready, no hacks: Pass (default cmdline, no runtime switches or delays).
- §3 Safety: Pass.
- §4 Clean-room & attribution: Pass (human author/committer + human
Signed-off-by:only, zero AI trailers in commit; PR body includesAssisted-by:). - §5 Evidence: Pass (44/44 arm64 QEMU KUnit
apple-m1-cpu-pmu, livelobataM5 Max J775c 1 s idle and busyperf statmeasurements + health tuple, CIhost-testspassed). - §6 Naming: Pass.
Assisted-by: LLM (Gemini 4 Neon)
satchlj
pushed a commit
to satchlj/linux
that referenced
this pull request
Dec 1, 2026
Commit 4fa08b4 ("soc: apple: mailbox: drain G17 receive interrupts in hard IRQ") moved the ASCWrap v6 GPU receive path out of the oneshot IRQ thread: normal completions are now drained in hard IRQ, and the thread runs only when the receive budget saturates. The thread was doing more than adding a wakeup. It is an RT task, so while it runs schedutil raises its CPU cluster to the top frequency, and the G17 driver steers that through apple_mbox_set_rx_util_min(): Port::rx_update() keeps the RT default for host-bound streams and lowers it only while the GPU is the bottleneck. Since 4fa08b4 the completion of every light submission runs without that boost, from whichever CPU takes the interrupt. On the MacBook Neo (J700, A18 Pro) gpubench-vk compute.light regressed with that commit alone. Built on its own parent with only its merge reverted, 6 reps each: row with reverted 7.3.0-41 compute.light queue/d2 (us) 52.3 35.3 35.5 submit CPU (us) 12.0 9.6 9.7 latency (us) 110 64 64 reps that lose the overlap 6/6 0/6 0/6 compute.light queue/d1 (us) 106.0 102.1 102.3 render.light queue/d1 (us) 137.8 122.1 127.0 Bisected on J700 from 7.3.0-41 (6f618bc, rebuilt with the same toolchain and config as every other point) to 7c9d9ad: the regression first appears in 3989d21..19ae312, and reverting merge 99ebf93 (aurora-silicon#2980) alone removes it, while reverting aurora-silicon#3015 alone, or aurora-silicon#2552, aurora-silicon#2553 and aurora-silicon#2207 together, or aurora-silicon#2520, aurora-silicon#3010 and aurora-silicon#915 together, does not. Restore the threaded receive handler for ASCWrap v6 G17 mailboxes. Keep that commit's exclusion of ASCWrap v8 (T8152) from apple_mbox_is_g17(), so the T8152 GPU mailbox stays on apple_mbox_recv_irq() with its storm guard as it is now, and keep a KUnit case for that exclusion. With "drm/asahi: g17: keep G17P work nodes and compute descriptors firmware-cached" on origin/main 16da002, a one-shot J700 boot gives compute.light d2 34.5 us (submit CPU 9.5 us, 0/9 reps losing the overlap), d1 104.1 us, render.light d1 124.9 us; the multi_queue CTS family 4266/0 three times, compute CRCs 5/5, Geekbench 6 Vulkan 8/8, and no GPU fault, WARN or AVC. Signed-off-by: Diljit Singh <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On M4 and later Apple cores, some CPU PMU cycle counters keep ticking across WFI (for example, M5 Max Sawtooth cores continue counting while idle), inflating CPU-wide
perfcycle counts with idle time unlike other arm64 PMUs. Because PMU register state survives WFI intact, saving and restoring the full counter bank is unnecessary.While perf events are active on a CPU, have the Apple CPU PMU driver maintain a per-CPU flag so the Apple WFI idle path clears the counter enable and IMODE bits in
PMCR0_EL1around WFI and restoresPMCR0_EL1on exit. When no perf events are active on the CPU, the idle path performs no extra register writes. No runtime switches or model-specific gates are added.Verification
scripts/checkpatch.pl --strict --git origin/integration/aurora..HEAD— 0 errors, 0 warnings, 0 checks;W=1arm64 build — 0 warnings on modified files.qemu-system-aarch64):apple-m1-cpu-pmu— 44/44 passed, 0 failed.lobata(Mac Studio M5 Max / J775c / T6050):origin/integration/aurora(880a97a3dca2) + this exact commit (f0140e6ab816),Image.gzSHA25651562a4abc14db4ab11b2f066129df645f012e4c09085751d32598b2d44fb21a,vmlinuxGNU build-idd041b92777dbb0670ea0a44dda3f14ff1687164e, paired with J775c board DTB0442bec28ef4c650d4e3395589f7001808c7e5b4a3bdd4971fc466d68f9de0ed(mixed-DTB boot because tip'st6050-j775c.dtsis still a disabled stub).fbbba97e-4464-4855-9874-d2d98550148d, default kernel cmdline (rdinit=/init nr_cpus=18 maxcpus=18 root=UUID=3da7492b-6c5e-4e84-9eac-65b89fae44c6 arm64.nomte).hw perfevents: enabled with apple_t6050_pmu PMU driver, 10 (0,000003ff) counters available.perf stat -a:cpu0(apple,sawtooth):3,734,540cycles /3,991,717instructions (frozen across WFI, not ticking at ~1.5 GHz).cpu12(apple,everest):5,753,092cycles /4,818,667instructions.cpu12(0.218 s):899,548,188cycles /7,594,758,125instructions (active counting unaffected).dmesg -l errlines andac-power-mode.servicefailure are unrelated tip-vs-J775c-DTB mismatches: second SPMI Gen4 IRQ-95,apple_aop-61,apple-dcpclock/lane warnings, missing SMCac_power_modesysfs).Assisted-by: LLM (Google:Gemini 4 Neon)