select_cpu_dispatch.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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();
  18. SCX_FAIL_IF(!skel, "Failed to open");
  19. SCX_ENUM_INIT(skel);
  20. SCX_FAIL_IF(select_cpu_dispatch__load(skel), "Failed to load skel");
  21. *ctx = skel;
  22. return SCX_TEST_PASS;
  23. }
  24. static enum scx_test_status run(void *ctx)
  25. {
  26. struct select_cpu_dispatch *skel = ctx;
  27. struct bpf_link *link;
  28. pid_t pids[NUM_CHILDREN];
  29. int i, status;
  30. link = bpf_map__attach_struct_ops(skel->maps.select_cpu_dispatch_ops);
  31. SCX_FAIL_IF(!link, "Failed to attach scheduler");
  32. for (i = 0; i < NUM_CHILDREN; i++) {
  33. pids[i] = fork();
  34. if (pids[i] == 0) {
  35. sleep(1);
  36. exit(0);
  37. }
  38. }
  39. for (i = 0; i < NUM_CHILDREN; i++) {
  40. SCX_EQ(waitpid(pids[i], &status, 0), pids[i]);
  41. SCX_EQ(status, 0);
  42. }
  43. bpf_link__destroy(link);
  44. return SCX_TEST_PASS;
  45. }
  46. static void cleanup(void *ctx)
  47. {
  48. struct select_cpu_dispatch *skel = ctx;
  49. select_cpu_dispatch__destroy(skel);
  50. }
  51. struct scx_test select_cpu_dispatch = {
  52. .name = "select_cpu_dispatch",
  53. .description = "Test direct dispatching to built-in DSQs from "
  54. "ops.select_cpu()",
  55. .setup = setup,
  56. .run = run,
  57. .cleanup = cleanup,
  58. };
  59. REGISTER_SCX_TEST(&select_cpu_dispatch)