Skip to content

cpufreq: apple-soc: honor min frequency floor during idle parking - #4016

Merged
DjDeveloperr merged 1 commit into
mainfrom
satchlj/cpufreq-park-min-floor
Dec 3, 2026
Merged

DjDeveloperr merged 1 commit into
mainfrom
satchlj/cpufreq-park-min-floor

Conversation

@satchlj

@satchlj satchlj commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

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 permit park_pstate.
Tested: T6050 / J775c (Apple M5 Max, default command line) at exact head 43daca44a907 inside batched candidate 7f0aa88166ed (linux-aurora-ane4): boots cleanly, 0 failed units, 0 new kernel errors, 3/3 15 s RTC s2idle PASS (suspend_stats 3/0), apple-cpufreq/park failed 0 across all 3 clusters; same apple-soc-cpufreq.c change also A/B verified under ANE load (with #3964 engine bridges): unet-320 on cpu0 (pc0 idle) drops from 1,054.0 us to 619.4 us (IN_PLACE 542.8 us), then re-parks cpus 12-17 cleanly within 2 s of ANE idle (parks 140 -> 153, failed 0, policy12 min=300000, wall power 14.80 W -> 8.81 W). KUnit apple_soc_cpufreq.* 73/73 passed (0 skipped); checkpatch.pl --strict 0/0/0.
Risk: two-way door · all Apple Silicon Macs using apple-soc-cpufreq idle 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) updates min_pstate via apple_soc_cpufreq_limits(), but apple_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 to park_pstate.

This change:

  • Adds apple_soc_cpufreq_park_allowed() checking whether park_pstate stays within the active min_pstate..cap_pstate clamp.
  • Refuses to park in apple_soc_cpufreq_park_now() while park_pstate is below min_pstate.
  • In 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.
  • In apple_soc_cpufreq_verify(), re-checks idle re-parking when the post-transition verification timer completes cleanly.
  • Adds cft_test_park_min_floor to apple-soc-cpufreq-test.c.
Evidence
$ ./scripts/checkpatch.pl --strict --git HEAD~1..HEAD
total: 0 errors, 0 warnings, 0 checks, 171 lines checked

$ ./tools/testing/kunit/kunit.py exec --arch=arm64 --build_dir=.kunit-pr1 --qemu_args="-accel tcg -smp 2" "apple_soc_cpufreq.*"
    ok 36 cft_test_park_min_floor
# apple_soc_cpufreq: pass:57 fail:0 skip:0 total:57
# Totals: pass:73 fail:0 skip:0 total:73

T6050 / J775c batched candidate 7f0aa88166ed (contains 43daca44a907 unchanged, default cmdline):
- failed_units=0, suspend_stats: success=3 fail=0, 0 new kernel errors
- apple-cpufreq/park: cpus 0-5 failed 0, cpus 6-11 failed 0, cpus 12-17 failed 0
- policy12 min returns to 300000 after ANE bursts

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>
@satchlj
satchlj marked this pull request as ready for review December 3, 2026 00:03
@satchlj
satchlj requested review from a team as code owners December 3, 2026 00:03
@satchlj satchlj closed this Dec 3, 2026
@satchlj satchlj reopened this Dec 3, 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: 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 RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@github-actions github-actions Bot added area:power Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) ready-to-merge Meets the merge policy: merge it (bot) labels Dec 3, 2026
@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Merge readiness at 43daca44: ready to merge

Check Detail
CI at head ok 6 checks passed
Review ok approved by RyanTheTide, sithglan
Requested changes ok none
Hardware row at head ok in the PR body at 43daca44
Conflicts ok none
PR text ok Risk: two-way · all Apple Silicon Macs using apple-soc-cpufreq idle cluster parking.

Areas: area:power
Merge: gh pr merge 4016 --merge (Owners and Core through the bypass: add --admin).

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

@sithglan sithglan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 against clamp_pstate(park_pstate), lazy_reconcile() unparks immediately when a floor rises above park_pstate (deferring publish_cur properly if the park command is still busy), verify() uses hrtimer_is_queued() instead of hrtimer_active() when re-parking from inside the verify callback, and try_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-9 and cpus 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_freq to 2508000: held 2 s with parks 1821 -> 1821 (delta=0, failed 0).
      • Restoring scaling_min_freq to 300000: re-parked cleanly (parks 1821 -> 1828, restores 1803 -> 1810, failed 0).
    • Live KUnit apple_soc_cpufreq: 39 passed, 0 failed (18 park tests skipped on J813's idle=nop boot cmdline).

@RyanTheTide RyanTheTide added question Further information is requested and removed question Further information is requested labels Dec 3, 2026

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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->waited still stops every new park after apple_soc_cpufreq_drain(), so suspend and exit keep their order.
  • Merges cleanly with main. W=1 arm64 build of apple-soc-cpufreq.o and cpuidle-apple.o: no warnings. checkpatch --strict is 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 two apple_soc_cpufreq_policy stats cases fail on plain main in that build, so they come from UML. The new case fails on main'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().

@DjDeveloperr
DjDeveloperr merged commit 2b26819 into main Dec 3, 2026
11 of 12 checks passed
@DjDeveloperr
DjDeveloperr deleted the satchlj/cpufreq-park-min-floor branch December 3, 2026 00:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:power Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants