kernel/padata.c
Source file repositories/reference/linux-study-clean/kernel/padata.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/padata.c- Extension
.c- Size
- 27771 bytes
- Lines
- 1119
- 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/completion.hlinux/export.hlinux/cpumask.hlinux/err.hlinux/cpu.hlinux/padata.hlinux/mutex.hlinux/sched.hlinux/slab.hlinux/sysfs.hlinux/rcupdate.h
Detected Declarations
struct padata_workstruct padata_mt_job_statestruct padata_sysfs_entryfunction padata_get_pdfunction padata_put_pd_cntfunction padata_put_pdfunction padata_cpu_hashfunction padata_mt_helperfunction padata_work_alloc_mtfunction padata_work_freefunction padata_works_freefunction padata_parallel_workerfunction padata_do_parallelfunction padata_reorderfunction padata_serial_workerfunction padata_do_serialfunction padata_setup_cpumasksfunction padata_mt_helperfunction padata_do_multithreadedfunction list_for_each_entryfunction padata_init_squeuesfunction for_each_cpufunction padata_init_reorder_listfunction for_each_cpufunction padata_free_pdfunction __padata_startfunction __padata_stopfunction padata_replace_onefunction padata_replacefunction list_for_each_entryfunction padata_validate_cpumaskfunction __padata_set_cpumasksfunction padata_set_cpumaskfunction pinst_has_cpufunction padata_cpu_onlinefunction padata_cpu_offlinefunction __padata_freefunction padata_sysfs_releasefunction show_cpumaskfunction store_cpumaskfunction padata_sysfs_showfunction padata_sysfs_storefunction padata_freefunction padata_free_shellfunction padata_initexport padata_do_parallelexport padata_do_serialexport padata_set_cpumask
Annotated Snippet
struct padata_work {
struct work_struct pw_work;
struct list_head pw_list; /* padata_free_works linkage */
void *pw_data;
};
static DEFINE_SPINLOCK(padata_works_lock);
static struct padata_work *padata_works;
static LIST_HEAD(padata_free_works);
struct padata_mt_job_state {
spinlock_t lock;
struct completion completion;
struct padata_mt_job *job;
int nworks;
int nworks_fini;
unsigned long chunk_size;
};
static void padata_free_pd(struct parallel_data *pd);
static void __init padata_mt_helper(struct work_struct *work);
static inline void padata_get_pd(struct parallel_data *pd)
{
refcount_inc(&pd->refcnt);
}
static inline void padata_put_pd_cnt(struct parallel_data *pd, int cnt)
{
if (refcount_sub_and_test(cnt, &pd->refcnt))
padata_free_pd(pd);
}
static inline void padata_put_pd(struct parallel_data *pd)
{
padata_put_pd_cnt(pd, 1);
}
static int padata_cpu_hash(struct parallel_data *pd, unsigned int seq_nr)
{
/*
* Hash the sequence numbers to the cpus by taking
* seq_nr mod. number of cpus in use.
*/
int cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
return cpumask_nth(cpu_index, pd->cpumask.pcpu);
}
static struct padata_work *padata_work_alloc(void)
{
struct padata_work *pw;
lockdep_assert_held(&padata_works_lock);
if (list_empty(&padata_free_works))
return NULL; /* No more work items allowed to be queued. */
pw = list_first_entry(&padata_free_works, struct padata_work, pw_list);
list_del(&pw->pw_list);
return pw;
}
/*
* This function is marked __ref because this function may be optimized in such
* a way that it directly refers to work_fn's address, which causes modpost to
* complain when work_fn is marked __init. This scenario was observed with clang
* LTO, where padata_work_init() was optimized to refer directly to
* padata_mt_helper() because the calls to padata_work_init() with other work_fn
* values were eliminated or inlined.
*/
static void __ref padata_work_init(struct padata_work *pw, work_func_t work_fn,
void *data, int flags)
{
if (flags & PADATA_WORK_ONSTACK)
INIT_WORK_ONSTACK(&pw->pw_work, work_fn);
else
INIT_WORK(&pw->pw_work, work_fn);
pw->pw_data = data;
}
static int __init padata_work_alloc_mt(int nworks, void *data,
struct list_head *head)
{
int i;
spin_lock_bh(&padata_works_lock);
/* Start at 1 because the current task participates in the job. */
for (i = 1; i < nworks; ++i) {
struct padata_work *pw = padata_work_alloc();
Annotation
- Immediate include surface: `linux/completion.h`, `linux/export.h`, `linux/cpumask.h`, `linux/err.h`, `linux/cpu.h`, `linux/padata.h`, `linux/mutex.h`, `linux/sched.h`.
- Detected declarations: `struct padata_work`, `struct padata_mt_job_state`, `struct padata_sysfs_entry`, `function padata_get_pd`, `function padata_put_pd_cnt`, `function padata_put_pd`, `function padata_cpu_hash`, `function padata_mt_helper`, `function padata_work_alloc_mt`, `function padata_work_free`.
- 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.