kernel/cgroup/cpuset.c
Source file repositories/reference/linux-study-clean/kernel/cgroup/cpuset.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/cgroup/cpuset.c- Extension
.c- Size
- 128811 bytes
- Lines
- 4398
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: implementation source
- Status
- source 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.
- 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
cpuset-internal.hlinux/init.hlinux/interrupt.hlinux/kernel.hlinux/mempolicy.hlinux/mm.hlinux/memory.hlinux/rcupdate.hlinux/sched.hlinux/sched/deadline.hlinux/sched/mm.hlinux/sched/task.hlinux/security.hlinux/oom.hlinux/sched/isolation.hlinux/wait.hlinux/workqueue.hlinux/task_work.h
Detected Declarations
struct tmpmasksstruct cpuset_migrate_mm_workenum partition_cmdfunction inc_dl_tasks_csfunction dec_dl_tasks_csfunction is_partition_validfunction is_partition_invalidfunction cs_is_memberfunction make_partition_invalidfunction notify_partition_changefunction cpuset_lockfunction cpuset_unlockfunction lockdep_assert_cpuset_lock_heldfunction lockfunction cpuset_full_unlockfunction lockdep_is_cpuset_heldfunction cpuset_callback_lock_irqfunction cpuset_callback_unlock_irqfunction check_insane_mems_configfunction dec_attach_in_progress_lockedfunction dec_attach_in_progressfunction cpuset_v2function is_in_v2_modefunction partition_is_populatedfunction guarantee_active_cpusfunction guarantee_online_memsfunction alloc_cpumasksfunction alloc_tmpmasksfunction free_tmpmasksfunction free_cpusetfunction xcpus_emptyfunction cpusets_are_exclusivefunction cpuset1_cpus_excl_conflictfunction mems_excl_conflictfunction validate_changefunction generate_sched_domainsfunction dl_update_tasks_root_domainfunction dl_rebuild_rd_accountingfunction for_each_possible_cpufunction cpuset_for_each_descendant_prefunction rebuild_sched_domains_lockedfunction rebuild_sched_domains_lockedfunction rebuild_sched_domainsfunction cpuset_reset_sched_domainsfunction task_cpu_possible_maskfunction compute_effective_cpumaskfunction update_partition_exclusive_flagfunction rebuild_sched_domains_locked
Annotated Snippet
struct tmpmasks {
cpumask_var_t addmask, delmask; /* For partition root */
cpumask_var_t new_cpus; /* For update_cpumasks_hier() */
};
void inc_dl_tasks_cs(struct task_struct *p)
{
struct cpuset *cs = task_cs(p);
cs->nr_deadline_tasks++;
}
void dec_dl_tasks_cs(struct task_struct *p)
{
struct cpuset *cs = task_cs(p);
cs->nr_deadline_tasks--;
}
static inline bool is_partition_valid(const struct cpuset *cs)
{
return cs->partition_root_state > 0;
}
static inline bool is_partition_invalid(const struct cpuset *cs)
{
return cs->partition_root_state < 0;
}
static inline bool cs_is_member(const struct cpuset *cs)
{
return cs->partition_root_state == PRS_MEMBER;
}
/*
* Callers should hold callback_lock to modify partition_root_state.
*/
static inline void make_partition_invalid(struct cpuset *cs)
{
if (cs->partition_root_state > 0)
cs->partition_root_state = -cs->partition_root_state;
}
/*
* Send notification event of whenever partition_root_state changes.
*/
static inline void notify_partition_change(struct cpuset *cs, int old_prs)
{
if (old_prs == cs->partition_root_state)
return;
cgroup_file_notify(&cs->partition_file);
/* Reset prs_err if not invalid */
if (is_partition_valid(cs))
WRITE_ONCE(cs->prs_err, PERR_NONE);
}
/*
* The top_cpuset is always synchronized to cpu_active_mask and we should avoid
* using cpu_online_mask as much as possible. An active CPU is always an online
* CPU, but not vice versa. cpu_active_mask and cpu_online_mask can differ
* during hotplug operations. A CPU is marked active at the last stage of CPU
* bringup (CPUHP_AP_ACTIVE). It is also the stage where cpuset hotplug code
* will be called to update the sched domains so that the scheduler can move
* a normal task to a newly active CPU or remove tasks away from a newly
* inactivated CPU. The online bit is set much earlier in the CPU bringup
* process and cleared much later in CPU teardown.
*
* If cpu_online_mask is used while a hotunplug operation is happening in
* parallel, we may leave an offline CPU in cpu_allowed or some other masks.
*/
struct cpuset top_cpuset = {
.flags = BIT(CS_CPU_EXCLUSIVE) |
BIT(CS_MEM_EXCLUSIVE) | BIT(CS_SCHED_LOAD_BALANCE),
.partition_root_state = PRS_ROOT,
.dl_bw_cpu = -1,
};
/**
* cpuset_lock - Acquire the global cpuset mutex
*
* This locks the global cpuset mutex to prevent modifications to cpuset
* hierarchy and configurations. This helper is not enough to make modification.
*/
void cpuset_lock(void)
{
mutex_lock(&cpuset_mutex);
}
void cpuset_unlock(void)
Annotation
- Immediate include surface: `cpuset-internal.h`, `linux/init.h`, `linux/interrupt.h`, `linux/kernel.h`, `linux/mempolicy.h`, `linux/mm.h`, `linux/memory.h`, `linux/rcupdate.h`.
- Detected declarations: `struct tmpmasks`, `struct cpuset_migrate_mm_work`, `enum partition_cmd`, `function inc_dl_tasks_cs`, `function dec_dl_tasks_cs`, `function is_partition_valid`, `function is_partition_invalid`, `function cs_is_member`, `function make_partition_invalid`, `function notify_partition_change`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: source 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.