1 /* SPDX-License-Identifier: GPL-2.0 */ 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 2 /* 3 * Copyright (c) 2024 Meta Platforms, Inc. and 3 * Copyright (c) 2024 Meta Platforms, Inc. and affiliates. 4 * Copyright (c) 2024 David Vernet <dvernet@me 4 * Copyright (c) 2024 David Vernet <dvernet@meta.com> 5 */ 5 */ 6 6 7 #include <scx/common.bpf.h> 7 #include <scx/common.bpf.h> 8 8 9 char _license[] SEC("license") = "GPL"; 9 char _license[] SEC("license") = "GPL"; 10 10 11 #include "exit_test.h" 11 #include "exit_test.h" 12 12 13 const volatile int exit_point; 13 const volatile int exit_point; 14 UEI_DEFINE(uei); 14 UEI_DEFINE(uei); 15 15 16 #define EXIT_CLEANLY() scx_bpf_exit(exit_point 16 #define EXIT_CLEANLY() scx_bpf_exit(exit_point, "%d", exit_point) 17 17 18 #define DSQ_ID 0 18 #define DSQ_ID 0 19 19 20 s32 BPF_STRUCT_OPS(exit_select_cpu, struct tas 20 s32 BPF_STRUCT_OPS(exit_select_cpu, struct task_struct *p, 21 s32 prev_cpu, u64 wake_flag 21 s32 prev_cpu, u64 wake_flags) 22 { 22 { 23 bool found; 23 bool found; 24 24 25 if (exit_point == EXIT_SELECT_CPU) 25 if (exit_point == EXIT_SELECT_CPU) 26 EXIT_CLEANLY(); 26 EXIT_CLEANLY(); 27 27 28 return scx_bpf_select_cpu_dfl(p, prev_ 28 return scx_bpf_select_cpu_dfl(p, prev_cpu, wake_flags, &found); 29 } 29 } 30 30 31 void BPF_STRUCT_OPS(exit_enqueue, struct task_ 31 void BPF_STRUCT_OPS(exit_enqueue, struct task_struct *p, u64 enq_flags) 32 { 32 { 33 if (exit_point == EXIT_ENQUEUE) 33 if (exit_point == EXIT_ENQUEUE) 34 EXIT_CLEANLY(); 34 EXIT_CLEANLY(); 35 35 36 scx_bpf_dispatch(p, DSQ_ID, SCX_SLICE_ 36 scx_bpf_dispatch(p, DSQ_ID, SCX_SLICE_DFL, enq_flags); 37 } 37 } 38 38 39 void BPF_STRUCT_OPS(exit_dispatch, s32 cpu, st 39 void BPF_STRUCT_OPS(exit_dispatch, s32 cpu, struct task_struct *p) 40 { 40 { 41 if (exit_point == EXIT_DISPATCH) 41 if (exit_point == EXIT_DISPATCH) 42 EXIT_CLEANLY(); 42 EXIT_CLEANLY(); 43 43 44 scx_bpf_consume(DSQ_ID); 44 scx_bpf_consume(DSQ_ID); 45 } 45 } 46 46 47 void BPF_STRUCT_OPS(exit_enable, struct task_s 47 void BPF_STRUCT_OPS(exit_enable, struct task_struct *p) 48 { 48 { 49 if (exit_point == EXIT_ENABLE) 49 if (exit_point == EXIT_ENABLE) 50 EXIT_CLEANLY(); 50 EXIT_CLEANLY(); 51 } 51 } 52 52 53 s32 BPF_STRUCT_OPS(exit_init_task, struct task 53 s32 BPF_STRUCT_OPS(exit_init_task, struct task_struct *p, 54 struct scx_init_task_args 54 struct scx_init_task_args *args) 55 { 55 { 56 if (exit_point == EXIT_INIT_TASK) 56 if (exit_point == EXIT_INIT_TASK) 57 EXIT_CLEANLY(); 57 EXIT_CLEANLY(); 58 58 59 return 0; 59 return 0; 60 } 60 } 61 61 62 void BPF_STRUCT_OPS(exit_exit, struct scx_exit 62 void BPF_STRUCT_OPS(exit_exit, struct scx_exit_info *ei) 63 { 63 { 64 UEI_RECORD(uei, ei); 64 UEI_RECORD(uei, ei); 65 } 65 } 66 66 67 s32 BPF_STRUCT_OPS_SLEEPABLE(exit_init) 67 s32 BPF_STRUCT_OPS_SLEEPABLE(exit_init) 68 { 68 { 69 if (exit_point == EXIT_INIT) 69 if (exit_point == EXIT_INIT) 70 EXIT_CLEANLY(); 70 EXIT_CLEANLY(); 71 71 72 return scx_bpf_create_dsq(DSQ_ID, -1); 72 return scx_bpf_create_dsq(DSQ_ID, -1); 73 } 73 } 74 74 75 SEC(".struct_ops.link") 75 SEC(".struct_ops.link") 76 struct sched_ext_ops exit_ops = { 76 struct sched_ext_ops exit_ops = { 77 .select_cpu = (void *) exi 77 .select_cpu = (void *) exit_select_cpu, 78 .enqueue = (void *) exi 78 .enqueue = (void *) exit_enqueue, 79 .dispatch = (void *) exi 79 .dispatch = (void *) exit_dispatch, 80 .init_task = (void *) exi 80 .init_task = (void *) exit_init_task, 81 .enable = (void *) exi 81 .enable = (void *) exit_enable, 82 .exit = (void *) exi 82 .exit = (void *) exit_exit, 83 .init = (void *) exi 83 .init = (void *) exit_init, 84 .name = "exit", 84 .name = "exit", 85 .timeout_ms = 1000U, 85 .timeout_ms = 1000U, 86 }; 86 }; 87 87
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.