tools/sched_ext/scx_sdt.bpf.c
Source file repositories/reference/linux-study-clean/tools/sched_ext/scx_sdt.bpf.c
File Facts
- System
- Linux kernel
- Corpus path
tools/sched_ext/scx_sdt.bpf.c- Extension
.c- Size
- 16091 bytes
- Lines
- 718
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- 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
scx/common.bpf.hscx/bpf_arena_common.bpf.hscx_sdt.h
Detected Declarations
struct scx_task_map_valfunction scx_arena_subprog_initfunction pool_set_sizefunction scx_alloc_initfunction set_idx_statefunction mark_nodes_availfunction scx_alloc_free_idxfunction ffsfunction chunk_find_emptyfunction desc_find_emptyfunction scx_task_initfunction scx_task_freefunction scx_stat_global_updatefunction BPF_STRUCT_OPSfunction BPF_STRUCT_OPSfunction BPF_STRUCT_OPSfunction BPF_STRUCT_OPS_SLEEPABLEfunction BPF_STRUCT_OPSfunction BPF_STRUCT_OPS_SLEEPABLEfunction BPF_STRUCT_OPS
Annotated Snippet
struct scx_task_map_val {
union sdt_id tid;
__u64 tptr;
struct sdt_data __arena *data;
};
struct {
__uint(type, BPF_MAP_TYPE_TASK_STORAGE);
__uint(map_flags, BPF_F_NO_PREALLOC);
__type(key, int);
__type(value, struct scx_task_map_val);
} scx_task_map SEC(".maps");
static struct scx_allocator scx_task_allocator;
__hidden
void __arena *scx_task_alloc(struct task_struct *p)
{
struct sdt_data __arena *data = NULL;
struct scx_task_map_val *mval;
mval = bpf_task_storage_get(&scx_task_map, p, 0,
BPF_LOCAL_STORAGE_GET_F_CREATE);
if (!mval)
return NULL;
data = scx_alloc(&scx_task_allocator);
if (unlikely(!data))
return NULL;
mval->tid = data->tid;
mval->tptr = (__u64) p;
mval->data = data;
return (void __arena *)data->payload;
}
__hidden
int scx_task_init(__u64 data_size)
{
return scx_alloc_init(&scx_task_allocator, data_size);
}
__hidden
void __arena *scx_task_data(struct task_struct *p)
{
struct sdt_data __arena *data;
struct scx_task_map_val *mval;
scx_arena_subprog_init();
mval = bpf_task_storage_get(&scx_task_map, p, 0, 0);
if (!mval)
return NULL;
data = mval->data;
return (void __arena *)data->payload;
}
__hidden
void scx_task_free(struct task_struct *p)
{
struct scx_task_map_val *mval;
scx_arena_subprog_init();
mval = bpf_task_storage_get(&scx_task_map, p, 0, 0);
if (!mval)
return;
bpf_spin_lock(&alloc_lock);
scx_alloc_free_idx(&scx_task_allocator, mval->tid.idx);
bpf_spin_unlock(&alloc_lock);
bpf_task_storage_delete(&scx_task_map, p);
}
static inline void
scx_stat_global_update(struct scx_stats __arena *stats)
{
cast_kern(stats);
__sync_fetch_and_add(&stat_enqueue, stats->enqueue);
__sync_fetch_and_add(&stat_init, stats->init);
__sync_fetch_and_add(&stat_exit, stats->exit);
__sync_fetch_and_add(&stat_select_idle_cpu, stats->select_idle_cpu);
__sync_fetch_and_add(&stat_select_busy_cpu, stats->select_busy_cpu);
}
s32 BPF_STRUCT_OPS(sdt_select_cpu, struct task_struct *p, s32 prev_cpu, u64 wake_flags)
Annotation
- Immediate include surface: `scx/common.bpf.h`, `scx/bpf_arena_common.bpf.h`, `scx_sdt.h`.
- Detected declarations: `struct scx_task_map_val`, `function scx_arena_subprog_init`, `function pool_set_size`, `function scx_alloc_init`, `function set_idx_state`, `function mark_nodes_avail`, `function scx_alloc_free_idx`, `function ffs`, `function chunk_find_empty`, `function desc_find_empty`.
- Atlas domain: Support Tooling And Documentation / tools.
- 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.