Skip to content

sched/uclamp: cap SCHED_IDLE tasks at smallest CPU capacity on asymmetric systems - #915

Merged
DjDeveloperr merged 1 commit into
aurora-silicon:mainfrom
AxxzyWasTaken:sched-uclamp-background
Nov 24, 2026
Merged

DjDeveloperr merged 1 commit into
aurora-silicon:mainfrom
AxxzyWasTaken:sched-uclamp-background

Conversation

@AxxzyWasTaken

@AxxzyWasTaken AxxzyWasTaken commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

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_IDLE tasks on asymmetric systems:

  • Automatic smallest CPU capacity (kernel/sched/topology.c): sched_uclamp_background_update() runs after sched_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 minimum arch_scale_cpu_capacity(cpu) across active CPUs in an asymmetric domain and passes it to uclamp_update_background_cap(). Symmetric systems pass SCHED_CAPACITY_SCALE and never enable sched_uclamp_used.
  • Single 0/1 opt-out toggle (kernel.sched_util_clamp_background): default 1 (enabled), CAP_SYS_ADMIN gated, taking cpus_read_lock() -> sched_domains_mutex_lock() to match sched_cache_active_set(). Removed kernel.sched_util_clamp_background_nice completely.
  • SCHED_IDLE only (kernel/sched/core.c): uclamp_eff_get() applies uclamp_tg_restrict and uclamp_default first, then caps only SCHED_IDLE tasks (!rt_or_dl_task(p), so PI-boosted/RT/DL tasks stay untouched) when sched_asym_cpucap_active() and sysctl_sched_uclamp_util_background are set.
  • Documented next-enqueue semantics (Documentation/admin-guide/sysctl/kernel.rst): sysctl toggles take effect on each task's next enqueue.

Verification (host/build)

  • Rebased cleanly onto integration/aurora (cacf35543b4d5), head 7bd6b5ad9548.
  • scripts/checkpatch.pl --strict --git HEAD: 0 errors, 0 warnings, 0 checks.
  • Compiled kernel/sched/ with LLVM=1 W=1 across 5 configs (CONFIG_UCLAMP_TASK=y + PROVE_LOCKING, CONFIG_UCLAMP_TASK=n, CONFIG_SMP=n, CONFIG_SYSCTL=n, tinyconfig) — 0 errors, 0 warnings.
  • Hardware test row on J616C (with SCHED_IDLE workload, foreground benchmark, and power/throughput check) is queued for our next idle test window.

@RyanTheTide

Copy link
Copy Markdown
Contributor

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

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.

@AxxzyWasTaken

Copy link
Copy Markdown
Contributor Author

Rebased onto current integration/aurora (cacf3554) as f5cb258deb01, plus minor cleanup (made the two sysctl vars static, dropped the dead late_initcall). checkpatch.pl --strict is 0 errors / 0 warnings and kernel/sched/core.o compiles clean with W=1.

Assisted-by: LLM (Google:Gemini 4 Neon)

@AxxzyWasTaken
AxxzyWasTaken force-pushed the sched-uclamp-background branch from 7076a34 to f5cb258 Compare November 21, 2026 21:28
@RyanTheTide

Copy link
Copy Markdown
Contributor

