xref: /linux/tools/testing/selftests/sched_ext/maybe_null.bpf.c (revision daa9f66fe194f672d2c94d879b6dad7035e03ebe)
1a5db7817SDavid Vernet /* SPDX-License-Identifier: GPL-2.0 */
2a5db7817SDavid Vernet /*
3a5db7817SDavid Vernet  * Copyright (c) 2024 Meta Platforms, Inc. and affiliates.
4a5db7817SDavid Vernet  */
5a5db7817SDavid Vernet 
6a5db7817SDavid Vernet #include <scx/common.bpf.h>
7a5db7817SDavid Vernet 
8a5db7817SDavid Vernet char _license[] SEC("license") = "GPL";
9a5db7817SDavid Vernet 
10a5db7817SDavid Vernet u64 vtime_test;
11a5db7817SDavid Vernet 
BPF_STRUCT_OPS(maybe_null_running,struct task_struct * p)12a5db7817SDavid Vernet void BPF_STRUCT_OPS(maybe_null_running, struct task_struct *p)
13a5db7817SDavid Vernet {}
14a5db7817SDavid Vernet 
BPF_STRUCT_OPS(maybe_null_success_dispatch,s32 cpu,struct task_struct * p)15a5db7817SDavid Vernet void BPF_STRUCT_OPS(maybe_null_success_dispatch, s32 cpu, struct task_struct *p)
16a5db7817SDavid Vernet {
17a5db7817SDavid Vernet 	if (p != NULL)
18a5db7817SDavid Vernet 		vtime_test = p->scx.dsq_vtime;
19a5db7817SDavid Vernet }
20a5db7817SDavid Vernet 
BPF_STRUCT_OPS(maybe_null_success_yield,struct task_struct * from,struct task_struct * to)21a5db7817SDavid Vernet bool BPF_STRUCT_OPS(maybe_null_success_yield, struct task_struct *from,
22a5db7817SDavid Vernet 		    struct task_struct *to)
23a5db7817SDavid Vernet {
24a5db7817SDavid Vernet 	if (to)
25a5db7817SDavid Vernet 		bpf_printk("Yielding to %s[%d]", to->comm, to->pid);
26a5db7817SDavid Vernet 
27a5db7817SDavid Vernet 	return false;
28a5db7817SDavid Vernet }
29a5db7817SDavid Vernet 
30a5db7817SDavid Vernet SEC(".struct_ops.link")
31a5db7817SDavid Vernet struct sched_ext_ops maybe_null_success = {
32*4f7f4170SVishal Chourasia 	.dispatch               = (void *) maybe_null_success_dispatch,
33*4f7f4170SVishal Chourasia 	.yield			= (void *) maybe_null_success_yield,
34*4f7f4170SVishal Chourasia 	.enable			= (void *) maybe_null_running,
35a5db7817SDavid Vernet 	.name			= "minimal",
36a5db7817SDavid Vernet };
37