Skip to contentSkip to conversation

perf metricgroup: Fix system PMU metrics

PATCH In review John Garry 4 participants 16 messages Jan 19, 2021 – Feb 6, 2021 perf events

lore
Share & tools
lore

John Garry

author
#0 lore raw

PATCH 1/1 perf metricgroup: Fix system PMU metrics

Joakim reports that getting "perf stat" for multiple system PMU metrics segfaults:
./perf stat -a -I 1000 -M imx8mm_ddr_write.all,imx8mm_ddr_write.all Segmentation fault

While the same works without issue for a single metric.

The logic in metricgroup__add_metric_sys_event_iter() is broken, in that add_metric() @m argument should be NULL for each new metric. Fix by not passing a holder for that, and rather make local in metricgroup__add_metric_sys_event_iter().

Fixes be335ec28efa ("perf metricgroup: Support adding metrics for system PMUs")
tools/perf/util/metricgroup.c +2 -3
index ee94d3e8dd65..2e60ee170abc 100644
@@ -766,7 +766,6 @@ int __weak arch_get_runtimeparam(struct pmu_event *pe __maybe_unused)
 struct metricgroup_add_iter_data {
 	struct list_head *metric_list;
 	const char *metric;
-	struct metric **m;
 	struct expr_ids *ids;
 	int *ret;
 	bool *has_match;
@@ -1058,12 +1057,13 @@ static int metricgroup__add_metric_sys_event_iter(struct pmu_event *pe,
 						  void *data)
 {
 	struct metricgroup_add_iter_data *d = data;
+	struct metric *m = NULL;
 	int ret;
 
 	if (!match_pe_metric(pe, d->metric))
 		return 0;
 
-	ret = add_metric(d->metric_list, pe, d->metric_no_group, d->m, NULL, d->ids);
+	ret = add_metric(d->metric_list, pe, d->metric_no_group, &m, NULL, d->ids);
 	if (ret)
 		return ret;
 
@@ -1114,7 +1114,6 @@ static int metricgroup__add_metric(const char *metric, bool metric_no_group,
 				.metric_list = &list,
 				.metric = metric,
 				.metric_no_group = metric_no_group,
-				.m = &m,
 				.ids = &ids,
 				.has_match = &has_match,
 				.ret = &ret,
Signature · 1 line
2.26.2
#1 lore raw
Quoted 24 lines

-----Original Message-----
From: John Garry <[email protected]>
Sent: 2021年1月19日 18:04
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; Joakim Zhang <[email protected]>; John Garry <[email protected]>
Subject: [PATCH] perf metricgroup: Fix system PMU metrics

Joakim reports that getting "perf stat" for multiple system PMU metrics segfaults:
./perf stat -a -I 1000 -M imx8mm_ddr_write.all,imx8mm_ddr_write.all Segmentation fault

While the same works without issue for a single metric.

The logic in metricgroup__add_metric_sys_event_iter() is broken, in that add_metric() @m argument should be NULL for each new metric. Fix by not passing a holder for that, and rather make local in metricgroup__add_metric_sys_event_iter().

Quoted 4 lines
Fixes be335ec28efa ("perf metricgroup: Support adding metrics for system

PMUs")

root@imx8mmevk:~# ./perf stat -a -I 1000 -M imx8mm_ddr_read.all,imx8mm_ddr_write                                                                                                    .all
#           time             counts unit events
     1.001446500              40832      imx8mm_ddr.read_cycles    #    638.0 KB  imx8mm_ddr_read.all
     1.001446500              16973      imx8mm_ddr.write_cycles   #    265.2 KB  imx8mm_ddr_write.all
     2.003150250              28836      imx8mm_ddr.read_cycles    #    450.6 KB  imx8mm_ddr_read.all
     2.003150250               6705      imx8mm_ddr.write_cycles   #    104.8 KB  imx8mm_ddr_write.all

For this issue, Tested-by: Joakim Zhang <[email protected]>

Hi John,

It seems have other issue compared to 5.10 kernel after switching to this framework, below metric can't work. "MetricExpr": "(( imx8_ddr0@read\\-cycles@ + imx8_ddr0@write\\-cycles@ ) * 4 * 4 / duration_time) / (750 * 1000000 * 4 * 4)" After change to:
"MetricExpr": "(( imx8mm_ddr.read_cycles + imx8mm_ddr.write_cycles ) * 4 * 4 / duration_time) / (750 * 1000000 * 4 * 4)",

Best Regards,
Joakim Zhang

Quoted 41 lines
tools/perf/util/metricgroup.c index renamed from tools/perf/util/metricgroup.c +0 -0

ee94d3e8dd65..2e60ee170abc 100644

tools/perf/util/metricgroup.c +3 -3
@@ -766,7 +766,6 @@ int __weak arch_get_runtimeparam(struct pmu_event
 *pe __maybe_unused)  struct metricgroup_add_iter_data {
 	struct list_head *metric_list;
 	const char *metric;
-	struct metric **m;
 	struct expr_ids *ids;
 	int *ret;
 	bool *has_match;
@@ -1058,12 +1057,13 @@ static int
 metricgroup__add_metric_sys_event_iter(struct pmu_event *pe,
 						  void *data)
 {
 	struct metricgroup_add_iter_data *d = data;
+	struct metric *m = NULL;
 	int ret;
 
 	if (!match_pe_metric(pe, d->metric))
 		return 0;
 
-	ret = add_metric(d->metric_list, pe, d->metric_no_group, d->m, NULL,
 d->ids);
+	ret = add_metric(d->metric_list, pe, d->metric_no_group, &m, NULL,
+d->ids);
 	if (ret)
 		return ret;
@@ -1114,7 +1114,6 @@ static int metricgroup__add_metric(const char
 *metric, bool metric_no_group,
 				.metric_list = &list,
 				.metric = metric,
 				.metric_no_group = metric_no_group,
-				.m = &m,
 				.ids = &ids,
 				.has_match = &has_match,

.ret = &ret,
--
2.26.2

author
#2 lore raw
Quoted 23 lines · Joakim Zhang
Quoted 12 lines

Joakim reports that getting "perf stat" for multiple system PMU metrics segfaults:
./perf stat -a -I 1000 -M imx8mm_ddr_write.all,imx8mm_ddr_write.all Segmentation fault

While the same works without issue for a single metric.

The logic in metricgroup__add_metric_sys_event_iter() is broken, in that add_metric() @m argument should be NULL for each new metric. Fix by not passing a holder for that, and rather make local in metricgroup__add_metric_sys_event_iter().

Quoted 4 lines
Fixes be335ec28efa ("perf metricgroup: Support adding metrics for system

PMUs")

root@imx8mmevk:~# ./perf stat -a -I 1000 -M imx8mm_ddr_read.all,imx8mm_ddr_write                                                                                                    .all
#           time             counts unit events
      1.001446500              40832      imx8mm_ddr.read_cycles    #    638.0 KB  imx8mm_ddr_read.all
      1.001446500              16973      imx8mm_ddr.write_cycles   #    265.2 KB  imx8mm_ddr_write.all
      2.003150250              28836      imx8mm_ddr.read_cycles    #    450.6 KB  imx8mm_ddr_read.all
      2.003150250               6705      imx8mm_ddr.write_cycles   #    104.8 KB  imx8mm_ddr_write.all
Quoted 8 lines

For this issue, Tested-by: Joakim Zhang<[email protected]>

Hi John,

It seems have other issue compared to 5.10 kernel after switching to this framework, below metric can't work. "MetricExpr": "(( imx8_ddr0@read\\-cycles@ + imx8_ddr0@write\\-cycles@ ) * 4 * 4 / duration_time) / (750 * 1000000 * 4 * 4)" After change to:
"MetricExpr": "(( imx8mm_ddr.read_cycles + imx8mm_ddr.write_cycles ) * 4 * 4 / duration_time) / (750 * 1000000 * 4 * 4)",

Hmmm... not sure what you mean by "compared to 5.10 kernel". As far as I'm concerned, none of this was supported in 5.10 and metrics did not work for arm64. Support for sys PMU events+metrics only came in 5.11-rc.

Anyway, can you share the full metric event which you say does not work, not just the "MetricExpr"?

Thanks,
John

#3 lore raw
Quoted 52 lines

-----Original Message-----
From: John Garry <[email protected]>
Sent: 2021年1月19日 19:05
To: Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]
Subject: Re: [PATCH] perf metricgroup: Fix system PMU metrics

Quoted 14 lines · Joakim Zhang
Quoted 14 lines

Joakim reports that getting "perf stat" for multiple system PMU metrics
segfaults:
./perf stat -a -I 1000 -M imx8mm_ddr_write.all,imx8mm_ddr_write.all Segmentation fault

While the same works without issue for a single metric.

The logic in metricgroup__add_metric_sys_event_iter() is broken, in that
add_metric() @m argument should be NULL for each new metric. Fix by not passing a holder for that, and rather make local in metricgroup__add_metric_sys_event_iter().

Quoted 6 lines
Quoted 5 lines
Fixes be335ec28efa ("perf metricgroup: Support adding metrics for

system
PMUs")

root@imx8mmevk:~# ./perf stat -a -I 1000 -M

imx8mm_ddr_read.all,imx8mm_ddr_write

.all

Quoted 2 lines

# time counts unit events

      1.001446500              40832

imx8mm_ddr.read_cycles # 638.0 KB imx8mm_ddr_read.all

Quoted 1 line
      1.001446500              16973

imx8mm_ddr.write_cycles # 265.2 KB imx8mm_ddr_write.all

Quoted 1 line
      2.003150250              28836

imx8mm_ddr.read_cycles # 450.6 KB imx8mm_ddr_read.all

Quoted 1 line
      2.003150250               6705

imx8mm_ddr.write_cycles # 104.8 KB imx8mm_ddr_write.all

Quoted 6 lines

For this issue, Tested-by: Joakim Zhang<[email protected]>

Hi John,

It seems have other issue compared to 5.10 kernel after switching to this

framework, below metric can't work.

Quoted 1 line

"MetricExpr": "(( imx8_ddr0@read\\-cycles@ + imx8_ddr0@write\\-cycles@ )

Quoted 8 lines

* 4 * 4 / duration_time) / (750 * 1000000 * 4 * 4)"

Quoted 3 lines

After change to:
"MetricExpr": "(( imx8mm_ddr.read_cycles + imx8mm_ddr.write_cycles ) * 4 * 4 / duration_time) / (750 * 1000000 * 4 * 4)",

Hmmm... not sure what you mean by "compared to 5.10 kernel". As far as I'm concerned, none of this was supported in 5.10 and metrics did not work for arm64. Support for sys PMU events+metrics only came in 5.11-rc.

Yes, 5.10 doesn't support ARM64. I add some code let it work locally. And,
"MetricExpr": "(( imx8_ddr0@read\\-cycles@ + imx8_ddr0@write\\-cycles@ ) * 4 * 4 / duration_time) / (750 * 1000000 * 4 * 4)" Above metric expression can work fine.

Quoted 2 lines

Anyway, can you share the full metric event which you say does not work, not just the "MetricExpr"?

OK, Could help check below metric? Thanks.
"MetricExpr": "(( imx8_ddr0@read\\-cycles@ + imx8_ddr0@write\\-cycles@ ) * 4 * 4 / duration_time) / (750 * 1000000 * 4 * 4)" or
"MetricExpr": "(( imx8mm_ddr.read_cycles + imx8mm_ddr.write_cycles ) * 4 * 4 / duration_time) / (750 * 1000000 * 4 * 4)"

Best Regards,
Joakim Zhang

Quoted 2 lines

Thanks,
John

author
#4 lore raw
In reply to Joakim Zhang
Quoted 7 lines · Joakim Zhang
root@imx8mmevk:~# ./perf stat -a -I 1000 -M imx8mm_ddr_read.all,imx8mm_ddr_write                                                                                                    .all
#           time             counts unit events
      1.001446500              40832      imx8mm_ddr.read_cycles    #    638.0 KB  imx8mm_ddr_read.all
      1.001446500              16973      imx8mm_ddr.write_cycles   #    265.2 KB  imx8mm_ddr_write.all
      2.003150250              28836      imx8mm_ddr.read_cycles    #    450.6 KB  imx8mm_ddr_read.all
      2.003150250               6705      imx8mm_ddr.write_cycles   #    104.8 KB  imx8mm_ddr_write.all
Quoted 9 lines

For this issue, Tested-by: Joakim Zhang<[email protected]>

Hi John,

It seems have other issue compared to 5.10 kernel after switching to this framework, below metric can't work. "MetricExpr": "(( imx8_ddr0@read\\-cycles@ + imx8_ddr0@write\\-cycles@ ) * 4 * 4 / duration_time) / (750 * 1000000 * 4 * 4)" After change to:
"MetricExpr": "(( imx8mm_ddr.read_cycles + imx8mm_ddr.write_cycles ) * 4 * 4 / duration_time) / (750 * 1000000 * 4 * 4)",

OK, I can have a look. So is there anything else, apart from this, which doesn't work now?

Thanks,
john

author
#5 lore raw
In reply to Joakim Zhang
Quoted 4 lines · Joakim Zhang

It seems have other issue compared to 5.10 kernel after switching to this framework, below metric can't work. "MetricExpr": "(( imx8_ddr0@read\\-cycles@ + imx8_ddr0@write\\-cycles@ ) * 4 * 4 / duration_time) / (750 * 1000000 * 4 * 4)" After change to:
"MetricExpr": "(( imx8mm_ddr.read_cycles + imx8mm_ddr.write_cycles ) * 4 * 4 / duration_time) / (750 * 1000000 * 4 * 4)",

It seems that any metric which includes "duration_time" is broken, even on x86:

john@localhost:~/acme/tools/perf> sudo ./perf stat -v -M L1D_Cache_Fill_BW sleep 1 Using CPUID GenuineIntel-6-3D-4
metric expr 64 * l1d.replacement / 1000000000 / duration_time for L1D_Cache_Fill_BW found event duration_time
found event l1d.replacement
adding {l1d.replacement}:W,duration_time
l1d.replacement -> cpu/umask=0x1,(null)=0x1e8483,event=0x51/ Segmentation fault

Seems to be from my commit c2337d67199 ("perf metricgroup: Fix metrics using aliases covering multiple PMUs")

I'll look to fix it now.

Thanks,
John

author
#6 lore raw
Quoted 18 lines · John Garry
Quoted 4 lines · Joakim Zhang

It seems have other issue compared to 5.10 kernel after switching to this framework, below metric can't work. "MetricExpr": "(( imx8_ddr0@read\\-cycles@ + imx8_ddr0@write\\-cycles@ ) * 4 * 4 / duration_time) / (750 * 1000000 * 4 * 4)" After change to:
"MetricExpr": "(( imx8mm_ddr.read_cycles + imx8mm_ddr.write_cycles ) * 4 * 4 / duration_time) / (750 * 1000000 * 4 * 4)",

It seems that any metric which includes "duration_time" is broken, even on x86:

john@localhost:~/acme/tools/perf> sudo ./perf stat -v -M L1D_Cache_Fill_BW sleep 1 Using CPUID GenuineIntel-6-3D-4
metric expr 64 * l1d.replacement / 1000000000 / duration_time for L1D_Cache_Fill_BW found event duration_time
found event l1d.replacement
adding {l1d.replacement}:W,duration_time
l1d.replacement -> cpu/umask=0x1,(null)=0x1e8483,event=0x51/ Segmentation fault

Quoted 4 lines

Seems to be from my commit c2337d67199 ("perf metricgroup: Fix metrics using aliases covering multiple PMUs")

I'll look to fix it now.

Please try this:

From 2380f1ef0250e6818b3dbc7bff4a868810875e2a Mon Sep 17 00:00:00 2001
From: John Garry <[email protected]>
Date: Tue, 19 Jan 2021 17:29:54 +0000
Subject: [PATCH] perf metricgroup: Fix metric support for duration_time

For a metric using duration_time, the strcmp() check when finding identical events in metric_events[] is broken, as it does not consider that the event pmu_name is NULL - it would be for duration_time.

As such, add a NULL check here for event pmu_name.

tools/perf/util/metricgroup.c +2 -0
index ee94d3e8dd65..277adff8017f 100644
@@ -280,6 +280,8 @@ static struct evsel *find_evsel_group(struct evlist *perf_evlist,
 			 */
 			if (!has_constraint &&
 			    ev->leader != metric_events[i]->leader &&
+			    ev->leader->pmu_name &&
+			    metric_events[i]->leader->pmu_name &&
 			    !strcmp(ev->leader->pmu_name,
 				    metric_events[i]->leader->pmu_name))
 				break;
Signature · 1 line
2.26.2
#7 lore raw
Quoted 70 lines

-----Original Message-----
From: John Garry <[email protected]>
Sent: 2021年1月20日 1:33
To: Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]
Subject: Re: [PATCH] perf metricgroup: Fix system PMU metrics

Quoted 23 lines · John Garry
Quoted 9 lines · Joakim Zhang

It seems have other issue compared to 5.10 kernel after switching to this framework, below metric can't work.
"MetricExpr": "(( imx8_ddr0@read\\-cycles@ + imx8_ddr0@write\\-cycles@
) * 4 * 4 / duration_time) / (750 * 1000000 * 4 * 4)" After change to:
"MetricExpr": "(( imx8mm_ddr.read_cycles + imx8mm_ddr.write_cycles ) *
4 * 4 / duration_time) / (750 * 1000000 * 4 * 4)",

It seems that any metric which includes "duration_time" is broken, even on x86:

john@localhost:~/acme/tools/perf> sudo ./perf stat -v -M L1D_Cache_Fill_BW sleep 1 Using CPUID GenuineIntel-6-3D-4 metric expr 64 * l1d.replacement / 1000000000 / duration_time for L1D_Cache_Fill_BW found event duration_time found event l1d.replacement adding {l1d.replacement}:W,duration_time l1d.replacement -> cpu/umask=0x1,(null)=0x1e8483,event=0x51/ Segmentation fault

Quoted 5 lines

Seems to be from my commit c2337d67199 ("perf metricgroup: Fix metrics using aliases covering multiple PMUs")

I'll look to fix it now.

Please try this:

From 2380f1ef0250e6818b3dbc7bff4a868810875e2a Mon Sep 17 00:00:00
2001
From: John Garry <[email protected]>
Date: Tue, 19 Jan 2021 17:29:54 +0000
Subject: [PATCH] perf metricgroup: Fix metric support for duration_time

For a metric using duration_time, the strcmp() check when finding identical events in metric_events[] is broken, as it does not consider that the event pmu_name is NULL - it would be for duration_time.

As such, add a NULL check here for event pmu_name.

tools/perf/util/metricgroup.c +2 -0
index ee94d3e8dd65..277adff8017f 100644
@@ -280,6 +280,8 @@ static struct evsel *find_evsel_group(struct evlist
 *perf_evlist,
  			 */
  			if (!has_constraint &&
  			    ev->leader != metric_events[i]->leader &&
+			    ev->leader->pmu_name &&
+			    metric_events[i]->leader->pmu_name &&
  			    !strcmp(ev->leader->pmu_name,
  				    metric_events[i]->leader->pmu_name))
Quoted 5 lines

break;
--
2.26.2

For this patch: Tested-by: Joakim Zhang <[email protected]>

Hi John, Jolsa,

Is there any way to avoid breaking exist metric expressions? If not, it will always happened after metricgroup changes.

I recall that Jolsa mentioned it before, but I don’t remember it very clearly.

Thanks a lot for John's bug fix.

Best Regards,
Joakim Zhang

author
#8 lore raw
Quoted 78 lines · Joakim Zhang
Quoted 71 lines

-----Original Message-----
From: John Garry <[email protected]>
Sent: 2021年1月20日 1:33
To: Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]
Subject: Re: [PATCH] perf metricgroup: Fix system PMU metrics

Quoted 23 lines · John Garry
Quoted 9 lines · Joakim Zhang

It seems have other issue compared to 5.10 kernel after switching to this framework, below metric can't work.
"MetricExpr": "(( imx8_ddr0@read\\-cycles@ + imx8_ddr0@write\\-cycles@
) * 4 * 4 / duration_time) / (750 * 1000000 * 4 * 4)" After change to:
"MetricExpr": "(( imx8mm_ddr.read_cycles + imx8mm_ddr.write_cycles ) *
4 * 4 / duration_time) / (750 * 1000000 * 4 * 4)",

It seems that any metric which includes "duration_time" is broken, even on x86:

john@localhost:~/acme/tools/perf> sudo ./perf stat -v -M L1D_Cache_Fill_BW sleep 1 Using CPUID GenuineIntel-6-3D-4 metric expr 64 * l1d.replacement / 1000000000 / duration_time for L1D_Cache_Fill_BW found event duration_time found event l1d.replacement adding {l1d.replacement}:W,duration_time l1d.replacement -> cpu/umask=0x1,(null)=0x1e8483,event=0x51/ Segmentation fault

Quoted 5 lines

Seems to be from my commit c2337d67199 ("perf metricgroup: Fix metrics using aliases covering multiple PMUs")

I'll look to fix it now.

Please try this:

From 2380f1ef0250e6818b3dbc7bff4a868810875e2a Mon Sep 17 00:00:00
2001
From: John Garry <[email protected]>
Date: Tue, 19 Jan 2021 17:29:54 +0000
Subject: [PATCH] perf metricgroup: Fix metric support for duration_time

For a metric using duration_time, the strcmp() check when finding identical events in metric_events[] is broken, as it does not consider that the event pmu_name is NULL - it would be for duration_time.

As such, add a NULL check here for event pmu_name.

tools/perf/util/metricgroup.c +2 -0
index ee94d3e8dd65..277adff8017f 100644
@@ -280,6 +280,8 @@ static struct evsel *find_evsel_group(struct evlist
 *perf_evlist,
   			 */
   			if (!has_constraint &&
   			    ev->leader != metric_events[i]->leader &&
+			    ev->leader->pmu_name &&
+			    metric_events[i]->leader->pmu_name &&
   			    !strcmp(ev->leader->pmu_name,
   				    metric_events[i]->leader->pmu_name))
   				break;
Quoted 4 lines

--
2.26.2

For this patch: Tested-by: Joakim Zhang <[email protected]>

Quoted 4 lines

Hi John, Jolsa,

Is there any way to avoid breaking exist metric expressions? If not, it will always happened after metricgroup changes.

They are not normally broken like that. Normally we test beforehand, but these cases were missed here by me. However if you were testing them previously, then it would be expected that you had tested them again for the final patchset which was merged.

Anyway, we can look to add metric tests for these.

@Arnaldo, I will send separate formal patch for this today.

Thanks,
John

#9 lore raw
Quoted 97 lines

-----Original Message-----
From: John Garry <[email protected]>
Sent: 2021年1月20日 17:16
To: Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]
Subject: Re: [PATCH] perf metricgroup: Fix system PMU metrics

Quoted 40 lines · Joakim Zhang
Quoted 40 lines

-----Original Message-----
From: John Garry <[email protected]>
Sent: 2021年1月20日 1:33
To: Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]
Subject: Re: [PATCH] perf metricgroup: Fix system PMU metrics

