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