kernel/sched/ext_idle.c
Source file repositories/reference/linux-study-clean/kernel/sched/ext_idle.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/sched/ext_idle.c- Extension
.c- Size
- 44898 bytes
- Lines
- 1512
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
struct scx_idle_cpusstruct scx_bpf_select_cpu_and_argsfunction scx_cpu_node_if_enabledfunction scx_idle_test_and_clear_cpufunction scx_pick_idle_cpufunction pick_idle_cpu_in_nodefunction pick_idle_cpu_from_online_nodesfunction Ofunction pick_idle_cpu_from_online_nodesfunction scx_pick_idle_cpufunction llc_weightfunction numa_weightfunction llc_numa_mismatchfunction scx_idle_update_selcpu_topologyfunction task_affinity_allfunction scx_select_cpu_dflfunction for_each_cpu_andfunction scx_idle_init_masksfunction for_each_nodefunction update_builtin_idlefunction transitionfunction reset_idle_masksfunction for_each_nodefunction scx_idle_enablefunction scx_idle_disablefunction validate_nodefunction check_builtin_idle_enabledfunction migrate_disablefunction select_cpu_from_kfuncfunction SCX_CALL_OP_TASK_RETfunction scx_bpf_cpu_nodefunction test_runfunction test_runfunction scx_bpf_select_cpu_andfunction scx_errorfunction scx_errorfunction scx_bpf_put_idle_cpumaskfunction distancefunction scx_bpf_kick_cpufunction distancefunction scx_bpf_pick_any_cpu_nodefunction scx_idle_init
Annotated Snippet
struct scx_idle_cpus {
cpumask_var_t cpu;
cpumask_var_t smt;
};
/*
* Global host-wide idle cpumasks (used when SCX_OPS_BUILTIN_IDLE_PER_NODE
* is not enabled).
*/
static struct scx_idle_cpus scx_idle_global_masks;
/*
* Per-node idle cpumasks.
*/
static struct scx_idle_cpus **scx_idle_node_masks;
/*
* Local per-CPU cpumasks (used to generate temporary idle cpumasks).
*/
static DEFINE_PER_CPU(cpumask_var_t, local_idle_cpumask);
static DEFINE_PER_CPU(cpumask_var_t, local_llc_idle_cpumask);
static DEFINE_PER_CPU(cpumask_var_t, local_numa_idle_cpumask);
/*
* Return the idle masks associated to a target @node.
*
* NUMA_NO_NODE identifies the global idle cpumask.
*/
static struct scx_idle_cpus *idle_cpumask(int node)
{
return node == NUMA_NO_NODE ? &scx_idle_global_masks : scx_idle_node_masks[node];
}
/*
* Returns the NUMA node ID associated with a @cpu, or NUMA_NO_NODE if
* per-node idle cpumasks are disabled.
*/
static int scx_cpu_node_if_enabled(int cpu)
{
if (!static_branch_maybe(CONFIG_NUMA, &scx_builtin_idle_per_node))
return NUMA_NO_NODE;
return cpu_to_node(cpu);
}
static bool scx_idle_test_and_clear_cpu(int cpu)
{
int node = scx_cpu_node_if_enabled(cpu);
struct cpumask *idle_cpus = idle_cpumask(node)->cpu;
/*
* SMT mask should be cleared whether we can claim @cpu or not. The SMT
* cluster is not wholly idle either way. This also prevents
* scx_pick_idle_cpu() from getting caught in an infinite loop.
*/
if (sched_smt_active()) {
const struct cpumask *smt = cpu_smt_mask(cpu);
struct cpumask *idle_smts = idle_cpumask(node)->smt;
/*
* If offline, @cpu is not its own sibling and
* scx_pick_idle_cpu() can get caught in an infinite loop as
* @cpu is never cleared from the idle SMT mask. Ensure that
* @cpu is eventually cleared.
*
* NOTE: Use cpumask_intersects() and cpumask_test_cpu() to
* reduce memory writes, which may help alleviate cache
* coherence pressure.
*/
if (cpumask_intersects(smt, idle_smts))
cpumask_andnot(idle_smts, idle_smts, smt);
else if (cpumask_test_cpu(cpu, idle_smts))
__cpumask_clear_cpu(cpu, idle_smts);
}
return cpumask_test_and_clear_cpu(cpu, idle_cpus);
}
/*
* Pick an idle CPU in a specific NUMA node.
*/
static s32 pick_idle_cpu_in_node(const struct cpumask *cpus_allowed, int node, u64 flags)
{
int cpu;
retry:
if (sched_smt_active()) {
cpu = cpumask_any_and_distribute(idle_cpumask(node)->smt, cpus_allowed);
if (cpu < nr_cpu_ids)
goto found;
Annotation
- Detected declarations: `struct scx_idle_cpus`, `struct scx_bpf_select_cpu_and_args`, `function scx_cpu_node_if_enabled`, `function scx_idle_test_and_clear_cpu`, `function scx_pick_idle_cpu`, `function pick_idle_cpu_in_node`, `function pick_idle_cpu_from_online_nodes`, `function O`, `function pick_idle_cpu_from_online_nodes`, `function scx_pick_idle_cpu`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.