Blockers: 2. The code does what it says. These points are about the interface.

  1. The feature only works if someone sets it, and the value it needs is machine data. With the default of 1024 nothing happens. A distro or user has to write kernel.sched_util_clamp_background, and the right value (410 on the J616C) is the capacity of that Mac's smallest CPU class. That differs between SoCs and is already known to the scheduler. So every distro would ship a per-model sysctl.d table, or one value that is wrong on most Macs. Make the cap automatic instead: take the smallest CPU capacity from arch_scale_cpu_capacity() (rebuilt with the sched domains), apply it only when sched_asym_cpucapacity is set, so symmetric systems are untouched, and keep the sysctl only as an opt-out (0/1), not as a number to tune. Background work on the efficiency cores is also what macOS does with background QoS, so a default-on version has a parity case. It then needs the rows in point 2.

  2. kernel.sched_util_clamp_background_nice (default 15) is a second tunable, and its default is chosen to fit how one compatibility layer uses nice 10. Nice is a weight, not a QoS class, so any threshold here is a guess about userspace. SCHED_IDLE is the unambiguous background signal. Cap SCHED_IDLE by default, and leave nice-based selection to userspace, which can set per-task uclamp.max (sched_setattr) or put the work in a cgroup with cpu.uclamp.max. A daemon such as a background-slice policy can do that today with no kernel change. If you keep a nice path, drop the sysctl and justify the fixed threshold in the commit message.

Code, checked at f5cb258: uclamp_eff_get() still applies the system default first (uc_req = uc_max instead of returning early), and the cap only lowers values, so min <= max holds. rt_or_dl_task() keeps RT/DL out. sched_uclamp_enable() on a write below 1024 matches the existing handler. CONFIG_UCLAMP_TASK=y is in our fleet config, so the code is live. One behaviour to document: a CPU-bound task that never sleeps keeps its old clamp after a sysctl write until its next enqueue. set_user_nice() re-enqueues, so nice changes are fine. The commit has a human Signed-off-by and no agent trailers.

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), dnf/PackageKit update wall time (the user-visible throughput cost), and 0 new kernel warnings.

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]>
@AxxzyWasTaken
AxxzyWasTaken force-pushed the sched-uclamp-background branch from f5cb258 to 7bd6b5a Compare November 21, 2026 23:47
@AxxzyWasTaken AxxzyWasTaken changed the title RFC: sched/uclamp: optionally cap background tasks at the E cores' capacity sched/uclamp: cap SCHED_IDLE tasks at smallest CPU capacity on asymmetric systems Nov 21, 2026
@AxxzyWasTaken

Copy link
Copy Markdown
Contributor Author

Pushed 7bd6b5ad9548 addressing both review blockers:

  1. Replaced the manual capacity sysctl with automatic detection of the smallest active asymmetric-domain arch_scale_cpu_capacity() on sched-domain build/rebuild, with kernel.sched_util_clamp_background now a default-on 0/1 opt-out toggle.
  2. Dropped kernel.sched_util_clamp_background_nice and restricted capping strictly to SCHED_IDLE (!rt_or_dl_task(p)), documenting the next-enqueue toggle semantics in kernel.rst and the commit message.

Compile-verified (LLVM=1 W=1) across UCLAMP_TASK=y/n, SMP=n, SYSCTL=n, and tinyconfig with checkpatch --strict 0/0/0. Hardware SCHED_IDLE row on J616C is queued for our next idle test boot.

@RyanTheTide

RyanTheTide commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Thanks, both points from the last review are addressed at 7bd6b5a:

  • The cap is now automatic: sched_uclamp_background_update() (kernel/sched/topology.c:3282) takes the smallest arch_scale_cpu_capacity() among active CPUs in an asymmetric domain on every domain build/rebuild, and kernel.sched_util_clamp_background is only a 0/1 opt-out, default on. Symmetric systems keep cap 1024 and never enable the key.
  • Selection keys only on SCHED_IDLE (core.c:1760); the nice sysctl is gone, and the next-enqueue behaviour is documented.

One thing to consider, not a blocker: on an asymmetric system the cap is always below 1024, so uclamp_update_background_cap() (core.c:2065) turns on sched_uclamp_used at boot even when no task is SCHED_IDLE, and every enqueue/dequeue then pays the uclamp bucket accounting. Enabling the key when a task first enters SCHED_IDLE in __sched_setscheduler() (as setattr already does with sched_uclamp_enable()), plus on the sysctl 0->1 write, would keep that cost off machines that never use SCHED_IDLE. If you keep it at boot, a hackbench or perf bench sched messaging row with the cap on vs kernel.sched_util_clamp_background=0 would show whether it matters.

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, dnf update wall time, and 0 new kernel warnings. Beside your J616c row, one more asymmetric Mac with a different E-core capacity (an M1 or M2) would show the cap follows the machine.

