mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00

With commit 08699d20467b6 ("sched_ext: idle: Consolidate default idle CPU selection kfuncs") allowing scx_bpf_select_cpu_dfl() to be invoked from multiple contexts, update the test to validate that the kfunc behaves correctly when used from ops.enqueue() and via BPF test_run. Additionally, rename the test to enq_select_cpu, dropping "fails" from the name, as the logic has now been inverted. Signed-off-by: Andrea Righi <arighi@nvidia.com> Signed-off-by: Tejun Heo <tj@kernel.org>
74 lines
1.6 KiB
C
74 lines
1.6 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* Copyright (c) 2023 Meta Platforms, Inc. and affiliates.
|
|
* Copyright (c) 2023 David Vernet <dvernet@meta.com>
|
|
* Copyright (c) 2023 Tejun Heo <tj@kernel.org>
|
|
*/
|
|
|
|
#include <scx/common.bpf.h>
|
|
|
|
char _license[] SEC("license") = "GPL";
|
|
|
|
UEI_DEFINE(uei);
|
|
|
|
s32 BPF_STRUCT_OPS(enq_select_cpu_select_cpu, struct task_struct *p,
|
|
s32 prev_cpu, u64 wake_flags)
|
|
{
|
|
/* Bounce all tasks to ops.enqueue() */
|
|
return prev_cpu;
|
|
}
|
|
|
|
void BPF_STRUCT_OPS(enq_select_cpu_enqueue, struct task_struct *p,
|
|
u64 enq_flags)
|
|
{
|
|
s32 cpu, prev_cpu = scx_bpf_task_cpu(p);
|
|
bool found = false;
|
|
|
|
cpu = scx_bpf_select_cpu_dfl(p, prev_cpu, 0, &found);
|
|
if (found) {
|
|
scx_bpf_dsq_insert(p, SCX_DSQ_LOCAL_ON | cpu, SCX_SLICE_DFL, enq_flags);
|
|
return;
|
|
}
|
|
|
|
scx_bpf_dsq_insert(p, SCX_DSQ_GLOBAL, SCX_SLICE_DFL, enq_flags);
|
|
}
|
|
|
|
void BPF_STRUCT_OPS(enq_select_cpu_exit, struct scx_exit_info *ei)
|
|
{
|
|
UEI_RECORD(uei, ei);
|
|
}
|
|
|
|
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,
|
|
};
|