drivers/base/cpu.c
Source file repositories/reference/linux-study-clean/drivers/base/cpu.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/base/cpu.c- Extension
.c- Size
- 18180 bytes
- Lines
- 697
- Domain
- Driver Families
- Bucket
- drivers/base
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/kernel.hlinux/module.hlinux/init.hlinux/sched.hlinux/cpu.hlinux/topology.hlinux/device.hlinux/node.hlinux/gfp.hlinux/slab.hlinux/percpu.hlinux/acpi.hlinux/of.hlinux/cpufeature.hlinux/tick.hlinux/pm_qos.hlinux/delay.hlinux/sched/isolation.hbase.hlinux/kexec.h
Detected Declarations
struct cpu_attrfunction cpu_subsys_matchfunction change_cpu_under_nodefunction cpu_subsys_onlinefunction cpu_hotplug_disablefunction cpu_subsys_offlinefunction unregister_cpufunction cpu_probe_storefunction cpu_release_storefunction crash_notes_showfunction crash_notes_size_showfunction show_cpus_attrfunction print_cpus_kernel_maxfunction print_cpus_offlinefunction print_cpus_enabledfunction print_cpus_isolatedfunction housekeeping_showfunction nohz_full_showfunction crash_hotplug_showfunction cpu_device_releasefunction cpu_ueventfunction register_cpufunction device_create_releasefunction __cpu_device_createfunction cpu_is_hotpluggablefunction arch_cpu_is_hotpluggablefunction arch_register_cpufunction arch_unregister_cpufunction cpu_dev_register_genericfunction for_each_present_cpufunction cpu_show_not_affectedfunction cpu_register_vulnerabilitiesfunction cpu_register_vulnerabilitiesexport cpu_subsysexport get_cpu_deviceexport cpu_device_createexport cpu_is_hotpluggable
Annotated Snippet
static int cpu_subsys_match(struct device *dev, const struct device_driver *drv)
{
/* ACPI style match is the only one that may succeed. */
if (acpi_driver_match_device(dev, drv))
return 1;
return 0;
}
#ifdef CONFIG_HOTPLUG_CPU
static void change_cpu_under_node(struct cpu *cpu,
unsigned int from_nid, unsigned int to_nid)
{
int cpuid = cpu->dev.id;
unregister_cpu_under_node(cpuid, from_nid);
register_cpu_under_node(cpuid, to_nid);
cpu->node_id = to_nid;
}
static int cpu_subsys_online(struct device *dev)
{
struct cpu *cpu = container_of(dev, struct cpu, dev);
int cpuid = dev->id;
int from_nid, to_nid;
int ret;
int retries = 0;
from_nid = cpu_to_node(cpuid);
if (from_nid == NUMA_NO_NODE)
return -ENODEV;
retry:
ret = cpu_device_up(dev);
/*
* If -EBUSY is returned, it is likely that hotplug is temporarily
* disabled when cpu_hotplug_disable() was called. This condition is
* transient. So we retry after waiting for an exponentially
* increasing delay up to a total of at least 620ms as some PCI
* device initialization can take quite a while.
*/
if (ret == -EBUSY) {
retries++;
if (retries > 5)
return ret;
msleep(10 * (1 << retries));
goto retry;
}
/*
* When hot adding memory to memoryless node and enabling a cpu
* on the node, node number of the cpu may internally change.
*/
to_nid = cpu_to_node(cpuid);
if (from_nid != to_nid)
change_cpu_under_node(cpu, from_nid, to_nid);
return ret;
}
static int cpu_subsys_offline(struct device *dev)
{
return cpu_device_down(dev);
}
void unregister_cpu(struct cpu *cpu)
{
int logical_cpu = cpu->dev.id;
set_cpu_enabled(logical_cpu, false);
unregister_cpu_under_node(logical_cpu, cpu_to_node(logical_cpu));
device_unregister(&cpu->dev);
per_cpu(cpu_sys_devices, logical_cpu) = NULL;
return;
}
#ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
static ssize_t cpu_probe_store(struct device *dev,
struct device_attribute *attr,
const char *buf,
size_t count)
{
ssize_t cnt;
int ret;
ret = lock_device_hotplug_sysfs();
if (ret)
return ret;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/init.h`, `linux/sched.h`, `linux/cpu.h`, `linux/topology.h`, `linux/device.h`, `linux/node.h`.
- Detected declarations: `struct cpu_attr`, `function cpu_subsys_match`, `function change_cpu_under_node`, `function cpu_subsys_online`, `function cpu_hotplug_disable`, `function cpu_subsys_offline`, `function unregister_cpu`, `function cpu_probe_store`, `function cpu_release_store`, `function crash_notes_show`.
- Atlas domain: Driver Families / drivers/base.
- Implementation status: pattern 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.