Skip to content

thermal/drivers/apple-pmp: ride out idle dark sensors and preserve zone backoff - #2774

Open
DjDeveloperr wants to merge 1 commit into
mainfrom
djdev/apple-pmp-thermal-idle-enodata
Open

DjDeveloperr wants to merge 1 commit into
mainfrom
djdev/apple-pmp-thermal-idle-enodata

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

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 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 thermal lockup:

  1. apple-pmp-thermal always expired the gated-sensor hold after 2 s even when CPUs were idle and generating negligible heat (unlike the G16 cooling backstop, which advances valid_ns while idle so the 2 s timeout begins only when work starts).
  2. 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.
  3. While cached_error was non-zero, apple_pmp_poll_work() kept calling thermal_zone_device_update() every 100 ms, stepping through all 16 exponential backoff increments of thermal_zone_recheck() 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

No knobs or board allowlists:

  • Extract gated-sensor hold and CPU busy-percentage helpers into drivers/thermal/apple-pmp-hold.h and integrate per-CPU idle counters over ≥50 ms windows. When the last valid sample was below APPLE_PMP_GATED_HOLD_MC (90 °C) and summed busy percentage across online CPUs is below 25% of one core, hold the cool reading and advance valid_ns so the 2 s fail-closed timeout starts only when CPU work begins. Non--ENODATA errors, hot readings (≥90 °C), and expired holds clear valid_ns so fault recovery always requires a fresh valid SRAM reading.
  • Refresh a cool valid hold and reset CPU idle baselines in apple_pmp_thermal_complete() across deep sleep, and reset the hold on mode changes.
  • Notify thermal_zone_device_update() once on fault entry so thermal_core runs its own exponential recheck backoff instead of prematurely disabling the zone at the 100 ms governor rate, and resume governor updates immediately upon recovery.
  • Add KUnit coverage for the gated-hold state machine and CPU busy accounting in drivers/thermal/apple-pmp-policy-test.c.

Verification

Host / KUnit

  • 33/33 UBSan KUnit checks + PMP host test suites passing (drivers/thermal/apple-pmp-policy-test.c).

