leafloop.c 749 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #include <signal.h>
  3. #include <stdlib.h>
  4. #include <linux/compiler.h>
  5. #include <unistd.h>
  6. #include "../tests.h"
  7. /* We want to check these symbols in perf script */
  8. noinline void leaf(volatile int b);
  9. noinline void parent(volatile int b);
  10. static volatile int a;
  11. static volatile sig_atomic_t done;
  12. static void sighandler(int sig __maybe_unused)
  13. {
  14. done = 1;
  15. }
  16. noinline void leaf(volatile int b)
  17. {
  18. while (!done)
  19. a += b;
  20. }
  21. noinline void parent(volatile int b)
  22. {
  23. leaf(b);
  24. }
  25. static int leafloop(int argc, const char **argv)
  26. {
  27. int sec = 1;
  28. if (argc > 0)
  29. sec = atoi(argv[0]);
  30. signal(SIGINT, sighandler);
  31. signal(SIGALRM, sighandler);
  32. alarm(sec);
  33. parent(sec);
  34. return 0;
  35. }
  36. DEFINE_WORKLOAD(leafloop);