kernel/sched/topology.c
Source file repositories/reference/linux-study-clean/kernel/sched/topology.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/sched/topology.c- Extension
.c- Size
- 90731 bytes
- Lines
- 3505
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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
linux/sched/isolation.hlinux/sched/clock.hlinux/bsearch.hsched.hlinux/sched/sd_flags.h
Detected Declarations
struct s_datastruct __cmp_keyenum s_allocfunction sched_domains_mutex_lockfunction sched_domains_mutex_unlockfunction sched_debug_setupfunction sched_debugfunction sched_domain_debug_onefunction for_each_set_bitfunction sched_domain_debugfunction sd_degeneratefunction sd_parent_degeneratefunction sched_is_eas_possiblefunction rebuild_sched_domains_energyfunction sched_energy_aware_handlerfunction sched_energy_aware_sysctl_initfunction free_pdfunction perf_domain_debugfunction destroy_perf_domain_rcufunction sched_energy_setfunction build_perf_domainsfunction for_each_cpufunction free_pdfunction rq_attach_rootfunction sched_get_rdfunction sched_put_rdfunction init_rootdomainfunction init_defrootdomainfunction free_sched_groupsfunction free_sched_domain_sharedfunction destroy_sched_domainfunction destroy_sched_domains_rcufunction destroy_sched_domainsfunction update_top_cache_domainfunction cpu_attach_domainfunction build_sched_domainsfunction alloc_sd_llcfunction for_each_cpufunction _sched_cache_active_setfunction sched_cache_active_setfunction cacheinfo_cpu_pre_downfunction get_effective_llc_bytesfunction sched_cache_setfunction alloc_sd_llcfunction sched_cache_setfunction should_we_balancefunction bitsfunction for_each_cpu
Annotated Snippet
struct s_data {
struct sched_domain_shared * __percpu *sds;
struct sched_domain * __percpu *sd;
struct root_domain *rd;
};
enum s_alloc {
sa_rootdomain,
sa_sd,
sa_sd_shared,
sa_sd_storage,
sa_none,
};
#ifdef CONFIG_SCHED_CACHE
/* hardware support for cache aware scheduling */
DEFINE_STATIC_KEY_FALSE(sched_cache_present);
/*
* Indicator of whether cache aware scheduling
* is active, used by the scheduler.
*/
DEFINE_STATIC_KEY_FALSE(sched_cache_active);
/* user wants cache aware scheduling [0 or 1] */
int sysctl_sched_cache_user = 1;
/*
* Get the effective LLC size in bytes that @cpu's bottom sched_domain
* can use. A CPU within a cpuset partition can only use a proportion
* of the physical LLC, scaled by the ratio of the partition's span
* weight to the hardware LLC sharing weight. @sd should be the
* topmost domain with SD_SHARE_LLC.
*
* Returns 0 if cacheinfo is not yet populated. This happens during
* early boot when build_sched_domains() runs before the generic
* cacheinfo framework has been initialized (cacheinfo_cpu_online()
* is a device_initcall cpuhp callback). In that case,
* cacheinfo_cpu_online() will later call sched_update_llc_bytes()
* to fill in the bottom domain's llc_bytes once the cache attributes
* are available.
*/
static unsigned long get_effective_llc_bytes(int cpu,
struct sched_domain *sd)
{
struct cacheinfo *ci;
unsigned int hw_weight;
ci = get_cpu_cacheinfo_llc(cpu);
if (!ci)
return 0;
hw_weight = cpumask_weight(&ci->shared_cpu_map);
if (!hw_weight)
return 0;
return div_u64((u64)ci->size * sd->span_weight, hw_weight);
}
static bool alloc_sd_llc(const struct cpumask *cpu_map,
struct s_data *d)
{
struct sched_domain *sd, *top_llc, *parent;
unsigned int *p;
int i;
for_each_cpu(i, cpu_map) {
sd = *per_cpu_ptr(d->sd, i);
if (!sd)
goto err;
p = kcalloc_node(max_lid + 1, sizeof(unsigned int),
GFP_KERNEL, cpu_to_node(i));
if (!p)
goto err;
top_llc = sd;
/*
* Find the topmost SD_SHARE_LLC domain.
* Not yet attached to the CPU, so per_cpu(sd_llc, i)
* can not be used.
*/
while ((parent = rcu_dereference_protected(top_llc->parent, true)) &&
(parent->flags & SD_SHARE_LLC))
top_llc = parent;
if (top_llc->flags & SD_SHARE_LLC) {
sd->llc_max = max_lid + 1;
sd->llc_counts = p;
sd->llc_bytes = get_effective_llc_bytes(i, top_llc);
} else {
/* avoid memory leak */
Annotation
- Immediate include surface: `linux/sched/isolation.h`, `linux/sched/clock.h`, `linux/bsearch.h`, `sched.h`, `linux/sched/sd_flags.h`.
- Detected declarations: `struct s_data`, `struct __cmp_key`, `enum s_alloc`, `function sched_domains_mutex_lock`, `function sched_domains_mutex_unlock`, `function sched_debug_setup`, `function sched_debug`, `function sched_domain_debug_one`, `function for_each_set_bit`, `function sched_domain_debug`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: integration 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.