The “example chip” is fictional: die 0 has 4 big cores (cpu 0-3) + 4 little cores (cpu 4-7); another die has 2 mid cores (cpu 8-9, the same core design as the big cores at a lower frequency). Capacities follow the example in 01 (big 1024, little ≈ 341, mid ≈ 683). Code references are against the Linux 6.18 source.

Part 01 covered how strong each core is. This post covers the relationships between cores: over what range the scheduler moves tasks and picks cores, and how it discovers that “there are big and little cores here”.

0. The whole picture

At boot the kernel does 4 things and ends up with 3 results, each used by different parts of the scheduler:

Overview of how the topology is built

Each of the following sections corresponds to one step in the figure.

1. The hardware first: who shares which cache

When a task moves from one core to another, the cost depends on which cache level the two cores share. If they share one, most data is hit directly in the shared cache after the move; if not, the local cache is empty and the data has to be fetched line by line across the interconnect from the other cluster’s cache or from memory (see the second half of this section). So the scheduler groups cores by cache sharing.

Cache structure of die 0 on the example chip

  • LLC = Last Level Cache, the last stop before memory. On the example chip it is the L3; on chips without an L3, the LLC is the L2.
  • A cluster is a hardware “group of cores”. How many cores it has is up to the chip design; 4, 8 and 2 are all common.

What snoop is: one mechanism, two uses

Multi-cluster chips usually have hardware coherency: clusters are connected by a coherent interconnect and each cluster has a snoop filter. The hardware knows nothing about threads; it only sees “which core reads or writes which address”, and the coherency protocol guarantees one thing: every core reads the latest value. For that, each cache line has a state in each core, simplified here to three:

StateMeaning
M (Modified)Only I have it, and I changed it; memory holds a stale copy
S (Shared)Several cores hold the same copy, read-only
I (Invalid)My copy is void, as if I didn’t have it

Snoop means “ask the others whether they have it, and in what state, before using it”. There are two kinds of request:

  • To write: tell the others “your copies are invalid”.
  • To read when I don’t have it: ask “who has the latest? Give me a copy”.

Note: a write does not push the new value to the other side; it only invalidates the other copy. The next time the other side reads, it misses and uses the second request to pull the new value. So the two requests always go together.

Snoop for a shared variable and for task migration

The table is a simplified three-state model; real protocols also have E, O and other states, and what each side ends up in after a read depends on the protocol implementation. That does not change the conclusion here. “Asking the others” is usually not a broadcast to every core: the snoop filter in the interconnect (which tracks “which line may be in which cluster”) only asks the cluster that may have it.

Cross-cluster migration: data is not lost, but has to be fetched across the interconnect

After a task moves from a big core to a little core, the full path of one read is:

Path of a cross-cluster cache miss

Every cache line goes through ①→④ the first time it is used. The data is “hot” (still on the other side) but “not at hand”. So “the cache goes cold after a move” is not quite right; more precisely: the local cache is empty, the data is in the other cluster or in memory, and has to be fetched across the interconnect one line at a time on demand. The cost comes from:

  • Every first access is slower: a local L3 hit stays inside the cluster; across clusters it has to leave the cluster, cross the interconnect, snoop the other side and come back, with much higher latency, possibly close to a DRAM access (measure for real numbers).
  • Lines move one by one on demand: the bigger the working set, the more transfers and the longer before it is “warm”.
  • It only helps for data still on the other side: new tasks on the old core gradually evict the old data, after which it can only come from DRAM.
  • Does it fit: the little cluster’s L3 is often smaller than the big cluster’s; with a big working set, the L3 hit rate itself drops after moving to the little core.
  • Data to be written must also “grab” ownership: before writing, the other copy must be invalidated and ownership moved over, another cross-cluster round trip. This repeats when a task ping-pongs between the two sides.
  • Whether clean (unmodified) lines are forwarded from the other cache or read from memory depends on the interconnect implementation and configuration.

Migration within a cluster (say cpu0 → cpu3) is different: L1/L2 are private and have to refill too, but their next level is the shared L3, so most data is hit directly in L3 without leaving the cluster. That is what “the shared cache level determines migration cost” means. The scheduler does not distinguish “fetched from the other cache” from “fetched from DRAM”; it only uses “shares the LLC or not” to build levels, plus sched_migration_cost (0.5 ms by default, “a task that just ran counts as hot, don’t move it yet”) as a rough cost estimate. Parts 04/05 will cover that.

2. How the scheduler builds levels: only “which level is shared”, not “which L”

The names the scheduler gives its levels (MC, CLS, PKG) are based on relative position and have nothing to do with whether the cache is called L2 or L3. There are only 4 rules:

  1. Find the LLC. The group of cores sharing the LLC is MC.
  2. If inside MC a smaller group of cores shares an inner cache, that smaller group is CLS. If not, there is no CLS.
  3. All cores on the same die (NUMA node) are PKG. Across dies, the level above is NUMA.
  4. Levels with the same span as the level above or below are removed.

