xref: /linux/tools/testing/selftests/sched_ext/maximal.bpf.c (revision d86adb4fc0655a0867da811d000df75d2a325ef6)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * A scheduler with every callback defined.
4  *
5  * This scheduler defines every callback.
6  *
7  * Copyright (c) 2024 Meta Platforms, Inc. and affiliates.
8  * Copyright (c) 2024 David Vernet <dvernet@meta.com>
9  */
10 
11 #include <scx/common.bpf.h>
12 
13 char _license[] SEC("license") = "GPL";
14 
15 s32 BPF_STRUCT_OPS(maximal_select_cpu, struct task_struct *p, s32 prev_cpu,
16 		   u64 wake_flags)
17 {
18 	return prev_cpu;
19 }
20 
21 void BPF_STRUCT_OPS(maximal_enqueue, struct task_struct *p, u64 enq_flags)
22 {
23 	scx_bpf_dispatch(p, SCX_DSQ_GLOBAL, SCX_SLICE_DFL, enq_flags);
24 }
25 
26 void BPF_STRUCT_OPS(maximal_dequeue, struct task_struct *p, u64 deq_flags)
27 {}
28 
29 void BPF_STRUCT_OPS(maximal_dispatch, s32 cpu, struct task_struct *prev)
30 {
31 	scx_bpf_consume(SCX_DSQ_GLOBAL);
32 }
33 
34 void BPF_STRUCT_OPS(maximal_runnable, struct task_struct *p, u64 enq_flags)
35 {}
36 
37 void BPF_STRUCT_OPS(maximal_running, struct task_struct *p)
38 {}
39 
40 void BPF_STRUCT_OPS(maximal_stopping, struct task_struct *p, bool runnable)
41 {}
42 
43 void BPF_STRUCT_OPS(maximal_quiescent, struct task_struct *p, u64 deq_flags)
44 {}
45 
46 bool BPF_STRUCT_OPS(maximal_yield, struct task_struct *from,
47 		    struct task_struct *to)
48 {
49 	return false;
50 }
51 
52 bool BPF_STRUCT_OPS(maximal_core_sched_before, struct task_struct *a,
53 		    struct task_struct *b)
54 {
55 	return false;
56 }
57 
58 void BPF_STRUCT_OPS(maximal_set_weight, struct task_struct *p, u32 weight)
59 {}
60 
61 void BPF_STRUCT_OPS(maximal_set_cpumask, struct task_struct *p,
62 		    const struct cpumask *cpumask)
63 {}
64 
65 void BPF_STRUCT_OPS(maximal_update_idle, s32 cpu, bool idle)
66 {}
67 
68 void BPF_STRUCT_OPS(maximal_cpu_acquire, s32 cpu,
69 		    struct scx_cpu_acquire_args *args)
70 {}
71 
72 void BPF_STRUCT_OPS(maximal_cpu_release, s32 cpu,
73 		    struct scx_cpu_release_args *args)
74 {}
75 
76 void BPF_STRUCT_OPS(maximal_cpu_online, s32 cpu)
77 {}
78 
79 void BPF_STRUCT_OPS(maximal_cpu_offline, s32 cpu)
80 {}
81 
82 s32 BPF_STRUCT_OPS(maximal_init_task, struct task_struct *p,
83 		   struct scx_init_task_args *args)
84 {
85 	return 0;
86 }
87 
88 void BPF_STRUCT_OPS(maximal_enable, struct task_struct *p)
89 {}
90 
91 void BPF_STRUCT_OPS(maximal_exit_task, struct task_struct *p,
92 		    struct scx_exit_task_args *args)
93 {}
94 
95 void BPF_STRUCT_OPS(maximal_disable, struct task_struct *p)
96 {}
97 
98 s32 BPF_STRUCT_OPS_SLEEPABLE(maximal_init)
99 {
100 	return 0;
101 }
102 
103 void BPF_STRUCT_OPS(maximal_exit, struct scx_exit_info *info)
104 {}
105 
106 SEC(".struct_ops.link")
107 struct sched_ext_ops maximal_ops = {
108 	.select_cpu		= maximal_select_cpu,
109 	.enqueue		= maximal_enqueue,
110 	.dequeue		= maximal_dequeue,
111 	.dispatch		= maximal_dispatch,
112 	.runnable		= maximal_runnable,
113 	.running		= maximal_running,
114 	.stopping		= maximal_stopping,
115 	.quiescent		= maximal_quiescent,
116 	.yield			= maximal_yield,
117 	.core_sched_before	= maximal_core_sched_before,
118 	.set_weight		= maximal_set_weight,
119 	.set_cpumask		= maximal_set_cpumask,
120 	.update_idle		= maximal_update_idle,
121 	.cpu_acquire		= maximal_cpu_acquire,
122 	.cpu_release		= maximal_cpu_release,
123 	.cpu_online		= maximal_cpu_online,
124 	.cpu_offline		= maximal_cpu_offline,
125 	.init_task		= maximal_init_task,
126 	.enable			= maximal_enable,
127 	.exit_task		= maximal_exit_task,
128 	.disable		= maximal_disable,
129 	.init			= maximal_init,
130 	.exit			= maximal_exit,
131 	.name			= "maximal",
132 };
133