select_cpu_vtime.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2024 Meta Platforms, Inc. and affiliates.
  4. * Copyright (c) 2024 David Vernet <dvernet@meta.com>
  5. * Copyright (c) 2024 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_vtime.bpf.skel.h"
  12. #include "scx_test.h"
  13. static enum scx_test_status setup(void **ctx)
  14. {
  15. struct select_cpu_vtime *skel;
  16. skel = select_cpu_vtime__open_and_load();
  17. SCX_FAIL_IF(!skel, "Failed to open and load skel");
  18. *ctx = skel;
  19. return SCX_TEST_PASS;
  20. }
  21. static enum scx_test_status run(void *ctx)
  22. {
  23. struct select_cpu_vtime *skel = ctx;
  24. struct bpf_link *link;
  25. SCX_ASSERT(!skel->bss->consumed);
  26. link = bpf_map__attach_struct_ops(skel->maps.select_cpu_vtime_ops);
  27. SCX_FAIL_IF(!link, "Failed to attach scheduler");
  28. sleep(1);
  29. SCX_ASSERT(skel->bss->consumed);
  30. bpf_link__destroy(link);
  31. return SCX_TEST_PASS;
  32. }
  33. static void cleanup(void *ctx)
  34. {
  35. struct select_cpu_vtime *skel = ctx;
  36. select_cpu_vtime__destroy(skel);
  37. }
  38. struct scx_test select_cpu_vtime = {
  39. .name = "select_cpu_vtime",
  40. .description = "Test doing direct vtime-dispatching from "
  41. "ops.select_cpu(), to a non-built-in DSQ",
  42. .setup = setup,
  43. .run = run,
  44. .cleanup = cleanup,
  45. };
  46. REGISTER_SCX_TEST(&select_cpu_vtime)