Repository navigation
cpufreq: apple-soc: verify every SoC's transitions lazily on fast switch - #2302
RyanTheTide wants to merge 5 commits into
Conversation
Lazy verification was enabled by a separate lazy_verify flag set only on T8140. The other SoCs whose command register reads back the accepted state (T8142, T8152, T6050) still waited about a transition per request on every frequency change, and so kept schedutil off the fast-switch path: every change woke the governor kthread, which then busy-waited on the register. Nothing in the lazy scheme is specific to T8140. It needs what verify_transition already describes: a command register whose PS1 field reads back the accepted state and a BUSY bit. It uses the per-SoC transition timeout for its deadline, so T8152 and T6050 keep their 2 ms bound, and it still stops all requests when the accepted state is not the one last written, so an unexpected owner is caught as before, one request later. Waited-for requests (initial check, static governors) are unchanged; suspend first settles a pending request, as on T8140. Drop lazy_verify and key the lazy path on verify_transition. Every policy can now switch from the scheduler, and a lowered fast die-temperature limit is applied to the cluster at once on all of them, as on T8140. The lazy scheme itself is Diljit Singh's. Fixes: b11a5e9 ("cpufreq: apple: verify T8140 transitions on the next request") Signed-off-by: Ryan Murray <[email protected]>
|
M2 (J413, T8112) no-regression row: pass. This PR's patch on the production fleet74 driver source (1f710d2), built as a module and swapped in at runtime, compared with the stock module on the same boot:
s2idle x2 on rtc1 with this PR's module: 2/2 clean, no cpufreq messages after, one busy P core at 2.529 GHz after resume. Stock module restored. |
|
Claude Opus 5.5 on @satchlj's behalf: a T6050 row for this PR, and a stacked follow-up.
🤖 Generated with Claude Code |
|
Looks good; approve once T6050 (J775c) has a row on 544c498.
The rest holds up. HW row: J775c (T6050) on 544c498 + integration, the run already offered on this PR. It should show schedutil on every policy with no Assisted-by: LLM (Claude:Opus 5.5) |
|
Merge-train adversarial review (MERGETRAIN-LINUX2) at 544c498: BLOCKERS. Not merging until the blockers below are fixed or answered; the details give file:line and a failure case. Full review#2302 cpufreq: apple-soc: verify every SoC's transitions lazily on fast switch @544c4981VERDICT: BLOCKERS The mechanics are sound. The timer and lock are initialised for every policy (drivers/cpufreq/apple-soc-cpufreq.c:1505-1508). Blockers:
Nits:
Missing rows: T6050 (J775c, from satchlj, pending), T8152 (J873, an M6 owner) with a transition-latency and hard-irq count under schedutil load, T8142 (J704/J813, an M5 owner), and the Neo T8140 no-regression row. |
|
Claude Opus 5.5 on @satchlj's behalf. J775c (Mac Studio M5 Max, T6050) row for this PR's What was booted: this is not an exact-head tree.
Results
Blocker 1 cost on T6050. I counted fires of
Evidence is in lobata's session notes ( Assisted-by: LLM (Anthropic:Claude Opus 5.5) |
|
The J775c (T6050) row is in and clean. Still needed: take the pending-request retry point from each SoC's transition latency instead of the T8140 50 us (and fix the comment that states it for every SoC), then T8152 and T8142 rows under schedutil load with the verify-timer fire count, plus the Neo no-regression row. |
There was a problem hiding this comment.
Formal pre-PR review (§1–§6) at 544c49819597c0f456f947a1f7058a35e2b30da5: REQUEST_CHANGES.
Verified Clean
- Core lazy-verify mechanics: Dropping
lazy_verifyand keying onverify_transitionkeepslock,verify_timer,pending_pstate,cap_pstateinitialized for every policy (drivers/cpufreq/apple-soc-cpufreq.c:1505-1510), preserves per-SoC deadlines viaapple_soc_cpufreq_timeout(), latchestransition_failedon unexpected PS1 (:588-590, :648), and drains/settles in->set_target,->suspend, and->exit. - Integration check (
70a00e583b03): Checked against newly landed8b5a4e4c836e(drivers/cpufreq/apple-soc-cpufreq-test.c) — no directinfo->lazy_verifyreferences break compilation. - §4 Attribution / CI: Commit
544c49819597carries human author/committer andSigned-off-by:only (zero AI commit trailers); live CI (Host tests) is green.
Blockers
- §1/§2 (Hardcoded T8140 retry timing on 2 ms-bound SoCs):
drivers/cpufreq/apple-soc-cpufreq.c:84, 531, 633-636, 677-680still schedule a pending-request retry atwrite_time + APPLE_DVFS_TRANSITION_NS(50 µs, the T8140 transition time) and then re-arm the hard-IRQ hrtimer everyAPPLE_DVFS_RETRY_NS(4 µs) whileBUSYstays set. While @satchlj's J775c (T6050) kprobe measurement showed few 4 µs retry chains on T6050 (12–75 µs typical transitions), T8152 has a 2 ms bound and unmeasured transition times; a 1–2 ms transition behind a pending request would fire ~250–500 hard-IRQ timers per burst (each takingraw_spin_lock_irqsave+ MMIO read). Derive the initial retry point from the SoC's transition latency (policy->cpuinfo.transition_latencywhen supplied, or a per-SoC field next totransition_timeout_us), and update the line 531 comment that states T8140's 50 µs for everyverify_transitionSoC. - §3/§5 (Missing hardware rows for affected SoCs, including thermal-safety path on T8152):
- @satchlj's J775c (T6050) row (
eb4a446cfbe2, matchingdrivers/cpufreq/on a combined tree) is clean, and J413/J316s/J616s are unaffected (verify_transition = false). - T8152 (M6, J873g) has zero hardware evidence, even though it gains both lazy fast-switch AND immediate
apple_fast_die_cap()(:1025, a §3 thermal-safety path). - T8142 (M5) has zero hardware evidence despite switching from waited kthread to lazy fast-switch.
- T8140 (Neo, J700) no-regression row is still listed as pending.
- After fixing blocker #1, re-prove on the updated exact head (default cmdline): J775c (T6050), Neo (T8140) no-regression, and T8142/T8152 rows (schedutil fast-switch with 0
sugov:kthreads, verify-timer fire counts under load, thermal cap check on T8152, s2idle, and0 AVC / 0 failed units / 0 new kernel errors), or explicitly note and request tester runs for unavailable machines per §1/§5.
- @satchlj's J775c (T6050) row (
Non-blocking Nit
- Avoid repeating the macOS internal name
CLPCin new PR text (§4/§6).
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge at 544c49819597
Blockers:
drivers/cpufreq/apple-soc-cpufreq.c:84, 531, 633-636, 677-680: now that everyverify_transitionSoC takes the lazy path, the pending-request retry is still scheduled atwrite_time + APPLE_DVFS_TRANSITION_NS, which is T8140's 50 µs, and re-armed every 4 µs while BUSY stays set. On a SoC whose transitions take longer (T8152's bound is 2 ms), that is hundreds of hard-IRQ timer runs per transition. Fix: take the first retry point from the SoC's own transition latency (policy->cpuinfo.transition_latency, which comes from the OPP table'sclock-latency-ns, as #2516 adds for T6050), or a per-SoC field next totransition_timeout_us. Update the comment at :531 too.
Checked: no Apple material. Dropping lazy_verify and keying on verify_transition keeps the lock, timer and pending state set up for every policy and keeps the per-SoC deadlines. An unexpected PS1 still latches transition_failed. Rows: M2 (J413) no regression, and J775c (T6050) clean at this head's driver. CI green. This replaces my earlier review; this is the only blocker. #2516 is stacked on this PR.
Evidence
Read 544c4981 and Ryan's 11-21/22 notes and satchlj's J775c row.
Superseded by the review at 544c498
…wn latency Review follow-up. With every verify_transition SoC on the lazy path, a request that finds the cluster busy was retried at write_time + 50 us, T8140's transition time, and then every 4 us while BUSY stayed set. On a SoC whose transitions take longer (T8152 and T6050 allow 2 ms), that is hundreds of hard-IRQ timer runs per transition. Take the first retry point from the SoC: the OPP table's clock-latency-ns when the tree has one, otherwise an eighth of the SoC's transaction timeout, which is 50 us for the default 400 us and keeps T8140 where it was. While the transition stays busy, the re-check interval starts at 4 us and doubles up to that point, so a 2 ms transition costs about eight timer runs. Signed-off-by: Ryan Murray <[email protected]>
commented
Nov 27, 2026
|
Fixed at 1b4b8f8 (fix commit c1b6d1c plus a merge of Blocker 1 (retry timed from T8140's 50 µs, re-armed every 4 µs): the first retry point is now |
commented
Nov 27, 2026
|
Row at These SoCs don't take the lazy-verify path, so this is the no-regression row only. The T8140 (Neo) row is still owed. DetailBoth rows ran on the default cmdline with the kernel booted once as a non-default entry, then back to fleet89, which was verified afterwards (saved entry, empty next_entry, kernel removed, 0 failed, Enforcing). Per Mac: SELinux Enforcing, 0 failed units, 0 AVC, 0 err-level kernel lines, 0 oops; Wi-Fi ping OK; s2idle (rtc1, 15 s) rc=0 with ping and a 64 MiB direct NVMe read after the wake; Apple SoC watchdog armed with time left counting (44 s and 58 s of systemd's 60 s); dEQP-VK |
commented
Nov 27, 2026
|
Row at This is the T8140 lazy-verify row: under schedutil with 30 rounds of 300 ms two-thread bursts, the two policies made 4064 and 2022 transitions with no DetailNeo (J700, T8140/G17P), fixa2 booted once as a non-default BLS entry, then back to fleet89, verified afterwards (saved entry, empty next_entry, kernel removed, 0 failed, Enforcing). SELinux Enforcing, 0 failed units, 0 AVC, 0 oops, 0 err-level kernel lines; Wi-Fi up; G17P Vulkan device; dEQP-VK api.smoke 8/8 and draw.renderpass.simple_draw 4/4; watchdog armed (57 s left of 60); s2idle on rtc0 rc=0 with a 64 MiB direct NVMe read after the wake. Two lines are the same on fleet89 (baseline traced): the boot-time "G17: crash logs from the firmware data segment" note, and Wi-Fi needing ~9 s after the wake before ping answers. Logs: traces/kernel/20261127-fixa2-rows/neo/ (store). |
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge at 1b4b8f8e
Blockers:
- Requires independent maintainer approval before merge (and optional confirmation row on a newly enabled
verify_transitionSoC such as T6050 or T8142 if desired).
Checked:
drivers/cpufreq/apple-soc-cpufreq.c: commitc1b6d1c0cleanly resolves the earlier hardcoded 50 us retry blocker by settingpriv->transition_nsfromdev_pm_opp_get_max_transition_latency(cpu_dev)(which returns0when absent) falling back toapple_soc_cpufreq_timeout(info) / 8, and exponentially doublingpriv->retry_nsfromAPPLE_DVFS_RETRY_NS(4 us) up topriv->transition_nswhile busy.- Drops the T8140-only
lazy_verifyflag in favor of keying onverify_transitionuniformly acrossset_target,suspend,fast_switch,apple_fast_die_cap, andinit. - Hardware rows & CI: 3/3 CI green (
SUCCESS),MERGEABLEonmain; exact-head rows posted on J700 (T8140 lazy-verify 4064/2022 transitions, 0 failures), J316s (M1 Pro), and J413 (M2 Air). - Checked for Apple material, tool attribution, private serials, and SoC gating: clean; human
Signed-off-bypresent.
Evidence
- Head:
1b4b8f8e5bd2(base: main,mergeable: MERGEABLE,+62/-33, 3/3 CI green). - Non-blocking nit: if a future OPP table specifies
clock-latency-nssmaller thanAPPLE_DVFS_RETRY_NS(4 us),min(priv->retry_ns * 2, priv->transition_ns)would step below 4 us; clampingtransition_nswithmax(..., (u64)APPLE_DVFS_RETRY_NS)would prevent that.
left a comment
There was a problem hiding this comment.
Reviewed and verified at exact head 1b4b8f8e5bd21ee5658ccae79d8c61676b3a61cf on Apple M5 Max (J775c, T6050) (newly enabled verify_transition SoC):
- Code audit: Removing the separate
lazy_verifyflag and gating lazy fast-switch verification,->target_indexdrain, suspend settle, and fast die-temperature capping onverify_transitionis consistent across all paths. Computingpriv->transition_nsfromdev_pm_opp_get_max_transition_latency()(falling back totimeout / APPLE_DVFS_TRANSITION_DIV) and exponentially backing offpriv->retry_nsfromAPPLE_DVFS_RETRY_NSup topriv->transition_ns(reset on everyapple_soc_cpufreq_lazy_write()) cleanly resolves the earlier T8140-specific retry-timing review finding. - Live T6050 verification (
1b4b8f8e5bd2, one-shot Aura trial with carried J775c DTB,0failed systemd units):- All 3 T6050 policies (
policy0CPUs 0–5,policy6CPUs 6–11,policy12CPUs 12–17) bound toapple-cpufrequnderschedutilwith 0sugovkthreads (fast_switch_possible = trueactive). - 30 rounds x 300 ms 18-thread bursts (150 ms idle gaps):
policy0432 -> 688(+256),policy6425 -> 688(+263),policy12649 -> 1005(+356) transitions. ->target_indexdrain path (schedutil -> performance -> powersave -> schedutilon all 3 policies): clean (690 / 693 / 1013total transitions).dmesg:0transition_failed,0cpufreq/DVFS warnings or kernel faults.
- All 3 T6050 policies (
Verdict: MERGE at 1b4b8f8e5bd2 (once the older 544c4981 CR is cleared).
commented
Nov 30, 2026
|
One blocker remains at For example, on T8152 the timer can fire 262 µs after the write and schedule its next check for 278 µs. A replacement request at 263 µs moves that check to 267 µs even though the hardware is still processing the same write. In a timing model with BUSY held for 2 ms, replacing the pending target every 8 µs from that point gives 220 timer callbacks before BUSY clears. A single pending target gives 12. Please keep the queued retry’s expiry when replacing an already pending target. The first pending request should still be able to bring the ordinary verification timer forward. |
Main gave T6050 lazy_verify and added two lazy_verify checks (the non-fast-switch target path and policy-bounds verification) plus a KUnit fixture that reads it. This branch keys lazy verification on verify_transition for every SoC, so T6050 drops lazy_verify and those checks and the fixture use verify_transition. Without this the merged tree does not build, although GitHub reports no text conflict. Signed-off-by: DjDeveloperr <[email protected]>
left a comment
There was a problem hiding this comment.
Verdict: HOLD at 075213d8ec92
Blockers:
- Unaddressed review finding from
2026-11-30: A replacement request while a P-state is already pending indrivers/cpufreq/apple-soc-cpufreq.cstill pulls the queued verify timer forward to4 usfrom now, undoing the exponential backoff when the hardware remainsBUSY. - Hosted CI at
075213d8ec92is still queued/pending (3queued,1pending): wait for build,host-tests,pr-text,readiness, andapple-soc-cpufreqKUnit to pass green.
Checked:
- Audited merge commit
075213d8ec92(MERGEABLEagainstmain, 2 files+66/-38): cleanly convertsmain's newlazy_verifyreferences (includingapple-soc-cpufreq-test.c) toverify_transitionso the merged tree builds cleanly without dropping any ofmain's new checks.
Evidence
- Head:
075213d8ec923b5fd29d589f042c271e1ffa0c10(basemain,MERGEABLE). - Prior J700 (
T8140) and J775c (T6050) hardware rows remain on file for1b4b8f8e.
commented
Dec 1, 2026
|
Merge-up review (our own PR, so no approval from this account): conflict-pass merge commit 075213d: compile fix checked: the lazy_verify field is fully renamed to main's verify_transition (only a test-case name keeps the old word); retry_ns backoff is initialised on both init paths. Nothing outside the conflict. Needs a non-author approval plus CI and rows at this head before merge. |
left a comment
There was a problem hiding this comment.
My one blocker is fixed: busy-transition retries now start at the SoC's own transition latency (the OPP clock-latency, or an eighth of its timeout) and back off from there.
Main had since given T6050 lazy_verify and added two checks on it, so the merge at 075213d8 moves those checks onto verify_transition, as this branch does for every SoC. Without that, the merged tree didn't build. The driver builds with and without its KUnit suite. Left before merge: J413 and J775c rows at this head.
Main's 848ee92 gave T8142 .lazy_verify = true. This branch folds that flag into .verify_transition (every verifying SoC checks lazily on fast switch), so the T8142 entry drops the field and its KUnit case drops the matching assertion. T8142 behaviour is unchanged.
commented
Dec 1, 2026
|
Merge-up pushed at Checked: the cpufreq KUnit suite on arm64 QEMU passes (74 tests: 70 passed, 4 skipped), and Correction: the B2-MERGE lane (Ryan's merge train) made this merge commit, not @DjDeveloperr. My script copied the committer identity from the previous commit on the branch, so the commit is mislabelled as Dj's. It can't be rewritten without a force push. Dj's approval at |
left a comment
There was a problem hiding this comment.
Verdict: MERGE at 17e6b44
Checked (merge resolution against main d148fbd, which already has lazy_verify on T8140/T8142/T6050):
lazy_verifyis folded intoverify_transitionat every use: get_rate, verify_policy, set_target drain, suspend, fast_switch, fast-die cap, plusfast_switch_possible = true. On main the only verify_transition SoC without lazy_verify is T8152, so T8152 is the one SoC whose behaviour changes: it gets the fast-switch path with its own 2000 us timeout as the deadline. T8140/T8142/T6050 keep their current lazy path.- The new busy-retry backoff (
retry_nsfrom 4 us, doubling up totransition_ns, reset on each write) starts its first re-check attransition_nsafter the write.transition_nsis the OPP table's maxclock-latency-ns, or timeout/8 (50 us for 400 us). Tried to makemin(retry_ns * 2, transition_ns)shrink the interval below 4 us: that needs a table max under 4 us. The only sub-4 us latencies in Apple DTs are on s8003/t7000/t7001, which aren't verify_transition SoCs, and t8140.dtsi has noclock-latency-ns, so it uses the 50 us fallback. - The deadline, failure stop and pending-replacement logic are unchanged. B2 reports cpufreq KUnit 70 pass / 0 fail / 4 skip at this head.
Follow-ups (not blocking):
- Clamp
transition_nsto at leastAPPLE_DVFS_RETRY_NSin init, so a future OPP table with a tiny max latency can't turn the backoff into a sub-4 us re-arm loop. - T8152 (and T8142/T6050) fast-switch still has no hardware row in our lab, as the PR says.
Problem
Lazy transition verification on the fast-switch path is enabled by a
lazy_verifyflag that onlysoc_t8140_infosets (drivers/cpufreq/apple-soc-cpufreq.c:300, from b11a5e9 "cpufreq: apple: verify T8140 transitions on the next request"). The other SoCs withverify_transition(T8142, T8152, T6050) getfast_switch_possible = false(line 1540). On them every schedutil frequency change wakes the governor kthread, which then busy-waits for the transition.Change
Drop
lazy_verifyand key the lazy path onverify_transition, the match-data property that says the command register's PS1 field reads back the accepted state. Every policy now setsfast_switch_possible = true.The lazy path needs nothing beyond what
verify_transitionalready requires: the BUSY bit and the PS1 readback. Its deadline is the per-SoC transition timeout, so T8152 and T6050 keep their 2 ms bound. It still stops all requests when the accepted state is not the one last written, so an unexpected owner is caught as before, one request later. Waited-for requests (initial check, static governors, suspend) are unchanged.The lazy verification scheme is by Diljit Singh (b11a5e9 and follow-ups); this only extends it to the SoCs that already verify transitions.
Testing
Build:
drivers/cpufreq/apple-soc-cpufreq.owith W=1 (arm64, LLVM=1, release config): builds, no warnings.SoCs that gain fast switch (T8142, T8152, T6050) are not bootable in our lab; the safety argument is from code and DT review below.
Hardware (one-shot test kernel 7.3.0-aurora-swl1 = integration 0abc2f3 + this and the other open sweep PRs, 2026-11-20):
Still to run
cat /sys/devices/system/cpu/cpufreq/policy*/scaling_driver=apple-cpufreq; schedutil active;cpu_frequencytrace events under load from task context (nosugov:kthread wakeups); no "stopping requests" in dmesg.verify_transitionand already used fast switch.Per-SoC impact and safety
m6_pm_cpufreqin t8152-j873g.dts), so one policy owns each command register. It has a fast die-temperature limit; a lowered limit is now also applied to the cluster at once, as on T8140.apple,firmware-managed-thermal); the resume path that re-reads the state after a firmware sleep already ran for everyverify_transitionSoC.Not changed here
of_machine_is_compatible("apple,t8112")in module init): measured, turbo states do not raise the delivered P-core clock there. Its reason is in the comment.needs_thermal_owner, which only T8132 sets. It could be derived from match data, but those lines are the context of the open boost-control change (cpufreq: apple-soc: offer no boost control without turbo-mode OPPs #2199), so it is left for after that lands.