Skip to contentSkip to conversation

perf metrics: Avoid segv if default metricgroup isn't set

PATCH Applied Ian Rogers 4 participants 12 messages Dec 4, 2023 – Dec 5, 2023

Subsystems (2)
lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/2 perf metrics: Avoid segv if default metricgroup isn't set

A metric is default by having "Default" within its groups. The default metricgroup name needn't be set and this can result in segv in default_metricgroup_cmp and perf_stat__print_shadow_stats_metricgroup that assume it has a value when there is a Default metric group. To avoid the segv initialize the value to "".

Fixes 1c0e47956a8e ("perf metrics: Sort the Default metricgroup")
---
 tools/perf/util/metricgroup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/metricgroup.c +1 -1
index 0484736d9fe4..ca3e0404f187 100644
@@ -225,7 +225,7 @@ static struct metric *metric__new(const struct pmu_metric *pm,
 
 	m->pmu = pm->pmu ?: "cpu";
 	m->metric_name = pm->metric_name;
-	m->default_metricgroup_name = pm->default_metricgroup_name;
+	m->default_metricgroup_name = pm->default_metricgroup_name ?: "";
 	m->modifier = NULL;
 	if (modifier) {
 		m->modifier = strdup(modifier);
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
author reviewer
#1 lore raw

PATCH 2/2 perf vendor events arm64: Fix default AmpereOne metrics

Add default metric group name for TopdownL1 metrics.

Fixes 59faeaf80d02 ("perf vendor events arm64: Fix for AmpereOne metrics")
---
 tools/perf/pmu-events/arch/arm64/ampere/ampereone/metrics.json | 2 ++
 1 file changed, 2 insertions(+)
tools/perf/pmu-events/arch/arm64/ampere/ampereone/metrics.json +2 -0
index e2848a9d4848..afcdad58ef89 100644
@@ -231,6 +231,7 @@
         "MetricName": "slots_lost_misspeculation_fraction",
         "MetricExpr": "100 * ((OP_SPEC - OP_RETIRED) / (CPU_CYCLES * #slots))",
         "BriefDescription": "Fraction of slots lost due to misspeculation",
+        "DefaultMetricgroupName": "TopdownL1",
         "MetricGroup": "Default;TopdownL1",
         "ScaleUnit": "1percent of slots"
     },
@@ -238,6 +239,7 @@
         "MetricName": "retired_fraction",
         "MetricExpr": "100 * (OP_RETIRED / (CPU_CYCLES * #slots))",
         "BriefDescription": "Fraction of slots retiring, useful work",
+        "DefaultMetricgroupName": "TopdownL1",
         "MetricGroup": "Default;TopdownL1",
 	"ScaleUnit": "1percent of slots"
     },
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#2 lore raw
In reply to Ian Rogers
Quoted 8 lines · Ian Rogers

A metric is default by having "Default" within its groups. The default metricgroup name needn't be set and this can result in segv in default_metricgroup_cmp and perf_stat__print_shadow_stats_metricgroup that assume it has a value when there is a Default metric group. To avoid the segv initialize the value to "".

Fixes 1c0e47956a8e ("perf metrics: Sort the Default metricgroup")

Thanks! I was going to look for the bug but got pulled to other tasks. The patch looks good to me and I tested it successfully on AmpereOne.

Cheers, Ilkka

Quoted 21 lines

