- Big-Little Scheduling 01: How the Kernel Knows Which Core Is Big
- Big-Little Scheduling 02: How the Scheduler Groups CPUs
- Big-Little Scheduling 03: How Heavy Is a Task, and Does It Fit
Still the fictional example chip from 01 and 02: big core capacity 1024 (up to 3.0 GHz), little core ≈ 341 (up to 2.0 GHz), and mid cores ≈ 683 on another die. Code references are against the Linux 6.18 source. The “Code references” at the end of each section are collapsed and can be skipped on a first read.
Part 01 covered how strong a core is (capacity). This post covers the other half: how heavy a task is (util), and how the two are compared to decide “does this task fit on this core”. Wake-up core selection, misfit migration and frequency selection later on all use these numbers.
0. The whole picture
① is in sections 2 and 3, ② in section 4, ④ in section 5, ⑤ in section 6, ③ in section 7. The three arrows at the bottom right are what the next three posts use them for.
1. Why a dedicated number
The scheduler keeps asking: “if I put this task on that core, will it fit?” To answer, it needs two comparable numbers: how strong the core is (capacity, covered in 01) and how heavy the task is.
The most intuitive measure of “how heavy” is CPU utilization, the percentage you see in top. It is measured with a stopwatch:
utilization = time the task was running in a window ÷ length of the window
The kernel records a timestamp every time a task gets on and off a CPU, so “how many ms it ran” is measured directly. For example, if in a 16 ms window a task ran 12 ms and slept 4 ms, its utilization is 12 ÷ 16 = 75%.
The problem: a stopwatch only measures “how long it ran”, not “how fast”. What really makes a task heavy is how much work it has to do (say, finish one frame every 16 ms), and
work done = running time × core speed
So utilization is determined by “the task + the core it is currently on”, not by the task alone. Look at two tasks that are both at 75%:
A little core at 1.0 GHz runs at only 1/6 the speed of a big core at 3.0 GHz (a little core at full speed is already only 1/3 of a big core, and now it runs at half of its own 2.0 GHz maximum), so work that task Y could finish in 2 ms on a big core takes 12 ms here.
| Task | Runs on | Ran in 16 ms | Utilization | Work in big-core-full-speed ms |
|---|---|---|---|---|
| X | Big core 3.0 GHz (full speed) | 12 ms | 75% | 12 ms |
| Y | Little core 1.0 GHz | 12 ms | 75% | 12 ÷ 6 = 2 ms |
| Y moved to a big core | Big core 3.0 GHz (full speed) | 2 ms | 12.5% | 2 ms |
- Task X is at 75% on a big core at full speed: it really is heavy, wherever it goes.
- Task Y is at 75% on a slow little core: it is actually light, the core is just slow; on a big core it would only be at 12.5%. The task didn’t change; moving it changed its utilization.
Looking only at “75%”, the scheduler cannot tell these two tasks apart. Worse, utilization changes as soon as a task moves, so it cannot be used to predict “will it fit over there” before moving.
So the kernel computes a separate number, util: the task’s work converted to “how long it would run on the strongest core at its highest frequency”, expressed as 0–1024. Whatever core the task is on, the same task has the same util (X is 768, Y is 128), and it can be compared directly with any core’s capacity.
util is computed in two steps: the bucket in section 2 tracks “how much it ran recently”, which on its own is just “utilization × 1024”; section 3 then converts running time into “big-core-full-speed time”. Only the two together give util.
2. PELT: how util_avg is computed
util_avg answers: “how busy has this task been recently?” on a 0–1024 scale: 1024 = always running, 0 = always sleeping.
The kernel’s method is called PELT (Per-Entity Load Tracking). Without formulas, think of it as a bucket with a hole in the bottom, where the water level is util_avg:
Every 1 ms, it leaks first and then pours. Two rules:
- Leak: 2.1% of the water currently in the bucket leaks out. Leaking is “forgetting the past”: all the water in the bucket was poured in earlier, so how much leaks depends on how much is there. More water leaks more: at level 1000 this 1 ms leaks 21, at 500 it leaks 10.5, at 100 it leaks 2.1.
- Pour: if the task ran in this 1 ms, pour a fixed 22; if it slept, pour nothing. Pouring is “recording what happened in this 1 ms”. Whether it ran in this 1 ms has nothing to do with how much it ran before, so the amount is always 22 regardless of the level. If the pour also depended on the level, an empty bucket would never get any water.
Where 22 comes from: it is derived backwards from a goal. The goal is “a task that runs all the time ends up at 1024”. The level stops moving when what leaks each 1 ms equals what is poured in; stopping at 1024 means the leak is 2.1% of 1024 ≈ 22, so each pour is 22.
Leak first or pour first: leak first, then pour. The 22 just poured in doesn’t leak during this 1 ms; it starts leaking in the next 1 ms, so the most recent 1 ms is always counted in full. The kernel code does it in this order too (see “Code references” at the end of this section). If it were reversed (pour, then leak), a task that runs all the time would only reach about 1002, never 1024.
Example 1: always running. Suppose task A was just created and its bucket is empty (level 0); from now on it runs all the time and never sleeps.
| ms | ① Leaked (2.1% of current water) | ② Poured | Level (util_avg) |
|---|---|---|---|
| 1 | 0 (empty bucket, nothing to leak) | 22 | 22 |
| 2 | 0.5 | 22 | 43 |
| 3 | 0.9 | 22 | 64 |
| 10 | 3.9 | 22 | ≈ 200 |
| 32 | 10.7 | 22 | 512 |
| 74 | 17.4 | 22 | ≈ 819 |
| Then sleeps for 32 ms | Leaks every ms | 0 | ≈ 410 (halved) |
The “poured” column is always 22; the “leaked” column grows with the level, so the level rises more and more slowly. Once the leak also reaches 22 (level 1024), it stops rising.
Three properties of util_avg follow directly from the bucket:
- It tracks “recent” activity: water poured long ago has mostly leaked out, so only the last hundred-odd milliseconds carry weight, and the more recent, the more weight.
- It takes time to rise and fall: a task that suddenly starts running all the time needs about 74 ms to reach 819; after it stops, it only halves every 32 ms.
- It is roughly “fraction of time running recently × 1024”: a task that steadily runs half of the time hovers around 512 (why, see below).
Example 1 plotted: running for 120 ms, then sleeping.
This “slowness” is deliberate: a task that is briefly busy is not immediately treated as heavy. The price is that when a task suddenly gets heavier, the scheduler needs tens of milliseconds to notice. The misfit lag in 05 and the frequency lag in 06 both stem from this.
Why the level ≈ fraction of time running × 1024
Example 2: running half of the time. Suppose task B was also just created with an empty bucket; it runs 1 ms, sleeps 1 ms, runs 1 ms, sleeps 1 ms, and so on: 50% utilization.
| ms | What B does | ① Leaked (2.1% of current water) | ② Poured | Level |
|---|---|---|---|---|
| 1 | Runs | 0 | 22 | 22 |
| 2 | Sleeps | 0.5 | 0 | 21.5 |
| 3 | Runs | 0.5 | 22 | 43 |
| 4 | Sleeps | 0.9 | 0 | 42 |
| 5 | Runs | 0.9 | 22 | 63 |
| 6 | Sleeps | 1.3 | 0 | 62 |
| 10 | Sleeps | 2.2 | 0 | 99 |
| 50 | Sleeps | 7.3 | 0 | 335 |
| 100 | Sleeps | 9.8 | 0 | 448 |
| 200 | Sleeps | 10.9 | 0 | 500 |
| 299 | Runs | 10.8 | 22 | 517 |
| 300 | Sleeps | 11.1 | 0 | 506 |
B pours 22 only once every 2 ms, but leaks in both of those ms. While the level is low, the two leaks together are far below 22 and the level rises; the higher the level, the more it leaks and the slower it rises; once each leak is about 11, so the two add up to 22, it stops. Each leak is 2.1% of the level, and a leak of 11 means a level of about 512.
When the level is high it leaks more and falls; when it is low it leaks less and rises. Wherever it starts, it ends up at the height where “leaked = poured”.
Other utilizations work the same way: always running pours an average of 22 per ms and settles at 1024; running half the time pours an average of 11 per ms and settles at 512; running a quarter of the time pours an average of 5.5 per ms and settles at 256. That is where “util ≈ fraction of time running × 1024” comes from.
It is “around” rather than “exactly” because the pouring isn’t uniform: in the 1 ms it runs, 22 is poured and the level goes up; in the 1 ms it sleeps, it only leaks and the level goes down. So B ends up swinging between 506 and 517. The longer each run and each sleep, the bigger the swing (section 4 has a figure like that).
Why exactly 2.1%
2.1% is not arbitrary; it is derived from one design decision. The kernel developers first decided: water poured in 32 ms ago should be down to half (a “half-life of 32 ms”). Then: how much must leak per ms so that exactly half is left after 32 ms?
| Time since some water was poured | Leaking 2.1% per ms: left | Leaking 10% per ms: left |
|---|---|---|
| 8 ms | 84% | 43% |
| 16 ms | 71% | 19% |
| 32 ms | 50% | 3% |
| 64 ms | 25% | ≈ 0 |
Leaking 2.1% per ms leaves exactly half after 32 ms, so that is the choice. Leaking 10% would be far too aggressive: anything from 32 ms ago would be almost entirely forgotten. The 22 follows from the 2.1% (as above, it is 2.1% of 1024).
So the only real design decision is why the half-life is 32 ms. It is a trade-off:
- Too short (say 4 ms): a task’s util drains after sleeping a few milliseconds, it is treated as light the next time it wakes up, and core selection flip-flops;
- Too long (say 256 ms): after a task gets heavier, it takes half a second to notice; it should have been moved to a big core long before.
32 ms is about two frames (one frame at 60 Hz is about 16.7 ms): long enough not to forget how heavy a task is because of one short idle period, short enough to follow changes within tens of milliseconds. In mainline this value is hard-coded and cannot be tuned at runtime.
For those who want the formula
Precisely, the fraction leaked per ms is 1 − y with y = 0.97857…, i.e. about 2.14% (2.1% in the text). This number is chosen because y32 = 1/2: leaking for 32 ms leaves exactly half, so the “half-life” is 32 ms (the constant LOAD_AVG_PERIOD). Each pour of 22 is 1024 × (1 − y) ≈ 21.94. Leaking first and then pouring, a task running all the time settles at 1024; pouring first and then leaking, it would settle at 1024 × y ≈ 1002. What the kernel actually stores is a sum decayed and accumulated the same way (util_sum), divided by its maximum possible value to get util_avg; the result is the same as the bucket model. A time slot is 1024 µs long, not exactly 1 ms.
Two more buckets: runnable_avg and load_avg
PELT actually keeps three buckets per task at the same time. The rule is the same for all (“each slot, leak 2.1% first, then pour”); the only difference is when water is poured:
| Bucket | When it pours | Question it answers | Where this post uses it |
|---|---|---|---|
util_avg | While running | How heavy is it | Everywhere |
runnable_avg | While running or waiting in the queue to run | Is it waiting in a queue | Section 4 (a queued sample doesn’t update the record), section 5 (how crowded a core is) |
load_avg | Like runnable_avg, but each pour is scaled by the weight (nice value) | Load weighted by priority | Section 2 (a new task’s starting value), section 6 (load balancing) |
Example: two tasks P and Q on a big core both want to run all the time. They can only take turns, each running half of the time.
- util_avg: about 512 each; only the half where they actually run pours water;
- runnable_avg: about 1024 each; the half where they wait their turn is spent in the queue, which also pours;
- The two buckets differ by 2×, which shows they spend half their time waiting. For a task that never waits, the two buckets are about the same.
Cores have these three buckets too. A core’s runnable bucket pours one portion per task queued on it in each slot, so with P and Q crowded together it is about 2 × 1024, while the core’s util bucket tops out at 1024 (section 5). To know how many tasks are crowded on a core, look at runnable.
load_avg differs from runnable_avg only by the weight: a nice 0 task has weight 1024, so its load_avg is about the same as its runnable_avg; the lower the nice value (the higher the priority), the larger the weight and the higher the bucket. Big/little decisions (fits, misfit, EAS, frequency selection) only look at util; load_avg is mainly for load balancing.
What a new task starts from
Not 0. For a forked task, the kernel first picks a core for it, then computes its starting value from that core (post_init_entity_util_avg()):
cap = (this core's capacity − this core's util) / 2
estimate = this core's util × new task's weight ÷ this core's load
start = cap if the core's util is 0; otherwise the smaller of estimate and cap
- “This core” is the core the child is placed on, not necessarily the parent’s core.
- “This core’s util” is the whole core’s bucket (section 5): every normal task on the core is in it, including tasks that went to sleep and haven’t drained yet, not just the parent.
- “estimate”: take “how much util one unit of weight corresponds to on this core, on average”, and multiply by the new task’s weight; i.e. guess that it is about as busy as the tasks already there. Nothing is taken away from the parent or anyone else.
Example 1: a big core has only one nice 0 task, util 200 (its load is also about 200). The child is placed on the same big core: cap = (1024 − 200) / 2 = 412; estimate = 200 × 1024 ÷ 201 ≈ 1019; taking the smaller one, the start is 412. When there are few tasks on the core, the estimate tends to be large and the cap is what matters.
Example 2: a big core has only one nice −10 task (weight 9548), util 200, so its load is about 9548 × 200 / 1024 ≈ 1865. A nice 0 child is placed there: estimate = 200 × 1024 ÷ 1866 ≈ 110, which is smaller than the cap 412, so the start is 110. The task already on the core has a high weight but low util, so by that ratio the new task is guessed to be light too.
Two edge cases: if the core is empty (util 0), the start is the cap, 512 on a big core and 341 / 2 ≈ 170 on a little core; if the core is already full (util ≥ capacity), the cap is ≤ 0 and the start is 0.
This way a new task is not treated as zero load from the start: its core’s util immediately includes it, and later core selection for other tasks and frequency selection can see it. It is only a starting point; once the task runs, it rises and falls by the bucket rules, and after a few tens of milliseconds it reflects the task’s real behaviour.
Code references
kernel/sched/pelt.caccumulate_sum(): first decays the old sum by the number of slots that passed (Step 1), then adds this segment (leak first, then pour);___update_load_avg(): divides the sum by its maximum to get avgkernel/sched/sched-pelt.hLOAD_AVG_PERIOD 32,LOAD_AVG_MAX(the upper bound of the summed decay series)kernel/sched/fair.cpost_init_entity_util_avg(): a new task’s starting value;kernel/sched/core.cwake_up_new_task():select_task_rq()picks the core first, then the starting value is computed
3. Invariance: making util comparable with capacity
The bucket in section 2 only looks at “did it run in this slot”, so on its own it gives “utilization × 1024”. Task Y from section 1 runs 12 ms out of every 16 ms on a little core at 1.0 GHz; the bucket would get 12 pours and end up at 768, the same as the really heavy task X. So the kernel also has to account for “which core, at what frequency”.
The pour amount and the leak rate don’t change: every slot is always “leak 2.1% first, then pour 22 if running”. What changes is how fast the slots go by, i.e. the bucket’s clock.
How big is one slot
First, a ruler:
1 slot = the work the strongest core (capacity 1024) does in 1 ms at its highest frequency
This unit is chosen because capacity also uses that core as 1024 (01). With util and capacity on the same ruler, they can be compared directly.
Other cores convert by speed. As 01 said, capacity is “this core’s full-speed speed as a fraction of the strongest core’s full-speed speed”; halving the frequency roughly halves the speed too. So when the kernel advances the bucket’s clock, it shrinks time by this formula (update_rq_clock_pelt()):
slots elapsed = real time (ms) × (this core's capacity / 1024) × (current frequency / this core's max frequency)
Conversions on the example chip:
| Core | capacity | Current / max frequency | Speed relative to strongest core at full speed | ms per slot |
|---|---|---|---|---|
| Big | 1024 | 3.0 / 3.0 | 1 | 1 ms |
| Big, lower frequency | 1024 | 1.5 / 3.0 | 1/2 | 2 ms |
| Mid | 683 | 2.0 / 2.0 | 2/3 | 1.5 ms |
| Little | 341 | 2.0 / 2.0 | 1/3 | 3 ms |
| Little, lower frequency | 341 | 1.0 / 2.0 | 1/3 × 1/2 = 1/6 | 6 ms |
The little core’s 341 is what 01 computed: the DT says 512 for the little core (half the big core’s performance per MHz), times the frequency ratio 2.0 / 3.0, normalized to 341, i.e. 341 / 1024 ≈ 1/3.
Where the two ratios come from:
- Strength ratio: the capacity from 01 (
arch_scale_cpu_capacity()), computed at boot and fixed. - Frequency ratio: updated by cpufreq on every frequency change (
arch_scale_freq_capacity(), which on RISC-V istopology_get_freq_scale(), equal to current / max frequency). Without cpufreq on a core this ratio is always 1. That is one more reason for “every core needs a cpufreq policy” (01, section 5).
There is an approximation here: it assumes “work done is proportional to capacity and frequency”. That is accurate enough for most compute-bound workloads; memory-heavy tasks (mostly waiting on memory) deviate, which is the same thing as 01’s “capacity is only a first-order approximation”.
Catching the clock up when the core goes idle
The clock only runs slow while a task is running. As soon as the core goes idle, the bucket’s clock catches up with real time; the missing slots are filled in all at once, and every filled-in slot counts as “sleeping” (leak only, no pour):
The little core at full speed ran for 6 ms but the bucket only advanced 2 slots (both with a pour); at the moment it goes idle, 4 slots are filled in, then one slot per ms. After 16 ms both sides have 16 slots, 2 of them with a pour.
Step through task Y from section 1. Y is on a little core at 1.0 GHz (6 ms per slot); it runs 12 ms, then sleeps 4 ms:
| Real time | What Y does | Bucket’s clock | What the bucket records in this stretch |
|---|---|---|---|
| 0 ms | Starts running | 0 slots | |
| 6 ms | Running | 1 slot | 1 “running” slot (one pour) |
| 12 ms | Done, goes to sleep, core goes idle | 2 slots | Another “running” slot (another pour) |
| 12 ms, right as the core goes idle | Jumps to 12 slots | The 10 skipped slots all count as “sleeping” | |
| 16 ms | Sleeping | 16 slots | 4 “sleeping” slots (the core is idle, the clock runs at real-time speed) |
After 16 ms the bucket has recorded 16 slots: 2 running, 14 sleeping.
- Why catch up: leaking must follow real time. Whatever core a task is on, something from 32 ms ago should be down to half; if the clock stayed behind, old records on a slow core would leak too slowly and be remembered too long.
- Why the filled-in slots count as “sleeping”: if Y’s 12 ms of work had run on a big core, it would have finished in 2 ms, and the big core would have been idle for the remaining 10 ms. The 10 filled-in slots record exactly that: “on a big core, this time would have been idle”.
If Y is moved to a big core and really runs 2 ms and sleeps 14 ms, the big core’s clock runs at real-time speed and the bucket also records 2 running slots and 14 sleeping slots. The bucket sees exactly the same thing in both cases, and the level hovers around 2/16 × 1024 = 128 in both.
Without catching up, the bucket would only record “2 running + 4 sleeping” slots in 16 ms, a running fraction of 2/6 = 1/3, and the level would settle around 341: neither Y’s real weight nor its value on a big core.
The three ways of running side by side:
In the three cases the real running time is 2 / 6 / 12 ms; after conversion all are 2 slots, and util ≈ 128 in all three.
Does catching up make util drop suddenly
Filling in 10 slots at once looks like “a lot leaks all of a sudden”. Look at Y’s own util and the core’s util (section 5) separately. The numbers below are for Y in steady state: about 110 when each round starts, about 148 when it finishes running.
Y’s own util: not computed at all while asleep.
- At 12 ms, Y goes to sleep: the kernel saves Y’s current util (about 148) into util_est (section 4). After that Y is asleep; nobody reads its util and the kernel doesn’t update it.
- At 16 ms, Y wakes up: only now does the kernel compute Y’s level: how many slots did the core’s clock advance between Y going to sleep and now (10 filled in + 4 slept = 14), leak 14 slots at once, and 148 becomes about 110. Had Y been on a big core, the clock would have been at 2 slots when it went to sleep and at 16 when it woke up: the same 14 slots and the same 110.
- Then a core is picked for Y: using the larger of util (110) and util_est (148), i.e. 148.
The core’s util: after catching up, the same as on a big core. After Y goes to sleep, the water it poured into the core’s bucket stays in the core’s bucket and keeps leaking with the core’s clock (section 5). So at the moment the core goes idle and the clock fills in 10 slots, the core’s bucket does leak 10 slots at once. But compare it with “Y on a big core” at the same real time:
| Real time | Y on a big core at full speed | Y on a little core at 1.0 GHz |
|---|---|---|
| 0–2 ms | Running, level rises to 148 | Running, level rises slowly |
| 2–12 ms | Sleeping, leaks 10 slots one ms at a time, down to 119 | Still running, only reaches 148 at 12 ms |
| 12 ms, the little core just went idle | 119 | 10 slots filled in: 148 → 119 |
| 12–16 ms | Sleeping, leaks 4 slots, down to 110 | Sleeping, leaks 4 slots, down to 110 |
The moment the clock catches up, the little core’s number equals the big core’s number at the same moment. Catching up doesn’t leak anything extra; it fills in “the 10 slots that would already have leaked on a big core”, aligning the number with real time. During the 12 ms before that, the little core really was busy running Y, and the slowly rising level reflects exactly that: “this core is occupied”.
Y’s level swings even on a big core: from about 110 up to about 148 while running, back down to 110 while sleeping, averaging about 128. That is the “around” from section 2 and has nothing to do with catching up.
Exception: a core that is always busy
The conversion above relies on “filling in the missed slots when the core goes idle”. If a core is always busy and never idle, there is never a chance to fill in: every slot the bucket sees is “running”, and not a single “sleeping” slot is recorded.
The classic case is while(1): on a big core or a little core, its utilization is 100% either way. Its util ends up at 1024 on both; the little core’s clock just runs slow (at full speed, 3 ms per slot), so it rises 3 times more slowly:
| Running from 0 | Big core, full speed | Little core, full speed |
|---|---|---|
| Reaches 273 (80% of the little core) | 14 ms | 43 ms |
| Reaches 341 (the little core’s capacity) | 19 ms | 56 ms |
| Reaches 512 | 32 ms | 96 ms |
| Reaches 819 (80% of the big core) | 74 ms | 223 ms |
| Eventually | 1024 | 1024 |
Starting from 0 and running flat out on a little core: after about 43 ms util reaches 273, and from then on it “doesn’t fit” on the little core. It keeps rising, beyond the little core’s own 341.
This is not a bug. If the core is never idle, the kernel cannot see what the task “really needs”: it might need more than the little core can give and is only held back by the little core’s speed. Since it can’t tell, it lets util keep rising and treats the task as “give it as much as it takes”.
- For while(1) this is exactly right: on a big core it would also keep the big core fully busy; its real demand is 1024.
- For a task whose real demand is half a big core (util should be 512): on a little core it also keeps the core fully busy and util climbs toward 1024, an overestimate; but that very overestimate pushes it past 273, makes it misfit and gets it moved to a big core (section 6). On the big core it runs half the time and idles half the time, the core has idle time so the clock can catch up, and util gradually comes back down to around 512.
Also, on the core side cpu_util() is clamped to the core’s capacity, so a little core reads at most 341 (section 5).
Code references
kernel/sched/pelt.hupdate_rq_clock_pelt(): twocap_scale()calls scale time;update_idle_rq_clock_pelt(): catches up with real time when idle, and when fully busy records the part that can’t be caught up aslost_idle_timekernel/sched/fair.cdequeue_task_fair():util_est_update()saves the current util when the task goes to sleep;enqueue_entity()→update_load_avg(): on wake-up, accounts for the whole sleep at once by the number of slots the core’s clock advanceddrivers/base/arch_topology.ctopology_set_freq_scale(): updates the frequency ratio when cpufreq changes frequencyarch/riscv/include/asm/topology.h:arch_scale_freq_capacity→topology_get_freq_scale
4. util_est: “memory” across sleeps
util_avg has a problem: it starts decaying as soon as a task goes to sleep. A periodic task (say, doing work once per frame) has a lower util_avg every time it wakes up than while it was working. Picking a core by the value at wake-up would systematically underestimate it.
A task doing 8 ms of work every 32 ms (on a big core). The blue line is util_avg, the red dashed line is util_est.
Think of util_est as a record: every time the task goes to sleep, the kernel looks at its util_avg at that moment (i.e. how heavy it was by the end of this round of work) and decides whether to update the record (util_est_update()). There are four rules:
- Higher than the record: take the new value immediately. The task got heavier and the kernel must know right away; otherwise next time it wakes it will be put on a core that’s too small, run slower and drop frames.
- Lower than the record: move down only 1/4 of the way. One round with less work doesn’t mean the task is lighter from now on. Underestimating (too small a core, stutter) costs more than overestimating (a slightly bigger core, a bit more power), so “trust increases fast, decreases slowly”.
- Difference under 10 (1% of 1024): no change. That much is normal noise; updating would be pointless.
- It waited in a queue this round: no change. See the explanation below.
An example of rule 2: the record is 326, and this time the task goes to sleep at only 200 (a bit less work). It moves down by (326 − 200) / 4 ≈ 32 and the record becomes 294. If every later round is also 200, the record steps down:
| Sleep # | This round’s value | Record (util_est) |
|---|---|---|
| Before | 326 | 326 |
| 1 | 200 | 294 |
| 2 | 200 | 270 |
| 3 | 200 | 252 |
| 4 | 200 | 239 |
| … | 200 | Slowly approaches 200 |
| Gets heavier again | 326 | 326 (immediately) |
What “waited in a queue” in rule 4 means: when a task wants to run, another task may already be running on that core, so it has to wait in the queue. While it waits it isn’t running and its bucket only leaks, so when it finishes its work and goes to sleep, util_avg is lower than if it had run straight through. The task didn’t get lighter; waiting just pushed its running time later.
How does the kernel know it waited? With runnable_avg from section 2, which pours both while running and while waiting. Without waiting the two buckets are about the same height; after waiting, the runnable bucket is clearly higher. So the rule is: if runnable_avg exceeds util_avg by more than 10, the round is considered to have waited, and its value is not used to update the record.
When used, the larger one is taken: task_util_est(p) = max(util_avg, util_est). Both the fits check and wake-up core selection use this.
The core side has a record too: the sum of util_est of the tasks queued on the core (section 5). Frequency selection (06) uses it to raise the frequency as soon as a task wakes up, without waiting for util_avg to climb.
Code references
kernel/sched/fair.cutil_est_update(): the update rules; the 1/4 weight isUTIL_EST_WEIGHT_SHIFT 2, the 1% isUTIL_EST_MARGINtask_util_est(): takes the max;util_est_enqueue()/util_est_dequeue(): the per-core sum- To compare with it turned off: write
NO_UTIL_ESTto/sys/kernel/debug/sched/features
5. The CPU side: cpu_util and capacity_of
When comparing against a task, the core side uses two numbers: cpu_util(cpu) (how full this core already is) and capacity_of(cpu) (how much this core can really give to normal tasks).
cpu_util: how full a core already is
Each core also has its own bucket and record, with the same rules as tasks:
- The core’s bucket (util_avg on the core): whenever any normal task runs on this core, water is poured into this bucket, so it is roughly the sum of the util of the tasks on the core. When a task goes to sleep, its share is not removed; it stays in the bucket and keeps leaking with the core’s clock. Only when a task migrates to another core is its whole share removed and added to the new core’s bucket.
- The core’s record (util_est on the core): the sum of util_est of the tasks queued on this core (running and waiting to run). Added when a task wakes up and is placed here, subtracted when it goes to sleep or migrates away (end of section 4).
cpu_util(cpu) = the larger of the two, clamped to this core’s capacity. During core selection it also computes the value “if task p moved here or away”.
Example: a big core has task A (util 300) and task B (util 200), so cpu_util is about 500. It is used in three places:
- Frequency selection: 500 means these tasks together need about half of a big core at full speed; there is no need for the highest frequency, about 1.8 GHz is enough (06 covers how it is computed). When a task leaves and the total drops, the frequency drops with it.
- Core selection for other tasks: task C (util 200) wakes up and needs a core. A little core (capacity 341) already has 100; adding C gives 300, which exceeds 80% of 341 (about 272), so it doesn’t fit. A mid core (capacity 683) already has 300; adding C gives 500, which is below 80% of 683 (about 546), so it fits. What is compared is “what the core already has + the new task”.
- Load balancing: compare how full the cores are and move tasks from full cores to emptier ones (section 6, 05).
Can a core’s util exceed 1024
The core’s bucket hardly can. util only records “running”, and a core can only run one task at a time, pouring at most 22 per slot, the same as one task that runs all the time; so it tops out at 1024. Example: a big core has 3 tasks that all want to run all the time. They can only take turns, each getting 1/3 of the time, so each has util about 341, about 1024 in total. With 10 tasks it’s the same: the more tasks, the less each gets.
The record’s sum can exceed it briefly: for example, several tasks each carrying a large util_est saved before sleeping wake up onto the same core at once. That is why cpu_util is finally clamped to the core’s capacity: at most 1024 on a big core, at most 341 on a little core.
The price: util can only say “full”, not “how much over”. With 3 tasks or 10 tasks crowded together, util says full either way. To see how crowded it is, the kernel looks at other numbers: the core’s runnable_avg (section 2, which pours both while running and while waiting; about 3 × 1024 when 3 tasks all want to run all the time), and the number of tasks on the core (nr_running).
capacity_of: how much a core can really give to normal tasks
The core’s capacity minus what others have taken:
How does it know how much is left: each part is measured with the same kind of bucket as in section 2, or read directly from cpufreq.
So “how strong a core is” actually has three layers: capacity (01, fixed) → actual capacity (minus thermal and hardware frequency-capping pressure) → capacity_of (further minus what RT, DL and interrupts take). fits uses capacity_of; the uclamp_min check uses actual capacity (section 7).
Code references
kernel/sched/fair.ccpu_util(): takes the larger of util and util_est, finallymin(util, arch_scale_cpu_capacity(cpu))- When a task goes to sleep, its util stays in the core’s
cfs_rq->avgand keeps decaying (blocked util); only migration removes the whole share viadetach_entity_load_avg().util_est_dequeue()subtracts on sleep get_actual_cpu_capacity(): subtracts thermal/hardware pressure;scale_rt_capacity(): further subtracts RT, DL and interrupts;update_cpu_capacity(): written intorq->cpu_capacityduring load balancing, which is whatcapacity_of()reads
6. fits: does it fit
With numbers on both sides, the comparison is one line (near the top of kernel/sched/fair.c):
| |
1280 / 1024 = 1.25, i.e. util must be less than 80% of capacity. The 20% margin exists because util is an average over the past and a task can get heavier at any time; waiting until it is at 100% before moving it would be too late.
Thresholds: big core util ≤ 819, mid ≤ 546, little ≤ 272.
misfit: tasks that don’t fit
On every timer tick (and when picking the next task to run), the kernel checks whether the current task fits on this core (update_misfit_status()). If it doesn’t, it records misfit_task_load on this core’s rq (each core’s run queue), and load balancing later moves it toward a bigger core (next subsection). Three cases are not recorded:
- The system has no big and little cores (the global switch from 02 is off);
- The task can only run on this one core (its affinity allows a single CPU);
- The task is already on the biggest core it can go to (
p->max_allowed_capacity), like task D in the figure above.
Example: a while(1) starts on a little core. After about 43 ms its util exceeds 273; the timer-tick check finds it doesn’t fit and records it on the little core’s rq; when load balancing sees that, it moves the task to a big core if one is free. On the big core util keeps rising to 1024, beyond 819, so strictly it still doesn’t fit; but the big core is already the biggest it can go to, so misfit is no longer recorded and it stays on the big core. Those first 43 ms of delay are the “misfit lag” that 05 covers. If you don’t want it to take a big core, a person has to tell the scheduler (section 7).
How load balancing “sees” it
Nobody notifies anybody. The little core only records it on its own rq; when a big core does load balancing, it reads through the rq of every core in the group it is comparing, and sees the record along the way:
The rq is each core’s own data structure, and other cores can read it. Load balancing reads every core’s rq anyway to compare how busy they are; looking at misfit is just one more field.
The “does it fit” check is task_fits_cpu(): it asks util_fits_cpu() with task_util_est (section 4) and the task’s uclamp (section 7), and only a return value of 1 counts as fitting.
What if no core fits
The task always runs. The 80% only affects “which core to put the task on”, not “whether it may run”. Wake-up core selection (EAS, covered in 04) first skips cores where it doesn’t fit, then picks the most energy-efficient of the rest; if none fits, the task goes back to the core it was on last time. It runs there as usual; that core just goes above 80%, or the task takes turns with other tasks.
EAS can’t guarantee that no core goes above 80% either, it can only try: a task fits when placed, then its util grows while it runs; new tasks are forked; or no core fits in the first place.
overutilized: one full core changes how the whole group works. As soon as one core’s cpu_util exceeds 80% of its capacity_of, the kernel sets the overutilized flag. Note that this means “at least one core is full”; other cores may still be quite empty. The flag is shared by the whole group of cores (the root domain from 02), so one full core changes the behaviour of the whole group:
| Not overutilized | Overutilized | |
|---|---|---|
| Core selection on wake-up | By “does it fit, which core saves more energy” (EAS) | No more energy calculation; the normal path just looks for an idle core |
| Load balancing | Mostly skipped and left to EAS (except misfit) | Fully on, moving tasks from busy cores to less busy ones |
Why one full core switches the whole group: EAS relies on “every core still has some idle time”. Only then does a task’s util equal what it really needs, and the energy estimated from util is meaningful. Once a core is full, the tasks on it take turns, and util only reflects “how much it got”, not “how much it wants” (section 5: three tasks that all want to run all the time have util of only about 341 each). Estimating energy and picking cores from such numbers gives wrong results, so EAS is turned off and load balancing spreads the tasks out. Once all cores are back below 80%, the flag is cleared and EAS takes over again.
When every core is full:
- Load balancing distributes by capability: it compares “load_avg (section 2) ÷ core capacity”, so big cores get more and little cores less, and each core carries about the same pressure relative to its own capability;
- Tasks take turns on each core: time is shared by weight (nice value), higher weights get more, and everyone runs slower than they would alone;
- The frequency goes to the maximum: the core’s util has hit its capacity, so frequency selection goes to the top.
At this point every core is running flat out and the scheduler has no better place for any task. To make some tasks run faster, a person has to step in: run fewer tasks; use nice or cgroup cpu weights so important tasks get more time; use affinity or cpuset to keep important tasks apart from the rest.
Code references
kernel/sched/fair.cfits_capacity(),util_fits_cpu(),task_fits_cpu()update_misfit_status(): called fromtask_tick_fair()and when picking the next taskfind_energy_efficient_cpu(): skips cores whereutil_fits_cpu()is false, returnsprev_cpuif none fitscpu_overutilized(),check_update_overutilized_status(),set_rd_overutilized(): set the flag;select_task_rq_fair()only takes the EAS path if!is_rd_overutilized();sched_balance_find_src_group()doesgoto out_balancedwhen not overutilized
7. uclamp: hints from a person
uclamp (utilization clamp) is two values a person gives the scheduler, both in the range 0–1024:
- uclamp_min: treat it as at least this heavy (I want performance);
- uclamp_max: treat it as at most this heavy (I don’t need a stronger core or a higher frequency).
They can be set at three levels: a single task with sched_setattr() (command-line tool uclampset); a cgroup with cpu.uclamp.min / cpu.uclamp.max (percentages); and system-wide limits in /proc/sys/kernel/sched_util_clamp_min and sched_util_clamp_max. The effective value = the task’s own request, first clamped by the cgroup, then capped by the system limit (uclamp_eff_value()).
How it works in fits (util_fits_cpu()):
All four cases are checked on a little core; util means task_util_est.
- uclamp_max does not change util itself. The rule is: as long as uclamp_max does not exceed this core’s capacity, it counts as fitting. That is how you keep a big task on a little core.
- uclamp_min doesn’t change util either. If util itself fits but uclamp_min exceeds this core’s actual capacity, it returns −1: it fits, but cannot deliver the performance the person asked for.
- If nobody has ever set uclamp in the system, all of these checks are skipped (
uclamp_is_used()), leaving only the fits_capacity line.
When uclamp_max holds a task down but it really wants 500
The second row in the figure: a task on a little core with util 500 and uclamp_max 200. It counts as fitting, and then:
- It still runs, with no time limit. uclamp_max is not a CPU-time quota; it only affects “which core” and “what frequency”. The task can run as long as it wants and keep the little core fully busy. Limiting CPU time is a different mechanism, cgroup
cpu.max. - It is not treated as misfit. The misfit check (
task_fits_cpu()) also goes throughutil_fits_cpu(); uclamp_max 200 ≤ 341 counts as fitting, so it is not moved to a big core. - It doesn’t make the system overutilized either. The check whether a core is full (
cpu_overutilized(), section 6) also uses the uclamp_max of the tasks on the core, and again it counts as fitting. EAS keeps working, which is exactly what uclamp_max is for. - The frequency is held down. When schedutil picks a frequency, the core’s util is capped at the uclamp_max of the tasks on it. Picking by 200: 2.0 GHz × 200 / 341 ≈ 1.2 GHz. At that point the little core’s speed is about 341/1024 × 1.2/2.0 ≈ 1/5 of a big core at full speed, which corresponds to exactly 200.
So it “pushes through” on the little core at about 1.2 GHz: it gets at most the equivalent of 200 on a big core at full speed; it wants 500, so the same work takes about 2.5 times as long. That is the effect a person asks for by setting uclamp_max to 200: “it is worth at most this much performance”. If it really needs 500, uclamp_max should not be set below 500.
One exception: when other tasks are also runnable on the core, the core’s uclamp_max is the largest among them. As soon as another task without uclamp_max (default 1024) shows up, the frequency cap is lifted. uclamp_max is “soft”, not a hard limit.
uclamp_min works the other way: when picking a frequency, the core’s util is taken as at least uclamp_min, which pushes the frequency up (06). That is the “side effect: raises the frequency” mentioned in section 6 of 01.
RT tasks are treated as needing full speed by default: without uclamp, as soon as an RT task is runnable on a core, schedutil goes straight to the maximum frequency; with uclamp enabled, RT tasks have a default uclamp_min of 1024, with the same effect. To keep RT tasks from forcing the maximum frequency, lower
/proc/sys/kernel/sched_util_clamp_min_rt_default.
Code references
kernel/sched/fair.cutil_fits_cpu(): special handling of uclamp_max and uclamp_min, the conditions for returning −1kernel/sched/core.cuclamp_eff_value()/uclamp_tg_restrict(): task → cgroup → system limit;sysctl_sched_uclamp_util_min_rt_defaultkernel/sched/fair.ceffective_cpu_util(): the minimum performance comes from uclamp_min (set to full when uclamp is unused and an RT task is runnable), the maximum from the core’s uclamp_maxkernel/sched/cpufreq_schedutil.csugov_effective_cpu_perf(): adds 25% headroom to util, then clamps it to [min, max] before picking a frequencycpu_overutilized(): uses the core’suclamp_rq_get(rq, UCLAMP_MAX)in its check
8. Checking on a board
| |
If the busy-loop task above were moved to a big core halfway through (it won’t be, since taskset only allows cpu4; try a version without pinning), that would be misfit at work; 05 covers that part.
9. Self-test
- A task runs 3 ms out of every 16 ms on a little core at full speed. On a big core at full speed, how long does it run per 16 ms? Roughly what is its util?
- Why can the util of a task that keeps a little core fully busy exceed 341? What is that good for?
- When the periodic task from section 4 wakes up, what value does the scheduler use to pick a core? If one round it does a bit less work and goes to sleep with util_avg at 200, what does util_est become?
- Little core capacity 341, a task with util_est 300 and uclamp_max 300 (uclamp has been used on the system). Is
task_fits_cpu()true or false? - A big core has an RT task taking 30% of its time. Is a normal task with util 700 on that big core misfit?
- Task Y runs 12 ms out of every 16 ms on a little core at 1.0 GHz. In 16 ms, how many “running” and how many “sleeping” slots does the bucket record? Roughly what is util? If the slots weren’t filled in when the core goes idle, where would util settle?
- A task wakes up and doesn’t fit on any core. What happens to it? How does the system’s behaviour change afterwards?
- A big core has only one nice 0 task, util 200. It forks a child, which is placed on the same big core. What is the child’s starting util? What if the child were placed on an empty little core instead?
- A task on a little core has util 500 and uclamp_max 200 (uclamp has been used on the system). Will it be treated as misfit and moved to a big core? Roughly what frequency does the little core run at?
Answers
- The little core is 1/3 the speed of the big core, so on a big core it needs only 1 ms. util ≈ 1 / 16 × 1024 = 64, the same whichever core it is computed on (on the little core: 3 ms × 341/1024 ≈ 1 ms).
- The core is always busy and never idle long enough to fill in sleeping slots, so the bucket only sees “always running” and keeps getting water; util keeps rising toward 1024 (3 times more slowly than on a big core, since the clock runs slow). Use: it crosses the little core’s 273 threshold, is detected as misfit and is moved to a big core.
- By max(util_avg, util_est) = max(194, 326) = 326. util_avg drops to 200, lower than the old 326, so it moves down with a 1/4 weight: 326 − (326 − 200) / 4 ≈ 294.
- True. fits_capacity(300, 341) on its own is false (300 > 272), but uclamp_max 300 ≤ the little core’s capacity 341, so it counts as fitting; uclamp_min defaults to 0, so it doesn’t return −1.
- No. capacity_of ≈ 1024 × 70% ≈ 717, and 700 exceeds 80% of that, so it really doesn’t fit; but the big core is already the biggest it can go to (max_allowed_capacity = 1024), there is nowhere bigger to move it, so misfit is not recorded.
- 12 ÷ 6 = 2 running slots; 10 slots filled in when the core goes idle plus 4 slept slots make 14 sleeping slots. util ≈ 2/16 × 1024 = 128, the same as on a big core. Without filling in, only 2 running + 4 sleeping slots would be recorded, 2/6 → about 341.
- It still runs: EAS can’t find a core where it fits, so it puts it back on the core it was on last time (prev_cpu). Once that core is above 80%, the whole group is marked overutilized, EAS is turned off and load balancing spreads the tasks out; once all cores are back below 80%, EAS takes over again.
- cap (1024 − 200) / 2 = 412, estimate by weight about 1019, take the smaller: the start is 412. On an empty little core: the core’s util is 0, so it takes the cap 341 / 2 ≈ 170.
- No: uclamp_max 200 ≤ 341 counts as fitting, so no misfit is recorded and overutilized is not triggered. The frequency is picked by 200: 2.0 GHz × 200 / 341 ≈ 1.2 GHz. The task can still keep the little core fully busy; the same work just takes about 2.5 times as long.