linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] powerpc/perf: Fix branch_filter support for multiple filters in powerpc
@ 2022-09-13 11:55 Athira Rajeev
  2022-09-13 11:55 ` [PATCH 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; 6+ messages in thread
From: Athira Rajeev @ 2022-09-13 11:55 UTC (permalink / raw)
  To: acme, jolsa, mpe
  Cc: linux-perf-users, linuxppc-dev, maddy, rnsastry, kjain, disgoel

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>
---
 arch/powerpc/perf/core-book3s.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c
index 13919eb96931..2c2d235cb8d8 100644
--- a/arch/powerpc/perf/core-book3s.c
+++ b/arch/powerpc/perf/core-book3s.c
@@ -2131,6 +2131,21 @@ 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)
+			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] 6+ messages in thread

* [PATCH 2/3] tools/perf/tests: Fix branch stack sampling test to include sanity check for branch filter
  2022-09-13 11:55 [PATCH 1/3] powerpc/perf: Fix branch_filter support for multiple filters in powerpc Athira Rajeev
@ 2022-09-13 11:55 ` Athira Rajeev
  2022-09-16 13:06   ` kajoljain
  2022-09-13 11:55 ` [PATCH 3/3] tools/testing/selftests/powerpc: Update the bhrb filter sampling test to test for multiple branch filters Athira Rajeev
       [not found] ` <ea4db5b9-ac85-ada0-5940-23255b4106da@linux.ibm.com>
  2 siblings, 1 reply; 6+ messages in thread
From: Athira Rajeev @ 2022-09-13 11:55 UTC (permalink / raw)
  To: acme, jolsa, mpe
  Cc: linux-perf-users, linuxppc-dev, maddy, rnsastry, kjain, disgoel

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>
---
 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] 6+ messages in thread

* [PATCH 3/3] tools/testing/selftests/powerpc: Update the bhrb filter sampling test to test for multiple branch filters
  2022-09-13 11:55 [PATCH 1/3] powerpc/perf: Fix branch_filter support for multiple filters in powerpc Athira Rajeev
  2022-09-13 11:55 ` [PATCH 2/3] tools/perf/tests: Fix branch stack sampling test to include sanity check for branch filter Athira Rajeev
@ 2022-09-13 11:55 ` Athira Rajeev
  2022-09-16 13:07   ` kajoljain
       [not found] ` <ea4db5b9-ac85-ada0-5940-23255b4106da@linux.ibm.com>
  2 siblings, 1 reply; 6+ messages in thread
From: Athira Rajeev @ 2022-09-13 11:55 UTC (permalink / raw)
  To: acme, jolsa, mpe
  Cc: linux-perf-users, linuxppc-dev, maddy, rnsastry, kjain, disgoel

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>
---
 .../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..605669d4e4cb 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 save_type
+	 * (PERF_SAMPLE_BRANCH_TYPE_SAVE).
+	 * The perf_event_open should fail in this case.
+	 */
+	event.attr.branch_sample_type = PERF_SAMPLE_BRANCH_ANY | PERF_SAMPLE_BRANCH_TYPE_SAVE;
+	FAIL_IF(!event_open(&event));
+
 	return 0;
 }
 
-- 
2.31.1


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

* Re: [PATCH 1/3] powerpc/perf: Fix branch_filter support for multiple filters in powerpc
       [not found] ` <ea4db5b9-ac85-ada0-5940-23255b4106da@linux.ibm.com>
