blob: cf20187eee0a7345373dfc053c580bc1e77c4bb8 [file] [log] [blame]
Thomas Gleixner6eda5832009-05-01 18:29:57 +02001#ifndef _PERF_PERF_H
2#define _PERF_PERF_H
3
David Howellsd2709c72012-11-19 22:21:03 +00004#include <asm/unistd.h>
5
Vince Weaver11d15782009-07-08 17:46:14 -04006#if defined(__i386__)
Vince Weaver11d15782009-07-08 17:46:14 -04007#define rmb() asm volatile("lock; addl $0,0(%%esp)" ::: "memory")
8#define cpu_relax() asm volatile("rep; nop" ::: "memory");
Stephane Eranianfbe96f22011-09-30 15:40:40 +02009#define CPUINFO_PROC "model name"
Ingo Molnareae7a752012-03-14 12:42:34 -030010#ifndef __NR_perf_event_open
11# define __NR_perf_event_open 336
12#endif
Vince Weaver11d15782009-07-08 17:46:14 -040013#endif
14
15#if defined(__x86_64__)
Peter Zijlstra1a482f32009-05-23 18:28:58 +020016#define rmb() asm volatile("lfence" ::: "memory")
17#define cpu_relax() asm volatile("rep; nop" ::: "memory");
Stephane Eranianfbe96f22011-09-30 15:40:40 +020018#define CPUINFO_PROC "model name"
Ingo Molnareae7a752012-03-14 12:42:34 -030019#ifndef __NR_perf_event_open
20# define __NR_perf_event_open 298
21#endif
Peter Zijlstra1a482f32009-05-23 18:28:58 +020022#endif
23
24#ifdef __powerpc__
Sukadev Bhattiprolu1483c2a2012-10-31 11:21:28 -070025#include "../../arch/powerpc/include/uapi/asm/unistd.h"
Peter Zijlstra1a482f32009-05-23 18:28:58 +020026#define rmb() asm volatile ("sync" ::: "memory")
27#define cpu_relax() asm volatile ("" ::: "memory");
Stephane Eranianfbe96f22011-09-30 15:40:40 +020028#define CPUINFO_PROC "cpu"
Peter Zijlstra1a482f32009-05-23 18:28:58 +020029#endif
30
Martin Schwidefsky12310e92009-06-22 12:08:22 +020031#ifdef __s390__
Martin Schwidefsky12310e92009-06-22 12:08:22 +020032#define rmb() asm volatile("bcr 15,0" ::: "memory")
33#define cpu_relax() asm volatile("" ::: "memory");
34#endif
35
Paul Mundtfebe8342009-06-25 14:41:57 +090036#ifdef __sh__
Paul Mundtfebe8342009-06-25 14:41:57 +090037#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")
Stephane Eranianfbe96f22011-09-30 15:40:40 +020043#define CPUINFO_PROC "cpu type"
Paul Mundtfebe8342009-06-25 14:41:57 +090044#endif
45
Kyle McMartin2d4618d2009-06-23 21:38:49 -040046#ifdef __hppa__
Kyle McMartin2d4618d2009-06-23 21:38:49 -040047#define rmb() asm volatile("" ::: "memory")
48#define cpu_relax() asm volatile("" ::: "memory");
Stephane Eranianfbe96f22011-09-30 15:40:40 +020049#define CPUINFO_PROC "cpu"
Kyle McMartin2d4618d2009-06-23 21:38:49 -040050#endif
51
Jens Axboe825c9fb2009-09-04 02:56:22 -070052#ifdef __sparc__
Jens Axboe825c9fb2009-09-04 02:56:22 -070053#define rmb() asm volatile("":::"memory")
54#define cpu_relax() asm volatile("":::"memory")
Stephane Eranianfbe96f22011-09-30 15:40:40 +020055#define CPUINFO_PROC "cpu"
Jens Axboe825c9fb2009-09-04 02:56:22 -070056#endif
57
Michael Creefcd14b32009-10-26 21:32:06 +130058#ifdef __alpha__
Michael Creefcd14b32009-10-26 21:32:06 +130059#define rmb() asm volatile("mb" ::: "memory")
60#define cpu_relax() asm volatile("" ::: "memory")
Stephane Eranianfbe96f22011-09-30 15:40:40 +020061#define CPUINFO_PROC "cpu model"
Michael Creefcd14b32009-10-26 21:32:06 +130062#endif
63
Luck, Tony11ada262009-11-17 09:05:56 -080064#ifdef __ia64__
Luck, Tony11ada262009-11-17 09:05:56 -080065#define rmb() asm volatile ("mf" ::: "memory")
66#define cpu_relax() asm volatile ("hint @pause" ::: "memory")
Stephane Eranianfbe96f22011-09-30 15:40:40 +020067#define CPUINFO_PROC "model name"
Luck, Tony11ada262009-11-17 09:05:56 -080068#endif
69
Jamie Iles58e9f942009-12-11 12:20:09 +000070#ifdef __arm__
Jamie Iles58e9f942009-12-11 12:20:09 +000071/*
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 */
Will Deaconda7196e2010-03-03 11:47:58 +000075#define rmb() ((void(*)(void))0xffff0fa0)()
Jamie Iles58e9f942009-12-11 12:20:09 +000076#define cpu_relax() asm volatile("":::"memory")
Stephane Eranianfbe96f22011-09-30 15:40:40 +020077#define CPUINFO_PROC "Processor"
Jamie Iles58e9f942009-12-11 12:20:09 +000078#endif
79
Will Deacon03089682012-03-05 11:49:32 +000080#ifdef __aarch64__
Will Deacon03089682012-03-05 11:49:32 +000081#define rmb() asm volatile("dmb ld" ::: "memory")
82#define cpu_relax() asm volatile("yield" ::: "memory")
83#endif
84
Deng-Cheng Zhuc1e028e2010-10-12 19:33:33 +080085#ifdef __mips__
Deng-Cheng Zhuc1e028e2010-10-12 19:33:33 +080086#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")
Stephane Eranianfbe96f22011-09-30 15:40:40 +020094#define CPUINFO_PROC "cpu model"
Deng-Cheng Zhuc1e028e2010-10-12 19:33:33 +080095#endif
96
Vineet Gupta98547832013-01-18 15:12:24 +053097#ifdef __arc__
98#define rmb() asm volatile("" ::: "memory")
99#define cpu_relax() rmb()
100#define CPUINFO_PROC "Processor"
101#endif
102
James Hogan1bea5b82013-01-31 12:22:37 +0000103#ifdef __metag__
104#define rmb() asm volatile("" ::: "memory")
105#define cpu_relax() asm volatile("" ::: "memory")
106#define CPUINFO_PROC "CPU"
107#endif
108
Peter Zijlstra1a482f32009-05-23 18:28:58 +0200109#include <time.h>
110#include <unistd.h>
111#include <sys/types.h>
112#include <sys/syscall.h>
113
David Howellsd2709c72012-11-19 22:21:03 +0000114#include <linux/perf_event.h>
Peter Zijlstra7c6a1c62009-06-25 17:05:54 +0200115#include "util/types.h"
Arnaldo Carvalho de Melo80354582010-05-17 15:51:10 -0300116#include <stdbool.h>
Peter Zijlstra1a482f32009-05-23 18:28:58 +0200117
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200118/*
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200119 * prctl(PR_TASK_PERF_EVENTS_DISABLE) will (cheaply) disable all
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200120 * counters in the current task.
121 */
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200122#define PR_TASK_PERF_EVENTS_DISABLE 31
123#define PR_TASK_PERF_EVENTS_ENABLE 32
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200124
Thomas Gleixnera92e702372009-05-01 18:39:47 +0200125#ifndef NSEC_PER_SEC
126# define NSEC_PER_SEC 1000000000ULL
127#endif
David Ahern70f7b4a2013-08-07 21:56:38 -0400128#ifndef NSEC_PER_USEC
129# define NSEC_PER_USEC 1000ULL
130#endif
Thomas Gleixnera92e702372009-05-01 18:39:47 +0200131
132static inline unsigned long long rdclock(void)
133{
134 struct timespec ts;
135
136 clock_gettime(CLOCK_MONOTONIC, &ts);
137 return ts.tv_sec * 1000000000ULL + ts.tv_nsec;
138}
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200139
140/*
141 * Pick up some kernel type conventions:
142 */
143#define __user
144#define asmlinkage
145
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200146#define unlikely(x) __builtin_expect(!!(x), 0)
147#define min(x, y) ({ \
148 typeof(x) _min1 = (x); \
149 typeof(y) _min2 = (y); \
150 (void) (&_min1 == &_min2); \
151 _min1 < _min2 ? _min1 : _min2; })
152
Jiri Olsa52502bf2012-10-31 15:52:47 +0100153extern bool test_attr__enabled;
154void test_attr__init(void);
155void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu,
156 int fd, int group_fd, unsigned long flags);
157
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200158static inline int
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200159sys_perf_event_open(struct perf_event_attr *attr,
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200160 pid_t pid, int cpu, int group_fd,
161 unsigned long flags)
162{
Jiri Olsa52502bf2012-10-31 15:52:47 +0100163 int fd;
164
165 fd = syscall(__NR_perf_event_open, attr, pid, cpu,
166 group_fd, flags);
167
168 if (unlikely(test_attr__enabled))
169 test_attr__open(attr, pid, cpu, fd, group_fd, flags);
170
171 return fd;
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200172}
173
Ingo Molnar85a9f922009-05-25 09:59:50 +0200174#define MAX_COUNTERS 256
175#define MAX_NR_CPUS 256
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200176
Frederic Weisbecker8cb76d92009-06-26 16:28:00 +0200177struct ip_callchain {
178 u64 nr;
179 u64 ips[0];
Peter Zijlstraf5970552009-06-18 23:22:55 +0200180};
181
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100182struct branch_flags {
183 u64 mispred:1;
184 u64 predicted:1;
185 u64 reserved:62;
186};
187
188struct branch_entry {
189 u64 from;
190 u64 to;
191 struct branch_flags flags;
192};
193
194struct branch_stack {
195 u64 nr;
196 struct branch_entry entries[0];
197};
198
Feng Tang70cb4e92012-10-30 11:56:02 +0800199extern const char *input_name;
Arnaldo Carvalho de Melo80354582010-05-17 15:51:10 -0300200extern bool perf_host, perf_guest;
Stephane Eranianfbe96f22011-09-30 15:40:40 +0200201extern const char perf_version_string[];
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800202
Arnaldo Carvalho de Melo3af6e332011-10-13 08:52:46 -0300203void pthread__unblock_sigwinch(void);
204
Namhyung Kim12864b32012-04-26 14:15:22 +0900205#include "util/target.h"
Namhyung Kimbea03402012-04-26 14:15:15 +0900206
Jiri Olsa26d33022012-08-07 15:20:47 +0200207enum perf_call_graph_mode {
208 CALLCHAIN_NONE,
209 CALLCHAIN_FP,
210 CALLCHAIN_DWARF
211};
212
Namhyung Kimbea03402012-04-26 14:15:15 +0900213struct perf_record_opts {
214 struct perf_target target;
Jiri Olsa26d33022012-08-07 15:20:47 +0200215 int call_graph;
Arnaldo Carvalho de Meloed80f582011-11-11 15:12:56 -0200216 bool group;
Arnaldo Carvalho de Melo0f82ebc2011-11-08 14:41:57 -0200217 bool inherit_stat;
218 bool no_delay;
219 bool no_inherit;
220 bool no_samples;
Arnaldo Carvalho de Melo35b9d882011-11-09 08:47:15 -0200221 bool pipe_output;
Arnaldo Carvalho de Melo0f82ebc2011-11-08 14:41:57 -0200222 bool raw_samples;
223 bool sample_address;
Andi Kleen05484292013-01-24 16:10:29 +0100224 bool sample_weight;
Arnaldo Carvalho de Melo0f82ebc2011-11-08 14:41:57 -0200225 bool sample_time;
Andrew Vagin3e76ac72011-12-20 17:32:45 +0300226 bool period;
Arnaldo Carvalho de Melo0f82ebc2011-11-08 14:41:57 -0200227 unsigned int freq;
Arnaldo Carvalho de Melo01c2d992011-11-09 09:16:26 -0200228 unsigned int mmap_pages;
Arnaldo Carvalho de Melo0f82ebc2011-11-08 14:41:57 -0200229 unsigned int user_freq;
Stephane Eraniana00dc312012-05-25 23:13:44 +0200230 u64 branch_stack;
Arnaldo Carvalho de Melo0f82ebc2011-11-08 14:41:57 -0200231 u64 default_interval;
232 u64 user_interval;
Jiri Olsa26d33022012-08-07 15:20:47 +0200233 u16 stack_dump_size;
Arnaldo Carvalho de Melo0f82ebc2011-11-08 14:41:57 -0200234};
235
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200236#endif