blob: f960ccb2edc6f38f8a7b7a3f0f1b740cbd351c2b [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__
60#include "../../arch/sparc/include/asm/unistd.h"
61#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
Deng-Cheng Zhuc1e028e2010-10-12 19:33:33 +080091#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")
Stephane Eranianfbe96f22011-09-30 15:40:40 +0200101#define CPUINFO_PROC "cpu model"
Deng-Cheng Zhuc1e028e2010-10-12 19:33:33 +0800102#endif
103
Peter Zijlstra1a482f32009-05-23 18:28:58 +0200104#include <time.h>
105#include <unistd.h>
106#include <sys/types.h>
107#include <sys/syscall.h>
108
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200109#include "../../include/linux/perf_event.h"
Peter Zijlstra7c6a1c62009-06-25 17:05:54 +0200110#include "util/types.h"
Arnaldo Carvalho de Melo80354582010-05-17 15:51:10 -0300111#include <stdbool.h>
Peter Zijlstra1a482f32009-05-23 18:28:58 +0200112
Arnaldo Carvalho de Melo70082dd2011-01-12 17:03:24 -0200113struct 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
Arnaldo Carvalho de Melo115d2d82011-01-12 17:11:53 -0200127static 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
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200139/*
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200140 * prctl(PR_TASK_PERF_EVENTS_DISABLE) will (cheaply) disable all
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200141 * counters in the current task.
142 */
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200143#define PR_TASK_PERF_EVENTS_DISABLE 31
144#define PR_TASK_PERF_EVENTS_ENABLE 32
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200145
Thomas Gleixnera92e702372009-05-01 18:39:47 +0200146#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}
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200157
158/*
159 * Pick up some kernel type conventions:
160 */
161#define __user
162#define asmlinkage
163
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200164#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
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200172sys_perf_event_open(struct perf_event_attr *attr,
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200173 pid_t pid, int cpu, int group_fd,
174 unsigned long flags)
175{
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200176 return syscall(__NR_perf_event_open, attr, pid, cpu,
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200177 group_fd, flags);
178}
179
Ingo Molnar85a9f922009-05-25 09:59:50 +0200180#define MAX_COUNTERS 256
181#define MAX_NR_CPUS 256
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200182
Frederic Weisbecker8cb76d92009-06-26 16:28:00 +0200183struct ip_callchain {
184 u64 nr;
185 u64 ips[0];
Peter Zijlstraf5970552009-06-18 23:22:55 +0200186};
187
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100188struct 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
Arnaldo Carvalho de Melo80354582010-05-17 15:51:10 -0300205extern bool perf_host, perf_guest;
Stephane Eranianfbe96f22011-09-30 15:40:40 +0200206extern const char perf_version_string[];
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800207
Arnaldo Carvalho de Melo3af6e332011-10-13 08:52:46 -0300208void pthread__unblock_sigwinch(void);
209
Namhyung Kim12864b32012-04-26 14:15:22 +0900210#include "util/target.h"
Namhyung Kimbea03402012-04-26 14:15:15 +0900211
212struct perf_record_opts {
213 struct perf_target target;
Arnaldo Carvalho de Melo0f82ebc2011-11-08 14:41:57 -0200214 bool call_graph;
Arnaldo Carvalho de Meloed80f582011-11-11 15:12:56 -0200215 bool group;
Arnaldo Carvalho de Melo0f82ebc2011-11-08 14:41:57 -0200216 bool inherit_stat;
217 bool no_delay;
218 bool no_inherit;
219 bool no_samples;
Arnaldo Carvalho de Melo35b9d882011-11-09 08:47:15 -0200220 bool pipe_output;
Arnaldo Carvalho de Melo0f82ebc2011-11-08 14:41:57 -0200221 bool raw_samples;
222 bool sample_address;
223 bool sample_time;
Arnaldo Carvalho de Melo808e1222012-02-14 14:18:57 -0200224 bool sample_id_all_missing;
Arnaldo Carvalho de Melobc76efe2012-02-14 14:05:30 -0200225 bool exclude_guest_missing;
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;
Arnaldo Carvalho de Melo0f82ebc2011-11-08 14:41:57 -0200233};
234
Thomas Gleixner6eda5832009-05-01 18:29:57 +0200235#endif