kernel/sched/ext_cid.c
Source file repositories/reference/linux-study-clean/kernel/sched/ext_cid.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/sched/ext_cid.c- Extension
.c- Size
- 21458 bytes
- Lines
- 708
- 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.
- 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
linux/cacheinfo.h
Detected Declarations
enum cmask_op2enum cmask_op1function scx_cid_arrays_allocfunction levelfunction for_each_cpufunction scx_cmask_clearfunction scx_cmask_clearfunction scx_cpumask_to_cmaskfunction scx_bpf_cid_overridefunction for_each_possible_cpufunction scx_bpf_cid_to_cpufunction scx_bpf_cpu_to_cidfunction cmask_op2_is_predfunction cmask_word_op2function cmask_walk_op2function cmask_word_op1function cmask_op2_is_predfunction scx_cmask_andfunction scx_cmask_orfunction scx_cmask_copy_racyfunction scx_cmask_copyfunction scx_cmask_copyfunction scx_cmask_andnotfunction cmask_any_set_in_rangefunction scx_cmask_subsetfunction scx_cmask_intersectsfunction scx_cmask_emptyfunction scx_bpf_cid_topofunction scx_cid_kfunc_init
Annotated Snippet
if (nid < 0) {
cpumask_clear_cpu(next_cpu, to_walk);
continue;
}
node_idx = next_node_idx++;
/* node_scratch = to_walk & this node */
cpumask_and(node_scratch, to_walk, cpumask_of_node(nid));
if (WARN_ON_ONCE(!cpumask_test_cpu(next_cpu, node_scratch)))
return -EINVAL;
while (!cpumask_empty(node_scratch)) {
s32 ncpu = cpumask_first(node_scratch);
const struct cpumask *llc_mask = cpu_llc_mask(ncpu, llc_fallback);
s32 llc_cid = next_cid;
s32 llc_idx = next_llc_idx++;
/* llc_scratch = node_scratch & this llc */
cpumask_and(llc_scratch, node_scratch, llc_mask);
if (WARN_ON_ONCE(!cpumask_test_cpu(ncpu, llc_scratch)))
return -EINVAL;
while (!cpumask_empty(llc_scratch)) {
s32 lcpu = cpumask_first(llc_scratch);
const struct cpumask *sib = topology_sibling_cpumask(lcpu);
s32 core_cid = next_cid;
s32 core_idx = next_core_idx++;
s32 ccpu;
/* core_scratch = llc_scratch & this core */
cpumask_and(core_scratch, llc_scratch, sib);
if (WARN_ON_ONCE(!cpumask_test_cpu(lcpu, core_scratch)))
return -EINVAL;
for_each_cpu(ccpu, core_scratch) {
s32 cid = next_cid++;
scx_cid_to_cpu_tbl[cid] = ccpu;
scx_cpu_to_cid_tbl[ccpu] = cid;
scx_cid_topo[cid] = (struct scx_cid_topo){
.core_cid = core_cid,
.core_idx = core_idx,
.llc_cid = llc_cid,
.llc_idx = llc_idx,
.node_cid = node_cid,
.node_idx = node_idx,
};
cpumask_clear_cpu(ccpu, llc_scratch);
cpumask_clear_cpu(ccpu, node_scratch);
cpumask_clear_cpu(ccpu, to_walk);
}
}
}
}
/*
* No-topo section: any possible cpu without a cid - normally just the
* not-online ones. Collect any currently-online cpus that land here in
* @online_no_topo so we can warn about them at the end.
*/
for_each_cpu(cpu, cpu_possible_mask) {
s32 cid;
if (__scx_cpu_to_cid(cpu) != -1)
continue;
if (cpu_online(cpu))
cpumask_set_cpu(cpu, online_no_topo);
cid = next_cid++;
scx_cid_to_cpu_tbl[cid] = cpu;
scx_cpu_to_cid_tbl[cpu] = cid;
scx_cid_topo[cid] = SCX_CID_TOPO_NEG;
}
if (!cpumask_empty(llc_fallback))
pr_warn("scx_cid: cpus without cacheinfo, using node mask as llc: %*pbl\n",
cpumask_pr_args(llc_fallback));
if (!cpumask_empty(online_no_topo))
pr_warn("scx_cid: online cpus with no usable topology: %*pbl\n",
cpumask_pr_args(online_no_topo));
return 0;
}
/**
* scx_cmask_clear - Zero every bit in @m's active range
* @m: cmask to clear
*
Annotation
- Immediate include surface: `linux/cacheinfo.h`.
- Detected declarations: `enum cmask_op2`, `enum cmask_op1`, `function scx_cid_arrays_alloc`, `function level`, `function for_each_cpu`, `function scx_cmask_clear`, `function scx_cmask_clear`, `function scx_cpumask_to_cmask`, `function scx_bpf_cid_override`, `function for_each_possible_cpu`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: source implementation candidate.
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.