powerpc/perf: Fix branch_filter support for multiple filters in powerpc
Subsystems (3)
PATCH 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'
--- arch/powerpc/perf/core-book3s.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
arch/powerpc/perf/core-book3s.c +15 -0
@@ -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);
Signature · 1 line
2.31.1
PATCH 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.
--- tools/perf/tests/shell/test_brstack.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/tests/shell/test_brstack.sh +2 -1
@@ -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
Re: [PATCH 2/3] tools/perf/tests: Fix branch stack sampling test to include sanity check for branch filter
Quoted 18 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/null2>&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.
Quoted 3 lines
Fixes b55878c90ab9 ("perf test: Add test for branch stack sampling")Reported-by Disha Goel <[email protected]>Signed-off-by Athira Rajeev <[email protected]>
Patch looks good to me.
Thanks,
Kajol Jain
Quoted 18 lines
--- tools/perf/tests/shell/test_brstack.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)tools/perf/tests/shell/test_brstack.sh +2
-1@@ -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)
PATCH 3/3 tools/testing/selftests/powerpc: Update the bhrb filter sampling test to test for multiple branch filters
In reply to Athira RajeevFor 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.
--- .../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
@@ -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 ; }
Signature · 1 line
2.31.1
Re: [PATCH 3/3] tools/testing/selftests/powerpc: Update the bhrb filter sampling test to test for multiple branch filters
Quoted 18 lines · Athira Rajeev
For
PERF_SAMPLE_BRANCH_STACKsample type, differentbranch_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 duringperf_event_open.Reported-by Disha Goel <[email protected]>Signed-off-by Athira Rajeev <[email protected]>--- .../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 +0
-0
tools/testing/selftests/powerpc/pmu/sampling_tests/bhrb_filter_map_test.c static int bhrb_filter_map_test(void) · line 98
Quoted 3 lines
tools/testing/selftests/powerpc/pmu/sampling_tests/bhrb_filter_map_test.c +0
-0@@ -96,6 +96,15 @@ static int bhrb_filter_map_test(void) } }
Patch looks good to me.
Thanks,
Kajol Jain
Quoted 12 lines
tools/testing/selftests/powerpc/pmu/sampling_tests/bhrb_filter_map_test.c +9
-0+/* +* 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 ; }
Quoted 32 lines · Athira Rajeev
For
PERF_SAMPLE_BRANCH_STACKsample type, differentbranch_sample_typeie 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 truePowerpc 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 trueThe "
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_initto 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'
Quoted 3 lines
Reported-by Disha Goel<[email protected]>Signed-off-by Athira Rajeev<[email protected]>Reviewed-by Madhavan Srinivasan<[email protected]>
Quoted 30 lines
--- arch/powerpc/perf/core-book3s.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)arch/powerpc/perf/core-book3s.c +15
-0@@ -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);
kajoljain
Reviewed-byQuoted 34 lines · Disha Goel
Quoted 32 lines · Athira Rajeev
For
PERF_SAMPLE_BRANCH_STACKsample type, differentbranch_sample_typeie 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 truePowerpc 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 trueThe "
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_initto 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'
Quoted 5 lines
Quoted 3 lines
Reported-by Disha Goel <[email protected]>Signed-off-by Athira Rajeev <[email protected]>Reviewed-by Madhavan Srinivasan <[email protected]>Tested-by Disha Goel <[email protected]>
Patch looks good to me.
Thanks,
Kajol Jain
Quoted 31 lines
Quoted 31 lines
--- arch/powerpc/perf/core-book3s.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)arch/powerpc/perf/core-book3s.c +15
-0@@ -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);