Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
perf.h
Go to the documentation of this file.
1 #ifndef _PERF_PERF_H
2 #define _PERF_PERF_H
3 
4 struct winsize;
5 
6 void get_term_dimensions(struct winsize *ws);
7 
8 #include <asm/unistd.h>
9 
10 #if defined(__i386__)
11 #define rmb() asm volatile("lock; addl $0,0(%%esp)" ::: "memory")
12 #define cpu_relax() asm volatile("rep; nop" ::: "memory");
13 #define CPUINFO_PROC "model name"
14 #ifndef __NR_perf_event_open
15 # define __NR_perf_event_open 336
16 #endif
17 #endif
18 
19 #if defined(__x86_64__)
20 #define rmb() asm volatile("lfence" ::: "memory")
21 #define cpu_relax() asm volatile("rep; nop" ::: "memory");
22 #define CPUINFO_PROC "model name"
23 #ifndef __NR_perf_event_open
24 # define __NR_perf_event_open 298
25 #endif
26 #endif
27 
28 #ifdef __powerpc__
29 #define rmb() asm volatile ("sync" ::: "memory")
30 #define cpu_relax() asm volatile ("" ::: "memory");
31 #define CPUINFO_PROC "cpu"
32 #endif
33 
34 #ifdef __s390__
35 #define rmb() asm volatile("bcr 15,0" ::: "memory")
36 #define cpu_relax() asm volatile("" ::: "memory");
37 #endif
38 
39 #ifdef __sh__
40 #if defined(__SH4A__) || defined(__SH5__)
41 # define rmb() asm volatile("synco" ::: "memory")
42 #else
43 # define rmb() asm volatile("" ::: "memory")
44 #endif
45 #define cpu_relax() asm volatile("" ::: "memory")
46 #define CPUINFO_PROC "cpu type"
47 #endif
48 
49 #ifdef __hppa__
50 #define rmb() asm volatile("" ::: "memory")
51 #define cpu_relax() asm volatile("" ::: "memory");
52 #define CPUINFO_PROC "cpu"
53 #endif
54 
55 #ifdef __sparc__
56 #define rmb() asm volatile("":::"memory")
57 #define cpu_relax() asm volatile("":::"memory")
58 #define CPUINFO_PROC "cpu"
59 #endif
60 
61 #ifdef __alpha__
62 #define rmb() asm volatile("mb" ::: "memory")
63 #define cpu_relax() asm volatile("" ::: "memory")
64 #define CPUINFO_PROC "cpu model"
65 #endif
66 
67 #ifdef __ia64__
68 #define rmb() asm volatile ("mf" ::: "memory")
69 #define cpu_relax() asm volatile ("hint @pause" ::: "memory")
70 #define CPUINFO_PROC "model name"
71 #endif
72 
73 #ifdef __arm__
74 /*
75  * Use the __kuser_memory_barrier helper in the CPU helper page. See
76  * arch/arm/kernel/entry-armv.S in the kernel source for details.
77  */
78 #define rmb() ((void(*)(void))0xffff0fa0)()
79 #define cpu_relax() asm volatile("":::"memory")
80 #define CPUINFO_PROC "Processor"
81 #endif
82 
83 #ifdef __aarch64__
84 #define rmb() asm volatile("dmb ld" ::: "memory")
85 #define cpu_relax() asm volatile("yield" ::: "memory")
86 #endif
87 
88 #ifdef __mips__
89 #define rmb() asm volatile( \
90  ".set mips2\n\t" \
91  "sync\n\t" \
92  ".set mips0" \
93  : /* no output */ \
94  : /* no input */ \
95  : "memory")
96 #define cpu_relax() asm volatile("" ::: "memory")
97 #define CPUINFO_PROC "cpu model"
98 #endif
99 
100 #include <time.h>
101 #include <unistd.h>
102 #include <sys/types.h>
103 #include <sys/syscall.h>
104 
105 #include <linux/perf_event.h>
106 #include "util/types.h"
107 #include <stdbool.h>
108 
109 struct perf_mmap {
110  void *base;
111  int mask;
112  unsigned int prev;
113 };
114 
115 static inline unsigned int perf_mmap__read_head(struct perf_mmap *mm)
116 {
117  struct perf_event_mmap_page *pc = mm->base;
118  int head = pc->data_head;
119  rmb();
120  return head;
121 }
122 
123 static inline void perf_mmap__write_tail(struct perf_mmap *md,
124  unsigned long tail)
125 {
126  struct perf_event_mmap_page *pc = md->base;
127 
128  /*
129  * ensure all reads are done before we write the tail out.
130  */
131  /* mb(); */
132  pc->data_tail = tail;
133 }
134 
135 /*
136  * prctl(PR_TASK_PERF_EVENTS_DISABLE) will (cheaply) disable all
137  * counters in the current task.
138  */
139 #define PR_TASK_PERF_EVENTS_DISABLE 31
140 #define PR_TASK_PERF_EVENTS_ENABLE 32
141 
142 #ifndef NSEC_PER_SEC
143 # define NSEC_PER_SEC 1000000000ULL
144 #endif
145 
146 static inline unsigned long long rdclock(void)
147 {
148  struct timespec ts;
149 
151  return ts.tv_sec * 1000000000ULL + ts.tv_nsec;
152 }
153 
154 /*
155  * Pick up some kernel type conventions:
156  */
157 #define __user
158 #define asmlinkage
159 
160 #define unlikely(x) __builtin_expect(!!(x), 0)
161 #define min(x, y) ({ \
162  typeof(x) _min1 = (x); \
163  typeof(y) _min2 = (y); \
164  (void) (&_min1 == &_min2); \
165  _min1 < _min2 ? _min1 : _min2; })
166 
167 static inline int
169  pid_t pid, int cpu, int group_fd,
170  unsigned long flags)
171 {
172  return syscall(__NR_perf_event_open, attr, pid, cpu,
173  group_fd, flags);
174 }
175 
176 #define MAX_COUNTERS 256
177 #define MAX_NR_CPUS 256
178 
179 struct ip_callchain {
181  u64 ips[0];
182 };
183 
184 struct branch_flags {
188 };
189 
190 struct branch_entry {
194 };
195 
196 struct branch_stack {
199 };
200 
201 extern bool perf_host, perf_guest;
202 extern const char perf_version_string[];
203 
204 void pthread__unblock_sigwinch(void);
205 
206 #include "util/target.h"
207 
212 };
213 
217  bool group;
219  bool no_delay;
228  bool period;
229  unsigned int freq;
230  unsigned int mmap_pages;
231  unsigned int user_freq;
236 };
237 
238 #endif