Walking through three cache structures (top to bottom is L1 → L2 → L3; the red box is each one’s LLC):

Three cache structures and the resulting levels

To decide whether a “group sharing an L2” is CLS or MC, look for a bigger shared cache below it. If there is one → CLS; if not (it is the LLC) → MC.

  • RISC-V has no CLS level: only the x86 and arm64 Kconfigs enable it; nobody has added it for RISC-V yet. Chip B above and the example chip cannot use it, so it does not matter here.
  • RISC-V has no SMT level either (multiple hardware threads in one core). So RISC-V effectively has only MC → PKG, plus the cross-die levels with NUMA enabled.
  • ARM phones (DynamIQ) commonly put big and little cores under the same L3: MC is all cores, and big and little are already mixed at the MC level (case C in section 3). The example chip is different: the big and little clusters each have their own L3 and only meet at the PKG level.
  • A cluster is not CLS: a cluster in hardware documentation is “a group of cores”; the scheduler’s CLS is “a subgroup inside the LLC”. On chip B and on the example chip, the hardware cluster corresponds to the MC level.
  • What PKG is: the name means package, but the code actually uses “all CPUs in the same NUMA node as me”. Without NUMA that is all CPUs; with one node per die it is all cores on one die.
Code references
  • List of levels: kernel/sched/topology.c default_topology[] (SMT→CLS→MC→PKG); with NUMA, NODE and NUMA levels are appended
  • Span of MC: drivers/base/arch_topology.c cpu_coregroup_mask(), the smallest of “same node”, “same package” and “shares the LLC”
  • CLS may not be ≥ MC: arch_topology.c cpu_clustergroup_mask()
  • Span of PKG: topology.c tl_pkg_mask() → cpu_node_mask(), i.e. the same NUMA node
  • Each CPU’s “sibling” masks: arch_topology.c update_siblings_masks(); llc_sibling comes from the cache description, cluster_sibling from cpu-map; they are computed independently and may or may not be equal
  • RISC-V only selects ARCH_SUPPORTS_SCHED_MC (arch/riscv/Kconfig); only x86 and arm64 select ARCH_SUPPORTS_SCHED_CLUSTER
  • Removing duplicate levels: topology.c sd_degenerate(), sd_parent_degenerate()

3. Levels on the example chip

Case A: the DT describes both L3s correctly

Scheduling levels of die 0 on the example chip

Once NUMA is enabled, there will be one more “cross-die” level outside PKG that also includes die 1.

Case B: the DT has no cache nodes, or describes a system-level cache shared by big and little cores as the LLC

Levels when the cache description is wrong

Big and little cores are still recognized, but logic such as “look for an idle core within the shared-cache range” mixes big and little cores together, and the cost of cross-cluster migration is underestimated. Conclusion: the DT should describe the two L3s separately; a system-level cache hanging off the interconnect should not be in the CPUs’ next-level-cache chain.

Case C: big and little cores share the same cache (e.g. ARM DynamIQ phones)

Levels when big and little cores share a cache

No special handling is needed: the rule is still “count the types”; the first level that sees 2 types just becomes MC. Sharing a cache actually makes migration between big and little cores cheaper.

4. Recognizing big and little cores: count the core types at each level

The method is simple:

  1. First list the distinct capacity values in the system. On die 0 of the example chip there are only two: 1024 (cpu 0-3) and 341 (cpu 4-7).
  2. Then each level counts how many types are in its span:
    • Only 1: the cores at this level are equally strong; nothing is flagged.
    • 2 or more: flag ASYM, meaning “this level has cores of different strength”.
    • And all types are present (as many types as this root domain has): also flag FULL.

Counting capacity types at each level

If special-purpose cores (such as AI cores) are in a separate partition (section 6), their type is not in this root domain at all and does not count as “missing”.

Code references and exact rules
  • Building the type list: topology.c asym_cpu_capacity_scan(), which only scans CPUs that take part in scheduling (those isolated with isolcpus=domain don’t count)
  • Counting types per level: topology.c asym_cpu_capacity_classify(span of this level, cpu_map), called from sd_init(). cpu_map is all CPUs of the current root domain
  • For each capacity value: present at this level → count++; absent here but present in the root domain → miss++; absent from the root domain too → not counted
  • count < 2 → no flag; miss > 0 → SD_ASYM_CPUCAPACITY; otherwise also SD_ASYM_CPUCAPACITY_FULL

5. Who uses these flags

Why flag every level? Because the scheduler has two kinds of code that use them differently:

How load balancing and wake-up core selection use the levels

All three results are in effect; they just serve different code. On the example chip, both “the level with ASYM” and “the core-selection range” are PKG.

