linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2 1/3] powerpc/perf: Fix branch_filter support for multiple filters in powerpc
@ 2022-09-21 14:52 Athira Rajeev
  2022-09-21 14:52 ` [PATCH V2 2/3] tools/perf/tests: Fix branch stack sampling test to include sanity check for branch filter Athira Rajeev
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Athira Rajeev @ 2022-09-21 14:52 UTC (permalink / raw)
  To: acme, jolsa, mpe
  Cc: maddy, rnsastry, kjain, linux-perf-users, disgoel, linuxppc-dev

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'

Reported-by: Disha Goel <disgoel@linux.vnet.ibm.com>
Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Reviewed-by: Madhavan Srinivasan <maddy@linux.ibm.com>
Tested-by: Disha Goel<disgoel@linux.vnet.ibm.com>
Reviewed-by: Kajol Jain <kjain@linux.ibm.com>
---
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(+)

diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c
index 13919eb96931..a939ac3b3a84 100644
--- a/arch/powerpc/perf/core-book3s.c
+++ b/arch/powerpc/perf/core-book3s.c
@@ -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);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH V2 2/3] tools/perf/tests: Fix branch stack sampling test to include sanity check for branch filter
  2022-09-21 14:52 [PATCH V2 1/3] powerpc/perf: Fix branch_filter support for multiple filters in powerpc Athira Rajeev
@ 2022-09-21 14:52 ` Athira Rajeev
  2022-09-28 14:27   ` Athira Rajeev
  2022-09-28 14:29   ` Arnaldo Carvalho de Melo
  2022-09-21 14:52 ` [PATCH V2 3/3] tools/testing/selftests/powerpc: Update the bhrb filter sampling test to test for multiple branch filters Athira Rajeev
  2022-10-04 13:25 ` (subset) [PATCH V2 1/3] powerpc/perf: Fix branch_filter support for multiple filters in powerpc Michael Ellerman
  2 siblings, 2 replies; 7+ messages in thread
From: Athira Rajeev @ 2022-09-21 14:52 UTC (permalink / raw)
  To: acme, jolsa, mpe
  Cc: maddy, rnsastry, kjain, linux-perf-users, disgoel, linuxppc-dev

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")
Reported-by: Disha Goel <disgoel@linux.vnet.ibm.com>
Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Reviewed-by: Kajol Jain <kjain@linux.ibm.com>
---
 tools/perf/tests/shell/test_brstack.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/perf/tests/shell/test_brstack.sh b/tools/perf/tests/shell/test_brstack.sh
index c644f94a6500..ec801cffae6b 100755
--- a/tools/perf/tests/shell/test_brstack.sh
+++ b/tools/perf/tests/shell/test_brstack.sh
@@ -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)
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH V2 3/3] tools/testing/selftests/powerpc: Update the bhrb filter sampling test to test for multiple branch filters
  2022-09-21 14:52 [PATCH V2 1/3] powerpc/perf: Fix branch_filter support for multiple filters in powerpc Athira Rajeev
  2022-09-21 14:52 ` [PATCH V2 2/3] tools/perf/tests: Fix branch stack sampling test to include sanity check for branch filter Athira Rajeev
@ 2022-09-21 14:52 ` Athira Rajeev
  2022-10-04 13:25 ` (subset) [PATCH V2 1/3] powerpc/perf: Fix branch_filter support for multiple filters in powerpc Michael Ellerman
  2 siblings, 0 replies; 7+ messages in thread
From: Athira Rajeev @ 2022-09-21 14:52 UTC (permalink / raw)
  To: acme, jolsa, mpe
  Cc: maddy, rnsastry, kjain, linux-perf-users, disgoel, linuxppc-dev

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.

Reported-by: Disha Goel <disgoel@linux.vnet.ibm.com>
Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Reviewed-by: Kajol Jain <kjain@linux.ibm.com>
---
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(+)

diff --git a/tools/testing/selftests/powerpc/pmu/sampling_tests/bhrb_filter_map_test.c b/tools/testing/selftests/powerpc/pmu/sampling_tests/bhrb_filter_map_test.c
index 8182647c63c8..3f43c315c666 100644
--- a/tools/testing/selftests/powerpc/pmu/sampling_tests/bhrb_filter_map_test.c
+++ b/tools/testing/selftests/powerpc/pmu/sampling_tests/bhrb_filter_map_test.c
@@ -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;
 }
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH V2 2/3] tools/perf/tests: Fix branch stack sampling test to include sanity check for branch filter
  2022-09-21 14:52 ` [PATCH V2 2/3] tools/perf/tests: Fix branch stack sampling test to include sanity check for branch filter Athira Rajeev
@ 2022-09-28 14:27   ` Athira Rajeev
  2022-09-28 14:29   ` Arnaldo Carvalho de Melo
  1 sibling, 0 replies; 7+ messages in thread
From: Athira Rajeev @ 2022-09-28 14:27 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa, Michael Ellerman,
	German Gomez, Namhyung Kim
  Cc: maddy, Nageswara Sastry, Kajol Jain, linux-perf-users,
	Disha Goel, linuxppc-dev



