blob: 469fbf2daea49cfeb86b9bcb1c876cf751929071 [file] [log] [blame]
Thomas Gleixner6eda5832009-05-01 18:29:57 +02001#ifndef _PERF_PERF_H
2#define _PERF_PERF_H
3
Arnaldo Carvalho de Melo895f0ed2010-03-11 20:12:41 -03004struct winsize;
5
6void get_term_dimensions(struct winsize *ws);
7
Vince Weaver11d15782009-07-08 17:46:14 -04008#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");
Stephane Eranianfbe96f22011-09-30 15:40:40 +020012#define CPUINFO_PROC "model name"
Ingo Molnareae7a752012-03-14 12:42:34 -030013#ifndef __NR_perf_event_open
14# define __NR_perf_event_open 336
15#endif
Vince Weaver11d15782009-07-08 17:46:14 -040016#endif
17
18#if defined(__x86_64__)
Peter Zijlstra1a482f32009-05-23 18:28:58 +020019#include "../../arch/x86/include/asm/unistd.h"
20#define rmb() asm volatile("lfence" ::: "memory")
21#define cpu_relax() asm volatile("rep; nop" ::: "memory");
Stephane Eranianfbe96f22011-09-30 15:40:40 +020022#define CPUINFO_PROC "model name"
Ingo Molnareae7a752012-03-14 12:42:34 -030023#ifndef __NR_perf_event_open
24# define __NR_perf_event_open 298
25#endif
Peter Zijlstra1a482f32009-05-23 18:28:58 +020026#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");
Stephane Eranianfbe96f22011-09-30 15:40:40 +020032#define CPUINFO_PROC "cpu"
Peter Zijlstra1a482f32009-05-23 18:28:58 +020033#endif
34
Martin Schwidefsky12310e92009-06-22 12:08:22 +020035#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
Paul Mundtfebe8342009-06-25 14:41:57 +090041#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")
Stephane Eranianfbe96f22011-09-30 15:40:40 +020049#define CPUINFO_PROC "cpu type"
Paul Mundtfebe8342009-06-25 14:41:57 +090050#endif
51
Kyle McMartin2d4618d2009-06-23 21:38:49 -040052#ifdef __hppa__
53#include "../../arch/parisc/include/asm/unistd.h"
54#define rmb() asm volatile("" ::: "memory")
55#define cpu_relax() asm volatile("" ::: "memory");
Stephane Eranianfbe96f22011-09-30 15:40:40 +020056#define CPUINFO_PROC "cpu"
Kyle McMartin2d4618d2009-06-23 21:38:49 -040057#endif
58
Jens Axboe825c9fb2009-09-04 02:56:22 -070059#ifdef __sparc__
David Miller77626082012-10-17 01:06:56 -040060#include "../../arch/sparc/include/uapi/asm/unistd.h"
Jens Axboe825c9fb2009-09-04 02:56:22 -070061#define rmb() asm volatile("":::"memory")
62#define cpu_relax() asm volatile("":::"memory")
Stephane Eranianfbe96f22011-09-30 15:40:40 +020063#define CPUINFO_PROC "cpu"
Jens Axboe825c9fb2009-09-04 02:56:22 -070064#endif
65
Michael Creefcd14b32009-10-26 21:32:06 +130066#ifdef __alpha__
67#include "../../arch/alpha/include/asm/unistd.h"
68#define rmb() asm volatile("mb" ::: "memory")
69#define cpu_relax() asm volatile("" ::: "memory")
Stephane Eranianfbe96f22011-09-30 15:40:40 +020070#define CPUINFO_PROC "cpu model"
Michael Creefcd14b32009-10-26 21:32:06 +130071#endif
72
Luck, Tony11ada262009-11-17 09:05:56 -080073#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")
Stephane Eranianfbe96f22011-09-30 15:40:40 +020077#define CPUINFO_PROC "model name"
Luck, Tony11ada262009-11-17 09:05:56 -080078#endif
79
Jamie Iles58e9f942009-12-11 12:20:09 +000080#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 */
Will Deaconda7196e2010-03-03 11:47:58 +000086#define rmb() ((void(*)(void))0xffff0fa0)()
Jamie Iles58e9f942009-12-11 12:20:09 +000087#define cpu_relax() asm volatile("":::"memory")
Stephane Eranianfbe96f22011-09-30 15:40:40 +020088#define CPUINFO_PROC "Processor"
Jamie Iles58e9f942009-12-11 12:20:09 +000089#endif
90
Will Deacon03089682012-03-05 11:49:32 +000091#ifdef __aarch64__
92#include "../../arch/arm64/include/asm/unistd.h"
93#define rmb() asm volatile("dmb ld" ::: "memory")
94#define cpu_relax() asm volatile("yield" ::: "memory")
95#endif
96
Deng-Cheng Zhuc1e028e2010-10-12 19:33:33 +080097#ifdef __mips__
98#include "../../arch/mips/include/asm/unistd.h"
99#define rmb() asm volatile( \
100 ".set mips2\n\t" \
101 "sync\n\t" \
102 ".set mips0" \
103 : /* no output */ \
104 : /* no input */ \
105 : "memory")
106#define cpu_relax() asm volatile("" ::: "memory")
Stephane Eranianfbe96f22011-09-30 15:40:40 +0200107#define CPUINFO_PROC "cpu model"
Deng-Cheng Zhuc1e028e2010-10-12 19:33:33 +0800108#endif
109
Peter Zijlstra1a482f32009-05-23 18:28:58 +0200110#include <time.h>
111#include <unistd.h>
112#include <sys/types.h>
113#include <sys/syscall.h>
114
Ingo Molnar7d380c82012-10-14 10:40:57 +0200115#include "../../include/uapi/linux/perf_event.h"
Peter Zijlstra7c6a1c62009-06-25 17:05:54 +0200116#include "util/types.h"
Arnaldo Carvalho de Melo80354582010-05-17 15:51:10 -0300117#include <stdbool.h>
Peter Zijlstra1a482f32009-05-23 18:28:58 +0200118
Arnaldo Carvalho de Melo70082dd2011-01-12 17:03:24 -0200119struct perf_mmap {
120 void *base;
121 int mask;
122 unsigned int prev;
123};
124
125static inline unsigned int perf_mmap__read_head(struct perf_mmap *mm)
126{
127 struct perf_event_mmap_page *pc = mm->base;
128 int head = pc->data_head;
129 rmb();
130 return head;
131}
132
Arnaldo Carvalho de Melo115d2d82011-01-12 17:11:53 -0200133static inline void perf_mmap__write_tail(struct perf_mmap *md,
134 unsigned long tail)
135{
136 struct perf_event_mmap_page *pc = md->base;
137
138 /*
139 * ensure all reads are done before we write the tail out.
140 */
141 /* mb(); */
142 pc->data_tail = tail;
143}
144
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200145/*
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200146 * prctl(PR_TASK_PERF_EVENTS_DISABLE) will (cheaply) disable all
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200147 * counters in the current task.
148 */
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200149#define PR_TASK_PERF_EVENTS_DISABLE 31
150#define PR_TASK_PERF_EVENTS_ENABLE 32
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200151
Thomas Gleixnera92e702372009-05-01 18:39:47 +0200152#ifndef NSEC_PER_SEC
153# define NSEC_PER_SEC 1000000000ULL
154#endif
155
156static inline unsigned long long rdclock(void)
157{
158 struct timespec ts;
159
160 clock_gettime(CLOCK_MONOTONIC, &ts);
161 return ts.tv_sec * 1000000000ULL + ts.tv_nsec;
162}
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200163
164/*
165 * Pick up some kernel type conventions:
166 */
167#define __user
168#define asmlinkage
169
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200170#define unlikely(x) __builtin_expect(!!(x), 0)
171#define min(x, y) ({ \
172 typeof(x) _min1 = (x); \
173 typeof(y) _min2 = (y); \
174 (void) (&_min1 == &_min2); \
175 _min1 < _min2 ? _min1 : _min2; })
176
177static inline int
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200178sys_perf_event_open(struct perf_event_attr *attr,
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200179 pid_t pid, int cpu, int group_fd,
180 unsigned long flags)
181{
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200182 return syscall(__NR_perf_event_open, attr, pid, cpu,
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200183 group_fd, flags);
184}
185
Ingo Molnar85a9f922009-05-25 09:59:50 +0200186#define MAX_COUNTERS 256
187#define MAX_NR_CPUS 256
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200188
Frederic Weisbecker8cb76d92009-06-26 16:28:00 +0200189struct ip_callchain {
190 u64 nr;
191 u64 ips[0];
Peter Zijlstraf5970552009-06-18 23:22:55 +0200192};
193
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100194struct branch_flags {
195 u64 mispred:1;
196 u64 predicted:1;
197 u64 reserved:62;
198};
199
200struct branch_entry {
201 u64 from;
202 u64 to;
203 struct branch_flags flags;
204};
205
206struct branch_stack {
207 u64 nr;
208 struct branch_entry entries[0];
209};
210
Feng Tang70cb4e92012-10-30 11:56:02 +0800211extern const char *input_name;
Arnaldo Carvalho de Melo80354582010-05-17 15:51:10 -0300212extern bool perf_host, perf_guest;
Stephane Eranianfbe96f22011-09-30 15:40:40 +0200213extern const char perf_version_string[];
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800214
Arnaldo Carvalho de Melo3af6e332011-10-13 08:52:46 -0300215void pthread__unblock_sigwinch(void);
216
Namhyung Kim12864b32012-04-26 14:15:22 +0900217#include "util/target.h"
Namhyung Kimbea03402012-04-26 14:15:15 +0900218
Jiri Olsa26d33022012-08-07 15:20:47 +0200219enum perf_call_graph_mode {
220 CALLCHAIN_NONE,
221 CALLCHAIN_FP,
222 CALLCHAIN_DWARF
223};
224
Namhyung Kimbea03402012-04-26 14:15:15 +0900225struct perf_record_opts {
226 struct perf_target target;
Jiri Olsa26d33022012-08-07 15:20:47 +0200227 int call_graph;
Arnaldo Carvalho de Meloed80f582011-11-11 15:12:56 -0200228 bool group;
Arnaldo Carvalho de Melo0f82ebc2011-11-08 14:41:57 -0200229 bool inherit_stat;
230 bool no_delay;
231 bool no_inherit;
232 bool no_samples;
Arnaldo Carvalho de Melo35b9d882011-11-09 08:47:15 -0200233 bool pipe_output;
Arnaldo Carvalho de Melo0f82ebc2011-11-08 14:41:57 -0200234 bool raw_samples;
235 bool sample_address;
236 bool sample_time;
Arnaldo Carvalho de Melo808e1222012-02-14 14:18:57 -0200237 bool sample_id_all_missing;
Arnaldo Carvalho de Melobc76efe2012-02-14 14:05:30 -0200238 bool exclude_guest_missing;
Andrew Vagin3e76ac72011-12-20 17:32:45 +0300239 bool period;
Arnaldo Carvalho de Melo0f82ebc2011-11-08 14:41:57 -0200240 unsigned int freq;
Arnaldo Carvalho de Melo01c2d992011-11-09 09:16:26 -0200241 unsigned int mmap_pages;
Arnaldo Carvalho de Melo0f82ebc2011-11-08 14:41:57 -0200242 unsigned int user_freq;
Stephane Eraniana00dc312012-05-25 23:13:44 +0200243 u64 branch_stack;
Arnaldo Carvalho de Melo0f82ebc2011-11-08 14:41:57 -0200244 u64 default_interval;
245 u64 user_interval;
Jiri Olsa26d33022012-08-07 15:20:47 +0200246 u16 stack_dump_size;
Arnaldo Carvalho de Melo0f82ebc2011-11-08 14:41:57 -0200247};
248
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200249#endif