Repository navigation
sched/fair: Treat a task that runs without sleeping on a smaller CPU as misfit - #2020
IronsideXXVI wants to merge 2 commits into
Conversation
DjDeveloperr
left a comment
There was a problem hiding this comment.
Thanks for the measurements. 89 % of the 10-thread copy work landing on P-cores instead of 40 %, and bandwidth matching macOS with no placement hint, is a real result. Because this changes CFS on every asymmetric-capacity system, I've held it to a higher bar, and it isn't ready to merge yet.
-
Off by default is an A/B switch. As posted, merged code would carry
MISFIT_RUNTIME= false plus a debugfs tunable: a knob choosing between old and new behaviour, which we don't merge any more. It has to be on by default, and justified as the default for asym-cpucap systems, or stay out of the tree. -
The evidence has to cover that default. So far it's a memory-bandwidth microbenchmark plus one CPU benchmark run with the P cluster capped. Before this is the default on a laptop, we'd need:
- battery or package power under bursty everyday loads: video playback, a browser workload with JS bursts longer than 8 ms, an idle desktop with periodic work;
- latency-sensitive loads, such as audio at small buffer sizes;
- a check for ping-pong, where wakeup placement keeps putting a task back on an E-core that it then leaves again 8 ms later.
-
The 8 ms default has no stated source. Where does it come from: the PELT ramp on these cores, a macOS observation, a sweep? A value that steers placement on every asymmetric system needs one.
-
The tick push skips the rotation path's serialisation. e0bb4f5 added
misfit_rotate_mutexandmisfit_rotate_last_cputo serialise destination choice.misfit_push_idle()instead always picks the first idle CPU of the highest capacity. Several E-cores ticking close together will therefore aim at the same idle P-core until one move lands.__active_load_balance_cpu_stop()only checks that the target is active, not that it is still idle.To your question: yes, I'd rather the push go through the rotation work. It already finds an idle bigger CPU (that's the
idle = truecase, which returns -EAGAIN today). Moving the task there, under the same mutex and the same wrap start, keeps one destination policy. -
This belongs upstream. It's generic fair-class policy, not Apple hardware, and upstream has been working on the same problem (a push mechanism for misfit tasks under EAS). A version that's on by default should go to LKML and the sched maintainers rather than be carried here, where every rebase onto a new kernel has to bring it along.
The rest looked right to me:
- the push runs from
sched_balance_trigger()outside the rq lock; - it follows the active-balance pattern:
active_balanceset under the lock,stop_one_cpu_nowait()with preemption off; - the uclamp_max, SCHED_IDLE and kthread exclusions are sensible;
- with the feature off, the existing paths are unchanged.
|
@DjDeveloperr thanks, that's a fair bar and I agree with point 5: this is generic fair-class policy and it should go to LKML and the sched maintainers, not be carried here. What I'll do:
I'll post the numbers here as they come in. |
|
Pushed b475b38, two commits on top:
checkpatch --strict is clean, and |
b475b38 to
1d0415c
Compare
|
Blockers: 1.
Nit: the idle move now runs only inside What I checked and found sound: the uclamp_max, SCHED_IDLE and kthread exclusions in HW row: this head (after the fix), default command line, on the J604 and on at least one other asymmetric Mac class (M1/M2 4+4, or an M-Pro with 2 or 4 E-cores): the 10-thread and 1-thread bandwidth A/B against the merge base, plus the power, audio and ping-pong rows already requested in this thread; 0 AVC, 0 failed units, no new kernel errors. Assisted-by: LLM (Claude:Opus 5.5) |
…as misfit A task becomes a misfit, and can be pulled up by an idle bigger CPU or rotated by MISFIT_ROTATE, only once task_fits_cpu() fails, i.e. once its PELT utilization exceeds 80 % of the smaller CPU's capacity. From zero utilization, a task that runs without a break on a CPU of capacity c (in 1/1024) at its highest frequency gets there after 32 / c * log2(1 / (1 - 0.8 c)) ms. On the M4 (T8132) the E-cores have c = 754 * 2892 MHz / (1024 * 4464 MHz) = 0.48, so that is about 46 ms at their top frequency, and longer at lower ones. Work that lasts less than that never moves. On the M4 MacBook Pro (4 P-cores, 6 E-cores) a 10-thread memory bandwidth test that splits 1 GiB into equal slices finishes the P-core slices at 11 ms and the E-core slices at 32 ms, with 0-4 migrations: 66-78 GB/s, against 97.2 GB/s for the same source on macOS on the same machine. A work queue over the same arrays reaches 95.8 GB/s, and uclamp_min 1024 on the test's threads 103 GB/s, so the loss is placement, not the memory system. A fair task that has run for MISFIT_SLICES (4) base slices without sleeping or migrating, on a CPU smaller than its maximum allowed capacity, now counts as misfit as well. A task that has used four full EEVDF requests in a row is CPU-bound by the scheduler's own measure. It is the interval misfit rotation already waits before a swap, which now uses the same constant, and it scales with the base slice and the CPU count as the slice does. With 10 CPUs the base slice is 2.8 ms, so the threshold is 11.2 ms. There is no feature bit and no tunable for it. The existing misfit balancing then moves the task to a bigger CPU with spare capacity, and MISFIT_ROTATE shares the bigger CPUs once they are all busy. The checkpoint is reset on fork, wakeup and migration. Kernel threads, SCHED_IDLE tasks and tasks whose uclamp_max is at or below the smaller CPU's capacity are left alone. On a CPU of the task's maximum allowed capacity, as on every CPU of a symmetric system, nothing changes. Signed-off-by: Dylan Ironside <[email protected]>
…tion work When a misfit task finds an idle bigger CPU, misfit rotation returns -EAGAIN and leaves the move to that CPU's next newly-idle or nohz idle balance, which is skipped by chance (NI_RANDOM) or waits for the domain's balance interval. A runtime misfit can sit on its small CPU for that long while the bigger CPU idles. Let the rotation work make the move: - the tick queues the work at once when a bigger CPU that the task may use looks idle, and otherwise after MISFIT_SLICES of misfit execution as before; - the work picks the destination under misfit_rotate_mutex from misfit_rotate_last_cpu, the same round-robin start as a swap, so smaller CPUs that tick close together never aim at the same idle CPU; - it moves the task with a synchronous stop_one_cpu(), so the move completes before the next destination is chosen; - the stopper is given the task and moves that task only, through can_migrate_task() and detach_task(), as migrate_swap() names its tasks. It moves nothing when the task has slept, moved or left the fair class since the work looked, or when the target is no longer idle. A task that woke on the smaller CPU in the meantime is never moved in its place; - rq->active_balance is held over the move, so load balancing does not queue its own stopper on that CPU meanwhile. The move does not depend on MISFIT_ROTATE: a task that task_is_misfit() marks gets it whether the feature is set or not. Clearing MISFIT_ROTATE turns off the swap only, and the work then reports -ECANCELED instead of swapping. There is one destination policy for both cases now. Signed-off-by: Dylan Ironside <[email protected]>
1d0415c to
bdc8ff7
Compare
|
@RyanTheTide thanks. Pushed bdc8ff7, which replaces the four commits with two.
Nit: I kept the idle move outside the What I ran: What I have not run: nothing is measured on this head yet. The J604 run is set up: this head against the merge base, default command line, with the bandwidth, power, audio and ping-pong rows from this thread. I've also asked for the same rows on an M1/M2 or an M-Pro. I'll post the numbers here. |
|
This still applies cleanly to the current integration/aurora tip 110861f. The tip has the misfit rotation (MISFIT_ROTATE) but no runtime-based misfit. The 11-21 head bdc8ff7 moves p by name in its own stopper and squashes the series to two commits, which covers both points from the last review; it hasn't been re-reviewed yet. No measurements have been posted for this head. The power, audio-latency and ping-pong rows and the slice sweep are what's left before it can be judged, here or on the list. Build check of 110861f plus this change (arm64, LLVM=1, Image, dtbs and every directory it touches, Fedora config plus asahi.config): builds, no warnings in the files it touches. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict: FINISH before any merge here. It's a draft for LKML, which is the right home for a fair-class policy change.
Blockers: none in the code. The points from my last review are fixed. Runtime misfit is on by default with no switch. MISFIT_SLICES names the 4 base slices the rotation code already used. The idle move now goes through the rotation work under misfit_rotate_mutex, and it moves p by name only while the target is still idle.
Rows before merging here: this changes CFS on every Mac with mixed cores, so it would need your "Not yet" items: audio wake-to-run latency, more power windows per row, and the same rows on a second asymmetric Mac from another generation.
Checked: thank you for re-measuring on the current base and saying plainly that it no longer shows a gain there. Ping-pong went down, to at most 1.88 per second against the base's 5.00.
Superseded by the review at bdc8ff7
|
@IronsideXXVI checking open drafts today. To come out of draft, this still needs:
If it's no longer needed, say so here and we'll close it. Otherwise it stays open as a draft until these are done. |
What: A fair task that runs for
MISFIT_SLICES(4) base slices without sleeping or migrating now counts as misfit on a CPU that has a bigger CPU in its affinity. The misfit rotation work then moves it to an idle bigger CPU, at once when one looks idle. There is no switch for this: the idle move works whetherMISFIT_ROTATEis set or not, and clearingMISFIT_ROTATEturns off only the swap. Draft: per the review, this belongs on LKML with the sched maintainers, and this PR will be closed with a link once it is posted there.Tested: On the J604 (M4, 4 performance + 6 efficiency cores), this head's two commits (bdc8ff7, same patch-id) on our kernel against the same kernel with
kernel/schedat the merge base, one boot each: no gain to show and no clear loss. 10-thread copy 102.4-103.3 against 102.1-103.2 GB/s (the base is already above macOS's 97.2), 0 xruns on both, package power 0.92-0.99 of the base except video at 1.06, where the base's own two windows differ by 17 %. One guard benchmark was 0.9 % below the base. checkpatch --strict is clean on both commits, andkernel/sched/builds with W=1 and no warnings with clang and gcc at both commits and on the base.Risk: two-way · every Mac with mixed core sizes (all Apple Silicon). It is on for any fair task whose affinity includes a bigger CPU.
Not yet: Audio wake-to-run latency (not captured in this run), more power windows than 2 per row, and the same rows on at least one other asymmetric Mac. Then the LKML posting.
Full description
Draft. Two commits on top of this tree's misfit handling (
MISFIT_ROTATE, 2d24fbc and e0bb4f5). Per the review, a version of this that is on by default belongs on LKML with the sched maintainers. This draft stays here until it is posted there, and I will close it with a link then.What it does.
MISFIT_SLICES(4) base slices without sleeping or migrating counts as misfit on a CPU that has a bigger CPU in its affinity. Today a task counts as misfit only once its PELT utilization no longer fits the CPU, which for a CPU-bound thread on an M4 E-core takes about 46 ms at the top frequency. It is on by default on asymmetric-capacity systems, with no feature bit and no debugfs word. The uclamp_max, SCHED_IDLE and kthread exclusions stay.MISFIT_SLICESas before. The work picks the destination undermisfit_rotate_mutexfrommisfit_rotate_last_cpu, the same start as a swap. A synchronous stopper moves that task by name, throughcan_migrate_task()anddetach_task(), the waymigrate_swap()names its tasks. It moves nothing when the task has slept, moved or left the fair class since the work looked, or when the target is no longer idle.MISFIT_ROTATE. ClearingMISFIT_ROTATEturns off the swap only.Measured on this head (J604, 2026-11-24). Side A: our kernel with
kernel/schedandinclude/linux/sched.hat this PR's merge base. Side B: A plus this PR's two commits (same patch-id as bdc8ff7), built with one test-only knob that readsMISFIT_SLICESfrom a sysctl; it stayed at 4, which is this head's policy. Same config and command line, one boot per side, 2 windows per row.checkpatch --strictis clean on both commits, andkernel/sched/builds with W=1 and no warnings with clang and gcc at both commits and on the base.Older numbers, not for this head. The first version of this PR (an off-by-default
MISFIT_RUNTIMEswitch and a stopper push from the tick, both now removed) was measured on the J604 on an older base. With no placement hint, 10-thread copy went from 68.2-70.5 to 97.4-97.6 GB/s (macOS on the same machine: 97.2), and the share of that work done on performance cores from 40 % to 89 %. Those runs measured that design on that base, not this one.Still to measure on this head, against the merge base, same kernel config and default command line: audio wake-to-run latency at small buffer sizes; more power windows per row (video, browser, idle desktop); 1-thread and 10-thread bandwidth again on a second boot per side; and no new kernel errors. On the J604 and on at least one other asymmetric Mac (M1/M2 4+4, or an M-Pro). I will post the numbers here as they come in.