xref: /linux/tools/testing/selftests/sched_ext/maximal.bpf.c (revision f96bc0fa92be8dc0ec97bbe5bec6d5df26f9585b)
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 #define DSQ_ID 0
16 
17 s32 BPF_STRUCT_OPS(maximal_select_cpu, struct task_struct *p, s32 prev_cpu,
18 		   u64 wake_flags)
19 {
20 	return prev_cpu;
21 }
22 
23 void BPF_STRUCT_OPS(maximal_enqueue, struct task_struct *p, u64 enq_flags)
24 {
25 	scx_bpf_dsq_insert(p, DSQ_ID, SCX_SLICE_DFL, enq_flags);
26 }
27 
28 void BPF_STRUCT_OPS(maximal_dequeue, struct task_struct *p, u64 deq_flags)
29 {}
30 
31 void BPF_STRUCT_OPS(maximal_dispatch, s32 cpu, struct task_struct *prev)
32 {
33 	scx_bpf_dsq_move_to_local(DSQ_ID, 0);
34 }
35 
36 void BPF_STRUCT_OPS(maximal_runnable, struct task_struct *p, u64 enq_flags)
37 {}
38 
39 void BPF_STRUCT_OPS(maximal_running, struct task_struct *p)
40 {}
41 
42 void BPF_STRUCT_OPS(maximal_stopping, struct task_struct *p, bool runnable)
43 {}
44 
45 void BPF_STRUCT_OPS(maximal_quiescent, struct task_struct *p, u64 deq_flags)
46 {}
47 
48 bool BPF_STRUCT_OPS(maximal_yield, struct task_struct *from,
49 		    struct task_struct *to)
50 {
51 	return false;
52 }
53 
54 bool BPF_STRUCT_OPS(maximal_core_sched_before, struct task_struct *a,
55 		    struct task_struct *b)
56 {
57 	return false;
58 }
59 
60 void BPF_STRUCT_OPS(maximal_set_weight, struct task_struct *p, u32 weight)
61 {}
62 
63 void BPF_STRUCT_OPS(maximal_set_cpumask, struct task_struct *p,
64 		    const struct cpumask *cpumask)
65 {}
66 
67 void BPF_STRUCT_OPS(maximal_update_idle, s32 cpu, bool idle)
68 {}
69 
70 SEC("tp_btf/sched_switch")
71 int BPF_PROG(maximal_sched_switch, bool preempt, struct task_struct *prev,
72 	     struct task_struct *next, unsigned int prev_state)
73 {
74 	return 0;
75 }
76 
77 void BPF_STRUCT_OPS(maximal_cpu_online, s32 cpu)
78 {}
79 
80 void BPF_STRUCT_OPS(maximal_cpu_offline, s32 cpu)
81 {}
82 
83 s32 BPF_STRUCT_OPS(maximal_init_task, struct task_struct *p,
84 		   struct scx_init_task_args *args)
85 {
86 	return 0;
87 }
88 
89 void BPF_STRUCT_OPS(maximal_enable, struct task_struct *p)
90 {}
91 
92 void BPF_STRUCT_OPS(maximal_exit_task, struct task_struct *p,
93 		    struct scx_exit_task_args *args)
94 {}
95 
96 void BPF_STRUCT_OPS(maximal_disable, struct task_struct *p)
97 {}
98 
99 s32 BPF_STRUCT_OPS(maximal_cgroup_init, struct cgroup *cgrp,
100 		   struct scx_cgroup_init_args *args)
101 {
102 	return 0;
103 }
104 
105 void BPF_STRUCT_OPS(maximal_cgroup_exit, struct cgroup *cgrp)
106 {}
107 
108 s32 BPF_STRUCT_OPS(maximal_cgroup_prep_move, struct task_struct *p,
109 		   struct cgroup *from, struct cgroup *to)
110 {
111 	return 0;
112 }
113 
114 void BPF_STRUCT_OPS(maximal_cgroup_move, struct task_struct *p,
115 		    struct cgroup *from, struct cgroup *to)
116 {}
117 
118 void BPF_STRUCT_OPS(maximal_cgroup_cancel_move, struct task_struct *p,
119 	       struct cgroup *from, struct cgroup *to)
120 {}
121 
122 void BPF_STRUCT_OPS(maximal_cgroup_set_weight, struct cgroup *cgrp, u32 weight)
123 {}
124 
125 void BPF_STRUCT_OPS(maximal_cgroup_set_bandwidth, struct cgroup *cgrp,
126 		    u64 period_us, u64 quota_us, u64 burst_us)
127 {}
128 
129 s32 BPF_STRUCT_OPS_SLEEPABLE(maximal_init)
130 {
131 	return scx_bpf_create_dsq(DSQ_ID, -1);
132 }
133 
134 void BPF_STRUCT_OPS(maximal_exit, struct scx_exit_info *info)
135 {}
136 
137 SEC(".struct_ops.link")
138 struct sched_ext_ops maximal_ops = {
139 	.select_cpu		= (void *) maximal_select_cpu,
140 	.enqueue		= (void *) maximal_enqueue,
141 	.dequeue		= (void *) maximal_dequeue,
142 	.dispatch		= (void *) maximal_dispatch,
143 	.runnable		= (void *) maximal_runnable,
144 	.running		= (void *) maximal_running,
145 	.stopping		= (void *) maximal_stopping,
146 	.quiescent		= (void *) maximal_quiescent,
147 	.yield			= (void *) maximal_yield,
148 	.core_sched_before	= (void *) maximal_core_sched_before,
149 	.set_weight		= (void *) maximal_set_weight,
150 	.set_cpumask		= (void *) maximal_set_cpumask,
151 	.update_idle		= (void *) maximal_update_idle,
152 	.cpu_online		= (void *) maximal_cpu_online,
153 	.cpu_offline		= (void *) maximal_cpu_offline,
154 	.init_task		= (void *) maximal_init_task,
155 	.enable			= (void *) maximal_enable,
156 	.exit_task		= (void *) maximal_exit_task,
157 	.disable		= (void *) maximal_disable,
158 	.cgroup_init		= (void *) maximal_cgroup_init,
159 	.cgroup_exit		= (void *) maximal_cgroup_exit,
160 	.cgroup_prep_move	= (void *) maximal_cgroup_prep_move,
161 	.cgroup_move		= (void *) maximal_cgroup_move,
162 	.cgroup_cancel_move	= (void *) maximal_cgroup_cancel_move,
163 	.cgroup_set_weight	= (void *) maximal_cgroup_set_weight,
164 	.cgroup_set_bandwidth	= (void *) maximal_cgroup_set_bandwidth,
165 	.init			= (void *) maximal_init,
166 	.exit			= (void *) maximal_exit,
167 	.name			= "maximal",
168 };
169