Repository navigation
thermal/drivers/apple-pmp: ride out idle dark sensors and preserve zone backoff - #2774
Conversation
|
The hold only engages when all six records are dark, so CPU heat should keep a real reading. Most of the change looks right: the guard still fails closed to level 8 while in error, apple_pmp_critical() still runs every poll, and recovery triggers an update straight away. A few things to address before this is safe on a fanless T8132:
Assisted-by: LLM (Claude:Opus 5.5) |
…ne backoff With cluster power-gating enabled for deep sleep, the T8132 PMP marks a cluster's die temperature records invalid (-ENODATA) while the cluster is power-gated in WFI. After cool-idle polling was slowed from 5 ms to 100 ms, quiet runtime idle routinely keeps all six PMP die sensors dark for 2.1-3.8 s at 41-54 C (and s2idle keeps clusters parked for >10 s across system sleep), exceeding the fixed 2 s APPLE_PMP_GATED_HOLD_NS timeout. Three compounding issues turned those benign idle dark stretches into repeated CPU minimum-frequency clamps and eventually a permanent lockup: 1. apple-pmp-thermal always expired the gated-sensor hold after 2 s even when the CPUs were idle and generating negligible heat, unlike the G16 cooling backstop which advances valid_ns while idle so the 2 s timeout starts only when work begins. 2. apple_pmp_thermal_prepare() skipped s2idle via pm_suspend_via_firmware() and apple_pmp_thermal_complete() only refreshed the power policy clock across deep sleep without refreshing the gated-sensor hold, letting both s2idle and firmware deep sleep consume the hold allowance before the first wake sample. 3. While cached_error was non-zero, apple_pmp_poll_work() continued calling thermal_zone_device_update() every 100 ms, stepping through all 16 exponential backoff increments of thermal_zone_recheck() (~330 s on non-EAGAIN faults; -EAGAIN rechecks every 250 ms without backing off) in ~1.55 s and tripping thermal_zone_broken_disable(). Once disabled, apple_pmp_change_mode() cleared pmp_thermal.enabled and permanently latched guard level 8 (minimum CPU frequencies) until reboot. Fix all three without adding knobs or board allowlists: - Extract the gated-sensor hold, CPU idle tracker, and zone-notify helpers into drivers/thermal/apple-pmp-hold.h. Integrate per-CPU idle counters over >=50 ms windows by accumulating busy and wall time across all online CPUs and dividing once in permille (APPLE_PMP_IDLE_BUSY_PERMILLE = 250, i.e., 25.0% of one core across the SoC) so per-CPU truncation cannot hide spread-out load. When the last valid sample was below APPLE_PMP_GATED_HOLD_MC (90 C) and CPUs are idle, hold the cool reading and advance valid_ns so the 2 s fail-closed timeout starts when CPU work begins, while tracking real_valid_ns separately to enforce a 15 s absolute fail-closed cap (APPLE_PMP_GATED_IDLE_CAP_NS) so non-CPU loads (GPU, ANE, media with gated CPU clusters) cannot suppress thermal fault detection indefinitely. Non-ENODATA errors, hot readings (>=90 C), and expired holds clear both timestamps so recovery always requires a fresh valid SRAM reading. - Pause both samplers and refresh a cool valid hold (resetting CPU idle baselines so post-wake dark reads stay bounded to 2 s) across both firmware deep sleep and s2idle in apple_pmp_thermal_prepare() and apple_pmp_thermal_complete(), and reset the hold on mode changes. - Notify thermal_zone_device_update() once on fault entry so thermal_core runs its full ~330 s exponential backoff on non-EAGAIN faults instead of tripping thermal_zone_broken_disable() at the 100 ms governor rate. Record fault_disabled when the zone is disabled during a non-EAGAIN fault (never overriding manual disables while healthy), and automatically call thermal_zone_device_enable() once sampling recovers so the zone exits the latched fault state through the normal 200 ms cool recovery ramp from guard level 8. - Update the gated-hold comments in include/linux/soc/apple/pmp-cooling.h and document the window, busy-permille, and idle-cap rationale in drivers/thermal/apple-pmp-hold.h. - Expand drivers/thermal/apple-pmp-policy-test.c to cover the 15 s absolute idle cap, non-truncating CPU idle tracker (priming, spread-out load, offline/re-online transitions), and fault-entry/recovery/re-enable zone notifications. Signed-off-by: Diljit Singh <hey@djdev.me>
6f3cc69 to
fcd71a1
Compare
|
@RyanTheTide Thanks for the detailed review! Rebased onto
Assisted-by: LLM (Gemini:4 Neon) |
|
Not on integration/aurora: on daa9e2d apple-pmp-thermal still expires the gated-sensor hold after a fixed 2 s whatever the CPUs are doing. The commit applies cleanly on daa9e2d, and the PMP host tests pass on that tree (run-host-tests.py --only pmp, 22/22). The R2 changes answer the code points of the review (absolute cap, non-truncating busy accounting, zone re-enable). What is still missing is the fanless side: every row so far is from the J773g, and this changes how long a cool reading is trusted on the M4 Airs too. The J713 rows listed in the review (sustained all-core load, long idle with per-record validity, GPU-only and ANE-only load with idle CPUs, deep-sleep cycles including one straight after a hot load) are needed before this merges. |
There was a problem hiding this comment.
Verdict: HOLD at fcd71a1e.
Blockers:
drivers/thermal/apple-pmp-hold.h:57refreshes the absolute age of the last real sample even though resume supplies no sample. The device's.completecallback also runs after an aborted suspend. A cool reading aged 14.9 s becomes age zero on that path and can outlive the claimed 15 s cap.ktime_get_ns()already excludes suspended time. Preserve the real-sample timestamp across completion and add an abort or repeated-resume fixture demonstrating that only a valid sensor read renews the absolute cap.drivers/thermal/apple-pmp-thermal.c:582infers who disabled the thermal zone fromcached_error. Both a user disable during a fault and the core's fault disable call the same mode callback. The next good sample then automatically re-enables a zone an operator explicitly disabled during a fault. Preserve the manual mode policy by tracking the actual disable reason or leaving re-enable to the owner. Test both disable origins.- Justify the new protective hold interval with a machine-provided limit or retain the existing bound. Remove the AI attribution from the PR body, resolve the base conflict with a forward merge, and provide the outstanding fanless J713 workload and hot-suspend evidence on the resulting commit.
Checked: Read the full patch, the thermal core mode paths, and the existing review. The idle arithmetic now divides after accumulating CPU deltas. Compiled the exact resume helper in a host harness and observed the 14.9 s sample become age zero without a new reading. No DT files changed.
|
@DjDeveloperr: stale-PR closeout. Everything that is open, in one list:
|
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
Hardware data point, J713 (MacBook Air M4, fanless), saved kernel
|
Conflicts in apple-pmp-thermal.c, apple-pmp-policy-test.c and pmp-cooling.h: keep main's lifecycle-locked sleep prepare, main's hold constants and its unbudgeted power tests; take this branch's gated hold in apple_pmp_sample() and its resume refresh.
…ack who disabled the zone Review items on the dark-sensor hold: - apple_pmp_gated_hold_resume() renewed real_valid_ns, the age of the last real sensor read. .complete also runs after an aborted suspend, so a cool reading 14.9 s old became 0 s old with no new read and could outlive the 15 s cap. ktime_get_ns() does not count suspended time, so the cap needs no help across sleep: only restart the busy-hold clock (valid_ns) and leave the real-sample age alone. - apple_pmp_change_mode() treated any disable during a sensor fault as the core's broken-sensor disable, so a zone that user space disabled during a fault was re-enabled by the next good read. The core disables from thermal_zone_broken_disable(), in the task whose temperature read just failed; record that task in .get_temp and count a disable as a fault disable only when it comes from it. - Keep main's single transient PMP SRAM refresh glitch hold (100 ms below passive throttling, counted from the real read) that the merge would otherwise have dropped. KUnit: aborted and repeated resumes do not stretch the cap, both disable origins, the transient edges. pmp-thermal-poll-tests: mock the hold and idle tracker that .complete now touches.
RyanTheTide
left a comment
There was a problem hiding this comment.
The manual-disable case still fails when one userspace thread reads thermal_zoneN/temp during a cached -ENODATA and then writes disabled to thermal_zoneN/mode before the next sample. temp_show calls the same get_temp, which saves current as failed_reader; mode_store then calls the same change_mode from that thread. I compiled the exact apple_pmp_fault_disable helper and confirmed it classifies this sequence as a core fault disable. The next good sample can therefore re-enable the manually disabled zone. Please use an explicit core fault-disable reason or leave re-enable to the owner.
|
We carry this PR in our J713 (M4 Air, T8132) daily kernel alongside #3267. With cluster power-gating and slower cool-idle PMP polling (including #3546 on Running smoothly together with #3267 on our J713 daily kernel with no dark-sensor thermal zone disables or level-8 clamps. |
…hold.h apple-pmp-thermal now resolves dark sensors in apple_pmp_gated_hold_sample(), which calls apple_pmp_hold_nodata() from apple-pmp-hold.h. Check that the driver includes the helper and the helper uses the shared hold.
|
Taking this over to land it (fleet regression: a J713 on fleet91 latches at level 8, 912/900 MHz, after a few hours; ewb's daily driver needs it). Pushed onto this branch without force: a merge of main (6f41f3a), the review fixes (97dedbc) and a selftest update (2407acd). Review items (App 11-28 HOLD + the 11-29 list)
Tests: KUnit apple-pmp-policy 13/13 (UML), Rows: 97dedbc driver + J713 (M4 Air, fanless) + PASS so far. This is apple-pmp-thermal built from the head driver files on fleet91 9c353d7. Main has the same copies of these files as fleet91; the delta since then is test-only. I swapped the module live on a boot that was latched at level 8.
|
There was a problem hiding this comment.
Verdict: CHANGES REQUESTED at 97dedbc (one test line; everything else is ready)
Failure: host-tests at this head is 944/945. The one failure is asahi-m4, case test-thermal-policy.py (run 46703205769), and it reproduces locally:
tools/testing/selftests/drivers/gpu/asahi-m4/test-thermal-policy.py:302
assert 'apple_pmp_hold_nodata(' in (ROOT/'drivers/thermal/apple-pmp-thermal.c').read_text()
AssertionError
The same test passes on main (d148fbd Host tests: asahi-m4 ok). This head moves the apple_pmp_hold_nodata() call from apple-pmp-thermal.c into apple_pmp_gated_hold_sample() in apple-pmp-hold.h:199, so the source check no longer finds it. Fix only that line: check drivers/thermal/apple-pmp-hold.h for apple_pmp_hold_nodata(, and optionally check that apple-pmp-thermal.c still calls apple_pmp_gated_hold_sample(. Then asahi-m4 is 25/25 again.
Checked (delta 6f41f3a merge + 97dedbc against my 11-28 items):
- Item 1 fixed:
apple_pmp_gated_hold_resume()no longer touchesreal_valid_ns, only the busy-hold clock. An aborted or repeated.completecan't stretch the 15 s cap, andktime_get_ns()already excludes suspended time. - Item 2 fixed: a disable counts as a fault disable only when it comes from the task whose
get_tempjust failed. In this treethermal_zone_recheck()->thermal_zone_broken_disable()->__thermal_zone_device_set_mode()->.change_moderuns synchronously in that same update, while a sysfsmodewrite comes from a user task.failed_readeris cleared on a good read, a mode change, cleanup and probe. - The merge keeps main's single transient SRAM-glitch hold (below passive,
APPLE_PMP_TRANSIENT_HOLD_NSfrom the real read). There's no AI attribution in the body or commits.
Follow-ups (not blocking):
- A single program that reads
temp(failing) and then writesmode=disabledfrom the same thread would be counted as a fault disable. That's unlikely, but worth a comment.
There was a problem hiding this comment.
Verdict: MERGE at 2407acd
Correction to my previous review at this head: it was written against 97dedbc. 2407acd had already fixed the one failure it named.
Checked:
- 2407acd points the
asahi-m4source check atapple-pmp-hold.hand checks thatapple-pmp-thermal.cincludes it.test-thermal-policy.pynow passes locally at this head (exit 0, including "Shared -ENODATA hold masks brief PMP refresh glitches ..."). - 11-28 items 1 and 2 are fixed as described in my previous review: the real-sample age is no longer renewed by
.complete, and the fault disable is attributed to the failing reader task, whichthermal_zone_recheck()->thermal_zone_broken_disable()->.change_moderuns in synchronously.
Follow-ups (not blocking):
- The same-thread case (one thread reads a failing
temp, then writesmode=disabled) still counts as a fault disable, as the Ryan-account comment on 97dedbc notes. That's a narrow manual edge; track it as an issue.
|
Row: 2407acd + J713 (M4 Air) + PASS. Driver = 97dedbc's (the delta to 2407acd is the selftest only), built on fleet91. Latch cleared on a latched boot; all-core 300 s regulated with no fault; hot and cool deep suspends clean; GPU-only 2 min clean; idle at level 0 with the zone enabled for 50+ min so far. Details in the comment above. Merging per ORCH5 (ewb's J713 daily driver needs it). The App review's same-thread sysfs case (read a failing |
|
@erikwb this landed on main as 76d0b51 (merge of main + the review fixes on top of Dj's commit). Your J713 daily kernel can drop the carried copy once it rebases. If you see a level-8 latch or a zone disable after this, please post the |
Problem
With cluster power-gating enabled for deep sleep, the T8132 PMP marks a cluster's die temperature records invalid (
-ENODATA) while the cluster is power-gated in WFI. After cool-idle polling was slowed from 5 ms to 100 ms, quiet systems routinely keep all six PMP die sensors dark for 2.1–3.8 s at 41–54 °C (and >10 s across s2idle), exceeding the fixed 2 sAPPLE_PMP_GATED_HOLD_NStimeout.Three compounding issues turned those benign idle dark stretches into repeated CPU minimum-frequency clamps and eventually a permanent thermal lockup:
apple-pmp-thermalalways expired the gated-sensor hold after 2 s even when CPUs were idle and generating negligible heat (unlike the G16 cooling backstop, which advancesvalid_nswhile idle so the 2 s timeout begins only when work starts).apple_pmp_thermal_complete()refreshed the power policy clock across deep sleep, but did not refresh the gated-sensor hold timestamp, letting suspend/resume consume the hold allowance before the first wake sample.cached_errorwas non-zero,apple_pmp_poll_work()kept callingthermal_zone_device_update()every 100 ms, stepping through all 16 exponential backoff increments ofthermal_zone_recheck()in ~1.55 s and trippingthermal_zone_broken_disable(). Once disabled,apple_pmp_change_mode()clearedpmp_thermal.enabledand permanently latched guard level 8 (minimum CPU frequencies) until reboot.Fix
No knobs or board allowlists:
drivers/thermal/apple-pmp-hold.hand integrate per-CPU idle counters over ≥50 ms windows. When the last valid sample was belowAPPLE_PMP_GATED_HOLD_MC(90 °C) and summed busy percentage across online CPUs is below 25% of one core, hold the cool reading and advancevalid_nsso the 2 s fail-closed timeout starts only when CPU work begins. Non--ENODATAerrors, hot readings (≥90 °C), and expired holds clearvalid_nsso fault recovery always requires a fresh valid SRAM reading.apple_pmp_thermal_complete()across deep sleep, and reset the hold on mode changes.thermal_zone_device_update()once on fault entry sothermal_coreruns its own exponential recheck backoff instead of prematurely disabling the zone at the 100 ms governor rate, and resume governor updates immediately upon recovery.drivers/thermal/apple-pmp-policy-test.c.Verification
Host / KUnit
drivers/thermal/apple-pmp-policy-test.c).Hardware (
dcp68, M4 Mac miniJ773g,7.3.0-ARCH-m4prod7)idle-pre-s2r.log):tz0=enabled,p0=4464000,p1=2892000,die=51.25–52.5 C,err61=0,disabled=0.NUB.SPMI0.SW3,0 -> 1) + 60 s post-wake cool idle (idle-post-s2r.log):tz0=enabled,p0=4464000,p1=2892000,die=50.25–53.25 C,err61=0,disabled=0.gpubench-vk+ 57-rowsuite/plan-90pct.txtsweep (boot2-clean-verify.log,gpubench-v3tc-clean-pmp.log):tz0=enabled,disabled=0, GPUsensor_errors=1->1 (+0).