Assisted-by: LLM (Claude:Opus 5.5)

@AxxzyWasTaken

Copy link
Copy Markdown
Contributor Author

J616C (M4 Max 16c/32g) exact-head boot & SCHED_IDLE uclamp cap verification at 7bd6b5ad9548 (7.3.0-j616c-pr915+, Stage 2 1.0.0b14-g6ac0495f):

  • Defaults & topology:
    • kernel.sched_util_clamp_background = 1 (enabled by default), kernel.sched_energy_aware = 1, schedutil governor.
    • Asymmetric CPU capacities: E-cores cpu1..4 = 383, P-cores cpu0, cpu5..13 = 1024 (policy9 range 1260..4512 MHz).
  • Live SCHED_IDLE frequency cap check (taskset -c 10 chrt -i 0 CPU spinner on P-cluster policy9, 12 × 100 ms samples of scaling_cur_freq):
    • kernel.sched_util_clamp_background = 1: P-cluster held at 1800 MHz (the first OPP above 383/1024 * 4512 MHz ≈ 1688 MHz; brief 4512 MHz excursions only when normal tasks woke on the cluster).
    • kernel.sched_util_clamp_background = 0: P-cluster immediately pinned at 4512 MHz across all 12/12 samples.
  • Health: Clean boot, FAILED_UNITS=0, aurora GPU loaded, wlan0 UP.

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

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

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() in kernel/sched/topology.c automatically derives the cap from min(arch_scale_cpu_capacity(cpu)) across active CPUs in asymmetric scheduling domains on both sched_init_domains() and partition_sched_domains_locked() (matching sched_cache_set() locking), leaving symmetric systems completely untouched (cap = SCHED_CAPACITY_SCALE, sched_uclamp_used never enabled).
  • §2 Production-ready / §3 Safety: Default-on automatic behavior on the default kernel command line with a single CAP_SYS_ADMIN-gated 0/1 opt-out (kernel.sched_util_clamp_background), dropping the old nice threshold and manual capacity sysctls as requested by @RyanTheTide. uclamp_eff_get() applies uclamp_default first, restricts strictly to p->policy == SCHED_IDLE, excludes !rt_or_dl_task(p) (preserving PI-boosted/RT/DL tasks), and caps both uclamp.min and uclamp.max identically so eff_min <= eff_max holds. Next-enqueue toggle semantics are documented in Documentation/admin-guide/sysctl/kernel.rst.
  • §4 Clean-room & attribution / §6 Naming: Single commit 7bd6b5ad9548, human author/committer + human Signed-off-by: only, zero AI trailers; PR body carries Assisted-by:; naming clean.
  • CI: host-tests SUCCESS; MERGEABLE (CLEAN), non-draft.

Technical note on sched_uclamp_used boot-time activation

  • uclamp_update_background_cap() calls sched_uclamp_enable_cpuslocked() at boot on every asymmetric system (since cap < SCHED_CAPACITY_SCALE and default is 1), and toggling kernel.sched_util_clamp_background=0 at runtime does not disable sched_uclamp_used. That means every enqueue/dequeue on every asymmetric Mac pays uclamp bucket accounting even if no SCHED_IDLE task ever runs — and a runtime =1 vs =0 toggle cannot measure that static-key cost. Please either lazy-enable sched_uclamp_used on first SCHED_IDLE entry in __sched_setscheduler() (plus 0->1 sysctl transition), or benchmark hackbench / perf bench sched messaging against the base kernel b8c5bb03 where sched_uclamp_used stays 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:

  1. Unpinned SCHED_IDLE workload A/B (cap on vs off): package power and throughput (confirming EAS E-core placement and real power savings).
  2. Foreground + user-visible background impact: A foreground benchmark while the SCHED_IDLE load runs (no foreground regression) plus user-visible throughput cost (e.g., dnf/PackageKit update wall time), plus the sched_uclamp_used overhead check vs base kernel if boot-time enablement is kept.
  3. Full regression check & second asymmetric Mac: Explicit 0 SELinux denials and 0 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)