Quoted 28 lines · John Garry
Quoted 10 lines · Joakim Zhang

It seems have other issue compared to 5.10 kernel after switching to this framework, below metric can't work. "MetricExpr": "(( imx8_ddr0@read\\-cycles@ + imx8_ddr0@write\\-cycles@
) * 4 * 4 / duration_time) / (750 * 1000000 * 4 * 4)" After change to:
"MetricExpr": "(( imx8mm_ddr.read_cycles + imx8mm_ddr.write_cycles )
*
4 * 4 / duration_time) / (750 * 1000000 * 4 * 4)",

It seems that any metric which includes "duration_time" is broken, even on x86:

john@localhost:~/acme/tools/perf> sudo ./perf stat -v -M L1D_Cache_Fill_BW sleep 1 Using CPUID GenuineIntel-6-3D-4 metric expr
64 * l1d.replacement / 1000000000 / duration_time for L1D_Cache_Fill_BW found event duration_time found event l1d.replacement adding {l1d.replacement}:W,duration_time l1d.replacement -> cpu/umask=0x1,(null)=0x1e8483,event=0x51/ Segmentation fault

Seems to be from my commit c2337d67199 ("perf metricgroup: Fix metrics using aliases covering multiple PMUs")

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

I'll look to fix it now.

Please try this:

