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