@RyanTheTide

Copy link
Copy Markdown
Contributor

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 LOCALVERSION changed. The arms are kernel.sched_util_clamp_background 1 and 0, alternated twice in one boot, and each load is started after the toggle. Production controls come from the same tree without this PR. Default command line, nothing played.

cap on (1) cap off (0) without #915
SCHED_IDLE spinner pinned to cpu7: P-cluster freq, median 1968 MHz (3204 in 12/50 and 14/50 samples, other tasks waking) 3204 MHz, 50/50 3204 MHz, 50/50
SCHED_IDLE task, unpinned, 8 ms busy / 2 ms sleep: samples on an E core 39/40, 39/40 0/40, 0/40 0/40, 0/40
4 such tasks: total system power, median 5.14 W, 5.35 W 12.81 W, 12.86 W 13.69 W, 13.69 W
same: P / E cluster power 0.39 / 1.36 W 6.9-7.0 / 0.01 W 7.5 / 0.01-0.02 W
same: work done in 12 s 188M loops 386-387M 388-389M
perf bench sched messaging -g 20 -l 1000, 3 runs x2 1.877-1.931 s 1.866-1.973 s 1.869-1.940 s
  • With the cap, background work moves to the E cores and gets done slower: about half the throughput at 40% of the system power. That is 14-18% less system energy per unit of background work, and 48% less CPU-cluster energy.
  • perf bench sched messaging shows no cost from the uclamp key being on at boot. The three arms overlap within run-to-run noise, so on this Mac the boot-time enable is fine as it is.
  • A SCHED_IDLE task that never sleeps is not moved to an E core in any arm. It gets no wakeup, so EAS never re-places it, and the cap then only lowers the clock of the cluster it is already on (the pinned row). That is expected; I'm noting it because a pure spinner can look like "placement doesn't work".
  • Health on the test kernel: SELinux Enforcing, 0 failed units, 0 AVCs, 0 kernel errors, 0 oops/WARN, 5 kernel warnings (the same 5 as the production kernel).

Still to run: a dnf update wall-time row and a foreground benchmark that is stable under load. My all-CPU busy-spinner + foreground loop was too noisy to quote, with foreground results ranging 15k-26k loops in every arm, cap on or off.

Method and raw numbers
  • Pinned row: taskset -c 7 chrt -i 0 Python spinner, policy4/scaling_cur_freq 50 x 100 ms, spinner loops per 7 s: cap on 26.3k / 27.0k, cap off 40.2k / 39.9k, without the PR 38.3k.
  • Placement row: chrt -i 0 Python task (8 ms busy / 2 ms sleep), ps -o psr 40 x 100 ms. sched_energy_aware = 1; the energy model has perf domains cpu0-3 and cpu4-7. SCHED_OTHER control: 0/40 on E cores.
  • Power row: 4 such tasks unpinned for 12 s; macsmc_hwmon "Total System Power", "P-cluster", "E-cluster", sampled 40 x 250 ms, medians. On AC.
  • Unpinned never-sleeping spinner: stayed on cpu4-7 in every arm.
  • One-shot boot with an unattended return to the default kernel afterwards.

