kernel/stop_machine.c
Source file repositories/reference/linux-study-clean/kernel/stop_machine.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/stop_machine.c- Extension
.c- Size
- 18855 bytes
- Lines
- 713
- 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/compiler.hlinux/completion.hlinux/cpu.hlinux/init.hlinux/kthread.hlinux/export.hlinux/percpu.hlinux/sched.hlinux/stop_machine.hlinux/interrupt.hlinux/kallsyms.hlinux/smpboot.hlinux/atomic.hlinux/nmi.hlinux/sched/wake_q.h
Detected Declarations
struct cpu_stop_donestruct cpu_stopperstruct multi_stop_dataenum multi_stop_statefunction print_stop_infofunction cpu_stop_init_donefunction cpu_stop_signal_donefunction __cpu_stop_queue_workfunction cpu_stop_queue_workfunction stop_one_cpufunction set_statefunction ack_statefunction stop_machine_yieldfunction multi_cpu_stopfunction cpu_stop_queue_two_worksfunction __stop_cpusfunction stop_two_cpusfunction stop_one_cpufunction queue_stop_cpus_workfunction __stop_cpusfunction stop_cpusfunction cpu_stop_should_runfunction cpu_stopper_threadfunction stop_machine_parkfunction cpu_stop_createfunction cpu_stop_parkfunction stop_machine_unparkfunction cpu_stop_initfunction for_each_possible_cpufunction stop_machine_cpuslockedfunction stop_machinefunction stop_core_cpuslockedfunction stop_machineexport stop_machineexport stop_core_cpuslocked
Annotated Snippet
struct cpu_stop_done {
atomic_t nr_todo; /* nr left to execute */
int ret; /* collected return value */
struct completion completion; /* fired if nr_todo reaches 0 */
};
/* the actual stopper, one per every possible cpu, enabled on online cpus */
struct cpu_stopper {
struct task_struct *thread;
raw_spinlock_t lock;
bool enabled; /* is this stopper enabled? */
struct list_head works; /* list of pending works */
struct cpu_stop_work stop_work; /* for stop_cpus */
unsigned long caller;
cpu_stop_fn_t fn;
};
static DEFINE_PER_CPU(struct cpu_stopper, cpu_stopper);
static bool stop_machine_initialized = false;
void print_stop_info(const char *log_lvl, struct task_struct *task)
{
/*
* If @task is a stopper task, it cannot migrate and task_cpu() is
* stable.
*/
struct cpu_stopper *stopper = per_cpu_ptr(&cpu_stopper, task_cpu(task));
if (task != stopper->thread)
return;
printk("%sStopper: %pS <- %pS\n", log_lvl, stopper->fn, (void *)stopper->caller);
}
/* static data for stop_cpus */
static DEFINE_MUTEX(stop_cpus_mutex);
static bool stop_cpus_in_progress;
static void cpu_stop_init_done(struct cpu_stop_done *done, unsigned int nr_todo)
{
memset(done, 0, sizeof(*done));
atomic_set(&done->nr_todo, nr_todo);
init_completion(&done->completion);
}
/* signal completion unless @done is NULL */
static void cpu_stop_signal_done(struct cpu_stop_done *done)
{
if (atomic_dec_and_test(&done->nr_todo))
complete(&done->completion);
}
static void __cpu_stop_queue_work(struct cpu_stopper *stopper,
struct cpu_stop_work *work)
{
list_add_tail(&work->list, &stopper->works);
}
/* queue @work to @stopper. if offline, @work is completed immediately */
static bool cpu_stop_queue_work(unsigned int cpu, struct cpu_stop_work *work)
{
struct cpu_stopper *stopper = &per_cpu(cpu_stopper, cpu);
unsigned long flags;
bool enabled;
preempt_disable();
raw_spin_lock_irqsave(&stopper->lock, flags);
enabled = stopper->enabled;
if (enabled)
__cpu_stop_queue_work(stopper, work);
else if (work->done)
cpu_stop_signal_done(work->done);
raw_spin_unlock_irqrestore(&stopper->lock, flags);
if (enabled)
wake_up_process(stopper->thread);
preempt_enable();
return enabled;
}
/**
* stop_one_cpu - stop a cpu
* @cpu: cpu to stop
* @fn: function to execute
* @arg: argument to @fn
*
* Execute @fn(@arg) on @cpu. @fn is run in a process context with
Annotation
- Immediate include surface: `linux/compiler.h`, `linux/completion.h`, `linux/cpu.h`, `linux/init.h`, `linux/kthread.h`, `linux/export.h`, `linux/percpu.h`, `linux/sched.h`.
- Detected declarations: `struct cpu_stop_done`, `struct cpu_stopper`, `struct multi_stop_data`, `enum multi_stop_state`, `function print_stop_info`, `function cpu_stop_init_done`, `function cpu_stop_signal_done`, `function __cpu_stop_queue_work`, `function cpu_stop_queue_work`, `function stop_one_cpu`.
- 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.