@ 2022-09-16 13:06   ` kajoljain
  0 siblings, 0 replies; 6+ messages in thread
From: kajoljain @ 2022-09-16 13:06 UTC (permalink / raw)
  To: Disha Goel, Athira Rajeev, acme, jolsa, mpe
  Cc: linux-perf-users, linuxppc-dev, maddy, rnsastry, disgoel



On 9/16/22 17:02, Disha Goel wrote:
> 
> On 9/13/22 5:25 PM, 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
>>
>> 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>

Patch looks good to me.

Reviewed-By: Kajol Jain <kjain@linux.ibm.com>

Thanks,
Kajol Jain

> 
>> ---
>>  arch/powerpc/perf/core-book3s.c | 15 +++++++++++++++
>>  1 file changed, 15 insertions(+)
>>
>> diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c
>> index 13919eb96931..2c2d235cb8d8 100644
>> --- a/arch/powerpc/perf/core-book3s.c
>> +++ b/arch/powerpc/perf/core-book3s.c
>> @@ -2131,6 +2131,21 @@ 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)
>> +			return -EOPNOTSUPP;
>> +
>>  		if (ppmu->bhrb_filter_map)
>>  			bhrb_filter = ppmu->bhrb_filter_map(
>>  					event->attr.branch_sample_type);

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

* Re: [PATCH 2/3] tools/perf/tests: Fix branch stack sampling test to include sanity check for branch filter
  2022-09-13 11:55 ` [PATCH 2/3] tools/perf/tests: Fix branch stack sampling test to include sanity check for branch filter Athira Rajeev
@ 2022-09-16 13:06   ` kajoljain
  0 siblings, 0 replies; 6+ messages in thread
From: kajoljain @ 2022-09-16 13:06 UTC (permalink / raw)
  To: Athira Rajeev, acme, jolsa, mpe
  Cc: linux-perf-users, linuxppc-dev, maddy, rnsastry, disgoel



On 9/13/22 17:25, Athira Rajeev 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>

Patch looks good to me.

Reviewed-By: Kajol Jain <kjain@linux.ibm.com>

Thanks,
Kajol Jain

> ---
>  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)
>  

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

* Re: [PATCH 3/3] tools/testing/selftests/powerpc: Update the bhrb filter sampling test to test for multiple branch filters
  2022-09-13 11:55 ` [PATCH 3/3] tools/testing/selftests/powerpc: Update the bhrb filter sampling test to test for multiple branch filters Athira Rajeev
@ 2022-09-16 13:07   ` kajoljain
  0 siblings, 0 replies; 6+ messages in thread
From: kajoljain @ 2022-09-16 13:07 UTC (permalink / raw)
  To: Athira Rajeev, acme, jolsa, mpe
  Cc: maddy, rnsastry, linux-perf-users, disgoel, linuxppc-dev



On 9/13/22 17:25, Athira Rajeev wrote:
> 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>
> ---
>  .../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..605669d4e4cb 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)
>  		}
>  	}
>  

Patch looks good to me.

Reviewed-By: Kajol Jain <kjain@linux.ibm.com>

Thanks,
Kajol Jain


> +	/*
> +	 * Combine filter maps which includes a valid branch filter and an invalid branch
> +	 * filter. Example: any ( PERF_SAMPLE_BRANCH_ANY) and save_type
> +	 * (PERF_SAMPLE_BRANCH_TYPE_SAVE).
> +	 * The perf_event_open should fail in this case.
> +	 */
> +	event.attr.branch_sample_type = PERF_SAMPLE_BRANCH_ANY | PERF_SAMPLE_BRANCH_TYPE_SAVE;
> +	FAIL_IF(!event_open(&event));
> +
>  	return 0;
>  }
>  

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

end of thread, other threads:[~2022-09-16 13:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-13 11:55 [PATCH 1/3] powerpc/perf: Fix branch_filter support for multiple filters in powerpc Athira Rajeev
2022-09-13 11:55 ` [PATCH 2/3] tools/perf/tests: Fix branch stack sampling test to include sanity check for branch filter Athira Rajeev
2022-09-16 13:06   ` kajoljain
2022-09-13 11:55 ` [PATCH 3/3] tools/testing/selftests/powerpc: Update the bhrb filter sampling test to test for multiple branch filters Athira Rajeev
2022-09-16 13:07   ` kajoljain
     [not found] ` <ea4db5b9-ac85-ada0-5940-23255b4106da@linux.ibm.com>
2022-09-16 13:06   ` [PATCH 1/3] powerpc/perf: Fix branch_filter support for multiple filters in powerpc kajoljain

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).