Assisted-by: LLM (Claude:Opus 5.5)

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

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() in kernel/sched/topology.c automatically derives the cap from min(arch_scale_cpu_capacity(cpu)) across cpu_active_mask CPUs participating in an asymmetric scheduling domain (per_cpu(sd_asym_cpucapacity, cpu) != NULL, naturally skipping isolated CPUs). Symmetric systems keep cap = SCHED_CAPACITY_SCALE and never enable sched_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-gated 0/1 opt-out (kernel.sched_util_clamp_background); next-enqueue toggle semantics are documented in Documentation/admin-guide/sysctl/kernel.rst.
    • Locking: uclamp_update_background_cap() asserts lockdep_assert_held(&sched_domains_mutex) and calls sched_uclamp_enable_cpuslocked(). Call sites in sched_init_domains() (under sched_domains_mutex_lock() in sched_init_smp(), matching adjacent sched_cache_set()) and partition_sched_domains_locked() (under cpus_read_lock() + sched_domains_mutex) match sysctl_sched_uclamp_background_handler() (cpus_read_lock() -> sched_domains_mutex_lock()).
    • Hotplug / cpufreq / cpusets: Recomputed on every domain build/rebuild (arch_topology cpufreq capacity rescan, CPU hotplug, cpuset partitioning); offlining all E-cores clears sched_asym_cpucapacity and resets the cap to SCHED_CAPACITY_SCALE.
    • Scheduler & PI interaction: uclamp_eff_get() applies uclamp_tg_restrict() and uclamp_default[] first, restricts strictly to p->policy == SCHED_IDLE && !rt_or_dl_task(p) (leaving RT/DL and PI-boosted tasks untouched), and caps both UCLAMP_MIN and UCLAMP_MAX identically (eff_min <= eff_max). uclamp_rq_dec_id() uses back-annotated p->uclamp[clamp_id].bucket_id, so concurrent sysctl or topology updates cannot cause bucket refcount mismatches.
  • §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]>) + human Signed-off-by: only, zero AI trailers in commit; PR body carries Assisted-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, and without #915 production control on the same tree) alongside the J616C (M4 Max) exact-head row:
    • Unpinned SCHED_IDLE (8 ms busy / 2 ms sleep): 39/40 samples on E-cores with cap on vs 0/40 off / without #915 (SCHED_OTHER control 0/40).
    • 4 unpinned SCHED_IDLE tasks: median total system power 5.14–5.35 W (P/E 0.39/1.36 W) vs 12.81–12.86 W off and 13.69 W without #915 — 14–18% less total system energy and 48% less CPU-cluster energy per unit of background work (188M vs 386–389M loops in 12 s).
    • Boot-time sched_uclamp_used overhead (perf bench sched messaging -g 20 -l 1000): 1.877–1.931 s (on) vs 1.866–1.973 s (off) vs 1.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, 0 failed units, 0 AVCs, 0 kernel errors, 0 oops/WARN, 0 new kernel warnings (same 5 as production).
  • §6 Naming: Pass.
  • CI & mergeability: host-tests SUCCESS; MERGEABLE (CLEAN) against integration/aurora (236 commits behind base, zero conflicts).

Non-blocking Notes

  • A dnf update 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-enabling sched_uclamp_used on first SCHED_IDLE entry remains an optional future refinement if ever warranted.

Assisted-by: LLM (Gemini 4 Neon)

@RyanTheTide

Copy link
Copy Markdown
Contributor

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 kernel/sched, the sched headers, arm64 topology, arch_topology or cpufreq. The cmdline is the same in both. In the PR boot kernel.sched_util_clamp_background was alternated 1/0/1/0; the base boot ran the same set twice. All work is fixed-size and timed by wall clock (lower is better):

cap on (1) cap off (0) base, no PR
Foreground, quiet perf bench sched messaging -g 20 -l 1000 1.32-1.38 s 1.31-1.39 s 1.32-1.38 s
Foreground under 10 SCHED_IDLE spinners: 1-thread python loop 2.09-2.41 s 2.09-2.20 s 2.07-2.15 s
same: xz -T4 -6, 48 MiB 6.9-7.5 s 6.9-7.4 s 7.1-7.3 s
same: sched messaging 1.33-1.40 s 1.37-1.47 s 1.36-1.47 s
Spinners' throughput / Total System Power 22.1-27.4 k loops/s at 30.7-40.3 W 29.8-29.9 k at 44.5-44.8 W 30.4-30.7 k at 48.7-53.6 W
Background job alone, chrt -i 0 xz -T0 -6 9.3 / 11.1-12.9 s at 6.6-8.2 W 6.7-7.2 s at 10.6-10.9 W 7.1-7.2 s
same: chrt -i 0 rpm -V of 600 packages (warm cache) 18.9-20.4 s 9.6-10.4 s 13.9 s (no warm-up pass in that boot, not comparable)

