create_dsq.bpf.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Create and destroy DSQs in a loop.
  4. *
  5. * Copyright (c) 2024 Meta Platforms, Inc. and affiliates.
  6. * Copyright (c) 2024 David Vernet <dvernet@meta.com>
  7. */
  8. #include <scx/common.bpf.h>
  9. char _license[] SEC("license") = "GPL";
  10. void BPF_STRUCT_OPS(create_dsq_exit_task, struct task_struct *p,
  11. struct scx_exit_task_args *args)
  12. {
  13. scx_bpf_destroy_dsq(p->pid);
  14. }
  15. s32 BPF_STRUCT_OPS_SLEEPABLE(create_dsq_init_task, struct task_struct *p,
  16. struct scx_init_task_args *args)
  17. {
  18. s32 err;
  19. err = scx_bpf_create_dsq(p->pid, -1);
  20. if (err)
  21. scx_bpf_error("Failed to create DSQ for %s[%d]",
  22. p->comm, p->pid);
  23. return err;
  24. }
  25. s32 BPF_STRUCT_OPS_SLEEPABLE(create_dsq_init)
  26. {
  27. u32 i;
  28. s32 err;
  29. bpf_for(i, 0, 1024) {
  30. err = scx_bpf_create_dsq(i, -1);
  31. if (err) {
  32. scx_bpf_error("Failed to create DSQ %d", i);
  33. return 0;
  34. }
  35. }
  36. bpf_for(i, 0, 1024) {
  37. scx_bpf_destroy_dsq(i);
  38. }
  39. return 0;
  40. }
  41. SEC(".struct_ops.link")
  42. struct sched_ext_ops create_dsq_ops = {
  43. .init_task = (void *) create_dsq_init_task,
  44. .exit_task = (void *) create_dsq_exit_task,
  45. .init = (void *) create_dsq_init,
  46. .name = "create_dsq",
  47. };