From 2380f1ef0250e6818b3dbc7bff4a868810875e2a Mon Sep 17

00:00:00

Quoted 38 lines
Quoted 29 lines

2001
From: John Garry <[email protected]>
Date: Tue, 19 Jan 2021 17:29:54 +0000
Subject: [PATCH] perf metricgroup: Fix metric support for duration_time

For a metric using duration_time, the strcmp() check when finding identical events in metric_events[] is broken, as it does not consider that the event pmu_name is NULL - it would be for duration_time.

As such, add a NULL check here for event pmu_name.

(quoted diff) +0 -0

b/tools/perf/util/metricgroup.c index ee94d3e8dd65..277adff8017f 100644

tools/perf/util/metricgroup.c +2 -0
@@ -280,6 +280,8 @@ static struct evsel *find_evsel_group(struct
 evlist *perf_evlist,
   			 */
   			if (!has_constraint &&
   			    ev->leader != metric_events[i]->leader &&
+			    ev->leader->pmu_name &&
+			    metric_events[i]->leader->pmu_name &&
   			    !strcmp(ev->leader->pmu_name,
   				    metric_events[i]->leader->pmu_name))
   				break;
Quoted 4 lines

--
2.26.2

For this patch: Tested-by: Joakim Zhang <[email protected]>

Hi John, Jolsa,

Quoted 8 lines
Quoted 1 line

Is there any way to avoid breaking exist metric expressions? If not, it will

always happened after metricgroup changes.

Quoted 1 line

They are not normally broken like that. Normally we test beforehand, but these cases were missed here by me. However if you were testing them previously, then it would be expected that you had tested them again for the final patchset which was merged.

Yes, John, sorry. I have not did the fully test before, this could be avoided.

Best Regards,
Joakim Zhang

Quoted 6 lines

Anyway, we can look to add metric tests for these.

@Arnaldo, I will send separate formal patch for this today.

Thanks,
John

#10 lore raw
In reply to John Garry

Em Wed, Jan 20, 2021 at 09:15:54AM +0000, John Garry escreveu:

Quoted 7 lines · Joakim Zhang
Quoted 5 lines

For this patch: Tested-by: Joakim Zhang <[email protected]>

Hi John, Jolsa,

Is there any way to avoid breaking exist metric expressions? If not, it will always happened after metricgroup changes.

Quoted 8 lines

They are not normally broken like that. Normally we test beforehand, but these cases were missed here by me. However if you were testing them previously, then it would be expected that you had tested them again for the final patchset which was merged.

Anyway, we can look to add metric tests for these.

@Arnaldo, I will send separate formal patch for this today.

Hi John, can you please take a look at my tmp.perf/urgent branch and see if all is well, i.e. the versions of these patches are the ones that should be merged and that all the patches discussed are there?

For your convenience:

https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/log/?h=tmp.perf/urgent

Thanks,

- Arnaldo

author
#11 lore raw
Quoted 7 lines · Arnaldo Carvalho de Melo
Quoted 6 lines

They are not normally broken like that. Normally we test beforehand, but these cases were missed here by me. However if you were testing them previously, then it would be expected that you had tested them again for the final patchset which was merged.

Anyway, we can look to add metric tests for these.

Quoted 8 lines
Quoted 1 line

@Arnaldo, I will send separate formal patch for this today.

Hi John, can you please take a look at my tmp.perf/urgent branch and see if all is well, i.e. the versions of these patches are the ones that should be merged and that all the patches discussed are there?

For your convenience:

https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/log/?h=tmp.perf/urgent

Hi Arnaldo,

Yeah, that looks fine. I gave it a quick spin also without issue.

Cheers,
John

#12 lore raw
In reply to John Garry

On Tue, Jan 19, 2021 at 05:33:13PM +0000, John Garry wrote:

SNIP

Quoted 28 lines

Please try this:

From 2380f1ef0250e6818b3dbc7bff4a868810875e2a Mon Sep 17 00:00:00 2001
From: John Garry <[email protected]>
Date: Tue, 19 Jan 2021 17:29:54 +0000
Subject: [PATCH] perf metricgroup: Fix metric support for duration_time

For a metric using duration_time, the strcmp() check when finding identical events in metric_events[] is broken, as it does not consider that the event pmu_name is NULL - it would be for duration_time.

As such, add a NULL check here for event pmu_name.

tools/perf/util/metricgroup.c +2 -0
index ee94d3e8dd65..277adff8017f 100644
@@ -280,6 +280,8 @@ static struct evsel *find_evsel_group(struct evlist
 *perf_evlist,
 			 */
 			if (!has_constraint &&
 			    ev->leader != metric_events[i]->leader &&
+			    ev->leader->pmu_name &&
+			    metric_events[i]->leader->pmu_name &&
 			    !strcmp(ev->leader->pmu_name,
 				    metric_events[i]->leader->pmu_name))
Quoted 6 lines

break;

Signature · 1 line
2.26.2

that's fixing the issue for me, this was crashing:

  # perf stat -a -I 1000 -M L1D_Cache_Fill_BW,L2_Cache_Fill_BW

could you please send it formaly, so it can be merged?

I can't reproduce the original patch issue and I need to check the code in more depth

thanks,
jirka

author
#13 lore raw
Quoted 5 lines · Jiri Olsa

that's fixing the issue for me, this was crashing:

   # perf stat -a -I 1000 -M L1D_Cache_Fill_BW,L2_Cache_Fill_BW

could you please send it formaly, so it can be merged?

I will do it today. But I want to make sure that the logic is correct, so checking it all again, i.e. I can fix the segfault but the logic may be wrong.

I think Ian wrote this code originally or made the most recent rework (which I tried to fix), so would like him to check also.

Quoted 2 lines

I can't reproduce the original patch issue and I need to check the code in more depth

It should only occur for metrics when using system PMUs, i.e. match via identifier file, so I really doubt your system has them.

I'd like to add a test for this - I need to think how...

Cheers,
John

author
#14 lore raw
In reply to Jiri Olsa
Quoted 6 lines
Quoted 3 lines

that's fixing the issue for me, this was crashing:

   # perf stat -a -I 1000 -M L1D_Cache_Fill_BW,L2_Cache_Fill_BW

To cover this scenario (multiple metrics listed), how about a simple addition like:

---->8----

From bd2ded1b0ef4962a9443cd180eed4e5c5b75ae5f Mon Sep 17 00:00:00 2001
From: John Garry <[email protected]>
Date: Fri, 5 Feb 2021 09:50:54 +0000
Subject: [PATCH] perf test: Add parse-metric list test scenario

tools/perf/tests/parse-metric.c +17 -1
index ce7be37f0d88..0626e389354c 100644
@@ -201,6 +201,13 @@ static int compute_metric_group(const char *name, struct value *vals,
 	return __compute_metric(name, vals, name1, ratio1, name2, ratio2);
 }
 
+static int compute_metric_list(const char *list, struct value *vals,
+				const char *name1, double *ratio1,
+				const char *name2, double *ratio2)
+{
+	return __compute_metric(list, vals, name1, ratio1, name2, ratio2);
+}
+
 static int test_ipc(void)
 {
 	double ratio;
@@ -279,7 +286,7 @@ static int test_cache_miss_cycles(void)
  */
 static int test_dcache_l2(void)
 {
-	double ratio;
+	double ratio, ratio1, ratio2;
 	struct value vals[] = {
 		{ .event = "l2_rqsts.demand_data_rd_hit", .val = 100 },
 		{ .event = "l2_rqsts.pf_hit",             .val = 200 },
@@ -301,6 +308,15 @@ static int test_dcache_l2(void)
 
 	TEST_ASSERT_VAL("DCache_L2_Misses failed, wrong ratio",
 			ratio == 0.7);
+
+	TEST_ASSERT_VAL("failed to compute metric",
+			compute_metric_list("DCache_L2_Hits,DCache_L2_Misses", vals, "DCache_L2_Hits", &ratio1, "DCache_L2_Misses", &ratio2) == 0);
+
+	TEST_ASSERT_VAL("DCache_L2_Hits failed, wrong ratio",
+			ratio1 == 0.3);
+
+	TEST_ASSERT_VAL("DCache_L2_Misses failed, wrong ratio",
+			ratio2 == 0.7);
 	return 0;
 }
 

----8<----

Quoted 4 lines

could you please send it formaly, so it can be merged?

I can't reproduce the original patch issue and I need to check the code in more depth

Thanks,
John

Acked-by on v1 1/1
#15 lore raw
In reply to John Garry
Quoted 7 lines · John Garry

Joakim reports that getting "perf stat" for multiple system PMU metrics segfaults:
./perf stat -a -I 1000 -M imx8mm_ddr_write.all,imx8mm_ddr_write.all Segmentation fault

While the same works without issue for a single metric.

Quoted 8 lines

The logic in metricgroup__add_metric_sys_event_iter() is broken, in that add_metric() @m argument should be NULL for each new metric. Fix by not passing a holder for that, and rather make local in metricgroup__add_metric_sys_event_iter().

Fixes be335ec28efa ("perf metricgroup: Support adding metrics for system PMUs")

thanks,
jirka

Quoted 39 lines
tools/perf/util/metricgroup.c +2 -3
index ee94d3e8dd65..2e60ee170abc 100644
@@ -766,7 +766,6 @@ int __weak arch_get_runtimeparam(struct pmu_event *pe __maybe_unused)
 struct metricgroup_add_iter_data {
 	struct list_head *metric_list;
 	const char *metric;
-	struct metric **m;
 	struct expr_ids *ids;
 	int *ret;
 	bool *has_match;
@@ -1058,12 +1057,13 @@ static int metricgroup__add_metric_sys_event_iter(struct pmu_event *pe,
 						  void *data)
 {
 	struct metricgroup_add_iter_data *d = data;
+	struct metric *m = NULL;
 	int ret;
 
 	if (!match_pe_metric(pe, d->metric))
 		return 0;
 
-	ret = add_metric(d->metric_list, pe, d->metric_no_group, d->m, NULL, d->ids);
+	ret = add_metric(d->metric_list, pe, d->metric_no_group, &m, NULL, d->ids);
 	if (ret)
 		return ret;
 
@@ -1114,7 +1114,6 @@ static int metricgroup__add_metric(const char *metric, bool metric_no_group,
 				.metric_list = &list,
 				.metric = metric,
 				.metric_no_group = metric_no_group,
-				.m = &m,
 				.ids = &ids,
 				.has_match = &has_match,
 				.ret = &ret,
Signature · 1 line
2.26.2