Results:

  • No foreground regression. Foreground timings with the SCHED_IDLE load running are the same with the cap on, off, and on the base kernel, within run-to-run noise.
  • No measurable cost from enabling the static key at boot. sched messaging on the PR kernel with the cap off matches the base kernel, which never enables uclamp.
  • User-visible cost: SCHED_IDLE jobs get slower. A SCHED_IDLE job on an otherwise idle system now takes longer: xz -T0 is 30-80 % slower and rpm -V about 2x. Power drops, but on this Mac xz uses about the same energy either way (77-79 J vs 75-76 J), so the M1 Pro gains no energy here. With only two E-cores, the background job mostly runs on capped P-cores. The spinner load gains 2-8 % in loops per watt. On the M2, the same kind of load used 14-18 % less system energy per unit of work. So the gain depends on how many E-cores the machine has, and it costs background latency. That trade-off is what the opt-out sysctl is for, and it belongs in the commit message.

Health in the PR boot: Enforcing, 0 failed units, 0 AVC, 0 kernel errors, 0 oops.

Method

fg915.sh per arm: Q = quiet foreground set (python 1e8-iteration loop x3, xz -T4 -6 -c of a fixed 48 MiB input x2, perf bench sched messaging -g 20 -l 1000 x3). L = the same set while nproc unpinned chrt -i 0 python spinners run, with macsmc_hwmon Total System Power sampled every 250 ms and the spinners' loops/s. B = background jobs under chrt -i 0 on a quiet system: xz -T0 -6 x2 with power, then rpm -V of the first 600 installed package names after one page-cache warm-up pass. The sysctl is written before each arm's work starts, since the cap applies at enqueue. Each boot is a one-shot boot with the fleet cmdline unchanged.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

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.

cap on (1) cap off (0) base, no PR
Foreground, quiet sched messaging 1.89-1.98 s 1.90-1.94 s 1.92-1.98 s
Foreground under 8 SCHED_IDLE spinners: 1-thread python loop 2.15-2.33 s 2.26-2.44 s 2.25-2.36 s
same: xz -T4 -6, 48 MiB 7.8-8.6 s 8.1-8.2 s 8.0-8.2 s
same: sched messaging 1.97-2.12 s 2.10-2.33 s 2.07-2.27 s
Total System Power during that load 15.7-15.9 W 15.6 W 15.5 W
Background job alone, chrt -i 0 xz -T0 -6 7.6-10.3 s at 5.5-5.7 W (50-52 J) 6.4 s at 9.1-9.2 W (58-59 J) 6.4-6.5 s at 8.9-9.1 W
same: chrt -i 0 rpm -V of 600 packages 12.1-12.4 s 7.7-8.2 s 8.1-9.7 s

Results:

  • Foreground: no regression. The cap does not slow the foreground. If anything it is slightly faster with the cap on.
  • No measurable cost from enabling the static key at boot. Quiet sched messaging matches the base kernel.
  • With a foreground task running, power is unchanged. On this Mac (one P cluster), the foreground task holds the cluster's frequency up, so the background cap saves nothing then.
  • Background job alone on this Mac: about 14 % less energy for the same job. The trade is wall time: xz takes 20-60 % longer and rpm -V about 50 % longer.

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)

@RyanTheTide

