Skip to contentSkip to conversation

powerpc/perf: Fix branch_filter support for multiple filters in powerpc

PATCH In review Athira Rajeev 4 participants 7 messages Sep 21, 2022 – Oct 4, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 powerpc/perf: Fix branch_filter support for multiple filters in powerpc

For PERF_SAMPLE_BRANCH_STACK sample type, different branch_sample_type ie branch filters are supported. The branch filters are requested via event attribute "branch_sample_type". Multiple branch filters can be passed in event attribute.

Example:
perf record -b -o- -B --branch-filter any,ind_call true

Powerpc does not support having multiple branch filters at sametime. In powerpc, branch filters for branch stack sampling is set via MMCRA IFM bits [32:33]. But currently when requesting for multiple filter types, the "perf record" command does not report any error.

Example:
perf record -b -o- -B --branch-filter any,save_type true perf record -b -o- -B --branch-filter any,ind_call true

The "bhrb_filter_map" function in PMU driver code does the validity check for supported branch filters. But this check is done for single filter. Hence "perf record" will proceed here without reporting any error.

Fix power_pmu_event_init to return EOPNOTSUPP when multiple branch filters are requested in the event attr.

After the fix:
perf record --branch-filter any,ind_call -- ls
Error:
cycles: PMU Hardware doesn't support sampling/overflow-interrupts. Try 'perf stat'

---
Changelog:
Addressed review comment from Michael Ellerman to do irq restore before returning EOPNOTSUPP

 arch/powerpc/perf/core-book3s.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
arch/powerpc/perf/core-book3s.c +17 -0
index 13919eb96931..a939ac3b3a84 100644
@@ -2131,6 +2131,23 @@ static int power_pmu_event_init(struct perf_event *event)
 	if (has_branch_stack(event)) {
 		u64 bhrb_filter = -1;
 
+		/*
+		 * powerpc does not support having multiple branch filters
+		 * at sametime. Branch filters are set via MMCRA IFM[32:33]
+		 * bits for power8 and above. Return EOPNOTSUPP when multiple
+		 * branch filters are requested in the event attr.
+		 *
+		 * When opening event via perf_event_open, branch_sample_type
+		 * gets adjusted in perf_copy_attr function. Kernel will
+		 * automatically adjust the branch_sample_type based on the
+		 * event modifier settings to include PERF_SAMPLE_BRANCH_PLM_ALL.
+		 * Hence drop the check for PERF_SAMPLE_BRANCH_PLM_ALL.
+		 */
+		if (hweight64(event->attr.branch_sample_type & ~PERF_SAMPLE_BRANCH_PLM_ALL) > 1) {
+			local_irq_restore(irq_flags);
+			return -EOPNOTSUPP;
+		}
+
 		if (ppmu->bhrb_filter_map)
 			bhrb_filter = ppmu->bhrb_filter_map(
 					event->attr.branch_sample_type);
Signature · 1 line
2.31.1
#1 lore raw

PATCH v2 2/3 tools/perf/tests: Fix branch stack sampling test to include sanity check for branch filter

commit b55878c90ab9 ("perf test: Add test for branch stack sampling") added test for branch stack sampling. There is a sanity check in the beginning to skip the test if the hardware doesn't support branch stack sampling.

Snippet
<<>>
skip the test if the hardware doesn't support branch stack sampling perf record -b -o- -B true > /dev/null 2>&1 || exit 2 <<>>

But the testcase also uses branch sample types: save_type, any. if any platform doesn't support the branch filters used in the test, the testcase will fail. In powerpc, currently mutliple branch filters are not supported and hence this test fails in powerpc. Fix the sanity check to look at the support for branch filters used in this test before proceeding with the test.

Fixes b55878c90ab9 ("perf test: Add test for branch stack sampling")
---
 tools/perf/tests/shell/test_brstack.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/tests/shell/test_brstack.sh +2 -1
index c644f94a6500..ec801cffae6b 100755
@@ -12,7 +12,8 @@ if ! [ -x "$(command -v cc)" ]; then
 fi
 
 # skip the test if the hardware doesn't support branch stack sampling
-perf record -b -o- -B true > /dev/null 2>&1 || exit 2
+# and if the architecture doesn't support filter types: any,save_type,u
+perf record -b -o- -B --branch-filter any,save_type,u true > /dev/null 2>&1 || exit 2
 
 TMPDIR=$(mktemp -d /tmp/__perf_test.program.XXXXX)
 
Signature · 1 line
2.31.1
#5 lore raw

PATCH v2 3/3 tools/testing/selftests/powerpc: Update the bhrb filter sampling test to test for multiple branch filters

In reply to Athira Rajeev

For PERF_SAMPLE_BRANCH_STACK sample type, different branch_sample_type, ie branch filters are supported. The testcase "bhrb_filter_map_test" tests the valid and invalid filter maps in different powerpc platforms. Update this testcase to include scenario to cover multiple branch filters at sametime. Since powerpc doesn't support multiple filters at sametime, expect failure during perf_event_open.

---
Changelog:
Fixed compile error for undefined branch sample type by using PERF_SAMPLE_BRANCH_ANY_CALL instead of PERF_SAMPLE_BRANCH_TYPE_SAVE

 .../powerpc/pmu/sampling_tests/bhrb_filter_map_test.c    | 9 +++++++++
 1 file changed, 9 insertions(+)
tools/testing/selftests/powerpc/pmu/sampling_tests/bhrb_filter_map_test.c +9 -0
index 8182647c63c8..3f43c315c666 100644
@@ -96,6 +96,15 @@ static int bhrb_filter_map_test(void)
 		}
 	}
 
