kernel/smpboot.c
Source file repositories/reference/linux-study-clean/kernel/smpboot.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/smpboot.c- Extension
.c- Size
- 7384 bytes
- Lines
- 323
- 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/cpu.hlinux/err.hlinux/smp.hlinux/delay.hlinux/init.hlinux/list.hlinux/slab.hlinux/sched.hlinux/sched/task.hlinux/export.hlinux/percpu.hlinux/kthread.hlinux/smpboot.hsmpboot.h
Detected Declarations
struct smpboot_thread_datafunction idle_thread_set_boot_cpufunction idle_initfunction idle_threads_initfunction for_each_possible_cpufunction smpboot_thread_fnfunction __smpboot_create_threadfunction smpboot_create_threadsfunction smpboot_unpark_threadfunction smpboot_unpark_threadsfunction smpboot_park_threadfunction smpboot_park_threadsfunction smpboot_destroy_threadsfunction smpboot_register_percpu_threadfunction smpboot_unregister_percpu_threadexport smpboot_register_percpu_threadexport smpboot_unregister_percpu_thread
Annotated Snippet
struct smpboot_thread_data {
unsigned int cpu;
unsigned int status;
struct smp_hotplug_thread *ht;
};
enum {
HP_THREAD_NONE = 0,
HP_THREAD_ACTIVE,
HP_THREAD_PARKED,
};
/**
* smpboot_thread_fn - percpu hotplug thread loop function
* @data: thread data pointer
*
* Checks for thread stop and park conditions. Calls the necessary
* setup, cleanup, park and unpark functions for the registered
* thread.
*
* Returns 1 when the thread should exit, 0 otherwise.
*/
static int smpboot_thread_fn(void *data)
{
struct smpboot_thread_data *td = data;
struct smp_hotplug_thread *ht = td->ht;
while (1) {
set_current_state(TASK_INTERRUPTIBLE);
preempt_disable();
if (kthread_should_stop()) {
__set_current_state(TASK_RUNNING);
preempt_enable();
/* cleanup must mirror setup */
if (ht->cleanup && td->status != HP_THREAD_NONE)
ht->cleanup(td->cpu, cpu_online(td->cpu));
kfree(td);
return 0;
}
if (kthread_should_park()) {
__set_current_state(TASK_RUNNING);
preempt_enable();
if (ht->park && td->status == HP_THREAD_ACTIVE) {
BUG_ON(td->cpu != smp_processor_id());
ht->park(td->cpu);
td->status = HP_THREAD_PARKED;
}
kthread_parkme();
/* We might have been woken for stop */
continue;
}
BUG_ON(td->cpu != smp_processor_id());
/* Check for state change setup */
switch (td->status) {
case HP_THREAD_NONE:
__set_current_state(TASK_RUNNING);
preempt_enable();
if (ht->setup)
ht->setup(td->cpu);
td->status = HP_THREAD_ACTIVE;
continue;
case HP_THREAD_PARKED:
__set_current_state(TASK_RUNNING);
preempt_enable();
if (ht->unpark)
ht->unpark(td->cpu);
td->status = HP_THREAD_ACTIVE;
continue;
}
if (!ht->thread_should_run(td->cpu)) {
preempt_enable_no_resched();
schedule();
} else {
__set_current_state(TASK_RUNNING);
preempt_enable();
ht->thread_fn(td->cpu);
}
}
}
static int
__smpboot_create_thread(struct smp_hotplug_thread *ht, unsigned int cpu)
{
struct task_struct *tsk = *per_cpu_ptr(ht->store, cpu);
struct smpboot_thread_data *td;
Annotation
- Immediate include surface: `linux/cpu.h`, `linux/err.h`, `linux/smp.h`, `linux/delay.h`, `linux/init.h`, `linux/list.h`, `linux/slab.h`, `linux/sched.h`.
- Detected declarations: `struct smpboot_thread_data`, `function idle_thread_set_boot_cpu`, `function idle_init`, `function idle_threads_init`, `function for_each_possible_cpu`, `function smpboot_thread_fn`, `function __smpboot_create_thread`, `function smpboot_create_threads`, `function smpboot_unpark_thread`, `function smpboot_unpark_threads`.
- 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.