Skip to content

cpufreq: schedutil: run CPUs that stay busy at full speed (busy_boost_us, admin tunable, default off) - #2479

Open
satchlj wants to merge 1 commit into
integration/aurorafrom
satchlj/schedutil-busy-full-speed-20261119
Open

satchlj wants to merge 1 commit into
integration/aurorafrom
satchlj/schedutil-busy-full-speed-20261119

Conversation

@satchlj

@satchlj satchlj commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Claude Opus 5.5 on @satchlj's behalf.

This adds a schedutil busy_boost_us tunable. When a CPU has not entered its idle loop for that long, schedutil requests its maximum capacity until the CPU idles again. Without it, a CPU that has clocked down takes about 165 ms to reach 4 GHz under a flat-out load on an M5 Max (T6050) performance core, because frequency-invariant utilization grows only in proportion to the current frequency. The commit message has the full rationale.

The default is unchanged: the tunable is 0, which means never, on every policy. After review (second commit): it is an admin tunable only. The first commit's per-driver policy->busy_boost_us field is removed, so no driver can turn it on per SoC. Making it a default would need a hardware property and rows from several SoCs; this PR claims no default for T6050.

Evidence (J775c, Mac Studio M5 Max, earlier lobata kernel; measured 2026-11-05)

Measured in the same boot, toggling the tunable (4000 µs vs 0):

busy_boost_us=0 busy_boost_us=4000
time for an S core to reach 4 GHz from idle 84 ms (165 ms on the kernel before) 7 ms
cold first-touch page fault 597–715 ns 380 ns (macOS: 491 ns)

The cost of the boost, on that kernel:

  • a 10 ms-busy-per-100 ms load drew 13.5 W instead of 11.9 W (SMC DC input);
  • idle drew 10.9–11.1 W instead of 10.5 W.

That cost applies only where an administrator turns the boost on.

Testing on this branch

  • The commit applies cleanly on integration/aurora 26294e82.
  • It is built and booted inside the J775c candidate kernel (integration/aurora 6ae9c3ca plus 63 commits, where the tunable stays at 0).
  • Not yet built on its own on 26294e82, and not yet measured on the tip. The candidate's numbers will follow as a comment.
  • Other SoCs are not tested. With the tunable at 0 they see no change.

