diff options
Diffstat (limited to 'include/linux/perf_event.h')
-rw-r--r-- | include/linux/perf_event.h | 212 |
1 files changed, 138 insertions, 74 deletions
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 716f99b682c1..057bf22a8323 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h | |||
@@ -486,6 +486,8 @@ struct perf_guest_info_callbacks { | |||
486 | #include <linux/workqueue.h> | 486 | #include <linux/workqueue.h> |
487 | #include <linux/ftrace.h> | 487 | #include <linux/ftrace.h> |
488 | #include <linux/cpu.h> | 488 | #include <linux/cpu.h> |
489 | #include <linux/irq_work.h> | ||
490 | #include <linux/jump_label_ref.h> | ||
489 | #include <asm/atomic.h> | 491 | #include <asm/atomic.h> |
490 | #include <asm/local.h> | 492 | #include <asm/local.h> |
491 | 493 | ||
@@ -529,16 +531,22 @@ struct hw_perf_event { | |||
529 | int last_cpu; | 531 | int last_cpu; |
530 | }; | 532 | }; |
531 | struct { /* software */ | 533 | struct { /* software */ |
532 | s64 remaining; | ||
533 | struct hrtimer hrtimer; | 534 | struct hrtimer hrtimer; |
534 | }; | 535 | }; |
535 | #ifdef CONFIG_HAVE_HW_BREAKPOINT | 536 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
536 | struct { /* breakpoint */ | 537 | struct { /* breakpoint */ |
537 | struct arch_hw_breakpoint info; | 538 | struct arch_hw_breakpoint info; |
538 | struct list_head bp_list; | 539 | struct list_head bp_list; |
540 | /* | ||
541 | * Crufty hack to avoid the chicken and egg | ||
542 | * problem hw_breakpoint has with context | ||
543 | * creation and event initalization. | ||
544 | */ | ||
545 | struct task_struct *bp_target; | ||
539 | }; | 546 | }; |
540 | #endif | 547 | #endif |
541 | }; | 548 | }; |
549 | int state; | ||
542 | local64_t prev_count; | 550 | local64_t prev_count; |
543 | u64 sample_period; | 551 | u64 sample_period; |
544 | u64 last_period; | 552 | u64 last_period; |
@@ -550,6 +558,13 @@ struct hw_perf_event { | |||
550 | #endif | 558 | #endif |
551 | }; | 559 | }; |
552 | 560 | ||
561 | /* | ||
562 | * hw_perf_event::state flags | ||
563 | */ | ||
564 | #define PERF_HES_STOPPED 0x01 /* the counter is stopped */ | ||
565 | #define PERF_HES_UPTODATE 0x02 /* event->count up-to-date */ | ||
566 | #define PERF_HES_ARCH 0x04 | ||
567 | |||
553 | struct perf_event; | 568 | struct perf_event; |
554 | 569 | ||
555 | /* | 570 | /* |
@@ -561,36 +576,70 @@ struct perf_event; | |||
561 | * struct pmu - generic performance monitoring unit | 576 | * struct pmu - generic performance monitoring unit |
562 | */ | 577 | */ |
563 | struct pmu { | 578 | struct pmu { |
564 | int (*enable) (struct perf_event *event); | 579 | struct list_head entry; |
565 | void (*disable) (struct perf_event *event); | 580 | |
566 | int (*start) (struct perf_event *event); | 581 | int * __percpu pmu_disable_count; |
567 | void (*stop) (struct perf_event *event); | 582 | struct perf_cpu_context * __percpu pmu_cpu_context; |
568 | void (*read) (struct perf_event *event); | 583 | int task_ctx_nr; |
569 | void (*unthrottle) (struct perf_event *event); | 584 | |
585 | /* | ||
586 | * Fully disable/enable this PMU, can be used to protect from the PMI | ||
587 | * as well as for lazy/batch writing of the MSRs. | ||
588 | */ | ||
589 | void (*pmu_enable) (struct pmu *pmu); /* optional */ | ||
590 | void (*pmu_disable) (struct pmu *pmu); /* optional */ | ||
570 | 591 | ||
571 | /* | 592 | /* |
572 | * Group events scheduling is treated as a transaction, add group | 593 | * Try and initialize the event for this PMU. |
573 | * events as a whole and perform one schedulability test. If the test | 594 | * Should return -ENOENT when the @event doesn't match this PMU. |
574 | * fails, roll back the whole group | ||
575 | */ | 595 | */ |
596 | int (*event_init) (struct perf_event *event); | ||
597 | |||
598 | #define PERF_EF_START 0x01 /* start the counter when adding */ | ||
599 | #define PERF_EF_RELOAD 0x02 /* reload the counter when starting */ | ||
600 | #define PERF_EF_UPDATE 0x04 /* update the counter when stopping */ | ||
576 | 601 | ||
577 | /* | 602 | /* |
578 | * Start the transaction, after this ->enable() doesn't need | 603 | * Adds/Removes a counter to/from the PMU, can be done inside |
579 | * to do schedulability tests. | 604 | * a transaction, see the ->*_txn() methods. |
580 | */ | 605 | */ |
581 | void (*start_txn) (const struct pmu *pmu); | 606 | int (*add) (struct perf_event *event, int flags); |
607 | void (*del) (struct perf_event *event, int flags); | ||
608 | |||
582 | /* | 609 | /* |
583 | * If ->start_txn() disabled the ->enable() schedulability test | 610 | * Starts/Stops a counter present on the PMU. The PMI handler |
611 | * should stop the counter when perf_event_overflow() returns | ||
612 | * !0. ->start() will be used to continue. | ||
613 | */ | ||
614 | void (*start) (struct perf_event *event, int flags); | ||
615 | void (*stop) (struct perf_event *event, int flags); | ||
616 | |||
617 | /* | ||
618 | * Updates the counter value of the event. | ||
619 | */ | ||
620 | void (*read) (struct perf_event *event); | ||
621 | |||
622 | /* | ||
623 | * Group events scheduling is treated as a transaction, add | ||
624 | * group events as a whole and perform one schedulability test. | ||
625 | * If the test fails, roll back the whole group | ||
626 | * | ||
627 | * Start the transaction, after this ->add() doesn't need to | ||
628 | * do schedulability tests. | ||
629 | */ | ||
630 | void (*start_txn) (struct pmu *pmu); /* optional */ | ||
631 | /* | ||
632 | * If ->start_txn() disabled the ->add() schedulability test | ||
584 | * then ->commit_txn() is required to perform one. On success | 633 | * then ->commit_txn() is required to perform one. On success |
585 | * the transaction is closed. On error the transaction is kept | 634 | * the transaction is closed. On error the transaction is kept |
586 | * open until ->cancel_txn() is called. | 635 | * open until ->cancel_txn() is called. |
587 | */ | 636 | */ |
588 | int (*commit_txn) (const struct pmu *pmu); | 637 | int (*commit_txn) (struct pmu *pmu); /* optional */ |
589 | /* | 638 | /* |
590 | * Will cancel the transaction, assumes ->disable() is called for | 639 | * Will cancel the transaction, assumes ->del() is called |
591 | * each successfull ->enable() during the transaction. | 640 | * for each successfull ->add() during the transaction. |
592 | */ | 641 | */ |
593 | void (*cancel_txn) (const struct pmu *pmu); | 642 | void (*cancel_txn) (struct pmu *pmu); /* optional */ |
594 | }; | 643 | }; |
595 | 644 | ||
596 | /** | 645 | /** |
@@ -631,11 +680,6 @@ struct perf_buffer { | |||
631 | void *data_pages[0]; | 680 | void *data_pages[0]; |
632 | }; | 681 | }; |
633 | 682 | ||
634 | struct perf_pending_entry { | ||
635 | struct perf_pending_entry *next; | ||
636 | void (*func)(struct perf_pending_entry *); | ||
637 | }; | ||
638 | |||
639 | struct perf_sample_data; | 683 | struct perf_sample_data; |
640 | 684 | ||
641 | typedef void (*perf_overflow_handler_t)(struct perf_event *, int, | 685 | typedef void (*perf_overflow_handler_t)(struct perf_event *, int, |
@@ -656,6 +700,7 @@ struct swevent_hlist { | |||
656 | 700 | ||
657 | #define PERF_ATTACH_CONTEXT 0x01 | 701 | #define PERF_ATTACH_CONTEXT 0x01 |
658 | #define PERF_ATTACH_GROUP 0x02 | 702 | #define PERF_ATTACH_GROUP 0x02 |
703 | #define PERF_ATTACH_TASK 0x04 | ||
659 | 704 | ||
660 | /** | 705 | /** |
661 | * struct perf_event - performance event kernel representation: | 706 | * struct perf_event - performance event kernel representation: |
@@ -669,7 +714,7 @@ struct perf_event { | |||
669 | int nr_siblings; | 714 | int nr_siblings; |
670 | int group_flags; | 715 | int group_flags; |
671 | struct perf_event *group_leader; | 716 | struct perf_event *group_leader; |
672 | const struct pmu *pmu; | 717 | struct pmu *pmu; |
673 | 718 | ||
674 | enum perf_event_active_state state; | 719 | enum perf_event_active_state state; |
675 | unsigned int attach_state; | 720 | unsigned int attach_state; |
@@ -743,7 +788,7 @@ struct perf_event { | |||
743 | int pending_wakeup; | 788 | int pending_wakeup; |
744 | int pending_kill; | 789 | int pending_kill; |
745 | int pending_disable; | 790 | int pending_disable; |
746 | struct perf_pending_entry pending; | 791 | struct irq_work pending; |
747 | 792 | ||
748 | atomic_t event_limit; | 793 | atomic_t event_limit; |
749 | 794 | ||
@@ -763,12 +808,19 @@ struct perf_event { | |||
763 | #endif /* CONFIG_PERF_EVENTS */ | 808 | #endif /* CONFIG_PERF_EVENTS */ |
764 | }; | 809 | }; |
765 | 810 | ||
811 | enum perf_event_context_type { | ||
812 | task_context, | ||
813 | cpu_context, | ||
814 | }; | ||
815 | |||
766 | /** | 816 | /** |
767 | * struct perf_event_context - event context structure | 817 | * struct perf_event_context - event context structure |
768 | * | 818 | * |
769 | * Used as a container for task events and CPU events as well: | 819 | * Used as a container for task events and CPU events as well: |
770 | */ | 820 | */ |
771 | struct perf_event_context { | 821 | struct perf_event_context { |
822 | enum perf_event_context_type type; | ||
823 | struct pmu *pmu; | ||
772 | /* | 824 | /* |
773 | * Protect the states of the events in the list, | 825 | * Protect the states of the events in the list, |
774 | * nr_active, and the list: | 826 | * nr_active, and the list: |
@@ -808,6 +860,12 @@ struct perf_event_context { | |||
808 | struct rcu_head rcu_head; | 860 | struct rcu_head rcu_head; |
809 | }; | 861 | }; |
810 | 862 | ||
863 | /* | ||
864 | * Number of contexts where an event can trigger: | ||
865 | * task, softirq, hardirq, nmi. | ||
866 | */ | ||
867 | #define PERF_NR_CONTEXTS 4 | ||
868 | |||
811 | /** | 869 | /** |
812 | * struct perf_event_cpu_context - per cpu event context structure | 870 | * struct perf_event_cpu_context - per cpu event context structure |
813 | */ | 871 | */ |
@@ -815,18 +873,9 @@ struct perf_cpu_context { | |||
815 | struct perf_event_context ctx; | 873 | struct perf_event_context ctx; |
816 | struct perf_event_context *task_ctx; | 874 | struct perf_event_context *task_ctx; |
817 | int active_oncpu; | 875 | int active_oncpu; |
818 | int max_pertask; | ||
819 | int exclusive; | 876 | int exclusive; |
820 | struct swevent_hlist *swevent_hlist; | 877 | struct list_head rotation_list; |
821 | struct mutex hlist_mutex; | 878 | int jiffies_interval; |
822 | int hlist_refcount; | ||
823 | |||
824 | /* | ||
825 | * Recursion avoidance: | ||
826 | * | ||
827 | * task, softirq, irq, nmi context | ||
828 | */ | ||
829 | int recursion[4]; | ||
830 | }; | 879 | }; |
831 | 880 | ||
832 | struct perf_output_handle { | 881 | struct perf_output_handle { |
@@ -842,26 +891,34 @@ struct perf_output_handle { | |||
842 | 891 | ||
843 | #ifdef CONFIG_PERF_EVENTS | 892 | #ifdef CONFIG_PERF_EVENTS |
844 | 893 | ||
845 | /* | 894 | extern int perf_pmu_register(struct pmu *pmu); |
846 | * Set by architecture code: | 895 | extern void perf_pmu_unregister(struct pmu *pmu); |
847 | */ | 896 | |
848 | extern int perf_max_events; | 897 | extern int perf_num_counters(void); |
898 | extern const char *perf_pmu_name(void); | ||
899 | extern void __perf_event_task_sched_in(struct task_struct *task); | ||
900 | extern void __perf_event_task_sched_out(struct task_struct *task, struct task_struct *next); | ||
849 | 901 | ||
850 | extern const struct pmu *hw_perf_event_init(struct perf_event *event); | 902 | extern atomic_t perf_task_events; |
903 | |||
904 | static inline void perf_event_task_sched_in(struct task_struct *task) | ||
905 | { | ||
906 | COND_STMT(&perf_task_events, __perf_event_task_sched_in(task)); | ||
907 | } | ||
908 | |||
909 | static inline | ||
910 | void perf_event_task_sched_out(struct task_struct *task, struct task_struct *next) | ||
911 | { | ||
912 | COND_STMT(&perf_task_events, __perf_event_task_sched_out(task, next)); | ||
913 | } | ||
851 | 914 | ||
852 | extern void perf_event_task_sched_in(struct task_struct *task); | ||
853 | extern void perf_event_task_sched_out(struct task_struct *task, struct task_struct *next); | ||
854 | extern void perf_event_task_tick(struct task_struct *task); | ||
855 | extern int perf_event_init_task(struct task_struct *child); | 915 | extern int perf_event_init_task(struct task_struct *child); |
856 | extern void perf_event_exit_task(struct task_struct *child); | 916 | extern void perf_event_exit_task(struct task_struct *child); |
857 | extern void perf_event_free_task(struct task_struct *task); | 917 | extern void perf_event_free_task(struct task_struct *task); |
858 | extern void set_perf_event_pending(void); | 918 | extern void perf_event_delayed_put(struct task_struct *task); |
859 | extern void perf_event_do_pending(void); | ||
860 | extern void perf_event_print_debug(void); | 919 | extern void perf_event_print_debug(void); |
861 | extern void __perf_disable(void); | 920 | extern void perf_pmu_disable(struct pmu *pmu); |
862 | extern bool __perf_enable(void); | 921 | extern void perf_pmu_enable(struct pmu *pmu); |
863 | extern void perf_disable(void); | ||
864 | extern void perf_enable(void); | ||
865 | extern int perf_event_task_disable(void); | 922 | extern int perf_event_task_disable(void); |
866 | extern int perf_event_task_enable(void); | 923 | extern int perf_event_task_enable(void); |
867 | extern void perf_event_update_userpage(struct perf_event *event); | 924 | extern void perf_event_update_userpage(struct perf_event *event); |
@@ -869,7 +926,7 @@ extern int perf_event_release_kernel(struct perf_event *event); | |||
869 | extern struct perf_event * | 926 | extern struct perf_event * |
870 | perf_event_create_kernel_counter(struct perf_event_attr *attr, | 927 | perf_event_create_kernel_counter(struct perf_event_attr *attr, |
871 | int cpu, | 928 | int cpu, |
872 | pid_t pid, | 929 | struct task_struct *task, |
873 | perf_overflow_handler_t callback); | 930 | perf_overflow_handler_t callback); |
874 | extern u64 perf_event_read_value(struct perf_event *event, | 931 | extern u64 perf_event_read_value(struct perf_event *event, |
875 | u64 *enabled, u64 *running); | 932 | u64 *enabled, u64 *running); |
@@ -920,14 +977,7 @@ extern int perf_event_overflow(struct perf_event *event, int nmi, | |||
920 | */ | 977 | */ |
921 | static inline int is_software_event(struct perf_event *event) | 978 | static inline int is_software_event(struct perf_event *event) |
922 | { | 979 | { |
923 | switch (event->attr.type) { | 980 | return event->pmu->task_ctx_nr == perf_sw_context; |
924 | case PERF_TYPE_SOFTWARE: | ||
925 | case PERF_TYPE_TRACEPOINT: | ||
926 | /* for now the breakpoint stuff also works as software event */ | ||
927 | case PERF_TYPE_BREAKPOINT: | ||
928 | return 1; | ||
929 | } | ||
930 | return 0; | ||
931 | } | 981 | } |
932 | 982 | ||
933 | extern atomic_t perf_swevent_enabled[PERF_COUNT_SW_MAX]; | 983 | extern atomic_t perf_swevent_enabled[PERF_COUNT_SW_MAX]; |
@@ -954,18 +1004,20 @@ static inline void perf_fetch_caller_regs(struct pt_regs *regs) | |||
954 | perf_arch_fetch_caller_regs(regs, CALLER_ADDR0); | 1004 | perf_arch_fetch_caller_regs(regs, CALLER_ADDR0); |
955 | } | 1005 | } |
956 | 1006 | ||
957 | static inline void | 1007 | static __always_inline void |
958 | perf_sw_event(u32 event_id, u64 nr, int nmi, struct pt_regs *regs, u64 addr) | 1008 | perf_sw_event(u32 event_id, u64 nr, int nmi, struct pt_regs *regs, u64 addr) |
959 | { | 1009 | { |
960 | if (atomic_read(&perf_swevent_enabled[event_id])) { | 1010 | struct pt_regs hot_regs; |
961 | struct pt_regs hot_regs; | 1011 | |
962 | 1012 | JUMP_LABEL(&perf_swevent_enabled[event_id], have_event); | |
963 | if (!regs) { | 1013 | return; |
964 | perf_fetch_caller_regs(&hot_regs); | 1014 | |
965 | regs = &hot_regs; | 1015 | have_event: |
966 | } | 1016 | if (!regs) { |
967 | __perf_sw_event(event_id, nr, nmi, regs, addr); | 1017 | perf_fetch_caller_regs(&hot_regs); |
1018 | regs = &hot_regs; | ||
968 | } | 1019 | } |
1020 | __perf_sw_event(event_id, nr, nmi, regs, addr); | ||
969 | } | 1021 | } |
970 | 1022 | ||
971 | extern void perf_event_mmap(struct vm_area_struct *vma); | 1023 | extern void perf_event_mmap(struct vm_area_struct *vma); |
@@ -976,7 +1028,21 @@ extern int perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks | |||
976 | extern void perf_event_comm(struct task_struct *tsk); | 1028 | extern void perf_event_comm(struct task_struct *tsk); |
977 | extern void perf_event_fork(struct task_struct *tsk); | 1029 | extern void perf_event_fork(struct task_struct *tsk); |
978 | 1030 | ||
979 | extern struct perf_callchain_entry *perf_callchain(struct pt_regs *regs); | 1031 | /* Callchains */ |
1032 | DECLARE_PER_CPU(struct perf_callchain_entry, perf_callchain_entry); | ||
1033 | |||
1034 | extern void perf_callchain_user(struct perf_callchain_entry *entry, | ||
1035 | struct pt_regs *regs); | ||
1036 | extern void perf_callchain_kernel(struct perf_callchain_entry *entry, | ||
1037 | struct pt_regs *regs); | ||
1038 | |||
1039 | |||
1040 | static inline void | ||
1041 | perf_callchain_store(struct perf_callchain_entry *entry, u64 ip) | ||
1042 | { | ||
1043 | if (entry->nr < PERF_MAX_STACK_DEPTH) | ||
1044 | entry->ip[entry->nr++] = ip; | ||
1045 | } | ||
980 | 1046 | ||
981 | extern int sysctl_perf_event_paranoid; | 1047 | extern int sysctl_perf_event_paranoid; |
982 | extern int sysctl_perf_event_mlock; | 1048 | extern int sysctl_perf_event_mlock; |
@@ -1019,21 +1085,18 @@ extern int perf_swevent_get_recursion_context(void); | |||
1019 | extern void perf_swevent_put_recursion_context(int rctx); | 1085 | extern void perf_swevent_put_recursion_context(int rctx); |
1020 | extern void perf_event_enable(struct perf_event *event); | 1086 | extern void perf_event_enable(struct perf_event *event); |
1021 | extern void perf_event_disable(struct perf_event *event); | 1087 | extern void perf_event_disable(struct perf_event *event); |
1088 | extern void perf_event_task_tick(void); | ||
1022 | #else | 1089 | #else |
1023 | static inline void | 1090 | static inline void |
1024 | perf_event_task_sched_in(struct task_struct *task) { } | 1091 | perf_event_task_sched_in(struct task_struct *task) { } |
1025 | static inline void | 1092 | static inline void |
1026 | perf_event_task_sched_out(struct task_struct *task, | 1093 | perf_event_task_sched_out(struct task_struct *task, |
1027 | struct task_struct *next) { } | 1094 | struct task_struct *next) { } |
1028 | static inline void | ||
1029 | perf_event_task_tick(struct task_struct *task) { } | ||
1030 | static inline int perf_event_init_task(struct task_struct *child) { return 0; } | 1095 | static inline int perf_event_init_task(struct task_struct *child) { return 0; } |
1031 | static inline void perf_event_exit_task(struct task_struct *child) { } | 1096 | static inline void perf_event_exit_task(struct task_struct *child) { } |
1032 | static inline void perf_event_free_task(struct task_struct *task) { } | 1097 | static inline void perf_event_free_task(struct task_struct *task) { } |
1033 | static inline void perf_event_do_pending(void) { } | 1098 | static inline void perf_event_delayed_put(struct task_struct *task) { } |
1034 | static inline void perf_event_print_debug(void) { } | 1099 | static inline void perf_event_print_debug(void) { } |
1035 | static inline void perf_disable(void) { } | ||
1036 | static inline void perf_enable(void) { } | ||
1037 | static inline int perf_event_task_disable(void) { return -EINVAL; } | 1100 | static inline int perf_event_task_disable(void) { return -EINVAL; } |
1038 | static inline int perf_event_task_enable(void) { return -EINVAL; } | 1101 | static inline int perf_event_task_enable(void) { return -EINVAL; } |
1039 | 1102 | ||
@@ -1056,6 +1119,7 @@ static inline int perf_swevent_get_recursion_context(void) { return -1; } | |||
1056 | static inline void perf_swevent_put_recursion_context(int rctx) { } | 1119 | static inline void perf_swevent_put_recursion_context(int rctx) { } |
1057 | static inline void perf_event_enable(struct perf_event *event) { } | 1120 | static inline void perf_event_enable(struct perf_event *event) { } |
1058 | static inline void perf_event_disable(struct perf_event *event) { } | 1121 | static inline void perf_event_disable(struct perf_event *event) { } |
1122 | static inline void perf_event_task_tick(void) { } | ||
1059 | #endif | 1123 | #endif |
1060 | 1124 | ||
1061 | #define perf_output_put(handle, x) \ | 1125 | #define perf_output_put(handle, x) \ |