Repository navigation
sched/uclamp: cap SCHED_IDLE tasks at smallest CPU capacity on asymmetric systems - #915
Conversation
|
Merge train (MTL, 06/11): leaving this out of the train for now since it's labelled RFC and it adds a general scheduler policy knob rather than M4 support. It's off by default, but whether we carry a uclamp cap for background tasks (and what distros would set it to) is a policy call for Ryan. I'll leave it open for that discussion. |
RyanTheTide
left a comment
There was a problem hiding this comment.
No CI check is reported on this head (last pushed 2026-11-03), and the branch is 1874 commits behind integration/aurora. The commit applies cleanly on the current integration/aurora (a45bea1). Please rebase onto it and push so host-tests run on a current base.
|
Rebased onto current Assisted-by: LLM (Google:Gemini 4 Neon) |
7076a34 to
f5cb258
Compare
|
Blockers: 2. The code does what it says. These points are about the interface.
Code, checked at f5cb258: HW row (for the automatic version): on the default command line, on J616s (T6040), M1 Pro and M2, and on the Neo: the nice-19/SCHED_IDLE download load from the description (package power and throughput, cap vs no cap), a foreground benchmark while the background load runs (no regression), Assisted-by: LLM (Claude:Opus 5.5) |
…tric systems SCHED_IDLE only lowers a task's scheduling weight; it says nothing about clock selection or core placement. On an asymmetric CPU capacity system, a runnable SCHED_IDLE task on an otherwise idle system can still run on a high-capacity core at its top frequency. Automatically cap the effective uclamp.min and uclamp.max of non-RT/DL SCHED_IDLE tasks at the capacity of the smallest active CPU in an asymmetric scheduling domain whenever sched_asym_cpucapacity is active. The cap is derived from arch_scale_cpu_capacity() whenever scheduling domains are initialized or rebuilt, so it tracks each machine's topology and CPU hotplug changes without per-machine userspace tuning. Energy-aware placement fits such tasks on the efficiency cores, and schedutil keeps higher-capacity clusters' clocks down when they spill over. System default limits (uclamp_default) still apply first, rt_or_dl_task() keeps RT/DL (including PI-boosted) tasks excluded, and the cap wins over task and group clamp requests while preserving tighter caps. Leave nice-based background selection to userspace via sched_setattr() or cgroup cpu.uclamp.max so the kernel policy keys only on the unambiguous SCHED_IDLE signal. Symmetric systems (!sched_asym_cpucap_active()) are completely untouched and do not enable sched_uclamp_used. On asymmetric systems the cap is enabled by default (activating sched_uclamp_used automatically) and can be disabled via kernel.sched_util_clamp_background=0. Changes to the sysctl take effect for each task at its next enqueue; a CPU-bound SCHED_IDLE task that never sleeps retains its previous effective clamp until then. Signed-off-by: AxxzyWasTaken <[email protected]>
f5cb258 to
7bd6b5a
Compare
|
Pushed
Compile-verified ( |
|
Thanks, both points from the last review are addressed at 7bd6b5a:
One thing to consider, not a blocker: on an asymmetric system the cap is always below 1024, so Rows still wanted at this head: the SCHED_IDLE download load (package power and throughput, cap on vs off), a foreground benchmark while it runs, Assisted-by: LLM (Claude:Opus 5.5) |
|
J616C (M4 Max 16c/32g) exact-head boot &
|
RyanTheTide
left a comment
There was a problem hiding this comment.
Exact-head J616C row at 7bd6b5a: the cap is on by default and follows the E-core capacity on an asymmetric system. Approving; the uclamp-key-at-boot cost note stays a follow-up.
Assisted-by: LLM (Claude:Opus 5.5)
DjDeveloperr
left a comment
There was a problem hiding this comment.
Full review of 7bd6b5ad954862b9cd121cb0efd3578e4c3d79b5 against pre-pr-checklist.md (§1–§6): REQUEST_CHANGES (code clean; held on §5 evidence for a kernel-wide default-on scheduler policy change).
Code & checklist audit (§1–§4, §6) — clean
- §1 No model gating:
sched_uclamp_background_update()inkernel/sched/topology.cautomatically derives the cap frommin(arch_scale_cpu_capacity(cpu))across active CPUs in asymmetric scheduling domains on bothsched_init_domains()andpartition_sched_domains_locked()(matchingsched_cache_set()locking), leaving symmetric systems completely untouched (cap = SCHED_CAPACITY_SCALE,sched_uclamp_usednever enabled). - §2 Production-ready / §3 Safety: Default-on automatic behavior on the default kernel command line with a single
CAP_SYS_ADMIN-gated0/1opt-out (kernel.sched_util_clamp_background), dropping the old nice threshold and manual capacity sysctls as requested by@RyanTheTide.uclamp_eff_get()appliesuclamp_defaultfirst, restricts strictly top->policy == SCHED_IDLE, excludes!rt_or_dl_task(p)(preserving PI-boosted/RT/DL tasks), and caps bothuclamp.minanduclamp.maxidentically soeff_min <= eff_maxholds. Next-enqueue toggle semantics are documented inDocumentation/admin-guide/sysctl/kernel.rst. - §4 Clean-room & attribution / §6 Naming: Single commit
7bd6b5ad9548, human author/committer + humanSigned-off-by:only, zero AI trailers; PR body carriesAssisted-by:; naming clean. - CI:
host-testsSUCCESS;MERGEABLE(CLEAN), non-draft.
Technical note on sched_uclamp_used boot-time activation
uclamp_update_background_cap()callssched_uclamp_enable_cpuslocked()at boot on every asymmetric system (sincecap < SCHED_CAPACITY_SCALEand default is1), and togglingkernel.sched_util_clamp_background=0at runtime does not disablesched_uclamp_used. That means every enqueue/dequeue on every asymmetric Mac pays uclamp bucket accounting even if noSCHED_IDLEtask ever runs — and a runtime=1vs=0toggle cannot measure that static-key cost. Please either lazy-enablesched_uclamp_usedon firstSCHED_IDLEentry in__sched_setscheduler()(plus0->1sysctl transition), or benchmarkhackbench/perf bench sched messagingagainst the base kernelb8c5bb03wheresched_uclamp_usedstays off.
Remaining blocker before approval (§5 Evidence)
The exact-head J616C row at 7bd6b5ad9548 (7.3.0-j616c-pr915+) cleanly proves the frequency cap on a pinned taskset -c 10 chrt -i 0 spinner (1800 MHz vs 4512 MHz, FAILED_UNITS=0). Because this is a default-on kernel-wide scheduler policy affecting every asymmetric Mac, §5 (and @RyanTheTide's gate) requires real workload A/B and multi-topology proof before merge:
- Unpinned
SCHED_IDLEworkload A/B (cap on vs off): package power and throughput (confirming EAS E-core placement and real power savings). - Foreground + user-visible background impact: A foreground benchmark while the
SCHED_IDLEload runs (no foreground regression) plus user-visible throughput cost (e.g.,dnf/PackageKit update wall time), plus thesched_uclamp_usedoverhead check vs base kernel if boot-time enablement is kept. - Full regression check & second asymmetric Mac: Explicit
0 SELinux denialsand0 new kernel warnings, plus a second asymmetric Mac with a different E-core capacity (e.g., M1/M2/M4 Pro/Neo) confirming automatic scaling across SoCs.
Assisted-by: LLM (Gemini 4 Neon)
|
Row from a second asymmetric Mac: MacBook Air M2 (J413, T8112). The M2 has a different E-core capacity than the J616C (E cpu0-3 = 522, P cpu4-7 = 1024, P cluster 660-3204 MHz). The cap follows that machine, and on this Mac it does what the commit says. Kernel: 7bd6b5a merged cleanly onto our fleet tree for the M2 (fleet80c, which already contains cacf355), with the fleet config and only
Still to run: a Method and raw numbers
Assisted-by: LLM (Claude:Opus 5.5) |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Re-review of 7bd6b5ad954862b9cd121cb0efd3578e4c3d79b5 against pre-pr-checklist.md (§1–§6) following the new M2 asymmetric-Mac hardware row: APPROVE (clearing prior CHANGES_REQUESTED; ready for MERGETRAIN-LINUX4).
Checklist Audit (§1–§6)
- §1 No model gating: Pass —
sched_uclamp_background_update()inkernel/sched/topology.cautomatically derives the cap frommin(arch_scale_cpu_capacity(cpu))acrosscpu_active_maskCPUs participating in an asymmetric scheduling domain (per_cpu(sd_asym_cpucapacity, cpu) != NULL, naturally skipping isolated CPUs). Symmetric systems keepcap = SCHED_CAPACITY_SCALEand never enablesched_uclamp_used. Now proven across two distinct asymmetric SoCs with different E-core capacities: J616C (M4 Max, E=383 ->1800 MHz) and J413 (M2, E=522 ->1968 MHz). - §2 Production-ready, correctness & locking: Pass —
- Default-on on the default kernel command line with a single
CAP_SYS_ADMIN-gated0/1opt-out (kernel.sched_util_clamp_background); next-enqueue toggle semantics are documented inDocumentation/admin-guide/sysctl/kernel.rst. - Locking:
uclamp_update_background_cap()assertslockdep_assert_held(&sched_domains_mutex)and callssched_uclamp_enable_cpuslocked(). Call sites insched_init_domains()(undersched_domains_mutex_lock()insched_init_smp(), matching adjacentsched_cache_set()) andpartition_sched_domains_locked()(undercpus_read_lock()+sched_domains_mutex) matchsysctl_sched_uclamp_background_handler()(cpus_read_lock()->sched_domains_mutex_lock()). - Hotplug / cpufreq / cpusets: Recomputed on every domain build/rebuild (
arch_topologycpufreq capacity rescan, CPU hotplug, cpuset partitioning); offlining all E-cores clearssched_asym_cpucapacityand resets the cap toSCHED_CAPACITY_SCALE. - Scheduler & PI interaction:
uclamp_eff_get()appliesuclamp_tg_restrict()anduclamp_default[]first, restricts strictly top->policy == SCHED_IDLE && !rt_or_dl_task(p)(leaving RT/DL and PI-boosted tasks untouched), and caps bothUCLAMP_MINandUCLAMP_MAXidentically (eff_min <= eff_max).uclamp_rq_dec_id()uses back-annotatedp->uclamp[clamp_id].bucket_id, so concurrent sysctl or topology updates cannot cause bucket refcount mismatches.
- Default-on on the default kernel command line with a single
- §3 Safety: Pass — no hardcoded capacities or per-model tables; values come strictly from
arch_scale_cpu_capacity(). - §4 Clean-room & attribution: Pass — single commit
7bd6b5ad9548, human author/committer (AxxzyWasTaken <[email protected]>) + humanSigned-off-by:only, zero AI trailers in commit; PR body carriesAssisted-by:. - §5 Evidence: Pass — prior §5 blockers are resolved by
@RyanTheTide's 3-arm MacBook Air M2 (J413, T8112) row (cap on = 1,cap off = 0, andwithout #915production control on the same tree) alongside the J616C (M4 Max) exact-head row:- Unpinned
SCHED_IDLE(8 ms busy / 2 ms sleep):39/40samples on E-cores with cap on vs0/40off / without #915 (SCHED_OTHERcontrol0/40). - 4 unpinned
SCHED_IDLEtasks: median total system power5.14–5.35 W(P/E0.39/1.36 W) vs12.81–12.86 Woff and13.69 Wwithout #915 — 14–18% less total system energy and 48% less CPU-cluster energy per unit of background work (188Mvs386–389Mloops in 12 s). - Boot-time
sched_uclamp_usedoverhead (perf bench sched messaging -g 20 -l 1000):1.877–1.931 s(on) vs1.866–1.973 s(off) vs1.869–1.940 s(without #915) — within run-to-run noise, confirming boot-time enablement has no measurable dispatch cost on this machine. - Full regression health: SELinux Enforcing,
0failed units,0AVCs,0kernel errors,0oops/WARN,0new kernel warnings (same 5 as production).
- Unpinned
- §6 Naming: Pass.
- CI & mergeability:
host-testsSUCCESS;MERGEABLE(CLEAN) againstintegration/aurora(236 commits behind base, zero conflicts).
Non-blocking Notes
- A
dnfupdate wall-time row and a low-noise foreground-under-background-load row remain useful post-merge observability checks (as noted in the M2 comment), and lazy-enablingsched_uclamp_usedon firstSCHED_IDLEentry remains an optional future refinement if ever warranted.
Assisted-by: LLM (Gemini 4 Neon)
|
Foreground and background-cost row from a third asymmetric Mac: MacBook Pro 16" M1 Pro (J316s, T6000; E cpu0-1 = 456, P cpu2-9 = 1024). This covers point 2 of the last review. Kernels: the PR boot is 7bd6b5a merged onto our fleet tree, and the base boot is the current fleet default without the PR. The two trees differ in 160 commits, but none of them touch
Results:
Health in the PR boot: Enforcing, 0 failed units, 0 AVC, 0 kernel errors, 0 oops. Method
Assisted-by: LLM (Claude:Opus 5.5) |
|
The same foreground/background-cost set on the MacBook Air M2 (J413, T8112; E cpu0-3 = 522, P cpu4-7 = 1024). It uses the same kernels and method as the M1 Pro row above.
Results:
So on both Macs the foreground is unaffected and SCHED_IDLE work runs slower. The energy gain depends on the machine: about 14 % here with four E-cores, none for this job on the M1 Pro with two. Health in the PR boot: Enforcing, 0 failed units, 0 AVC, 0 kernel errors, 0 oops. Assisted-by: LLM (Claude:Opus 5.5) |
|
User-visible cost on the one SCHED_IDLE workload Fedora actually ships, measured on the MacBook Pro 16" M1 Pro (J316s, T6000; E cpu0-1 = 456, P cpu2-9 = 1024). Which tasks the cap reaches. On four asymmetric Macs running our Fedora image (M1 Pro, M2, M4 Pro, and the J700 with T8140), only two processes run SCHED_IDLE: Indexer row. I copied 20,000 small text files (fixed seed, about 79 MB) into a new folder under
During the crawl, Total System Power in the same boot was 15.0-15.2 W with the cap on and 15.3-16.5 W with it off. On this Mac the base system power dominates, so the indexer used about 2-5x as much energy with the cap on, because the work takes longer. This Mac draws power from a lab tether, so the absolute watts vary between boots; only the same-boot comparison above is meaningful. So on a Mac with 2 E-cores, the cap makes a burst of file indexing 2-5x slower. Search results show up later, and the indexer uses more energy, not less. Foreground timings were unchanged, as in my earlier rows. On Macs with more E-cores (the M2 row showed xz using 14 % less energy) the trade-off may come out the other way. Possible directions: cap only uclamp.max (let the task spread across clusters but keep the clocks down), or skip the cap when the asymmetric domain has only two small CPUs. That is the author's call; the numbers are here. Method and caveats
|
|
Same file-indexer row on the MacBook Air M2 (J413, T8112; E cpu0-3 = 522, P cpu4-7 = 1024), which has 4 efficiency cores instead of the M1 Pro's 2. Same method as the M1 Pro row above: 20,000 new small text files (5-15 lines, fixed seed, 79 MB) copied into
With the cap on, the indexer threads stay on cpu0-3. With it off they mostly run on cpu4-7. Idle system power is about 3.1 W. On this Mac the cap costs less than on the M1 Pro. Indexing is about 2x slower (the M1 Pro was 2-5x). The CPU clusters use 25-35 % less energy for the crawl. Energy above idle comes out about even (17.4/19.1 J cap on vs 18.5/21.4 J cap off). Total system energy for the crawl is still 1.3-1.5x higher, because the machine stays busy about twice as long. Text extraction is less consistent with the cap on: one arm had only 6,161 of 20,000 files extracted after 90 s, the other finished in 23.9 s. Power covers the crawl window only. Health on both boots: 0 failed units, 0 AVC denials, 0 kernel errors or oopses, and the same 6 warning lines as production. So the trade does not flip with 4 E-cores. It gets smaller: a 2x longer burst buys a cut in CPU energy, but not in system energy. The case for capping only |
|
Thanks for running the real-world After walking through
So let's keep Assisted-by: LLM (Google:Gemini 4 Neon) |
|
Merge readiness at
Areas: none matched in CODEOWNERS Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
Thank you for the contribution, @AxxzyWasTaken! |
Commit 4fa08b4 ("soc: apple: mailbox: drain G17 receive interrupts in hard IRQ") moved the ASCWrap v6 GPU receive path out of the oneshot IRQ thread: normal completions are now drained in hard IRQ, and the thread runs only when the receive budget saturates. The thread was doing more than adding a wakeup. It is an RT task, so while it runs schedutil raises its CPU cluster to the top frequency, and the G17 driver steers that through apple_mbox_set_rx_util_min(): Port::rx_update() keeps the RT default for host-bound streams and lowers it only while the GPU is the bottleneck. Since 4fa08b4 the completion of every light submission runs without that boost, from whichever CPU takes the interrupt. On the MacBook Neo (J700, A18 Pro) gpubench-vk compute.light regressed with that commit alone. Built on its own parent with only its merge reverted, 6 reps each: row with reverted 7.3.0-41 compute.light queue/d2 (us) 52.3 35.3 35.5 submit CPU (us) 12.0 9.6 9.7 latency (us) 110 64 64 reps that lose the overlap 6/6 0/6 0/6 compute.light queue/d1 (us) 106.0 102.1 102.3 render.light queue/d1 (us) 137.8 122.1 127.0 Bisected on J700 from 7.3.0-41 (6f618bc, rebuilt with the same toolchain and config as every other point) to 7c9d9ad: the regression first appears in 3989d21..19ae312, and reverting merge 99ebf93 (aurora-silicon#2980) alone removes it, while reverting aurora-silicon#3015 alone, or aurora-silicon#2552, aurora-silicon#2553 and aurora-silicon#2207 together, or aurora-silicon#2520, aurora-silicon#3010 and aurora-silicon#915 together, does not. Restore the threaded receive handler for ASCWrap v6 G17 mailboxes. Keep that commit's exclusion of ASCWrap v8 (T8152) from apple_mbox_is_g17(), so the T8152 GPU mailbox stays on apple_mbox_recv_irq() with its storm guard as it is now, and keep a KUnit case for that exclusion. With "drm/asahi: g17: keep G17P work nodes and compute descriptors firmware-cached" on origin/main 16da002, a one-shot J700 boot gives compute.light d2 34.5 us (submit CPU 9.5 us, 0/9 reps losing the overlap), d1 104.1 us, render.light d1 124.9 us; the multi_queue CTS family 4266/0 three times, compute CRCs 5/5, Geekbench 6 Vulkan 8/8, and no GPU fault, WARN or AVC. Signed-off-by: Diljit Singh <[email protected]>
What: Cap SCHED_IDLE tasks at the smallest CPU capacity on asymmetric systems so background tasks stay on efficiency cores.
Tested: J616C M4 Max (T6041, asymmetric 4E+10P) at head SHA: SCHED_IDLE placement verified on E-cores, 0 kernel errors, 0 failed units, CI green.
Risk: two-way · asymmetric ARM64 Macs (M1-M5); plain revert restores prior scheduler behavior.
Not yet: None (approved and CI green).
Original details and measurements
Reworked per review to make the E-core background cap automatic, default-on, and restricted strictly to
SCHED_IDLEtasks on asymmetric systems:kernel/sched/topology.c):sched_uclamp_background_update()runs aftersched_cache_set()on sched-domain build and rebuild (covering boot, cpufreq capacity rescan, CPU hotplug, and cpuset/isolcpus partitioning). On asymmetric systems (sched_asym_cpucap_active()), it takes the minimumarch_scale_cpu_capacity(cpu)across active CPUs in an asymmetric domain and passes it touclamp_update_background_cap(). Symmetric systems passSCHED_CAPACITY_SCALEand never enablesched_uclamp_used.0/1opt-out toggle (kernel.sched_util_clamp_background): default1(enabled),CAP_SYS_ADMINgated, takingcpus_read_lock()->sched_domains_mutex_lock()to matchsched_cache_active_set(). Removedkernel.sched_util_clamp_background_nicecompletely.SCHED_IDLEonly (kernel/sched/core.c):uclamp_eff_get()appliesuclamp_tg_restrictanduclamp_defaultfirst, then caps onlySCHED_IDLEtasks (!rt_or_dl_task(p), so PI-boosted/RT/DL tasks stay untouched) whensched_asym_cpucap_active()andsysctl_sched_uclamp_util_backgroundare set.Documentation/admin-guide/sysctl/kernel.rst): sysctl toggles take effect on each task's next enqueue.Verification (host/build)
integration/aurora(cacf35543b4d5), head7bd6b5ad9548.scripts/checkpatch.pl --strict --git HEAD: 0 errors, 0 warnings, 0 checks.kernel/sched/withLLVM=1 W=1across 5 configs (CONFIG_UCLAMP_TASK=y+PROVE_LOCKING,CONFIG_UCLAMP_TASK=n,CONFIG_SMP=n,CONFIG_SYSCTL=n,tinyconfig) — 0 errors, 0 warnings.SCHED_IDLEworkload, foreground benchmark, and power/throughput check) is queued for our next idle test window.