Assisted-by: LLM (Anthropic:Claude Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks for this, and for measuring both the ramp time and the power cost.

One structural point. We select behaviour by a hardware property, not by which machines it was tested on. An improvement behind a default-off switch that each SoC opts into ends up selected by test history:

  • include/linux/cpufreq.h:141 adds policy->busy_boost_us "to be set by the scaling driver", and kernel/sched/cpufreq_schedutil.c:897 copies it into the tunable, so the follow-up would turn it on per SoC.

The slow ramp comes from frequency-invariant utilization, which applies to any CPU that idles down under schedutil. Could you pick one of these?

  1. Make it the default wherever the hardware property holds (for example frequency invariance plus a fast-switch driver), with rows to back it.
  2. Keep it only as an admin tunable, 0 everywhere, and drop the per-driver field.

For option 1 we can run ramp and power rows on our M1 Pro, M2, M4 Pro and A18 Pro. The idle power rising from 10.5 to 11 W is worth a look first.

@satchlj satchlj changed the title cpufreq: schedutil: run CPUs that stay busy at full speed (busy_boost_us, default off) cpufreq: schedutil: run CPUs that stay busy at full speed (busy_boost_us, admin tunable, default off) Nov 20, 2026
@satchlj

satchlj commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Claude Opus 5.5 on @satchlj's behalf: thanks. I took option 2, in 787ec4422 (a new commit, no force-push). The per-driver policy->busy_boost_us field and its copy in sugov_init() are removed, and the documentation now gives the default as 0 (never). busy_boost_us is an admin tunable only, at 0 on every policy, so nothing in the tree selects it by SoC. I've updated the description so it no longer implies T6050 will get it.

Option 1 would need two things first: an explanation of the idle rise from 10.5 to ~11 W with the boost on, and rows on more than one core design. Your M1 Pro, M2, M4 Pro and A18 Pro ramp and power rows would be the right basis for that later change. I won't propose a default before both exist.

🤖 Generated with Claude Code

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks for 787ec44. With the per-driver field gone and busy_boost_us an admin tunable at 0 on every policy, nothing selects it by SoC, which resolves our point. Agreed that a default should wait for an explanation of the idle rise and rows on more than one core design; our ramp and power rows will be there when you get to it.

@satchlj
satchlj force-pushed the satchlj/schedutil-busy-full-speed-20261119 branch from 787ec44 to 13283c3 Compare November 21, 2026 21:12
@satchlj

satchlj commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Claude Opus 5.5 on @satchlj's behalf: trailer-only rewrite, removed Co-Authored-By from 2 commit(s); same trees, Signed-off-by kept (787ec44 -> 13283c3, --force-with-lease).

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

Pre-PR checklist review (§1–§6) on head 13283c387a7cf1319c7d19f60e878435ffff2e92.

Blockers

  1. Missing scx_switched_all() guard in sugov_busy_boost() (kernel/sched/cpufreq_schedutil.c) — Right above it, sugov_hold_freq() checks if (scx_switched_all()) return false; so schedutil defers to the BPF scheduler's scx_cpuperf_target(). sugov_busy_boost() omits this check and feeds max_cap into boost, which overrides util = max(util, boost) in sugov_get_util(), breaking BPF scheduler frequency control whenever busy_boost_us > 0.
  2. Cross-CPU data race and 32-bit torn read on ts->idle_entrytime (kernel/time/tick-sched.c, kernel/sched/cpufreq_schedutil.c) — tick_nohz_get_idle_entrytime_cpu() reads the 64-bit ktime_t ts->idle_entrytime with READ_ONCE() cross-CPU from sugov_next_freq_shared() (which runs on every shared-cluster cpufreq policy, including all Apple Silicon CPU clusters):
    • None of the writers in kernel/time/tick-sched.c (tick_nohz_idle_enter(), tick_nohz_irq_exit(), tick_nohz_idle_restart_tick()) use WRITE_ONCE(), creating a KCSAN data race even on 64-bit.
    • Because cpufreq_schedutil.c and tick-sched.c are architecture-independent core kernel code, a cross-CPU READ_ONCE() of a 64-bit ktime_t can tear on 32-bit SMP platforms (unlike tick_nohz_get_idle_calls_cpu(), which is unsigned long and explicitly single-CPU-policy only). Either use an architecture-safe primitive / unsigned long per-idle-entry counter (updated with WRITE_ONCE) or guard 64-bit cross-CPU reads safely.
  3. busy_boost_us sysfs ABI exposed as a silent no-op when !CONFIG_NO_HZ_COMMON (kernel/sched/cpufreq_schedutil.c) — busy_boost_us is unconditionally registered in sugov_attrs[] even though sugov_busy_boost() compiles to a stub returning 0 when CONFIG_NO_HZ_COMMON is disabled. Userspace can write a value and read it back while the feature silently does nothing. Also, in sugov_next_freq_shared(), j_sg_cpu->busy_since is stamped and compared using the calling CPU's rq_clock (time) rather than j's clock, and if a CPU has never idled (entry == 0) across sugov_start() / enabling busy_boost_us, entry == sg_cpu->busy_idle_entry immediately triggers boost.
  4. Unexplained idle/periodic power regression & §2 (Default-off manual tunable):
    • The PR's own J775c measurements show an unexplained idle power increase (10.5 W -> 10.9–11.1 W) and a +1.6 W jump on 10% periodic load (11.9 W -> 13.5 W) with busy_boost_us=4000. Note one likely mechanism in sugov_busy_boost(): on shared clusters, a single core running a >= 4 ms burst (or a wakeup/dequeue window before do_idle() updates idle_entrytime and idle_cpu() becomes true) requests max_cap for the entire 4–6 core cluster, slamming the whole cluster to peak voltage/OPP. On battery-powered Apple Silicon Macs (M1/M2/M3/M4/M5 laptops), unexplained idle/periodic power overhead is a major battery/thermal risk and needs root-cause analysis before introducing a new core schedutil sysfs ABI.
    • Under §2, shipping a default-off (0) manual sysfs tunable does nothing on the default kernel command line.
  5. §5 Evidence — Zero live-head hardware proof:
    • The PR body explicitly states: "Not yet built on its own on 26294e82, and not yet measured on the tip... Other SoCs are not tested." The only data cited is from an earlier 2026-11-05 lobata kernel.
    • Required before approval: standalone build & boot on current integration/aurora tip on the default command line with clean regression checks (0 AVC denials, 0 failed units, 0 new kernel errors), plus same-boot busy_boost_us=0 vs active A/B (ramp latency, workload perf, idle & periodic-load power/thermals) on J775c and at least one other Apple Silicon family (e.g. M1/M2/M4), with the idle power rise explained.

Non-blocking Notes

  • Commit 13283c387a7c reverts the policy->busy_boost_us field added in commit 6813616556e3; squashing the two commits avoids leaving dead intermediate ABI churn in git history.

Checklist Summary

  • §1 No model gating: Pass (per-driver policy->busy_boost_us removed in commit 2).
  • §2 Production-ready / default cmdline: Fail (default-off manual sysfs ABI with unexplained power regression).
  • §3 Safety: Needs power/thermal explanation for idle (+0.5 W) and periodic-load (+1.6 W) power rise before enabling by default; note uclamp_max still caps sugov_effective_cpu_perf() via max, which is good.
  • §4 Clean-room & attribution: Pass (both commits have human author/committer + human Signed-off-by: only; PR body discloses Assisted-by:).
  • §5 Evidence: Fail (live head 13283c387a7c has not been built or measured standalone on any Mac; zero regression run).
  • §6 Naming: Pass.
  • CI: host-tests passed on 13283c387a7c.

Assisted-by: LLM (Gemini 4 Neon)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Status: nothing equivalent is on integration/aurora at 4a17f73. kernel/sched/cpufreq_schedutil.c, kernel/time/tick-sched.c and the other two files have not changed since this branch's base, and the branch merges cleanly. The four points of the 2026-11-22 review are open on head 13283c3: the missing scx_switched_all() check, the cross-CPU read of idle_entrytime, the tunable being exposed without NO_HZ_COMMON, and the unexplained idle and periodic-load power rise. @satchlj, besides those it still needs a standalone build and a ramp/power measurement of this head on the tip; the M1 Pro, M2, M4 Pro and A18 Pro rows offered earlier still stand.

@satchlj
satchlj force-pushed the satchlj/schedutil-busy-full-speed-20261119 branch from 13283c3 to 58fde2c Compare November 24, 2026 02:10
@satchlj

satchlj commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Gemini 4 Neon on @satchlj's behalf.

Rebased and squashed onto integration/aurora (0bbe021a28bd) at 58fde2c97bd6, resolving all code/race/config blockers from @DjDeveloperr and @RyanTheTide:

  1. Added scx_switched_all() guard (kernel/sched/cpufreq_schedutil.c):
    • sugov_busy_boost() now checks if (!boost_ns || scx_switched_all()) (resetting busy_since = 0 and returning 0) so schedutil defers to BPF schedulers' scx_cpuperf_target().
  2. Eliminated cross-CPU 64-bit torn read & KCSAN data race (kernel/time/tick-sched.h, tick-sched.c, include/linux/tick.h):
    • Replaced tick_nohz_get_idle_entrytime_cpu() (reading 64-bit ktime_t ts->idle_entrytime without writer WRITE_ONCE) with a per-CPU unsigned long idle_entries counter in struct tick_sched, incremented with WRITE_ONCE(ts->idle_entries, ts->idle_entries + 1) in tick_nohz_idle_enter() and read via tick_nohz_get_idle_entries_cpu() with READ_ONCE(). This is single-word atomic on both 32-bit and 64-bit SMP with no KCSAN race.
  3. Gated busy_boost_us sysfs ABI on CONFIG_NO_HZ_COMMON + fixed clock & init edge cases (kernel/sched/cpufreq_schedutil.c, Documentation/admin-guide/pm/cpufreq.rst):
    • busy_boost_us sysfs attribute and struct fields are now compiled only under #ifdef CONFIG_NO_HZ_COMMON (no silent no-op ABI when CONFIG_NO_HZ_COMMON=n).
    • sugov_busy_boost() now measures elapsed busy time with ktime_get_mono_fast_ns() so shared-policy cross-CPU comparisons use a single monotonic clock domain, and checks !sg_cpu->busy_since (resetting on sugov_start() and whenever disabled) so a CPU that hasn't idled yet does not spuriously boost immediately when enabled.
  4. Commit hygiene:
    • Squashed the two commits into one clean commit (58fde2c97bd6), dropping the dead intermediate policy->busy_boost_us churn.
  5. Verification at 58fde2c97bd6:
    • scripts/checkpatch.pl --strict --git HEAD~1..HEAD: 0 errors, 0 warnings, 0 checks.
    • kernel/time/tick-sched.o + kernel/sched/cpufreq_schedutil.o (W=1): clean compile with 0 warnings under both CONFIG_NO_HZ_COMMON=y and CONFIG_NO_HZ_COMMON=n (CONFIG_HZ_PERIODIC=y).

Remaining §2/§5 items (standalone J775c + cross-SoC A/B ramp/power measurements and root-cause analysis of the idle/periodic power delta) remain open for follow-up hardware trial boots.

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

Pre-PR re-review (§1–§6) at 58fde2c97bd6: REQUEST_CHANGES — prior scx_switched_all(), 32-bit tearing/KCSAN, CONFIG_NO_HZ_COMMON sysfs gating, and commit-squash items are all resolved (and host-tests passed), but there is a real logic bug in sugov_busy_boost() that counts idle sleep time as busy time and should be fixed before the 03:00Z hardware boot run.

Prior Blockers Cleared

  • Added scx_switched_all() guard in sugov_busy_boost().
  • Replaced cross-CPU 64-bit ts->idle_entrytime reads with a per-CPU unsigned long idle_entries counter (WRITE_ONCE in tick_nohz_idle_enter(), READ_ONCE in tick_nohz_get_idle_entries_cpu()), eliminating 32-bit tearing and KCSAN races.
  • Gated the busy_boost_us sysfs attribute and fields on CONFIG_NO_HZ_COMMON, switched elapsed-time tracking to ktime_get_mono_fast_ns(), and squashed into a single clean commit (58fde2c97bd6).

Remaining Code Blocker (fix before 03:00Z boot run)

  1. Idle sleep time is counted as busy time in sugov_busy_boost() (kernel/sched/cpufreq_schedutil.c:448-455):
    	now = ktime_get_mono_fast_ns();
    	entries = tick_nohz_get_idle_entries_cpu(sg_cpu->cpu);
    	if (!sg_cpu->busy_since || entries != sg_cpu->busy_idle_entries ||
    	    idle_cpu(sg_cpu->cpu)) {
    		sg_cpu->busy_idle_entries = entries;
    		sg_cpu->busy_since = now;
    		return 0;
    	}
    
    	return (s64)(now - sg_cpu->busy_since) >= boost_ns ? max_cap : 0;
    • Bug: When idle_cpu(sg_cpu->cpu) is true, line 451 stamps sg_cpu->busy_since = now instead of clearing it to 0.
    • Failure scenario (occurs routinely on every shared-policy cluster, including all Apple Silicon CPU clusters):
      1. At t = 0 ms, CPU 1 enters do_idle() -> tick_nohz_idle_enter() increments ts->idle_entries to N, and CPU 1 goes idle.
      2. At t = 1 ms, sibling CPU 0 runs sugov_next_freq_shared(), calling sugov_busy_boost(cpu 1). Because idle_cpu(1) is true, it sets busy_idle_entries = N and busy_since = 1 ms.
      3. CPU 1 stays asleep in the same do_idle() pass for >= busy_boost_us (e.g., 20 ms); ts->idle_entries remains N (since tick_nohz_idle_enter() runs once per do_idle() entry).
      4. At t = 21 ms, a brief task wakes on CPU 1: enqueue_task_fair() increments rq->nr_running to 1 (idle_cpu(1) becomes false) and invokes cpufreq_update_util() -> sugov_busy_boost(cpu 1). Now busy_since != 0, entries == busy_idle_entries (N == N), and !idle_cpu(1), so (s64)(21 ms - 1 ms) >= boost_ns is immediately true and returns max_cap on microsecond 0 of waking up!
    • This breaks the stated invariant ("Work that idles in between, however briefly, is not affected") and directly explains the idle/periodic power jump (10.5 W -> 11.1 W idle, 11.9 W -> 13.5 W periodic) observed on J775c.
    • Fix: Clear busy_since = 0 when idle_cpu(sg_cpu->cpu) is true, so the busy window only starts at the first non-idle observation:
      	entries = tick_nohz_get_idle_entries_cpu(sg_cpu->cpu);
      	if (idle_cpu(sg_cpu->cpu)) {
      		sg_cpu->busy_idle_entries = entries;
      		sg_cpu->busy_since = 0;
      		return 0;
      	}
      
      	now = ktime_get_mono_fast_ns();
      	if (!sg_cpu->busy_since || entries != sg_cpu->busy_idle_entries) {
      		sg_cpu->busy_idle_entries = entries;
      		sg_cpu->busy_since = now;
      		return 0;
      	}

Checklist Summary (§1–§6 / CI)

  • §1 No model gating: Pass.
  • §2 Production-ready / §3 Safety: Fail until the idle_cpu() -> busy_since = 0 bug above is fixed (plus re-measure idle/periodic power once fixed).
  • §4 Attribution: Pass (single commit 58fde2c97bd6 with human author/committer + human Signed-off-by: only, zero AI commit trailers; PR body discloses Assisted-by:).
  • §6 Naming / CI: Pass (host-tests SUCCESS, clean merge onto integration/aurora).
  • §5 Evidence: Pending exact-head standalone J775c + cross-SoC A/B ramp/power measurements and clean regression counts (0 AVC denials, 0 failed units, 0 new kernel errors).

Assisted-by: LLM (Gemini 4 Neon)

Frequency-invariant utilization grows in proportion to the frequency a
CPU runs at, so a task that starts running flat out on a CPU clocked
down by idle takes on the order of 100 ms to reach peak OPP. Short
compute bursts after a pause run mostly near the bottom of the
frequency range.

Add an opt-in busy_boost_us tunable (default 0, disabled) under
CONFIG_NO_HZ_COMMON that requests maximum capacity for a CPU once it
has remained out of its idle loop for busy_boost_us, until it enters
idle again.

Track idle-loop entries via a per-CPU unsigned long counter
(tick_nohz_get_idle_entries_cpu()) updated with WRITE_ONCE() in
tick_nohz_idle_enter() and read with READ_ONCE(), avoiding cross-CPU
64-bit tearing and KCSAN data races. Measure elapsed busy duration
with ktime_get_mono_fast_ns() so shared-policy cross-CPU comparisons
use a single monotonic clock domain, reset the window when starting or
enabling busy_boost_us, defer to BPF schedulers when
scx_switched_all() is active, and gate the sysfs attribute on
CONFIG_NO_HZ_COMMON.

Signed-off-by: Satya Benson <satya@benson.earth>
@satchlj
satchlj force-pushed the satchlj/schedutil-busy-full-speed-20261119 branch from 58fde2c to 6810ea7 Compare November 24, 2026 02:31
@satchlj

satchlj commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Gemini 4 Neon on @satchlj's behalf.

Fixed the sugov_busy_boost() idle-time accounting bug at 6810ea7b4a16 (58fde2c97bd6 -> 6810ea7b4a16):

  • idle_cpu() handling (kernel/sched/cpufreq_schedutil.c): Check idle_cpu(sg_cpu->cpu) first and clear sg_cpu->busy_since = 0 (while recording busy_idle_entries = entries), instead of stamping busy_since = now. That ensures idle sleep time on a shared-policy sibling is never counted as busy time on wakeup; the busy window now starts only on the first non-idle observation.

Verification (6810ea7b4a16):

  • scripts/checkpatch.pl --strict --git HEAD~1..HEAD: 0 errors, 0 warnings, 0 checks.
  • make W=1 kernel/time/tick-sched.o kernel/sched/cpufreq_schedutil.o: 0 warnings under both CONFIG_NO_HZ_COMMON=y and CONFIG_NO_HZ_COMMON=n (CONFIG_HZ_PERIODIC=y).

Exact-head standalone J775c A/B ramp + idle/periodic power re-measurement + §5 regression rows are queued after the 03:00Z scheduled run.

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

Code re-review at verified live head 6810ea7b4a164d14f094bab23813c5c0132dde56.

  • sugov_busy_boost() idle-time blocker — CLEARED: Checking idle_cpu(sg_cpu->cpu) first and resetting sg_cpu->busy_since = 0 while recording busy_idle_entries eliminates counting idle sleep time toward busy_boost_ns on shared policies. Commit carries human author/committer + human Signed-off-by: only, and CONFIG_NO_HZ_COMMON gating + s64 nanosecond conversion (u32 * 1000 fits in positive s64) are clean.
  • 0 remaining code/policy/attribution blockers. Ready to flip to APPROVE once host-tests finishes green and the exact-head §5 hardware row (including idle/periodic power check with busy_boost_us active) is posted.

Assisted-by: LLM (Gemini 4 Neon)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants