kernel/bpf/cpumask.c
Source file repositories/reference/linux-study-clean/kernel/bpf/cpumask.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/bpf/cpumask.c- Extension
.c- Size
- 16449 bytes
- Lines
- 535
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bpf.hlinux/bpf_mem_alloc.hlinux/btf.hlinux/btf_ids.hlinux/cpumask.h
Detected Declarations
struct bpf_cpumaskfunction cpu_validfunction bpf_cpumask_createfunction bpf_cpumask_acquirefunction bpf_cpumask_releasefunction bpf_cpumask_release_dtorfunction bpf_cpumask_firstfunction bpf_cpumask_first_zerofunction bpf_cpumask_first_andfunction bpf_cpumask_set_cpufunction bpf_cpumask_clear_cpufunction bpf_cpumask_test_cpufunction bpf_cpumask_test_and_set_cpufunction bpf_cpumask_test_and_clear_cpufunction bpf_cpumask_setallfunction bpf_cpumask_clearfunction bpf_cpumask_andfunction bpf_cpumask_orfunction bpf_cpumask_xorfunction bpf_cpumask_equalfunction bpf_cpumask_intersectsfunction bpf_cpumask_subsetfunction bpf_cpumask_emptyfunction bpf_cpumask_fullfunction bpf_cpumask_copyfunction bpf_cpumask_any_distributefunction bpf_cpumask_any_and_distributefunction bpf_cpumask_weightfunction bpf_cpumask_populatefunction cpumask_kfunc_init
Annotated Snippet
struct bpf_cpumask {
cpumask_t cpumask;
refcount_t usage;
};
static struct bpf_mem_alloc bpf_cpumask_ma;
static bool cpu_valid(u32 cpu)
{
return cpu < nr_cpu_ids;
}
__bpf_kfunc_start_defs();
/**
* bpf_cpumask_create() - Create a mutable BPF cpumask.
*
* Allocates a cpumask that can be queried, mutated, acquired, and released by
* a BPF program. The cpumask returned by this function must either be embedded
* in a map as a kptr, or freed with bpf_cpumask_release().
*
* bpf_cpumask_create() allocates memory using the BPF memory allocator, and
* will not block. It may return NULL if no memory is available.
*
* Return:
* * A pointer to a new struct bpf_cpumask instance on success.
* * NULL if the BPF memory allocator is out of memory.
*/
__bpf_kfunc struct bpf_cpumask *bpf_cpumask_create(void)
{
struct bpf_cpumask *cpumask;
/* cpumask must be the first element so struct bpf_cpumask be cast to struct cpumask. */
BUILD_BUG_ON(offsetof(struct bpf_cpumask, cpumask) != 0);
cpumask = bpf_mem_cache_alloc(&bpf_cpumask_ma);
if (!cpumask)
return NULL;
memset(cpumask, 0, sizeof(*cpumask));
refcount_set(&cpumask->usage, 1);
return cpumask;
}
/**
* bpf_cpumask_acquire() - Acquire a reference to a BPF cpumask.
* @cpumask: The BPF cpumask being acquired. The cpumask must be a trusted
* pointer.
*
* Acquires a reference to a BPF cpumask. The cpumask returned by this function
* must either be embedded in a map as a kptr, or freed with
* bpf_cpumask_release().
*
* Return:
* * The struct bpf_cpumask pointer passed to the function.
*
*/
__bpf_kfunc struct bpf_cpumask *bpf_cpumask_acquire(struct bpf_cpumask *cpumask)
{
refcount_inc(&cpumask->usage);
return cpumask;
}
/**
* bpf_cpumask_release() - Release a previously acquired BPF cpumask.
* @cpumask: The cpumask being released.
*
* Releases a previously acquired reference to a BPF cpumask. When the final
* reference of the BPF cpumask has been released, it is subsequently freed in
* an RCU callback in the BPF memory allocator.
*/
__bpf_kfunc void bpf_cpumask_release(struct bpf_cpumask *cpumask)
{
if (!refcount_dec_and_test(&cpumask->usage))
return;
bpf_mem_cache_free_rcu(&bpf_cpumask_ma, cpumask);
}
__bpf_kfunc void bpf_cpumask_release_dtor(void *cpumask)
{
bpf_cpumask_release(cpumask);
}
CFI_NOSEAL(bpf_cpumask_release_dtor);
/**
* bpf_cpumask_first() - Get the index of the first nonzero bit in the cpumask.
* @cpumask: The cpumask being queried.
*
Annotation
- Immediate include surface: `linux/bpf.h`, `linux/bpf_mem_alloc.h`, `linux/btf.h`, `linux/btf_ids.h`, `linux/cpumask.h`.
- Detected declarations: `struct bpf_cpumask`, `function cpu_valid`, `function bpf_cpumask_create`, `function bpf_cpumask_acquire`, `function bpf_cpumask_release`, `function bpf_cpumask_release_dtor`, `function bpf_cpumask_first`, `function bpf_cpumask_first_zero`, `function bpf_cpumask_first_and`, `function bpf_cpumask_set_cpu`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: source implementation candidate.
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.