Skip to contentSkip to conversation

perf script: Fix output type for dynamically allocated core PMU's

PATCH Superseded Thomas Falcon 3 participants 4 messages Dec 13, 2024 perf events

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf script: Fix output type for dynamically allocated core PMU's

perf script output may show different fields on different core PMU's that exist on heterogeneous platforms. For example,

perf record -e "{cpu_core/mem-loads-aux/,cpu_core/event=0xcd,\
umask=0x01,ldlat=3,name=MEM_UOPS_RETIRED.LOAD_LATENCY/}:upp"\
-c10000 -W -d -a -- sleep 1

perf script:

chromium-browse 46572 [002] 544966.882384: 10000 cpu_core/MEM_UOPS_RETIRED.LOAD_LATENCY/: 7ffdf1391b0c 10268100142 \
|OP LOAD|LVL L1 hit|SNP None|TLB L1 or L2 hit|LCK No|BLK N/A 5 7 0 7fad7c47425d [unknown] (/usr/lib64/libglib-2.0.so.0.8000.3)

perf record -e cpu_atom/event=0xd0,umask=0x05,ldlat=3,\
name=MEM_UOPS_RETIRED.LOAD_LATENCY/upp -c10000 -W -d -a -- sleep 1

perf script:

gnome-control-c 534224 [023] 544951.816227: 10000 cpu_atom/MEM_UOPS_RETIRED.LOAD_LATENCY/: 7f0aaaa0aae0 [unknown] (/usr/lib64/libglib-2.0.so.0.8000.3)

Some fields, such as data_src, are not included by default.

The cause is that while one PMU may be assigned a type such as PERF_TYPE_RAW, other core PMU's are dynamically allocated at boot time. If this value does not match an existing PERF_TYPE_X value, output_type(perf_event_attr.type) will return OUTPUT_TYPE_OTHER.

Instead search for a core PMU with a matching perf_event_attr type and, if one is found, return PERF_TYPE_RAW to match output of other core PMU's.

---
 tools/perf/builtin-script.c | 6 ++++++
 1 file changed, 6 insertions(+)
tools/perf/builtin-script.c +6 -0
index 9e47905f75a6..e091fa1be052 100644
@@ -386,6 +386,8 @@ static int evsel_script__fprintf(struct evsel_script *es, FILE *fp)
 
 static inline int output_type(unsigned int type)
 {
+	struct perf_pmu *pmu;
+
 	switch (type) {
 	case PERF_TYPE_SYNTH:
 		return OUTPUT_TYPE_SYNTH;
@@ -394,6 +396,10 @@ static inline int output_type(unsigned int type)
 			return type;
 	}
 
+	pmu = perf_pmus__find_by_type(type);
+	if (pmu && pmu->is_core)
+		return PERF_TYPE_RAW;
+
 	return OUTPUT_TYPE_OTHER;
 }
 
Signature · 1 line
2.47.1
#1 lore raw

Hi Thomas,

Quoted 10 lines
tools/perf/builtin-script.c +2 -0
@@ -386,6 +386,8 @@ static int evsel_script__fprintf(struct evsel_script *es, FILE *fp)
 
 static inline int output_type(unsigned int type)
 {
+	struct perf_pmu *pmu;
+
 	switch (type) {
 	case PERF_TYPE_SYNTH:
 		return OUTPUT_TYPE_SYNTH;

tools/perf/builtin-script.c static inline int output_type(unsigned int type) · line 401

Quoted 6 lines
tools/perf/builtin-script.c +3 -0
@@ -394,6 +396,10 @@ static inline int output_type(unsigned int type)
 			return type;
 	}
 
+	pmu = perf_pmus__find_by_type(type);
+	if (pmu && pmu->is_core)
+		return PERF_TYPE_RAW;

Minor nit ...

output_type() seems to be getting called a lot. For ex, for a perf.data with 4530 samples, output_type() was called 181246 times when I ran "perf script". IIUC, this pmu lookup is unnecessary for homogeneous platforms? If so, can we make it conditional?

Thanks,
Ravi

#2 lore raw
Quoted 21 lines · Ravi Bangoria

Hi Thomas,

Quoted 10 lines
tools/perf/builtin-script.c +2 -0
@@ -386,6 +386,8 @@ static int evsel_script__fprintf(struct evsel_script *es, FILE *fp)
 
 static inline int output_type(unsigned int type)
 {
+	struct perf_pmu *pmu;
+
 	switch (type) {
 	case PERF_TYPE_SYNTH:
 		return OUTPUT_TYPE_SYNTH;

tools/perf/builtin-script.c static inline int output_type(unsigned int type) · line 401

Quoted 6 lines
tools/perf/builtin-script.c +3 -0
@@ -394,6 +396,10 @@ static inline int output_type(unsigned int type)
 			return type;
 	}
 
+	pmu = perf_pmus__find_by_type(type);
+	if (pmu && pmu->is_core)
+		return PERF_TYPE_RAW;

Minor nit ...

Quoted 5 lines

output_type() seems to be getting called a lot. For ex, for a perf.data with 4530 samples, output_type() was called 181246 times when I ran "perf script". IIUC, this pmu lookup is unnecessary for homogeneous platforms? If so, can we make it conditional?

Agreed. I think the search should only be applied for the perf_pmus__num_core_pmus() > 1 case.

We should just need to search the core_pmus when comparing the type.

Thanks,
Kan

#3 lore raw
Quoted 33 lines · Kan
Quoted 23 lines · Ravi Bangoria

Hi Thomas,

Quoted 15 lines
(quoted diff) +0 -0
@@ -386,6 +386,8 @@ static int evsel_script__fprintf(struct
 evsel_script *es, FILE *fp)


 static inline int output_type(unsigned int type)
 {

tools/perf/builtin-script.c +2 -0
+	struct perf_pmu *pmu;
+

  switch (type) {
  case PERF_TYPE_SYNTH:
  return OUTPUT_TYPE_SYNTH;

tools/perf/builtin-script.c +0 -0
@@ -394,6 +396,10 @@ static inline int output_type(unsigned int
 type)
  			return type;
  	}

tools/perf/builtin-script.c static inline int output_type(unsigned int type) · line 401

Quoted 3 lines
tools/perf/builtin-script.c +3 -0
+	pmu = perf_pmus__find_by_type(type);
+	if (pmu && pmu->is_core)
+		return PERF_TYPE_RAW;

Minor nit ...

Quoted 6 lines

output_type() seems to be getting called a lot. For ex, for a perf.data
with 4530 samples, output_type() was called 181246 times when I ran "perf script". IIUC, this pmu lookup is unnecessary for homogeneous platforms? If so, can we make it conditional?

Quoted 5 lines

Agreed. I think the search should only be applied for the perf_pmus__num_core_pmus() > 1 case.

We should just need to search the core_pmus when comparing the type.

Thanks, will send v2 soon.

Tom

Quoted 3 lines

Thanks,
Kan