aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/perf_counter.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/perf_counter.h')
-rw-r--r--include/linux/perf_counter.h183
1 files changed, 138 insertions, 45 deletions
diff --git a/include/linux/perf_counter.h b/include/linux/perf_counter.h
index 1b3118a1023a..9ba1822272c7 100644
--- a/include/linux/perf_counter.h
+++ b/include/linux/perf_counter.h
@@ -115,26 +115,44 @@ enum perf_counter_sample_format {
115 PERF_SAMPLE_TID = 1U << 1, 115 PERF_SAMPLE_TID = 1U << 1,
116 PERF_SAMPLE_TIME = 1U << 2, 116 PERF_SAMPLE_TIME = 1U << 2,
117 PERF_SAMPLE_ADDR = 1U << 3, 117 PERF_SAMPLE_ADDR = 1U << 3,
118 PERF_SAMPLE_GROUP = 1U << 4, 118 PERF_SAMPLE_READ = 1U << 4,
119 PERF_SAMPLE_CALLCHAIN = 1U << 5, 119 PERF_SAMPLE_CALLCHAIN = 1U << 5,
120 PERF_SAMPLE_ID = 1U << 6, 120 PERF_SAMPLE_ID = 1U << 6,
121 PERF_SAMPLE_CPU = 1U << 7, 121 PERF_SAMPLE_CPU = 1U << 7,
122 PERF_SAMPLE_PERIOD = 1U << 8, 122 PERF_SAMPLE_PERIOD = 1U << 8,
123 PERF_SAMPLE_STREAM_ID = 1U << 9,
124 PERF_SAMPLE_RAW = 1U << 10,
123 125
124 PERF_SAMPLE_MAX = 1U << 9, /* non-ABI */ 126 PERF_SAMPLE_MAX = 1U << 11, /* non-ABI */
125}; 127};
126 128
127/* 129/*
128 * Bits that can be set in attr.read_format to request that 130 * The format of the data returned by read() on a perf counter fd,
129 * reads on the counter should return the indicated quantities, 131 * as specified by attr.read_format:
130 * in increasing order of bit value, after the counter value. 132 *
133 * struct read_format {
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
139 *
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
147 * };
131 */ 148 */
132enum perf_counter_read_format { 149enum perf_counter_read_format {
133 PERF_FORMAT_TOTAL_TIME_ENABLED = 1U << 0, 150 PERF_FORMAT_TOTAL_TIME_ENABLED = 1U << 0,
134 PERF_FORMAT_TOTAL_TIME_RUNNING = 1U << 1, 151 PERF_FORMAT_TOTAL_TIME_RUNNING = 1U << 1,
135 PERF_FORMAT_ID = 1U << 2, 152 PERF_FORMAT_ID = 1U << 2,
153 PERF_FORMAT_GROUP = 1U << 3,
136 154
137 PERF_FORMAT_MAX = 1U << 3, /* non-ABI */ 155 PERF_FORMAT_MAX = 1U << 4, /* non-ABI */
138}; 156};
139 157
140#define PERF_ATTR_SIZE_VER0 64 /* sizeof first published struct */ 158#define PERF_ATTR_SIZE_VER0 64 /* sizeof first published struct */
@@ -178,8 +196,11 @@ struct perf_counter_attr {
178 mmap : 1, /* include mmap data */ 196 mmap : 1, /* include mmap data */
179 comm : 1, /* include comm data */ 197 comm : 1, /* include comm data */
180 freq : 1, /* use freq, not period */ 198 freq : 1, /* use freq, not period */
199 inherit_stat : 1, /* per task counts */
200 enable_on_exec : 1, /* next exec enables */
201 task : 1, /* trace fork/exit */
181 202
182 __reserved_1 : 53; 203 __reserved_1 : 50;
183 204
184 __u32 wakeup_events; /* wakeup every n events */ 205 __u32 wakeup_events; /* wakeup every n events */
185 __u32 __reserved_2; 206 __u32 __reserved_2;
@@ -232,14 +253,28 @@ struct perf_counter_mmap_page {
232 __u32 lock; /* seqlock for synchronization */ 253 __u32 lock; /* seqlock for synchronization */
233 __u32 index; /* hardware counter identifier */ 254 __u32 index; /* hardware counter identifier */
234 __s64 offset; /* add to hardware counter value */ 255 __s64 offset; /* add to hardware counter value */
256 __u64 time_enabled; /* time counter active */
257 __u64 time_running; /* time counter on cpu */
258
259 /*
260 * Hole for extension of the self monitor capabilities
261 */
262
263 __u64 __reserved[123]; /* align to 1k */
235 264
236 /* 265 /*
237 * Control data for the mmap() data buffer. 266 * Control data for the mmap() data buffer.
238 * 267 *
239 * User-space reading this value should issue an rmb(), on SMP capable 268 * User-space reading the @data_head value should issue an rmb(), on
240 * platforms, after reading this value -- see perf_counter_wakeup(). 269 * SMP capable platforms, after reading this value -- see
270 * perf_counter_wakeup().
271 *
272 * When the mapping is PROT_WRITE the @data_tail value should be
273 * written by userspace to reflect the last read data. In this case
274 * the kernel will not over-write unread data.
241 */ 275 */
242 __u64 data_head; /* head in the data section */ 276 __u64 data_head; /* head in the data section */
277 __u64 data_tail; /* user-space written tail */
243}; 278};
244 279
245#define PERF_EVENT_MISC_CPUMODE_MASK (3 << 0) 280#define PERF_EVENT_MISC_CPUMODE_MASK (3 << 0)
@@ -247,7 +282,6 @@ struct perf_counter_mmap_page {
247#define PERF_EVENT_MISC_KERNEL (1 << 0) 282#define PERF_EVENT_MISC_KERNEL (1 << 0)
248#define PERF_EVENT_MISC_USER (2 << 0) 283#define PERF_EVENT_MISC_USER (2 << 0)
249#define PERF_EVENT_MISC_HYPERVISOR (3 << 0) 284#define PERF_EVENT_MISC_HYPERVISOR (3 << 0)
250#define PERF_EVENT_MISC_OVERFLOW (1 << 2)
251 285
252struct perf_event_header { 286struct perf_event_header {
253 __u32 type; 287 __u32 type;
@@ -275,6 +309,15 @@ enum perf_event_type {
275 309
276 /* 310 /*
277 * struct { 311 * struct {
312 * struct perf_event_header header;
313 * u64 id;
314 * u64 lost;
315 * };
316 */
317 PERF_EVENT_LOST = 2,
318
319 /*
320 * struct {
278 * struct perf_event_header header; 321 * struct perf_event_header header;
279 * 322 *
280 * u32 pid, tid; 323 * u32 pid, tid;
@@ -286,18 +329,18 @@ enum perf_event_type {
286 /* 329 /*
287 * struct { 330 * struct {
288 * struct perf_event_header header; 331 * struct perf_event_header header;
289 * u64 time; 332 * u32 pid, ppid;
290 * u64 id; 333 * u32 tid, ptid;
291 * u64 sample_period;
292 * }; 334 * };
293 */ 335 */
294 PERF_EVENT_PERIOD = 4, 336 PERF_EVENT_EXIT = 4,
295 337
296 /* 338 /*
297 * struct { 339 * struct {
298 * struct perf_event_header header; 340 * struct perf_event_header header;
299 * u64 time; 341 * u64 time;
300 * u64 id; 342 * u64 id;
343 * u64 stream_id;
301 * }; 344 * };
302 */ 345 */
303 PERF_EVENT_THROTTLE = 5, 346 PERF_EVENT_THROTTLE = 5,
@@ -307,34 +350,69 @@ enum perf_event_type {
307 * struct { 350 * struct {
308 * struct perf_event_header header; 351 * struct perf_event_header header;
309 * u32 pid, ppid; 352 * u32 pid, ppid;
353 * u32 tid, ptid;
310 * }; 354 * };
311 */ 355 */
312 PERF_EVENT_FORK = 7, 356 PERF_EVENT_FORK = 7,
313 357
314 /* 358 /*
315 * When header.misc & PERF_EVENT_MISC_OVERFLOW the event_type field 359 * struct {
316 * will be PERF_RECORD_* 360 * struct perf_event_header header;
361 * u32 pid, tid;
317 * 362 *
363 * struct read_format values;
364 * };
365 */
366 PERF_EVENT_READ = 8,
367
368 /*
318 * struct { 369 * struct {
319 * struct perf_event_header header; 370 * struct perf_event_header header;
320 * 371 *
321 * { u64 ip; } && PERF_RECORD_IP 372 * { u64 ip; } && PERF_SAMPLE_IP
322 * { u32 pid, tid; } && PERF_RECORD_TID 373 * { u32 pid, tid; } && PERF_SAMPLE_TID
323 * { u64 time; } && PERF_RECORD_TIME 374 * { u64 time; } && PERF_SAMPLE_TIME
324 * { u64 addr; } && PERF_RECORD_ADDR 375 * { u64 addr; } && PERF_SAMPLE_ADDR
325 * { u64 config; } && PERF_RECORD_CONFIG 376 * { u64 id; } && PERF_SAMPLE_ID
326 * { u32 cpu, res; } && PERF_RECORD_CPU 377 * { u64 stream_id;} && PERF_SAMPLE_STREAM_ID
378 * { u32 cpu, res; } && PERF_SAMPLE_CPU
379 * { u64 period; } && PERF_SAMPLE_PERIOD
380 *
381 * { struct read_format values; } && PERF_SAMPLE_READ
327 * 382 *
328 * { u64 nr; 383 * { u64 nr,
329 * { u64 id, val; } cnt[nr]; } && PERF_RECORD_GROUP 384 * u64 ips[nr]; } && PERF_SAMPLE_CALLCHAIN
330 * 385 *
331 * { u16 nr, 386 * #
332 * hv, 387 * # The RAW record below is opaque data wrt the ABI
333 * kernel, 388 * #
334 * user; 389 * # That is, the ABI doesn't make any promises wrt to
335 * u64 ips[nr]; } && PERF_RECORD_CALLCHAIN 390 * # the stability of its content, it may vary depending
391 * # on event, hardware, kernel version and phase of
392 * # the moon.
393 * #
394 * # In other words, PERF_SAMPLE_RAW contents are not an ABI.
395 * #
396 *
397 * { u32 size;
398 * char data[size];}&& PERF_SAMPLE_RAW
336 * }; 399 * };
337 */ 400 */
401 PERF_EVENT_SAMPLE = 9,
402
403 PERF_EVENT_MAX, /* non-ABI */
404};
405
406enum perf_callchain_context {
407 PERF_CONTEXT_HV = (__u64)-32,
408 PERF_CONTEXT_KERNEL = (__u64)-128,
409 PERF_CONTEXT_USER = (__u64)-512,
410
411 PERF_CONTEXT_GUEST = (__u64)-2048,
412 PERF_CONTEXT_GUEST_KERNEL = (__u64)-2176,
413 PERF_CONTEXT_GUEST_USER = (__u64)-2560,
414
415 PERF_CONTEXT_MAX = (__u64)-4095,
338}; 416};
339 417
340#ifdef __KERNEL__ 418#ifdef __KERNEL__
@@ -356,6 +434,18 @@ enum perf_event_type {
356#include <linux/pid_namespace.h> 434#include <linux/pid_namespace.h>
357#include <asm/atomic.h> 435#include <asm/atomic.h>
358 436
437#define PERF_MAX_STACK_DEPTH 255
438
439struct perf_callchain_entry {
440 __u64 nr;
441 __u64 ip[PERF_MAX_STACK_DEPTH];
442};
443
444struct perf_raw_record {
445 u32 size;
446 void *data;
447};
448
359struct task_struct; 449struct task_struct;
360 450
361/** 451/**
@@ -414,6 +504,7 @@ struct file;
414struct perf_mmap_data { 504struct perf_mmap_data {
415 struct rcu_head rcu_head; 505 struct rcu_head rcu_head;
416 int nr_pages; /* nr of data pages */ 506 int nr_pages; /* nr of data pages */
507 int writable; /* are we writable */
417 int nr_locked; /* nr pages mlocked */ 508 int nr_locked; /* nr pages mlocked */
418 509
419 atomic_t poll; /* POLL_ for wakeups */ 510 atomic_t poll; /* POLL_ for wakeups */
@@ -423,8 +514,8 @@ struct perf_mmap_data {
423 atomic_long_t done_head; /* completed head */ 514 atomic_long_t done_head; /* completed head */
424 515
425 atomic_t lock; /* concurrent writes */ 516 atomic_t lock; /* concurrent writes */
426
427 atomic_t wakeup; /* needs a wakeup */ 517 atomic_t wakeup; /* needs a wakeup */
518 atomic_t lost; /* nr records lost */
428 519
429 struct perf_counter_mmap_page *user_page; 520 struct perf_counter_mmap_page *user_page;
430 void *data_pages[0]; 521 void *data_pages[0];
@@ -550,6 +641,7 @@ struct perf_counter_context {
550 int nr_counters; 641 int nr_counters;
551 int nr_active; 642 int nr_active;
552 int is_active; 643 int is_active;
644 int nr_stat;
553 atomic_t refcount; 645 atomic_t refcount;
554 struct task_struct *task; 646 struct task_struct *task;
555 647
@@ -604,6 +696,7 @@ extern void perf_counter_task_tick(struct task_struct *task, int cpu);
604extern int perf_counter_init_task(struct task_struct *child); 696extern int perf_counter_init_task(struct task_struct *child);
605extern void perf_counter_exit_task(struct task_struct *child); 697extern void perf_counter_exit_task(struct task_struct *child);
606extern void perf_counter_free_task(struct task_struct *task); 698extern void perf_counter_free_task(struct task_struct *task);
699extern void set_perf_counter_pending(void);
607extern void perf_counter_do_pending(void); 700extern void perf_counter_do_pending(void);
608extern void perf_counter_print_debug(void); 701extern void perf_counter_print_debug(void);
609extern void __perf_disable(void); 702extern void __perf_disable(void);
@@ -621,10 +714,13 @@ struct perf_sample_data {
621 struct pt_regs *regs; 714 struct pt_regs *regs;
622 u64 addr; 715 u64 addr;
623 u64 period; 716 u64 period;
717 struct perf_raw_record *raw;
624}; 718};
625 719
626extern int perf_counter_overflow(struct perf_counter *counter, int nmi, 720extern int perf_counter_overflow(struct perf_counter *counter, int nmi,
627 struct perf_sample_data *data); 721 struct perf_sample_data *data);
722extern void perf_counter_output(struct perf_counter *counter, int nmi,
723 struct perf_sample_data *data);
628 724
629/* 725/*
630 * Return 1 for a software counter, 0 for a hardware counter 726 * Return 1 for a software counter, 0 for a hardware counter
@@ -636,7 +732,16 @@ static inline int is_software_counter(struct perf_counter *counter)
636 (counter->attr.type != PERF_TYPE_HW_CACHE); 732 (counter->attr.type != PERF_TYPE_HW_CACHE);
637} 733}
638 734
639extern void perf_swcounter_event(u32, u64, int, struct pt_regs *, u64); 735extern atomic_t perf_swcounter_enabled[PERF_COUNT_SW_MAX];
736
737extern void __perf_swcounter_event(u32, u64, int, struct pt_regs *, u64);
738
739static inline void
740perf_swcounter_event(u32 event, u64 nr, int nmi, struct pt_regs *regs, u64 addr)
741{
742 if (atomic_read(&perf_swcounter_enabled[event]))
743 __perf_swcounter_event(event, nr, nmi, regs, addr);
744}
640 745
641extern void __perf_counter_mmap(struct vm_area_struct *vma); 746extern void __perf_counter_mmap(struct vm_area_struct *vma);
642 747
@@ -649,18 +754,6 @@ static inline void perf_counter_mmap(struct vm_area_struct *vma)
649extern void perf_counter_comm(struct task_struct *tsk); 754extern void perf_counter_comm(struct task_struct *tsk);
650extern void perf_counter_fork(struct task_struct *tsk); 755extern void perf_counter_fork(struct task_struct *tsk);
651 756
652extern void perf_counter_task_migration(struct task_struct *task, int cpu);
653
654#define MAX_STACK_DEPTH 255
655
656struct perf_callchain_entry {
657 u16 nr;
658 u16 hv;
659 u16 kernel;
660 u16 user;
661 u64 ip[MAX_STACK_DEPTH];
662};
663
664extern struct perf_callchain_entry *perf_callchain(struct pt_regs *regs); 757extern struct perf_callchain_entry *perf_callchain(struct pt_regs *regs);
665 758
666extern int sysctl_perf_counter_paranoid; 759extern int sysctl_perf_counter_paranoid;
@@ -668,6 +761,8 @@ extern int sysctl_perf_counter_mlock;
668extern int sysctl_perf_counter_sample_rate; 761extern int sysctl_perf_counter_sample_rate;
669 762
670extern void perf_counter_init(void); 763extern void perf_counter_init(void);
764extern void perf_tpcounter_event(int event_id, u64 addr, u64 count,
765 void *record, int entry_size);
671 766
672#ifndef perf_misc_flags 767#ifndef perf_misc_flags
673#define perf_misc_flags(regs) (user_mode(regs) ? PERF_EVENT_MISC_USER : \ 768#define perf_misc_flags(regs) (user_mode(regs) ? PERF_EVENT_MISC_USER : \
@@ -701,8 +796,6 @@ static inline void perf_counter_mmap(struct vm_area_struct *vma) { }
701static inline void perf_counter_comm(struct task_struct *tsk) { } 796static inline void perf_counter_comm(struct task_struct *tsk) { }
702static inline void perf_counter_fork(struct task_struct *tsk) { } 797static inline void perf_counter_fork(struct task_struct *tsk) { }
703static inline void perf_counter_init(void) { } 798static inline void perf_counter_init(void) { }
704static inline void perf_counter_task_migration(struct task_struct *task,
705 int cpu) { }
706#endif 799#endif
707 800
708#endif /* __KERNEL__ */ 801#endif /* __KERNEL__ */