+	/*
+	 * Combine filter maps which includes a valid branch filter and an invalid branch
+	 * filter. Example: any ( PERF_SAMPLE_BRANCH_ANY) and any_call
+	 * (PERF_SAMPLE_BRANCH_ANY_CALL).
+	 * The perf_event_open should fail in this case.
+	 */
+	event.attr.branch_sample_type = PERF_SAMPLE_BRANCH_ANY | PERF_SAMPLE_BRANCH_ANY_CALL;
+	FAIL_IF(!event_open(&event));
+
 	return 0;
 }
 
Signature · 1 line
2.31.1
#2 lore raw

Re: [PATCH V2 2/3] tools/perf/tests: Fix branch stack sampling test to include sanity check for branch filter

In reply to Athira Rajeev
Quoted 38 lines · Athira Rajeev

commit b55878c90ab9 ("perf test: Add test for branch stack sampling") added test for branch stack sampling. There is a sanity check in the beginning to skip the test if the hardware doesn't support branch stack sampling.

Snippet
<<>>
skip the test if the hardware doesn't support branch stack sampling perf record -b -o- -B true > /dev/null 2>&1 || exit 2 <<>>

But the testcase also uses branch sample types: save_type, any. if any platform doesn't support the branch filters used in the test, the testcase will fail. In powerpc, currently mutliple branch filters are not supported and hence this test fails in powerpc. Fix the sanity check to look at the support for branch filters used in this test before proceeding with the test.

Fixes b55878c90ab9 ("perf test: Add test for branch stack sampling")

---
tools/perf/tests/shell/test_brstack.sh | 3 ++-

1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/tests/shell/test_brstack.sh +0 -0
index c644f94a6500..ec801cffae6b 100755
@@ -12,7 +12,8 @@ if ! [ -x "$(command -v cc)" ]; then

fi

# skip the test if the hardware doesn't support branch stack sampling

tools/perf/tests/shell/test_brstack.sh if ! [ -x "$(command -v cc)" ]; then · line 16

Quoted 3 lines
tools/perf/tests/shell/test_brstack.sh +2 -1
-perf record -b -o- -B true > /dev/null 2>&1 || exit 2
+# and if the architecture doesn't support filter types: any,save_type,u
+perf record -b -o- -B --branch-filter any,save_type,u true > /dev/null 2>&1 || exit 2

Hi,

Looking for review comments for this change.

