Skip to contentSkip to conversation

perf: New conditional branch filter

PATCH Superseded Anshuman Khandual 2 participants 10 messages Mar 7, 2014 – Apr 7, 2014

Subsystems (2)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover perf: New conditional branch filter

Hello Arnaldo,

I had posted the V5 version of PowerPC SW branch filter enablement
patchset last month. Please find the patchset here at

	https://lkml.org/lkml/2014/2/5/79

These following patches (2,4,5,6 patches from the original V5 version patchset) are the ones which change code in the generic kernel, perf tool and X86 perf. Basically this patchset adds one more branch filter for "conditional" branches. In X86 code, this new filter has been implemented with the help of availble SW filter X86_BR_JCC and LBR_JCC. We had some discussions in this regard before. Please review these changes and if it's okay, please merge them. Other patches in the series are powerpc specific and are being reviewed by Benjamin Herrenschmidt and Michael Ellerman. Let me know if you need more information.

[1] https://lkml.org/lkml/2013/5/22/51
[2] https://lkml.org/lkml/2013/8/30/10
[3] https://lkml.org/lkml/2013/10/16/75
[4] https://lkml.org/lkml/2013/12/4/168
[5] https://lkml.org/lkml/2014/2/5/79

c: Arnaldo Carvalho de Melo <[email protected]>
Cc: Stephane Eranian <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Peter Zijlstra <[email protected]>

Anshuman Khandual (4):
perf: Add PERF_SAMPLE_BRANCH_COND
perf, tool: Conditional branch filter 'cond' added to perf record x86, perf: Add conditional branch filtering support perf, documentation: Description for conditional branch filter

 arch/x86/kernel/cpu/perf_event_intel_lbr.c | 5 +++++
 include/uapi/linux/perf_event.h            | 3 ++-
 tools/perf/Documentation/perf-record.txt   | 3 ++-
 tools/perf/builtin-record.c                | 1 +
 4 files changed, 10 insertions(+), 2 deletions(-)
Signature · 1 line
1.7.11.7
#1 lore raw

PATCH v5 1/4 perf: Add PERF_SAMPLE_BRANCH_COND

This patch introduces new branch filter PERF_SAMPLE_BRANCH_COND which will extend the existing perf ABI. Various architectures can provide this functionality with either with HW filtering support (if present) or with SW filtering of captured branch instructions.

---
 include/uapi/linux/perf_event.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/uapi/linux/perf_event.h +2 -1
index 853bc1c..696f69b4 100644
@@ -163,8 +163,9 @@ enum perf_branch_sample_type {
 	PERF_SAMPLE_BRANCH_ABORT_TX	= 1U << 7, /* transaction aborts */
 	PERF_SAMPLE_BRANCH_IN_TX	= 1U << 8, /* in transaction */
 	PERF_SAMPLE_BRANCH_NO_TX	= 1U << 9, /* not in transaction */
+	PERF_SAMPLE_BRANCH_COND		= 1U << 10, /* conditional branches */
 
-	PERF_SAMPLE_BRANCH_MAX		= 1U << 10, /* non-ABI */
+	PERF_SAMPLE_BRANCH_MAX		= 1U << 11, /* non-ABI */
 };
 
 #define PERF_SAMPLE_BRANCH_PLM_ALL \
Signature · 1 line
1.7.11.7
#2 lore raw

PATCH v5 2/4 perf, tool: Conditional branch filter 'cond' added to perf record

In reply to Anshuman Khandual

Adding perf record support for new branch stack filter criteria PERF_SAMPLE_BRANCH_COND.

---
 tools/perf/builtin-record.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/builtin-record.c +1 -0
index 3c394bf..eb74bcd 100644
@@ -589,6 +589,7 @@ static const struct branch_mode branch_modes[] = {
 	BRANCH_OPT("abort_tx", PERF_SAMPLE_BRANCH_ABORT_TX),
 	BRANCH_OPT("in_tx", PERF_SAMPLE_BRANCH_IN_TX),
 	BRANCH_OPT("no_tx", PERF_SAMPLE_BRANCH_NO_TX),
+	BRANCH_OPT("cond", PERF_SAMPLE_BRANCH_COND),
 	BRANCH_END
 };
 
Signature · 1 line
1.7.11.7
#3 lore raw

PATCH v5 3/4 x86, perf: Add conditional branch filtering support

In reply to Anshuman Khandual

This patch adds conditional branch filtering support, enabling it for PERF_SAMPLE_BRANCH_COND in perf branch stack sampling framework by utilizing an available software filter X86_BR_JCC.

---
 arch/x86/kernel/cpu/perf_event_intel_lbr.c | 5 +++++
 1 file changed, 5 insertions(+)
arch/x86/kernel/cpu/perf_event_intel_lbr.c +5 -0
index d82d155..9dd2459 100644
@@ -384,6 +384,9 @@ static void intel_pmu_setup_sw_lbr_filter(struct perf_event *event)
 	if (br_type & PERF_SAMPLE_BRANCH_NO_TX)
 		mask |= X86_BR_NO_TX;
 
