141522f74SNamhyung Kim /* SPDX-License-Identifier: GPL-2.0 */ 2*ff16aeb9SJames Clark #include <signal.h> 341522f74SNamhyung Kim #include <stdlib.h> 441522f74SNamhyung Kim #include <linux/compiler.h> 5*ff16aeb9SJames Clark #include <unistd.h> 641522f74SNamhyung Kim #include "../tests.h" 741522f74SNamhyung Kim 841522f74SNamhyung Kim /* We want to check these symbols in perf script */ 941522f74SNamhyung Kim noinline void leaf(volatile int b); 1041522f74SNamhyung Kim noinline void parent(volatile int b); 1141522f74SNamhyung Kim 1241522f74SNamhyung Kim static volatile int a; 13*ff16aeb9SJames Clark static volatile sig_atomic_t done; 14*ff16aeb9SJames Clark sighandler(int sig __maybe_unused)15*ff16aeb9SJames Clarkstatic void sighandler(int sig __maybe_unused) 16*ff16aeb9SJames Clark { 17*ff16aeb9SJames Clark done = 1; 18*ff16aeb9SJames Clark } 1941522f74SNamhyung Kim leaf(volatile int b)2041522f74SNamhyung Kimnoinline void leaf(volatile int b) 2141522f74SNamhyung Kim { 22*ff16aeb9SJames Clark while (!done) 2341522f74SNamhyung Kim a += b; 2441522f74SNamhyung Kim } 2541522f74SNamhyung Kim parent(volatile int b)2641522f74SNamhyung Kimnoinline void parent(volatile int b) 2741522f74SNamhyung Kim { 2841522f74SNamhyung Kim leaf(b); 2941522f74SNamhyung Kim } 3041522f74SNamhyung Kim leafloop(int argc,const char ** argv)3141522f74SNamhyung Kimstatic int leafloop(int argc, const char **argv) 3241522f74SNamhyung Kim { 33*ff16aeb9SJames Clark int sec = 1; 3441522f74SNamhyung Kim 3541522f74SNamhyung Kim if (argc > 0) 36*ff16aeb9SJames Clark sec = atoi(argv[0]); 3741522f74SNamhyung Kim 38*ff16aeb9SJames Clark signal(SIGINT, sighandler); 39*ff16aeb9SJames Clark signal(SIGALRM, sighandler); 40*ff16aeb9SJames Clark alarm(sec); 41*ff16aeb9SJames Clark 42*ff16aeb9SJames Clark parent(sec); 4341522f74SNamhyung Kim return 0; 4441522f74SNamhyung Kim } 4541522f74SNamhyung Kim 4641522f74SNamhyung Kim DEFINE_WORKLOAD(leafloop); 47