Commit | Line | Data |
---|---|---|
6eda5838 TG |
1 | #ifndef _PERF_PERF_H |
2 | #define _PERF_PERF_H | |
3 | ||
d2709c7c DH |
4 | #include <asm/unistd.h> |
5 | ||
11d1578f | 6 | #if defined(__i386__) |
11d1578f VW |
7 | #define rmb() asm volatile("lock; addl $0,0(%%esp)" ::: "memory") |
8 | #define cpu_relax() asm volatile("rep; nop" ::: "memory"); | |
fbe96f29 | 9 | #define CPUINFO_PROC "model name" |
eae7a755 IM |
10 | #ifndef __NR_perf_event_open |
11 | # define __NR_perf_event_open 336 | |
12 | #endif | |
11d1578f VW |
13 | #endif |
14 | ||
15 | #if defined(__x86_64__) | |
1a482f38 PZ |
16 | #define rmb() asm volatile("lfence" ::: "memory") |
17 | #define cpu_relax() asm volatile("rep; nop" ::: "memory"); | |
fbe96f29 | 18 | #define CPUINFO_PROC "model name" |
eae7a755 IM |
19 | #ifndef __NR_perf_event_open |
20 | # define __NR_perf_event_open 298 | |
21 | #endif | |
1a482f38 PZ |
22 | #endif |
23 | ||
24 | #ifdef __powerpc__ | |
1483c2ae | 25 | #include "../../arch/powerpc/include/uapi/asm/unistd.h" |
1a482f38 PZ |
26 | #define rmb() asm volatile ("sync" ::: "memory") |
27 | #define cpu_relax() asm volatile ("" ::: "memory"); | |
fbe96f29 | 28 | #define CPUINFO_PROC "cpu" |
1a482f38 PZ |
29 | #endif |
30 | ||
12310e9c | 31 | #ifdef __s390__ |
12310e9c MS |
32 | #define rmb() asm volatile("bcr 15,0" ::: "memory") |
33 | #define cpu_relax() asm volatile("" ::: "memory"); | |
34 | #endif | |
35 | ||
febe8345 | 36 | #ifdef __sh__ |
febe8345 PM |
37 | #if defined(__SH4A__) || defined(__SH5__) |
38 | # define rmb() asm volatile("synco" ::: "memory") | |
39 | #else | |
40 | # define rmb() asm volatile("" ::: "memory") | |
41 | #endif | |
42 | #define cpu_relax() asm volatile("" ::: "memory") | |
fbe96f29 | 43 | #define CPUINFO_PROC "cpu type" |
febe8345 PM |
44 | #endif |
45 | ||
2d4618dc | 46 | #ifdef __hppa__ |
2d4618dc KM |
47 | #define rmb() asm volatile("" ::: "memory") |
48 | #define cpu_relax() asm volatile("" ::: "memory"); | |
fbe96f29 | 49 | #define CPUINFO_PROC "cpu" |
2d4618dc KM |
50 | #endif |
51 | ||
825c9fb4 | 52 | #ifdef __sparc__ |
825c9fb4 JA |
53 | #define rmb() asm volatile("":::"memory") |
54 | #define cpu_relax() asm volatile("":::"memory") | |
fbe96f29 | 55 | #define CPUINFO_PROC "cpu" |
825c9fb4 JA |
56 | #endif |
57 | ||
fcd14b32 | 58 | #ifdef __alpha__ |
fcd14b32 MC |
59 | #define rmb() asm volatile("mb" ::: "memory") |
60 | #define cpu_relax() asm volatile("" ::: "memory") | |
fbe96f29 | 61 | #define CPUINFO_PROC "cpu model" |
fcd14b32 MC |
62 | #endif |
63 | ||
11ada26c | 64 | #ifdef __ia64__ |
11ada26c LT |
65 | #define rmb() asm volatile ("mf" ::: "memory") |
66 | #define cpu_relax() asm volatile ("hint @pause" ::: "memory") | |
fbe96f29 | 67 | #define CPUINFO_PROC "model name" |
11ada26c LT |
68 | #endif |
69 | ||
58e9f941 | 70 | #ifdef __arm__ |
58e9f941 JI |
71 | /* |
72 | * Use the __kuser_memory_barrier helper in the CPU helper page. See | |
73 | * arch/arm/kernel/entry-armv.S in the kernel source for details. | |
74 | */ | |
da7196e1 | 75 | #define rmb() ((void(*)(void))0xffff0fa0)() |
58e9f941 | 76 | #define cpu_relax() asm volatile("":::"memory") |
fbe96f29 | 77 | #define CPUINFO_PROC "Processor" |
58e9f941 JI |
78 | #endif |
79 | ||
03089688 | 80 | #ifdef __aarch64__ |
03089688 WD |
81 | #define rmb() asm volatile("dmb ld" ::: "memory") |
82 | #define cpu_relax() asm volatile("yield" ::: "memory") | |
83 | #endif | |
84 | ||
c1e028ef | 85 | #ifdef __mips__ |
c1e028ef DCZ |
86 | #define rmb() asm volatile( \ |
87 | ".set mips2\n\t" \ | |
88 | "sync\n\t" \ | |
89 | ".set mips0" \ | |
90 | : /* no output */ \ | |
91 | : /* no input */ \ | |
92 | : "memory") | |
93 | #define cpu_relax() asm volatile("" ::: "memory") | |
fbe96f29 | 94 | #define CPUINFO_PROC "cpu model" |
c1e028ef DCZ |
95 | #endif |
96 | ||
9854783e VG |
97 | #ifdef __arc__ |
98 | #define rmb() asm volatile("" ::: "memory") | |
99 | #define cpu_relax() rmb() | |
100 | #define CPUINFO_PROC "Processor" | |
101 | #endif | |
102 | ||
1bea5b81 JH |
103 | #ifdef __metag__ |
104 | #define rmb() asm volatile("" ::: "memory") | |
105 | #define cpu_relax() asm volatile("" ::: "memory") | |
106 | #define CPUINFO_PROC "CPU" | |
107 | #endif | |
108 | ||
1a482f38 PZ |
109 | #include <time.h> |
110 | #include <unistd.h> | |
111 | #include <sys/types.h> | |
112 | #include <sys/syscall.h> | |
113 | ||
d2709c7c | 114 | #include <linux/perf_event.h> |
7c6a1c65 | 115 | #include "util/types.h" |
8035458f | 116 | #include <stdbool.h> |
1a482f38 | 117 | |
6eda5838 | 118 | /* |
cdd6c482 | 119 | * prctl(PR_TASK_PERF_EVENTS_DISABLE) will (cheaply) disable all |
6eda5838 TG |
120 | * counters in the current task. |
121 | */ | |
cdd6c482 IM |
122 | #define PR_TASK_PERF_EVENTS_DISABLE 31 |
123 | #define PR_TASK_PERF_EVENTS_ENABLE 32 | |
6eda5838 | 124 | |
a92e7023 TG |
125 | #ifndef NSEC_PER_SEC |
126 | # define NSEC_PER_SEC 1000000000ULL | |
127 | #endif | |
128 | ||
129 | static inline unsigned long long rdclock(void) | |
130 | { | |
131 | struct timespec ts; | |
132 | ||
133 | clock_gettime(CLOCK_MONOTONIC, &ts); | |
134 | return ts.tv_sec * 1000000000ULL + ts.tv_nsec; | |
135 | } | |
6eda5838 TG |
136 | |
137 | /* | |
138 | * Pick up some kernel type conventions: | |
139 | */ | |
140 | #define __user | |
141 | #define asmlinkage | |
142 | ||
6eda5838 TG |
143 | #define unlikely(x) __builtin_expect(!!(x), 0) |
144 | #define min(x, y) ({ \ | |
145 | typeof(x) _min1 = (x); \ | |
146 | typeof(y) _min2 = (y); \ | |
147 | (void) (&_min1 == &_min2); \ | |
148 | _min1 < _min2 ? _min1 : _min2; }) | |
149 | ||
52502bf2 JO |
150 | extern bool test_attr__enabled; |
151 | void test_attr__init(void); | |
152 | void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu, | |
153 | int fd, int group_fd, unsigned long flags); | |
154 | ||
6eda5838 | 155 | static inline int |
cdd6c482 | 156 | sys_perf_event_open(struct perf_event_attr *attr, |
6eda5838 TG |
157 | pid_t pid, int cpu, int group_fd, |
158 | unsigned long flags) | |
159 | { | |
52502bf2 JO |
160 | int fd; |
161 | ||
162 | fd = syscall(__NR_perf_event_open, attr, pid, cpu, | |
163 | group_fd, flags); | |
164 | ||
165 | if (unlikely(test_attr__enabled)) | |
166 | test_attr__open(attr, pid, cpu, fd, group_fd, flags); | |
167 | ||
168 | return fd; | |
6eda5838 TG |
169 | } |
170 | ||
85a9f920 IM |
171 | #define MAX_COUNTERS 256 |
172 | #define MAX_NR_CPUS 256 | |
6eda5838 | 173 | |
8cb76d99 FW |
174 | struct ip_callchain { |
175 | u64 nr; | |
176 | u64 ips[0]; | |
f5970550 PZ |
177 | }; |
178 | ||
b5387528 RAV |
179 | struct branch_flags { |
180 | u64 mispred:1; | |
181 | u64 predicted:1; | |
182 | u64 reserved:62; | |
183 | }; | |
184 | ||
185 | struct branch_entry { | |
186 | u64 from; | |
187 | u64 to; | |
188 | struct branch_flags flags; | |
189 | }; | |
190 | ||
191 | struct branch_stack { | |
192 | u64 nr; | |
193 | struct branch_entry entries[0]; | |
194 | }; | |
195 | ||
70cb4e96 | 196 | extern const char *input_name; |
8035458f | 197 | extern bool perf_host, perf_guest; |
fbe96f29 | 198 | extern const char perf_version_string[]; |
a1645ce1 | 199 | |
3af6e338 ACM |
200 | void pthread__unblock_sigwinch(void); |
201 | ||
12864b31 | 202 | #include "util/target.h" |
bea03405 | 203 | |
26d33022 JO |
204 | enum perf_call_graph_mode { |
205 | CALLCHAIN_NONE, | |
206 | CALLCHAIN_FP, | |
207 | CALLCHAIN_DWARF | |
208 | }; | |
209 | ||
bea03405 NK |
210 | struct perf_record_opts { |
211 | struct perf_target target; | |
26d33022 | 212 | int call_graph; |
ed80f581 | 213 | bool group; |
0f82ebc4 ACM |
214 | bool inherit_stat; |
215 | bool no_delay; | |
216 | bool no_inherit; | |
217 | bool no_samples; | |
35b9d88e | 218 | bool pipe_output; |
0f82ebc4 ACM |
219 | bool raw_samples; |
220 | bool sample_address; | |
05484298 | 221 | bool sample_weight; |
0f82ebc4 | 222 | bool sample_time; |
3e76ac78 | 223 | bool period; |
0f82ebc4 | 224 | unsigned int freq; |
01c2d99b | 225 | unsigned int mmap_pages; |
0f82ebc4 | 226 | unsigned int user_freq; |
a00dc319 | 227 | u64 branch_stack; |
0f82ebc4 ACM |
228 | u64 default_interval; |
229 | u64 user_interval; | |
26d33022 | 230 | u16 stack_dump_size; |
0f82ebc4 ACM |
231 | }; |
232 | ||
6eda5838 | 233 | #endif |