Thomas Gleixner | 6eda583 | 2009-05-01 18:29:57 +0200 | [diff] [blame] | 1 | #ifndef _PERF_PERF_H |
| 2 | #define _PERF_PERF_H |
| 3 | |
Arnaldo Carvalho de Melo | 895f0ed | 2010-03-11 20:12:41 -0300 | [diff] [blame] | 4 | struct winsize; |
| 5 | |
| 6 | void get_term_dimensions(struct winsize *ws); |
| 7 | |
Vince Weaver | 11d1578 | 2009-07-08 17:46:14 -0400 | [diff] [blame] | 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"); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 12 | #define CPUINFO_PROC "model name" |
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 | #include "../../arch/x86/include/asm/unistd.h" |
| 17 | #define rmb() asm volatile("lfence" ::: "memory") |
| 18 | #define cpu_relax() asm volatile("rep; nop" ::: "memory"); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 19 | #define CPUINFO_PROC "model name" |
Peter Zijlstra | 1a482f3 | 2009-05-23 18:28:58 +0200 | [diff] [blame] | 20 | #endif |
| 21 | |
| 22 | #ifdef __powerpc__ |
| 23 | #include "../../arch/powerpc/include/asm/unistd.h" |
| 24 | #define rmb() asm volatile ("sync" ::: "memory") |
| 25 | #define cpu_relax() asm volatile ("" ::: "memory"); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 26 | #define CPUINFO_PROC "cpu" |
Peter Zijlstra | 1a482f3 | 2009-05-23 18:28:58 +0200 | [diff] [blame] | 27 | #endif |
| 28 | |
Martin Schwidefsky | 12310e9 | 2009-06-22 12:08:22 +0200 | [diff] [blame] | 29 | #ifdef __s390__ |
| 30 | #include "../../arch/s390/include/asm/unistd.h" |
| 31 | #define rmb() asm volatile("bcr 15,0" ::: "memory") |
| 32 | #define cpu_relax() asm volatile("" ::: "memory"); |
| 33 | #endif |
| 34 | |
Paul Mundt | febe834 | 2009-06-25 14:41:57 +0900 | [diff] [blame] | 35 | #ifdef __sh__ |
| 36 | #include "../../arch/sh/include/asm/unistd.h" |
| 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__ |
| 47 | #include "../../arch/parisc/include/asm/unistd.h" |
| 48 | #define rmb() asm volatile("" ::: "memory") |
| 49 | #define cpu_relax() asm volatile("" ::: "memory"); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 50 | #define CPUINFO_PROC "cpu" |
Kyle McMartin | 2d4618d | 2009-06-23 21:38:49 -0400 | [diff] [blame] | 51 | #endif |
| 52 | |
Jens Axboe | 825c9fb | 2009-09-04 02:56:22 -0700 | [diff] [blame] | 53 | #ifdef __sparc__ |
| 54 | #include "../../arch/sparc/include/asm/unistd.h" |
| 55 | #define rmb() asm volatile("":::"memory") |
| 56 | #define cpu_relax() asm volatile("":::"memory") |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 57 | #define CPUINFO_PROC "cpu" |
Jens Axboe | 825c9fb | 2009-09-04 02:56:22 -0700 | [diff] [blame] | 58 | #endif |
| 59 | |
Michael Cree | fcd14b3 | 2009-10-26 21:32:06 +1300 | [diff] [blame] | 60 | #ifdef __alpha__ |
| 61 | #include "../../arch/alpha/include/asm/unistd.h" |
| 62 | #define rmb() asm volatile("mb" ::: "memory") |
| 63 | #define cpu_relax() asm volatile("" ::: "memory") |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 64 | #define CPUINFO_PROC "cpu model" |
Michael Cree | fcd14b3 | 2009-10-26 21:32:06 +1300 | [diff] [blame] | 65 | #endif |
| 66 | |
Luck, Tony | 11ada26 | 2009-11-17 09:05:56 -0800 | [diff] [blame] | 67 | #ifdef __ia64__ |
| 68 | #include "../../arch/ia64/include/asm/unistd.h" |
| 69 | #define rmb() asm volatile ("mf" ::: "memory") |
| 70 | #define cpu_relax() asm volatile ("hint @pause" ::: "memory") |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 71 | #define CPUINFO_PROC "model name" |
Luck, Tony | 11ada26 | 2009-11-17 09:05:56 -0800 | [diff] [blame] | 72 | #endif |
| 73 | |
Jamie Iles | 58e9f94 | 2009-12-11 12:20:09 +0000 | [diff] [blame] | 74 | #ifdef __arm__ |
| 75 | #include "../../arch/arm/include/asm/unistd.h" |
| 76 | /* |
| 77 | * Use the __kuser_memory_barrier helper in the CPU helper page. See |
| 78 | * arch/arm/kernel/entry-armv.S in the kernel source for details. |
| 79 | */ |
Will Deacon | da7196e | 2010-03-03 11:47:58 +0000 | [diff] [blame] | 80 | #define rmb() ((void(*)(void))0xffff0fa0)() |
Jamie Iles | 58e9f94 | 2009-12-11 12:20:09 +0000 | [diff] [blame] | 81 | #define cpu_relax() asm volatile("":::"memory") |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 82 | #define CPUINFO_PROC "Processor" |
Jamie Iles | 58e9f94 | 2009-12-11 12:20:09 +0000 | [diff] [blame] | 83 | #endif |
| 84 | |
Deng-Cheng Zhu | c1e028e | 2010-10-12 19:33:33 +0800 | [diff] [blame] | 85 | #ifdef __mips__ |
| 86 | #include "../../arch/mips/include/asm/unistd.h" |
| 87 | #define rmb() asm volatile( \ |
| 88 | ".set mips2\n\t" \ |
| 89 | "sync\n\t" \ |
| 90 | ".set mips0" \ |
| 91 | : /* no output */ \ |
| 92 | : /* no input */ \ |
| 93 | : "memory") |
| 94 | #define cpu_relax() asm volatile("" ::: "memory") |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 95 | #define CPUINFO_PROC "cpu model" |
Deng-Cheng Zhu | c1e028e | 2010-10-12 19:33:33 +0800 | [diff] [blame] | 96 | #endif |
| 97 | |
Peter Zijlstra | 1a482f3 | 2009-05-23 18:28:58 +0200 | [diff] [blame] | 98 | #include <time.h> |
| 99 | #include <unistd.h> |
| 100 | #include <sys/types.h> |
| 101 | #include <sys/syscall.h> |
| 102 | |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 103 | #include "../../include/linux/perf_event.h" |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 104 | #include "util/types.h" |
Arnaldo Carvalho de Melo | 8035458 | 2010-05-17 15:51:10 -0300 | [diff] [blame] | 105 | #include <stdbool.h> |
Peter Zijlstra | 1a482f3 | 2009-05-23 18:28:58 +0200 | [diff] [blame] | 106 | |
Arnaldo Carvalho de Melo | 70082dd | 2011-01-12 17:03:24 -0200 | [diff] [blame] | 107 | struct perf_mmap { |
| 108 | void *base; |
| 109 | int mask; |
| 110 | unsigned int prev; |
| 111 | }; |
| 112 | |
| 113 | static inline unsigned int perf_mmap__read_head(struct perf_mmap *mm) |
| 114 | { |
| 115 | struct perf_event_mmap_page *pc = mm->base; |
| 116 | int head = pc->data_head; |
| 117 | rmb(); |
| 118 | return head; |
| 119 | } |
| 120 | |
Arnaldo Carvalho de Melo | 115d2d8 | 2011-01-12 17:11:53 -0200 | [diff] [blame] | 121 | static inline void perf_mmap__write_tail(struct perf_mmap *md, |
| 122 | unsigned long tail) |
| 123 | { |
| 124 | struct perf_event_mmap_page *pc = md->base; |
| 125 | |
| 126 | /* |
| 127 | * ensure all reads are done before we write the tail out. |
| 128 | */ |
| 129 | /* mb(); */ |
| 130 | pc->data_tail = tail; |
| 131 | } |
| 132 | |
Thomas Gleixner | 6eda583 | 2009-05-01 18:29:57 +0200 | [diff] [blame] | 133 | /* |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 134 | * prctl(PR_TASK_PERF_EVENTS_DISABLE) will (cheaply) disable all |
Thomas Gleixner | 6eda583 | 2009-05-01 18:29:57 +0200 | [diff] [blame] | 135 | * counters in the current task. |
| 136 | */ |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 137 | #define PR_TASK_PERF_EVENTS_DISABLE 31 |
| 138 | #define PR_TASK_PERF_EVENTS_ENABLE 32 |
Thomas Gleixner | 6eda583 | 2009-05-01 18:29:57 +0200 | [diff] [blame] | 139 | |
Thomas Gleixner | a92e70237 | 2009-05-01 18:39:47 +0200 | [diff] [blame] | 140 | #ifndef NSEC_PER_SEC |
| 141 | # define NSEC_PER_SEC 1000000000ULL |
| 142 | #endif |
| 143 | |
| 144 | static inline unsigned long long rdclock(void) |
| 145 | { |
| 146 | struct timespec ts; |
| 147 | |
| 148 | clock_gettime(CLOCK_MONOTONIC, &ts); |
| 149 | return ts.tv_sec * 1000000000ULL + ts.tv_nsec; |
| 150 | } |
Thomas Gleixner | 6eda583 | 2009-05-01 18:29:57 +0200 | [diff] [blame] | 151 | |
| 152 | /* |
| 153 | * Pick up some kernel type conventions: |
| 154 | */ |
| 155 | #define __user |
| 156 | #define asmlinkage |
| 157 | |
Thomas Gleixner | 6eda583 | 2009-05-01 18:29:57 +0200 | [diff] [blame] | 158 | #define unlikely(x) __builtin_expect(!!(x), 0) |
| 159 | #define min(x, y) ({ \ |
| 160 | typeof(x) _min1 = (x); \ |
| 161 | typeof(y) _min2 = (y); \ |
| 162 | (void) (&_min1 == &_min2); \ |
| 163 | _min1 < _min2 ? _min1 : _min2; }) |
| 164 | |
| 165 | static inline int |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 166 | sys_perf_event_open(struct perf_event_attr *attr, |
Thomas Gleixner | 6eda583 | 2009-05-01 18:29:57 +0200 | [diff] [blame] | 167 | pid_t pid, int cpu, int group_fd, |
| 168 | unsigned long flags) |
| 169 | { |
Peter Zijlstra | 974802e | 2009-06-12 12:46:55 +0200 | [diff] [blame] | 170 | attr->size = sizeof(*attr); |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 171 | return syscall(__NR_perf_event_open, attr, pid, cpu, |
Thomas Gleixner | 6eda583 | 2009-05-01 18:29:57 +0200 | [diff] [blame] | 172 | group_fd, flags); |
| 173 | } |
| 174 | |
Ingo Molnar | 85a9f92 | 2009-05-25 09:59:50 +0200 | [diff] [blame] | 175 | #define MAX_COUNTERS 256 |
| 176 | #define MAX_NR_CPUS 256 |
Thomas Gleixner | 6eda583 | 2009-05-01 18:29:57 +0200 | [diff] [blame] | 177 | |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 178 | struct ip_callchain { |
| 179 | u64 nr; |
| 180 | u64 ips[0]; |
Peter Zijlstra | f597055 | 2009-06-18 23:22:55 +0200 | [diff] [blame] | 181 | }; |
| 182 | |
Arnaldo Carvalho de Melo | 8035458 | 2010-05-17 15:51:10 -0300 | [diff] [blame] | 183 | extern bool perf_host, perf_guest; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 184 | extern const char perf_version_string[]; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 185 | |
Arnaldo Carvalho de Melo | 3af6e33 | 2011-10-13 08:52:46 -0300 | [diff] [blame] | 186 | void pthread__unblock_sigwinch(void); |
| 187 | |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 188 | struct perf_record_opts { |
| 189 | pid_t target_pid; |
| 190 | pid_t target_tid; |
Arnaldo Carvalho de Melo | 0d37aa3 | 2012-01-19 14:08:15 -0200 | [diff] [blame] | 191 | uid_t uid; |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 192 | bool call_graph; |
Arnaldo Carvalho de Melo | ed80f58 | 2011-11-11 15:12:56 -0200 | [diff] [blame] | 193 | bool group; |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 194 | bool inherit_stat; |
| 195 | bool no_delay; |
| 196 | bool no_inherit; |
| 197 | bool no_samples; |
Arnaldo Carvalho de Melo | 35b9d88 | 2011-11-09 08:47:15 -0200 | [diff] [blame] | 198 | bool pipe_output; |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 199 | bool raw_samples; |
| 200 | bool sample_address; |
| 201 | bool sample_time; |
| 202 | bool sample_id_all_avail; |
| 203 | bool system_wide; |
Andrew Vagin | 3e76ac7 | 2011-12-20 17:32:45 +0300 | [diff] [blame] | 204 | bool period; |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 205 | unsigned int freq; |
Arnaldo Carvalho de Melo | 01c2d99 | 2011-11-09 09:16:26 -0200 | [diff] [blame] | 206 | unsigned int mmap_pages; |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 207 | unsigned int user_freq; |
| 208 | u64 default_interval; |
| 209 | u64 user_interval; |
| 210 | const char *cpu_list; |
| 211 | }; |
| 212 | |
Thomas Gleixner | 6eda583 | 2009-05-01 18:29:57 +0200 | [diff] [blame] | 213 | #endif |