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.h497
1 files changed, 40 insertions, 457 deletions
diff --git a/include/linux/perf_counter.h b/include/linux/perf_counter.h
index 740caad09a44..368bd70f1d2d 100644
--- a/include/linux/perf_counter.h
+++ b/include/linux/perf_counter.h
@@ -1,5 +1,9 @@
1/* 1/*
2 * Performance counters: 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.
5 *
6 * Performance events:
3 * 7 *
4 * Copyright (C) 2008-2009, Thomas Gleixner <tglx@linutronix.de> 8 * Copyright (C) 2008-2009, Thomas Gleixner <tglx@linutronix.de>
5 * Copyright (C) 2008-2009, Red Hat, Inc., Ingo Molnar 9 * Copyright (C) 2008-2009, Red Hat, Inc., Ingo Molnar
@@ -131,19 +135,19 @@ enum perf_counter_sample_format {
131 * as specified by attr.read_format: 135 * as specified by attr.read_format:
132 * 136 *
133 * struct read_format { 137 * struct read_format {
134 * { u64 value; 138 * { u64 value;
135 * { u64 time_enabled; } && PERF_FORMAT_ENABLED 139 * { u64 time_enabled; } && PERF_FORMAT_ENABLED
136 * { u64 time_running; } && PERF_FORMAT_RUNNING 140 * { u64 time_running; } && PERF_FORMAT_RUNNING
137 * { u64 id; } && PERF_FORMAT_ID 141 * { u64 id; } && PERF_FORMAT_ID
138 * } && !PERF_FORMAT_GROUP 142 * } && !PERF_FORMAT_GROUP
139 * 143 *
140 * { u64 nr; 144 * { u64 nr;
141 * { u64 time_enabled; } && PERF_FORMAT_ENABLED 145 * { u64 time_enabled; } && PERF_FORMAT_ENABLED
142 * { u64 time_running; } && PERF_FORMAT_RUNNING 146 * { u64 time_running; } && PERF_FORMAT_RUNNING
143 * { u64 value; 147 * { u64 value;
144 * { u64 id; } && PERF_FORMAT_ID 148 * { u64 id; } && PERF_FORMAT_ID
145 * } cntr[nr]; 149 * } cntr[nr];
146 * } && PERF_FORMAT_GROUP 150 * } && PERF_FORMAT_GROUP
147 * }; 151 * };
148 */ 152 */
149enum perf_counter_read_format { 153enum perf_counter_read_format {
@@ -314,9 +318,9 @@ enum perf_event_type {
314 318
315 /* 319 /*
316 * struct { 320 * struct {
317 * struct perf_event_header header; 321 * struct perf_event_header header;
318 * u64 id; 322 * u64 id;
319 * u64 lost; 323 * u64 lost;
320 * }; 324 * };
321 */ 325 */
322 PERF_EVENT_LOST = 2, 326 PERF_EVENT_LOST = 2,
@@ -364,10 +368,10 @@ enum perf_event_type {
364 368
365 /* 369 /*
366 * struct { 370 * struct {
367 * struct perf_event_header header; 371 * struct perf_event_header header;
368 * u32 pid, tid; 372 * u32 pid, tid;
369 * 373 *
370 * struct read_format values; 374 * struct read_format values;
371 * }; 375 * };
372 */ 376 */
373 PERF_EVENT_READ = 8, 377 PERF_EVENT_READ = 8,
@@ -383,23 +387,23 @@ enum perf_event_type {
383 * { u64 id; } && PERF_SAMPLE_ID 387 * { u64 id; } && PERF_SAMPLE_ID
384 * { u64 stream_id;} && PERF_SAMPLE_STREAM_ID 388 * { u64 stream_id;} && PERF_SAMPLE_STREAM_ID
385 * { u32 cpu, res; } && PERF_SAMPLE_CPU 389 * { u32 cpu, res; } && PERF_SAMPLE_CPU
386 * { u64 period; } && PERF_SAMPLE_PERIOD 390 * { u64 period; } && PERF_SAMPLE_PERIOD
387 * 391 *
388 * { struct read_format values; } && PERF_SAMPLE_READ 392 * { struct read_format values; } && PERF_SAMPLE_READ
389 * 393 *
390 * { u64 nr, 394 * { u64 nr,
391 * u64 ips[nr]; } && PERF_SAMPLE_CALLCHAIN 395 * u64 ips[nr]; } && PERF_SAMPLE_CALLCHAIN
392 * 396 *
393 * # 397 * #
394 * # The RAW record below is opaque data wrt the ABI 398 * # The RAW record below is opaque data wrt the ABI
395 * # 399 * #
396 * # That is, the ABI doesn't make any promises wrt to 400 * # That is, the ABI doesn't make any promises wrt to
397 * # the stability of its content, it may vary depending 401 * # the stability of its content, it may vary depending
398 * # on event, hardware, kernel version and phase of 402 * # on event, hardware, kernel version and phase of
399 * # the moon. 403 * # the moon.
400 * # 404 * #
401 * # In other words, PERF_SAMPLE_RAW contents are not an ABI. 405 * # In other words, PERF_SAMPLE_RAW contents are not an ABI.
402 * # 406 * #
403 * 407 *
404 * { u32 size; 408 * { u32 size;
405 * char data[size];}&& PERF_SAMPLE_RAW 409 * char data[size];}&& PERF_SAMPLE_RAW
@@ -422,437 +426,16 @@ enum perf_callchain_context {
422 PERF_CONTEXT_MAX = (__u64)-4095, 426 PERF_CONTEXT_MAX = (__u64)-4095,
423}; 427};
424 428
425#define PERF_FLAG_FD_NO_GROUP (1U << 0) 429#define PERF_FLAG_FD_NO_GROUP (1U << 0)
426#define PERF_FLAG_FD_OUTPUT (1U << 1) 430#define PERF_FLAG_FD_OUTPUT (1U << 1)
427 431
428#ifdef __KERNEL__
429/* 432/*
430 * Kernel-internal data types and definitions: 433 * In case some app still references the old symbols:
431 */
432
433#ifdef CONFIG_PERF_COUNTERS
434# include <asm/perf_counter.h>
435#endif
436
437#include <linux/list.h>
438#include <linux/mutex.h>
439#include <linux/rculist.h>
440#include <linux/rcupdate.h>
441#include <linux/spinlock.h>
442#include <linux/hrtimer.h>
443#include <linux/fs.h>
444#include <linux/pid_namespace.h>
445#include <asm/atomic.h>
446
447#define PERF_MAX_STACK_DEPTH 255
448
449struct perf_callchain_entry {
450 __u64 nr;
451 __u64 ip[PERF_MAX_STACK_DEPTH];
452};
453
454struct perf_raw_record {
455 u32 size;
456 void *data;
457};
458
459struct task_struct;
460
461/**
462 * struct hw_perf_counter - performance counter hardware details:
463 */ 434 */
464struct hw_perf_counter {
465#ifdef CONFIG_PERF_COUNTERS
466 union {
467 struct { /* hardware */
468 u64 config;
469 unsigned long config_base;
470 unsigned long counter_base;
471 int idx;
472 };
473 union { /* software */
474 atomic64_t count;
475 struct hrtimer hrtimer;
476 };
477 };
478 atomic64_t prev_count;
479 u64 sample_period;
480 u64 last_period;
481 atomic64_t period_left;
482 u64 interrupts;
483
484 u64 freq_count;
485 u64 freq_interrupts;
486 u64 freq_stamp;
487#endif
488};
489
490struct perf_counter;
491
492/**
493 * struct pmu - generic performance monitoring unit
494 */
495struct pmu {
496 int (*enable) (struct perf_counter *counter);
497 void (*disable) (struct perf_counter *counter);
498 void (*read) (struct perf_counter *counter);
499 void (*unthrottle) (struct perf_counter *counter);
500};
501
502/**
503 * enum perf_counter_active_state - the states of a counter
504 */
505enum perf_counter_active_state {
506 PERF_COUNTER_STATE_ERROR = -2,
507 PERF_COUNTER_STATE_OFF = -1,
508 PERF_COUNTER_STATE_INACTIVE = 0,
509 PERF_COUNTER_STATE_ACTIVE = 1,
510};
511
512struct file;
513 435
514struct perf_mmap_data { 436#define __NR_perf_counter_open __NR_perf_event_open
515 struct rcu_head rcu_head;
516 int nr_pages; /* nr of data pages */
517 int writable; /* are we writable */
518 int nr_locked; /* nr pages mlocked */
519 437
520 atomic_t poll; /* POLL_ for wakeups */ 438#define PR_TASK_PERF_COUNTERS_DISABLE PR_TASK_PERF_EVENTS_DISABLE
521 atomic_t events; /* event limit */ 439#define PR_TASK_PERF_COUNTERS_ENABLE PR_TASK_PERF_EVENTS_ENABLE
522 440
523 atomic_long_t head; /* write position */
524 atomic_long_t done_head; /* completed head */
525
526 atomic_t lock; /* concurrent writes */
527 atomic_t wakeup; /* needs a wakeup */
528 atomic_t lost; /* nr records lost */
529
530 long watermark; /* wakeup watermark */
531
532 struct perf_counter_mmap_page *user_page;
533 void *data_pages[0];
534};
535
536struct perf_pending_entry {
537 struct perf_pending_entry *next;
538 void (*func)(struct perf_pending_entry *);
539};
540
541/**
542 * struct perf_counter - performance counter kernel representation:
543 */
544struct perf_counter {
545#ifdef CONFIG_PERF_COUNTERS
546 struct list_head list_entry;
547 struct list_head event_entry;
548 struct list_head sibling_list;
549 int nr_siblings;
550 struct perf_counter *group_leader;
551 struct perf_counter *output;
552 const struct pmu *pmu;
553
554 enum perf_counter_active_state state;
555 atomic64_t count;
556
557 /*
558 * These are the total time in nanoseconds that the counter
559 * has been enabled (i.e. eligible to run, and the task has
560 * been scheduled in, if this is a per-task counter)
561 * and running (scheduled onto the CPU), respectively.
562 *
563 * They are computed from tstamp_enabled, tstamp_running and
564 * tstamp_stopped when the counter is in INACTIVE or ACTIVE state.
565 */
566 u64 total_time_enabled;
567 u64 total_time_running;
568
569 /*
570 * These are timestamps used for computing total_time_enabled
571 * and total_time_running when the counter is in INACTIVE or
572 * ACTIVE state, measured in nanoseconds from an arbitrary point
573 * in time.
574 * tstamp_enabled: the notional time when the counter was enabled
575 * tstamp_running: the notional time when the counter was scheduled on
576 * tstamp_stopped: in INACTIVE state, the notional time when the
577 * counter was scheduled off.
578 */
579 u64 tstamp_enabled;
580 u64 tstamp_running;
581 u64 tstamp_stopped;
582
583 struct perf_counter_attr attr;
584 struct hw_perf_counter hw;
585
586 struct perf_counter_context *ctx;
587 struct file *filp;
588
589 /*
590 * These accumulate total time (in nanoseconds) that children
591 * counters have been enabled and running, respectively.
592 */
593 atomic64_t child_total_time_enabled;
594 atomic64_t child_total_time_running;
595
596 /*
597 * Protect attach/detach and child_list:
598 */
599 struct mutex child_mutex;
600 struct list_head child_list;
601 struct perf_counter *parent;
602
603 int oncpu;
604 int cpu;
605
606 struct list_head owner_entry;
607 struct task_struct *owner;
608
609 /* mmap bits */
610 struct mutex mmap_mutex;
611 atomic_t mmap_count;
612 struct perf_mmap_data *data;
613
614 /* poll related */
615 wait_queue_head_t waitq;
616 struct fasync_struct *fasync;
617
618 /* delayed work for NMIs and such */
619 int pending_wakeup;
620 int pending_kill;
621 int pending_disable;
622 struct perf_pending_entry pending;
623
624 atomic_t event_limit;
625
626 void (*destroy)(struct perf_counter *);
627 struct rcu_head rcu_head;
628
629 struct pid_namespace *ns;
630 u64 id;
631#endif
632};
633
634/**
635 * struct perf_counter_context - counter context structure
636 *
637 * Used as a container for task counters and CPU counters as well:
638 */
639struct perf_counter_context {
640 /*
641 * Protect the states of the counters in the list,
642 * nr_active, and the list:
643 */
644 spinlock_t lock;
645 /*
646 * Protect the list of counters. Locking either mutex or lock
647 * is sufficient to ensure the list doesn't change; to change
648 * the list you need to lock both the mutex and the spinlock.
649 */
650 struct mutex mutex;
651
652 struct list_head counter_list;
653 struct list_head event_list;
654 int nr_counters;
655 int nr_active;
656 int is_active;
657 int nr_stat;
658 atomic_t refcount;
659 struct task_struct *task;
660
661 /*
662 * Context clock, runs when context enabled.
663 */
664 u64 time;
665 u64 timestamp;
666
667 /*
668 * These fields let us detect when two contexts have both
669 * been cloned (inherited) from a common ancestor.
670 */
671 struct perf_counter_context *parent_ctx;
672 u64 parent_gen;
673 u64 generation;
674 int pin_count;
675 struct rcu_head rcu_head;
676};
677
678/**
679 * struct perf_counter_cpu_context - per cpu counter context structure
680 */
681struct perf_cpu_context {
682 struct perf_counter_context ctx;
683 struct perf_counter_context *task_ctx;
684 int active_oncpu;
685 int max_pertask;
686 int exclusive;
687
688 /*
689 * Recursion avoidance:
690 *
691 * task, softirq, irq, nmi context
692 */
693 int recursion[4];
694};
695
696struct perf_output_handle {
697 struct perf_counter *counter;
698 struct perf_mmap_data *data;
699 unsigned long head;
700 unsigned long offset;
701 int nmi;
702 int sample;
703 int locked;
704 unsigned long flags;
705};
706
707#ifdef CONFIG_PERF_COUNTERS
708
709/*
710 * Set by architecture code:
711 */
712extern int perf_max_counters;
713
714extern const struct pmu *hw_perf_counter_init(struct perf_counter *counter);
715
716extern void perf_counter_task_sched_in(struct task_struct *task, int cpu);
717extern void perf_counter_task_sched_out(struct task_struct *task,
718 struct task_struct *next, int cpu);
719extern void perf_counter_task_tick(struct task_struct *task, int cpu);
720extern int perf_counter_init_task(struct task_struct *child);
721extern void perf_counter_exit_task(struct task_struct *child);
722extern void perf_counter_free_task(struct task_struct *task);
723extern void set_perf_counter_pending(void);
724extern void perf_counter_do_pending(void);
725extern void perf_counter_print_debug(void);
726extern void __perf_disable(void);
727extern bool __perf_enable(void);
728extern void perf_disable(void);
729extern void perf_enable(void);
730extern int perf_counter_task_disable(void);
731extern int perf_counter_task_enable(void);
732extern int hw_perf_group_sched_in(struct perf_counter *group_leader,
733 struct perf_cpu_context *cpuctx,
734 struct perf_counter_context *ctx, int cpu);
735extern void perf_counter_update_userpage(struct perf_counter *counter);
736
737struct perf_sample_data {
738 u64 type;
739
740 u64 ip;
741 struct {
742 u32 pid;
743 u32 tid;
744 } tid_entry;
745 u64 time;
746 u64 addr;
747 u64 id;
748 u64 stream_id;
749 struct {
750 u32 cpu;
751 u32 reserved;
752 } cpu_entry;
753 u64 period;
754 struct perf_callchain_entry *callchain;
755 struct perf_raw_record *raw;
756};
757
758extern void perf_output_sample(struct perf_output_handle *handle,
759 struct perf_event_header *header,
760 struct perf_sample_data *data,
761 struct perf_counter *counter);
762extern void perf_prepare_sample(struct perf_event_header *header,
763 struct perf_sample_data *data,
764 struct perf_counter *counter,
765 struct pt_regs *regs);
766
767extern int perf_counter_overflow(struct perf_counter *counter, int nmi,
768 struct perf_sample_data *data,
769 struct pt_regs *regs);
770
771/*
772 * Return 1 for a software counter, 0 for a hardware counter
773 */
774static inline int is_software_counter(struct perf_counter *counter)
775{
776 return (counter->attr.type != PERF_TYPE_RAW) &&
777 (counter->attr.type != PERF_TYPE_HARDWARE) &&
778 (counter->attr.type != PERF_TYPE_HW_CACHE);
779}
780
781extern atomic_t perf_swcounter_enabled[PERF_COUNT_SW_MAX];
782
783extern void __perf_swcounter_event(u32, u64, int, struct pt_regs *, u64);
784
785static inline void
786perf_swcounter_event(u32 event, u64 nr, int nmi, struct pt_regs *regs, u64 addr)
787{
788 if (atomic_read(&perf_swcounter_enabled[event]))
789 __perf_swcounter_event(event, nr, nmi, regs, addr);
790}
791
792extern void __perf_counter_mmap(struct vm_area_struct *vma);
793
794static inline void perf_counter_mmap(struct vm_area_struct *vma)
795{
796 if (vma->vm_flags & VM_EXEC)
797 __perf_counter_mmap(vma);
798}
799
800extern void perf_counter_comm(struct task_struct *tsk);
801extern void perf_counter_fork(struct task_struct *tsk);
802
803extern struct perf_callchain_entry *perf_callchain(struct pt_regs *regs);
804
805extern int sysctl_perf_counter_paranoid;
806extern int sysctl_perf_counter_mlock;
807extern int sysctl_perf_counter_sample_rate;
808
809extern void perf_counter_init(void);
810extern void perf_tpcounter_event(int event_id, u64 addr, u64 count,
811 void *record, int entry_size);
812
813#ifndef perf_misc_flags
814#define perf_misc_flags(regs) (user_mode(regs) ? PERF_EVENT_MISC_USER : \
815 PERF_EVENT_MISC_KERNEL)
816#define perf_instruction_pointer(regs) instruction_pointer(regs)
817#endif
818
819extern int perf_output_begin(struct perf_output_handle *handle,
820 struct perf_counter *counter, unsigned int size,
821 int nmi, int sample);
822extern void perf_output_end(struct perf_output_handle *handle);
823extern void perf_output_copy(struct perf_output_handle *handle,
824 const void *buf, unsigned int len);
825#else
826static inline void
827perf_counter_task_sched_in(struct task_struct *task, int cpu) { }
828static inline void
829perf_counter_task_sched_out(struct task_struct *task,
830 struct task_struct *next, int cpu) { }
831static inline void
832perf_counter_task_tick(struct task_struct *task, int cpu) { }
833static inline int perf_counter_init_task(struct task_struct *child) { return 0; }
834static inline void perf_counter_exit_task(struct task_struct *child) { }
835static inline void perf_counter_free_task(struct task_struct *task) { }
836static inline void perf_counter_do_pending(void) { }
837static inline void perf_counter_print_debug(void) { }
838static inline void perf_disable(void) { }
839static inline void perf_enable(void) { }
840static inline int perf_counter_task_disable(void) { return -EINVAL; }
841static inline int perf_counter_task_enable(void) { return -EINVAL; }
842
843static inline void
844perf_swcounter_event(u32 event, u64 nr, int nmi,
845 struct pt_regs *regs, u64 addr) { }
846
847static inline void perf_counter_mmap(struct vm_area_struct *vma) { }
848static inline void perf_counter_comm(struct task_struct *tsk) { }
849static inline void perf_counter_fork(struct task_struct *tsk) { }
850static inline void perf_counter_init(void) { }
851
852#endif
853
854#define perf_output_put(handle, x) \
855 perf_output_copy((handle), &(x), sizeof(x))
856
857#endif /* __KERNEL__ */
858#endif /* _LINUX_PERF_COUNTER_H */ 441#endif /* _LINUX_PERF_COUNTER_H */