include/linux/cpumask.h
Source file repositories/reference/linux-study-clean/include/linux/cpumask.h
File Facts
- System
- Linux kernel
- Corpus path
include/linux/cpumask.h- Extension
.h- Size
- 41740 bytes
- Lines
- 1425
- Domain
- Core OS
- Bucket
- Core Kernel Interface
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/atomic.hlinux/bitmap.hlinux/cleanup.hlinux/cpumask_types.hlinux/gfp_types.hlinux/numa.hlinux/sprintf.hlinux/threads.hlinux/types.hvdso/page.hasm/bug.h
Detected Declarations
function set_nr_cpu_idsfunction cpu_max_bits_warnfunction cpumask_checkfunction cpumask_firstfunction cpumask_first_zerofunction cpumask_first_andfunction cpumask_first_andnotfunction cpumask_first_and_andfunction cpumask_lastfunction cpumask_nextfunction cpumask_next_zerofunction cpumask_local_spreadfunction cpumask_any_and_distributefunction cpumask_any_distributefunction cpumask_next_andfunction cpumask_next_andnotfunction cpumask_next_and_wrapfunction cpumask_next_wrapfunction cpumask_randomfunction for_each_cpufunction cpumask_any_and_butfunction cpumask_any_andnot_butfunction cpumask_nthfunction cpumask_nth_andfunction cpumask_nth_and_andnotfunction cpumask_set_cpufunction __cpumask_set_cpufunction cpumask_clear_cpusfunction cpumask_clear_cpufunction __cpumask_clear_cpufunction cpumask_test_cpufunction cpumask_test_and_set_cpufunction cpumask_test_and_clear_cpufunction cpumask_setallfunction cpumask_clearfunction cpumask_andfunction cpumask_orfunction cpumask_weighted_orfunction cpumask_xorfunction cpumask_andnotfunction cpumask_equalfunction cpumask_or_equalfunction cpumask_intersectsfunction cpumask_subsetfunction cpumask_emptyfunction cpumask_fullfunction cpumask_weightfunction cpumask_weight_and
Annotated Snippet
#ifndef __LINUX_CPUMASK_H
#define __LINUX_CPUMASK_H
/*
* Cpumasks provide a bitmap suitable for representing the
* set of CPUs in a system, one bit position per CPU number. In general,
* only nr_cpu_ids (<= NR_CPUS) bits are valid.
*/
#include <linux/atomic.h>
#include <linux/bitmap.h>
#include <linux/cleanup.h>
#include <linux/cpumask_types.h>
#include <linux/gfp_types.h>
#include <linux/numa.h>
#include <linux/sprintf.h>
#include <linux/threads.h>
#include <linux/types.h>
#include <vdso/page.h>
#include <asm/bug.h>
/**
* cpumask_pr_args - printf args to output a cpumask
* @maskp: cpumask to be printed
*
* Can be used to provide arguments for '%*pb[l]' when printing a cpumask.
*/
#define cpumask_pr_args(maskp) nr_cpu_ids, cpumask_bits(maskp)
#if (NR_CPUS == 1) || defined(CONFIG_FORCE_NR_CPUS)
#define nr_cpu_ids ((unsigned int)NR_CPUS)
#else
extern unsigned int nr_cpu_ids;
#endif
static __always_inline void set_nr_cpu_ids(unsigned int nr)
{
#if (NR_CPUS == 1) || defined(CONFIG_FORCE_NR_CPUS)
WARN_ON(nr != nr_cpu_ids);
#else
nr_cpu_ids = nr;
#endif
}
/*
* We have several different "preferred sizes" for the cpumask
* operations, depending on operation.
*
* For example, the bitmap scanning and operating operations have
* optimized routines that work for the single-word case, but only when
* the size is constant. So if NR_CPUS fits in one single word, we are
* better off using that small constant, in order to trigger the
* optimized bit finding. That is 'small_cpumask_size'.
*
* The clearing and copying operations will similarly perform better
* with a constant size, but we limit that size arbitrarily to four
* words. We call this 'large_cpumask_size'.
*
* Finally, some operations just want the exact limit, either because
* they set bits or just don't have any faster fixed-sized versions. We
* call this just 'nr_cpumask_bits'.
*
* Note that these optional constants are always guaranteed to be at
* least as big as 'nr_cpu_ids' itself is, and all our cpumask
* allocations are at least that size (see cpumask_size()). The
* optimization comes from being able to potentially use a compile-time
* constant instead of a run-time generated exact number of CPUs.
*/
#if NR_CPUS <= BITS_PER_LONG
#define small_cpumask_bits ((unsigned int)NR_CPUS)
#define large_cpumask_bits ((unsigned int)NR_CPUS)
#elif NR_CPUS <= 4*BITS_PER_LONG
#define small_cpumask_bits nr_cpu_ids
#define large_cpumask_bits ((unsigned int)NR_CPUS)
#else
#define small_cpumask_bits nr_cpu_ids
#define large_cpumask_bits nr_cpu_ids
#endif
#define nr_cpumask_bits nr_cpu_ids
/*
* The following particular system cpumasks and operations manage
* possible, present, active and online cpus.
*
* cpu_possible_mask- has bit 'cpu' set iff cpu is populatable
* cpu_present_mask - has bit 'cpu' set iff cpu is populated
* cpu_enabled_mask - has bit 'cpu' set iff cpu can be brought online
* cpu_online_mask - has bit 'cpu' set iff cpu available to scheduler
* cpu_active_mask - has bit 'cpu' set iff cpu available to migration
*
Annotation
- Immediate include surface: `linux/atomic.h`, `linux/bitmap.h`, `linux/cleanup.h`, `linux/cpumask_types.h`, `linux/gfp_types.h`, `linux/numa.h`, `linux/sprintf.h`, `linux/threads.h`.
- Detected declarations: `function set_nr_cpu_ids`, `function cpu_max_bits_warn`, `function cpumask_check`, `function cpumask_first`, `function cpumask_first_zero`, `function cpumask_first_and`, `function cpumask_first_andnot`, `function cpumask_first_and_and`, `function cpumask_last`, `function cpumask_next`.
- Atlas domain: Core OS / Core Kernel Interface.
- 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.