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_bad_dsq_select_cpu,struct task_struct * p,s32 prev_cpu,u64 wake_flags)17 s32 BPF_STRUCT_OPS(select_cpu_dispatch_bad_dsq_select_cpu, struct task_struct *p,
18 s32 prev_cpu, u64 wake_flags)
19 {
20 /* Dispatching to a random DSQ should fail. */
21 scx_bpf_dispatch(p, 0xcafef00d, SCX_SLICE_DFL, 0);
22
23 return prev_cpu;
24 }
25
BPF_STRUCT_OPS(select_cpu_dispatch_bad_dsq_exit,struct scx_exit_info * ei)26 void BPF_STRUCT_OPS(select_cpu_dispatch_bad_dsq_exit, struct scx_exit_info *ei)
27 {
28 UEI_RECORD(uei, ei);
29 }
30
31 SEC(".struct_ops.link")
32 struct sched_ext_ops select_cpu_dispatch_bad_dsq_ops = {
33 .select_cpu = (void *) select_cpu_dispatch_bad_dsq_select_cpu,
34 .exit = (void *) select_cpu_dispatch_bad_dsq_exit,
35 .name = "select_cpu_dispatch_bad_dsq",
36 .timeout_ms = 1000U,
37 };
38