]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/perf_event.h
hw-breakpoint: Move asm-generic/hw_breakpoint.h to linux/hw_breakpoint.h
[mirror_ubuntu-bionic-kernel.git] / include / linux / perf_event.h
CommitLineData
0793a61d 1/*
57c0c15b 2 * Performance events:
0793a61d 3 *
a308444c
IM
4 * Copyright (C) 2008-2009, Thomas Gleixner <tglx@linutronix.de>
5 * Copyright (C) 2008-2009, Red Hat, Inc., Ingo Molnar
6 * Copyright (C) 2008-2009, Red Hat, Inc., Peter Zijlstra
0793a61d 7 *
57c0c15b 8 * Data type definitions, declarations, prototypes.
0793a61d 9 *
a308444c 10 * Started by: Thomas Gleixner and Ingo Molnar
0793a61d 11 *
57c0c15b 12 * For licencing details see kernel-base/COPYING
0793a61d 13 */
cdd6c482
IM
14#ifndef _LINUX_PERF_EVENT_H
15#define _LINUX_PERF_EVENT_H
0793a61d 16
f3dfd265
PM
17#include <linux/types.h>
18#include <linux/ioctl.h>
9aaa131a 19#include <asm/byteorder.h>
0793a61d
TG
20
21/*
9f66a381
IM
22 * User-space ABI bits:
23 */
24
25/*
0d48696f 26 * attr.type
0793a61d 27 */
1c432d89 28enum perf_type_id {
a308444c
IM
29 PERF_TYPE_HARDWARE = 0,
30 PERF_TYPE_SOFTWARE = 1,
31 PERF_TYPE_TRACEPOINT = 2,
32 PERF_TYPE_HW_CACHE = 3,
33 PERF_TYPE_RAW = 4,
b8e83514 34
a308444c 35 PERF_TYPE_MAX, /* non-ABI */
b8e83514 36};
6c594c21 37
b8e83514 38/*
cdd6c482
IM
39 * Generalized performance event event_id types, used by the
40 * attr.event_id parameter of the sys_perf_event_open()
a308444c 41 * syscall:
b8e83514 42 */
1c432d89 43enum perf_hw_id {
9f66a381 44 /*
b8e83514 45 * Common hardware events, generalized by the kernel:
9f66a381 46 */
f4dbfa8f
PZ
47 PERF_COUNT_HW_CPU_CYCLES = 0,
48 PERF_COUNT_HW_INSTRUCTIONS = 1,
49 PERF_COUNT_HW_CACHE_REFERENCES = 2,
50 PERF_COUNT_HW_CACHE_MISSES = 3,
51 PERF_COUNT_HW_BRANCH_INSTRUCTIONS = 4,
52 PERF_COUNT_HW_BRANCH_MISSES = 5,
53 PERF_COUNT_HW_BUS_CYCLES = 6,
54
a308444c 55 PERF_COUNT_HW_MAX, /* non-ABI */
b8e83514 56};
e077df4f 57
8326f44d 58/*
cdd6c482 59 * Generalized hardware cache events:
8326f44d 60 *
8be6e8f3 61 * { L1-D, L1-I, LLC, ITLB, DTLB, BPU } x
8326f44d
IM
62 * { read, write, prefetch } x
63 * { accesses, misses }
64 */
1c432d89 65enum perf_hw_cache_id {
a308444c
IM
66 PERF_COUNT_HW_CACHE_L1D = 0,
67 PERF_COUNT_HW_CACHE_L1I = 1,
68 PERF_COUNT_HW_CACHE_LL = 2,
69 PERF_COUNT_HW_CACHE_DTLB = 3,
70 PERF_COUNT_HW_CACHE_ITLB = 4,
71 PERF_COUNT_HW_CACHE_BPU = 5,
72
73 PERF_COUNT_HW_CACHE_MAX, /* non-ABI */
8326f44d
IM
74};
75
1c432d89 76enum perf_hw_cache_op_id {
a308444c
IM
77 PERF_COUNT_HW_CACHE_OP_READ = 0,
78 PERF_COUNT_HW_CACHE_OP_WRITE = 1,
79 PERF_COUNT_HW_CACHE_OP_PREFETCH = 2,
8326f44d 80
a308444c 81 PERF_COUNT_HW_CACHE_OP_MAX, /* non-ABI */
8326f44d
IM
82};
83
1c432d89
PZ
84enum perf_hw_cache_op_result_id {
85 PERF_COUNT_HW_CACHE_RESULT_ACCESS = 0,
86 PERF_COUNT_HW_CACHE_RESULT_MISS = 1,
8326f44d 87
a308444c 88 PERF_COUNT_HW_CACHE_RESULT_MAX, /* non-ABI */
8326f44d
IM
89};
90
b8e83514 91/*
cdd6c482
IM
92 * Special "software" events provided by the kernel, even if the hardware
93 * does not support performance events. These events measure various
b8e83514
PZ
94 * physical and sw events of the kernel (and allow the profiling of them as
95 * well):
96 */
1c432d89 97enum perf_sw_ids {
a308444c
IM
98 PERF_COUNT_SW_CPU_CLOCK = 0,
99 PERF_COUNT_SW_TASK_CLOCK = 1,
100 PERF_COUNT_SW_PAGE_FAULTS = 2,
101 PERF_COUNT_SW_CONTEXT_SWITCHES = 3,
102 PERF_COUNT_SW_CPU_MIGRATIONS = 4,
103 PERF_COUNT_SW_PAGE_FAULTS_MIN = 5,
104 PERF_COUNT_SW_PAGE_FAULTS_MAJ = 6,
105
106 PERF_COUNT_SW_MAX, /* non-ABI */
0793a61d
TG
107};
108
8a057d84 109/*
0d48696f 110 * Bits that can be set in attr.sample_type to request information
8a057d84
PZ
111 * in the overflow packets.
112 */
cdd6c482 113enum perf_event_sample_format {
a308444c
IM
114 PERF_SAMPLE_IP = 1U << 0,
115 PERF_SAMPLE_TID = 1U << 1,
116 PERF_SAMPLE_TIME = 1U << 2,
117 PERF_SAMPLE_ADDR = 1U << 3,
3dab77fb 118 PERF_SAMPLE_READ = 1U << 4,
a308444c
IM
119 PERF_SAMPLE_CALLCHAIN = 1U << 5,
120 PERF_SAMPLE_ID = 1U << 6,
121 PERF_SAMPLE_CPU = 1U << 7,
122 PERF_SAMPLE_PERIOD = 1U << 8,
7f453c24 123 PERF_SAMPLE_STREAM_ID = 1U << 9,
3a43ce68 124 PERF_SAMPLE_RAW = 1U << 10,
974802ea 125
f413cdb8 126 PERF_SAMPLE_MAX = 1U << 11, /* non-ABI */
8a057d84
PZ
127};
128
53cfbf59 129/*
cdd6c482 130 * The format of the data returned by read() on a perf event fd,
3dab77fb
PZ
131 * as specified by attr.read_format:
132 *
133 * struct read_format {
57c0c15b
IM
134 * { u64 value;
135 * { u64 time_enabled; } && PERF_FORMAT_ENABLED
136 * { u64 time_running; } && PERF_FORMAT_RUNNING
137 * { u64 id; } && PERF_FORMAT_ID
138 * } && !PERF_FORMAT_GROUP
3dab77fb 139 *
57c0c15b
IM
140 * { u64 nr;
141 * { u64 time_enabled; } && PERF_FORMAT_ENABLED
142 * { u64 time_running; } && PERF_FORMAT_RUNNING
143 * { u64 value;
144 * { u64 id; } && PERF_FORMAT_ID
145 * } cntr[nr];
146 * } && PERF_FORMAT_GROUP
3dab77fb 147 * };
53cfbf59 148 */
cdd6c482 149enum perf_event_read_format {
a308444c
IM
150 PERF_FORMAT_TOTAL_TIME_ENABLED = 1U << 0,
151 PERF_FORMAT_TOTAL_TIME_RUNNING = 1U << 1,
152 PERF_FORMAT_ID = 1U << 2,
3dab77fb 153 PERF_FORMAT_GROUP = 1U << 3,
974802ea 154
57c0c15b 155 PERF_FORMAT_MAX = 1U << 4, /* non-ABI */
53cfbf59
PM
156};
157
974802ea
PZ
158#define PERF_ATTR_SIZE_VER0 64 /* sizeof first published struct */
159
9f66a381 160/*
cdd6c482 161 * Hardware event_id to monitor via a performance monitoring event:
9f66a381 162 */
cdd6c482 163struct perf_event_attr {
974802ea 164
f4a2deb4 165 /*
a21ca2ca
IM
166 * Major type: hardware/software/tracepoint/etc.
167 */
168 __u32 type;
974802ea
PZ
169
170 /*
171 * Size of the attr structure, for fwd/bwd compat.
172 */
173 __u32 size;
a21ca2ca
IM
174
175 /*
176 * Type specific configuration information.
f4a2deb4
PZ
177 */
178 __u64 config;
9f66a381 179
60db5e09 180 union {
b23f3325
PZ
181 __u64 sample_period;
182 __u64 sample_freq;
60db5e09
PZ
183 };
184
b23f3325
PZ
185 __u64 sample_type;
186 __u64 read_format;
9f66a381 187
2743a5b0 188 __u64 disabled : 1, /* off by default */
0475f9ea
PM
189 inherit : 1, /* children inherit it */
190 pinned : 1, /* must always be on PMU */
191 exclusive : 1, /* only group on PMU */
192 exclude_user : 1, /* don't count user */
193 exclude_kernel : 1, /* ditto kernel */
194 exclude_hv : 1, /* ditto hypervisor */
2743a5b0 195 exclude_idle : 1, /* don't count when idle */
0a4a9391 196 mmap : 1, /* include mmap data */
8d1b2d93 197 comm : 1, /* include comm data */
60db5e09 198 freq : 1, /* use freq, not period */
bfbd3381 199 inherit_stat : 1, /* per task counts */
57e7986e 200 enable_on_exec : 1, /* next exec enables */
9f498cc5 201 task : 1, /* trace fork/exit */
2667de81 202 watermark : 1, /* wakeup_watermark */
0475f9ea 203
2667de81 204 __reserved_1 : 49;
2743a5b0 205
2667de81
PZ
206 union {
207 __u32 wakeup_events; /* wakeup every n events */
208 __u32 wakeup_watermark; /* bytes before wakeup */
209 };
974802ea 210 __u32 __reserved_2;
9f66a381 211
974802ea 212 __u64 __reserved_3;
eab656ae
TG
213};
214
d859e29f 215/*
cdd6c482 216 * Ioctls that can be done on a perf event fd:
d859e29f 217 */
cdd6c482 218#define PERF_EVENT_IOC_ENABLE _IO ('$', 0)
57c0c15b
IM
219#define PERF_EVENT_IOC_DISABLE _IO ('$', 1)
220#define PERF_EVENT_IOC_REFRESH _IO ('$', 2)
cdd6c482
IM
221#define PERF_EVENT_IOC_RESET _IO ('$', 3)
222#define PERF_EVENT_IOC_PERIOD _IOW('$', 4, u64)
223#define PERF_EVENT_IOC_SET_OUTPUT _IO ('$', 5)
6fb2915d 224#define PERF_EVENT_IOC_SET_FILTER _IOW('$', 6, char *)
cdd6c482
IM
225
226enum perf_event_ioc_flags {
3df5edad
PZ
227 PERF_IOC_FLAG_GROUP = 1U << 0,
228};
d859e29f 229
37d81828
PM
230/*
231 * Structure of the page that can be mapped via mmap
232 */
cdd6c482 233struct perf_event_mmap_page {
37d81828
PM
234 __u32 version; /* version number of this structure */
235 __u32 compat_version; /* lowest version this is compat with */
38ff667b
PZ
236
237 /*
cdd6c482 238 * Bits needed to read the hw events in user-space.
38ff667b 239 *
92f22a38
PZ
240 * u32 seq;
241 * s64 count;
38ff667b 242 *
a2e87d06
PZ
243 * do {
244 * seq = pc->lock;
38ff667b 245 *
a2e87d06
PZ
246 * barrier()
247 * if (pc->index) {
248 * count = pmc_read(pc->index - 1);
249 * count += pc->offset;
250 * } else
251 * goto regular_read;
38ff667b 252 *
a2e87d06
PZ
253 * barrier();
254 * } while (pc->lock != seq);
38ff667b 255 *
92f22a38
PZ
256 * NOTE: for obvious reason this only works on self-monitoring
257 * processes.
38ff667b 258 */
37d81828 259 __u32 lock; /* seqlock for synchronization */
cdd6c482
IM
260 __u32 index; /* hardware event identifier */
261 __s64 offset; /* add to hardware event value */
262 __u64 time_enabled; /* time event active */
263 __u64 time_running; /* time event on cpu */
7b732a75 264
41f95331
PZ
265 /*
266 * Hole for extension of the self monitor capabilities
267 */
268
7f8b4e4e 269 __u64 __reserved[123]; /* align to 1k */
41f95331 270
38ff667b
PZ
271 /*
272 * Control data for the mmap() data buffer.
273 *
43a21ea8
PZ
274 * User-space reading the @data_head value should issue an rmb(), on
275 * SMP capable platforms, after reading this value -- see
cdd6c482 276 * perf_event_wakeup().
43a21ea8
PZ
277 *
278 * When the mapping is PROT_WRITE the @data_tail value should be
279 * written by userspace to reflect the last read data. In this case
280 * the kernel will not over-write unread data.
38ff667b 281 */
8e3747c1 282 __u64 data_head; /* head in the data section */
43a21ea8 283 __u64 data_tail; /* user-space written tail */
37d81828
PM
284};
285
cdd6c482
IM
286#define PERF_RECORD_MISC_CPUMODE_MASK (3 << 0)
287#define PERF_RECORD_MISC_CPUMODE_UNKNOWN (0 << 0)
288#define PERF_RECORD_MISC_KERNEL (1 << 0)
289#define PERF_RECORD_MISC_USER (2 << 0)
290#define PERF_RECORD_MISC_HYPERVISOR (3 << 0)
6fab0192 291
5c148194
PZ
292struct perf_event_header {
293 __u32 type;
6fab0192
PZ
294 __u16 misc;
295 __u16 size;
5c148194
PZ
296};
297
298enum perf_event_type {
5ed00415 299
0c593b34
PZ
300 /*
301 * The MMAP events record the PROT_EXEC mappings so that we can
302 * correlate userspace IPs to code. They have the following structure:
303 *
304 * struct {
0127c3ea 305 * struct perf_event_header header;
0c593b34 306 *
0127c3ea
IM
307 * u32 pid, tid;
308 * u64 addr;
309 * u64 len;
310 * u64 pgoff;
311 * char filename[];
0c593b34
PZ
312 * };
313 */
cdd6c482 314 PERF_RECORD_MMAP = 1,
0a4a9391 315
43a21ea8
PZ
316 /*
317 * struct {
57c0c15b
IM
318 * struct perf_event_header header;
319 * u64 id;
320 * u64 lost;
43a21ea8
PZ
321 * };
322 */
cdd6c482 323 PERF_RECORD_LOST = 2,
43a21ea8 324
8d1b2d93
PZ
325 /*
326 * struct {
0127c3ea 327 * struct perf_event_header header;
8d1b2d93 328 *
0127c3ea
IM
329 * u32 pid, tid;
330 * char comm[];
8d1b2d93
PZ
331 * };
332 */
cdd6c482 333 PERF_RECORD_COMM = 3,
8d1b2d93 334
9f498cc5
PZ
335 /*
336 * struct {
337 * struct perf_event_header header;
338 * u32 pid, ppid;
339 * u32 tid, ptid;
393b2ad8 340 * u64 time;
9f498cc5
PZ
341 * };
342 */
cdd6c482 343 PERF_RECORD_EXIT = 4,
9f498cc5 344
26b119bc
PZ
345 /*
346 * struct {
0127c3ea
IM
347 * struct perf_event_header header;
348 * u64 time;
689802b2 349 * u64 id;
7f453c24 350 * u64 stream_id;
a78ac325
PZ
351 * };
352 */
cdd6c482
IM
353 PERF_RECORD_THROTTLE = 5,
354 PERF_RECORD_UNTHROTTLE = 6,
a78ac325 355
60313ebe
PZ
356 /*
357 * struct {
a21ca2ca
IM
358 * struct perf_event_header header;
359 * u32 pid, ppid;
9f498cc5 360 * u32 tid, ptid;
a6f10a2f 361 * u64 time;
60313ebe
PZ
362 * };
363 */
cdd6c482 364 PERF_RECORD_FORK = 7,
60313ebe 365
38b200d6
PZ
366 /*
367 * struct {
368 * struct perf_event_header header;
369 * u32 pid, tid;
3dab77fb
PZ
370 *
371 * struct read_format values;
38b200d6
PZ
372 * };
373 */
cdd6c482 374 PERF_RECORD_READ = 8,
38b200d6 375
8a057d84 376 /*
0c593b34 377 * struct {
0127c3ea 378 * struct perf_event_header header;
0c593b34 379 *
43a21ea8
PZ
380 * { u64 ip; } && PERF_SAMPLE_IP
381 * { u32 pid, tid; } && PERF_SAMPLE_TID
382 * { u64 time; } && PERF_SAMPLE_TIME
383 * { u64 addr; } && PERF_SAMPLE_ADDR
e6e18ec7 384 * { u64 id; } && PERF_SAMPLE_ID
7f453c24 385 * { u64 stream_id;} && PERF_SAMPLE_STREAM_ID
43a21ea8 386 * { u32 cpu, res; } && PERF_SAMPLE_CPU
57c0c15b 387 * { u64 period; } && PERF_SAMPLE_PERIOD
0c593b34 388 *
3dab77fb 389 * { struct read_format values; } && PERF_SAMPLE_READ
0c593b34 390 *
f9188e02 391 * { u64 nr,
43a21ea8 392 * u64 ips[nr]; } && PERF_SAMPLE_CALLCHAIN
3dab77fb 393 *
57c0c15b
IM
394 * #
395 * # The RAW record below is opaque data wrt the ABI
396 * #
397 * # That is, the ABI doesn't make any promises wrt to
398 * # the stability of its content, it may vary depending
399 * # on event, hardware, kernel version and phase of
400 * # the moon.
401 * #
402 * # In other words, PERF_SAMPLE_RAW contents are not an ABI.
403 * #
3dab77fb 404 *
a044560c
PZ
405 * { u32 size;
406 * char data[size];}&& PERF_SAMPLE_RAW
0c593b34 407 * };
8a057d84 408 */
cdd6c482 409 PERF_RECORD_SAMPLE = 9,
e6e18ec7 410
cdd6c482 411 PERF_RECORD_MAX, /* non-ABI */
5c148194
PZ
412};
413
f9188e02
PZ
414enum perf_callchain_context {
415 PERF_CONTEXT_HV = (__u64)-32,
416 PERF_CONTEXT_KERNEL = (__u64)-128,
417 PERF_CONTEXT_USER = (__u64)-512,
7522060c 418
f9188e02
PZ
419 PERF_CONTEXT_GUEST = (__u64)-2048,
420 PERF_CONTEXT_GUEST_KERNEL = (__u64)-2176,
421 PERF_CONTEXT_GUEST_USER = (__u64)-2560,
422
423 PERF_CONTEXT_MAX = (__u64)-4095,
7522060c
IM
424};
425
a4be7c27
PZ
426#define PERF_FLAG_FD_NO_GROUP (1U << 0)
427#define PERF_FLAG_FD_OUTPUT (1U << 1)
428
f3dfd265 429#ifdef __KERNEL__
9f66a381 430/*
f3dfd265 431 * Kernel-internal data types and definitions:
9f66a381
IM
432 */
433
cdd6c482
IM
434#ifdef CONFIG_PERF_EVENTS
435# include <asm/perf_event.h>
f3dfd265
PM
436#endif
437
438#include <linux/list.h>
439#include <linux/mutex.h>
440#include <linux/rculist.h>
441#include <linux/rcupdate.h>
442#include <linux/spinlock.h>
d6d020e9 443#include <linux/hrtimer.h>
3c446b3d 444#include <linux/fs.h>
709e50cf 445#include <linux/pid_namespace.h>
906010b2 446#include <linux/workqueue.h>
f3dfd265
PM
447#include <asm/atomic.h>
448
f9188e02
PZ
449#define PERF_MAX_STACK_DEPTH 255
450
451struct perf_callchain_entry {
452 __u64 nr;
453 __u64 ip[PERF_MAX_STACK_DEPTH];
454};
455
3a43ce68
FW
456struct perf_raw_record {
457 u32 size;
458 void *data;
f413cdb8
FW
459};
460
f3dfd265
PM
461struct task_struct;
462
0793a61d 463/**
cdd6c482 464 * struct hw_perf_event - performance event hardware details:
0793a61d 465 */
cdd6c482
IM
466struct hw_perf_event {
467#ifdef CONFIG_PERF_EVENTS
d6d020e9
PZ
468 union {
469 struct { /* hardware */
a308444c
IM
470 u64 config;
471 unsigned long config_base;
cdd6c482 472 unsigned long event_base;
a308444c 473 int idx;
d6d020e9
PZ
474 };
475 union { /* software */
a308444c
IM
476 atomic64_t count;
477 struct hrtimer hrtimer;
d6d020e9
PZ
478 };
479 };
ee06094f 480 atomic64_t prev_count;
b23f3325 481 u64 sample_period;
9e350de3 482 u64 last_period;
ee06094f 483 atomic64_t period_left;
60db5e09 484 u64 interrupts;
6a24ed6c
PZ
485
486 u64 freq_count;
487 u64 freq_interrupts;
bd2b5b12 488 u64 freq_stamp;
ee06094f 489#endif
0793a61d
TG
490};
491
cdd6c482 492struct perf_event;
621a01ea
IM
493
494/**
4aeb0b42 495 * struct pmu - generic performance monitoring unit
621a01ea 496 */
4aeb0b42 497struct pmu {
cdd6c482
IM
498 int (*enable) (struct perf_event *event);
499 void (*disable) (struct perf_event *event);
500 void (*read) (struct perf_event *event);
501 void (*unthrottle) (struct perf_event *event);
621a01ea
IM
502};
503
6a930700 504/**
cdd6c482 505 * enum perf_event_active_state - the states of a event
6a930700 506 */
cdd6c482 507enum perf_event_active_state {
57c0c15b 508 PERF_EVENT_STATE_ERROR = -2,
cdd6c482
IM
509 PERF_EVENT_STATE_OFF = -1,
510 PERF_EVENT_STATE_INACTIVE = 0,
57c0c15b 511 PERF_EVENT_STATE_ACTIVE = 1,
6a930700
IM
512};
513
9b51f66d
IM
514struct file;
515
7b732a75
PZ
516struct perf_mmap_data {
517 struct rcu_head rcu_head;
906010b2
PZ
518#ifdef CONFIG_PERF_USE_VMALLOC
519 struct work_struct work;
520#endif
521 int data_order;
8740f941 522 int nr_pages; /* nr of data pages */
43a21ea8 523 int writable; /* are we writable */
c5078f78 524 int nr_locked; /* nr pages mlocked */
8740f941 525
c33a0bc4 526 atomic_t poll; /* POLL_ for wakeups */
cdd6c482 527 atomic_t events; /* event_id limit */
8740f941 528
8e3747c1
PZ
529 atomic_long_t head; /* write position */
530 atomic_long_t done_head; /* completed head */
531
c33a0bc4 532 atomic_t lock; /* concurrent writes */
c66de4a5 533 atomic_t wakeup; /* needs a wakeup */
43a21ea8 534 atomic_t lost; /* nr records lost */
c66de4a5 535
2667de81
PZ
536 long watermark; /* wakeup watermark */
537
57c0c15b 538 struct perf_event_mmap_page *user_page;
0127c3ea 539 void *data_pages[0];
7b732a75
PZ
540};
541
671dec5d
PZ
542struct perf_pending_entry {
543 struct perf_pending_entry *next;
544 void (*func)(struct perf_pending_entry *);
925d519a
PZ
545};
546
97eaf530
FW
547typedef void (*perf_callback_t)(struct perf_event *, void *);
548
0793a61d 549/**
cdd6c482 550 * struct perf_event - performance event kernel representation:
0793a61d 551 */
cdd6c482
IM
552struct perf_event {
553#ifdef CONFIG_PERF_EVENTS
65abc865 554 struct list_head group_entry;
592903cd 555 struct list_head event_entry;
04289bb9 556 struct list_head sibling_list;
0127c3ea 557 int nr_siblings;
cdd6c482
IM
558 struct perf_event *group_leader;
559 struct perf_event *output;
4aeb0b42 560 const struct pmu *pmu;
04289bb9 561
cdd6c482 562 enum perf_event_active_state state;
0793a61d 563 atomic64_t count;
ee06094f 564
53cfbf59 565 /*
cdd6c482 566 * These are the total time in nanoseconds that the event
53cfbf59 567 * has been enabled (i.e. eligible to run, and the task has
cdd6c482 568 * been scheduled in, if this is a per-task event)
53cfbf59
PM
569 * and running (scheduled onto the CPU), respectively.
570 *
571 * They are computed from tstamp_enabled, tstamp_running and
cdd6c482 572 * tstamp_stopped when the event is in INACTIVE or ACTIVE state.
53cfbf59
PM
573 */
574 u64 total_time_enabled;
575 u64 total_time_running;
576
577 /*
578 * These are timestamps used for computing total_time_enabled
cdd6c482 579 * and total_time_running when the event is in INACTIVE or
53cfbf59
PM
580 * ACTIVE state, measured in nanoseconds from an arbitrary point
581 * in time.
cdd6c482
IM
582 * tstamp_enabled: the notional time when the event was enabled
583 * tstamp_running: the notional time when the event was scheduled on
53cfbf59 584 * tstamp_stopped: in INACTIVE state, the notional time when the
cdd6c482 585 * event was scheduled off.
53cfbf59
PM
586 */
587 u64 tstamp_enabled;
588 u64 tstamp_running;
589 u64 tstamp_stopped;
590
cdd6c482
IM
591 struct perf_event_attr attr;
592 struct hw_perf_event hw;
0793a61d 593
cdd6c482 594 struct perf_event_context *ctx;
9b51f66d 595 struct file *filp;
0793a61d 596
53cfbf59
PM
597 /*
598 * These accumulate total time (in nanoseconds) that children
cdd6c482 599 * events have been enabled and running, respectively.
53cfbf59
PM
600 */
601 atomic64_t child_total_time_enabled;
602 atomic64_t child_total_time_running;
603
0793a61d 604 /*
d859e29f 605 * Protect attach/detach and child_list:
0793a61d 606 */
fccc714b
PZ
607 struct mutex child_mutex;
608 struct list_head child_list;
cdd6c482 609 struct perf_event *parent;
0793a61d
TG
610
611 int oncpu;
612 int cpu;
613
082ff5a2
PZ
614 struct list_head owner_entry;
615 struct task_struct *owner;
616
7b732a75
PZ
617 /* mmap bits */
618 struct mutex mmap_mutex;
619 atomic_t mmap_count;
620 struct perf_mmap_data *data;
37d81828 621
7b732a75 622 /* poll related */
0793a61d 623 wait_queue_head_t waitq;
3c446b3d 624 struct fasync_struct *fasync;
79f14641
PZ
625
626 /* delayed work for NMIs and such */
627 int pending_wakeup;
4c9e2542 628 int pending_kill;
79f14641 629 int pending_disable;
671dec5d 630 struct perf_pending_entry pending;
592903cd 631
79f14641
PZ
632 atomic_t event_limit;
633
cdd6c482 634 void (*destroy)(struct perf_event *);
592903cd 635 struct rcu_head rcu_head;
709e50cf
PZ
636
637 struct pid_namespace *ns;
8e5799b1 638 u64 id;
6fb2915d
LZ
639
640#ifdef CONFIG_EVENT_PROFILE
641 struct event_filter *filter;
ee06094f 642#endif
6fb2915d 643
97eaf530
FW
644 perf_callback_t callback;
645
6fb2915d 646#endif /* CONFIG_PERF_EVENTS */
0793a61d
TG
647};
648
649/**
cdd6c482 650 * struct perf_event_context - event context structure
0793a61d 651 *
cdd6c482 652 * Used as a container for task events and CPU events as well:
0793a61d 653 */
cdd6c482 654struct perf_event_context {
0793a61d 655 /*
cdd6c482 656 * Protect the states of the events in the list,
d859e29f 657 * nr_active, and the list:
0793a61d 658 */
a308444c 659 spinlock_t lock;
d859e29f 660 /*
cdd6c482 661 * Protect the list of events. Locking either mutex or lock
d859e29f
PM
662 * is sufficient to ensure the list doesn't change; to change
663 * the list you need to lock both the mutex and the spinlock.
664 */
a308444c 665 struct mutex mutex;
04289bb9 666
65abc865 667 struct list_head group_list;
a308444c 668 struct list_head event_list;
cdd6c482 669 int nr_events;
a308444c
IM
670 int nr_active;
671 int is_active;
bfbd3381 672 int nr_stat;
a308444c
IM
673 atomic_t refcount;
674 struct task_struct *task;
53cfbf59
PM
675
676 /*
4af4998b 677 * Context clock, runs when context enabled.
53cfbf59 678 */
a308444c
IM
679 u64 time;
680 u64 timestamp;
564c2b21
PM
681
682 /*
683 * These fields let us detect when two contexts have both
684 * been cloned (inherited) from a common ancestor.
685 */
cdd6c482 686 struct perf_event_context *parent_ctx;
a308444c
IM
687 u64 parent_gen;
688 u64 generation;
689 int pin_count;
690 struct rcu_head rcu_head;
0793a61d
TG
691};
692
693/**
cdd6c482 694 * struct perf_event_cpu_context - per cpu event context structure
0793a61d
TG
695 */
696struct perf_cpu_context {
cdd6c482
IM
697 struct perf_event_context ctx;
698 struct perf_event_context *task_ctx;
0793a61d
TG
699 int active_oncpu;
700 int max_pertask;
3b6f9e5c 701 int exclusive;
96f6d444
PZ
702
703 /*
704 * Recursion avoidance:
705 *
706 * task, softirq, irq, nmi context
707 */
22a4f650 708 int recursion[4];
0793a61d
TG
709};
710
5622f295 711struct perf_output_handle {
57c0c15b
IM
712 struct perf_event *event;
713 struct perf_mmap_data *data;
714 unsigned long head;
715 unsigned long offset;
716 int nmi;
717 int sample;
718 int locked;
719 unsigned long flags;
5622f295
MM
720};
721
cdd6c482 722#ifdef CONFIG_PERF_EVENTS
829b42dd 723
0793a61d
TG
724/*
725 * Set by architecture code:
726 */
cdd6c482 727extern int perf_max_events;
0793a61d 728
cdd6c482 729extern const struct pmu *hw_perf_event_init(struct perf_event *event);
621a01ea 730
cdd6c482
IM
731extern void perf_event_task_sched_in(struct task_struct *task, int cpu);
732extern void perf_event_task_sched_out(struct task_struct *task,
564c2b21 733 struct task_struct *next, int cpu);
cdd6c482
IM
734extern void perf_event_task_tick(struct task_struct *task, int cpu);
735extern int perf_event_init_task(struct task_struct *child);
736extern void perf_event_exit_task(struct task_struct *child);
737extern void perf_event_free_task(struct task_struct *task);
738extern void set_perf_event_pending(void);
739extern void perf_event_do_pending(void);
740extern void perf_event_print_debug(void);
9e35ad38
PZ
741extern void __perf_disable(void);
742extern bool __perf_enable(void);
743extern void perf_disable(void);
744extern void perf_enable(void);
cdd6c482
IM
745extern int perf_event_task_disable(void);
746extern int perf_event_task_enable(void);
747extern int hw_perf_group_sched_in(struct perf_event *group_leader,
3cbed429 748 struct perf_cpu_context *cpuctx,
cdd6c482
IM
749 struct perf_event_context *ctx, int cpu);
750extern void perf_event_update_userpage(struct perf_event *event);
fb0459d7
AV
751extern int perf_event_release_kernel(struct perf_event *event);
752extern struct perf_event *
753perf_event_create_kernel_counter(struct perf_event_attr *attr,
754 int cpu,
97eaf530
FW
755 pid_t pid,
756 perf_callback_t callback);
fb0459d7 757extern u64 perf_event_read_value(struct perf_event *event);
5c92d124 758
df1a132b 759struct perf_sample_data {
5622f295
MM
760 u64 type;
761
762 u64 ip;
763 struct {
764 u32 pid;
765 u32 tid;
766 } tid_entry;
767 u64 time;
a308444c 768 u64 addr;
5622f295
MM
769 u64 id;
770 u64 stream_id;
771 struct {
772 u32 cpu;
773 u32 reserved;
774 } cpu_entry;
a308444c 775 u64 period;
5622f295 776 struct perf_callchain_entry *callchain;
3a43ce68 777 struct perf_raw_record *raw;
df1a132b
PZ
778};
779
5622f295
MM
780extern void perf_output_sample(struct perf_output_handle *handle,
781 struct perf_event_header *header,
782 struct perf_sample_data *data,
cdd6c482 783 struct perf_event *event);
5622f295
MM
784extern void perf_prepare_sample(struct perf_event_header *header,
785 struct perf_sample_data *data,
cdd6c482 786 struct perf_event *event,
5622f295
MM
787 struct pt_regs *regs);
788
cdd6c482 789extern int perf_event_overflow(struct perf_event *event, int nmi,
5622f295
MM
790 struct perf_sample_data *data,
791 struct pt_regs *regs);
df1a132b 792
3b6f9e5c 793/*
cdd6c482 794 * Return 1 for a software event, 0 for a hardware event
3b6f9e5c 795 */
cdd6c482 796static inline int is_software_event(struct perf_event *event)
3b6f9e5c 797{
cdd6c482
IM
798 return (event->attr.type != PERF_TYPE_RAW) &&
799 (event->attr.type != PERF_TYPE_HARDWARE) &&
800 (event->attr.type != PERF_TYPE_HW_CACHE);
3b6f9e5c
PM
801}
802
cdd6c482 803extern atomic_t perf_swevent_enabled[PERF_COUNT_SW_MAX];
f29ac756 804
cdd6c482 805extern void __perf_sw_event(u32, u64, int, struct pt_regs *, u64);
f29ac756
PZ
806
807static inline void
cdd6c482 808perf_sw_event(u32 event_id, u64 nr, int nmi, struct pt_regs *regs, u64 addr)
f29ac756 809{
cdd6c482
IM
810 if (atomic_read(&perf_swevent_enabled[event_id]))
811 __perf_sw_event(event_id, nr, nmi, regs, addr);
f29ac756 812}
15dbf27c 813
cdd6c482 814extern void __perf_event_mmap(struct vm_area_struct *vma);
089dd79d 815
cdd6c482 816static inline void perf_event_mmap(struct vm_area_struct *vma)
089dd79d
PZ
817{
818 if (vma->vm_flags & VM_EXEC)
cdd6c482 819 __perf_event_mmap(vma);
089dd79d 820}
0a4a9391 821
cdd6c482
IM
822extern void perf_event_comm(struct task_struct *tsk);
823extern void perf_event_fork(struct task_struct *tsk);
8d1b2d93 824
394ee076
PZ
825extern struct perf_callchain_entry *perf_callchain(struct pt_regs *regs);
826
cdd6c482
IM
827extern int sysctl_perf_event_paranoid;
828extern int sysctl_perf_event_mlock;
829extern int sysctl_perf_event_sample_rate;
1ccd1549 830
cdd6c482
IM
831extern void perf_event_init(void);
832extern void perf_tp_event(int event_id, u64 addr, u64 count,
f4b5ffcc 833 void *record, int entry_size);
0d905bca 834
9d23a90a 835#ifndef perf_misc_flags
cdd6c482
IM
836#define perf_misc_flags(regs) (user_mode(regs) ? PERF_RECORD_MISC_USER : \
837 PERF_RECORD_MISC_KERNEL)
9d23a90a
PM
838#define perf_instruction_pointer(regs) instruction_pointer(regs)
839#endif
840
5622f295 841extern int perf_output_begin(struct perf_output_handle *handle,
cdd6c482 842 struct perf_event *event, unsigned int size,
5622f295
MM
843 int nmi, int sample);
844extern void perf_output_end(struct perf_output_handle *handle);
845extern void perf_output_copy(struct perf_output_handle *handle,
846 const void *buf, unsigned int len);
0793a61d
TG
847#else
848static inline void
cdd6c482 849perf_event_task_sched_in(struct task_struct *task, int cpu) { }
0793a61d 850static inline void
cdd6c482 851perf_event_task_sched_out(struct task_struct *task,
910431c7 852 struct task_struct *next, int cpu) { }
0793a61d 853static inline void
57c0c15b 854perf_event_task_tick(struct task_struct *task, int cpu) { }
cdd6c482
IM
855static inline int perf_event_init_task(struct task_struct *child) { return 0; }
856static inline void perf_event_exit_task(struct task_struct *child) { }
857static inline void perf_event_free_task(struct task_struct *task) { }
57c0c15b
IM
858static inline void perf_event_do_pending(void) { }
859static inline void perf_event_print_debug(void) { }
9e35ad38
PZ
860static inline void perf_disable(void) { }
861static inline void perf_enable(void) { }
57c0c15b
IM
862static inline int perf_event_task_disable(void) { return -EINVAL; }
863static inline int perf_event_task_enable(void) { return -EINVAL; }
15dbf27c 864
925d519a 865static inline void
cdd6c482 866perf_sw_event(u32 event_id, u64 nr, int nmi,
78f13e95 867 struct pt_regs *regs, u64 addr) { }
0a4a9391 868
57c0c15b 869static inline void perf_event_mmap(struct vm_area_struct *vma) { }
cdd6c482
IM
870static inline void perf_event_comm(struct task_struct *tsk) { }
871static inline void perf_event_fork(struct task_struct *tsk) { }
872static inline void perf_event_init(void) { }
5622f295 873
0793a61d
TG
874#endif
875
5622f295
MM
876#define perf_output_put(handle, x) \
877 perf_output_copy((handle), &(x), sizeof(x))
878
f3dfd265 879#endif /* __KERNEL__ */
cdd6c482 880#endif /* _LINUX_PERF_EVENT_H */