select_cpu_dfl.c 1.5 KB

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