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