xref: /linux/tools/perf/tests/workloads/inlineloop.c (revision c7decec2f2d2ab0366567f9e30c0e1418cece43f)
1*27fc6f56SIan Rogers // SPDX-License-Identifier: GPL-2.0
2*27fc6f56SIan Rogers #include <pthread.h>
3*27fc6f56SIan Rogers #include <stdlib.h>
4*27fc6f56SIan Rogers #include <signal.h>
5*27fc6f56SIan Rogers #include <unistd.h>
6*27fc6f56SIan Rogers #include <linux/compiler.h>
7*27fc6f56SIan Rogers #include "../tests.h"
8*27fc6f56SIan Rogers 
9*27fc6f56SIan Rogers static volatile int a;
10*27fc6f56SIan Rogers static volatile sig_atomic_t done;
11*27fc6f56SIan Rogers 
sighandler(int sig __maybe_unused)12*27fc6f56SIan Rogers static void sighandler(int sig __maybe_unused)
13*27fc6f56SIan Rogers {
14*27fc6f56SIan Rogers 	done = 1;
15*27fc6f56SIan Rogers }
16*27fc6f56SIan Rogers 
leaf(int b)17*27fc6f56SIan Rogers static inline void __attribute__((always_inline)) leaf(int b)
18*27fc6f56SIan Rogers {
19*27fc6f56SIan Rogers again:
20*27fc6f56SIan Rogers 	a += b;
21*27fc6f56SIan Rogers 	if (!done)
22*27fc6f56SIan Rogers 		goto again;
23*27fc6f56SIan Rogers }
24*27fc6f56SIan Rogers 
middle(int b)25*27fc6f56SIan Rogers static inline void __attribute__((always_inline)) middle(int b)
26*27fc6f56SIan Rogers {
27*27fc6f56SIan Rogers 	leaf(b);
28*27fc6f56SIan Rogers }
29*27fc6f56SIan Rogers 
parent(int b)30*27fc6f56SIan Rogers static noinline void parent(int b)
31*27fc6f56SIan Rogers {
32*27fc6f56SIan Rogers 	middle(b);
33*27fc6f56SIan Rogers }
34*27fc6f56SIan Rogers 
inlineloop(int argc,const char ** argv)35*27fc6f56SIan Rogers static int inlineloop(int argc, const char **argv)
36*27fc6f56SIan Rogers {
37*27fc6f56SIan Rogers 	int sec = 1;
38*27fc6f56SIan Rogers 
39*27fc6f56SIan Rogers 	pthread_setname_np(pthread_self(), "perf-inlineloop");
40*27fc6f56SIan Rogers 	if (argc > 0)
41*27fc6f56SIan Rogers 		sec = atoi(argv[0]);
42*27fc6f56SIan Rogers 
43*27fc6f56SIan Rogers 	signal(SIGINT, sighandler);
44*27fc6f56SIan Rogers 	signal(SIGALRM, sighandler);
45*27fc6f56SIan Rogers 	alarm(sec);
46*27fc6f56SIan Rogers 
47*27fc6f56SIan Rogers 	parent(sec);
48*27fc6f56SIan Rogers 
49*27fc6f56SIan Rogers 	return 0;
50*27fc6f56SIan Rogers }
51*27fc6f56SIan Rogers 
52*27fc6f56SIan Rogers DEFINE_WORKLOAD(inlineloop);
53