usb_serial: Kill port mutex
[linux-2.6/kvm.git] / include / linux / perf_counter.h
blobe3fb256067066ad947596efeb9f848ee136acbe7
1 /*
2 * NOTE: this file will be removed in a future kernel release, it is
3 * provided as a courtesy copy of user-space code that relies on the
4 * old (pre-rename) symbols and constants.
6 * Performance events:
8 * Copyright (C) 2008-2009, Thomas Gleixner <tglx@linutronix.de>
9 * Copyright (C) 2008-2009, Red Hat, Inc., Ingo Molnar
10 * Copyright (C) 2008-2009, Red Hat, Inc., Peter Zijlstra
12 * Data type definitions, declarations, prototypes.
14 * Started by: Thomas Gleixner and Ingo Molnar
16 * For licencing details see kernel-base/COPYING
18 #ifndef _LINUX_PERF_COUNTER_H
19 #define _LINUX_PERF_COUNTER_H
21 #include <linux/types.h>
22 #include <linux/ioctl.h>
23 #include <asm/byteorder.h>
26 * User-space ABI bits:
30 * attr.type
32 enum perf_type_id {
33 PERF_TYPE_HARDWARE = 0,
34 PERF_TYPE_SOFTWARE = 1,
35 PERF_TYPE_TRACEPOINT = 2,
36 PERF_TYPE_HW_CACHE = 3,
37 PERF_TYPE_RAW = 4,
39 PERF_TYPE_MAX, /* non-ABI */
43 * Generalized performance counter event types, used by the
44 * attr.event_id parameter of the sys_perf_counter_open()
45 * syscall:
47 enum perf_hw_id {
49 * Common hardware events, generalized by the kernel:
51 PERF_COUNT_HW_CPU_CYCLES = 0,
52 PERF_COUNT_HW_INSTRUCTIONS = 1,
53 PERF_COUNT_HW_CACHE_REFERENCES = 2,
54 PERF_COUNT_HW_CACHE_MISSES = 3,
55 PERF_COUNT_HW_BRANCH_INSTRUCTIONS = 4,
56 PERF_COUNT_HW_BRANCH_MISSES = 5,
57 PERF_COUNT_HW_BUS_CYCLES = 6,
59 PERF_COUNT_HW_MAX, /* non-ABI */
63 * Generalized hardware cache counters:
65 * { L1-D, L1-I, LLC, ITLB, DTLB, BPU } x
66 * { read, write, prefetch } x
67 * { accesses, misses }
69 enum perf_hw_cache_id {
70 PERF_COUNT_HW_CACHE_L1D = 0,
71 PERF_COUNT_HW_CACHE_L1I = 1,
72 PERF_COUNT_HW_CACHE_LL = 2,
73 PERF_COUNT_HW_CACHE_DTLB = 3,
74 PERF_COUNT_HW_CACHE_ITLB = 4,
75 PERF_COUNT_HW_CACHE_BPU = 5,
77 PERF_COUNT_HW_CACHE_MAX, /* non-ABI */
80 enum perf_hw_cache_op_id {
81 PERF_COUNT_HW_CACHE_OP_READ = 0,
82 PERF_COUNT_HW_CACHE_OP_WRITE = 1,
83 PERF_COUNT_HW_CACHE_OP_PREFETCH = 2,
85 PERF_COUNT_HW_CACHE_OP_MAX, /* non-ABI */
88 enum perf_hw_cache_op_result_id {
89 PERF_COUNT_HW_CACHE_RESULT_ACCESS = 0,
90 PERF_COUNT_HW_CACHE_RESULT_MISS = 1,
92 PERF_COUNT_HW_CACHE_RESULT_MAX, /* non-ABI */
96 * Special "software" counters provided by the kernel, even if the hardware
97 * does not support performance counters. These counters measure various
98 * physical and sw events of the kernel (and allow the profiling of them as
99 * well):
101 enum perf_sw_ids {
102 PERF_COUNT_SW_CPU_CLOCK = 0,
103 PERF_COUNT_SW_TASK_CLOCK = 1,
104 PERF_COUNT_SW_PAGE_FAULTS = 2,
105 PERF_COUNT_SW_CONTEXT_SWITCHES = 3,
106 PERF_COUNT_SW_CPU_MIGRATIONS = 4,
107 PERF_COUNT_SW_PAGE_FAULTS_MIN = 5,
108 PERF_COUNT_SW_PAGE_FAULTS_MAJ = 6,
109 PERF_COUNT_SW_ALIGNMENT_FAULTS = 7,
110 PERF_COUNT_SW_EMULATION_FAULTS = 8,
112 PERF_COUNT_SW_MAX, /* non-ABI */
116 * Bits that can be set in attr.sample_type to request information
117 * in the overflow packets.
119 enum perf_counter_sample_format {
120 PERF_SAMPLE_IP = 1U << 0,
121 PERF_SAMPLE_TID = 1U << 1,
122 PERF_SAMPLE_TIME = 1U << 2,
123 PERF_SAMPLE_ADDR = 1U << 3,
124 PERF_SAMPLE_READ = 1U << 4,
125 PERF_SAMPLE_CALLCHAIN = 1U << 5,
126 PERF_SAMPLE_ID = 1U << 6,
127 PERF_SAMPLE_CPU = 1U << 7,
128 PERF_SAMPLE_PERIOD = 1U << 8,
129 PERF_SAMPLE_STREAM_ID = 1U << 9,
130 PERF_SAMPLE_RAW = 1U << 10,
132 PERF_SAMPLE_MAX = 1U << 11, /* non-ABI */
136 * The format of the data returned by read() on a perf counter fd,
137 * as specified by attr.read_format:
139 * struct read_format {
140 * { u64 value;
141 * { u64 time_enabled; } && PERF_FORMAT_ENABLED
142 * { u64 time_running; } && PERF_FORMAT_RUNNING
143 * { u64 id; } && PERF_FORMAT_ID
144 * } && !PERF_FORMAT_GROUP
146 * { u64 nr;
147 * { u64 time_enabled; } && PERF_FORMAT_ENABLED
148 * { u64 time_running; } && PERF_FORMAT_RUNNING
149 * { u64 value;
150 * { u64 id; } && PERF_FORMAT_ID
151 * } cntr[nr];
152 * } && PERF_FORMAT_GROUP
153 * };
155 enum perf_counter_read_format {
156 PERF_FORMAT_TOTAL_TIME_ENABLED = 1U << 0,
157 PERF_FORMAT_TOTAL_TIME_RUNNING = 1U << 1,
158 PERF_FORMAT_ID = 1U << 2,
159 PERF_FORMAT_GROUP = 1U << 3,
161 PERF_FORMAT_MAX = 1U << 4, /* non-ABI */
164 #define PERF_ATTR_SIZE_VER0 64 /* sizeof first published struct */
167 * Hardware event to monitor via a performance monitoring counter:
169 struct perf_counter_attr {
172 * Major type: hardware/software/tracepoint/etc.
174 __u32 type;
177 * Size of the attr structure, for fwd/bwd compat.
179 __u32 size;
182 * Type specific configuration information.
184 __u64 config;
186 union {
187 __u64 sample_period;
188 __u64 sample_freq;
191 __u64 sample_type;
192 __u64 read_format;
194 __u64 disabled : 1, /* off by default */
195 inherit : 1, /* children inherit it */
196 pinned : 1, /* must always be on PMU */
197 exclusive : 1, /* only group on PMU */
198 exclude_user : 1, /* don't count user */
199 exclude_kernel : 1, /* ditto kernel */
200 exclude_hv : 1, /* ditto hypervisor */
201 exclude_idle : 1, /* don't count when idle */
202 mmap : 1, /* include mmap data */
203 comm : 1, /* include comm data */
204 freq : 1, /* use freq, not period */
205 inherit_stat : 1, /* per task counts */
206 enable_on_exec : 1, /* next exec enables */
207 task : 1, /* trace fork/exit */
208 watermark : 1, /* wakeup_watermark */
210 __reserved_1 : 49;
212 union {
213 __u32 wakeup_events; /* wakeup every n events */
214 __u32 wakeup_watermark; /* bytes before wakeup */
216 __u32 __reserved_2;
218 __u64 __reserved_3;
222 * Ioctls that can be done on a perf counter fd:
224 #define PERF_COUNTER_IOC_ENABLE _IO ('$', 0)
225 #define PERF_COUNTER_IOC_DISABLE _IO ('$', 1)
226 #define PERF_COUNTER_IOC_REFRESH _IO ('$', 2)
227 #define PERF_COUNTER_IOC_RESET _IO ('$', 3)
228 #define PERF_COUNTER_IOC_PERIOD _IOW('$', 4, u64)
229 #define PERF_COUNTER_IOC_SET_OUTPUT _IO ('$', 5)
230 #define PERF_COUNTER_IOC_SET_FILTER _IOW('$', 6, char *)
232 enum perf_counter_ioc_flags {
233 PERF_IOC_FLAG_GROUP = 1U << 0,
237 * Structure of the page that can be mapped via mmap
239 struct perf_counter_mmap_page {
240 __u32 version; /* version number of this structure */
241 __u32 compat_version; /* lowest version this is compat with */
244 * Bits needed to read the hw counters in user-space.
246 * u32 seq;
247 * s64 count;
249 * do {
250 * seq = pc->lock;
252 * barrier()
253 * if (pc->index) {
254 * count = pmc_read(pc->index - 1);
255 * count += pc->offset;
256 * } else
257 * goto regular_read;
259 * barrier();
260 * } while (pc->lock != seq);
262 * NOTE: for obvious reason this only works on self-monitoring
263 * processes.
265 __u32 lock; /* seqlock for synchronization */
266 __u32 index; /* hardware counter identifier */
267 __s64 offset; /* add to hardware counter value */
268 __u64 time_enabled; /* time counter active */
269 __u64 time_running; /* time counter on cpu */
272 * Hole for extension of the self monitor capabilities
275 __u64 __reserved[123]; /* align to 1k */
278 * Control data for the mmap() data buffer.
280 * User-space reading the @data_head value should issue an rmb(), on
281 * SMP capable platforms, after reading this value -- see
282 * perf_counter_wakeup().
284 * When the mapping is PROT_WRITE the @data_tail value should be
285 * written by userspace to reflect the last read data. In this case
286 * the kernel will not over-write unread data.
288 __u64 data_head; /* head in the data section */
289 __u64 data_tail; /* user-space written tail */
292 #define PERF_EVENT_MISC_CPUMODE_MASK (3 << 0)
293 #define PERF_EVENT_MISC_CPUMODE_UNKNOWN (0 << 0)
294 #define PERF_EVENT_MISC_KERNEL (1 << 0)
295 #define PERF_EVENT_MISC_USER (2 << 0)
296 #define PERF_EVENT_MISC_HYPERVISOR (3 << 0)
298 struct perf_event_header {
299 __u32 type;
300 __u16 misc;
301 __u16 size;
304 enum perf_event_type {
307 * The MMAP events record the PROT_EXEC mappings so that we can
308 * correlate userspace IPs to code. They have the following structure:
310 * struct {
311 * struct perf_event_header header;
313 * u32 pid, tid;
314 * u64 addr;
315 * u64 len;
316 * u64 pgoff;
317 * char filename[];
318 * };
320 PERF_EVENT_MMAP = 1,
323 * struct {
324 * struct perf_event_header header;
325 * u64 id;
326 * u64 lost;
327 * };
329 PERF_EVENT_LOST = 2,
332 * struct {
333 * struct perf_event_header header;
335 * u32 pid, tid;
336 * char comm[];
337 * };
339 PERF_EVENT_COMM = 3,
342 * struct {
343 * struct perf_event_header header;
344 * u32 pid, ppid;
345 * u32 tid, ptid;
346 * u64 time;
347 * };
349 PERF_EVENT_EXIT = 4,
352 * struct {
353 * struct perf_event_header header;
354 * u64 time;
355 * u64 id;
356 * u64 stream_id;
357 * };
359 PERF_EVENT_THROTTLE = 5,
360 PERF_EVENT_UNTHROTTLE = 6,
363 * struct {
364 * struct perf_event_header header;
365 * u32 pid, ppid;
366 * u32 tid, ptid;
367 * u64 time;
368 * };
370 PERF_EVENT_FORK = 7,
373 * struct {
374 * struct perf_event_header header;
375 * u32 pid, tid;
377 * struct read_format values;
378 * };
380 PERF_EVENT_READ = 8,
383 * struct {
384 * struct perf_event_header header;
386 * { u64 ip; } && PERF_SAMPLE_IP
387 * { u32 pid, tid; } && PERF_SAMPLE_TID
388 * { u64 time; } && PERF_SAMPLE_TIME
389 * { u64 addr; } && PERF_SAMPLE_ADDR
390 * { u64 id; } && PERF_SAMPLE_ID
391 * { u64 stream_id;} && PERF_SAMPLE_STREAM_ID
392 * { u32 cpu, res; } && PERF_SAMPLE_CPU
393 * { u64 period; } && PERF_SAMPLE_PERIOD
395 * { struct read_format values; } && PERF_SAMPLE_READ
397 * { u64 nr,
398 * u64 ips[nr]; } && PERF_SAMPLE_CALLCHAIN
401 * # The RAW record below is opaque data wrt the ABI
403 * # That is, the ABI doesn't make any promises wrt to
404 * # the stability of its content, it may vary depending
405 * # on event, hardware, kernel version and phase of
406 * # the moon.
408 * # In other words, PERF_SAMPLE_RAW contents are not an ABI.
411 * { u32 size;
412 * char data[size];}&& PERF_SAMPLE_RAW
413 * };
415 PERF_EVENT_SAMPLE = 9,
417 PERF_EVENT_MAX, /* non-ABI */
420 enum perf_callchain_context {
421 PERF_CONTEXT_HV = (__u64)-32,
422 PERF_CONTEXT_KERNEL = (__u64)-128,
423 PERF_CONTEXT_USER = (__u64)-512,
425 PERF_CONTEXT_GUEST = (__u64)-2048,
426 PERF_CONTEXT_GUEST_KERNEL = (__u64)-2176,
427 PERF_CONTEXT_GUEST_USER = (__u64)-2560,
429 PERF_CONTEXT_MAX = (__u64)-4095,
432 #define PERF_FLAG_FD_NO_GROUP (1U << 0)
433 #define PERF_FLAG_FD_OUTPUT (1U << 1)
436 * In case some app still references the old symbols:
439 #define __NR_perf_counter_open __NR_perf_event_open
441 #define PR_TASK_PERF_COUNTERS_DISABLE PR_TASK_PERF_EVENTS_DISABLE
442 #define PR_TASK_PERF_COUNTERS_ENABLE PR_TASK_PERF_EVENTS_ENABLE
444 #endif /* _LINUX_PERF_COUNTER_H */