drivers/base/arch_topology.c
Source file repositories/reference/linux-study-clean/drivers/base/arch_topology.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/base/arch_topology.c- Extension
.c- Size
- 24830 bytes
- Lines
- 980
- Domain
- Driver Families
- Bucket
- drivers/base
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- 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/acpi.hlinux/cacheinfo.hlinux/cleanup.hlinux/cpu.hlinux/cpufreq.hlinux/cpu_smt.hlinux/device.hlinux/of.hlinux/slab.hlinux/sched/topology.hlinux/cpuset.hlinux/cpumask.hlinux/init.hlinux/rcupdate.hlinux/sched.hlinux/units.htrace/events/hw_pressure.hacpi/cppc_acpi.h
Detected Declarations
struct cpu_smt_infofunction supports_scale_freq_countersfunction for_each_cpufunction topology_scale_freq_invariantfunction update_scale_freq_invariantfunction topology_set_scale_freq_sourcefunction for_each_cpufunction topology_clear_scale_freq_sourcefunction for_each_cpufunction topology_scale_freq_tickfunction topology_set_freq_scalefunction topology_update_hw_pressurefunction topology_update_cpu_topologyfunction update_topology_flags_workfnfunction free_raw_capacityfunction topology_normalize_cpu_scalefunction topology_parse_cpu_capacityfunction freq_inv_set_max_ratiofunction for_each_possible_cpufunction for_each_possible_cpufunction acpi_processor_init_invariance_cppcfunction init_cpu_capacity_callbackfunction for_each_cpufunction register_cpufreq_notifierfunction parsing_done_workfnfunction get_cpu_for_nodefunction parse_corefunction parse_clusterfunction parse_socketfunction parse_dt_topologyfunction update_siblings_masksfunction clear_cpu_topologyfunction reset_cpu_topologyfunction for_each_possible_cpufunction remove_cpu_topologyfunction acpi_cpu_is_threadedfunction parse_acpi_topologyfunction for_each_possible_cpufunction init_cpu_topologyfunction for_each_possible_cpufunction store_cpu_topologymodule init register_cpufreq_notifiermodule init free_raw_capacityexport topology_set_scale_freq_sourceexport topology_clear_scale_freq_sourceexport topology_update_hw_pressureexport cpu_topology
Annotated Snippet
core_initcall(register_cpufreq_notifier);
static void parsing_done_workfn(struct work_struct *work)
{
cpufreq_unregister_notifier(&init_cpu_capacity_notifier,
CPUFREQ_POLICY_NOTIFIER);
free_cpumask_var(cpus_to_visit);
}
#else
core_initcall(free_raw_capacity);
#endif
#if defined(CONFIG_ARM64) || defined(CONFIG_RISCV)
/* Used to enable the SMT control */
static unsigned int max_smt_thread_num = 1;
/*
* This function returns the logic cpu number of the node.
* There are basically three kinds of return values:
* (1) logic cpu number which is > 0.
* (2) -ENODEV when the device tree(DT) node is valid and found in the DT but
* there is no possible logical CPU in the kernel to match. This happens
* when CONFIG_NR_CPUS is configure to be smaller than the number of
* CPU nodes in DT. We need to just ignore this case.
* (3) -1 if the node does not exist in the device tree
*/
static int __init get_cpu_for_node(struct device_node *node)
{
int cpu;
struct device_node *cpu_node __free(device_node) =
of_parse_phandle(node, "cpu", 0);
if (!cpu_node)
return -1;
cpu = of_cpu_node_to_id(cpu_node);
if (cpu >= 0)
topology_parse_cpu_capacity(cpu_node, cpu);
else
pr_info("CPU node for %pOF exist but the possible cpu range is :%*pbl\n",
cpu_node, cpumask_pr_args(cpu_possible_mask));
return cpu;
}
static int __init parse_core(struct device_node *core, int package_id,
int cluster_id, int core_id)
{
char name[20];
bool leaf = true;
int i = 0;
int cpu;
do {
snprintf(name, sizeof(name), "thread%d", i);
struct device_node *t __free(device_node) =
of_get_child_by_name(core, name);
if (!t)
break;
leaf = false;
cpu = get_cpu_for_node(t);
if (cpu >= 0) {
cpu_topology[cpu].package_id = package_id;
cpu_topology[cpu].cluster_id = cluster_id;
cpu_topology[cpu].core_id = core_id;
cpu_topology[cpu].thread_id = i;
} else if (cpu != -ENODEV) {
pr_err("%pOF: Can't get CPU for thread\n", t);
return -EINVAL;
}
i++;
} while (1);
max_smt_thread_num = max_t(unsigned int, max_smt_thread_num, i);
cpu = get_cpu_for_node(core);
if (cpu >= 0) {
if (!leaf) {
pr_err("%pOF: Core has both threads and CPU\n",
core);
return -EINVAL;
}
cpu_topology[cpu].package_id = package_id;
cpu_topology[cpu].cluster_id = cluster_id;
cpu_topology[cpu].core_id = core_id;
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/cacheinfo.h`, `linux/cleanup.h`, `linux/cpu.h`, `linux/cpufreq.h`, `linux/cpu_smt.h`, `linux/device.h`, `linux/of.h`.
- Detected declarations: `struct cpu_smt_info`, `function supports_scale_freq_counters`, `function for_each_cpu`, `function topology_scale_freq_invariant`, `function update_scale_freq_invariant`, `function topology_set_scale_freq_source`, `function for_each_cpu`, `function topology_clear_scale_freq_source`, `function for_each_cpu`, `function topology_scale_freq_tick`.
- Atlas domain: Driver Families / drivers/base.
- 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.