select_cpu_dfl.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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_dfl.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_dfl *skel;
  17. skel = select_cpu_dfl__open();
  18. SCX_FAIL_IF(!skel, "Failed to open");
  19. SCX_ENUM_INIT(skel);
  20. SCX_FAIL_IF(select_cpu_dfl__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_dfl *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_dfl_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. SCX_ASSERT(!skel->bss->saw_local);
  44. bpf_link__destroy(link);
  45. return SCX_TEST_PASS;
  46. }
  47. static void cleanup(void *ctx)
  48. {
  49. struct select_cpu_dfl *skel = ctx;
  50. select_cpu_dfl__destroy(skel);
  51. }
  52. struct scx_test select_cpu_dfl = {
  53. .name = "select_cpu_dfl",
  54. .description = "Verify the default ops.select_cpu() dispatches tasks "
  55. "when idles cores are found, and skips ops.enqueue()",
  56. .setup = setup,
  57. .run = run,
  58. .cleanup = cleanup,
  59. };
  60. REGISTER_SCX_TEST(&select_cpu_dfl)