---
tools/perf/util/metricgroup.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/metricgroup.c +1 -1
index 0484736d9fe4..ca3e0404f187 100644
@@ -225,7 +225,7 @@ static struct metric *metric__new(const struct pmu_metric *pm,
 
 	m->pmu = pm->pmu ?: "cpu";
 	m->metric_name = pm->metric_name;
-	m->default_metricgroup_name = pm->default_metricgroup_name;
+	m->default_metricgroup_name = pm->default_metricgroup_name ?: "";
 	m->modifier = NULL;
 	if (modifier) {
 		m->modifier = strdup(modifier);
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
maintainer
#3 lore raw

Hello,

Quoted 10 lines · Ilkka Koskinen
Quoted 6 lines · Ian Rogers

A metric is default by having "Default" within its groups. The default metricgroup name needn't be set and this can result in segv in default_metricgroup_cmp and perf_stat__print_shadow_stats_metricgroup that assume it has a value when there is a Default metric group. To avoid the segv initialize the value to "".

Quoted 8 lines
Quoted 2 lines
Fixes 1c0e47956a8e ("perf metrics: Sort the Default metricgroup")

Thanks! I was going to look for the bug but got pulled to other tasks. The patch looks good to me and I tested it successfully on AmpereOne.

Looks like it needs to go through perf-tools for v6.7. Ian, do you think this one is enough?

Thanks,
Namhyung

author reviewer
#4 lore raw
Quoted 18 lines · Namhyung Kim

Hello,

Quoted 13 lines · Ilkka Koskinen
Quoted 8 lines · Ian Rogers

A metric is default by having "Default" within its groups. The default metricgroup name needn't be set and this can result in segv in default_metricgroup_cmp and perf_stat__print_shadow_stats_metricgroup that assume it has a value when there is a Default metric group. To avoid the segv initialize the value to "".

Fixes 1c0e47956a8e ("perf metrics: Sort the Default metricgroup")
Quoted 8 lines
Quoted 5 lines

Thanks! I was going to look for the bug but got pulled to other tasks. The patch looks good to me and I tested it successfully on AmpereOne.

Looks like it needs to go through perf-tools for v6.7. Ian, do you think this one is enough?

From a user's pov the json fix is nicer as otherwise perf stat output for the relevant metrics lacks a heading on the left. This fix is smaller. I'm easy about which to take :-)

Thanks,
Ian

Quoted 2 lines

Thanks,
Namhyung

#5 lore raw
In reply to Namhyung Kim

Em Mon, Dec 04, 2023 at 07:33:18PM -0800, Namhyung Kim escreveu:

Quoted 11 lines · Ilkka Koskinen
Quoted 9 lines · Ian Rogers
Quoted 8 lines

A metric is default by having "Default" within its groups. The default metricgroup name needn't be set and this can result in segv in default_metricgroup_cmp and perf_stat__print_shadow_stats_metricgroup that assume it has a value when there is a Default metric group. To avoid the segv initialize the value to "".

Fixes 1c0e47956a8e ("perf metrics: Sort the Default metricgroup")
Quoted 8 lines
Quoted 5 lines

Thanks! I was going to look for the bug but got pulled to other tasks. The patch looks good to me and I tested it successfully on AmpereOne.

Looks like it needs to go through perf-tools for v6.7. Ian, do you think this one is enough?

So I had this on my local perf-tools-next, removed now, I also have some other fixes by Ian on the tmp.perf-tools-next, please let me know what you guys decide to have in perf-tools for v6.7 so that I can remove it from there.

- Arnaldo

maintainer
#6 lore raw

Hi Arnaldo,

Quoted 19 lines · Arnaldo Carvalho de Melo

Em Mon, Dec 04, 2023 at 07:33:18PM -0800, Namhyung Kim escreveu:

Quoted 16 lines · Ilkka Koskinen
Quoted 15 lines · Ian Rogers
Quoted 8 lines

A metric is default by having "Default" within its groups. The default metricgroup name needn't be set and this can result in segv in default_metricgroup_cmp and perf_stat__print_shadow_stats_metricgroup that assume it has a value when there is a Default metric group. To avoid the segv initialize the value to "".

Fixes 1c0e47956a8e ("perf metrics: Sort the Default metricgroup")

Thanks! I was going to look for the bug but got pulled to other tasks. The patch looks good to me and I tested it successfully on AmpereOne.

Quoted 7 lines
Quoted 2 lines

Looks like it needs to go through perf-tools for v6.7. Ian, do you think this one is enough?

So I had this on my local perf-tools-next, removed now, I also have some other fixes by Ian on the tmp.perf-tools-next, please let me know what you guys decide to have in perf-tools for v6.7 so that I can remove it from there.

I think we need this one and the Ampere default-metric-group fix.

https://lore.kernel.org/r/[email protected]/

Also perf list JSON fix can go to v6.7.

https://lore.kernel.org/r/[email protected]/

Thanks,
Namhyung

#7 lore raw

Em Tue, Dec 05, 2023 at 09:24:42AM -0800, Namhyung Kim escreveu:

Quoted 30 lines

Hi Arnaldo,

Quoted 19 lines · Arnaldo Carvalho de Melo

Em Mon, Dec 04, 2023 at 07:33:18PM -0800, Namhyung Kim escreveu:

Quoted 16 lines · Ilkka Koskinen
Quoted 15 lines · Ian Rogers
Quoted 8 lines

A metric is default by having "Default" within its groups. The default metricgroup name needn't be set and this can result in segv in default_metricgroup_cmp and perf_stat__print_shadow_stats_metricgroup that assume it has a value when there is a Default metric group. To avoid the segv initialize the value to "".

Fixes 1c0e47956a8e ("perf metrics: Sort the Default metricgroup")

Thanks! I was going to look for the bug but got pulled to other tasks. The patch looks good to me and I tested it successfully on AmpereOne.

Quoted 7 lines
Quoted 2 lines

Looks like it needs to go through perf-tools for v6.7. Ian, do you think this one is enough?

So I had this on my local perf-tools-next, removed now, I also have some other fixes by Ian on the tmp.perf-tools-next, please let me know what you guys decide to have in perf-tools for v6.7 so that I can remove it from there.

Quoted 7 lines

I think we need this one and the Ampere default-metric-group fix.

https://lore.kernel.org/r/[email protected]/

Also perf list JSON fix can go to v6.7.

https://lore.kernel.org/r/[email protected]/

Ok, removed both, please augment the later description to:

"perf list: Fix JSON segfault by setting the used skip_fuplicate_pmus callback"

The original description was vague, improving it a bit like that helps when just looking at the output of "git log --oneline".

Thanks,

- Arnaldo

maintainer
#8 lore raw
Quoted 38 lines · Arnaldo Carvalho de Melo

Em Tue, Dec 05, 2023 at 09:24:42AM -0800, Namhyung Kim escreveu:

Quoted 36 lines

Hi Arnaldo,

Quoted 19 lines · Arnaldo Carvalho de Melo

Em Mon, Dec 04, 2023 at 07:33:18PM -0800, Namhyung Kim escreveu:

Quoted 16 lines · Ilkka Koskinen
Quoted 15 lines · Ian Rogers
Quoted 8 lines

A metric is default by having "Default" within its groups. The default metricgroup name needn't be set and this can result in segv in default_metricgroup_cmp and perf_stat__print_shadow_stats_metricgroup that assume it has a value when there is a Default metric group. To avoid the segv initialize the value to "".

Fixes 1c0e47956a8e ("perf metrics: Sort the Default metricgroup")

Thanks! I was going to look for the bug but got pulled to other tasks. The patch looks good to me and I tested it successfully on AmpereOne.

Quoted 7 lines
Quoted 2 lines

Looks like it needs to go through perf-tools for v6.7. Ian, do you think this one is enough?

So I had this on my local perf-tools-next, removed now, I also have some other fixes by Ian on the tmp.perf-tools-next, please let me know what you guys decide to have in perf-tools for v6.7 so that I can remove it from there.

I think we need this one and the Ampere default-metric-group fix.

https://lore.kernel.org/r/[email protected]/

Also perf list JSON fix can go to v6.7.

Quoted 8 lines
Quoted 1 line

https://lore.kernel.org/r/[email protected]/

Ok, removed both, please augment the later description to:

"perf list: Fix JSON segfault by setting the used skip_fuplicate_pmus callback"

The original description was vague, improving it a bit like that helps when just looking at the output of "git log --oneline".

Done and pushed to tmp.perf-tools!

Thanks,
Namhyung

author reviewer
#9 lore raw
Quoted 43 lines · Namhyung Kim
Quoted 40 lines · Arnaldo Carvalho de Melo

Em Tue, Dec 05, 2023 at 09:24:42AM -0800, Namhyung Kim escreveu:

Quoted 37 lines

Hi Arnaldo,

Quoted 19 lines · Arnaldo Carvalho de Melo

Em Mon, Dec 04, 2023 at 07:33:18PM -0800, Namhyung Kim escreveu:

Quoted 16 lines · Ilkka Koskinen
Quoted 15 lines · Ian Rogers
Quoted 8 lines

A metric is default by having "Default" within its groups. The default metricgroup name needn't be set and this can result in segv in default_metricgroup_cmp and perf_stat__print_shadow_stats_metricgroup that assume it has a value when there is a Default metric group. To avoid the segv initialize the value to "".

Fixes 1c0e47956a8e ("perf metrics: Sort the Default metricgroup")

Thanks! I was going to look for the bug but got pulled to other tasks. The patch looks good to me and I tested it successfully on AmpereOne.

Quoted 7 lines
Quoted 2 lines

Looks like it needs to go through perf-tools for v6.7. Ian, do you think this one is enough?

So I had this on my local perf-tools-next, removed now, I also have some other fixes by Ian on the tmp.perf-tools-next, please let me know what you guys decide to have in perf-tools for v6.7 so that I can remove it from there.

I think we need this one and the Ampere default-metric-group fix.

https://lore.kernel.org/r/[email protected]/

Also perf list JSON fix can go to v6.7.

https://lore.kernel.org/r/[email protected]/

Quoted 8 lines
Quoted 6 lines

Ok, removed both, please augment the later description to:

"perf list: Fix JSON segfault by setting the used skip_fuplicate_pmus callback"

The original description was vague, improving it a bit like that helps when just looking at the output of "git log --oneline".

Done and pushed to tmp.perf-tools!

Thanks Namhyung, there was a typo in Arnaldo's commit message "s/fuplicate/duplicate/" could you fix?

Ian

Quoted 2 lines

Thanks,
Namhyung

maintainer
#10 lore raw
Quoted 8 lines · Ian Rogers
Quoted 6 lines · Namhyung Kim
Quoted 2 lines · Arnaldo Carvalho de Melo

"perf list: Fix JSON segfault by setting the used skip_fuplicate_pmus callback"

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

The original description was vague, improving it a bit like that helps when just looking at the output of "git log --oneline".

Done and pushed to tmp.perf-tools!

Thanks Namhyung, there was a typo in Arnaldo's commit message "s/fuplicate/duplicate/" could you fix?

Oops, fixed now. Thanks for checking.
Namhyung

maintainer Applied
#11 lore raw
In reply to Ilkka Koskinen

Em Mon, Dec 04, 2023 at 02:44:54PM -0800, Ilkka Koskinen escreveu:

Quoted 9 lines · Ian Rogers
Quoted 6 lines

A metric is default by having "Default" within its groups. The default metricgroup name needn't be set and this can result in segv in default_metricgroup_cmp and perf_stat__print_shadow_stats_metricgroup that assume it has a value when there is a Default metric group. To avoid the segv initialize the value to "".

Quoted 7 lines
Quoted 2 lines
Fixes 1c0e47956a8e ("perf metrics: Sort the Default metricgroup")

Thanks! I was going to look for the bug but got pulled to other tasks. The patch looks good to me and I tested it successfully on AmpereOne.

Thanks, applied to perf-tools-next.

- Arnaldo