diff options
Diffstat (limited to 'arch/x86/kernel/cpu/perf_event.c')
-rw-r--r-- | arch/x86/kernel/cpu/perf_event.c | 269 |
1 files changed, 166 insertions, 103 deletions
diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c index 641ccb9dddb..db5bdc8addf 100644 --- a/arch/x86/kernel/cpu/perf_event.c +++ b/arch/x86/kernel/cpu/perf_event.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <linux/kdebug.h> | 21 | #include <linux/kdebug.h> |
22 | #include <linux/sched.h> | 22 | #include <linux/sched.h> |
23 | #include <linux/uaccess.h> | 23 | #include <linux/uaccess.h> |
24 | #include <linux/slab.h> | ||
24 | #include <linux/highmem.h> | 25 | #include <linux/highmem.h> |
25 | #include <linux/cpu.h> | 26 | #include <linux/cpu.h> |
26 | #include <linux/bitops.h> | 27 | #include <linux/bitops.h> |
@@ -28,6 +29,7 @@ | |||
28 | #include <asm/apic.h> | 29 | #include <asm/apic.h> |
29 | #include <asm/stacktrace.h> | 30 | #include <asm/stacktrace.h> |
30 | #include <asm/nmi.h> | 31 | #include <asm/nmi.h> |
32 | #include <asm/compat.h> | ||
31 | 33 | ||
32 | static u64 perf_event_mask __read_mostly; | 34 | static u64 perf_event_mask __read_mostly; |
33 | 35 | ||
@@ -73,10 +75,10 @@ struct debug_store { | |||
73 | struct event_constraint { | 75 | struct event_constraint { |
74 | union { | 76 | union { |
75 | unsigned long idxmsk[BITS_TO_LONGS(X86_PMC_IDX_MAX)]; | 77 | unsigned long idxmsk[BITS_TO_LONGS(X86_PMC_IDX_MAX)]; |
76 | u64 idxmsk64[1]; | 78 | u64 idxmsk64; |
77 | }; | 79 | }; |
78 | int code; | 80 | u64 code; |
79 | int cmask; | 81 | u64 cmask; |
80 | int weight; | 82 | int weight; |
81 | }; | 83 | }; |
82 | 84 | ||
@@ -103,7 +105,7 @@ struct cpu_hw_events { | |||
103 | }; | 105 | }; |
104 | 106 | ||
105 | #define __EVENT_CONSTRAINT(c, n, m, w) {\ | 107 | #define __EVENT_CONSTRAINT(c, n, m, w) {\ |
106 | { .idxmsk64[0] = (n) }, \ | 108 | { .idxmsk64 = (n) }, \ |
107 | .code = (c), \ | 109 | .code = (c), \ |
108 | .cmask = (m), \ | 110 | .cmask = (m), \ |
109 | .weight = (w), \ | 111 | .weight = (w), \ |
@@ -116,7 +118,7 @@ struct cpu_hw_events { | |||
116 | EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVTSEL_MASK) | 118 | EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVTSEL_MASK) |
117 | 119 | ||
118 | #define FIXED_EVENT_CONSTRAINT(c, n) \ | 120 | #define FIXED_EVENT_CONSTRAINT(c, n) \ |
119 | EVENT_CONSTRAINT(c, n, INTEL_ARCH_FIXED_MASK) | 121 | EVENT_CONSTRAINT(c, (1ULL << (32+n)), INTEL_ARCH_FIXED_MASK) |
120 | 122 | ||
121 | #define EVENT_CONSTRAINT_END \ | 123 | #define EVENT_CONSTRAINT_END \ |
122 | EVENT_CONSTRAINT(0, 0, 0) | 124 | EVENT_CONSTRAINT(0, 0, 0) |
@@ -133,8 +135,8 @@ struct x86_pmu { | |||
133 | int (*handle_irq)(struct pt_regs *); | 135 | int (*handle_irq)(struct pt_regs *); |
134 | void (*disable_all)(void); | 136 | void (*disable_all)(void); |
135 | void (*enable_all)(void); | 137 | void (*enable_all)(void); |
136 | void (*enable)(struct hw_perf_event *, int); | 138 | void (*enable)(struct perf_event *); |
137 | void (*disable)(struct hw_perf_event *, int); | 139 | void (*disable)(struct perf_event *); |
138 | unsigned eventsel; | 140 | unsigned eventsel; |
139 | unsigned perfctr; | 141 | unsigned perfctr; |
140 | u64 (*event_map)(int); | 142 | u64 (*event_map)(int); |
@@ -157,6 +159,11 @@ struct x86_pmu { | |||
157 | void (*put_event_constraints)(struct cpu_hw_events *cpuc, | 159 | void (*put_event_constraints)(struct cpu_hw_events *cpuc, |
158 | struct perf_event *event); | 160 | struct perf_event *event); |
159 | struct event_constraint *event_constraints; | 161 | struct event_constraint *event_constraints; |
162 | |||
163 | int (*cpu_prepare)(int cpu); | ||
164 | void (*cpu_starting)(int cpu); | ||
165 | void (*cpu_dying)(int cpu); | ||
166 | void (*cpu_dead)(int cpu); | ||
160 | }; | 167 | }; |
161 | 168 | ||
162 | static struct x86_pmu x86_pmu __read_mostly; | 169 | static struct x86_pmu x86_pmu __read_mostly; |
@@ -165,8 +172,7 @@ static DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events) = { | |||
165 | .enabled = 1, | 172 | .enabled = 1, |
166 | }; | 173 | }; |
167 | 174 | ||
168 | static int x86_perf_event_set_period(struct perf_event *event, | 175 | static int x86_perf_event_set_period(struct perf_event *event); |
169 | struct hw_perf_event *hwc, int idx); | ||
170 | 176 | ||
171 | /* | 177 | /* |
172 | * Generalized hw caching related hw_event table, filled | 178 | * Generalized hw caching related hw_event table, filled |
@@ -189,11 +195,12 @@ static u64 __read_mostly hw_cache_event_ids | |||
189 | * Returns the delta events processed. | 195 | * Returns the delta events processed. |
190 | */ | 196 | */ |
191 | static u64 | 197 | static u64 |
192 | x86_perf_event_update(struct perf_event *event, | 198 | x86_perf_event_update(struct perf_event *event) |
193 | struct hw_perf_event *hwc, int idx) | ||
194 | { | 199 | { |
200 | struct hw_perf_event *hwc = &event->hw; | ||
195 | int shift = 64 - x86_pmu.event_bits; | 201 | int shift = 64 - x86_pmu.event_bits; |
196 | u64 prev_raw_count, new_raw_count; | 202 | u64 prev_raw_count, new_raw_count; |
203 | int idx = hwc->idx; | ||
197 | s64 delta; | 204 | s64 delta; |
198 | 205 | ||
199 | if (idx == X86_PMC_IDX_FIXED_BTS) | 206 | if (idx == X86_PMC_IDX_FIXED_BTS) |
@@ -293,7 +300,7 @@ static inline bool bts_available(void) | |||
293 | return x86_pmu.enable_bts != NULL; | 300 | return x86_pmu.enable_bts != NULL; |
294 | } | 301 | } |
295 | 302 | ||
296 | static inline void init_debug_store_on_cpu(int cpu) | 303 | static void init_debug_store_on_cpu(int cpu) |
297 | { | 304 | { |
298 | struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds; | 305 | struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds; |
299 | 306 | ||
@@ -305,7 +312,7 @@ static inline void init_debug_store_on_cpu(int cpu) | |||
305 | (u32)((u64)(unsigned long)ds >> 32)); | 312 | (u32)((u64)(unsigned long)ds >> 32)); |
306 | } | 313 | } |
307 | 314 | ||
308 | static inline void fini_debug_store_on_cpu(int cpu) | 315 | static void fini_debug_store_on_cpu(int cpu) |
309 | { | 316 | { |
310 | if (!per_cpu(cpu_hw_events, cpu).ds) | 317 | if (!per_cpu(cpu_hw_events, cpu).ds) |
311 | return; | 318 | return; |
@@ -503,6 +510,9 @@ static int __hw_perf_event_init(struct perf_event *event) | |||
503 | */ | 510 | */ |
504 | if (attr->type == PERF_TYPE_RAW) { | 511 | if (attr->type == PERF_TYPE_RAW) { |
505 | hwc->config |= x86_pmu.raw_event(attr->config); | 512 | hwc->config |= x86_pmu.raw_event(attr->config); |
513 | if ((hwc->config & ARCH_PERFMON_EVENTSEL_ANY) && | ||
514 | perf_paranoid_cpu() && !capable(CAP_SYS_ADMIN)) | ||
515 | return -EACCES; | ||
506 | return 0; | 516 | return 0; |
507 | } | 517 | } |
508 | 518 | ||
@@ -553,9 +563,9 @@ static void x86_pmu_disable_all(void) | |||
553 | if (!test_bit(idx, cpuc->active_mask)) | 563 | if (!test_bit(idx, cpuc->active_mask)) |
554 | continue; | 564 | continue; |
555 | rdmsrl(x86_pmu.eventsel + idx, val); | 565 | rdmsrl(x86_pmu.eventsel + idx, val); |
556 | if (!(val & ARCH_PERFMON_EVENTSEL0_ENABLE)) | 566 | if (!(val & ARCH_PERFMON_EVENTSEL_ENABLE)) |
557 | continue; | 567 | continue; |
558 | val &= ~ARCH_PERFMON_EVENTSEL0_ENABLE; | 568 | val &= ~ARCH_PERFMON_EVENTSEL_ENABLE; |
559 | wrmsrl(x86_pmu.eventsel + idx, val); | 569 | wrmsrl(x86_pmu.eventsel + idx, val); |
560 | } | 570 | } |
561 | } | 571 | } |
@@ -590,7 +600,7 @@ static void x86_pmu_enable_all(void) | |||
590 | continue; | 600 | continue; |
591 | 601 | ||
592 | val = event->hw.config; | 602 | val = event->hw.config; |
593 | val |= ARCH_PERFMON_EVENTSEL0_ENABLE; | 603 | val |= ARCH_PERFMON_EVENTSEL_ENABLE; |
594 | wrmsrl(x86_pmu.eventsel + idx, val); | 604 | wrmsrl(x86_pmu.eventsel + idx, val); |
595 | } | 605 | } |
596 | } | 606 | } |
@@ -612,8 +622,8 @@ static int x86_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign) | |||
612 | bitmap_zero(used_mask, X86_PMC_IDX_MAX); | 622 | bitmap_zero(used_mask, X86_PMC_IDX_MAX); |
613 | 623 | ||
614 | for (i = 0; i < n; i++) { | 624 | for (i = 0; i < n; i++) { |
615 | constraints[i] = | 625 | c = x86_pmu.get_event_constraints(cpuc, cpuc->event_list[i]); |
616 | x86_pmu.get_event_constraints(cpuc, cpuc->event_list[i]); | 626 | constraints[i] = c; |
617 | } | 627 | } |
618 | 628 | ||
619 | /* | 629 | /* |
@@ -635,7 +645,7 @@ static int x86_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign) | |||
635 | if (test_bit(hwc->idx, used_mask)) | 645 | if (test_bit(hwc->idx, used_mask)) |
636 | break; | 646 | break; |
637 | 647 | ||
638 | set_bit(hwc->idx, used_mask); | 648 | __set_bit(hwc->idx, used_mask); |
639 | if (assign) | 649 | if (assign) |
640 | assign[i] = hwc->idx; | 650 | assign[i] = hwc->idx; |
641 | } | 651 | } |
@@ -676,7 +686,7 @@ static int x86_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign) | |||
676 | if (c->weight != w) | 686 | if (c->weight != w) |
677 | continue; | 687 | continue; |
678 | 688 | ||
679 | for_each_bit(j, c->idxmsk, X86_PMC_IDX_MAX) { | 689 | for_each_set_bit(j, c->idxmsk, X86_PMC_IDX_MAX) { |
680 | if (!test_bit(j, used_mask)) | 690 | if (!test_bit(j, used_mask)) |
681 | break; | 691 | break; |
682 | } | 692 | } |
@@ -684,7 +694,7 @@ static int x86_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign) | |||
684 | if (j == X86_PMC_IDX_MAX) | 694 | if (j == X86_PMC_IDX_MAX) |
685 | break; | 695 | break; |
686 | 696 | ||
687 | set_bit(j, used_mask); | 697 | __set_bit(j, used_mask); |
688 | 698 | ||
689 | if (assign) | 699 | if (assign) |
690 | assign[i] = j; | 700 | assign[i] = j; |
@@ -777,6 +787,7 @@ static inline int match_prev_assignment(struct hw_perf_event *hwc, | |||
777 | hwc->last_tag == cpuc->tags[i]; | 787 | hwc->last_tag == cpuc->tags[i]; |
778 | } | 788 | } |
779 | 789 | ||
790 | static int x86_pmu_start(struct perf_event *event); | ||
780 | static void x86_pmu_stop(struct perf_event *event); | 791 | static void x86_pmu_stop(struct perf_event *event); |
781 | 792 | ||
782 | void hw_perf_enable(void) | 793 | void hw_perf_enable(void) |
@@ -793,6 +804,7 @@ void hw_perf_enable(void) | |||
793 | return; | 804 | return; |
794 | 805 | ||
795 | if (cpuc->n_added) { | 806 | if (cpuc->n_added) { |
807 | int n_running = cpuc->n_events - cpuc->n_added; | ||
796 | /* | 808 | /* |
797 | * apply assignment obtained either from | 809 | * apply assignment obtained either from |
798 | * hw_perf_group_sched_in() or x86_pmu_enable() | 810 | * hw_perf_group_sched_in() or x86_pmu_enable() |
@@ -800,8 +812,7 @@ void hw_perf_enable(void) | |||
800 | * step1: save events moving to new counters | 812 | * step1: save events moving to new counters |
801 | * step2: reprogram moved events into new counters | 813 | * step2: reprogram moved events into new counters |
802 | */ | 814 | */ |
803 | for (i = 0; i < cpuc->n_events; i++) { | 815 | for (i = 0; i < n_running; i++) { |
804 | |||
805 | event = cpuc->event_list[i]; | 816 | event = cpuc->event_list[i]; |
806 | hwc = &event->hw; | 817 | hwc = &event->hw; |
807 | 818 | ||
@@ -816,29 +827,18 @@ void hw_perf_enable(void) | |||
816 | continue; | 827 | continue; |
817 | 828 | ||
818 | x86_pmu_stop(event); | 829 | x86_pmu_stop(event); |
819 | |||
820 | hwc->idx = -1; | ||
821 | } | 830 | } |
822 | 831 | ||
823 | for (i = 0; i < cpuc->n_events; i++) { | 832 | for (i = 0; i < cpuc->n_events; i++) { |
824 | |||
825 | event = cpuc->event_list[i]; | 833 | event = cpuc->event_list[i]; |
826 | hwc = &event->hw; | 834 | hwc = &event->hw; |
827 | 835 | ||
828 | if (hwc->idx == -1) { | 836 | if (!match_prev_assignment(hwc, cpuc, i)) |
829 | x86_assign_hw_event(event, cpuc, i); | 837 | x86_assign_hw_event(event, cpuc, i); |
830 | x86_perf_event_set_period(event, hwc, hwc->idx); | 838 | else if (i < n_running) |
831 | } | 839 | continue; |
832 | /* | ||
833 | * need to mark as active because x86_pmu_disable() | ||
834 | * clear active_mask and events[] yet it preserves | ||
835 | * idx | ||
836 | */ | ||
837 | set_bit(hwc->idx, cpuc->active_mask); | ||
838 | cpuc->events[hwc->idx] = event; | ||
839 | 840 | ||
840 | x86_pmu.enable(hwc, hwc->idx); | 841 | x86_pmu_start(event); |
841 | perf_event_update_userpage(event); | ||
842 | } | 842 | } |
843 | cpuc->n_added = 0; | 843 | cpuc->n_added = 0; |
844 | perf_events_lapic_init(); | 844 | perf_events_lapic_init(); |
@@ -850,15 +850,16 @@ void hw_perf_enable(void) | |||
850 | x86_pmu.enable_all(); | 850 | x86_pmu.enable_all(); |
851 | } | 851 | } |
852 | 852 | ||
853 | static inline void __x86_pmu_enable_event(struct hw_perf_event *hwc, int idx) | 853 | static inline void __x86_pmu_enable_event(struct hw_perf_event *hwc) |
854 | { | 854 | { |
855 | (void)checking_wrmsrl(hwc->config_base + idx, | 855 | (void)checking_wrmsrl(hwc->config_base + hwc->idx, |
856 | hwc->config | ARCH_PERFMON_EVENTSEL0_ENABLE); | 856 | hwc->config | ARCH_PERFMON_EVENTSEL_ENABLE); |
857 | } | 857 | } |
858 | 858 | ||
859 | static inline void x86_pmu_disable_event(struct hw_perf_event *hwc, int idx) | 859 | static inline void x86_pmu_disable_event(struct perf_event *event) |
860 | { | 860 | { |
861 | (void)checking_wrmsrl(hwc->config_base + idx, hwc->config); | 861 | struct hw_perf_event *hwc = &event->hw; |
862 | (void)checking_wrmsrl(hwc->config_base + hwc->idx, hwc->config); | ||
862 | } | 863 | } |
863 | 864 | ||
864 | static DEFINE_PER_CPU(u64 [X86_PMC_IDX_MAX], pmc_prev_left); | 865 | static DEFINE_PER_CPU(u64 [X86_PMC_IDX_MAX], pmc_prev_left); |
@@ -868,12 +869,12 @@ static DEFINE_PER_CPU(u64 [X86_PMC_IDX_MAX], pmc_prev_left); | |||
868 | * To be called with the event disabled in hw: | 869 | * To be called with the event disabled in hw: |
869 | */ | 870 | */ |
870 | static int | 871 | static int |
871 | x86_perf_event_set_period(struct perf_event *event, | 872 | x86_perf_event_set_period(struct perf_event *event) |
872 | struct hw_perf_event *hwc, int idx) | ||
873 | { | 873 | { |
874 | struct hw_perf_event *hwc = &event->hw; | ||
874 | s64 left = atomic64_read(&hwc->period_left); | 875 | s64 left = atomic64_read(&hwc->period_left); |
875 | s64 period = hwc->sample_period; | 876 | s64 period = hwc->sample_period; |
876 | int err, ret = 0; | 877 | int err, ret = 0, idx = hwc->idx; |
877 | 878 | ||
878 | if (idx == X86_PMC_IDX_FIXED_BTS) | 879 | if (idx == X86_PMC_IDX_FIXED_BTS) |
879 | return 0; | 880 | return 0; |
@@ -919,11 +920,11 @@ x86_perf_event_set_period(struct perf_event *event, | |||
919 | return ret; | 920 | return ret; |
920 | } | 921 | } |
921 | 922 | ||
922 | static void x86_pmu_enable_event(struct hw_perf_event *hwc, int idx) | 923 | static void x86_pmu_enable_event(struct perf_event *event) |
923 | { | 924 | { |
924 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | 925 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); |
925 | if (cpuc->enabled) | 926 | if (cpuc->enabled) |
926 | __x86_pmu_enable_event(hwc, idx); | 927 | __x86_pmu_enable_event(&event->hw); |
927 | } | 928 | } |
928 | 929 | ||
929 | /* | 930 | /* |
@@ -959,34 +960,32 @@ static int x86_pmu_enable(struct perf_event *event) | |||
959 | memcpy(cpuc->assign, assign, n*sizeof(int)); | 960 | memcpy(cpuc->assign, assign, n*sizeof(int)); |
960 | 961 | ||
961 | cpuc->n_events = n; | 962 | cpuc->n_events = n; |
962 | cpuc->n_added = n - n0; | 963 | cpuc->n_added += n - n0; |
963 | 964 | ||
964 | return 0; | 965 | return 0; |
965 | } | 966 | } |
966 | 967 | ||
967 | static int x86_pmu_start(struct perf_event *event) | 968 | static int x86_pmu_start(struct perf_event *event) |
968 | { | 969 | { |
969 | struct hw_perf_event *hwc = &event->hw; | 970 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); |
971 | int idx = event->hw.idx; | ||
970 | 972 | ||
971 | if (hwc->idx == -1) | 973 | if (idx == -1) |
972 | return -EAGAIN; | 974 | return -EAGAIN; |
973 | 975 | ||
974 | x86_perf_event_set_period(event, hwc, hwc->idx); | 976 | x86_perf_event_set_period(event); |
975 | x86_pmu.enable(hwc, hwc->idx); | 977 | cpuc->events[idx] = event; |
978 | __set_bit(idx, cpuc->active_mask); | ||
979 | x86_pmu.enable(event); | ||
980 | perf_event_update_userpage(event); | ||
976 | 981 | ||
977 | return 0; | 982 | return 0; |
978 | } | 983 | } |
979 | 984 | ||
980 | static void x86_pmu_unthrottle(struct perf_event *event) | 985 | static void x86_pmu_unthrottle(struct perf_event *event) |
981 | { | 986 | { |
982 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | 987 | int ret = x86_pmu_start(event); |
983 | struct hw_perf_event *hwc = &event->hw; | 988 | WARN_ON_ONCE(ret); |
984 | |||
985 | if (WARN_ON_ONCE(hwc->idx >= X86_PMC_IDX_MAX || | ||
986 | cpuc->events[hwc->idx] != event)) | ||
987 | return; | ||
988 | |||
989 | x86_pmu.enable(hwc, hwc->idx); | ||
990 | } | 989 | } |
991 | 990 | ||
992 | void perf_event_print_debug(void) | 991 | void perf_event_print_debug(void) |
@@ -1046,18 +1045,16 @@ static void x86_pmu_stop(struct perf_event *event) | |||
1046 | struct hw_perf_event *hwc = &event->hw; | 1045 | struct hw_perf_event *hwc = &event->hw; |
1047 | int idx = hwc->idx; | 1046 | int idx = hwc->idx; |
1048 | 1047 | ||
1049 | /* | 1048 | if (!__test_and_clear_bit(idx, cpuc->active_mask)) |
1050 | * Must be done before we disable, otherwise the nmi handler | 1049 | return; |
1051 | * could reenable again: | 1050 | |
1052 | */ | 1051 | x86_pmu.disable(event); |
1053 | clear_bit(idx, cpuc->active_mask); | ||
1054 | x86_pmu.disable(hwc, idx); | ||
1055 | 1052 | ||
1056 | /* | 1053 | /* |
1057 | * Drain the remaining delta count out of a event | 1054 | * Drain the remaining delta count out of a event |
1058 | * that we are disabling: | 1055 | * that we are disabling: |
1059 | */ | 1056 | */ |
1060 | x86_perf_event_update(event, hwc, idx); | 1057 | x86_perf_event_update(event); |
1061 | 1058 | ||
1062 | cpuc->events[idx] = NULL; | 1059 | cpuc->events[idx] = NULL; |
1063 | } | 1060 | } |
@@ -1094,8 +1091,7 @@ static int x86_pmu_handle_irq(struct pt_regs *regs) | |||
1094 | int idx, handled = 0; | 1091 | int idx, handled = 0; |
1095 | u64 val; | 1092 | u64 val; |
1096 | 1093 | ||
1097 | data.addr = 0; | 1094 | perf_sample_data_init(&data, 0); |
1098 | data.raw = NULL; | ||
1099 | 1095 | ||
1100 | cpuc = &__get_cpu_var(cpu_hw_events); | 1096 | cpuc = &__get_cpu_var(cpu_hw_events); |
1101 | 1097 | ||
@@ -1106,7 +1102,7 @@ static int x86_pmu_handle_irq(struct pt_regs *regs) | |||
1106 | event = cpuc->events[idx]; | 1102 | event = cpuc->events[idx]; |
1107 | hwc = &event->hw; | 1103 | hwc = &event->hw; |
1108 | 1104 | ||
1109 | val = x86_perf_event_update(event, hwc, idx); | 1105 | val = x86_perf_event_update(event); |
1110 | if (val & (1ULL << (x86_pmu.event_bits - 1))) | 1106 | if (val & (1ULL << (x86_pmu.event_bits - 1))) |
1111 | continue; | 1107 | continue; |
1112 | 1108 | ||
@@ -1116,11 +1112,11 @@ static int x86_pmu_handle_irq(struct pt_regs *regs) | |||
1116 | handled = 1; | 1112 | handled = 1; |
1117 | data.period = event->hw.last_period; | 1113 | data.period = event->hw.last_period; |
1118 | 1114 | ||
1119 | if (!x86_perf_event_set_period(event, hwc, idx)) | 1115 | if (!x86_perf_event_set_period(event)) |
1120 | continue; | 1116 | continue; |
1121 | 1117 | ||
1122 | if (perf_event_overflow(event, 1, &data, regs)) | 1118 | if (perf_event_overflow(event, 1, &data, regs)) |
1123 | x86_pmu.disable(hwc, idx); | 1119 | x86_pmu_stop(event); |
1124 | } | 1120 | } |
1125 | 1121 | ||
1126 | if (handled) | 1122 | if (handled) |
@@ -1307,7 +1303,7 @@ int hw_perf_group_sched_in(struct perf_event *leader, | |||
1307 | memcpy(cpuc->assign, assign, n0*sizeof(int)); | 1303 | memcpy(cpuc->assign, assign, n0*sizeof(int)); |
1308 | 1304 | ||
1309 | cpuc->n_events = n0; | 1305 | cpuc->n_events = n0; |
1310 | cpuc->n_added = n1; | 1306 | cpuc->n_added += n1; |
1311 | ctx->nr_active += n1; | 1307 | ctx->nr_active += n1; |
1312 | 1308 | ||
1313 | /* | 1309 | /* |
@@ -1335,6 +1331,41 @@ undo: | |||
1335 | #include "perf_event_p6.c" | 1331 | #include "perf_event_p6.c" |
1336 | #include "perf_event_intel.c" | 1332 | #include "perf_event_intel.c" |
1337 | 1333 | ||
1334 | static int __cpuinit | ||
1335 | x86_pmu_notifier(struct notifier_block *self, unsigned long action, void *hcpu) | ||
1336 | { | ||
1337 | unsigned int cpu = (long)hcpu; | ||
1338 | int ret = NOTIFY_OK; | ||
1339 | |||
1340 | switch (action & ~CPU_TASKS_FROZEN) { | ||
1341 | case CPU_UP_PREPARE: | ||
1342 | if (x86_pmu.cpu_prepare) | ||
1343 | ret = x86_pmu.cpu_prepare(cpu); | ||
1344 | break; | ||
1345 | |||
1346 | case CPU_STARTING: | ||
1347 | if (x86_pmu.cpu_starting) | ||
1348 | x86_pmu.cpu_starting(cpu); | ||
1349 | break; | ||
1350 | |||
1351 | case CPU_DYING: | ||
1352 | if (x86_pmu.cpu_dying) | ||
1353 | x86_pmu.cpu_dying(cpu); | ||
1354 | break; | ||
1355 | |||
1356 | case CPU_UP_CANCELED: | ||
1357 | case CPU_DEAD: | ||
1358 | if (x86_pmu.cpu_dead) | ||
1359 | x86_pmu.cpu_dead(cpu); | ||
1360 | break; | ||
1361 | |||
1362 | default: | ||
1363 | break; | ||
1364 | } | ||
1365 | |||
1366 | return ret; | ||
1367 | } | ||
1368 | |||
1338 | static void __init pmu_check_apic(void) | 1369 | static void __init pmu_check_apic(void) |
1339 | { | 1370 | { |
1340 | if (cpu_has_apic) | 1371 | if (cpu_has_apic) |
@@ -1347,6 +1378,7 @@ static void __init pmu_check_apic(void) | |||
1347 | 1378 | ||
1348 | void __init init_hw_perf_events(void) | 1379 | void __init init_hw_perf_events(void) |
1349 | { | 1380 | { |
1381 | struct event_constraint *c; | ||
1350 | int err; | 1382 | int err; |
1351 | 1383 | ||
1352 | pr_info("Performance Events: "); | 1384 | pr_info("Performance Events: "); |
@@ -1395,6 +1427,16 @@ void __init init_hw_perf_events(void) | |||
1395 | __EVENT_CONSTRAINT(0, (1ULL << x86_pmu.num_events) - 1, | 1427 | __EVENT_CONSTRAINT(0, (1ULL << x86_pmu.num_events) - 1, |
1396 | 0, x86_pmu.num_events); | 1428 | 0, x86_pmu.num_events); |
1397 | 1429 | ||
1430 | if (x86_pmu.event_constraints) { | ||
1431 | for_each_event_constraint(c, x86_pmu.event_constraints) { | ||
1432 | if (c->cmask != INTEL_ARCH_FIXED_MASK) | ||
1433 | continue; | ||
1434 | |||
1435 | c->idxmsk64 |= (1ULL << x86_pmu.num_events) - 1; | ||
1436 | c->weight += x86_pmu.num_events; | ||
1437 | } | ||
1438 | } | ||
1439 | |||
1398 | pr_info("... version: %d\n", x86_pmu.version); | 1440 | pr_info("... version: %d\n", x86_pmu.version); |
1399 | pr_info("... bit width: %d\n", x86_pmu.event_bits); | 1441 | pr_info("... bit width: %d\n", x86_pmu.event_bits); |
1400 | pr_info("... generic registers: %d\n", x86_pmu.num_events); | 1442 | pr_info("... generic registers: %d\n", x86_pmu.num_events); |
@@ -1402,11 +1444,13 @@ void __init init_hw_perf_events(void) | |||
1402 | pr_info("... max period: %016Lx\n", x86_pmu.max_period); | 1444 | pr_info("... max period: %016Lx\n", x86_pmu.max_period); |
1403 | pr_info("... fixed-purpose events: %d\n", x86_pmu.num_events_fixed); | 1445 | pr_info("... fixed-purpose events: %d\n", x86_pmu.num_events_fixed); |
1404 | pr_info("... event mask: %016Lx\n", perf_event_mask); | 1446 | pr_info("... event mask: %016Lx\n", perf_event_mask); |
1447 | |||
1448 | perf_cpu_notifier(x86_pmu_notifier); | ||
1405 | } | 1449 | } |
1406 | 1450 | ||
1407 | static inline void x86_pmu_read(struct perf_event *event) | 1451 | static inline void x86_pmu_read(struct perf_event *event) |
1408 | { | 1452 | { |
1409 | x86_perf_event_update(event, &event->hw, event->hw.idx); | 1453 | x86_perf_event_update(event); |
1410 | } | 1454 | } |
1411 | 1455 | ||
1412 | static const struct pmu pmu = { | 1456 | static const struct pmu pmu = { |
@@ -1588,14 +1632,42 @@ copy_from_user_nmi(void *to, const void __user *from, unsigned long n) | |||
1588 | return len; | 1632 | return len; |
1589 | } | 1633 | } |
1590 | 1634 | ||
1591 | static int copy_stack_frame(const void __user *fp, struct stack_frame *frame) | 1635 | #ifdef CONFIG_COMPAT |
1636 | static inline int | ||
1637 | perf_callchain_user32(struct pt_regs *regs, struct perf_callchain_entry *entry) | ||
1592 | { | 1638 | { |
1593 | unsigned long bytes; | 1639 | /* 32-bit process in 64-bit kernel. */ |
1640 | struct stack_frame_ia32 frame; | ||
1641 | const void __user *fp; | ||
1594 | 1642 | ||
1595 | bytes = copy_from_user_nmi(frame, fp, sizeof(*frame)); | 1643 | if (!test_thread_flag(TIF_IA32)) |
1644 | return 0; | ||
1596 | 1645 | ||
1597 | return bytes == sizeof(*frame); | 1646 | fp = compat_ptr(regs->bp); |
1647 | while (entry->nr < PERF_MAX_STACK_DEPTH) { | ||
1648 | unsigned long bytes; | ||
1649 | frame.next_frame = 0; | ||
1650 | frame.return_address = 0; | ||
1651 | |||
1652 | bytes = copy_from_user_nmi(&frame, fp, sizeof(frame)); | ||
1653 | if (bytes != sizeof(frame)) | ||
1654 | break; | ||
1655 | |||
1656 | if (fp < compat_ptr(regs->sp)) | ||
1657 | break; | ||
1658 | |||
1659 | callchain_store(entry, frame.return_address); | ||
1660 | fp = compat_ptr(frame.next_frame); | ||
1661 | } | ||
1662 | return 1; | ||
1663 | } | ||
1664 | #else | ||
1665 | static inline int | ||
1666 | perf_callchain_user32(struct pt_regs *regs, struct perf_callchain_entry *entry) | ||
1667 | { | ||
1668 | return 0; | ||
1598 | } | 1669 | } |
1670 | #endif | ||
1599 | 1671 | ||
1600 | static void | 1672 | static void |
1601 | perf_callchain_user(struct pt_regs *regs, struct perf_callchain_entry *entry) | 1673 | perf_callchain_user(struct pt_regs *regs, struct perf_callchain_entry *entry) |
@@ -1611,11 +1683,16 @@ perf_callchain_user(struct pt_regs *regs, struct perf_callchain_entry *entry) | |||
1611 | callchain_store(entry, PERF_CONTEXT_USER); | 1683 | callchain_store(entry, PERF_CONTEXT_USER); |
1612 | callchain_store(entry, regs->ip); | 1684 | callchain_store(entry, regs->ip); |
1613 | 1685 | ||
1686 | if (perf_callchain_user32(regs, entry)) | ||
1687 | return; | ||
1688 | |||
1614 | while (entry->nr < PERF_MAX_STACK_DEPTH) { | 1689 | while (entry->nr < PERF_MAX_STACK_DEPTH) { |
1690 | unsigned long bytes; | ||
1615 | frame.next_frame = NULL; | 1691 | frame.next_frame = NULL; |
1616 | frame.return_address = 0; | 1692 | frame.return_address = 0; |
1617 | 1693 | ||
1618 | if (!copy_stack_frame(fp, &frame)) | 1694 | bytes = copy_from_user_nmi(&frame, fp, sizeof(frame)); |
1695 | if (bytes != sizeof(frame)) | ||
1619 | break; | 1696 | break; |
1620 | 1697 | ||
1621 | if ((unsigned long)fp < regs->sp) | 1698 | if ((unsigned long)fp < regs->sp) |
@@ -1662,28 +1739,14 @@ struct perf_callchain_entry *perf_callchain(struct pt_regs *regs) | |||
1662 | return entry; | 1739 | return entry; |
1663 | } | 1740 | } |
1664 | 1741 | ||
1665 | void hw_perf_event_setup_online(int cpu) | 1742 | void perf_arch_fetch_caller_regs(struct pt_regs *regs, unsigned long ip, int skip) |
1666 | { | ||
1667 | init_debug_store_on_cpu(cpu); | ||
1668 | |||
1669 | switch (boot_cpu_data.x86_vendor) { | ||
1670 | case X86_VENDOR_AMD: | ||
1671 | amd_pmu_cpu_online(cpu); | ||
1672 | break; | ||
1673 | default: | ||
1674 | return; | ||
1675 | } | ||
1676 | } | ||
1677 | |||
1678 | void hw_perf_event_setup_offline(int cpu) | ||
1679 | { | 1743 | { |
1680 | init_debug_store_on_cpu(cpu); | 1744 | regs->ip = ip; |
1681 | 1745 | /* | |
1682 | switch (boot_cpu_data.x86_vendor) { | 1746 | * perf_arch_fetch_caller_regs adds another call, we need to increment |
1683 | case X86_VENDOR_AMD: | 1747 | * the skip level |
1684 | amd_pmu_cpu_offline(cpu); | 1748 | */ |
1685 | break; | 1749 | regs->bp = rewind_frame_pointer(skip + 1); |
1686 | default: | 1750 | regs->cs = __KERNEL_CS; |
1687 | return; | 1751 | local_save_flags(regs->flags); |
1688 | } | ||
1689 | } | 1752 | } |