xref: /linux/tools/testing/selftests/sched_ext/select_cpu_dispatch_dbl_dsp.bpf.c (revision daa9f66fe194f672d2c94d879b6dad7035e03ebe)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * A scheduler that validates the behavior of direct dispatching with a default
4  * select_cpu implementation.
5  *
6  * Copyright (c) 2023 Meta Platforms, Inc. and affiliates.
7  * Copyright (c) 2023 David Vernet <dvernet@meta.com>
8  * Copyright (c) 2023 Tejun Heo <tj@kernel.org>
9  */
10 
11 #include <scx/common.bpf.h>
12 
13 char _license[] SEC("license") = "GPL";
14 
15 UEI_DEFINE(uei);
16 
BPF_STRUCT_OPS(select_cpu_dispatch_dbl_dsp_select_cpu,struct task_struct * p,s32 prev_cpu,u64 wake_flags)17 s32 BPF_STRUCT_OPS(select_cpu_dispatch_dbl_dsp_select_cpu, struct task_struct *p,
18 		   s32 prev_cpu, u64 wake_flags)
19 {
20 	/* Dispatching twice in a row is disallowed. */
21 	scx_bpf_dispatch(p, SCX_DSQ_GLOBAL, SCX_SLICE_DFL, 0);
22 	scx_bpf_dispatch(p, SCX_DSQ_GLOBAL, SCX_SLICE_DFL, 0);
23 
24 	return prev_cpu;
25 }
26 
BPF_STRUCT_OPS(select_cpu_dispatch_dbl_dsp_exit,struct scx_exit_info * ei)27 void BPF_STRUCT_OPS(select_cpu_dispatch_dbl_dsp_exit, struct scx_exit_info *ei)
28 {
29 	UEI_RECORD(uei, ei);
30 }
31 
32 SEC(".struct_ops.link")
33 struct sched_ext_ops select_cpu_dispatch_dbl_dsp_ops = {
34 	.select_cpu		= (void *) select_cpu_dispatch_dbl_dsp_select_cpu,
35 	.exit			= (void *) select_cpu_dispatch_dbl_dsp_exit,
36 	.name			= "select_cpu_dispatch_dbl_dsp",
37 	.timeout_ms		= 1000U,
38 };
39