numa.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2025 Andrea Righi <arighi@nvidia.com>
  4. */
  5. #include <bpf/bpf.h>
  6. #include <scx/common.h>
  7. #include <sys/wait.h>
  8. #include <unistd.h>
  9. #include "numa.bpf.skel.h"
  10. #include "scx_test.h"
  11. static enum scx_test_status setup(void **ctx)
  12. {
  13. struct numa *skel;
  14. skel = numa__open();
  15. SCX_FAIL_IF(!skel, "Failed to open");
  16. SCX_ENUM_INIT(skel);
  17. skel->rodata->__COMPAT_SCX_PICK_IDLE_IN_NODE = SCX_PICK_IDLE_IN_NODE;
  18. skel->struct_ops.numa_ops->flags = SCX_OPS_BUILTIN_IDLE_PER_NODE;
  19. SCX_FAIL_IF(numa__load(skel), "Failed to load skel");
  20. *ctx = skel;
  21. return SCX_TEST_PASS;
  22. }
  23. static enum scx_test_status run(void *ctx)
  24. {
  25. struct numa *skel = ctx;
  26. struct bpf_link *link;
  27. link = bpf_map__attach_struct_ops(skel->maps.numa_ops);
  28. SCX_FAIL_IF(!link, "Failed to attach scheduler");
  29. /* Just sleeping is fine, plenty of scheduling events happening */
  30. sleep(1);
  31. SCX_EQ(skel->data->uei.kind, EXIT_KIND(SCX_EXIT_NONE));
  32. bpf_link__destroy(link);
  33. return SCX_TEST_PASS;
  34. }
  35. static void cleanup(void *ctx)
  36. {
  37. struct numa *skel = ctx;
  38. numa__destroy(skel);
  39. }
  40. struct scx_test numa = {
  41. .name = "numa",
  42. .description = "Verify NUMA-aware functionalities",
  43. .setup = setup,
  44. .run = run,
  45. .cleanup = cleanup,
  46. };
  47. REGISTER_SCX_TEST(&numa)