kernel/workqueue.c
Source file repositories/reference/linux-study-clean/kernel/workqueue.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/workqueue.c- Extension
.c- Size
- 245647 bytes
- Lines
- 8476
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/export.hlinux/kernel.hlinux/sched.hlinux/init.hlinux/interrupt.hlinux/signal.hlinux/completion.hlinux/workqueue.hlinux/slab.hlinux/cpu.hlinux/notifier.hlinux/kthread.hlinux/hardirq.hlinux/mempolicy.hlinux/freezer.hlinux/debug_locks.hlinux/device/devres.hlinux/lockdep.hlinux/idr.hlinux/jhash.hlinux/hashtable.hlinux/rculist.hlinux/nodemask.hlinux/moduleparam.hlinux/uaccess.hlinux/sched/isolation.hlinux/sched/debug.hlinux/nmi.hlinux/kvm_para.hlinux/delay.hlinux/irq_work.hworkqueue_internal.h
Detected Declarations
struct llc_shard_layoutstruct worker_poolstruct pool_workqueuestruct wq_flusherstruct wq_devicestruct wq_node_nr_activestruct workqueue_structstruct wq_pod_typestruct work_offq_datastruct wci_entstruct wq_drain_dead_softirq_workstruct wq_barrierstruct apply_wqattrs_ctxstruct pr_cont_work_structstruct work_for_cpustruct wq_deviceenum worker_pool_flagsenum worker_flagsenum work_cancel_flagsenum wq_internal_constsenum pool_workqueue_statsfunction work_is_static_objectfunction work_fixup_initfunction work_fixup_freefunction debug_work_activatefunction debug_work_deactivatefunction __init_workfunction destroy_work_on_stackfunction destroy_delayed_work_on_stackfunction debug_work_activatefunction unbound_pwq_slotfunction work_color_to_flagsfunction get_work_colorfunction work_next_colorfunction pool_offq_flagsfunction set_work_pwqfunction set_work_pwqfunction set_work_pool_and_keep_pendingfunction set_work_pool_and_clear_pendingfunction queue_work_onfunction rcu_read_lockfunction shift_and_maskfunction work_offqd_unpackfunction work_offqd_pack_flagsfunction need_more_workerfunction may_start_workingfunction keep_workingfunction need_to_create_worker
Annotated Snippet
static const struct bus_type wq_subsys = {
.name = "workqueue",
.dev_groups = wq_sysfs_groups,
};
/**
* workqueue_set_unbound_cpumask - Set the low-level unbound cpumask
* @cpumask: the cpumask to set
*
* The low-level workqueues cpumask is a global cpumask that limits
* the affinity of all unbound workqueues. This function check the @cpumask
* and apply it to all unbound workqueues and updates all pwqs of them.
*
* Return: 0 - Success
* -EINVAL - Invalid @cpumask
* -ENOMEM - Failed to allocate memory for attrs or pwqs.
*/
static int workqueue_set_unbound_cpumask(cpumask_var_t cpumask)
{
int ret = -EINVAL;
/*
* Not excluding isolated cpus on purpose.
* If the user wishes to include them, we allow that.
*/
cpumask_and(cpumask, cpumask, cpu_possible_mask);
if (!cpumask_empty(cpumask)) {
ret = 0;
mutex_lock(&wq_pool_mutex);
if (!cpumask_equal(cpumask, wq_unbound_cpumask))
ret = workqueue_apply_unbound_cpumask(cpumask);
if (!ret)
cpumask_copy(wq_requested_unbound_cpumask, cpumask);
mutex_unlock(&wq_pool_mutex);
}
return ret;
}
static ssize_t __wq_cpumask_show(struct device *dev,
struct device_attribute *attr, char *buf, cpumask_var_t mask)
{
int written;
mutex_lock(&wq_pool_mutex);
written = scnprintf(buf, PAGE_SIZE, "%*pb\n", cpumask_pr_args(mask));
mutex_unlock(&wq_pool_mutex);
return written;
}
static ssize_t cpumask_requested_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
return __wq_cpumask_show(dev, attr, buf, wq_requested_unbound_cpumask);
}
static DEVICE_ATTR_RO(cpumask_requested);
static ssize_t cpumask_isolated_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
return __wq_cpumask_show(dev, attr, buf, wq_isolated_cpumask);
}
static DEVICE_ATTR_RO(cpumask_isolated);
static ssize_t cpumask_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
return __wq_cpumask_show(dev, attr, buf, wq_unbound_cpumask);
}
static ssize_t cpumask_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
cpumask_var_t cpumask;
int ret;
if (!zalloc_cpumask_var(&cpumask, GFP_KERNEL))
return -ENOMEM;
ret = cpumask_parse(buf, cpumask);
if (!ret)
ret = workqueue_set_unbound_cpumask(cpumask);
free_cpumask_var(cpumask);
return ret ? ret : count;
}
static DEVICE_ATTR_RW(cpumask);
static struct attribute *wq_sysfs_cpumask_attrs[] = {
Annotation
- Immediate include surface: `linux/export.h`, `linux/kernel.h`, `linux/sched.h`, `linux/init.h`, `linux/interrupt.h`, `linux/signal.h`, `linux/completion.h`, `linux/workqueue.h`.
- Detected declarations: `struct llc_shard_layout`, `struct worker_pool`, `struct pool_workqueue`, `struct wq_flusher`, `struct wq_device`, `struct wq_node_nr_active`, `struct workqueue_struct`, `struct wq_pod_type`, `struct work_offq_data`, `struct wci_ent`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: pattern 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.