hotplug.bpf.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2024 Meta Platforms, Inc. and affiliates.
  4. * Copyright (c) 2024 David Vernet <dvernet@meta.com>
  5. */
  6. #include <scx/common.bpf.h>
  7. char _license[] SEC("license") = "GPL";
  8. #include "hotplug_test.h"
  9. UEI_DEFINE(uei);
  10. void BPF_STRUCT_OPS(hotplug_exit, struct scx_exit_info *ei)
  11. {
  12. UEI_RECORD(uei, ei);
  13. }
  14. static void exit_from_hotplug(s32 cpu, bool onlining)
  15. {
  16. /*
  17. * Ignored, just used to verify that we can invoke blocking kfuncs
  18. * from the hotplug path.
  19. */
  20. scx_bpf_create_dsq(0, -1);
  21. s64 code = SCX_ECODE_ACT_RESTART | HOTPLUG_EXIT_RSN;
  22. if (onlining)
  23. code |= HOTPLUG_ONLINING;
  24. scx_bpf_exit(code, "hotplug event detected (%d going %s)", cpu,
  25. onlining ? "online" : "offline");
  26. }
  27. void BPF_STRUCT_OPS_SLEEPABLE(hotplug_cpu_online, s32 cpu)
  28. {
  29. exit_from_hotplug(cpu, true);
  30. }
  31. void BPF_STRUCT_OPS_SLEEPABLE(hotplug_cpu_offline, s32 cpu)
  32. {
  33. exit_from_hotplug(cpu, false);
  34. }
  35. SEC(".struct_ops.link")
  36. struct sched_ext_ops hotplug_cb_ops = {
  37. .cpu_online = (void *) hotplug_cpu_online,
  38. .cpu_offline = (void *) hotplug_cpu_offline,
  39. .exit = (void *) hotplug_exit,
  40. .name = "hotplug_cbs",
  41. .timeout_ms = 1000U,
  42. };
  43. SEC(".struct_ops.link")
  44. struct sched_ext_ops hotplug_nocb_ops = {
  45. .exit = (void *) hotplug_exit,
  46. .name = "hotplug_nocbs",
  47. .timeout_ms = 1000U,
  48. };