tools/sched_ext/include/scx/common.bpf.h
Source file repositories/reference/linux-study-clean/tools/sched_ext/include/scx/common.bpf.h
File Facts
- System
- Linux kernel
- Corpus path
tools/sched_ext/include/scx/common.bpf.h- Extension
.h- Size
- 38518 bytes
- Lines
- 1070
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
../vmlinux.hvmlinux.hbpf/bpf_helpers.hbpf/bpf_tracing.hasm-generic/errno.huser_exit_info.bpf.henum_defs.autogen.hcompat.bpf.henums.bpf.hcid.bpf.h
Detected Declarations
struct bpf_iter_cssstruct cgroup_subsys_statestruct rq___localstruct irqtime___localfunction ___vmlinux_h_sanity_check___function bpf_for_eachfunction bpf_forfunction is_migration_disabledfunction time_deltafunction codefunction time_beforefunction time_after_eqfunction time_before_eqfunction time_in_rangefunction time_in_range_openfunction __read_once_sizefunction __write_once_sizefunction log2_u32function log2_u64function __sqrt_u64function ctzllfunction scale_by_task_weightfunction scale_by_task_weight_inversefunction get_prandom_u64function scx_clock_taskfunction scx_clock_peltfunction scx_clock_virtfunction scx_clock_irq
Annotated Snippet
struct rq___local {
/*
* A monotonically increasing clock per CPU. It is rq->clock minus
* cumulative IRQ time and hypervisor steal time. Unlike rq->clock,
* it does not advance during IRQ processing or hypervisor preemption.
* It does advance during idle (the idle task counts as a running task
* for this purpose).
*/
u64 clock_task;
/*
* Invariant version of clock_task scaled by CPU capacity and
* frequency. For example, clock_pelt advances 2x slower on a CPU
* with half the capacity.
*
* At idle exit, rq->clock_pelt jumps forward to resync with
* clock_task. The kernel's rq_clock_pelt() corrects for this jump
* by subtracting lost_idle_time, yielding a clock that appears
* continuous across idle transitions. scx_clock_pelt() mirrors
* rq_clock_pelt() by performing the same subtraction.
*/
u64 clock_pelt;
/*
* Accumulates the magnitude of each clock_pelt jump at idle exit.
* Subtracting this from clock_pelt gives rq_clock_pelt(): a
* continuous, capacity-invariant clock suitable for both task
* execution time stamping and cross-idle measurements.
*/
unsigned long lost_idle_time;
/*
* Shadow of paravirt_steal_clock() (the hypervisor's cumulative
* stolen time counter). Stays frozen while the hypervisor preempts
* the vCPU; catches up the next time update_rq_clock_task() is
* called. The delta is the stolen time not yet subtracted from
* clock_task.
*
* Unlike irqtime->total (a plain kernel-side field), the live stolen
* time counter lives in hypervisor-specific shared memory and has no
* kernel-side equivalent readable from BPF in a hypervisor-agnostic
* way. This field is therefore the only portable BPF-accessible
* approximation of cumulative steal time.
*
* Available only when CONFIG_PARAVIRT_TIME_ACCOUNTING is on.
*/
u64 prev_steal_time_rq;
} __attribute__((preserve_access_index));
extern struct rq runqueues __ksym;
/*
* Define the shadow structure to avoid a compilation error when
* vmlinux.h does not enable necessary kernel configs.
*/
struct irqtime___local {
/*
* Cumulative IRQ time counter for this CPU, in nanoseconds. Advances
* immediately at the exit of every hardirq and non-ksoftirqd softirq
* via irqtime_account_irq(). ksoftirqd time is counted as normal
* task time and is NOT included. NMI time is also NOT included.
*
* The companion field irqtime->sync (struct u64_stats_sync) protects
* against 64-bit tearing on 32-bit architectures. On 64-bit kernels,
* u64_stats_sync is an empty struct and all seqcount operations are
* no-ops, so a plain BPF_CORE_READ of this field is safe.
*
* Available only when CONFIG_IRQ_TIME_ACCOUNTING is on.
*/
u64 total;
} __attribute__((preserve_access_index));
/*
* cpu_irqtime is a per-CPU variable defined only when
* CONFIG_IRQ_TIME_ACCOUNTING is on. Declare it as __weak so the BPF
* loader sets its address to 0 (rather than failing) when the symbol
* is absent from the running kernel.
*/
extern struct irqtime___local cpu_irqtime __ksym __weak;
static inline struct rq___local *get_current_rq(u32 cpu)
{
/*
* This is a workaround to get an rq pointer since we decided to
* deprecate scx_bpf_cpu_rq().
*
* WARNING: The caller must hold the rq lock for @cpu. This is
* guaranteed when called from scheduling callbacks (ops.running,
* ops.stopping, ops.enqueue, ops.dequeue, ops.dispatch, etc.).
* There is no runtime check available in BPF for kernel spinlock
* state — correctness is enforced by calling context only.
*/
return (void *)bpf_per_cpu_ptr(&runqueues, cpu);
Annotation
- Immediate include surface: `../vmlinux.h`, `vmlinux.h`, `bpf/bpf_helpers.h`, `bpf/bpf_tracing.h`, `asm-generic/errno.h`, `user_exit_info.bpf.h`, `enum_defs.autogen.h`, `compat.bpf.h`.
- Detected declarations: `struct bpf_iter_css`, `struct cgroup_subsys_state`, `struct rq___local`, `struct irqtime___local`, `function ___vmlinux_h_sanity_check___`, `function bpf_for_each`, `function bpf_for`, `function is_migration_disabled`, `function time_delta`, `function code`.
- 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.