select_cpu_dispatch.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2023 Meta Platforms, Inc. and affiliates.
  4. * Copyright (c) 2023 David Vernet <dvernet@meta.com>
  5. * Copyright (c) 2023 Tejun Heo <tj@kernel.org>
  6. */
  7. #include <bpf/bpf.h>
  8. #include <scx/common.h>
  9. #include <sys/wait.h>
  10. #include <unistd.h>
  11. #include "select_cpu_dispatch.bpf.skel.h"
  12. #include "scx_test.h"
  13. #define NUM_CHILDREN 1028
  14. static enum scx_test_status setup(void **ctx)
  15. {
  16. struct select_cpu_dispatch *skel;
  17. skel = select_cpu_dispatch__open_and_load();
  18. SCX_FAIL_IF(!skel, "Failed to open and load skel");
  19. *ctx = skel;
  20. return SCX_TEST_PASS;
  21. }
  22. static enum scx_test_status run(void *ctx)
  23. {
  24. struct select_cpu_dispatch *skel = ctx;
  25. struct bpf_link *link;
  26. pid_t pids[NUM_CHILDREN];
  27. int i, status;
  28. link = bpf_map__attach_struct_ops(skel->maps.select_cpu_dispatch_ops);
  29. SCX_FAIL_IF(!link, "Failed to attach scheduler");
  30. for (i = 0; i < NUM_CHILDREN; i++) {
  31. pids[i] = fork();
  32. if (pids[i] == 0) {
  33. sleep(1);
  34. exit(0);
  35. }
  36. }
  37. for (i = 0; i < NUM_CHILDREN; i++) {
  38. SCX_EQ(waitpid(pids[i], &status, 0), pids[i]);
  39. SCX_EQ(status, 0);
  40. }
  41. bpf_link__destroy(link);
  42. return SCX_TEST_PASS;
  43. }
  44. static void cleanup(void *ctx)
  45. {
  46. struct select_cpu_dispatch *skel = ctx;
  47. select_cpu_dispatch__destroy(skel);
  48. }
  49. struct scx_test select_cpu_dispatch = {
  50. .name = "select_cpu_dispatch",
  51. .description = "Test direct dispatching to built-in DSQs from "
  52. "ops.select_cpu()",
  53. .setup = setup,
  54. .run = run,
  55. .cleanup = cleanup,
  56. };
  57. REGISTER_SCX_TEST(&select_cpu_dispatch)