Repository navigation
thermal: apple-pmp: avoid P-core wakeups for cool idle polling - #3546
Conversation
When the die is cool and idle (below 95 C with no active cooling level or fault), apple-pmp-thermal currently runs its 100 ms poll_timer hrtimer pinned to whichever CPU armed it (often a P-core) and queues poll_work onto CPU-bound system_highpri_wq, waking a P-core ~10 times/s at idle. power_work also runs on CPU-bound system_wq every 500 ms. Move die polling onto a dedicated single-active unbound high-priority workqueue (WQ_UNBOUND | WQ_HIGHPRI | WQ_MEM_RECLAIM). Keep the 5 ms self-rearming hrtimer unchanged whenever fast_poll is true, and hand off to an unbound delayed_work at the same 100 ms slow cadence when !fast_poll so idle timers and workers can run on E-cores without weakening any thermal cadence or slope window. Queue power_work on system_unbound_wq at the same 500 ms interval. Serialize setup, cleanup, and PM prepare/complete under lifecycle_lock and publish live polling only after cpufreq thermal ownership handoff succeeds. Signed-off-by: Erik Bourget <[email protected]>
There was a problem hiding this comment.
Verdict: MERGE at b56b7461
Blockers: none (wait for the queued CI checks at b56b7461 to finish green before merging).
Checked:
drivers/thermal/apple-pmp-thermal.c: moves die polling onto a dedicated single-active unbound high-priority workqueue (WQ_UNBOUND | WQ_HIGHPRI | WQ_MEM_RECLAIM,max_active = 1), keeps the 5 ms self-rearminghrtimerwheneverfast_pollis true, hands off to 100 msslow_poll_workonsystem_unbound_wqwhen!fast_poll, and moves 500 mspower_worktosystem_unbound_wq.- Lock ordering and teardown safety verified:
lifecycle_lockserializessetup,cleanup,prepare, andcompletewithout nesting underpoll_lockorlock;apple_pmp_poll_stop()clearspoll_armedunderpoll_lockbeforehrtimer_cancel(),cancel_delayed_work_sync(&slow_poll_work), andcancel_work_sync(&poll_work), preventingapple_pmp_change_mode()->apple_pmp_poll_ensure_fast()from touchingpoll_wqorpoll_timerduring unregister;apple_pmp_thermal_setup()hands over cpufreq thermal ownership before arming polling and honorssleep_paused. - Exact-head J713 M4 Air verification at
b56b74618ee2: 5 s idleftracedropsapple_pmp_*P-core wakeups from113to0across repeated runs; unload/reload recovery (level 8 -> 0) andpower_statusverified live; 0 failed units. - Checked for Apple material, tool attribution, and private serials: clean;
checkpatch.pl0/0;MERGEABLEonmain; humanSigned-off-by;Tested:andRisk: two-way doorpresent.
Evidence
- Head:
b56b7461(base: main,mergeable: MERGEABLE,+127/-25indrivers/thermal/apple-pmp-thermal.c). - Non-blocking note: if
apple_pmp_poll_ensure_fast()runs while an already-startedapple_pmp_slow_poll_work()is waiting onpoll_lockandfast_pollreturns tofalsebeforeslow_poll_workacquirespoll_lock,slow_poll_workcan queue one 100 ms delayed work whilefast_timer_armedis still true; this self-converges cleanly on the next 5 ms timer expiry (HRTIMER_NORESTART+queue_delayed_workcoalescing). - Hosted CI at
b56b7461is currently queued.
|
code-owner ping <@422957901716652033> / @DjDeveloperr: merge train at |
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
apple_pmp_thermal_prepare() previously returned early on !pm_suspend_via_firmware(), leaving the unbound poll/power workqueues and fast hrtimer unpaused across s2idle and creating a conflict hazard if any caller or merge cancels poll_timer without setting sleep_paused (leaving fast_timer_armed latched and die polling stopped permanently after hot s2idle resume, causing -EAGAIN power telemetry errors). Pause both die and power polling unconditionally across every system sleep in apple_pmp_thermal_prepare() under lifecycle_lock so apple_pmp_poll_stop() and apple_pmp_thermal_complete() always stay paired. Also guard apple_pmp_slow_poll_work() against fast_timer_armed so a racing slow_poll_work callback cannot re-queue itself if apple_pmp_poll_ensure_fast() already armed poll_timer. Add host tests in tools/asahi/pmp-thermal-poll-tests.py covering s2idle prepare/complete across fast and slow polling modes and the slow_poll_work vs fast_timer_armed race. Signed-off-by: Erik Bourget <[email protected]>
|
On J713 ( Pushed follow-up commit Verification at
PR body updated with the full evidence; hosted CI at |
There was a problem hiding this comment.
Verdict: FINISH at 6ffed10. The prepare path now pairs sampler stop and resume for s2idle as well as deep sleep. The slow callback checks fast_timer_armed under poll_lock before it can queue more work. The composed J713 build recovered telemetry after both controlled CPU-only hot sleeps. The CPU-plus-render trial lost reachability after its second pre-suspend snapshot. Please keep this result open until a matched control distinguishes a regression from a pre-existing stress failure, and link current-head CI.
|
Matched control for the CPU-plus-render hot-
Both kernels passed 2/2: every hot wake resumed and the Mac stayed reachable, with 0 Current-head CI at Evidence
|
There was a problem hiding this comment.
Verdict: MERGE at 6ffed106f481
Blockers: None (the only failing CI check at 6ffed106f481 is host-tests on main's unrelated g17-compute-owed-stamp-tests.py E0061 regression tracked in #3594; wait for host-tests / readiness to clear once #3594 lands).
Checked:
- Incremental changes since
b56b7461(drivers/thermal/apple-pmp-thermal.c):apple_pmp_slow_poll_work()now checksif (!pmp_thermal.poll_armed || pmp_thermal.fast_timer_armed) return;underpoll_lock, eliminating the benign dual-arm window whenensure_fast()races a pending slow callback.apple_pmp_thermal_prepare()removes the!pm_suspend_via_firmware()early return so boths2idleand deep sleep symmetrically pause and resume die/power polling throughapple_pmp_poll_stop()andapple_pmp_thermal_complete().tools/asahi/pmp-thermal-poll-tests.py(registered inrun-host-tests.py) compiles the extracted functions with-Wall -Wextra -Werror -fsanitize=undefinedand exercises hots2idle, cools2idle, and theslow_poll_workvsensure_fast()handoff race.
- Exact-head J713 matched control (
6ffed106f481, 2026-11-29): Control (ctl1/ctl2) and PR (pr1/pr2) both passed 2/2 hot CPU+renders2idlecycles (97.0–107.8 °C pre-suspend die), with 0power telemetry error -11lines,apple-pmp-diereadable after every wake, 0 failed units, and 0 call traces — clearing the earlier unmatched reachability question. - Checked for Apple material, tool attribution, private serials, and gating: clean.
Evidence
- Head:
6ffed106f481(base: main,mergeable: MERGEABLE). - CI at
6ffed106f481:pr-textPASS;readinessqueued;host-testsfailed solely ing17-compute-owed-stamp-tests.py(crate::g17::recovery::note_retiredE0061frommain, tracked in#3594).
main marks system_unbound_wq deprecated, and the first power poll after
boot now warns:
workqueue: work func apple_pmp_power_work [apple_pmp_thermal] enqueued
on deprecated workqueue. Use system_{percpu|dfl}_wq instead.
system_dfl_wq is the unbound system workqueue that replaces it, with the
same WQ_UNBOUND flags, max_active and default CPU mask, so the pollers
still run on any CPU and are not pinned to the P-cores at idle. The poll
host test's workqueue mock follows the rename.
Signed-off-by: Erik Bourget <[email protected]>
Signed-off-by: Erik Bourget <[email protected]>
There was a problem hiding this comment.
Verdict: MERGE at 77845d57b293
Blockers: None (wait for the queued hosted CI checks at 77845d57b293 to finish green before merging).
Checked:
- Verified the incremental delta since the previously approved
6ffed106f481consists solely of83913030d4d5(+8/-8) and a clean merge ofmain(d02c84abc8de->77845d57b293), both with DCO sign-off. - Confirmed
83913030d4d5replaces all 5system_unbound_wqcallsites indrivers/thermal/apple-pmp-thermal.c(L281,L606,L627,L1012,L1113) and the corresponding mock intools/asahi/pmp-thermal-poll-tests.py(L59,L131) withsystem_dfl_wq, leaving zerosystem_unbound_wqreferences in either file and preserving unbound scheduling semantics without triggering the deprecated-workqueue boot warning. - Verified exact-head J713 (
M4 Air,T8132, 27.2) testing with83913030d4d5(llvm-nm -uconfirmssystem_dfl_wqonly,0P-coreapple_pmp_*wakeups across two 5 s cool idle traces, cools2idlecycle PASS,0new kernel errors),linux-j713clean build,24/24pmphost tests passing, andcheckpatch.pl --strictclean, building on the full6ffed106f481J713 cool/hots2idlerows (apple-pmp-thermalbinds only onapple,t8132-pmp-v2).
Evidence
drivers/thermal/apple-pmp-thermal.cat77845d57b293: all 5queue_delayed_work()callsites (L281,L606,L627,L1012,L1113) usesystem_dfl_wq; zero occurrences ofsystem_unbound_wq.tools/asahi/pmp-thermal-poll-tests.pyat77845d57b293:mock_dfl_wq/system_dfl_wqmatchesapple-pmp-thermal.c(24/24pmphost tests pass).- Merge commit
77845d57b293mergesmain(d02c84abc8de) cleanly (MERGEABLE, 3 PR files intact).
|
Merging under the 6-point rule (Ryan 09:29, permanent), at |
What: Move
apple-pmp-thermaldie polling and rail-power polling off CPU-pinned timers and workqueues when cool and idle, avoiding idle P-core wakeups (0observed across two 5 s cool idle traces on J713) without changing any thermal polling cadence, slope window, or power telemetry interval, and pause both samplers cleanly acrosss2idleas well as firmware sleep.Tested: At head
77845d57b293(83913030d4d5moves the pollers from the deprecatedsystem_unbound_wqtosystem_dfl_wq, thenmainmerged in): host checks pass, and on J713 (M4 Air,T8132)apple-pmp-thermalwith this change (built in the J713 daily tree that carries6ffed106f481) runs with0P-coreapple_pmp_*wakeups across two 5 s cool idle traces and one cools2idlecycle, with0new kernel errors. Earlier rows at6ffed106f481: host checks pass, and J713 (M4 Air,T8132) passes cool idle wakeup traces, cools2idle, and 2x controlled CPU-load hots2idle, while an earlier CPU-plus-off-screen-render hots2idlestress run remains unresolved:77845d57b293:linux-j713kernel build clean (Image, modules, dtbs);run-host-tests.py:830/832passed, all24pmptests pass, and the two failures (apple-dcp,apple-scaler-recovery-tests) fail the same way onmaind02c84abc8de;checkpatch.pl --strictclean for83913030d4d5;git diff --checkclean. J713 rows in Evidence.6ffed106f481:arm64 LLVM=1compile (W=1 KCFLAGS=-Werror) ofdrivers/thermal/apple-pmp-thermal.o,test-thermal-policy.py(22/22 Rust unit tests + 571,828-row trace check + GPU attach epoch +-ENODATAhold),run-host-tests.py --only pmp(24/24 passed includingpmp-thermal-poll-tests.pycoverings2idleprepare/completeand theslow_poll_workvsfast_timer_armedrace),checkpatch.pl --strict(0 errors; 1 new-fileMAINTAINERSwarning fortools/asahi/pmp-thermal-poll-tests.py, already covered bytools/asahi/),git diff --checkclean, andgit merge-tree --write-tree origin/main HEADclean (027c2968fd16againstorigin/main8ebb0f75ae2d).M4 Air,T8132, 27.2) at6ffed106f481(composed onto the J713 daily PMP thermal tree withapple-soc-cpufreqas a module, one-shot boot, default Stage 2):49–54 °Cdie):0P-coreapple_pmp_*wakeups across two 5 s traces (148and128executions, all on E-cores).s2idle(40.0 °C -> 42.5 °C): PASS (0power telemetry error -11,apple-pmp-diereadable at39.75 °C).s2idle(2 cycles, 8 CPU spinners,98.5 °Cand106.5 °Cpre-suspend): PASS —0power telemetry error -11,50governor decisions (48error=0,2error=-61, all50qos_error=0),apple-pmp-diereadable after both wakes (102.5 -> 106.5 °Cand101.75 -> 102.5 °C),0newerr+lines (4baseline lines only), and0failed units; within the controlled interval,3transientsensor error -61; CPU minimum caps retainedwarnings occurred (2after cycle-1PM: suspend entry (s2idle)recovering toerror=0at188.106 s, and1on load teardown at208.109 sfollowed byerror=0decisions at levels7and6and cooling devices atcur=0in the post-run snapshot).s2idlestress run on the same trial build: an earlier single boot (17:07 EST) running the CPU+render stress harness (20load processes: CPU loops plus off-screenglmark2, 20 srtcwake -m freeze) resumed cools2idleand hot cycle 1 cleanly (17:10:21 EST/22:10:21 UTC,0-11telemetry errors,1sensor error -61,40decisions logged,apple-pmp-diereadable and cooling engaged to1/19,1/7,1/8), then stopped logging after cycle 2's pre-suspend snapshot (apple-pmp-die=102500,macsmc_soc_die=102583) and lost reachability (journal ended at17:10:37 EST; unanswered after 12 min; cause unresolved, tracked in**Not yet:**).b56b74618ee2rows (idle wakeups113 -> 0, unload/reload ramp, and the hot-s2idle-11regression that6ffed106f481fixes) are retained in Evidence.Risk: two-way door · T8132 (M4) Macs binding
apple-pmp-thermal(apple,t8132-pmp-v2); other SoC families only build the module and never probe it (apple_pmp_telemetry_register()andapple_pmp_thermal_probe()both require"apple,t8132-pmp-v2", present only int8132.dtsi).Revert:
git revert -m 1 <merge-commit>(no persistent on-disk, ESP, DT, or firmware state is modified).Not yet: Hosted CI at
77845d57b293(queued on push); a fresh boot at this head (the deprecation warning prints once per boot, so the module swap below proves its absence by the module's symbol references instead); explaining or reproducing with a control the unresolved J713 CPU-plus-off-screen-render hot-s2idleloss of reachability (the 8-CPU-spinner controlled hot-s2idlepass completed cleanly with0-11errors); other T8132 boards outside this lab (J604,J623,J624,J715,J773g).Details
Previously,
apple-pmp-thermalarmed a CPU-pinnedhrtimer(poll_timer) and queuedpoll_workonto CPU-boundsystem_highpri_wq, whilepower_workran on CPU-boundsystem_wq. Whenever deferred setup happened to run on a P-core, the 100 ms slow die poll and 500 ms power poll woke P-cores continuously at idle (measured 113 P-core wakeups per 5 s on J713).apple-pmp-thermalbinds only on"apple,t8132-pmp-v2"(drivers/soc/apple/pmp-telemetry.candapple_pmp_thermal_probe()), so it is active only on T8132 boards (t8132.dtsi).This change keeps every sampling interval identical while avoiding P-core pinning at idle and keeping sleep pause/resume synchronized:
WQ_UNBOUND | WQ_HIGHPRI | WQ_MEM_RECLAIM,max_active = 1) forpoll_workso sampling remains strictly serialized while EAS can schedule it on E-cores.hrtimer(hrtimer_forward_now+HRTIMER_RESTART) unchanged wheneverfast_pollis true (die>= 95 C, active cooling, or fault).slow_poll_workonsystem_dfl_wqat the same 100 ms cadence when!fast_poll, re-arming itself immediately so the 100 ms tick stays independent ofpoll_workruntime and preserves the 50–250 ms cooling slope window, and guardsapple_pmp_slow_poll_work()againstfast_timer_armedso a racing worker never re-queues alongside an armedpoll_timer.poll_armedandfast_timer_armedunderpoll_locksopoll_timerowns its fast→slow handoff withouthrtimer_try_to_cancel(), and mode changes preserve any live fast timer deadline.power_workontosystem_dfl_wqat the unchanged 500 ms interval.setup,cleanup,prepare, andcompleteunderlifecycle_lock, publishes live polling only afterapple_soc_cpufreq_set_thermal_owner()succeeds (and while!sleep_paused), and removes the!pm_suspend_via_firmware()early return inapple_pmp_thermal_prepare()sos2idleand firmware deep sleep both pause and resumeapple_pmp_poll_stop()/power_worksymmetrically.tools/asahi/pmp-thermal-poll-tests.py(registered intools/asahi/run-host-tests.py) coverings2idleprepare/completeacross fast and slow modes and theslow_poll_workvsfast_timer_armedrace.Evidence
J713 M4 Air (
T8132, 27.2) with83913030d4d5(2026-11-29)apple-pmp-thermal.korebuilt with thesystem_dfl_wqchange in the J713 daily tree that carries this PR at6ffed106f481(7.3.0, default command line, booted kernel unchanged), loaded withrmmod+insmod, then the installed module restored withmodprobe.system_unbound_wq(the deprecated queue behindworkqueue: work func apple_pmp_power_work [apple_pmp_thermal] enqueued on deprecated workqueue, which this boot printed once); the module built with it references onlysystem_dfl_wq(llvm-nm -u).35.5–38 °Cdie): two 5 s traces ofworkqueue_execute_startandhrtimer_expire_entryforapple_pmp_*:106executions each,0on P-cores (CPUs 0, 7, 8, 9), the rest on E-cores (apple_pmp_poll_work,apple_pmp_slow_poll_work,apple_pmp_power_work).s2idle:rtcwake -d rtc1 -m freeze -s 10resumed;0kernel errors,0power telemetry error,apple-pmp-diereadable (38 °C), Wi-Fi associated,0failed units.level 8 -> 0in 200 ms steps witherror=0;sensor error -61warnings only in the start burst and one isolated reading in about 90 s, the same pattern as the installed module before the swap.Static & host checks (
6ffed106f481)git diff --check b56b74618ee2^..HEAD: clean./scripts/checkpatch.pl --strict --git b56b74618ee2^..HEAD:b56b74618ee20 errors / 0 warnings / 0 checks;6ffed106f4810 errors, 1 warning (new-fileMAINTAINERScheck fortools/asahi/pmp-thermal-poll-tests.py, covered bytools/asahi/atMAINTAINERS:4572)git merge-tree --write-tree origin/main HEAD: clean (027c2968fd16againstorigin/main8ebb0f75ae2d)make O=_build ARCH=arm64 LLVM=1 W=1 KCFLAGS=-Werror drivers/thermal/apple-pmp-thermal.o: clean (aurora_defconfig)python3 tools/testing/selftests/drivers/gpu/asahi-m4/test-thermal-policy.py: 22/22 Rust unit tests + 571,828-row shared C cooling policy trace check + GPU attach epoch +-ENODATAhold passedpython3 tools/asahi/run-host-tests.py --only pmp:24/24passed (pmp-thermal-poll-testspassed in 0.4 s)J713 M4 Air (
T8132, 27.2) verification at6ffed106f481(2026-11-29)6ffed106f481composed onto the J713 daily PMP thermal code alongsidelinux#3397(apple-soc-cpufreqas a module), default Stage 2 (sha2563b2d2f059858d1891b225910864c02d68afb1b42893667e0afa8666491651071untouched), one-shot GRUB trial boot (vmlinuzsha256cebaa4e73e6268f14de680996a76fa94d301be8a675b7614044da050d4223f73,apple-pmp-thermal.kosha256df3dad5b95dcd56a23b2a58ff6d532a70f4f5c427d8783dcf7a84346f5045e8b, default command line).ftracetraces ofapple_pmp_*work and timer executions recorded148(0on P-cores) and128(0on P-cores).s2idle:rtcwake -d rtc1 -m freeze(apple-pmp-die40.0 °C -> 42.5 °C,macsmc_soc_die37.655 °C -> 37.702 °C) resumed cleanly with0power telemetry error -11lines andapple-pmp-diereadable (39.75 °C).s2idle(2 cycles, 8 CPU spinners):apple-pmp-die=98500(98.5 °C).rtcwake -d rtc1 -m freeze -s 10resumed cleanly (+2 s: 102500,+10 s: 106500),new -11=0,apple-pmp-diereadable; 2sensor error -61; CPU minimum caps retainedwarnings (187.451670 s,187.456669 s) followedPM: suspend entry (s2idle)(187.448516 s), followed byPM: suspend exit(187.703007 s) and cleanerror=0recovery at188.106023 s(mc=55500,level=7).apple-pmp-die=106500(106.5 °C).rtcwake -d rtc1 -m freeze -s 10resumed cleanly (+2 s: 101750,+10 s: 102500),new -11=0,new -61=0,apple-pmp-diereadable, with active governor decisions (level 2 -> 1 -> 0 -> 2 -> 3,qos_error=0).0power telemetry error -11,50governor decisions (48error=0,2error=-61, all50qos_error=0),3sensor error -61; CPU minimum caps retainedwarnings in the controlled interval (the 2 in cycle 1 plus 1 on load teardown at208.109554 s, followed by cleanerror=0decisions atlevel=7(208.534590 s) andlevel=6(208.739682 s) and a subsequent cooling-device snapshot with all three cooling devices atcur=0),0failed systemd units, and4baselineerr+lines only (AFK[ep:20],unsupported DFB layout,brcmfmac ring 4,apple_sep). (Earlier in the same boot, during the preceding cpufreq stress/handoff test at178.937 s..178.982 s,10transient-61warnings also occurred and recovered cleanly toerror=0.)s2idlestress boot on the same trial build (17:07:53 ESTboot):20load processes: CPU busy loops plus off-screenglmark2, 20 srtcwake -m freezewith load still running) completed cools2idle(17:08:55..17:09:16 EST) and hot cycle 1 (pre-suspend apple-pmp-die=108250, resumed at17:10:21 EST/22:10:21 UTCwith1sensor error -61; CPU minimum caps retained,0power telemetry error -11,apple-pmp-diereadable62000 -> 96750 -> 106000 -> 103500,40decisions logged, cooling engaged tocpufreq-cpu0=1/19,cpufreq-cpu1=1/7,aurora-g16g=1/8, and3baselineerr+lines only).apple-pmp-die=102500,macsmc_soc_die=102583,20load processes) and the persistent journal ended at17:10:37 EST; the Mac lost reachability and had not returned after 12 minutes (cause unresolved).Earlier J713 M4 Air (
T8132) checks atb56b74618ee2(prior to6ffed106f481)apple_pmp_*P-core wakeups (5 s)apple_pmp_*E-core wakeups (5 s)apple-pmp-thermalonmain)1131b56b74618ee2(Run 1)0172b56b74618ee2(Run 2)0169b56b74618ee2:level 8 → 7 → 6 → 5 → 4 → 3 → 2 → 1 → 0at 200 ms steps,ready=Y,fault=0 error=0 credit_mj=600000,0new kernel errors.76649338a1bc(b56b74618ee2merged onto the J713 daily PMP thermal code, commit57e65ff632c4) failed hots2idle(die 96–100 °C under load, 2/2 boots) with permanentpower telemetry error -11and-ENODATAonapple-pmp-die/temp, while Control A (default kernel) and Control B (a657f408f30c, same batch without#3546, enterings2idleat94.8 °C) passed. Identified path:apple_pmp_thermal_prepare()still returned early on!pm_suspend_via_firmware(), which collided with the daily'shrtimer_cancel()and leftfast_timer_armedlatched without settingsleep_paused = true;6ffed106f481fixes that path by pausing unconditionally across every sleep inapple_pmp_thermal_prepare(), verified above under controlled CPU load.