thloop.c 813 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #include <pthread.h>
  3. #include <stdlib.h>
  4. #include <signal.h>
  5. #include <unistd.h>
  6. #include <linux/compiler.h>
  7. #include "../tests.h"
  8. static volatile sig_atomic_t done;
  9. /* We want to check this symbol in perf report */
  10. noinline void test_loop(void);
  11. static void sighandler(int sig __maybe_unused)
  12. {
  13. done = 1;
  14. }
  15. noinline void test_loop(void)
  16. {
  17. while (!done);
  18. }
  19. static void *thfunc(void *arg)
  20. {
  21. void (*loop_fn)(void) = arg;
  22. loop_fn();
  23. return NULL;
  24. }
  25. static int thloop(int argc, const char **argv)
  26. {
  27. int sec = 1;
  28. pthread_t th;
  29. if (argc > 0)
  30. sec = atoi(argv[0]);
  31. signal(SIGINT, sighandler);
  32. signal(SIGALRM, sighandler);
  33. alarm(sec);
  34. pthread_create(&th, NULL, thfunc, test_loop);
  35. test_loop();
  36. pthread_join(th, NULL);
  37. return 0;
  38. }
  39. DEFINE_WORKLOAD(thloop);