Copy link
Copy Markdown
Contributor

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: localsearch-3 (the GNOME file indexer, all of its threads) and alsactl rdaemon. The usual background services (dnf-makecache, logrotate, man-db-cache-update, plocate-updatedb) are Nice=19 SCHED_OTHER, so this patch does not touch them. The xz/rpm -V numbers in my earlier two rows came from jobs I started with chrt -i 0. They stand in for SCHED_IDLE work in general; they do not describe what a default install runs.

Indexer row. I copied 20,000 small text files (fixed seed, about 79 MB) into a new folder under $HOME and timed how long it took until all of them appeared in the LocalSearch index (crawl plus insert, polled over SPARQL). Cap on and cap off ran in the same boot of fleet80c + this PR, with the sysctl toggled; production fleet81 (without the PR) ran on the same corpus.

arm crawl + insert (s) where the indexer threads ran text extraction
cap on (sysctl 1) 43.65, 16.38 cpu0/1 (E) in 71/77 and 38/41 samples all 20,000 by 44.5 s; in the second arm only 5,673 / 20,000 after 91 s
cap off (sysctl 0) 8.35, 7.07 spread over 6-9 CPUs all 20,000 within ~7 s after the crawl
production, no PR 15.33 (first run after boot), 8.63 spread over all 10 CPUs all 20,000 within ~1-8 s after the crawl

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
  • Kernels: production 7.3.0-aurora-fleet81; test 7.3.0-aurora-fleet80c915+ = fleet80c + this PR (7bd6b5a). Between fleet80c and fleet81 nothing changed under kernel/sched, include/linux/sched*, arm64 topology, arch_topology or cpufreq.
  • Per arm: fixed-seed corpus (20,000 files, 5-15 lines each) copied from a hidden directory that is not indexed into $HOME/<new dir>. Every ~0.3 s I count nfo:FileDataObject rows under that URL prefix ending in .txt, plus rows that have tracker:extractorHash. I sample SMC Total System Power at 4 Hz until the crawl finishes, and log the CPU of each indexer thread in R state.
  • One cap-on arm and one cap-off arm did not finish within 90 s. In both, the previous arm's index deletions had stalled; LocalSearch leaves thousands of deleted entries in place until localsearch-3 restarts, with or without the cap. I left those two arms out of the table. Removal time is not used as a metric.
  • With 3,000 larger files (~28 KB each), extraction stopped at exactly 200 files on production too. That is LocalSearch behaviour and has nothing to do with this PR.
  • Health on both kernels: 0 failed units, 0 AVC denials, 0 kernel errors, 0 oops.

@RyanTheTide

Copy link
Copy Markdown
Contributor

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 $HOME, then we time how long localsearch-3 (all threads SCHED_IDLE) takes to get every file into its index. The PR kernel is 7bd6b5a merged onto our fleet tree, with kernel.sched_util_clamp_background set to 1/0/1/0 in one boot. Production is the current fleet default without the PR. One fix from last time: the indexer's own deletes stall after each arm whatever the cap setting, so each arm now restarts localsearch-3 until the leftovers are gone, and every arm here starts from a clean index.

arm all 20,000 in index system power during crawl system energy (W x s) CPU clusters P+E text extracted
production #1 4.10 s 6.47 W 26.5 J all by 10.5 s
production #2 4.46 s 7.00 W 31.2 J all by 10.7 s
cap on #1 9.43 s 4.95 W 46.7 J 1.35 W, 12.7 J 6,161 after 90 s
cap off #2 4.89 s 6.89 W 33.7 J 3.58 W, 17.5 J all by 11.2 s
cap on #3 10.10 s 4.99 W 50.4 J 1.34 W, 13.6 J all by 23.9 s
cap off #4 5.73 s 6.84 W 39.2 J 3.73 W, 21.4 J all by 12.0 s

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 uclamp.max, or skipping the cap when the smallest cluster is small, still holds. The M1 Pro (2 E-cores) is where it hurts most.

@AxxzyWasTaken

Copy link
Copy Markdown
Contributor Author

