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 9 static volatile sig_atomic_t done; 10 11 /* We want to check this symbol in perf report */ 12 noinline void test_loop(void); 13 sighandler(int sig __maybe_unused)14static void sighandler(int sig __maybe_unused) 15 { 16 done = 1; 17 } 18 test_loop(void)19noinline void test_loop(void) 20 { 21 while (!done); 22 } 23 thfunc(void * arg)24static void *thfunc(void *arg) 25 { 26 void (*loop_fn)(void) = arg; 27 28 loop_fn(); 29 return NULL; 30 } 31 thloop(int argc,const char ** argv)32static int thloop(int argc, const char **argv) 33 { 34 int sec = 1; 35 pthread_t th; 36 37 if (argc > 0) 38 sec = atoi(argv[0]); 39 40 signal(SIGINT, sighandler); 41 signal(SIGALRM, sighandler); 42 alarm(sec); 43 44 pthread_create(&th, NULL, thfunc, test_loop); 45 test_loop(); 46 pthread_join(th, NULL); 47 48 return 0; 49 } 50 51 DEFINE_WORKLOAD(thloop); 52