169b35292SNamhyung Kim /* SPDX-License-Identifier: GPL-2.0 */ 269b35292SNamhyung Kim #include <pthread.h> 369b35292SNamhyung Kim #include <stdlib.h> 469b35292SNamhyung Kim #include <signal.h> 569b35292SNamhyung Kim #include <unistd.h> 669b35292SNamhyung Kim #include <linux/compiler.h> 769b35292SNamhyung Kim #include "../tests.h" 869b35292SNamhyung Kim 969b35292SNamhyung Kim static volatile sig_atomic_t done; 1069b35292SNamhyung Kim 1169b35292SNamhyung Kim /* We want to check this symbol in perf report */ 1269b35292SNamhyung Kim noinline void test_loop(void); 1369b35292SNamhyung Kim 1469b35292SNamhyung Kim static void sighandler(int sig __maybe_unused) 1569b35292SNamhyung Kim { 1669b35292SNamhyung Kim done = 1; 1769b35292SNamhyung Kim } 1869b35292SNamhyung Kim 1969b35292SNamhyung Kim noinline void test_loop(void) 2069b35292SNamhyung Kim { 21*72b4ca7eSNick Forrington while (!done); 2269b35292SNamhyung Kim } 2369b35292SNamhyung Kim 2469b35292SNamhyung Kim static void *thfunc(void *arg) 2569b35292SNamhyung Kim { 2669b35292SNamhyung Kim void (*loop_fn)(void) = arg; 2769b35292SNamhyung Kim 2869b35292SNamhyung Kim loop_fn(); 2969b35292SNamhyung Kim return NULL; 3069b35292SNamhyung Kim } 3169b35292SNamhyung Kim 3269b35292SNamhyung Kim static int thloop(int argc, const char **argv) 3369b35292SNamhyung Kim { 3469b35292SNamhyung Kim int sec = 1; 3569b35292SNamhyung Kim pthread_t th; 3669b35292SNamhyung Kim 3769b35292SNamhyung Kim if (argc > 0) 3869b35292SNamhyung Kim sec = atoi(argv[0]); 3969b35292SNamhyung Kim 4069b35292SNamhyung Kim signal(SIGINT, sighandler); 4169b35292SNamhyung Kim signal(SIGALRM, sighandler); 4269b35292SNamhyung Kim alarm(sec); 4369b35292SNamhyung Kim 4469b35292SNamhyung Kim pthread_create(&th, NULL, thfunc, test_loop); 4569b35292SNamhyung Kim test_loop(); 4669b35292SNamhyung Kim pthread_join(th, NULL); 4769b35292SNamhyung Kim 4869b35292SNamhyung Kim return 0; 4969b35292SNamhyung Kim } 5069b35292SNamhyung Kim 5169b35292SNamhyung Kim DEFINE_WORKLOAD(thloop); 52