Hardware (dcp68, M4 Mac mini J773g, 7.3.0-ARCH-m4prod7)

  • 60 s pre-S2R cool idle (idle-pre-s2r.log): tz0=enabled, p0=4464000, p1=2892000, die=51.25–52.5 C, err61=0, disabled=0.
  • 1× Real Deep Sleep (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.
  • Clean full 24-row gpubench-vk + 57-row suite/plan-90pct.txt sweep (boot2-clean-verify.log, gpubench-v3tc-clean-pmp.log): tz0=enabled, disabled=0, GPU sensor_errors=1->1 (+0).

@RyanTheTide

Copy link
Copy Markdown
Contributor

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:

  • drivers/thermal/apple-pmp-hold.h:89-95: while "idle", valid_ns advances on every dark sample, so a cool value is reported with no time limit (the test asserts this at apple-pmp-policy-test.c:177). Idle is the summed CPU busy% across the whole system (apple-pmp-thermal.c:374-407). GPU, ANE and media load are not counted. A GPU- or ANE-bound job with little CPU time and gated CPU clusters therefore shows the last cool value for as long as it runs. The G16 backstop still expires its own hold because it uses GPU idle, but ANE and media have nothing similar. Please add an absolute cap on time without a real sample, even when idle (fail closed once after it), and show whether all six records go dark under GPU-only and ANE-only load.
  • apple-pmp-thermal.c:551-559: notifying once on fault entry only slows the zone-disable path down. The core recheck backs off from 250 ms by x1.5 and still calls thermal_zone_broken_disable() after about 330 s (thermal_core.c:261-286). After that, apple_pmp_change_mode() latches guard 8 until reboot (:585-591). Failing closed on a persistent fault is reasonable, but please either state the ~5.5 min bound in the commit message or re-enable the zone once sampling recovers. Note also that a -EAGAIN cached_error never backs off.
  • apple-pmp-thermal.c:874,899: the resume refresh only runs when pm_suspend_via_firmware(), so the ">10 s across s2idle" case in the description is not what this path handles. Please say which sleep path the numbers come from. The refresh also accepts any pre-sleep value under 90 C. Clearing cpus_idle on resume bounds that to 2 s, which seems fine.
  • apple-pmp-hold.h:63 with apple-pmp-thermal.c:399: per-CPU percentages are truncated before summing, so ten CPUs at 2.9% count as 20 (idle) when the true total is ~29%. Sum busy and wall time first and divide once, or use permille.
  • include/linux/soc/apple/pmp-cooling.h:24-27 still says the longest dark stretch measured is 0.46 s, which contradicts the 2.1-3.8 s here. The 25% and 50 ms in apple-pmp-hold.h have no measurement behind them; please say how they were chosen.
  • Tests: the KUnit cases cover the hold state machine well. The poll-loop change (single update on fault entry, update on recovery) and apple_pmp_cpus_idle() priming and offline-CPU handling are not covered.
  • Hardware: every row is from J773g, which has a fan, and the kernel is not tied to this head. For J713 at 6f3cc69 please post:
    • a 10 min all-core load: hotspot, cpufreq max and guard level against time, base and PR;
    • 30 min idle with per-record validity, the longest all-dark stretch, guard level, and no "disabling" in dmesg;
    • single-thread load pinned to an E core and to a P core at ~20% and ~30% duty, showing the busy cluster's record stays valid;
    • a GPU-only and an ANE-only load with CPUs idle, showing the record validity and the G16 backstop level;
    • 20 deep-sleep cycles, including a suspend straight after a hot load, with the first post-wake sample and guard level;
    • thermal_zone mode staying enabled and guard level never latched at 8 throughout.

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 <[email protected]>
@DjDeveloperr
DjDeveloperr force-pushed the djdev/apple-pmp-thermal-idle-enodata branch from 6f3cc69 to fcd71a1 Compare November 22, 2026 09:53
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

@RyanTheTide Thanks for the detailed review! Rebased onto integration/aurora (32bf9dd3569d2) and force-pushed R2 (fcd71a1ed5902) addressing all 6 items:

  1. Absolute cap on idle hold (apple-pmp-hold.h): Tracked real_valid_ns separately from idle-extended valid_ns and enforced a 15 s absolute fail-closed ceiling (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.
  2. Non-truncating SoC-wide CPU busy accounting (apple-pmp-hold.h, apple-pmp-thermal.c): Accumulated busy and wall time across all online CPUs over >=50 ms windows and divided 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, with offline/re-online transitions handled cleanly.
  3. Thermal zone backoff & auto-recovery: Notifies thermal_zone_device_update() once on fault entry so thermal_core runs its full exponential backoff instead of tripping thermal_zone_broken_disable() at 100 ms cadence; tracks fault_disabled only when disabled during a non--EAGAIN fault (never overriding manual disables while healthy) and re-enables the zone cleanly once sampling recovers.
  4. System sleep (s2idle + deep sleep): Pauses both samplers in apple_pmp_thermal_prepare() and refreshes a cool valid hold while resetting CPU idle baselines in apple_pmp_thermal_complete() (bounding post-wake dark reads to 2 s), and resets the hold on mode changes.
  5. Comments & documentation: Updated gated-hold comments in include/linux/soc/apple/pmp-cooling.h and documented window, busy-permille, and idle-cap rationale in drivers/thermal/apple-pmp-hold.h.
  6. Tests & live hardware verification:
    • Expanded drivers/thermal/apple-pmp-policy-test.c for the 15 s absolute idle cap, non-truncating CPU idle tracker (priming, spread-out load, offline/re-online), and fault-entry/recovery/re-enable zone notifications.
    • scripts/checkpatch.pl --strict --ignore FILE_PATH_CHANGES: 0/0/0.
    • python3 tools/asahi/run-host-tests.py --only pmp: 22/22 passed.
    • python3 tools/testing/selftests/drivers/gpu/asahi-m4/test-thermal-sensor.py: passed (75,414 rows).
    • Live hardware (dcp72-m4prod11-wave5-v7tc-s2r, M4 Mac mini J773g / T8132, 7.3.0-ARCH-m4prod11): 2/2 consecutive real deep sleeps passed; across the 60 s cool-idle window tz0=enabled, aurora-g16 sensor_errors delta +0 (3 -> 3), and continuous dark spans rode out silently up to the bounded 15 s safety ceiling, firing fail-closed right on schedule at ~16–17 s (1364.83s, 1381.05s, 1398.06s) and stepping right back down to level=0 in <0.9 s.

Assisted-by: LLM (Gemini:4 Neon)

@RyanTheTide

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot added needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) merge-conflict Conflicts with the base branch (bot) and removed merge-conflict Conflicts with the base branch (bot) labels Nov 24, 2026

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: HOLD at fcd71a1e.

Blockers:

  1. drivers/thermal/apple-pmp-hold.h:57 refreshes the absolute age of the last real sample even though resume supplies no sample. The device's .complete callback 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.
  2. drivers/thermal/apple-pmp-thermal.c:582 infers who disabled the thermal zone from cached_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.
  3. 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.

@RyanTheTide

Copy link
Copy Markdown
Contributor

@DjDeveloperr: stale-PR closeout. Everything that is open, in one list:

  1. Do not renew the real-sample age in .complete (the aborted-suspend case), and add a fixture for it.
  2. Track who disabled the zone, so that a manual disable during a fault is not re-enabled.
  3. A source for the new hold interval, or keep 2 s.
  4. Merge main (3 files conflict) and drop the Assisted-by trailer.
  5. The J713 fanless rows from the 11-23 comment, at the new head.
    This is thermal on a fanless Mac, so we will not fix it forward without you. If there is no reply in 24 h, we park it with this list.

@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Merge readiness at fcd71a1e: not ready yet

Check Detail
CI at head no failing: host-tests
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head no no line with the head SHA fcd71a1e, a Mac and a result in the PR body or a comment
Conflicts no merge conflicts with main: merge it in (no force push)
PR text adopt when you next edit add a 'Tested:' line; a 'Risk:' line (door and Macs) (guide)

Areas: none matched in CODEOWNERS

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Hardware data point, J713 (MacBook Air M4, fanless), saved kernel 7.3.0-aurora-fleet91 (9c353d7, contains #3546), not this PR's head:

  • After 5 h 27 min uptime at ~38 C: thermal thermal_zone2: Unable to get temperature, disabling!, then apple-pmp-thermal: power telemetry error -11, retaining minimum CPU/GPU ceilings every 500 ms (1482 lines so far).
  • power_status: p_level=8 e_level=8 gpu_level=8 fault=1 error=-11. scaling_max_freq is 912000 (P) / 900000 (E) under a 10-thread load, cooling devices all at 0. It stays that way through a deep-sleep cycle; only a reboot clears it.
  • Same boot: H.264/HEVC/VP9/AV1 decode took ~6 s against 2.4-3.5 s on the other Macs, and the ANE MobileNet firmware time was 0.76 ms against 0.22 ms on the J616s.
  • Before the latch the log shows sensor error -61; CPU minimum caps retained bursts and Temperature check failed (-61) every ~4 s for about 80 s. That matches point 3 of the description (the zone is disabled, then level 8 stays latched).
  • An earlier fleet91 boot logged one telemetry error at 330 s and then recovered. The short boots in between were clean.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-failing A check failed at the PR head (bot) merge-conflict Conflicts with the base branch (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants