Skip to contentSkip to conversation

perf, bts: Make BTS exclusive again

PATCH New Alexander Shishkin 2 participants 5 messages Sep 20, 2016 – Sep 22, 2016

Subsystems (2)
lore
Share & tools
lore

Alexander Shishkin

author reviewer
#0 lore raw

cover perf, bts: Make BTS exclusive again

Hi Peter,

While looking at something else I noticed that the exclusive event filter only allows one such event per context, whereas it should allow one such event from each PMU that has PERF_PMU_CAP_EXCLUSIVE. At the same time, intel_bts PMU doesn't even have this capability set (which is why on systems that allow coexistance of PT and BTS it still works, see ccbebba4c6 for more context).

Alexander Shishkin (2):
perf/x86/intel/bts: Make it an exclusive PMU
perf: Limit matching exclusive events to one PMU

 arch/x86/events/intel/bts.c | 3 ++-
 kernel/events/core.c        | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)
Signature · 1 line
2.9.3
author reviewer
#1 lore raw

PATCH 1/2 perf/x86/intel/bts: Make it an exclusive PMU

Just like intel_pt, intel_bts can only handle one event at a time, which is the reason we introduced PERF_PMU_CAP_EXCLUSIVE in the first place. However, at the moment one can have as many intel_bts events within the same context at the same time as one pleases. Only one of them, however, will get scheduled and receive the actual trace data.

Fix this by making intel_bts an "exclusive" PMU.

---
 arch/x86/events/intel/bts.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/events/intel/bts.c +2 -1
index bdcd651099..6112c3d538 100644
@@ -584,7 +584,8 @@ static __init int bts_init(void)
 	if (!boot_cpu_has(X86_FEATURE_DTES64) || !x86_pmu.bts)
 		return -ENODEV;
 
-	bts_pmu.capabilities	= PERF_PMU_CAP_AUX_NO_SG | PERF_PMU_CAP_ITRACE;
+	bts_pmu.capabilities	= PERF_PMU_CAP_AUX_NO_SG | PERF_PMU_CAP_ITRACE |
+				  PERF_PMU_CAP_EXCLUSIVE;
 	bts_pmu.task_ctx_nr	= perf_sw_context;
 	bts_pmu.event_init	= bts_event_init;
 	bts_pmu.add		= bts_event_add;
Signature · 1 line
2.9.3
#2 lore raw

[tip:perf/urgent] perf/x86/intel/bts: Make it an exclusive PMU

perf/x86/intel/bts: Make it an exclusive PMU
Commit-ID:  08b90f0655258411a1b41d856331e20e7ec8d55c
Gitweb:     http://git.kernel.org/tip/08b90f0655258411a1b41d856331e20e7ec8d55c
Author:     Alexander Shishkin <[email protected]>
AuthorDate: Tue, 20 Sep 2016 18:48:10 +0300
Committer:  Ingo Molnar <[email protected]>
CommitDate: Thu, 22 Sep 2016 14:56:08 +0200

perf/x86/intel/bts: Make it an exclusive PMU

Just like intel_pt, intel_bts can only handle one event at a time, which is the reason we introduced PERF_PMU_CAP_EXCLUSIVE in the first place. However, at the moment one can have as many intel_bts events within the same context at the same time as one pleases. Only one of them, however, will get scheduled and receive the actual trace data.

Fix this by making intel_bts an "exclusive" PMU.

Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Vince Weaver <[email protected]>
---
 arch/x86/events/intel/bts.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/events/intel/bts.c +2 -1
index 6ff66ef..982c9e3 100644
@@ -584,7 +584,8 @@ static __init int bts_init(void)
 	if (!boot_cpu_has(X86_FEATURE_DTES64) || !x86_pmu.bts)
 		return -ENODEV;
 
-	bts_pmu.capabilities	= PERF_PMU_CAP_AUX_NO_SG | PERF_PMU_CAP_ITRACE;
+	bts_pmu.capabilities	= PERF_PMU_CAP_AUX_NO_SG | PERF_PMU_CAP_ITRACE |
+				  PERF_PMU_CAP_EXCLUSIVE;
 	bts_pmu.task_ctx_nr	= perf_sw_context;
 	bts_pmu.event_init	= bts_event_init;
 	bts_pmu.add		= bts_event_add;
author reviewer
#3 lore raw

PATCH 2/2 perf: Limit matching exclusive events to one PMU

In reply to Alexander Shishkin

An "exclusive" PMU is the one that can only have one event scheduled in at any given time. There may be more than one of such PMUs in a system, though, like Intel PT and BTS. It should be allowed to have one event for either of those inside the same context (there may be other constraints that may prevent this, but those would be hardware-specific). However, the exclusivity code is written so that only one event from any of the "exclusive" PMUs is allowed in a context.

Fix this by making the exclusive event filter explicitly match two events' PMUs.

---
 kernel/events/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/events/core.c +1 -1
index fedba316cc..7c0d263f6b 100644
@@ -3958,7 +3958,7 @@ static void exclusive_event_destroy(struct perf_event *event)
 
 static bool exclusive_event_match(struct perf_event *e1, struct perf_event *e2)
 {
-	if ((e1->pmu->capabilities & PERF_PMU_CAP_EXCLUSIVE) &&
+	if ((e1->pmu == e2->pmu) &&
 	    (e1->cpu == e2->cpu ||
 	     e1->cpu == -1 ||
 	     e2->cpu == -1))
Signature · 1 line
2.9.3
#4 lore raw

[tip:perf/urgent] perf/core: Limit matching exclusive events to one PMU

perf/core: Limit matching exclusive events to one PMU
Commit-ID:  3bf6215a1b30db7df6083c708caab3fe1a8e8abe
Gitweb:     http://git.kernel.org/tip/3bf6215a1b30db7df6083c708caab3fe1a8e8abe
Author:     Alexander Shishkin <[email protected]>
AuthorDate: Tue, 20 Sep 2016 18:48:11 +0300
Committer:  Ingo Molnar <[email protected]>
CommitDate: Thu, 22 Sep 2016 14:56:09 +0200

perf/core: Limit matching exclusive events to one PMU

An "exclusive" PMU is the one that can only have one event scheduled in at any given time. There may be more than one of such PMUs in a system, though, like Intel PT and BTS. It should be allowed to have one event for either of those inside the same context (there may be other constraints that may prevent this, but those would be hardware-specific). However, the exclusivity code is written so that only one event from any of the "exclusive" PMUs is allowed in a context.

Fix this by making the exclusive event filter explicitly match two events' PMUs.

Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Vince Weaver <[email protected]>
---
 kernel/events/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/events/core.c +1 -1
index a54f2c2..fc9bb22 100644
@@ -3929,7 +3929,7 @@ static void exclusive_event_destroy(struct perf_event *event)
 
 static bool exclusive_event_match(struct perf_event *e1, struct perf_event *e2)
 {
-	if ((e1->pmu->capabilities & PERF_PMU_CAP_EXCLUSIVE) &&
+	if ((e1->pmu == e2->pmu) &&
 	    (e1->cpu == e2->cpu ||
 	     e1->cpu == -1 ||
 	     e2->cpu == -1))