perf: Enable building perf tools for Meta
[firefly-linux-kernel-4.4.55.git] / tools / perf / perf.h
1 #ifndef _PERF_PERF_H
2 #define _PERF_PERF_H
3
4 struct winsize;
5
6 void get_term_dimensions(struct winsize *ws);
7
8 #include <asm/unistd.h>
9
10 #if defined(__i386__)
11 #define rmb()           asm volatile("lock; addl $0,0(%%esp)" ::: "memory")
12 #define cpu_relax()     asm volatile("rep; nop" ::: "memory");
13 #define CPUINFO_PROC    "model name"
14 #ifndef __NR_perf_event_open
15 # define __NR_perf_event_open 336
16 #endif
17 #endif
18
19 #if defined(__x86_64__)
20 #define rmb()           asm volatile("lfence" ::: "memory")
21 #define cpu_relax()     asm volatile("rep; nop" ::: "memory");
22 #define CPUINFO_PROC    "model name"
23 #ifndef __NR_perf_event_open
24 # define __NR_perf_event_open 298
25 #endif
26 #endif
27
28 #ifdef __powerpc__
29 #include "../../arch/powerpc/include/uapi/asm/unistd.h"
30 #define rmb()           asm volatile ("sync" ::: "memory")
31 #define cpu_relax()     asm volatile ("" ::: "memory");
32 #define CPUINFO_PROC    "cpu"
33 #endif
34
35 #ifdef __s390__
36 #define rmb()           asm volatile("bcr 15,0" ::: "memory")
37 #define cpu_relax()     asm volatile("" ::: "memory");
38 #endif
39
40 #ifdef __sh__
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")
47 #define CPUINFO_PROC    "cpu type"
48 #endif
49
50 #ifdef __hppa__
51 #define rmb()           asm volatile("" ::: "memory")
52 #define cpu_relax()     asm volatile("" ::: "memory");
53 #define CPUINFO_PROC    "cpu"
54 #endif
55
56 #ifdef __sparc__
57 #define rmb()           asm volatile("":::"memory")
58 #define cpu_relax()     asm volatile("":::"memory")
59 #define CPUINFO_PROC    "cpu"
60 #endif
61
62 #ifdef __alpha__
63 #define rmb()           asm volatile("mb" ::: "memory")
64 #define cpu_relax()     asm volatile("" ::: "memory")
65 #define CPUINFO_PROC    "cpu model"
66 #endif
67
68 #ifdef __ia64__
69 #define rmb()           asm volatile ("mf" ::: "memory")
70 #define cpu_relax()     asm volatile ("hint @pause" ::: "memory")
71 #define CPUINFO_PROC    "model name"
72 #endif
73
74 #ifdef __arm__
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  */
79 #define rmb()           ((void(*)(void))0xffff0fa0)()
80 #define cpu_relax()     asm volatile("":::"memory")
81 #define CPUINFO_PROC    "Processor"
82 #endif
83
84 #ifdef __aarch64__
85 #define rmb()           asm volatile("dmb ld" ::: "memory")
86 #define cpu_relax()     asm volatile("yield" ::: "memory")
87 #endif
88
89 #ifdef __mips__
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")
98 #define CPUINFO_PROC    "cpu model"
99 #endif
100
101 #ifdef __metag__
102 #define rmb()           asm volatile("" ::: "memory")
103 #define cpu_relax()     asm volatile("" ::: "memory")
104 #define CPUINFO_PROC    "CPU"
105 #endif
106
107 #include <time.h>
108 #include <unistd.h>
109 #include <sys/types.h>
110 #include <sys/syscall.h>
111
112 #include <linux/perf_event.h>
113 #include "util/types.h"
114 #include <stdbool.h>
115
116 struct perf_mmap {
117         void                    *base;
118         int                     mask;
119         unsigned int            prev;
120 };
121
122 static inline unsigned int perf_mmap__read_head(struct perf_mmap *mm)
123 {
124         struct perf_event_mmap_page *pc = mm->base;
125         int head = pc->data_head;
126         rmb();
127         return head;
128 }
129
130 static inline void perf_mmap__write_tail(struct perf_mmap *md,
131                                          unsigned long tail)
132 {
133         struct perf_event_mmap_page *pc = md->base;
134
135         /*
136          * ensure all reads are done before we write the tail out.
137          */
138         /* mb(); */
139         pc->data_tail = tail;
140 }
141
142 /*
143  * prctl(PR_TASK_PERF_EVENTS_DISABLE) will (cheaply) disable all
144  * counters in the current task.
145  */
146 #define PR_TASK_PERF_EVENTS_DISABLE   31
147 #define PR_TASK_PERF_EVENTS_ENABLE    32
148
149 #ifndef NSEC_PER_SEC
150 # define NSEC_PER_SEC                   1000000000ULL
151 #endif
152
153 static inline unsigned long long rdclock(void)
154 {
155         struct timespec ts;
156
157         clock_gettime(CLOCK_MONOTONIC, &ts);
158         return ts.tv_sec * 1000000000ULL + ts.tv_nsec;
159 }
160
161 /*
162  * Pick up some kernel type conventions:
163  */
164 #define __user
165 #define asmlinkage
166
167 #define unlikely(x)     __builtin_expect(!!(x), 0)
168 #define min(x, y) ({                            \
169         typeof(x) _min1 = (x);                  \
170         typeof(y) _min2 = (y);                  \
171         (void) (&_min1 == &_min2);              \
172         _min1 < _min2 ? _min1 : _min2; })
173
174 extern bool test_attr__enabled;
175 void test_attr__init(void);
176 void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu,
177                      int fd, int group_fd, unsigned long flags);
178
179 static inline int
180 sys_perf_event_open(struct perf_event_attr *attr,
181                       pid_t pid, int cpu, int group_fd,
182                       unsigned long flags)
183 {
184         int fd;
185
186         fd = syscall(__NR_perf_event_open, attr, pid, cpu,
187                      group_fd, flags);
188
189         if (unlikely(test_attr__enabled))
190                 test_attr__open(attr, pid, cpu, fd, group_fd, flags);
191
192         return fd;
193 }
194
195 #define MAX_COUNTERS                    256
196 #define MAX_NR_CPUS                     256
197
198 struct ip_callchain {
199         u64 nr;
200         u64 ips[0];
201 };
202
203 struct branch_flags {
204         u64 mispred:1;
205         u64 predicted:1;
206         u64 reserved:62;
207 };
208
209 struct branch_entry {
210         u64                             from;
211         u64                             to;
212         struct branch_flags flags;
213 };
214
215 struct branch_stack {
216         u64                             nr;
217         struct branch_entry     entries[0];
218 };
219
220 extern const char *input_name;
221 extern bool perf_host, perf_guest;
222 extern const char perf_version_string[];
223
224 void pthread__unblock_sigwinch(void);
225
226 #include "util/target.h"
227
228 enum perf_call_graph_mode {
229         CALLCHAIN_NONE,
230         CALLCHAIN_FP,
231         CALLCHAIN_DWARF
232 };
233
234 struct perf_record_opts {
235         struct perf_target target;
236         int          call_graph;
237         bool         group;
238         bool         inherit_stat;
239         bool         no_delay;
240         bool         no_inherit;
241         bool         no_samples;
242         bool         pipe_output;
243         bool         raw_samples;
244         bool         sample_address;
245         bool         sample_time;
246         bool         sample_id_all_missing;
247         bool         exclude_guest_missing;
248         bool         period;
249         unsigned int freq;
250         unsigned int mmap_pages;
251         unsigned int user_freq;
252         u64          branch_stack;
253         u64          default_interval;
254         u64          user_interval;
255         u16          stack_dump_size;
256 };
257
258 #endif