Thanks for running the real-world localsearch-3 rows on both M1 Pro (2E) and M2 Air (4E) — that data makes the exact tradeoff crystal clear.

After walking through kernel/sched/fair.c against those numbers, keeping 7bd6b5ad as-is (for MERGETRAIN-LINUX4) is the cleanest engineering call:

  1. Why uclamp.max-only wouldn't change placement: Normal SCHED_IDLE tasks already have uclamp.min == 0, so dropping the UCLAMP_MIN cap is a no-op on localsearch-3 (and would break eff_min <= eff_max if a SCHED_IDLE task ever sets uclamp.min > E_cap). What keeps waking localsearch-3 threads on E-cores is uclamp_max <= capacity_orig in util_fits_cpu() (fair.c:6286), which overrides fits_capacity(), keeps cpu_overutilized() false, and makes compute_energy() see cur_delta == 0 on an already-saturated E-cluster vs cur_delta > 0 on an idle P-cluster.
  2. Why E_cap + 1 or a custom fair.c spillover is worse: Raising the cap above E_cap causes any single CPU-bound SCHED_IDLE task (util >= 80%) to become misfit and spill onto P-cores (~2.5× CPU energy plus P-cluster wakeup). Conversely, patching cpu_overutilized() / find_energy_efficient_cpu() with Aurora-only SCHED_IDLE spillover rules diverges from upstream EAS/uclamp semantics and risks cross-cluster ping-pong on wakeups.
  3. Why skipping 2E clusters is the wrong abstraction: Only M1 Pro/Max (t6000/t6001) have 2E (4E/6E covers the rest of the lineup), and skipping 2E throws away the ~12× core power saving on 1–2 background tasks while adding a non-upstreamable nr_small threshold to kernel/sched/topology.c. Users on 2E Macs who prefer faster bulk SCHED_IDLE indexing over E-core confinement already have the clean kernel.sched_util_clamp_background=0 opt-out.
  4. Awake-laptop energy on 4E (M2 Air): On M2 Air's localsearch-3 row, CPU energy drops 25–35% (12.7–13.5 J vs 17.5–21.4 J), peak power drops 28% (4.97 W vs 6.86 W), and incremental energy above the ~3.1 W screen-on idle floor is lower (17.4–19.1 J vs 18.5–21.4 J). Charging P_idle × T_crawl only penalizes battery if the laptop immediately enters deep sleep the instant indexing finishes; on an awake desktop the idle floor is sunk cost.

So let's keep 7bd6b5ad as-is with the existing approvals and keep lazy sched_uclamp_used as a separate follow-up if ever needed.

Assisted-by: LLM (Google:Gemini 4 Neon)

@github-actions github-actions Bot added needs-template PR body lacks Tested or Risk (bot) ready-to-merge Meets the merge policy: merge it (bot) blast:m1 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) and removed needs-template PR body lacks Tested or Risk (bot) labels Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Merge readiness at 7bd6b5ad: ready to merge

Check Detail
CI at head ok 2 checks passed
Review ok approved by DjDeveloperr, RyanTheTide
Requested changes ok none
Hardware row at head ok comment at 7bd6b5ad
Conflicts ok none
PR text ok Risk: two-way · asymmetric ARM64 Macs (M1-M5); plain revert restores prior scheduler behavior.

Areas: none matched in CODEOWNERS
Merge: gh pr merge 915 --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.

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed ready-to-merge Meets the merge policy: merge it (bot) labels Nov 24, 2026
@DjDeveloperr
DjDeveloperr merged commit 8950cce into aurora-silicon:main Nov 24, 2026
3 checks passed
@DjDeveloperr

Copy link
Copy Markdown
Contributor

Thank you for the contribution, @AxxzyWasTaken!

satchlj pushed a commit to satchlj/linux that referenced this pull request Dec 1, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blast:m1 Macs affected, from Merge risk (bot) blast:m5 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.

3 participants