xref: /linux/tools/perf/tests/workloads/leafloop.c (revision ff16aeb9b83441b8458d4235496cf320189a0c60)
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 
15*ff16aeb9SJames Clark static void sighandler(int sig __maybe_unused)
16*ff16aeb9SJames Clark {
17*ff16aeb9SJames Clark 	done = 1;
18*ff16aeb9SJames Clark }
1941522f74SNamhyung Kim 
2041522f74SNamhyung Kim noinline void leaf(volatile int b)
2141522f74SNamhyung Kim {
22*ff16aeb9SJames Clark 	while (!done)
2341522f74SNamhyung Kim 		a += b;
2441522f74SNamhyung Kim }
2541522f74SNamhyung Kim 
2641522f74SNamhyung Kim noinline void parent(volatile int b)
2741522f74SNamhyung Kim {
2841522f74SNamhyung Kim 	leaf(b);
2941522f74SNamhyung Kim }
3041522f74SNamhyung Kim 
3141522f74SNamhyung Kim static 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