Skip to contentSkip to conversation

perf evlist: Fix id index for heterogeneous systems

PATCH In review Adrian Hunter 2 participants 4 messages Jan 21, 2021 perf events

lore
Share & tools
lore

Adrian Hunter

author reviewer
#0 lore raw

PATCH 1/1 perf evlist: Fix id index for heterogeneous systems

perf_evlist__set_sid_idx() updates perf_sample_id with the evlist map index, cpu number and tid. It is passed indexes to the evsel's cpu and thread maps, but references the evlist's maps instead. That results in using incorrect cpu numbers on heterogeneous systems. Fix by using evsel maps.

The id index (PERF_RECORD_ID_INDEX) is used by AUX area tracing when in sampling mode. Having an incorrect cpu number causes the trace data to be attributed to the wrong cpu, and can result in decoder errors because the trace data is then associated with the wrong process.

---
 tools/lib/perf/evlist.c | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)
tools/lib/perf/evlist.c +4 -13
index cfcdbd7be066..37be8042889f 100644
@@ -367,21 +367,13 @@ static struct perf_mmap* perf_evlist__alloc_mmap(struct perf_evlist *evlist, boo
 	return map;
 }
 
-static void perf_evlist__set_sid_idx(struct perf_evlist *evlist,
-				     struct perf_evsel *evsel, int idx, int cpu,
-				     int thread)
+static void set_sid_idx(struct perf_evsel *evsel, int idx, int cpu, int thread)
 {
 	struct perf_sample_id *sid = SID(evsel, cpu, thread);
 
 	sid->idx = idx;
-	if (evlist->cpus && cpu >= 0)
-		sid->cpu = evlist->cpus->map[cpu];
-	else
-		sid->cpu = -1;
-	if (!evsel->system_wide && evlist->threads && thread >= 0)
-		sid->tid = perf_thread_map__pid(evlist->threads, thread);
-	else
-		sid->tid = -1;
+	sid->cpu = perf_cpu_map__cpu(evsel->cpus, cpu);
+	sid->tid = perf_thread_map__pid(evsel->threads, thread);
 }
 
 static struct perf_mmap*
@@ -500,8 +492,7 @@ mmap_per_evsel(struct perf_evlist *evlist, struct perf_evlist_mmap_ops *ops,
 			if (perf_evlist__id_add_fd(evlist, evsel, cpu, thread,
 						   fd) < 0)
 				return -1;
-			perf_evlist__set_sid_idx(evlist, evsel, idx, cpu,
-						 thread);
+			set_sid_idx(evsel, idx, cpu, thread);
 		}
 	}
 
Signature · 1 line
2.17.1
#1 lore raw

Em Thu, Jan 21, 2021 at 02:54:46PM +0200, Adrian Hunter escreveu:

Quoted 10 lines

perf_evlist__set_sid_idx() updates perf_sample_id with the evlist map index, cpu number and tid. It is passed indexes to the evsel's cpu and thread maps, but references the evlist's maps instead. That results in using incorrect cpu numbers on heterogeneous systems. Fix by using evsel maps.

The id index (PERF_RECORD_ID_INDEX) is used by AUX area tracing when in sampling mode. Having an incorrect cpu number causes the trace data to be attributed to the wrong cpu, and can result in decoder errors because the trace data is then associated with the wrong process.

Can you please provide a Fixes: tag so that the [email protected] guys can apply where appropriate?

Thanks,

- Arnaldo

Quoted 47 lines
---
 tools/lib/perf/evlist.c | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)
tools/lib/perf/evlist.c +4 -13
index cfcdbd7be066..37be8042889f 100644
@@ -367,21 +367,13 @@ static struct perf_mmap* perf_evlist__alloc_mmap(struct perf_evlist *evlist, boo
 	return map;
 }
 
-static void perf_evlist__set_sid_idx(struct perf_evlist *evlist,
-				     struct perf_evsel *evsel, int idx, int cpu,
-				     int thread)
+static void set_sid_idx(struct perf_evsel *evsel, int idx, int cpu, int thread)
 {
 	struct perf_sample_id *sid = SID(evsel, cpu, thread);
 
 	sid->idx = idx;
-	if (evlist->cpus && cpu >= 0)
-		sid->cpu = evlist->cpus->map[cpu];
-	else
-		sid->cpu = -1;
-	if (!evsel->system_wide && evlist->threads && thread >= 0)
-		sid->tid = perf_thread_map__pid(evlist->threads, thread);
-	else
-		sid->tid = -1;
+	sid->cpu = perf_cpu_map__cpu(evsel->cpus, cpu);
+	sid->tid = perf_thread_map__pid(evsel->threads, thread);
 }
 
 static struct perf_mmap*
@@ -500,8 +492,7 @@ mmap_per_evsel(struct perf_evlist *evlist, struct perf_evlist_mmap_ops *ops,
 			if (perf_evlist__id_add_fd(evlist, evsel, cpu, thread,
 						   fd) < 0)
 				return -1;
-			perf_evlist__set_sid_idx(evlist, evsel, idx, cpu,
-						 thread);
+			set_sid_idx(evsel, idx, cpu, thread);
 		}
 	}
 
Signature · 1 line
2.17.1
Signature · 1 line
- Arnaldo
author reviewer
#2 lore raw
Quoted 7 lines · Arnaldo Carvalho de Melo

Em Thu, Jan 21, 2021 at 02:54:46PM +0200, Adrian Hunter escreveu:

Quoted 6 lines

perf_evlist__set_sid_idx() updates perf_sample_id with the evlist map index, cpu number and tid. It is passed indexes to the evsel's cpu and thread maps, but references the evlist's maps instead. That results in using incorrect cpu numbers on heterogeneous systems. Fix by using evsel maps.

Quoted 7 lines
Quoted 4 lines

The id index (PERF_RECORD_ID_INDEX) is used by AUX area tracing when in sampling mode. Having an incorrect cpu number causes the trace data to be attributed to the wrong cpu, and can result in decoder errors because the trace data is then associated with the wrong process.

Can you please provide a Fixes: tag so that the [email protected] guys can apply where appropriate?

Oops sorry missed that. Here it is:

Fixes 3c659eedada2 ("perf tools: Add id index")
#3 lore raw

Em Thu, Jan 21, 2021 at 03:39:03PM +0200, Adrian Hunter escreveu:

Quoted 13 lines · Arnaldo Carvalho de Melo
Quoted 12 lines

Em Thu, Jan 21, 2021 at 02:54:46PM +0200, Adrian Hunter escreveu:

Quoted 10 lines

perf_evlist__set_sid_idx() updates perf_sample_id with the evlist map index, cpu number and tid. It is passed indexes to the evsel's cpu and thread maps, but references the evlist's maps instead. That results in using incorrect cpu numbers on heterogeneous systems. Fix by using evsel maps.

The id index (PERF_RECORD_ID_INDEX) is used by AUX area tracing when in sampling mode. Having an incorrect cpu number causes the trace data to be attributed to the wrong cpu, and can result in decoder errors because the trace data is then associated with the wrong process.

Quoted 6 lines
Quoted 2 lines

Can you please provide a Fixes: tag so that the [email protected] guys can apply where appropriate?

Oops sorry missed that. Here it is:

Fixes 3c659eedada2 ("perf tools: Add id index")

Thanks a lot!

- Arnaldo