1 #ifndef _PERF_PERF_H 2 #define _PERF_PERF_H 3 4 #include <asm/unistd.h> 5 6 #if defined(__i386__) 7 #define rmb() asm volatile("lock; addl $0,0(%%esp)" ::: "memory") 8 #define cpu_relax() asm volatile("rep; nop" ::: "memory"); 9 #define CPUINFO_PROC "model name" 10 #ifndef __NR_perf_event_open 11 # define __NR_perf_event_open 336 12 #endif 13 #endif 14 15 #if defined(__x86_64__) 16 #define rmb() asm volatile("lfence" ::: "memory") 17 #define cpu_relax() asm volatile("rep; nop" ::: "memory"); 18 #define CPUINFO_PROC "model name" 19 #ifndef __NR_perf_event_open 20 # define __NR_perf_event_open 298 21 #endif 22 #endif 23 24 #ifdef __powerpc__ 25 #include "../../arch/powerpc/include/uapi/asm/unistd.h" 26 #define rmb() asm volatile ("sync" ::: "memory") 27 #define cpu_relax() asm volatile ("" ::: "memory"); 28 #define CPUINFO_PROC "cpu" 29 #endif 30 31 #ifdef __s390__ 32 #define rmb() asm volatile("bcr 15,0" ::: "memory") 33 #define cpu_relax() asm volatile("" ::: "memory"); 34 #endif 35 36 #ifdef __sh__ 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") 43 #define CPUINFO_PROC "cpu type" 44 #endif 45 46 #ifdef __hppa__ 47 #define rmb() asm volatile("" ::: "memory") 48 #define cpu_relax() asm volatile("" ::: "memory"); 49 #define CPUINFO_PROC "cpu" 50 #endif 51 52 #ifdef __sparc__ 53 #define rmb() asm volatile("":::"memory") 54 #define cpu_relax() asm volatile("":::"memory") 55 #define CPUINFO_PROC "cpu" 56 #endif 57 58 #ifdef __alpha__ 59 #define rmb() asm volatile("mb" ::: "memory") 60 #define cpu_relax() asm volatile("" ::: "memory") 61 #define CPUINFO_PROC "cpu model" 62 #endif 63 64 #ifdef __ia64__ 65 #define rmb() asm volatile ("mf" ::: "memory") 66 #define cpu_relax() asm volatile ("hint @pause" ::: "memory") 67 #define CPUINFO_PROC "model name" 68 #endif 69 70 #ifdef __arm__ 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 */ 75 #define rmb() ((void(*)(void))0xffff0fa0)() 76 #define cpu_relax() asm volatile("":::"memory") 77 #define CPUINFO_PROC "Processor" 78 #endif 79 80 #ifdef __aarch64__ 81 #define rmb() asm volatile("dmb ld" ::: "memory") 82 #define cpu_relax() asm volatile("yield" ::: "memory") 83 #endif 84 85 #ifdef __mips__ 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") 94 #define CPUINFO_PROC "cpu model" 95 #endif 96 97 #include <time.h> 98 #include <unistd.h> 99 #include <sys/types.h> 100 #include <sys/syscall.h> 101 102 #include <linux/perf_event.h> 103 #include "util/types.h" 104 #include <stdbool.h> 105 106 /* 107 * prctl(PR_TASK_PERF_EVENTS_DISABLE) will (cheaply) disable all 108 * counters in the current task. 109 */ 110 #define PR_TASK_PERF_EVENTS_DISABLE 31 111 #define PR_TASK_PERF_EVENTS_ENABLE 32 112 113 #ifndef NSEC_PER_SEC 114 # define NSEC_PER_SEC 1000000000ULL 115 #endif 116 117 static inline unsigned long long rdclock(void) 118 { 119 struct timespec ts; 120 121 clock_gettime(CLOCK_MONOTONIC, &ts); 122 return ts.tv_sec * 1000000000ULL + ts.tv_nsec; 123 } 124 125 /* 126 * Pick up some kernel type conventions: 127 */ 128 #define __user 129 #define asmlinkage 130 131 #define unlikely(x) __builtin_expect(!!(x), 0) 132 #define min(x, y) ({ \ 133 typeof(x) _min1 = (x); \ 134 typeof(y) _min2 = (y); \ 135 (void) (&_min1 == &_min2); \ 136 _min1 < _min2 ? _min1 : _min2; }) 137 138 extern bool test_attr__enabled; 139 void test_attr__init(void); 140 void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu, 141 int fd, int group_fd, unsigned long flags); 142 143 static inline int 144 sys_perf_event_open(struct perf_event_attr *attr, 145 pid_t pid, int cpu, int group_fd, 146 unsigned long flags) 147 { 148 int fd; 149 150 fd = syscall(__NR_perf_event_open, attr, pid, cpu, 151 group_fd, flags); 152 153 if (unlikely(test_attr__enabled)) 154 test_attr__open(attr, pid, cpu, fd, group_fd, flags); 155 156 return fd; 157 } 158 159 #define MAX_COUNTERS 256 160 #define MAX_NR_CPUS 256 161 162 struct ip_callchain { 163 u64 nr; 164 u64 ips[0]; 165 }; 166 167 struct branch_flags { 168 u64 mispred:1; 169 u64 predicted:1; 170 u64 reserved:62; 171 }; 172 173 struct branch_entry { 174 u64 from; 175 u64 to; 176 struct branch_flags flags; 177 }; 178 179 struct branch_stack { 180 u64 nr; 181 struct branch_entry entries[0]; 182 }; 183 184 extern const char *input_name; 185 extern bool perf_host, perf_guest; 186 extern const char perf_version_string[]; 187 188 void pthread__unblock_sigwinch(void); 189 190 #include "util/target.h" 191 192 enum perf_call_graph_mode { 193 CALLCHAIN_NONE, 194 CALLCHAIN_FP, 195 CALLCHAIN_DWARF 196 }; 197 198 struct perf_record_opts { 199 struct perf_target target; 200 int call_graph; 201 bool group; 202 bool inherit_stat; 203 bool no_delay; 204 bool no_inherit; 205 bool no_samples; 206 bool pipe_output; 207 bool raw_samples; 208 bool sample_address; 209 bool sample_time; 210 bool period; 211 unsigned int freq; 212 unsigned int mmap_pages; 213 unsigned int user_freq; 214 u64 branch_stack; 215 u64 default_interval; 216 u64 user_interval; 217 u16 stack_dump_size; 218 }; 219 220 #endif 221