Commit ecef7c1a authored by Jiri Olsa's avatar Jiri Olsa Committed by Greg Kroah-Hartman

perf/x86/intel: Add generic branch tracing check to intel_pmu_has_bts()

commit 67266c10 upstream.

Currently we check the branch tracing only by checking for the
PERF_COUNT_HW_BRANCH_INSTRUCTIONS event of PERF_TYPE_HARDWARE
type. But we can define the same event with the PERF_TYPE_RAW
type.

Changing the intel_pmu_has_bts() code to check on event's final
hw config value, so both HW types are covered.

Adding unlikely to intel_pmu_has_bts() condition calls, because
it was used in the original code in intel_bts_constraints.
Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
Acked-by: default avatarPeter Zijlstra <a.p.zijlstra@chello.nl>
Cc: <stable@vger.kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Link: http://lkml.kernel.org/r/20181121101612.16272-2-jolsa@kernel.orgSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent fae1bec5
...@@ -2345,16 +2345,7 @@ static int intel_pmu_handle_irq(struct pt_regs *regs) ...@@ -2345,16 +2345,7 @@ static int intel_pmu_handle_irq(struct pt_regs *regs)
static struct event_constraint * static struct event_constraint *
intel_bts_constraints(struct perf_event *event) intel_bts_constraints(struct perf_event *event)
{ {
struct hw_perf_event *hwc = &event->hw; if (unlikely(intel_pmu_has_bts(event)))
unsigned int hw_event, bts_event;
if (event->attr.freq)
return NULL;
hw_event = hwc->config & INTEL_ARCH_EVENT_MASK;
bts_event = x86_pmu.event_map(PERF_COUNT_HW_BRANCH_INSTRUCTIONS);
if (unlikely(hw_event == bts_event && hwc->sample_period == 1))
return &bts_constraint; return &bts_constraint;
return NULL; return NULL;
...@@ -2976,10 +2967,8 @@ static unsigned long intel_pmu_free_running_flags(struct perf_event *event) ...@@ -2976,10 +2967,8 @@ static unsigned long intel_pmu_free_running_flags(struct perf_event *event)
static int intel_pmu_bts_config(struct perf_event *event) static int intel_pmu_bts_config(struct perf_event *event)
{ {
struct perf_event_attr *attr = &event->attr; struct perf_event_attr *attr = &event->attr;
struct hw_perf_event *hwc = &event->hw;
if (attr->config == PERF_COUNT_HW_BRANCH_INSTRUCTIONS && if (unlikely(intel_pmu_has_bts(event))) {
!attr->freq && hwc->sample_period == 1) {
/* BTS is not supported by this architecture. */ /* BTS is not supported by this architecture. */
if (!x86_pmu.bts_active) if (!x86_pmu.bts_active)
return -EOPNOTSUPP; return -EOPNOTSUPP;
...@@ -3038,7 +3027,7 @@ static int intel_pmu_hw_config(struct perf_event *event) ...@@ -3038,7 +3027,7 @@ static int intel_pmu_hw_config(struct perf_event *event)
/* /*
* BTS is set up earlier in this path, so don't account twice * BTS is set up earlier in this path, so don't account twice
*/ */
if (!intel_pmu_has_bts(event)) { if (!unlikely(intel_pmu_has_bts(event))) {
/* disallow lbr if conflicting events are present */ /* disallow lbr if conflicting events are present */
if (x86_add_exclusive(x86_lbr_exclusive_lbr)) if (x86_add_exclusive(x86_lbr_exclusive_lbr))
return -EBUSY; return -EBUSY;
......
...@@ -850,11 +850,16 @@ static inline int amd_pmu_init(void) ...@@ -850,11 +850,16 @@ static inline int amd_pmu_init(void)
static inline bool intel_pmu_has_bts(struct perf_event *event) static inline bool intel_pmu_has_bts(struct perf_event *event)
{ {
if (event->attr.config == PERF_COUNT_HW_BRANCH_INSTRUCTIONS && struct hw_perf_event *hwc = &event->hw;
!event->attr.freq && event->hw.sample_period == 1) unsigned int hw_event, bts_event;
return true;
if (event->attr.freq)
return false;
hw_event = hwc->config & INTEL_ARCH_EVENT_MASK;
bts_event = x86_pmu.event_map(PERF_COUNT_HW_BRANCH_INSTRUCTIONS);
return false; return hw_event == bts_event && hwc->sample_period == 1;
} }
int intel_pmu_save_and_restart(struct perf_event *event); int intel_pmu_save_and_restart(struct perf_event *event);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment