]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - arch/x86/kernel/cpu/perf_event_intel_ds.c
perf: Rework the PMU methods
[mv-sheeva.git] / arch / x86 / kernel / cpu / perf_event_intel_ds.c
index c59678a14a2e549fb5b0b79daa223d447a43d378..9893a2f77b7ad56ff9736fe7dad1bfa5c98116df 100644 (file)
@@ -37,15 +37,6 @@ struct pebs_record_nhm {
        u64 status, dla, dse, lat;
 };
 
-/*
- * Bits in the debugctlmsr controlling branch tracing.
- */
-#define X86_DEBUGCTL_TR                        (1 << 6)
-#define X86_DEBUGCTL_BTS               (1 << 7)
-#define X86_DEBUGCTL_BTINT             (1 << 8)
-#define X86_DEBUGCTL_BTS_OFF_OS                (1 << 9)
-#define X86_DEBUGCTL_BTS_OFF_USR       (1 << 10)
-
 /*
  * A debug store configuration.
  *
@@ -193,15 +184,15 @@ static void intel_pmu_enable_bts(u64 config)
 
        debugctlmsr = get_debugctlmsr();
 
-       debugctlmsr |= X86_DEBUGCTL_TR;
-       debugctlmsr |= X86_DEBUGCTL_BTS;
-       debugctlmsr |= X86_DEBUGCTL_BTINT;
+       debugctlmsr |= DEBUGCTLMSR_TR;
+       debugctlmsr |= DEBUGCTLMSR_BTS;
+       debugctlmsr |= DEBUGCTLMSR_BTINT;
 
        if (!(config & ARCH_PERFMON_EVENTSEL_OS))
-               debugctlmsr |= X86_DEBUGCTL_BTS_OFF_OS;
+               debugctlmsr |= DEBUGCTLMSR_BTS_OFF_OS;
 
        if (!(config & ARCH_PERFMON_EVENTSEL_USR))
-               debugctlmsr |= X86_DEBUGCTL_BTS_OFF_USR;
+               debugctlmsr |= DEBUGCTLMSR_BTS_OFF_USR;
 
        update_debugctlmsr(debugctlmsr);
 }
@@ -217,8 +208,8 @@ static void intel_pmu_disable_bts(void)
        debugctlmsr = get_debugctlmsr();
 
        debugctlmsr &=
-               ~(X86_DEBUGCTL_TR | X86_DEBUGCTL_BTS | X86_DEBUGCTL_BTINT |
-                 X86_DEBUGCTL_BTS_OFF_OS | X86_DEBUGCTL_BTS_OFF_USR);
+               ~(DEBUGCTLMSR_TR | DEBUGCTLMSR_BTS | DEBUGCTLMSR_BTINT |
+                 DEBUGCTLMSR_BTS_OFF_OS | DEBUGCTLMSR_BTS_OFF_USR);
 
        update_debugctlmsr(debugctlmsr);
 }
@@ -316,7 +307,7 @@ intel_pebs_constraints(struct perf_event *event)
 {
        struct event_constraint *c;
 
-       if (!event->attr.precise)
+       if (!event->attr.precise_ip)
                return NULL;
 
        if (x86_pmu.pebs_constraints) {
@@ -339,7 +330,7 @@ static void intel_pmu_pebs_enable(struct perf_event *event)
        cpuc->pebs_enabled |= 1ULL << hwc->idx;
        WARN_ON_ONCE(cpuc->enabled);
 
-       if (x86_pmu.intel_cap.pebs_trap)
+       if (x86_pmu.intel_cap.pebs_trap && event->attr.precise_ip > 1)
                intel_pmu_lbr_enable(event);
 }
 
@@ -354,7 +345,7 @@ static void intel_pmu_pebs_disable(struct perf_event *event)
 
        hwc->config |= ARCH_PERFMON_EVENTSEL_INT;
 
-       if (x86_pmu.intel_cap.pebs_trap)
+       if (x86_pmu.intel_cap.pebs_trap && event->attr.precise_ip > 1)
                intel_pmu_lbr_disable(event);
 }
 
@@ -461,15 +452,54 @@ static int intel_pmu_pebs_fixup_ip(struct pt_regs *regs)
 
 static int intel_pmu_save_and_restart(struct perf_event *event);
 
+static void __intel_pmu_pebs_event(struct perf_event *event,
+                                  struct pt_regs *iregs, void *__pebs)
+{
+       /*
+        * We cast to pebs_record_core since that is a subset of
+        * both formats and we don't use the other fields in this
+        * routine.
+        */
+       struct pebs_record_core *pebs = __pebs;
+       struct perf_sample_data data;
+       struct pt_regs regs;
+
+       if (!intel_pmu_save_and_restart(event))
+               return;
+
+       perf_sample_data_init(&data, 0);
+       data.period = event->hw.last_period;
+
+       /*
+        * We use the interrupt regs as a base because the PEBS record
+        * does not contain a full regs set, specifically it seems to
+        * lack segment descriptors, which get used by things like
+        * user_mode().
+        *
+        * In the simple case fix up only the IP and BP,SP regs, for
+        * PERF_SAMPLE_IP and PERF_SAMPLE_CALLCHAIN to function properly.
+        * A possible PERF_SAMPLE_REGS will have to transfer all regs.
+        */
+       regs = *iregs;
+       regs.ip = pebs->ip;
+       regs.bp = pebs->bp;
+       regs.sp = pebs->sp;
+
+       if (event->attr.precise_ip > 1 && intel_pmu_pebs_fixup_ip(&regs))
+               regs.flags |= PERF_EFLAGS_EXACT;
+       else
+               regs.flags &= ~PERF_EFLAGS_EXACT;
+
+       if (perf_event_overflow(event, 1, &data, &regs))
+               x86_pmu_stop(event, 0);
+}
+
 static void intel_pmu_drain_pebs_core(struct pt_regs *iregs)
 {
        struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
        struct debug_store *ds = cpuc->ds;
        struct perf_event *event = cpuc->events[0]; /* PMC0 only */
        struct pebs_record_core *at, *top;
-       struct perf_sample_data data;
-       struct perf_raw_record raw;
-       struct pt_regs regs;
        int n;
 
        if (!ds || !x86_pmu.pebs)
@@ -488,16 +518,13 @@ static void intel_pmu_drain_pebs_core(struct pt_regs *iregs)
 
        WARN_ON_ONCE(!event);
 
-       if (!event->attr.precise)
+       if (!event->attr.precise_ip)
                return;
 
        n = top - at;
        if (n <= 0)
                return;
 
-       if (!intel_pmu_save_and_restart(event))
-               return;
-
        /*
         * Should not happen, we program the threshold at 1 and do not
         * set a reset value.
@@ -505,37 +532,7 @@ static void intel_pmu_drain_pebs_core(struct pt_regs *iregs)
        WARN_ON_ONCE(n > 1);
        at += n - 1;
 
-       perf_sample_data_init(&data, 0);
-       data.period = event->hw.last_period;
-
-       if (event->attr.sample_type & PERF_SAMPLE_RAW) {
-               raw.size = x86_pmu.pebs_record_size;
-               raw.data = at;
-               data.raw = &raw;
-       }
-
-       /*
-        * We use the interrupt regs as a base because the PEBS record
-        * does not contain a full regs set, specifically it seems to
-        * lack segment descriptors, which get used by things like
-        * user_mode().
-        *
-        * In the simple case fix up only the IP and BP,SP regs, for
-        * PERF_SAMPLE_IP and PERF_SAMPLE_CALLCHAIN to function properly.
-        * A possible PERF_SAMPLE_REGS will have to transfer all regs.
-        */
-       regs = *iregs;
-       regs.ip = at->ip;
-       regs.bp = at->bp;
-       regs.sp = at->sp;
-
-       if (intel_pmu_pebs_fixup_ip(&regs))
-               regs.flags |= PERF_EFLAGS_EXACT;
-       else
-               regs.flags &= ~PERF_EFLAGS_EXACT;
-
-       if (perf_event_overflow(event, 1, &data, &regs))
-               x86_pmu_stop(event);
+       __intel_pmu_pebs_event(event, iregs, at);
 }
 
 static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs)
