Repository navigation
cpufreq: apple-soc: honor min frequency floor during idle parking - #4016
Conversation
When a CPU cluster is idle-parked at park_pstate, a cpufreq QoS minimum frequency floor raised from another cluster (such as CLPC raising the ANE CPU cluster floor while ANE work runs from another cluster) updates min_pstate via the limits callback, but lazy_reconcile() previously parked or kept the cluster parked because the idle CPUs never woke to restore it. Conversely, once that floor was released back down while the cluster remained all-idle, the cluster stayed unparked at the restored P-state instead of re-parking at park_pstate. Treat park_pstate as allowed only when it is within the active min_pstate..cap_pstate clamp: - Prevent apple_soc_cpufreq_park_now() from parking while park_pstate falls below min_pstate. - In apple_soc_cpufreq_lazy_reconcile(), unpark immediately when a parked cluster is no longer allowed to stay parked, and re-park an all-idle cluster once the floor drops back to permit park_pstate. - In apple_soc_cpufreq_verify(), re-check idle re-parking when the post-transition verify timer completes cleanly. Add a KUnit test (cft_test_park_min_floor) covering raising the floor on a parked cluster, refusing to park while the floor is held, re-parking when the floor drops, and re-parking from verify(). Signed-off-by: Satya Benson <satya@benson.earth>
There was a problem hiding this comment.
Verdict: MERGE at 43daca4
Checked: Idle parking still requires the verified-transition capability and a configured cluster. I checked the shared behavior for T8140, T8142, T8152 and T6050, and the older entries without that capability. The park decision honors both the QoS floor and thermal cap. The all-CPU wake sequence is rechecked before the MMIO write, including when called from the verify timer. The author reports 73/73 KUnit cases and three exact-candidate J775c s2idle cycles passing.
RyanTheTide
left a comment
There was a problem hiding this comment.
Reviewed 43daca4. Park eligibility now uses the same policy clamp as restore, and a raised minimum starts or defers the restore through the existing verify timer. Idle re-parking retains the idle-count race check and active-command guard. The reported J775c row covers re-park after ANE load, with the second-Mac row pending.
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
sithglan
left a comment
There was a problem hiding this comment.
Reviewed at 43daca44a907 and ran a second-Mac exact-head row on J813 (M5 Air, 7.3.0-aurora-pr4016+, one-shot aura-try): PASS
- Code review:
apple_soc_cpufreq_park_allowed()cleanly gates parking againstclamp_pstate(park_pstate),lazy_reconcile()unparks immediately when a floor rises abovepark_pstate(deferringpublish_curproperly if the park command is still busy),verify()useshrtimer_is_queued()instead ofhrtimer_active()when re-parking from inside the verify callback, andtry_park_idle()re-parks an already-idle cluster when the floor drops back.W=1 drivers/cpufreq/apple-soc-cpufreq.o(LLVM 19): 0 warnings. - Live hardware check on J813 (
43daca44a907):- Boot + idle parking active on both clusters (
cpus 0,7-9andcpus 1-6,failed 0,enabled 1). - True SoC-off deep sleep (
rtcwake -d /dev/rtc0 -m mem -s 15):rc=0,dt=17s,boot object resumes 0 -> 1,wake source: NUB.SPMI0.SW3. - Post-wake min-floor hold / release test on
policy0(cpus 0,7-9):- Raising
scaling_min_freqto2508000: held 2 s withparks 1821 -> 1821(delta=0,failed 0). - Restoring
scaling_min_freqto300000: re-parked cleanly (parks 1821 -> 1828,restores 1803 -> 1810,failed 0).
- Raising
- Live KUnit
apple_soc_cpufreq: 39 passed, 0 failed (18 park tests skipped on J813'sidle=nopboot cmdline).
- Boot + idle parking active on both clusters (
DjDeveloperr
left a comment
There was a problem hiding this comment.
Read 43daca44a907 against main 2b09f588. The change is right and I found nothing to fix before merge.
What I checked
- A floor above the park state now ends the park at once, a held floor refuses new parks, and a released floor lets an idle cluster park again. The re-park from the verify timer is safe. If the timer fires on one of the cluster's own CPUs, that CPU has already left the idle count, so nothing parks. If it fires on another cluster's CPU, the wake count is read again after the flag is set, as in the idle path.
priv->waitedstill stops every new park afterapple_soc_cpufreq_drain(), so suspend and exit keep their order.- Merges cleanly with
main. W=1 arm64 build ofapple-soc-cpufreq.oandcpuidle-apple.o: no warnings.checkpatch --strictis clean. - KUnit on a two-CPU UML build (no QEMU here): 71 pass, 0 fail, 2 skip in
apple_soc_cpufreq, with all 18 park cases run. The same twoapple_soc_cpufreq_policystats cases fail on plainmainin that build, so they come from UML. The new case fails onmain's driver, so it does pin the fix.
Who changes: only SoCs that park: T6050, T8142 (J704, J813, J815), T8140 (J700) and T8152 (J873g). T8132, T604x and everything older never reach this code.
Worth knowing: the ANE is not the only user of these floors. The G17 refill floor (g17/feed.rs) asks for 100% of every cluster's top frequency on M5 and 50% on J700. Until now a parked cluster ignored it. With this change the idle clusters follow it too while the GPU waits on the host. That is what the feed was written for (it predates parking), but nobody has measured the power on a laptop. I'll ask for a J714s before/after on the next composite. It doesn't hold this.
Small things for a later patch: the "Idle parking" comment still says a new limit waits for a CPU to wake and that only the last CPU in and the waking CPUs take the lock. The PR body names apple_soc_cpufreq_limits(), but the code is in apple_soc_cpufreq_verify_policy().
What: Unpark an idle-parked CPU cluster when a cpufreq QoS minimum frequency floor rises above
park_pstate, prevent re-parking while that floor is held, and re-park an all-idle cluster once the floor drops back to permitpark_pstate.Tested:
T6050 / J775c(Apple M5 Max, default command line) at exact head43daca44a907inside batched candidate7f0aa88166ed(linux-aurora-ane4): boots cleanly,0failed units,0new kernel errors, 3/3 15 s RTCs2idlePASS (suspend_stats 3/0),apple-cpufreq/parkfailed 0across all 3 clusters; sameapple-soc-cpufreq.cchange also A/B verified under ANE load (with#3964engine bridges):unet-320oncpu0(pc0idle) drops from1,054.0 usto619.4 us(IN_PLACE542.8 us), then re-parkscpus 12-17cleanly within 2 s of ANE idle (parks 140 -> 153,failed 0,policy12 min=300000, wall power14.80 W -> 8.81 W). KUnitapple_soc_cpufreq.*73/73passed (0skipped);checkpatch.pl --strict0/0/0.Risk: two-way door · all Apple Silicon Macs using
apple-soc-cpufreqidle cluster parking.Not yet: Regression row on a second Apple Silicon generation (requested via team regression queue).
Details
When all CPUs of a cluster are idle and parked at
park_pstate, a QoS minimum frequency floor raised from another cluster (such as CLPC raising the ANE CPU cluster floor while ANE work runs on another cluster) updatesmin_pstateviaapple_soc_cpufreq_limits(), butapple_soc_cpufreq_lazy_reconcile()previously kept the cluster parked because none of its CPUs woke to trigger a restore. Conversely, when the floor was later released while the cluster remained idle, the cluster stayed unparked at the restored P-state instead of returning topark_pstate.This change:
apple_soc_cpufreq_park_allowed()checking whetherpark_pstatestays within the activemin_pstate..cap_pstateclamp.apple_soc_cpufreq_park_now()whilepark_pstateis belowmin_pstate.apple_soc_cpufreq_lazy_reconcile(), unparks immediately when a parked cluster is no longer allowed to stay parked, and attempts to re-park an all-idle cluster when the floor drops back down.apple_soc_cpufreq_verify(), re-checks idle re-parking when the post-transition verification timer completes cleanly.cft_test_park_min_floortoapple-soc-cpufreq-test.c.Evidence