Repository navigation
thermal: apple-pmp: end an idle dark hold early only for GPU work - #3766
IronsideXXVI wants to merge 4 commits into
Conversation
…he GPU is idle The PMP firmware publishes a die record only while its CPU cluster has power. When every record is dark (`-ENODATA`), the driver reuses the last reading for a fixed 2 s (`APPLE_PMP_GATED_HOLD_NS`). On J604 (T8132), with cool polling slowed to 50-100 ms, an idle desktop routinely stays dark past 2 s, expiring the hold, logging repeated sensor errors, and clamping both CPU clusters at their floor while polling recovers. For a cool last reading (`< APPLE_PMP_GATED_HOLD_MC`), extend the dark hold past 2 s at 8 C/s of headroom below `APPLE_PMP_PASSIVE_MC` (clamped to [2 s, 10 s]: 8.25 s at 40 C, 6.5 s at 54 C, 2 s at >= 90 C), gated on the GPU rail (`PP1b`, sampled by the power worker every 500 ms) reading idle (`< 50 mW`, no error, timestamp <= 1 s old). Because every die record is a CPU record, the GPU rail gate prevents a busy GPU from heating the die unseen while CPU clusters are power-gated. Clear `rail_ns` on probe and across sleep (`apple_pmp_thermal_complete`) since `CLOCK_MONOTONIC` pauses during sleep. Non-`-ENODATA` errors, hot readings (`>= APPLE_PMP_GATED_HOLD_MC`), missing/stale/errored rail reads, GPU load (`>= 50 mW`), and dark spells past the scaled cap (10 s maximum) continue to take the stock fail-closed path immediately. Add KUnit coverage in `apple_pmp_test_dark_hold_gate`. Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
Integrate the dark-sensor hold with upstream main's apple-pmp-hold.h gated-hold helper, CPU idle tracker, sleep/resume real-sample-age tracking, and thermal-zone fault-disable handling: - Gate extended dark holds in apple_pmp_sample() on both cpus_idle and apple_pmp_gated_gpu_idle() (PP1b < 50 mW, error-free, <= 1 s fresh, with rail_ns cleared on probe, cleanup, and across sleep). - Bound apple_pmp_gated_hold_sample() by apple_pmp_gated_hold_ns(valid_mc) (8 C/s headroom below APPLE_PMP_PASSIVE_MC, clamped to [2 s, 10 s]) instead of a flat 15 s cap. - Update apple_pmp_test_gated_hold() and tools/asahi/pmp-thermal-poll-tests.py for the headroom-scaled cap and rail_ns sleep-resume reset. Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
|
Merged
Verified locally on
|
DjDeveloperr
left a comment
There was a problem hiding this comment.
Correct, and after the merge with main it's a tightening. Main already holds a cool, dark die while the CPUs are idle, for up to 15 s (APPLE_PMP_GATED_IDLE_CAP_NS). This lowers that to a headroom-scaled 2-10 s, and holds past 2 s only while the GPU rail reads idle (< 50 mW, fresh). So a GPU load during a CPU-dark spell no longer goes unseen for 15 s. The rail age check fits the 500 ms power poll, and clearing rail_ns across sleep is right, since monotonic time stops.
Two notes, no code change needed:
- The body's A/B was against the old 2 s hold, not today's main. Please restate Risk and Tested against main: the change versus main is the shorter cap plus the GPU gate. The thing to watch is more hold expiries (sensor-error CPU caps) on an idle desktop.
- Hardware gates. PMP thermal is shared code, so it needs a row at this head on the M4 it targets plus one other generation. I've queued our J773g (idle desktop for 10 minutes:
arch_timerrate and sensor-error lines vs main; a GPU load while the CPUs idle ends the hold) and the J700 (no regression). Your J604 run used your own tree, not this head.
|
Hardware A/B on J773g (M4 Mac mini, T8132,
Summary: Compared to stock |
|
Matched 10-minute stock idle baseline addendum on J773g (
|
|
Matched 10-minute stock idle baseline on J773g (
|
Main already holds a cool dark die for up to 15 s while the CPUs are idle. Scaling that cap down to 2-10 s by headroom, and requiring a fresh idle GPU rail past 2 s, can only end a hold sooner. At 46 C the cap is 7.5 s, and each expiry costs sensor errors, capped CPUs and 5 ms polling until the sensors read again and the guard has stepped down. Over 10 idle minutes a J773g went from 78 to 371 "sensor error -61" lines and from 304.6 to 330.6 arch_timer interrupts per second. Go back to main's 15 s cap and keep the GPU gate, but let only a rail that reads busy start the 2 s clock. A failed or missing rail read leaves main's behaviour: the power policy already keeps the CPUs and the GPU at their floor for it. That also removes the rail timestamp: a stale reading can't hold the die longer than main does. Set the GPU threshold between what a J773g reads idle (0-43 mW) and under a light GPU load (1630 mW). 50 mW was within one 15 mW rail step of idle. The KUnit and host tests check that 10 idle minutes of 14 s dark spells cost no error and no fast poll. The host test also checks that mutations (a 7.5 s cap, a failed rail read that counts as GPU work, no GPU gate) are caught. Signed-off-by: DjDeveloperr <hey@djdev.me>
|
Pushed Why it got worse. The change could only end a hold sooner than main, never later:
Measured on J773g: 78 against 371 error lines, 304.6 against 330.6 What changed.
With the GPU rail under 250 mW the holds are now exactly main's, so J604 keeps the long idle hold (its earlier A/B was against the old 2 s hold, which main has since replaced). What is left over main is the GPU gate: with GPU work and dark sensors it still errors sooner than main, on purpose. Tested at Rows owed at
The title and the What, Tested, Risk and Not yet lines still describe the 2-10 s cap, so they need an update. The push dismissed the approval, so it needs a new one from someone who did not push. |
|
At |
|
Thanks for pushing
|
…to cool 200 ms slow poll Merge aurora-silicon#3766 (52e3af5, 250 mW GPU-busy dark-hold gate on top of main's 15 s APPLE_PMP_GATED_IDLE_CAP_NS) cleanly so aurora-silicon#3994 is a minimal delta on aurora-silicon#3949 + aurora-silicon#3766: - Drop the unmeasured 15 s -> 30 s dark-hold cap expansion (deferring any > 15 s extension until ANE-only and ProRes-only die ramp measurements are collected on fan and fanless T8132). - Drop the 50 mW rail_ns / apple_pmp_gpu_gate / apple_pmp_gated_hold_sample_capped() path, inheriting aurora-silicon#3766's apple_pmp_die_idle() (250 mW busy threshold, failed rail reads left on main's path) and apple_pmp_gated_hold_sample(), which also fixes the post-wake first dark read failure. - Keep cool-only 200 ms slow polling (< 90 C, 100 ms in 90-94.9 C on immediate entry via aurora-silicon#3949's apple_pmp_poll_reschedule(), 5 ms at >= 95 C, cooling, or fault) and clean up the inaccurate transient-hold comment. - Extend KUnit (17/17: cool poll cadence, 10-min 200 ms dark-idle rate = 3000 polls / 0 errors, post-wake dark-read replay) and host poll tests (including 92 C warm-band immediate 100 ms entry + mutation test). Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
There was a problem hiding this comment.
Verdict: REQUEST CHANGES at 52e3af5
Failure: The new apple_pmp_test_dark_idle_rate() overflows signed long on 32-bit KUnit builds. APPLE_PMP_POLICY_KUNIT_TEST depends only on KUNIT, so it can be selected on a 32-bit target. NSEC_PER_SEC is 1000000000L and all three products (10, 14, and 600 times that constant) are calculated before conversion to u64. I compiled the exact expressions with gcc -m32 -Werror=overflow -fsyntax-only and all three failed. The 14-second product became 1115098112 and the 600-second product became -1295421440. Give those multiplications an unsigned 64-bit operand, for example 14ULL * NSEC_PER_SEC. The same 32-bit compile passed with that change. Test source
Checked: I ran the exact host polling suite. It passed the 15-second idle and 2-second active holds, rail-error fallback, and sleep and s2idle transitions. It rejected all three mutations. The power worker publishes power_error and the rail values under the mutex that the thermal sampler holds when it reads both. The GPU threshold applies to the rail reading across supported boards.
Follow-ups: The author’s current-main J604 comparison remains tracked separately from this build finding.
Use 10ULL, 14ULL, and 600ULL when multiplying by NSEC_PER_SEC in apple_pmp_test_dark_idle_rate() so the multiplications do not overflow 32-bit signed long on 32-bit KUnit builds before converting to u64. Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
|
Thanks for catching the 32-bit signed Verified offline at
|
There was a problem hiding this comment.
Verdict: MERGE at 5d1e0cf
Checked: The only delta from 52e3af5d widens the three KUnit duration literals to 10ULL, 14ULL, and 600ULL. I compiled the exact changed expressions with gcc -m32 and gcc -m64, both with -Wall -Werror=overflow -fsyntax-only. Both passed. The unchanged host thermal polling suite also passed and rejected all three mutations. The earlier 32-bit KUnit finding is resolved.
Follow-ups: The current-main J604 comparison is tracked by the author. Author verification
DjDeveloperr
left a comment
There was a problem hiding this comment.
Code is fine at 5d1e0cf98d21. Not an approval: 52e3af5d was our push. What is missing is hardware, not code.
The bot's point is right and fixed. At 52e3af5d an ARCH=i386 build of apple-pmp-policy-test.o with WERROR fails with three overflow errors (lines 391 and 400). At 5d1e0cf9 it builds clean. The push changes only those two lines.
Its other statements hold, except one to read narrowly:
rail_mwandpower_errorare written and read underpmp_thermal.lock: yes.- "The GPU threshold applies to the rail reading across supported boards": true for the code, not measured. The driver binds only on T8132 (
apple,t8132-pmp-v2, rails fromapple,t8132-smc), so J604, J623, J624, J713, J715 and J773g. The 250 mW comes from J773g alone (0-43 mW idle, 1630 mW incompute.light). I found no posted idle PP1b for any of the others. The ones with a panel of their own may idle higher, for example a 120 Hz desktop on J604. Idle above 250 mW with dark sensors meanssensor error -61, full CPU and GPU protection and 5 ms polling after 2 s instead of 15 s, which is the J773g regression ofe49cdb43again.
Behaviour next to main: below 250 mW, or with a failed rail read, holds are the same as main. A stale rail value can't hold longer than main's 15 s cap. After resume a busy value from before sleep is replaced by the first power poll, before the 2 s run out. None of the six PMP records is labelled as a GPU sensor, so the gate has a purpose.
Owed before merge:
- J604 at this head against current
main, 10 minutes idle, panel on at its normal refresh rate:PP1bmin, median and max (one sample per second), count ofsensor error -61lines,arch_timerrate. Then a GPU load with the CPUs idle:PP1band the same count. Pass: idlePP1bwell under 250 mW, idle error count not abovemain, and the GPU-load run shows what the gate changes. If idlePP1breaches 250 mW, the threshold needs to move before anything else. - J773g at this head, the same two parts with DP-3 on, once 1 shows a gain. The earlier J773g rows were at
e49cdb43. - A fanless Air (J713 or J715) idle
PP1breading would settle the third form factor. Not required if 1 and 2 pass.
No J700 or other second-generation row: nothing but T8132 runs this code.
If 1 shows no gain over main, close this as superseded by #2774, as said on 12-03.
Small: Tested: and Not yet: still say 52e3af5dd8ac. The readiness bot takes that Tested: line for a hardware row; it is not one.
What was run
Merged with main 8ec8740a1e6f (no conflicts, #3949 is in there): apple-pmp-policy KUnit on UML 15/15, tools/asahi/pmp-thermal-poll-tests.py passes with 3/3 mutations caught, apple-pmp-thermal.o and apple-pmp-policy-test.o clang arm64 W=1 with 0 warnings. Head alone: ARCH=i386 WERROR build of the test object, clean. No hardware was used.
What: End
apple-pmp-thermal's cool dark-sensor (-ENODATA) idle hold early when GPU work is active onPP1b, while preservingmain's 15 s idle cap (APPLE_PMP_GATED_IDLE_CAP_NS) when idle:APPLE_PMP_GPU_BUSY_MW(250 mW, between J773g idle0–43 mWand light GPU load1630 mW) andapple_pmp_die_idle(cpus_idle, rail_error, gpu_mw)indrivers/thermal/apple-pmp-hold.h, and pass it toapple_pmp_gated_hold_sample()indrivers/thermal/apple-pmp-thermal.c.>= 250 mWends an idle dark hold at2 s(APPLE_PMP_GATED_HOLD_NS); a failed/missing rail read leavesmain's behavior intact (since the power policy already holds CPUs and GPU at their floor on rail faults).apple_pmp_test_die_idleandapple_pmp_test_dark_idle_rate) and host-test (tools/asahi/pmp-thermal-poll-tests.pydark_sensor_tests()+ mutation checks) coverage.Tested:
52e3af5dd8ac:apple-pmp-policyKUnit:15/15PASSED (including 10-minute 14 s dark-spell rate test:0errors,6000slow polls).scripts/checkpatch.pl --strict:0errors,0warnings,0checks.W=1:drivers/thermal/apple-pmp-thermal.oanddrivers/thermal/apple-pmp-policy-test.oclean (0warnings).tools/asahi/pmp-thermal-poll-tests.pywith mutation checks +test-thermal-policy.py):PASS.Risk: two-way door · M4 (T8132)
apple-pmp-thermal. Preservesmain's exact15 sidle hold wheneverPP1b < 250 mWor on rail read errors; only ends an idle dark hold at2 s(starting the normal busy-hold clock) when a validPP1bread reports>= 250 mWso GPU work cannot heat a dark die unseen for 15 s. Revertible cleanly with no changes to thermal trips, fast-poll thresholds, or rail-fault policy.Not yet:
52e3af5dd8acagainst currentmain(10-minute idlesensor error -61/arch_timer/PP1b, plus GPU load while CPUs idle).52e3af5dd8ac(pending J604 A/B vsmain).52e3af5dd8ac.History and relation to #2774
main(#2774,apple-pmp-hold.h) holds a cool dark die while CPUs are idle for up to15 s(APPLE_PMP_GATED_IDLE_CAP_NS) regardless of GPU rail power.e49cdb436757tightened the cap to2–10 sat8 C/swith a50 mWfresh-rail gate, which regressed idle desktop hold expiries on J773g (+371vs+78sensor error -61over 10 min at43.5–46.5 C).52e3af5dd8acrestoresmain's15 scap, drops the headroom formula andrail_ns, raises the GPU busy threshold to250 mW, and leaves failed rail reads onmain's path, keeping only the active-GPU2 sfail-closed gate overmain.