Thanks
Athira

Quoted 6 lines

TMPDIR=$(mktemp -d /tmp/__perf_test.program.XXXXX)

Signature · 1 line
2.31.1
#3 lore raw

Re: [PATCH V2 2/3] tools/perf/tests: Fix branch stack sampling test to include sanity check for branch filter

In reply to Athira Rajeev

Em Wed, Sep 21, 2022 at 08:22:54PM +0530, Athira Rajeev escreveu:

Quoted 11 lines

commit b55878c90ab9 ("perf test: Add test for branch stack sampling") added test for branch stack sampling. There is a sanity check in the beginning to skip the test if the hardware doesn't support branch stack sampling.

Snippet
<<>>
skip the test if the hardware doesn't support branch stack sampling perf record -b -o- -B true > /dev/null 2>&1 || exit 2 <<>>

Quoted 6 lines

But the testcase also uses branch sample types: save_type, any. if any platform doesn't support the branch filters used in the test, the testcase will fail. In powerpc, currently mutliple branch filters are not supported and hence this test fails in powerpc. Fix the sanity check to look at the support for branch filters used in this test before proceeding with

Quoted 1 line

the test.

Applied the tools/perf/ part

- Arnaldo

Quoted 24 lines
Fixes b55878c90ab9 ("perf test: Add test for branch stack sampling")
---
 tools/perf/tests/shell/test_brstack.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/tests/shell/test_brstack.sh +2 -1
index c644f94a6500..ec801cffae6b 100755
@@ -12,7 +12,8 @@ if ! [ -x "$(command -v cc)" ]; then
 fi
 
 # skip the test if the hardware doesn't support branch stack sampling
-perf record -b -o- -B true > /dev/null 2>&1 || exit 2
+# and if the architecture doesn't support filter types: any,save_type,u
+perf record -b -o- -B --branch-filter any,save_type,u true > /dev/null 2>&1 || exit 2
 
 TMPDIR=$(mktemp -d /tmp/__perf_test.program.XXXXX)
 
Signature · 1 line
2.31.1
Signature · 1 line
- Arnaldo
#4 lore raw

Re: [PATCH V2 2/3] tools/perf/tests: Fix branch stack sampling test to include sanity check for branch filter

Quoted 12 lines · Arnaldo Carvalho de Melo

Em Wed, Sep 21, 2022 at 08:22:54PM +0530, Athira Rajeev escreveu:

Quoted 11 lines

commit b55878c90ab9 ("perf test: Add test for branch stack sampling") added test for branch stack sampling. There is a sanity check in the beginning to skip the test if the hardware doesn't support branch stack sampling.

Snippet
<<>>
skip the test if the hardware doesn't support branch stack sampling perf record -b -o- -B true > /dev/null 2>&1 || exit 2 <<>>

Quoted 8 lines
Quoted 6 lines

But the testcase also uses branch sample types: save_type, any. if any platform doesn't support the branch filters used in the test, the testcase will fail. In powerpc, currently mutliple branch filters are not supported and hence this test fails in powerpc. Fix the sanity check to look at the support for branch filters used in this test before proceeding with

Quoted 1 line

the test.

Applied the tools/perf/ part

Thanks, I have the other two queued.

cheers

#6 lore raw

Re: (subset) [PATCH V2 1/3] powerpc/perf: Fix branch_filter support for multiple filters in powerpc

In reply to Athira Rajeev
Quoted 9 lines · Athira Rajeev

For PERF_SAMPLE_BRANCH_STACK sample type, different branch_sample_type ie branch filters are supported. The branch filters are requested via event attribute "branch_sample_type". Multiple branch filters can be passed in event attribute.

Example:
perf record -b -o- -B --branch-filter any,ind_call true

[...]

Patch 3 applied to powerpc/next.

[3/3] tools/testing/selftests/powerpc: Update the bhrb filter sampling test to test for multiple branch filters

      https://git.kernel.org/powerpc/c/18213532de7156af689cb0511d2f95bcbe3c98a0

cheers