maybe_null.bpf.c 829 B

123456789101112131415161718192021222324252627282930313233343536
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2024 Meta Platforms, Inc. and affiliates.
  4. */
  5. #include <scx/common.bpf.h>
  6. char _license[] SEC("license") = "GPL";
  7. u64 vtime_test;
  8. void BPF_STRUCT_OPS(maybe_null_running, struct task_struct *p)
  9. {}
  10. void BPF_STRUCT_OPS(maybe_null_success_dispatch, s32 cpu, struct task_struct *p)
  11. {
  12. if (p != NULL)
  13. vtime_test = p->scx.dsq_vtime;
  14. }
  15. bool BPF_STRUCT_OPS(maybe_null_success_yield, struct task_struct *from,
  16. struct task_struct *to)
  17. {
  18. if (to)
  19. bpf_printk("Yielding to %s[%d]", to->comm, to->pid);
  20. return false;
  21. }
  22. SEC(".struct_ops.link")
  23. struct sched_ext_ops maybe_null_success = {
  24. .dispatch = (void *) maybe_null_success_dispatch,
  25. .yield = (void *) maybe_null_success_yield,
  26. .enable = (void *) maybe_null_running,
  27. .name = "minimal",
  28. };