exit.bpf.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2024 Meta Platforms, Inc. and affiliates.
  4. * Copyright (c) 2024 David Vernet <dvernet@meta.com>
  5. */
  6. #include <scx/common.bpf.h>
  7. char _license[] SEC("license") = "GPL";
  8. #include "exit_test.h"
  9. const volatile int exit_point;
  10. UEI_DEFINE(uei);
  11. #define EXIT_CLEANLY() scx_bpf_exit(exit_point, "%d", exit_point)
  12. #define DSQ_ID 0
  13. s32 BPF_STRUCT_OPS(exit_select_cpu, struct task_struct *p,
  14. s32 prev_cpu, u64 wake_flags)
  15. {
  16. bool found;
  17. if (exit_point == EXIT_SELECT_CPU)
  18. EXIT_CLEANLY();
  19. return scx_bpf_select_cpu_dfl(p, prev_cpu, wake_flags, &found);
  20. }
  21. void BPF_STRUCT_OPS(exit_enqueue, struct task_struct *p, u64 enq_flags)
  22. {
  23. if (exit_point == EXIT_ENQUEUE)
  24. EXIT_CLEANLY();
  25. scx_bpf_dsq_insert(p, DSQ_ID, SCX_SLICE_DFL, enq_flags);
  26. }
  27. void BPF_STRUCT_OPS(exit_dispatch, s32 cpu, struct task_struct *p)
  28. {
  29. if (exit_point == EXIT_DISPATCH)
  30. EXIT_CLEANLY();
  31. scx_bpf_dsq_move_to_local(DSQ_ID);
  32. }
  33. void BPF_STRUCT_OPS(exit_enable, struct task_struct *p)
  34. {
  35. if (exit_point == EXIT_ENABLE)
  36. EXIT_CLEANLY();
  37. }
  38. s32 BPF_STRUCT_OPS(exit_init_task, struct task_struct *p,
  39. struct scx_init_task_args *args)
  40. {
  41. if (exit_point == EXIT_INIT_TASK)
  42. EXIT_CLEANLY();
  43. return 0;
  44. }
  45. void BPF_STRUCT_OPS(exit_exit, struct scx_exit_info *ei)
  46. {
  47. UEI_RECORD(uei, ei);
  48. }
  49. s32 BPF_STRUCT_OPS_SLEEPABLE(exit_init)
  50. {
  51. if (exit_point == EXIT_INIT)
  52. EXIT_CLEANLY();
  53. return scx_bpf_create_dsq(DSQ_ID, -1);
  54. }
  55. SEC(".struct_ops.link")
  56. struct sched_ext_ops exit_ops = {
  57. .select_cpu = (void *) exit_select_cpu,
  58. .enqueue = (void *) exit_enqueue,
  59. .dispatch = (void *) exit_dispatch,
  60. .init_task = (void *) exit_init_task,
  61. .enable = (void *) exit_enable,
  62. .exit = (void *) exit_exit,
  63. .init = (void *) exit_init,
  64. .name = "exit",
  65. .timeout_ms = 1000U,
  66. };