maximal.bpf.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. #include <scx/common.bpf.h>
  11. char _license[] SEC("license") = "GPL";
  12. #define DSQ_ID 0
  13. s32 BPF_STRUCT_OPS(maximal_select_cpu, struct task_struct *p, s32 prev_cpu,
  14. u64 wake_flags)
  15. {
  16. return prev_cpu;
  17. }
  18. void BPF_STRUCT_OPS(maximal_enqueue, struct task_struct *p, u64 enq_flags)
  19. {
  20. scx_bpf_dsq_insert(p, DSQ_ID, SCX_SLICE_DFL, enq_flags);
  21. }
  22. void BPF_STRUCT_OPS(maximal_dequeue, struct task_struct *p, u64 deq_flags)
  23. {}
  24. void BPF_STRUCT_OPS(maximal_dispatch, s32 cpu, struct task_struct *prev)
  25. {
  26. scx_bpf_dsq_move_to_local(DSQ_ID);
  27. }
  28. void BPF_STRUCT_OPS(maximal_runnable, struct task_struct *p, u64 enq_flags)
  29. {}
  30. void BPF_STRUCT_OPS(maximal_running, struct task_struct *p)
  31. {}
  32. void BPF_STRUCT_OPS(maximal_stopping, struct task_struct *p, bool runnable)
  33. {}
  34. void BPF_STRUCT_OPS(maximal_quiescent, struct task_struct *p, u64 deq_flags)
  35. {}
  36. bool BPF_STRUCT_OPS(maximal_yield, struct task_struct *from,
  37. struct task_struct *to)
  38. {
  39. return false;
  40. }
  41. bool BPF_STRUCT_OPS(maximal_core_sched_before, struct task_struct *a,
  42. struct task_struct *b)
  43. {
  44. return false;
  45. }
  46. void BPF_STRUCT_OPS(maximal_set_weight, struct task_struct *p, u32 weight)
  47. {}
  48. void BPF_STRUCT_OPS(maximal_set_cpumask, struct task_struct *p,
  49. const struct cpumask *cpumask)
  50. {}
  51. void BPF_STRUCT_OPS(maximal_update_idle, s32 cpu, bool idle)
  52. {}
  53. void BPF_STRUCT_OPS(maximal_cpu_acquire, s32 cpu,
  54. struct scx_cpu_acquire_args *args)
  55. {}
  56. void BPF_STRUCT_OPS(maximal_cpu_release, s32 cpu,
  57. struct scx_cpu_release_args *args)
  58. {}
  59. void BPF_STRUCT_OPS(maximal_cpu_online, s32 cpu)
  60. {}
  61. void BPF_STRUCT_OPS(maximal_cpu_offline, s32 cpu)
  62. {}
  63. s32 BPF_STRUCT_OPS(maximal_init_task, struct task_struct *p,
  64. struct scx_init_task_args *args)
  65. {
  66. return 0;
  67. }
  68. void BPF_STRUCT_OPS(maximal_enable, struct task_struct *p)
  69. {}
  70. void BPF_STRUCT_OPS(maximal_exit_task, struct task_struct *p,
  71. struct scx_exit_task_args *args)
  72. {}
  73. void BPF_STRUCT_OPS(maximal_disable, struct task_struct *p)
  74. {}
  75. s32 BPF_STRUCT_OPS(maximal_cgroup_init, struct cgroup *cgrp,
  76. struct scx_cgroup_init_args *args)
  77. {
  78. return 0;
  79. }
  80. void BPF_STRUCT_OPS(maximal_cgroup_exit, struct cgroup *cgrp)
  81. {}
  82. s32 BPF_STRUCT_OPS(maximal_cgroup_prep_move, struct task_struct *p,
  83. struct cgroup *from, struct cgroup *to)
  84. {
  85. return 0;
  86. }
  87. void BPF_STRUCT_OPS(maximal_cgroup_move, struct task_struct *p,
  88. struct cgroup *from, struct cgroup *to)
  89. {}
  90. void BPF_STRUCT_OPS(maximal_cgroup_cancel_move, struct task_struct *p,
  91. struct cgroup *from, struct cgroup *to)
  92. {}
  93. void BPF_STRUCT_OPS(maximal_cgroup_set_weight, struct cgroup *cgrp, u32 weight)
  94. {}
  95. void BPF_STRUCT_OPS(maximal_cgroup_set_bandwidth, struct cgroup *cgrp,
  96. u64 period_us, u64 quota_us, u64 burst_us)
  97. {}
  98. s32 BPF_STRUCT_OPS_SLEEPABLE(maximal_init)
  99. {
  100. return scx_bpf_create_dsq(DSQ_ID, -1);
  101. }
  102. void BPF_STRUCT_OPS(maximal_exit, struct scx_exit_info *info)
  103. {}
  104. SEC(".struct_ops.link")
  105. struct sched_ext_ops maximal_ops = {
  106. .select_cpu = (void *) maximal_select_cpu,
  107. .enqueue = (void *) maximal_enqueue,
  108. .dequeue = (void *) maximal_dequeue,
  109. .dispatch = (void *) maximal_dispatch,
  110. .runnable = (void *) maximal_runnable,
  111. .running = (void *) maximal_running,
  112. .stopping = (void *) maximal_stopping,
  113. .quiescent = (void *) maximal_quiescent,
  114. .yield = (void *) maximal_yield,
  115. .core_sched_before = (void *) maximal_core_sched_before,
  116. .set_weight = (void *) maximal_set_weight,
  117. .set_cpumask = (void *) maximal_set_cpumask,
  118. .update_idle = (void *) maximal_update_idle,
  119. .cpu_acquire = (void *) maximal_cpu_acquire,
  120. .cpu_release = (void *) maximal_cpu_release,
  121. .cpu_online = (void *) maximal_cpu_online,
  122. .cpu_offline = (void *) maximal_cpu_offline,
  123. .init_task = (void *) maximal_init_task,
  124. .enable = (void *) maximal_enable,
  125. .exit_task = (void *) maximal_exit_task,
  126. .disable = (void *) maximal_disable,
  127. .cgroup_init = (void *) maximal_cgroup_init,
  128. .cgroup_exit = (void *) maximal_cgroup_exit,
  129. .cgroup_prep_move = (void *) maximal_cgroup_prep_move,
  130. .cgroup_move = (void *) maximal_cgroup_move,
  131. .cgroup_cancel_move = (void *) maximal_cgroup_cancel_move,
  132. .cgroup_set_weight = (void *) maximal_cgroup_set_weight,
  133. .cgroup_set_bandwidth = (void *) maximal_cgroup_set_bandwidth,
  134. .init = (void *) maximal_init,
  135. .exit = (void *) maximal_exit,
  136. .name = "maximal",
  137. };