Thomas Gleixner | 6eda583 | 2009-05-01 18:29:57 +0200 | [diff] [blame] | 1 | #ifndef _PERF_PERF_H |
| 2 | #define _PERF_PERF_H |
| 3 | |
David Howells | d2709c7 | 2012-11-19 22:21:03 +0000 | [diff] [blame] | 4 | #include <asm/unistd.h> |
| 5 | |
Vince Weaver | 11d1578 | 2009-07-08 17:46:14 -0400 | [diff] [blame] | 6 | #if defined(__i386__) |
Vince Weaver | 11d1578 | 2009-07-08 17:46:14 -0400 | [diff] [blame] | 7 | #define rmb() asm volatile("lock; addl $0,0(%%esp)" ::: "memory") |
| 8 | #define cpu_relax() asm volatile("rep; nop" ::: "memory"); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 9 | #define CPUINFO_PROC "model name" |
Ingo Molnar | eae7a75 | 2012-03-14 12:42:34 -0300 | [diff] [blame] | 10 | #ifndef __NR_perf_event_open |
| 11 | # define __NR_perf_event_open 336 |
| 12 | #endif |
Vince Weaver | 11d1578 | 2009-07-08 17:46:14 -0400 | [diff] [blame] | 13 | #endif |
| 14 | |
| 15 | #if defined(__x86_64__) |
Peter Zijlstra | 1a482f3 | 2009-05-23 18:28:58 +0200 | [diff] [blame] | 16 | #define rmb() asm volatile("lfence" ::: "memory") |
| 17 | #define cpu_relax() asm volatile("rep; nop" ::: "memory"); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 18 | #define CPUINFO_PROC "model name" |
Ingo Molnar | eae7a75 | 2012-03-14 12:42:34 -0300 | [diff] [blame] | 19 | #ifndef __NR_perf_event_open |
| 20 | # define __NR_perf_event_open 298 |
| 21 | #endif |
Peter Zijlstra | 1a482f3 | 2009-05-23 18:28:58 +0200 | [diff] [blame] | 22 | #endif |
| 23 | |
| 24 | #ifdef __powerpc__ |
Sukadev Bhattiprolu | 1483c2a | 2012-10-31 11:21:28 -0700 | [diff] [blame] | 25 | #include "../../arch/powerpc/include/uapi/asm/unistd.h" |
Peter Zijlstra | 1a482f3 | 2009-05-23 18:28:58 +0200 | [diff] [blame] | 26 | #define rmb() asm volatile ("sync" ::: "memory") |
| 27 | #define cpu_relax() asm volatile ("" ::: "memory"); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 28 | #define CPUINFO_PROC "cpu" |
Peter Zijlstra | 1a482f3 | 2009-05-23 18:28:58 +0200 | [diff] [blame] | 29 | #endif |
| 30 | |
Martin Schwidefsky | 12310e9 | 2009-06-22 12:08:22 +0200 | [diff] [blame] | 31 | #ifdef __s390__ |
Martin Schwidefsky | 12310e9 | 2009-06-22 12:08:22 +0200 | [diff] [blame] | 32 | #define rmb() asm volatile("bcr 15,0" ::: "memory") |
| 33 | #define cpu_relax() asm volatile("" ::: "memory"); |
| 34 | #endif |
| 35 | |
Paul Mundt | febe834 | 2009-06-25 14:41:57 +0900 | [diff] [blame] | 36 | #ifdef __sh__ |
Paul Mundt | febe834 | 2009-06-25 14:41:57 +0900 | [diff] [blame] | 37 | #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 Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 43 | #define CPUINFO_PROC "cpu type" |
Paul Mundt | febe834 | 2009-06-25 14:41:57 +0900 | [diff] [blame] | 44 | #endif |
| 45 | |
Kyle McMartin | 2d4618d | 2009-06-23 21:38:49 -0400 | [diff] [blame] | 46 | #ifdef __hppa__ |
Kyle McMartin | 2d4618d | 2009-06-23 21:38:49 -0400 | [diff] [blame] | 47 | #define rmb() asm volatile("" ::: "memory") |
| 48 | #define cpu_relax() asm volatile("" ::: "memory"); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 49 | #define CPUINFO_PROC "cpu" |
Kyle McMartin | 2d4618d | 2009-06-23 21:38:49 -0400 | [diff] [blame] | 50 | #endif |
| 51 | |
Jens Axboe | 825c9fb | 2009-09-04 02:56:22 -0700 | [diff] [blame] | 52 | #ifdef __sparc__ |
Jens Axboe | 825c9fb | 2009-09-04 02:56:22 -0700 | [diff] [blame] | 53 | #define rmb() asm volatile("":::"memory") |
| 54 | #define cpu_relax() asm volatile("":::"memory") |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 55 | #define CPUINFO_PROC "cpu" |
Jens Axboe | 825c9fb | 2009-09-04 02:56:22 -0700 | [diff] [blame] | 56 | #endif |
| 57 | |
Michael Cree | fcd14b3 | 2009-10-26 21:32:06 +1300 | [diff] [blame] | 58 | #ifdef __alpha__ |
Michael Cree | fcd14b3 | 2009-10-26 21:32:06 +1300 | [diff] [blame] | 59 | #define rmb() asm volatile("mb" ::: "memory") |
| 60 | #define cpu_relax() asm volatile("" ::: "memory") |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 61 | #define CPUINFO_PROC "cpu model" |
Michael Cree | fcd14b3 | 2009-10-26 21:32:06 +1300 | [diff] [blame] | 62 | #endif |
| 63 | |
Luck, Tony | 11ada26 | 2009-11-17 09:05:56 -0800 | [diff] [blame] | 64 | #ifdef __ia64__ |
Luck, Tony | 11ada26 | 2009-11-17 09:05:56 -0800 | [diff] [blame] | 65 | #define rmb() asm volatile ("mf" ::: "memory") |
| 66 | #define cpu_relax() asm volatile ("hint @pause" ::: "memory") |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 67 | #define CPUINFO_PROC "model name" |
Luck, Tony | 11ada26 | 2009-11-17 09:05:56 -0800 | [diff] [blame] | 68 | #endif |
| 69 | |
Jamie Iles | 58e9f94 | 2009-12-11 12:20:09 +0000 | [diff] [blame] | 70 | #ifdef __arm__ |
Jamie Iles | 58e9f94 | 2009-12-11 12:20:09 +0000 | [diff] [blame] | 71 | /* |
| 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 Deacon | da7196e | 2010-03-03 11:47:58 +0000 | [diff] [blame] | 75 | #define rmb() ((void(*)(void))0xffff0fa0)() |
Jamie Iles | 58e9f94 | 2009-12-11 12:20:09 +0000 | [diff] [blame] | 76 | #define cpu_relax() asm volatile("":::"memory") |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 77 | #define CPUINFO_PROC "Processor" |
Jamie Iles | 58e9f94 | 2009-12-11 12:20:09 +0000 | [diff] [blame] | 78 | #endif |
| 79 | |
Will Deacon | 0308968 | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 80 | #ifdef __aarch64__ |
Will Deacon | 0308968 | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 81 | #define rmb() asm volatile("dmb ld" ::: "memory") |
| 82 | #define cpu_relax() asm volatile("yield" ::: "memory") |
| 83 | #endif |
| 84 | |
Deng-Cheng Zhu | c1e028e | 2010-10-12 19:33:33 +0800 | [diff] [blame] | 85 | #ifdef __mips__ |
Deng-Cheng Zhu | c1e028e | 2010-10-12 19:33:33 +0800 | [diff] [blame] | 86 | #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 Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 94 | #define CPUINFO_PROC "cpu model" |
Deng-Cheng Zhu | c1e028e | 2010-10-12 19:33:33 +0800 | [diff] [blame] | 95 | #endif |
| 96 | |
Vineet Gupta | 9854783 | 2013-01-18 15:12:24 +0530 | [diff] [blame] | 97 | #ifdef __arc__ |
| 98 | #define rmb() asm volatile("" ::: "memory") |
| 99 | #define cpu_relax() rmb() |
| 100 | #define CPUINFO_PROC "Processor" |
| 101 | #endif |
| 102 | |
James Hogan | 1bea5b8 | 2013-01-31 12:22:37 +0000 | [diff] [blame] | 103 | #ifdef __metag__ |
| 104 | #define rmb() asm volatile("" ::: "memory") |
| 105 | #define cpu_relax() asm volatile("" ::: "memory") |
| 106 | #define CPUINFO_PROC "CPU" |
| 107 | #endif |
| 108 | |
Peter Zijlstra | 1a482f3 | 2009-05-23 18:28:58 +0200 | [diff] [blame] | 109 | #include <time.h> |
| 110 | #include <unistd.h> |
| 111 | #include <sys/types.h> |
| 112 | #include <sys/syscall.h> |
| 113 | |
David Howells | d2709c7 | 2012-11-19 22:21:03 +0000 | [diff] [blame] | 114 | #include <linux/perf_event.h> |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 115 | #include "util/types.h" |
Arnaldo Carvalho de Melo | 8035458 | 2010-05-17 15:51:10 -0300 | [diff] [blame] | 116 | #include <stdbool.h> |
Peter Zijlstra | 1a482f3 | 2009-05-23 18:28:58 +0200 | [diff] [blame] | 117 | |
Thomas Gleixner | 6eda583 | 2009-05-01 18:29:57 +0200 | [diff] [blame] | 118 | /* |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 119 | * prctl(PR_TASK_PERF_EVENTS_DISABLE) will (cheaply) disable all |
Thomas Gleixner | 6eda583 | 2009-05-01 18:29:57 +0200 | [diff] [blame] | 120 | * counters in the current task. |
| 121 | */ |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 122 | #define PR_TASK_PERF_EVENTS_DISABLE 31 |
| 123 | #define PR_TASK_PERF_EVENTS_ENABLE 32 |
Thomas Gleixner | 6eda583 | 2009-05-01 18:29:57 +0200 | [diff] [blame] | 124 | |
Thomas Gleixner | a92e70237 | 2009-05-01 18:39:47 +0200 | [diff] [blame] | 125 | #ifndef NSEC_PER_SEC |
| 126 | # define NSEC_PER_SEC 1000000000ULL |
| 127 | #endif |
David Ahern | 70f7b4a | 2013-08-07 21:56:38 -0400 | [diff] [blame] | 128 | #ifndef NSEC_PER_USEC |
| 129 | # define NSEC_PER_USEC 1000ULL |
| 130 | #endif |
Thomas Gleixner | a92e70237 | 2009-05-01 18:39:47 +0200 | [diff] [blame] | 131 | |
| 132 | static 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 Gleixner | 6eda583 | 2009-05-01 18:29:57 +0200 | [diff] [blame] | 139 | |
| 140 | /* |
| 141 | * Pick up some kernel type conventions: |
| 142 | */ |
| 143 | #define __user |
| 144 | #define asmlinkage |
| 145 | |
Thomas Gleixner | 6eda583 | 2009-05-01 18:29:57 +0200 | [diff] [blame] | 146 | #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 Olsa | 52502bf | 2012-10-31 15:52:47 +0100 | [diff] [blame] | 153 | extern bool test_attr__enabled; |
| 154 | void test_attr__init(void); |
| 155 | void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu, |
| 156 | int fd, int group_fd, unsigned long flags); |
| 157 | |
Thomas Gleixner | 6eda583 | 2009-05-01 18:29:57 +0200 | [diff] [blame] | 158 | static inline int |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 159 | sys_perf_event_open(struct perf_event_attr *attr, |
Thomas Gleixner | 6eda583 | 2009-05-01 18:29:57 +0200 | [diff] [blame] | 160 | pid_t pid, int cpu, int group_fd, |
| 161 | unsigned long flags) |
| 162 | { |
Jiri Olsa | 52502bf | 2012-10-31 15:52:47 +0100 | [diff] [blame] | 163 | 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 Gleixner | 6eda583 | 2009-05-01 18:29:57 +0200 | [diff] [blame] | 172 | } |
| 173 | |
Ingo Molnar | 85a9f92 | 2009-05-25 09:59:50 +0200 | [diff] [blame] | 174 | #define MAX_COUNTERS 256 |
| 175 | #define MAX_NR_CPUS 256 |
Thomas Gleixner | 6eda583 | 2009-05-01 18:29:57 +0200 | [diff] [blame] | 176 | |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 177 | struct ip_callchain { |
| 178 | u64 nr; |
| 179 | u64 ips[0]; |
Peter Zijlstra | f597055 | 2009-06-18 23:22:55 +0200 | [diff] [blame] | 180 | }; |
| 181 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 182 | struct branch_flags { |
| 183 | u64 mispred:1; |
| 184 | u64 predicted:1; |
| 185 | u64 reserved:62; |
| 186 | }; |
| 187 | |
| 188 | struct branch_entry { |
| 189 | u64 from; |
| 190 | u64 to; |
| 191 | struct branch_flags flags; |
| 192 | }; |
| 193 | |
| 194 | struct branch_stack { |
| 195 | u64 nr; |
| 196 | struct branch_entry entries[0]; |
| 197 | }; |
| 198 | |
Feng Tang | 70cb4e9 | 2012-10-30 11:56:02 +0800 | [diff] [blame] | 199 | extern const char *input_name; |
Arnaldo Carvalho de Melo | 8035458 | 2010-05-17 15:51:10 -0300 | [diff] [blame] | 200 | extern bool perf_host, perf_guest; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 201 | extern const char perf_version_string[]; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 202 | |
Arnaldo Carvalho de Melo | 3af6e33 | 2011-10-13 08:52:46 -0300 | [diff] [blame] | 203 | void pthread__unblock_sigwinch(void); |
| 204 | |
Namhyung Kim | 12864b3 | 2012-04-26 14:15:22 +0900 | [diff] [blame] | 205 | #include "util/target.h" |
Namhyung Kim | bea0340 | 2012-04-26 14:15:15 +0900 | [diff] [blame] | 206 | |
Jiri Olsa | 26d3302 | 2012-08-07 15:20:47 +0200 | [diff] [blame] | 207 | enum perf_call_graph_mode { |
| 208 | CALLCHAIN_NONE, |
| 209 | CALLCHAIN_FP, |
| 210 | CALLCHAIN_DWARF |
| 211 | }; |
| 212 | |
Namhyung Kim | bea0340 | 2012-04-26 14:15:15 +0900 | [diff] [blame] | 213 | struct perf_record_opts { |
| 214 | struct perf_target target; |
Jiri Olsa | 26d3302 | 2012-08-07 15:20:47 +0200 | [diff] [blame] | 215 | int call_graph; |
Arnaldo Carvalho de Melo | ed80f58 | 2011-11-11 15:12:56 -0200 | [diff] [blame] | 216 | bool group; |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 217 | bool inherit_stat; |
| 218 | bool no_delay; |
| 219 | bool no_inherit; |
| 220 | bool no_samples; |
Arnaldo Carvalho de Melo | 35b9d88 | 2011-11-09 08:47:15 -0200 | [diff] [blame] | 221 | bool pipe_output; |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 222 | bool raw_samples; |
| 223 | bool sample_address; |
Andi Kleen | 0548429 | 2013-01-24 16:10:29 +0100 | [diff] [blame] | 224 | bool sample_weight; |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 225 | bool sample_time; |
Andrew Vagin | 3e76ac7 | 2011-12-20 17:32:45 +0300 | [diff] [blame] | 226 | bool period; |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 227 | unsigned int freq; |
Arnaldo Carvalho de Melo | 01c2d99 | 2011-11-09 09:16:26 -0200 | [diff] [blame] | 228 | unsigned int mmap_pages; |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 229 | unsigned int user_freq; |
Stephane Eranian | a00dc31 | 2012-05-25 23:13:44 +0200 | [diff] [blame] | 230 | u64 branch_stack; |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 231 | u64 default_interval; |
| 232 | u64 user_interval; |
Jiri Olsa | 26d3302 | 2012-08-07 15:20:47 +0200 | [diff] [blame] | 233 | u16 stack_dump_size; |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 234 | }; |
| 235 | |
Thomas Gleixner | 6eda583 | 2009-05-01 18:29:57 +0200 | [diff] [blame] | 236 | #endif |