reload_loop.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. */
  6. #include <bpf/bpf.h>
  7. #include <pthread.h>
  8. #include <scx/common.h>
  9. #include <sys/wait.h>
  10. #include <unistd.h>
  11. #include "maximal.bpf.skel.h"
  12. #include "scx_test.h"
  13. static struct maximal *skel;
  14. static pthread_t threads[2];
  15. bool force_exit = false;
  16. static enum scx_test_status setup(void **ctx)
  17. {
  18. skel = maximal__open();
  19. SCX_FAIL_IF(!skel, "Failed to open");
  20. SCX_ENUM_INIT(skel);
  21. SCX_FAIL_IF(maximal__load(skel), "Failed to load skel");
  22. return SCX_TEST_PASS;
  23. }
  24. static void *do_reload_loop(void *arg)
  25. {
  26. u32 i;
  27. for (i = 0; i < 1024 && !force_exit; i++) {
  28. struct bpf_link *link;
  29. link = bpf_map__attach_struct_ops(skel->maps.maximal_ops);
  30. if (link)
  31. bpf_link__destroy(link);
  32. }
  33. return NULL;
  34. }
  35. static enum scx_test_status run(void *ctx)
  36. {
  37. int err;
  38. void *ret;
  39. err = pthread_create(&threads[0], NULL, do_reload_loop, NULL);
  40. SCX_FAIL_IF(err, "Failed to create thread 0");
  41. err = pthread_create(&threads[1], NULL, do_reload_loop, NULL);
  42. SCX_FAIL_IF(err, "Failed to create thread 1");
  43. SCX_FAIL_IF(pthread_join(threads[0], &ret), "thread 0 failed");
  44. SCX_FAIL_IF(pthread_join(threads[1], &ret), "thread 1 failed");
  45. return SCX_TEST_PASS;
  46. }
  47. static void cleanup(void *ctx)
  48. {
  49. force_exit = true;
  50. maximal__destroy(skel);
  51. }
  52. struct scx_test reload_loop = {
  53. .name = "reload_loop",
  54. .description = "Stress test loading and unloading schedulers repeatedly in a tight loop",
  55. .setup = setup,
  56. .run = run,
  57. .cleanup = cleanup,
  58. };
  59. REGISTER_SCX_TEST(&reload_loop)