ResultQuestion it answersUsed byOn the example chip
A. Global switchDoes the system have big and little cores?Master switch for all big/little logic: misfit tracking, wake-up core selection, RT core selection, uclampOn
B. ASYM per levelDo the groups at this level differ in strength?Load balancing (each level decides on its own)Not on MC, on PKG
C. Core-selection range (FULL)Where to look when choosing between big and little cores?Wake-up core selection, EAS, idle cores actively pulling misfit tasksPKG

In addition, a level with ASYM turns off “spread evenly” (SD_PREFER_SIBLING) for the level below: between big and little cores, work should not be forced onto little cores just for balance.

The two paths of load balancing

Periodic balancing and idle balancing

“Stop once something is pulled, going up level by level” only applies to path 2. Path 1 runs on each level’s own timer.

How often load balancing runs: the kernel decides and adjusts it

LevelInitial intervalMaximum (when balanced for a while)When the CPU is busy (×16)
MC {0-3}4 ms8 ms64–128 ms
PKG {0-7}8 ms16 ms128–256 ms
  • Who sets it: the kernel computes it when building the levels: initial interval = number of CPUs in the level (ms), maximum = 2×.
  • How it adapts: when a balance pass finds things balanced with nothing to move, the interval doubles (up to the maximum); as soon as it finds an imbalance, the interval goes back to the initial value. Idle balancing and misfit migration do not lengthen the interval.
  • When the CPU is busy it is multiplied by 16 (busy_factor): a busy CPU worries less about others, and idle CPUs are the ones that eagerly pull work.
  • Upper bound: no level exceeds HZ × online CPUs / 10 ticks (about 0.8 s on 8 cores). Time is actually counted in ticks, so intervals finer than a tick are not possible.
  • Can it be configured: there is no official sysctl. With sched verbose enabled, min_interval, max_interval, busy_factor and imbalance_pct under debugfs /sys/kernel/debug/sched/domains/cpuN/domainM/ are writable, for debugging only: whenever the domain tree is rebuilt (CPU hotplug, cpuset changes) they reset to defaults.

Without big and little cores, do the levels still exist? Yes. Levels such as MC and PKG are built whether or not there are big and little cores, and load balancing runs at each level as usual. There is just no level with ASYM, so: the global switch is off; the “core-selection range” pointer is NULL (not “everything is FULL by default”); wake-up core selection uses the level that shares the LLC (MC) as its range and looks for an idle core there. A system where every core has the same capacity (e.g. the DT has no capacity-dmips-mhz) behaves exactly like this.

Code references
  • A, the global switch sched_asym_cpucapacity: in build_sched_domains(), turned on if any level has ASYM; checked with sched_asym_cpucap_active() in fair.c, rt.c and core.c (uclamp)
  • B, per-level ASYM in load balancing (fair.c): update_sg_lb_stats() (records misfit), update_sd_pick_busiest() (picks the busiest group), calculate_imbalance() (moves by misfit), sched_balance_find_src_rq() (picks the source CPU), update_sg_wakeup_stats() (fork/exec slow-path group selection)
  • C, the core-selection range sd_asym_cpucapacity = the lowest FULL level (topology.c update_top_cache_domain()); used in select_idle_sibling() → select_idle_capacity(), find_energy_efficient_cpu(), nohz_balancer_kick() and the check whether EAS can be enabled; without big and little cores sd_llc is used
  • Periodic balancing: sched_balance_trigger() (checks rq->next_balance every tick) → sched_balance_domains(), each level only when due; interval from get_sd_balance_interval() (initial balance_interval = sd_weight, ×busy_factor when busy); one CPU per group: should_we_balance()
  • Adaptive interval: at the end of sched_balance_rq(), balance_interval *= 2 when balanced, back to min_interval when not
  • Idle balancing: sched_balance_newidle(), level by level, stopping when avg_idle cannot cover this level’s cost
  • Turning off PREFER_SIBLING, the WARN for SMT + ASYM: topology.c sd_init()

6. Root domains: the scheduler’s “borders”

All the levels above are built inside one root domain. The system can be cut into several pieces, each with its own domain tree. Core selection and load balancing never cross a border; a task only moves to another piece if its affinity or cpuset is changed.

Example root domain partitioning

Ways to partition: one for the whole system by default; the boot parameter isolcpus=domain,…; or cgroup v2 cpuset partitions (cpuset.cpus.partition = root / isolated).

How root domains relate to levels

An analogy: levels are “city, province, country” inside one country, nested one in another; a task can move from one city to another province, it just happens less the farther it is. Root domains are different countries: each has its own “city, province, country”, and the scheduler never compares which country is busier.

Root domains vs affinity

Both approaches keep tasks from crossing the line, but the mechanisms differ: approach 1 cuts the scheduler’s structure; approach 2 leaves the structure alone and gives each task an allow list.