+	if (br_type & PERF_SAMPLE_BRANCH_COND)
+		mask |= X86_BR_JCC;
+
 	/*
 	 * stash actual user request into reg, it may
 	 * be used by fixup code for some CPU
@@ -678,6 +681,7 @@ static const int nhm_lbr_sel_map[PERF_SAMPLE_BRANCH_MAX] = {
 	 * NHM/WSM erratum: must include IND_JMP to capture IND_CALL
 	 */
 	[PERF_SAMPLE_BRANCH_IND_CALL] = LBR_IND_CALL | LBR_IND_JMP,
+	[PERF_SAMPLE_BRANCH_COND]     = LBR_JCC,
 };
 
 static const int snb_lbr_sel_map[PERF_SAMPLE_BRANCH_MAX] = {
@@ -689,6 +693,7 @@ static const int snb_lbr_sel_map[PERF_SAMPLE_BRANCH_MAX] = {
 	[PERF_SAMPLE_BRANCH_ANY_CALL]	= LBR_REL_CALL | LBR_IND_CALL
 					| LBR_FAR,
 	[PERF_SAMPLE_BRANCH_IND_CALL]	= LBR_IND_CALL,
+	[PERF_SAMPLE_BRANCH_COND]       = LBR_JCC,
 };
 
 /* core */
Signature · 1 line
1.7.11.7
#4 lore raw

PATCH v5 4/4 perf, documentation: Description for conditional branch filter

In reply to Anshuman Khandual

Adding documentation support for conditional branch filter.

---
 tools/perf/Documentation/perf-record.txt | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-record.txt +2 -1
index c71b0f3..d460049 100644
@@ -184,9 +184,10 @@ following filters are defined:
 	- in_tx: only when the target is in a hardware transaction
 	- no_tx: only when the target is not in a hardware transaction
 	- abort_tx: only when the target is a hardware transaction abort
+	- cond: conditional branches
 
 +
-The option requires at least one branch type among any, any_call, any_ret, ind_call.
+The option requires at least one branch type among any, any_call, any_ret, ind_call, cond.
 The privilege levels may be omitted, in which case, the privilege levels of the associated
 event are applied to the branch filter. Both kernel (k) and hypervisor (hv) privilege
 levels are subject to permissions.  When sampling on multiple events, branch stack sampling
Signature · 1 line
1.7.11.7
#5 lore raw
In reply to Anshuman Khandual
Quoted 16 lines · Anshuman Khandual

Hello Arnaldo,

I had posted the V5 version of PowerPC SW branch filter enablement
patchset last month. Please find the patchset here at

	https://lkml.org/lkml/2014/2/5/79

These following patches (2,4,5,6 patches from the original V5 version patchset) are the ones which change code in the generic kernel, perf tool and X86 perf. Basically this patchset adds one more branch filter for "conditional" branches. In X86 code, this new filter has been implemented with the help of availble SW filter X86_BR_JCC and LBR_JCC. We had some discussions in this regard before. Please review these changes and if it's okay, please merge them. Other patches in the series are powerpc specific and are being reviewed by Benjamin Herrenschmidt and Michael Ellerman. Let me know if you need more information.

Quoted 5 lines

[1] https://lkml.org/lkml/2013/5/22/51
[2] https://lkml.org/lkml/2013/8/30/10
[3] https://lkml.org/lkml/2013/10/16/75
[4] https://lkml.org/lkml/2013/12/4/168
[5] https://lkml.org/lkml/2014/2/5/79

Hey Arnaldo,

Do you have any comments or suggestions on this ? Have not received any response on these proposed patch series yet. Thank you.

#6 lore raw
Quoted 4 lines

Hey Arnaldo,

Do you have any comments or suggestions on this ? Have not received any response on these proposed patch series yet. Thank you.

I read it earlier and it looks good to me.

-Andi

#7 lore raw
Quoted 6 lines · Andi Kleen
Quoted 4 lines

Hey Arnaldo,

Do you have any comments or suggestions on this ? Have not received any response on these proposed patch series yet. Thank you.

I read it earlier and it looks good to me.

Hey Andi,

Can I add your "Reviewed-by" or "Acked-by" to all these four patches ?

#8 lore raw
Quoted 11 lines · Anshuman Khandual
Quoted 6 lines · Andi Kleen
Quoted 4 lines

Hey Arnaldo,

Do you have any comments or suggestions on this ? Have not received any response on these proposed patch series yet. Thank you.

I read it earlier and it looks good to me.

Hey Andi,

Can I add your "Reviewed-by" or "Acked-by" to all these four patches ?

Ok for me.

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only
#9 lore raw
In reply to Anshuman Khandual
Quoted 2 lines

Do you have any comments or suggestions on this ? Have not received any response on these proposed patch series yet. Thank you.

Also BTW I'm also at least three patchkits behind on perf tools merges, some of them several weeks old.

Perhaps we need a staging tree somewhere to collect all the patches until they can actually get processed.

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only