kernel/cpu.c
Source file repositories/reference/linux-study-clean/kernel/cpu.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/cpu.c- Extension
.c- Size
- 83272 bytes
- Lines
- 3344
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/sched/mm.hlinux/proc_fs.hlinux/smp.hlinux/init.hlinux/notifier.hlinux/sched/signal.hlinux/sched/hotplug.hlinux/sched/isolation.hlinux/sched/task.hlinux/sched/smt.hlinux/unistd.hlinux/cpu.hlinux/oom.hlinux/rcupdate.hlinux/delay.hlinux/export.hlinux/bug.hlinux/kthread.hlinux/stop_machine.hlinux/mutex.hlinux/gfp.hlinux/suspend.hlinux/lockdep.hlinux/tick.hlinux/irq.hlinux/nmi.hlinux/smpboot.hlinux/relay.hlinux/slab.hlinux/scs.hlinux/percpu-rwsem.hlinux/cpuset.h
Detected Declarations
struct cpuhp_cpu_statestruct cpuhp_stepenum cpuhp_sync_stateenum cpu_mitigationsfunction cpuhp_lock_acquirefunction cpuhp_lock_releasefunction cpuhp_lock_acquirefunction cpuhp_step_emptyfunction cpuhp_invoke_callbackfunction hlist_for_eachfunction cpuhp_is_atomic_statefunction cpuhp_is_ap_statefunction wait_for_ap_threadfunction complete_ap_threadfunction cpuhp_ap_update_sync_statefunction arch_cpuhp_sync_state_pollfunction cpuhp_wait_for_sync_statefunction cpuhp_ap_update_sync_statefunction arch_cpuhp_cleanup_dead_cpufunction cpuhp_bp_sync_deadfunction cpuhp_can_boot_apfunction arch_cpuhp_cleanup_kick_cpufunction cpuhp_bp_sync_alivefunction cpuhp_can_boot_apfunction APIsfunction cpu_maps_update_donefunction cpus_read_lockfunction cpus_read_trylockfunction cpus_read_unlockfunction cpus_write_lockfunction cpus_write_unlockfunction lockdep_assert_cpus_heldfunction lockdep_is_cpus_heldfunction lockdep_is_cpus_write_heldfunction lockdep_acquire_cpus_lockfunction lockdep_release_cpus_lockfunction cpu_hotplug_disable_offliningfunction completefunction __cpu_hotplug_enablefunction cpu_hotplug_enablefunction lockdep_acquire_cpus_lockfunction cpu_smt_disablefunction cpu_smt_set_num_threadsfunction smt_cmdline_disablefunction cpu_smt_thread_allowedfunction cpu_bootablefunction cpu_smt_possiblefunction cpu_bootable
Annotated Snippet
core_initcall(alloc_frozen_cpus);
/*
* When callbacks for CPU hotplug notifications are being executed, we must
* ensure that the state of the system with respect to the tasks being frozen
* or not, as reported by the notification, remains unchanged *throughout the
* duration* of the execution of the callbacks.
* Hence we need to prevent the freezer from racing with regular CPU hotplug.
*
* This synchronization is implemented by mutually excluding regular CPU
* hotplug and Suspend/Hibernate call paths by hooking onto the Suspend/
* Hibernate notifications.
*/
static int
cpu_hotplug_pm_callback(struct notifier_block *nb,
unsigned long action, void *ptr)
{
switch (action) {
case PM_SUSPEND_PREPARE:
case PM_HIBERNATION_PREPARE:
cpu_hotplug_disable();
break;
case PM_POST_SUSPEND:
case PM_POST_HIBERNATION:
cpu_hotplug_enable();
break;
default:
return NOTIFY_DONE;
}
return NOTIFY_OK;
}
static int __init cpu_hotplug_pm_sync_init(void)
{
/*
* cpu_hotplug_pm_callback has higher priority than x86
* bsp_pm_callback which depends on cpu_hotplug_pm_callback
* to disable cpu hotplug to avoid cpu hotplug race.
*/
pm_notifier(cpu_hotplug_pm_callback, 0);
return 0;
}
core_initcall(cpu_hotplug_pm_sync_init);
#endif /* CONFIG_PM_SLEEP_SMP */
int __boot_cpu_id;
#endif /* CONFIG_SMP */
/* Boot processor state steps */
static struct cpuhp_step cpuhp_hp_states[] = {
[CPUHP_OFFLINE] = {
.name = "offline",
.startup.single = NULL,
.teardown.single = NULL,
},
#ifdef CONFIG_SMP
[CPUHP_CREATE_THREADS]= {
.name = "threads:prepare",
.startup.single = smpboot_create_threads,
.teardown.single = NULL,
.cant_stop = true,
},
[CPUHP_RANDOM_PREPARE] = {
.name = "random:prepare",
.startup.single = random_prepare_cpu,
.teardown.single = NULL,
},
[CPUHP_WORKQUEUE_PREP] = {
.name = "workqueue:prepare",
.startup.single = workqueue_prepare_cpu,
.teardown.single = NULL,
},
[CPUHP_HRTIMERS_PREPARE] = {
.name = "hrtimers:prepare",
.startup.single = hrtimers_prepare_cpu,
.teardown.single = NULL,
},
[CPUHP_SMPCFD_PREPARE] = {
.name = "smpcfd:prepare",
.startup.single = smpcfd_prepare_cpu,
.teardown.single = smpcfd_dead_cpu,
},
[CPUHP_RELAY_PREPARE] = {
Annotation
- Immediate include surface: `linux/sched/mm.h`, `linux/proc_fs.h`, `linux/smp.h`, `linux/init.h`, `linux/notifier.h`, `linux/sched/signal.h`, `linux/sched/hotplug.h`, `linux/sched/isolation.h`.
- Detected declarations: `struct cpuhp_cpu_state`, `struct cpuhp_step`, `enum cpuhp_sync_state`, `enum cpu_mitigations`, `function cpuhp_lock_acquire`, `function cpuhp_lock_release`, `function cpuhp_lock_acquire`, `function cpuhp_step_empty`, `function cpuhp_invoke_callback`, `function hlist_for_each`.
- 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.