tools/testing/selftests/sched_ext/enq_select_cpu.bpf.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/sched_ext/enq_select_cpu.bpf.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/sched_ext/enq_select_cpu.bpf.c
Extension
.c
Size
1611 bytes
Lines
75
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct task_cpu_arg {
	pid_t pid;
};

SEC("syscall")
int select_cpu_from_user(struct task_cpu_arg *input)
{
	struct task_struct *p;
	bool found = false;
	s32 cpu;

	p = bpf_task_from_pid(input->pid);
	if (!p)
		return -EINVAL;

	bpf_rcu_read_lock();
	cpu = scx_bpf_select_cpu_dfl(p, bpf_get_smp_processor_id(), 0, &found);
	if (!found)
		cpu = -EBUSY;
	bpf_rcu_read_unlock();

	bpf_task_release(p);

	return cpu;
}

SEC(".struct_ops.link")
struct sched_ext_ops enq_select_cpu_ops = {
	.select_cpu		= (void *)enq_select_cpu_select_cpu,
	.enqueue		= (void *)enq_select_cpu_enqueue,
	.exit			= (void *)enq_select_cpu_exit,
	.name			= "enq_select_cpu",
	.timeout_ms		= 1000U,
};

Annotation

Implementation Notes