tools/testing/selftests/sched_ext/select_cpu_vtime.bpf.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/sched_ext/select_cpu_vtime.bpf.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/sched_ext/select_cpu_vtime.bpf.c- Extension
.c- Size
- 2417 bytes
- Lines
- 95
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
scx/common.bpf.h
Detected Declarations
function vtime_beforefunction task_vtimefunction BPF_STRUCT_OPSfunction BPF_STRUCT_OPSfunction BPF_STRUCT_OPSfunction BPF_STRUCT_OPSfunction BPF_STRUCT_OPSfunction BPF_STRUCT_OPS_SLEEPABLE
Annotated Snippet
#include <scx/common.bpf.h>
char _license[] SEC("license") = "GPL";
volatile bool consumed;
static u64 vtime_now;
#define VTIME_DSQ 0
static inline bool vtime_before(u64 a, u64 b)
{
return (s64)(a - b) < 0;
}
static inline u64 task_vtime(const struct task_struct *p)
{
u64 vtime = p->scx.dsq_vtime;
if (vtime_before(vtime, vtime_now - SCX_SLICE_DFL))
return vtime_now - SCX_SLICE_DFL;
else
return vtime;
}
s32 BPF_STRUCT_OPS(select_cpu_vtime_select_cpu, struct task_struct *p,
s32 prev_cpu, u64 wake_flags)
{
s32 cpu;
cpu = scx_bpf_pick_idle_cpu(p->cpus_ptr, 0);
if (cpu >= 0)
goto ddsp;
cpu = prev_cpu;
scx_bpf_test_and_clear_cpu_idle(cpu);
ddsp:
scx_bpf_dsq_insert_vtime(p, VTIME_DSQ, SCX_SLICE_DFL, task_vtime(p), 0);
return cpu;
}
void BPF_STRUCT_OPS(select_cpu_vtime_dispatch, s32 cpu, struct task_struct *p)
{
if (scx_bpf_dsq_move_to_local(VTIME_DSQ, 0))
consumed = true;
}
void BPF_STRUCT_OPS(select_cpu_vtime_running, struct task_struct *p)
{
if (vtime_before(vtime_now, p->scx.dsq_vtime))
vtime_now = p->scx.dsq_vtime;
}
void BPF_STRUCT_OPS(select_cpu_vtime_stopping, struct task_struct *p,
bool runnable)
{
u64 delta = scale_by_task_weight_inverse(p, SCX_SLICE_DFL - p->scx.slice);
scx_bpf_task_set_dsq_vtime(p, p->scx.dsq_vtime + delta);
}
void BPF_STRUCT_OPS(select_cpu_vtime_enable, struct task_struct *p)
{
scx_bpf_task_set_dsq_vtime(p, vtime_now);
}
s32 BPF_STRUCT_OPS_SLEEPABLE(select_cpu_vtime_init)
{
return scx_bpf_create_dsq(VTIME_DSQ, -1);
}
SEC(".struct_ops.link")
struct sched_ext_ops select_cpu_vtime_ops = {
.select_cpu = (void *) select_cpu_vtime_select_cpu,
.dispatch = (void *) select_cpu_vtime_dispatch,
.running = (void *) select_cpu_vtime_running,
.stopping = (void *) select_cpu_vtime_stopping,
.enable = (void *) select_cpu_vtime_enable,
.init = (void *) select_cpu_vtime_init,
.name = "select_cpu_vtime",
.timeout_ms = 1000U,
};
Annotation
- Immediate include surface: `scx/common.bpf.h`.
- Detected declarations: `function vtime_before`, `function task_vtime`, `function BPF_STRUCT_OPS`, `function BPF_STRUCT_OPS`, `function BPF_STRUCT_OPS`, `function BPF_STRUCT_OPS`, `function BPF_STRUCT_OPS`, `function BPF_STRUCT_OPS_SLEEPABLE`.
- Atlas domain: Support Tooling And Documentation / tools.
- 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.