Levels (MC / PKG / NUMA)Root domainAffinity
What it isNested groups in one treeCPUs cut into pieces, one tree per pieceA per-task list of “cores I may run on”
Can tasks crossYes, just less often at higher levelsNo (unless the cpuset changes)Not outside the list
How the scheduler accountsOne tree, accounted togetherEach piece accounted separatelyStill one tree, accounted together; migration just skips disallowed cores
Who sets it upThe kernel, automatically from the DTBoot parameter or cpusetThe process itself / user space / a vendor driver

A typical affinity-based design: some vendor kernels’ HMP schemes do not cut root domains. Instead they split cores into “normal cores” and “AI cores”: every new task is only allowed on normal cores; tasks marked as AI are only allowed on AI cores; when user space changes affinity, requests outside the task’s class are rejected. Such a system has a single root domain with all cores in one tree.

Why special-purpose cores should get their own root domain when doing big/little scheduling: EAS and misfit handling run between big and little cores, and both are computed per root domain. If the special-purpose cores stay in the same root domain, there are more capacity types: a level that only contains big + little cores is no longer “complete” and cannot get FULL (section 4), and EAS also has to include them in the energy model. Once they are cut out, the big + little root domain is clean.

The root domain also holds the perf domains used by EAS and the “overutilized” flag; part 04 will cover those.

Code references
  • One root domain by default: topology.c sched_init_domains() (excluding cores isolated by HK_TYPE_DOMAIN)
  • cpuset partitions: kernel/cgroup/cpuset.c generate_sched_domains() → partition_sched_domains()
  • Type counting only looks at this root domain: miss in asym_cpu_capacity_classify() only counts types present in cpu_map
  • Affinity checks: sched_setaffinity() → __sched_setaffinity(); load balancing skips disallowed cores in can_migrate_task()

7. Checking on a board

1
2
3
4
5
6
7
# topology parsed from the DT
cat /sys/devices/system/cpu/cpu0/topology/{package_cpus_list,cluster_cpus_list}
# caches: who shares each level (the last level is the LLC)
grep . /sys/devices/system/cpu/cpu0/cache/index*/{level,shared_cpu_list}
# domain tree: enable verbose first, otherwise the domains directory does not exist
echo Y > /sys/kernel/debug/sched/verbose      # or the boot parameter sched_verbose
grep . /sys/kernel/debug/sched/domains/cpu0/domain*/{name,flags}

Expected for case A on the example chip: cpu0/domain0 is MC without ASYM; domain1 is PKG with SD_ASYM_CPUCAPACITY SD_ASYM_CPUCAPACITY_FULL. If every core’s cpu_capacity is 1024, no level has ASYM.

8. Self-test

  1. On RISC-V, cpu-map describes the big and little cores as two clusters, but the DT has no cache nodes. How many levels are there in the end? Which level has ASYM + FULL?
  2. Suppose a level’s span is {0-3, 4} (4 big cores plus 1 little core). In a root domain with only big + little cores, is it ASYM or ASYM + FULL?
  3. After using cpuset to cut the little cores into their own partition, does the big-core tree still have ASYM? Is the global switch still on?
  4. A task on a little core can’t keep up. Which level’s load balancing moves it to a big core? Can the MC level do it?
Answers
  1. Only 1 level, MC, spanning cpu 0-7, and it is ASYM + FULL. Without cache nodes the kernel has no LLC information, so MC falls back to the span of the die (with no socket in cpu-map, all cores count as the same package); PKG has the same span and is removed. The two clusters in cpu-map are only used by the CLS level, and RISC-V has no CLS, so they might as well not be there. The result is case B in section 3: the scheduler thinks all 8 cores share a cache. If die 1 is in the same root domain, there is one more NUMA level on top.
  2. ASYM + FULL. FULL only requires “every capacity type in the root domain appears at least once at this level”, not that every CPU is present. {0-3, 4} has both big and little cores: count = 2, miss = 0.
  3. Neither. The big-core tree has only one capacity type, count = 1 at every level, so no ASYM; the same for the little-core tree. The global switch is a counter: +1 when a tree with ASYM is built, −1 when one is torn down. Repartitioning tears down the old tree (−1), and neither new tree has ASYM (no +1), so the switch turns off and all big/little logic is skipped (assuming no other partition still has ASYM).
  4. The PKG level. To move a task from a little core to a big core, the balancing range must include both; on the example chip the lowest such level is PKG (two groups {0-3}, {4-7}), which has ASYM and pulls the struggling task to a big core by the big/little rules (part 05 covers the process). The MC level cannot: the little cores’ MC only has cpu 4-7 and can only move tasks among little cores. Also, the next time the task wakes up, wake-up core selection (whose range is also PKG) may place it directly on a big core, but that is not load balancing.