> On 21-Sep-2022, at 8:22 PM, Athira Rajeev <atrajeev@linux.vnet.ibm.com> wrote:
> 
> 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")
> Reported-by: Disha Goel <disgoel@linux.vnet.ibm.com>
> Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
> Reviewed-by: Kajol Jain <kjain@linux.ibm.com>
> ---
> tools/perf/tests/shell/test_brstack.sh | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/tests/shell/test_brstack.sh b/tools/perf/tests/shell/test_brstack.sh
> index c644f94a6500..ec801cffae6b 100755
> --- a/tools/perf/tests/shell/test_brstack.sh
> +++ b/tools/perf/tests/shell/test_brstack.sh
> @@ -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

Hi,

Looking for review comments for this change.

Thanks
Athira
> 
> TMPDIR=$(mktemp -d /tmp/__perf_test.program.XXXXX)
> 
> -- 
> 2.31.1
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH V2 2/3] tools/perf/tests: Fix branch stack sampling test to include sanity check for branch filter
  2022-09-21 14:52 ` [PATCH V2 2/3] tools/perf/tests: Fix branch stack sampling test to include sanity check for branch filter Athira Rajeev
  2022-09-28 14:27   ` Athira Rajeev
@ 2022-09-28 14:29   ` Arnaldo Carvalho de Melo
  2022-09-29  5:35     ` Michael Ellerman
  1 sibling, 1 reply; 7+ messages in thread
From: Arnaldo Carvalho de Melo @ 2022-09-28 14:29 UTC (permalink / raw)
  To: Athira Rajeev
  Cc: maddy, rnsastry, linux-perf-users, jolsa, kjain, disgoel, linuxppc-dev

Em Wed, Sep 21, 2022 at 08:22:54PM +0530, Athira Rajeev escreveu:
> 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.

Applied the tools/perf/ part

- Arnaldo
 
> Fixes: b55878c90ab9 ("perf test: Add test for branch stack sampling")
> Reported-by: Disha Goel <disgoel@linux.vnet.ibm.com>
> Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
> Reviewed-by: Kajol Jain <kjain@linux.ibm.com>
> ---
>  tools/perf/tests/shell/test_brstack.sh | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/tests/shell/test_brstack.sh b/tools/perf/tests/shell/test_brstack.sh
> index c644f94a6500..ec801cffae6b 100755
> --- a/tools/perf/tests/shell/test_brstack.sh
> +++ b/tools/perf/tests/shell/test_brstack.sh
> @@ -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)
>  
> -- 
> 2.31.1

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH V2 2/3] tools/perf/tests: Fix branch stack sampling test to include sanity check for branch filter
  2022-09-28 14:29   ` Arnaldo Carvalho de Melo
@ 2022-09-29  5:35     ` Michael Ellerman
  0 siblings, 0 replies; 7+ messages in thread
From: Michael Ellerman @ 2022-09-29  5:35 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Athira Rajeev
  Cc: maddy, rnsastry, kjain, linux-perf-users, jolsa, disgoel, linuxppc-dev

Arnaldo Carvalho de Melo <acme@kernel.org> writes:
> Em Wed, Sep 21, 2022 at 08:22:54PM +0530, Athira Rajeev escreveu:
>> 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.
>
> Applied the tools/perf/ part

Thanks, I have the other two queued.

cheers

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: (subset) [PATCH V2 1/3] powerpc/perf: Fix branch_filter support for multiple filters in powerpc
  2022-09-21 14:52 [PATCH V2 1/3] powerpc/perf: Fix branch_filter support for multiple filters in powerpc Athira Rajeev
  2022-09-21 14:52 ` [PATCH V2 2/3] tools/perf/tests: Fix branch stack sampling test to include sanity check for branch filter Athira Rajeev
  2022-09-21 14:52 ` [PATCH V2 3/3] tools/testing/selftests/powerpc: Update the bhrb filter sampling test to test for multiple branch filters Athira Rajeev
@ 2022-10-04 13:25 ` Michael Ellerman
  2 siblings, 0 replies; 7+ messages in thread
From: Michael Ellerman @ 2022-10-04 13:25 UTC (permalink / raw)
  To: jolsa, Athira Rajeev, acme, mpe
  Cc: maddy, rnsastry, kjain, linux-perf-users, disgoel, linuxppc-dev

On Wed, 21 Sep 2022 20:22:53 +0530, Athira Rajeev wrote:
> 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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-10-04 13:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-21 14:52 [PATCH V2 1/3] powerpc/perf: Fix branch_filter support for multiple filters in powerpc Athira Rajeev
2022-09-21 14:52 ` [PATCH V2 2/3] tools/perf/tests: Fix branch stack sampling test to include sanity check for branch filter Athira Rajeev
2022-09-28 14:27   ` Athira Rajeev
2022-09-28 14:29   ` Arnaldo Carvalho de Melo
2022-09-29  5:35     ` Michael Ellerman
2022-09-21 14:52 ` [PATCH V2 3/3] tools/testing/selftests/powerpc: Update the bhrb filter sampling test to test for multiple branch filters Athira Rajeev
2022-10-04 13:25 ` (subset) [PATCH V2 1/3] powerpc/perf: Fix branch_filter support for multiple filters in powerpc Michael Ellerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).