select_cpu_dfl.bpf.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * A scheduler that validates the behavior of direct dispatching with a default
  4. * select_cpu implementation.
  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. bool saw_local = false;
  13. static bool task_is_test(const struct task_struct *p)
  14. {
  15. return !bpf_strncmp(p->comm, 9, "select_cpu");
  16. }
  17. void BPF_STRUCT_OPS(select_cpu_dfl_enqueue, struct task_struct *p,
  18. u64 enq_flags)
  19. {
  20. const struct cpumask *idle_mask = scx_bpf_get_idle_cpumask();
  21. if (task_is_test(p) &&
  22. bpf_cpumask_test_cpu(scx_bpf_task_cpu(p), idle_mask)) {
  23. saw_local = true;
  24. }
  25. scx_bpf_put_idle_cpumask(idle_mask);
  26. scx_bpf_dsq_insert(p, SCX_DSQ_GLOBAL, SCX_SLICE_DFL, enq_flags);
  27. }
  28. SEC(".struct_ops.link")
  29. struct sched_ext_ops select_cpu_dfl_ops = {
  30. .enqueue = (void *) select_cpu_dfl_enqueue,
  31. .name = "select_cpu_dfl",
  32. };