xref: /linux/tools/perf/tests/workloads/callchain.c (revision 67f8bc848ee31831336bd478e57d2f993551902e)
1*ca0e1907SLeo Yan // SPDX-License-Identifier: GPL-2.0
2*ca0e1907SLeo Yan #include <linux/compiler.h>
3*ca0e1907SLeo Yan #include <sys/syscall.h>
4*ca0e1907SLeo Yan #include <unistd.h>
5*ca0e1907SLeo Yan #include "../tests.h"
6*ca0e1907SLeo Yan 
7*ca0e1907SLeo Yan /*
8*ca0e1907SLeo Yan  * Mark as noinline to establish the call chain, and avoid the static
9*ca0e1907SLeo Yan  * annotation to prevent LTO from renaming the functions.
10*ca0e1907SLeo Yan  */
11*ca0e1907SLeo Yan noinline void callchain_do_syscall(void);
12*ca0e1907SLeo Yan noinline void callchain_foo(void);
13*ca0e1907SLeo Yan noinline int callchain(int argc, const char **argv);
14*ca0e1907SLeo Yan 
15*ca0e1907SLeo Yan noinline void callchain_do_syscall(void)
16*ca0e1907SLeo Yan {
17*ca0e1907SLeo Yan 	syscall(SYS_gettid);
18*ca0e1907SLeo Yan }
19*ca0e1907SLeo Yan 
20*ca0e1907SLeo Yan noinline void callchain_foo(void)
21*ca0e1907SLeo Yan {
22*ca0e1907SLeo Yan 	callchain_do_syscall();
23*ca0e1907SLeo Yan }
24*ca0e1907SLeo Yan 
25*ca0e1907SLeo Yan noinline int callchain(int argc __maybe_unused,
26*ca0e1907SLeo Yan 		       const char **argv __maybe_unused)
27*ca0e1907SLeo Yan {
28*ca0e1907SLeo Yan 	callchain_foo();
29*ca0e1907SLeo Yan 
30*ca0e1907SLeo Yan 	return 0;
31*ca0e1907SLeo Yan }
32*ca0e1907SLeo Yan 
33*ca0e1907SLeo Yan DEFINE_WORKLOAD(callchain);
34