init_enable_count.bpf.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * A scheduler that verifies that we do proper counting of init, enable, etc
  4. * callbacks.
  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. #include <scx/common.bpf.h>
  11. char _license[] SEC("license") = "GPL";
  12. u64 init_task_cnt, exit_task_cnt, enable_cnt, disable_cnt;
  13. u64 init_fork_cnt, init_transition_cnt;
  14. s32 BPF_STRUCT_OPS_SLEEPABLE(cnt_init_task, struct task_struct *p,
  15. struct scx_init_task_args *args)
  16. {
  17. __sync_fetch_and_add(&init_task_cnt, 1);
  18. if (args->fork)
  19. __sync_fetch_and_add(&init_fork_cnt, 1);
  20. else
  21. __sync_fetch_and_add(&init_transition_cnt, 1);
  22. return 0;
  23. }
  24. void BPF_STRUCT_OPS(cnt_exit_task, struct task_struct *p)
  25. {
  26. __sync_fetch_and_add(&exit_task_cnt, 1);
  27. }
  28. void BPF_STRUCT_OPS(cnt_enable, struct task_struct *p)
  29. {
  30. __sync_fetch_and_add(&enable_cnt, 1);
  31. }
  32. void BPF_STRUCT_OPS(cnt_disable, struct task_struct *p)
  33. {
  34. __sync_fetch_and_add(&disable_cnt, 1);
  35. }
  36. SEC(".struct_ops.link")
  37. struct sched_ext_ops init_enable_count_ops = {
  38. .init_task = (void *) cnt_init_task,
  39. .exit_task = (void *) cnt_exit_task,
  40. .enable = (void *) cnt_enable,
  41. .disable = (void *) cnt_disable,
  42. .name = "init_enable_count",
  43. };