Skip to content

soc: apple: clpc: use per-CPU deferrable timers when idle on idle_on_time SoCs - #3293

Merged
RyanTheTide merged 2 commits into
mainfrom
feat/clpc-idle-deferrable-timers
Nov 27, 2026
Merged

RyanTheTide merged 2 commits into
mainfrom
feat/clpc-idle-deferrable-timers

Conversation

@erikwb

@erikwb erikwb commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What: On idle_on_time SoCs with PMC sampling, replace the continuous 4 ms idle polling work with per-CPU pinned deferrable timers while no floor vote is held (whenever nohz_full is not enabled), eliminating idle CLPC CPU wakeups while keeping active sampling responsive when any CPU becomes busy.
Tested: J716c M5 Max (T6050) at a5e14b7862a0 (kernel commit 6125e3d724b0 unchanged in batched trial build 7.3.0-ewb321+ and 7.3.0-ewb323+, default command line; head commit a5e14b7862a0 updates only host tests in tools/asahi/): boots cleanly, 0 new failed units, 0 kernel errors; 3 s idle ftrace (workqueue_execute_start) saw 1 apple_clpc execution (down from ~750/3 s), cpu17 offline/online hotplug passed, 2× s2idle + 2× deep S2R passed, and battery BAAC lit idle draw dropped from 5,284 mW (ewb317) to 4,857 mW (-427 mW combined across the 5 PRs).
Risk: two-way door · idle_on_time Apple Silicon SoCs with PMC CLPC (apple,t6050-clpc and any other idle_on_time SoCs).
Not yet: Hardware run on a second idle_on_time board (e.g. J714s).

Details
  • Allocates per-CPU TIMER_DEFERRABLE | TIMER_PINNED timers when clpc->has_pmc && clpc->hw->idle_on_time.
  • When entering idle (apple_clpc_queue(clpc, true)) without tick_nohz_full_enabled(), preserves any fresh client demand already queued on clpc->work (delayed_work_pending(&clpc->work)) instead of cancelling it, then arms pinned deferrable timers across idle_online_cpus.
  • Serializes timer drain/re-arm with CPU hotplug (cpuhp_setup_state_multi) and apple_clpc_halt() through a dedicated idle_lock (strictly ordered inside cpuhp and sample_lock), deleting timers on CPU teardown before migration and initializing fresh baselines when CPUs come online.
  • Refreshes the per-CPU baseline on backwards or di > dw idle samples rather than triggering spurious workqueue wakeups.
Evidence
  • Batched trial build 7.3.0-ewb321+ (ac261293cd3f, contains 6125e3d724b0 unchanged) on J716c (T6050):
    • ftrace 3 s idle workqueue_execute_start: clpc_wq_3s=1.
    • CPU hotplug: echo 0 > /sys/devices/system/cpu/cpu17/online && echo 1 > ... succeeded (online=0-17), 0 lockdep/kernel warnings.
    • 2× s2idle + 2× deep S2R resumed cleanly, 0 kernel errors.

…time SoCs

On idle_on_time SoCs with PMC sampling, replace the continuous 4 ms
idle sampling timer while no floor vote is held with per-CPU pinned
deferrable timers (minimum 2 jiffies step) whenever nohz_full is not
enabled. Idle NO_HZ CPUs take zero CLPC wakeups while any busy CPU
kicks active sampling once its tick resumes.

Preserve any fresh client demand already queued on clpc->work when
entering idle, serialize timer drain/re-arm with CPU hotplug and halt
via a dedicated idle_lock (ordered inside cpuhp and sample_lock) and an
idle_online_cpus mask so teardown never migrates a pinned timer and
newly onlined CPUs start with a fresh baseline, and refresh the
baseline on backwards or invalid idle deltas.

Signed-off-by: Erik Bourget <[email protected]>
@erikwb
erikwb requested review from a team as code owners November 26, 2026 18:17
@erikwb
erikwb requested review from LiamRay11 and maralcbr November 26, 2026 18:17
@github-actions github-actions Bot added area:platform Area from CODEOWNERS (bot) blast:m5 Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Merge readiness at a5e14b78: not ready yet

Check Detail
CI at head no failing: pr-text / pr-text
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok in the PR body at a5e14b78
Conflicts ok none
PR text ok Risk: two-way · idleontime Apple Silicon SoCs with PMC CLPC (apple,t6050-clpc and any other idleontime SoCs).

Areas: area:gpu, area:platform

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

Mirror the new idle_armed, idle_timers, idle_lock, and cpuhp fields in
the CLPC host-test harnesses and accept the extra pre-timer work cancel
in apple_clpc_halt() while preserving the --old-ref control.

Signed-off-by: Erik Bourget <[email protected]>
@erikwb
erikwb requested a review from DjDeveloperr as a code owner November 26, 2026 20:39
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) needs-hw-row No hardware row at the PR head (bot) ci-failing A check failed at the PR head (bot) and removed ci-failing A check failed at the PR head (bot) needs-hw-row No hardware row at the PR head (bot) labels Nov 26, 2026

@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.

Verdict at a5e14b7: merge.

Blockers: none.

Checked:

  • Scope comes from the hardware data: per-CPU timers only where has_pmc && hw->idle_on_time (T6041, T6050 entries), and only when nohz_full is off. Other SoCs get a cpuhp state with no instance, so their callbacks return early.
  • Init order: cpuhp_setup_state_multi() failing fails the driver, so a probe never runs with an empty idle_online_cpus (which would have meant no idle sampling at all).
  • Teardown: halt sets stopped and disarms first, cancels the works, then timer_delete_sync()s every per-CPU timer under idle_lock, then runs the existing two cancel rounds. A callback that raced past the stopped check can queue work once, which the later round cancels. stop removes the cpuhp instance (nocalls) before halt.
  • Hotplug: cpu_down deletes the pinned timer on the dying CPU before migration; cpu_online re-arms only while armed and not stopped. Lock order is cpuhp/sample_lock -> idle_lock, and nothing takes cpus_read_lock() under idle_lock.
  • Row validity: the J716c row ran kernel commit 6125e3d724b0, which the head carries unchanged (the head commit touches only tools/asahi/ host tests), as the fast-track byte-identical rule allows. ftrace shows 1 apple_clpc execution per 3 s idle (was ~750); hotplug, 2x s2idle and 2x deep all pass.

Follow-up: a T6041 row (J614c/J616c/J575c owners) is welcome as the second idle_on_time SoC; not a merge blocker.

@RyanTheTide
RyanTheTide merged commit 4ac70df into main Nov 27, 2026
26 of 27 checks passed
@RyanTheTide
RyanTheTide deleted the feat/clpc-idle-deferrable-timers branch November 27, 2026 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gpu Area from CODEOWNERS (bot) area:platform Area from CODEOWNERS (bot) blast:m5 Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants