tools/perf/metricgroup: Fix printing event names of metric group with multiple events
PATCH 1/1 tools/perf/metricgroup: Fix printing event names of metric group with multiple events
Commit f01642e4912b ("perf metricgroup: Support multiple events for metricgroup") introduced support for multiple events in a metric group. But with the current upstream, metric events names are not printed properly
In power9 platform:
command:# ./perf stat --metric-only -M translation -C 0 -I 1000 sleep 2
1.000208486
2.000368863
2.001400558Similarly in skylake platform:
command:./perf stat --metric-only -M Power -I 1000
1.000579994
2.002189493With current upstream version, issue is with event name comparison logic in find_evsel_group(). Current logic is to compare events belonging to a metric group to the events in perf_evlist. Since the break statement is missing in the loop used for comparison between metric group and perf_evlist events, the loop continues to execute even after getting a pattern match, and end up in discarding the matches.
Incase of single metric event belongs to metric group, its working fine, because in case of single event once it compare all events it reaches to end of perf_evlist.
Example for single metric event in power9 platform
command:# ./perf stat --metric-only -M branches_per_inst -I 1000 sleep 1
1.000094653 0.2
1.001337059 0.0Patch fixes the issue by making sure once we found all events belongs to that metric event matched in find_evsel_group(), we successfully break from that loop by adding corresponding condition.
With this patch:
In power9 platform:
command:# ./perf stat --metric-only -M translation -C 0 -I 1000 sleep 2
result:# time derat_4k_miss_rate_percent derat_4k_miss_ratio
derat_miss_ratio derat_64k_miss_rate_percent derat_64k_miss_ratio
dslb_miss_rate_percent islb_miss_rate_percent
1.000135672 0.0 0.3
1.0 0.0 0.2
0.0 0.0
2.000380617 0.0 0.0
0.0 0.0
0.0 0.0
command:# ./perf stat --metric-only -M Power -I 1000
Similarly in skylake platform:
result:# time Turbo_Utilization C3_Core_Residency
C6_Core_Residency C7_Core_Residency C2_Pkg_Residency
C3_Pkg_Residency C6_Pkg_Residency C7_Pkg_Residency
1.000563580 0.3 0.0 2.6 44.2 21.9
0.0 0.0 0.0
2.002235027 0.4 0.0
2.7 43.0 20.7
0.0 0.0 0.0
--- tools/perf/util/metricgroup.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
tools/perf/util/metricgroup.c +5 -2
@@ -103,8 +103,11 @@ static struct evsel *find_evsel_group(struct evlist *perf_evlist,if (!strcmp (ev->name, ids[i])) {if (!metric_events[i]) metric_events[i] = ev; + i++; +if (i == idnum) +break ; }else { -if (++i == idnum) { +if (i +1 == idnum) {/* Discard the whole match and start again */ i =0 ; memset(metric_events, 0,
@@ -124,7 +127,7 @@ static struct evsel *find_evsel_group(struct evlist *perf_evlist, } } -if (i != idnum -1 ) { +if (i != idnum) {/* Not whole match */ return NULL ; }
Signature · 1 line
2.21.0
Quoted 63 lines · Kajol Jain
Commit
f01642e4912b("perf metricgroup: Support multiple events for metricgroup") introduced support for multiple events in a metric group. But with the current upstream, metric events names are not printed properlyIn power9 platform:
command:# ./perf stat --metric-only -M translation -C 0 -I 1000 sleep 21.000208486 2.000368863 2.001400558Similarly in skylake platform:
command:./perf stat --metric-only -M Power -I 10001.000579994 2.002189493With current upstream version, issue is with event name comparison logic in
find_evsel_group(). Current logic is to compare events belonging to a metric group to the events inperf_evlist. Since the break statement is missing in the loop used for comparison between metric group andperf_evlistevents, the loop continues to execute even after getting a pattern match, and end up in discarding the matches.
Incase of single metric event belongs to metric group, its working fine, because in case of single event once it compare all events it reaches to end ofperf_evlist.Example for single metric event in power9 platform
command:# ./perf stat --metric-only -Mbranches_per_inst-I 1000 sleep 11.000094653 0.2 1.001337059 0.0Patch fixes the issue by making sure once we found all events belongs to that metric event matched in
find_evsel_group(), we successfully break from that loop by adding corresponding condition.With this patch:
In power9 platform:command:# ./perf stat --metric-only -M translation -C 0 -I 1000 sleep 2
result:# timederat_4k_miss_rate_percentderat_4k_miss_ratio
derat_miss_ratioderat_64k_miss_rate_percentderat_64k_miss_ratio
dslb_miss_rate_percentislb_miss_rate_percent
1.000135672 0.0 0.3
1.0 0.0 0.2
0.0 0.0
2.000380617 0.0 0.0
0.0 0.0
0.0 0.0command:# ./perf stat --metric-only -M Power -I 1000
Similarly in skylake platform:
result:# timeTurbo_UtilizationC3_Core_ResidencyC6_Core_Residency C7_Core_Residency C2_Pkg_Residency C3_Pkg_Residency C6_Pkg_Residency C7_Pkg_Residency 1.000563580 0.3 0.02.6 44.2 21.9
0.0 0.0 0.0
2.002235027 0.4 0.0
2.7 43.0 20.7
0.0 0.0 0.0
Quoted 10 lines
Signed-off-by Kajol Jain <[email protected]>Cc Alexander Shishkin <[email protected]>Cc Andi Kleen <[email protected]>Cc Jiri Olsa <[email protected]>Cc Kan Liang <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Jin Yao <[email protected]>Cc Madhavan Srinivasan <[email protected]>Cc Anju T Sudhakar <[email protected]>Cc Ravi Bangoria <[email protected]>
But while looking at the patch, I found that, commit f01642e4912b has (again) screwed up logic for metric with overlapping events.
$ sudo ./perf stat -M UPI,IPC sleep 1
Performance counter stats for 'sleep 1':
948,650 uops_retired.retire_slots
866,182 inst_retired.any # 0.7 IPC
866,182 inst_retired.any
1,175,671 cpu_clk_unhalted.threadThis also needs to be fixed.
Ravi
Em Wed, Dec 04, 2019 at 12:25:22PM +0530, Ravi Bangoria escreveu:
Quoted 77 lines · Kajol Jain
Quoted 63 lines
Commit
f01642e4912b("perf metricgroup: Support multiple events for metricgroup") introduced support for multiple events in a metric group. But with the current upstream, metric events names are not printed properlyIn power9 platform:
command:# ./perf stat --metric-only -M translation -C 0 -I 1000 sleep 21.000208486 2.000368863 2.001400558Similarly in skylake platform:
command:./perf stat --metric-only -M Power -I 10001.000579994 2.002189493With current upstream version, issue is with event name comparison logic in
find_evsel_group(). Current logic is to compare events belonging to a metric group to the events inperf_evlist. Since the break statement is missing in the loop used for comparison between metric group andperf_evlistevents, the loop continues to execute even after getting a pattern match, and end up in discarding the matches.
Incase of single metric event belongs to metric group, its working fine, because in case of single event once it compare all events it reaches to end ofperf_evlist.Example for single metric event in power9 platform
command:# ./perf stat --metric-only -Mbranches_per_inst-I 1000 sleep 11.000094653 0.2 1.001337059 0.0Patch fixes the issue by making sure once we found all events belongs to that metric event matched in
find_evsel_group(), we successfully break from that loop by adding corresponding condition.With this patch:
In power9 platform:command:# ./perf stat --metric-only -M translation -C 0 -I 1000 sleep 2
result:# timederat_4k_miss_rate_percentderat_4k_miss_ratio
derat_miss_ratioderat_64k_miss_rate_percentderat_64k_miss_ratio
dslb_miss_rate_percentislb_miss_rate_percent
1.000135672 0.0 0.3
1.0 0.0 0.2
0.0 0.0
2.000380617 0.0 0.0
0.0 0.0
0.0 0.0command:# ./perf stat --metric-only -M Power -I 1000
Similarly in skylake platform:
result:# timeTurbo_UtilizationC3_Core_ResidencyC6_Core_Residency C7_Core_Residency C2_Pkg_Residency C3_Pkg_Residency C6_Pkg_Residency C7_Pkg_Residency 1.000563580 0.3 0.02.6 44.2 21.9
0.0 0.0 0.0
2.002235027 0.4 0.0
2.7 43.0 20.7
0.0 0.0 0.0Quoted 10 lines
Signed-off-by Kajol Jain <[email protected]>Cc Alexander Shishkin <[email protected]>Cc Andi Kleen <[email protected]>Cc Jiri Olsa <[email protected]>Cc Kan Liang <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Jin Yao <[email protected]>Cc Madhavan Srinivasan <[email protected]>Cc Anju T Sudhakar <[email protected]>Cc Ravi Bangoria <[email protected]>
Quoted 2 lines
Fixes f01642e4912b ("perf metricgroup: Support multiple events for metricgroup")Reviewed-by Ravi Bangoria <[email protected]>
Tested on a Skylake machine and applied.
Quoted 2 lines
But while looking at the patch, I found that, commit
f01642e4912bhas (again) screwed up logic for metric with overlapping events.
Is someone looking into this?
Quoted 12 lines
$ sudo ./perf stat -M UPI,IPC sleep 1Performance counter stats for 'sleep 1': 948,650 uops_retired.retire_slots 866,182 inst_retired.any # 0.7 IPC 866,182 inst_retired.any 1,175,671 cpu_clk_unhalted.threadThis also needs to be fixed.
Ravi
Signature · 1 line
- Arnaldo
Quoted 4 lines
Quoted 2 lines
But while looking at the patch, I found that, commit
f01642e4912bhas (again) screwed up logic for metric with overlapping events.Is someone looking into this?
Looks like we really need some proper regression tests for this.
-Andi
Quoted 76 lines · Arnaldo Carvalho de Melo
Em Wed, Dec 04, 2019 at 12:25:22PM +0530, Ravi Bangoria escreveu:
Quoted 75 lines · Kajol Jain
Quoted 73 lines
Commit
f01642e4912b("perf metricgroup: Support multiple events for metricgroup") introduced support for multiple events in a metric group. But with the current upstream, metric events names are not printed properlyIn power9 platform:
command:# ./perf stat --metric-only -M translation -C 0 -I 1000 sleep 21.000208486 2.000368863 2.001400558Similarly in skylake platform:
command:./perf stat --metric-only -M Power -I 10001.000579994 2.002189493With current upstream version, issue is with event name comparison logic in
find_evsel_group(). Current logic is to compare events belonging to a metric group to the events inperf_evlist. Since the break statement is missing in the loop used for comparison between metric group andperf_evlistevents, the loop continues to execute even after getting a pattern match, and end up in discarding the matches.
Incase of single metric event belongs to metric group, its working fine, because in case of single event once it compare all events it reaches to end ofperf_evlist.Example for single metric event in power9 platform
command:# ./perf stat --metric-only -Mbranches_per_inst-I 1000 sleep 11.000094653 0.2 1.001337059 0.0Patch fixes the issue by making sure once we found all events belongs to that metric event matched in
find_evsel_group(), we successfully break from that loop by adding corresponding condition.With this patch:
In power9 platform:command:# ./perf stat --metric-only -M translation -C 0 -I 1000 sleep 2
result:# timederat_4k_miss_rate_percentderat_4k_miss_ratio
derat_miss_ratioderat_64k_miss_rate_percentderat_64k_miss_ratio
dslb_miss_rate_percentislb_miss_rate_percent
1.000135672 0.0 0.3
1.0 0.0 0.2
0.0 0.0
2.000380617 0.0 0.0
0.0 0.0
0.0 0.0command:# ./perf stat --metric-only -M Power -I 1000
Similarly in skylake platform:
result:# timeTurbo_UtilizationC3_Core_ResidencyC6_Core_Residency C7_Core_Residency C2_Pkg_Residency C3_Pkg_Residency C6_Pkg_Residency C7_Pkg_Residency 1.000563580 0.3 0.02.6 44.2 21.9
0.0 0.0 0.0
2.002235027 0.4 0.0
2.7 43.0 20.7
0.0 0.0 0.0Signed-off-by Kajol Jain <[email protected]>Cc Alexander Shishkin <[email protected]>Cc Andi Kleen <[email protected]>Cc Jiri Olsa <[email protected]>Cc Kan Liang <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Jin Yao <[email protected]>Cc Madhavan Srinivasan <[email protected]>Cc Anju T Sudhakar <[email protected]>Cc Ravi Bangoria <[email protected]>
Quoted 7 lines
Quoted 2 lines
Fixes f01642e4912b ("perf metricgroup: Support multiple events for metricgroup")Reviewed-by Ravi Bangoria <[email protected]>Tested on a Skylake machine and applied.
Quoted 2 lines
But while looking at the patch, I found that, commit
f01642e4912bhas (again) screwed up logic for metric with overlapping events.Is someone looking into this?
Hi Arnaldo,
I am looking into this issue and will post the fix soon.
Kajol
Quoted 13 lines
Quoted 13 lines
$ sudo ./perf stat -M UPI,IPC sleep 1Performance counter stats for 'sleep 1': 948,650 uops_retired.retire_slots 866,182 inst_retired.any # 0.7 IPC 866,182 inst_retired.any 1,175,671 cpu_clk_unhalted.threadThis also needs to be fixed.
Ravi
[tip: perf/urgent] perf metricgroup: Fix printing event names of metric group with multiple events
In reply to Kajol JainThe following commit has been merged into the perf/urgent branch of tip:
The following commit has been merged into the perf/urgent branch of tip:
Commit-ID: eb573e746b9d4f0921dcb2449be3df41dae3caea Gitweb: https://git.kernel.org/tip/eb573e746b9d4f0921dcb2449be3df41dae3caea Author: Kajol Jain <[email protected]> AuthorDate: Wed, 20 Nov 2019 14:10:59 +05:30 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Wed, 11 Dec 2019 12:28:14 -03:00
perf metricgroup: Fix printing event names of metric group with multiple events
Commit f01642e4912b ("perf metricgroup: Support multiple events for metricgroup") introduced support for multiple events in a metric group. But with the current upstream, metric events names are not printed properly
In power9 platform:
command:# ./perf stat --metric-only -M translation -C 0 -I 1000 sleep 2
1.000208486
2.000368863
2.001400558Similarly in skylake platform:
command:./perf stat --metric-only -M Power -I 1000
1.000579994
2.002189493With current upstream version, issue is with event name comparison logic in find_evsel_group(). Current logic is to compare events belonging to a metric group to the events in perf_evlist. Since the break statement is missing in the loop used for comparison between metric group and perf_evlist events, the loop continues to execute even after getting a pattern match, and end up in discarding the matches.
Incase of single metric event belongs to metric group, its working fine, because in case of single event once it compare all events it reaches to end of perf_evlist.
Example for single metric event in power9 platform:
command:# ./perf stat --metric-only -M branches_per_inst -I 1000 sleep 1
1.000094653 0.2
1.001337059 0.0This patch fixes the issue by making sure once we found all events belongs to that metric event matched in find_evsel_group(), we successfully break from that loop by adding corresponding condition.
With this patch:
In power9 platform:
command:# ./perf stat --metric-only -M translation -C 0 -I 1000 sleep 2
result:#
time derat_4k_miss_rate_percent derat_4k_miss_ratio derat_miss_ratio derat_64k_miss_rate_percent derat_64k_miss_ratio dslb_miss_rate_percent islb_miss_rate_percent
1.000135672 0.0 0.3 1.0 0.0 0.2 0.0 0.0
2.000380617 0.0 0.0 0.0 0.0 0.0 0.0 0.0
command:# ./perf stat --metric-only -M Power -I 1000
Similarly in skylake platform:
result:#
time Turbo_Utilization C3_Core_Residency C6_Core_Residency C7_Core_Residency C2_Pkg_Residency C3_Pkg_Residency C6_Pkg_Residency C7_Pkg_Residency
1.000563580 0.3 0.0 2.6 44.2 21.9 0.0 0.0 0.0
2.002235027 0.4 0.0 2.7 43.0 20.7 0.0 0.0 0.0
Committer testing:
Before:
[root@seventh ~]# perf stat --metric-only -M Power -I 1000
# time
1.000383223
2.001168182
3.001968545
4.002741200
5.003442022
^C 5.777687244[root@seventh ~]#
After the patch:
[root@seventh ~]# perf stat --metric-only -M Power -I 1000
# time Turbo_Utilization C3_Core_Residency C6_Core_Residency C7_Core_Residency C2_Pkg_Residency C3_Pkg_Residency C6_Pkg_Residency C7_Pkg_Residency
1.000406577 0.4 0.1 1.4 97.0 0.0 0.0 0.0 0.0
2.001481572 0.3 0.0 0.6 97.9 0.0 0.0 0.0 0.0
3.002332585 0.2 0.0 1.0 97.5 0.0 0.0 0.0 0.0
4.003196624 0.2 0.0 0.3 98.6 0.0 0.0 0.0 0.0
5.004063851 0.3 0.0 0.7 97.7 0.0 0.0 0.0 0.0
^C 5.471260276 0.2 0.0 0.5 49.3 0.0 0.0 0.0 0.0 [root@seventh ~]#
[root@seventh ~]# dmesg | grep -i skylake
[ 0.187807] Performance Events: PEBS fmt3+, Skylake events, 32-deep LBR, full-width counters, Intel PMU driver. [root@seventh ~]#
--- tools/perf/util/metricgroup.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
tools/perf/util/metricgroup.c +5 -2
@@ -103,8 +103,11 @@ static struct evsel *find_evsel_group(struct evlist *perf_evlist,if (!strcmp (ev->name, ids[i])) {if (!metric_events[i]) metric_events[i] = ev; + i++; +if (i == idnum) +break ; }else { -if (++i == idnum) { +if (i +1 == idnum) {/* Discard the whole match and start again */ i =0 ; memset(metric_events, 0,
@@ -124,7 +127,7 @@ static struct evsel *find_evsel_group(struct evlist *perf_evlist, } } -if (i != idnum -1 ) { +if (i != idnum) {/* Not whole match */ return NULL ; }