@@ -543,10 +540,7 @@ static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs)
        struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
        struct debug_store *ds = cpuc->ds;
        struct pebs_record_nhm *at, *top;
-       struct perf_sample_data data;
        struct perf_event *event = NULL;
-       struct perf_raw_record raw;
-       struct pt_regs regs;
        u64 status = 0;
        int bit, n;
 
@@ -569,14 +563,14 @@ static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs)
        WARN_ON_ONCE(n > MAX_PEBS_EVENTS);
 
        for ( ; at < top; at++) {
-               for_each_bit(bit, (unsigned long *)&at->status, MAX_PEBS_EVENTS) {
+               for_each_set_bit(bit, (unsigned long *)&at->status, MAX_PEBS_EVENTS) {
                        event = cpuc->events[bit];
                        if (!test_bit(bit, cpuc->active_mask))
                                continue;
 
                        WARN_ON_ONCE(!event);
 
-                       if (!event->attr.precise)
+                       if (!event->attr.precise_ip)
                                continue;
 
                        if (__test_and_set_bit(bit, (unsigned long *)&status))
@@ -588,33 +582,7 @@ static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs)
                if (!event || bit >= MAX_PEBS_EVENTS)
                        continue;
 
-               if (!intel_pmu_save_and_restart(event))
-                       continue;
-
-               perf_sample_data_init(&data, 0);
-               data.period = event->hw.last_period;
-
-               if (event->attr.sample_type & PERF_SAMPLE_RAW) {
-                       raw.size = x86_pmu.pebs_record_size;
-                       raw.data = at;
-                       data.raw = &raw;
-               }
-
-               /*
-                * See the comment in intel_pmu_drain_pebs_core()
-                */
-               regs = *iregs;
-               regs.ip = at->ip;
-               regs.bp = at->bp;
-               regs.sp = at->sp;
-
-               if (intel_pmu_pebs_fixup_ip(&regs))
-                       regs.flags |= PERF_EFLAGS_EXACT;
-               else
-                       regs.flags &= ~PERF_EFLAGS_EXACT;
-
-               if (perf_event_overflow(event, 1, &data, &regs))
-                       x86_pmu_stop(event);
+               __intel_pmu_pebs_event(event, iregs, at);
        }
 }