blob: c20c75f7ba49ec591229947db8aa561399141363 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
/* SPDX-License-Identifier: GPL-2.0 */
#include <signal.h>
#include <stdlib.h>
#include <linux/compiler.h>
#include <unistd.h>
#include "../tests.h"
/* We want to check these symbols in perf script */
noinline void leaf(void);
noinline void parent(void);
static volatile sig_atomic_t done asm("leafloop_done");
static void sighandler(int sig __maybe_unused)
{
done = 1;
}
#if defined(__aarch64__)
/*
* Write leaf() in assembly so it stays as a minimal leaf function with no
* stack frame and won't get silently broken in the future by any Perf wide
* compilation options like -fstack-protector-all.
*/
asm(
".pushsection .text,\"ax\",%progbits\n"
".global leaf\n"
".type leaf, %function\n"
"leaf:\n"
" adrp x1, leafloop_done\n"
" ldr w2, [x1, #:lo12:leafloop_done]\n"
" cbz w2, leaf\n"
" ret\n"
".size leaf, .-leaf\n"
".popsection\n"
);
#else
noinline void leaf(void)
{
while (!done)
;
}
#endif
noinline void parent(void)
{
leaf();
}
static int leafloop(int argc, const char **argv)
{
int sec = 1;
if (argc > 0)
sec = atoi(argv[0]);
signal(SIGINT, sighandler);
signal(SIGALRM, sighandler);
alarm(sec);
parent();
return 0;
}
DEFINE_WORKLOAD(leafloop);
|