Skip to contentSkip to conversation

perf header: Support HYBRID_TOPOLOGY and hybrid CPU_PMU_CAPS

PATCH Superseded Jin Yao 2 participants 6 messages May 7, 2021 – May 11, 2021 perf events

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Jin Yao

author
#0 lore raw

v2 cover perf header: Support HYBRID_TOPOLOGY and hybrid CPU_PMU_CAPS

AlderLake uses a hybrid architecture utilizing Golden Cove cores (core cpu) and Gracemont cores (atom cpu). It would be useful to let user know the hybrid topology, the HYBRID_TOPOLOGY feature in header indicates which cpus are core cpus, and which cpus are atom cpus.

On hybrid platform, it may have several cpu pmus, such as, "cpu_core" and "cpu_atom". The CPU_PMU_CAPS feature in perf header is improved to support multiple cpu pmus.

v2:
---
- In "perf header: Support HYBRID_TOPOLOGY feature", don't use the n->map to print the cpu list, just use n->cpus.

- Separate hybrid CPU_PMU_CAPS support into two patches:
perf header: Write hybrid CPU_PMU_CAPS
perf header: Process hybrid CPU_PMU_CAPS

- Add some words to perf.data-file-format.txt for HYBRID_TOPOLOGY and hybrid CPU_PMU_CAPS.

Jin Yao (3):
perf header: Support HYBRID_TOPOLOGY feature
perf header: Write hybrid CPU_PMU_CAPS
perf header: Process hybrid CPU_PMU_CAPS

 .../Documentation/perf.data-file-format.txt   |  20 ++
 tools/perf/util/cputopo.c                     |  80 ++++++
 tools/perf/util/cputopo.h                     |  13 +
 tools/perf/util/env.c                         |  12 +
 tools/perf/util/env.h                         |  18 +-
 tools/perf/util/header.c                      | 269 ++++++++++++++++--
 tools/perf/util/header.h                      |   1 +
 tools/perf/util/pmu-hybrid.h                  |  11 +
 8 files changed, 400 insertions(+), 24 deletions(-)
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH v2 1/3 perf header: Support HYBRID_TOPOLOGY feature

It would be useful to let user know the hybrid topology. Adding HYBRID_TOPOLOGY feature in header to indicate the core cpus and the atom cpus.

With this patch,

For the perf.data generated on hybrid platform, reports the hybrid cpu list.

  root@otcpl-adl-s-2:~# perf report --header-only -I
  ...
  # hybrid cpu system:
  # cpu_core cpu list : 0-15
  # cpu_atom cpu list : 16-23

For the perf.data generated on non-hybrid platform, reports the message that HYBRID_TOPOLOGY is missing.

  root@kbl-ppc:~# perf report --header-only -I
  ...
  # missing features: TRACING_DATA BRANCH_STACK GROUP_DESC AUXTRACE STAT CLOCKID DIR_FORMAT COMPRESSED CLOCK_DATA HYBRID_TOPOLOGY
---
 .../Documentation/perf.data-file-format.txt   | 14 +++
 tools/perf/util/cputopo.c                     | 80 +++++++++++++++++
 tools/perf/util/cputopo.h                     | 13 +++
 tools/perf/util/env.c                         |  6 ++
 tools/perf/util/env.h                         |  7 ++
 tools/perf/util/header.c                      | 87 +++++++++++++++++++
 tools/perf/util/header.h                      |  1 +
 tools/perf/util/pmu-hybrid.h                  | 11 +++
 8 files changed, 219 insertions(+)
tools/perf/Documentation/perf.data-file-format.txt +14 -0
index 9ee96640744e..d9d82ca8aeb7 100644
@@ -402,6 +402,20 @@ struct {
 	u64 clockid_time_ns;
 };
 
+	HEADER_HYBRID_TOPOLOGY = 30,
+
+Indicate the hybrid CPUs. The format of data is as below.
+
+struct {
+	char *pmu_name;
+	char *cpus;
+};
+
+Example:
+  hybrid cpu system:
+  cpu_core cpu list : 0-15
+  cpu_atom cpu list : 16-23
+
 	other bits are reserved and should ignored for now
 	HEADER_FEAT_BITS	= 256,
 
tools/perf/util/cputopo.c +80 -0

89 lines not on this page · raw message

tools/perf/util/cputopo.h +13 -0
index 6201c3790d86..d9af97177068 100644
@@ -25,10 +25,23 @@ struct numa_topology {
 	struct numa_topology_node	nodes[];
 };
 
+struct hybrid_topology_node {
+	char		*pmu_name;
+	char		*cpus;
+};
+
+struct hybrid_topology {
+	u32				nr;
+	struct hybrid_topology_node	nodes[];
+};
+
 struct cpu_topology *cpu_topology__new(void);
 void cpu_topology__delete(struct cpu_topology *tp);
 
 struct numa_topology *numa_topology__new(void);
 void numa_topology__delete(struct numa_topology *tp);
 
+struct hybrid_topology *hybrid_topology__new(void);
+void hybrid_topology__delete(struct hybrid_topology *tp);
+
 #endif /* __PERF_CPUTOPO_H */
tools/perf/util/env.c +6 -0
index 9130f6fad8d5..744ae87b5bfa 100644
@@ -202,6 +202,12 @@ void perf_env__exit(struct perf_env *env)
 	for (i = 0; i < env->nr_memory_nodes; i++)
 		zfree(&env->memory_nodes[i].set);
 	zfree(&env->memory_nodes);
+
+	for (i = 0; i < env->nr_hybrid_nodes; i++) {
+		zfree(&env->hybrid_nodes[i].pmu_name);
+		zfree(&env->hybrid_nodes[i].cpus);
+	}
+	zfree(&env->hybrid_nodes);
 }
 
 void perf_env__init(struct perf_env *env __maybe_unused)
tools/perf/util/env.h +7 -0
index ca249bf5e984..e5e5deebe68d 100644
@@ -37,6 +37,11 @@ struct memory_node {
 	unsigned long	*set;
 };
 
+struct hybrid_node {
+	char	*pmu_name;
+	char	*cpus;
+};
+
 struct perf_env {
 	char			*hostname;
 	char			*os_release;
@@ -59,6 +64,7 @@ struct perf_env {
 	int			nr_pmu_mappings;
 	int			nr_groups;
 	int			nr_cpu_pmu_caps;
+	int			nr_hybrid_nodes;
 	char			*cmdline;
 	const char		**cmdline_argv;
 	char			*sibling_cores;
@@ -77,6 +83,7 @@ struct perf_env {
 	struct numa_node	*numa_nodes;
 	struct memory_node	*memory_nodes;
 	unsigned long long	 memory_bsize;
+	struct hybrid_node	*hybrid_nodes;
 #ifdef HAVE_LIBBPF_SUPPORT
 	/*
 	 * bpf_info_lock protects bpf rbtrees. This is needed because the
tools/perf/util/header.c +87 -0

111 lines not on this page · raw message

tools/perf/util/header.h +1 -0
index 2aca71763ecf..3f12ec0eb84e 100644
@@ -45,6 +45,7 @@ enum {
 	HEADER_COMPRESSED,
 	HEADER_CPU_PMU_CAPS,
 	HEADER_CLOCK_DATA,
+	HEADER_HYBRID_TOPOLOGY,
 	HEADER_LAST_FEATURE,
 	HEADER_FEAT_BITS	= 256,
 };
tools/perf/util/pmu-hybrid.h +11 -0
index d0fa7bc50a76..2b186c26a43e 100644
@@ -19,4 +19,15 @@ struct perf_pmu *perf_pmu__find_hybrid_pmu(const char *name);
 bool perf_pmu__is_hybrid(const char *name);
 char *perf_pmu__hybrid_type_to_pmu(const char *type);
 
+static inline int perf_pmu__hybrid_pmu_num(void)
+{
+	struct perf_pmu *pmu;
+	int num = 0;
+
+	perf_pmu__for_each_hybrid_pmu(pmu)
+		num++;
+
+	return num;
+}
+
 #endif /* __PMU_HYBRID_H */
Signature · 1 line
2.17.1
author
#4 lore raw

PATCH v2 2/3 perf header: Write hybrid CPU_PMU_CAPS

In reply to Jin Yao

On hybrid platform, it may have several cpu pmus, such as, "cpu_core" and "cpu_atom". The CPU_PMU_CAPS feature in perf header needs to be improved to support multiple cpu pmus.

The existing layout:

<caps nr>
<caps string 1>
<caps string 2>
<caps string N>

Now it's extended to:

<pmu1 caps nr>
<caps string 1>
<caps string 2>
<caps string N>
<pmu1 name>
<nr of rest pmus to process>
<pmu2 caps nr>
<caps string 1>
<caps string 2>
<caps string N>
<pmu2 name>
<nr of rest pmus to process>

The 'nr of rest pmus to process' indicates the remaining pmus which are waiting for process. When we see it's 0 during data processing, we can know all of the pmus have been processed.

The new layout is considered to be compatible with old perf.data (the perf.data generated by old perf tool).

This patch doesn't change the processing part, so the result is

  root@otcpl-adl-s-2:~# perf report --header-only -I
  ...
  # cpu pmu capabilities: branches=32, max_precise=3, pmu_name=alderlake_hybrid
---
 .../Documentation/perf.data-file-format.txt   |  6 ++
 tools/perf/util/header.c                      | 68 ++++++++++++++++---
 2 files changed, 66 insertions(+), 8 deletions(-)
tools/perf/Documentation/perf.data-file-format.txt +6 -0
index d9d82ca8aeb7..ee0af7bf655b 100644
@@ -383,6 +383,8 @@ struct {
 		char	name[];
 		char	value[];
 	} [nr_cpu_pmu_caps]
+	char pmu_name[];
+	int nr_rest_pmus;
 };
 
 
@@ -391,6 +393,10 @@ Example:
 
 	HEADER_CLOCK_DATA = 29,
 
+ On hybrid system:
+ cpu_core pmu capabilities: branches=32, max_precise=3, pmu_name=alderlake_hybrid
+ cpu_atom pmu capabilities: branches=32, max_precise=3, pmu_name=alderlake_hybrid
+
 	Contains clock id and its reference time together with wall clock
 	time taken at the 'same time', both values are in nanoseconds.
 	The format of data is as below.
tools/perf/util/header.c +60 -8

100 lines not on this page · raw message

Signature · 1 line
2.17.1
author
#5 lore raw

PATCH v2 3/3 perf header: Process hybrid CPU_PMU_CAPS

In reply to Jin Yao

For CPU_PMU_CAPS feature, the layout is extended to:

<pmu1 caps nr>
<caps string 1>
<caps string 2>
<caps string N>
<pmu1 name>
<nr of rest pmus to process>
<pmu2 caps nr>
<caps string 1>
<caps string 2>
<caps string N>
<pmu2 name>
<nr of rest pmus to process>

When we see '0' at 'nr of rest pmus to process', we know all the pmu have been processed yet.

With this patch, some examples,

New perf tool with new perf.data
(new perf.data is generated on hybrid platform):

  root@otcpl-adl-s-2:~# perf report --header-only -I
  ...
  # cpu_core pmu capabilities: branches=32, max_precise=3, pmu_name=alderlake_hybrid
  # cpu_atom pmu capabilities: branches=32, max_precise=3, pmu_name=alderlake_hybrid

New perf tool with new perf.data
(new perf.data is generated on non-hybrid platform):

  root@kbl-ppc:~# perf report --header-only -I
  ...
  # cpu pmu capabilities: branches=32, max_precise=3, pmu_name=skylake

New perf tool with old perf.data
(old perf.data is generated by old perf tool on non-hybrid platform):

  root@kbl-ppc:~# perf report --header-only -I
  ...
  # cpu pmu capabilities: branches=32, max_precise=3, pmu_name=skylake
---
 tools/perf/util/env.c    |   6 +++
 tools/perf/util/env.h    |  11 +++-
 tools/perf/util/header.c | 114 ++++++++++++++++++++++++++++++++++-----
 3 files changed, 115 insertions(+), 16 deletions(-)
tools/perf/util/env.c +6 -0
index 744ae87b5bfa..ea952ec507da 100644
@@ -208,6 +208,12 @@ void perf_env__exit(struct perf_env *env)
 		zfree(&env->hybrid_nodes[i].cpus);
 	}
 	zfree(&env->hybrid_nodes);
+
+	for (i = 0; i < env->nr_cpu_pmu_caps_nodes; i++) {
+		zfree(&env->cpu_pmu_caps_nodes[i].cpu_pmu_caps);
+		zfree(&env->cpu_pmu_caps_nodes[i].pmu_name);
+	}
+	zfree(&env->cpu_pmu_caps_nodes);
 }
 
 void perf_env__init(struct perf_env *env __maybe_unused)
tools/perf/util/env.h +9 -2
index e5e5deebe68d..5885c055b63e 100644
@@ -42,6 +42,13 @@ struct hybrid_node {
 	char	*cpus;
 };
 
+struct cpu_pmu_caps_node {
+	int		nr_cpu_pmu_caps;
+	unsigned int	max_branches;
+	char		*cpu_pmu_caps;
+	char		*pmu_name;
+};
+
 struct perf_env {
 	char			*hostname;
 	char			*os_release;
@@ -63,15 +70,14 @@ struct perf_env {
 	int			nr_memory_nodes;
 	int			nr_pmu_mappings;
 	int			nr_groups;
-	int			nr_cpu_pmu_caps;
 	int			nr_hybrid_nodes;
+	int			nr_cpu_pmu_caps_nodes;
 	char			*cmdline;
 	const char		**cmdline_argv;
 	char			*sibling_cores;
 	char			*sibling_dies;
 	char			*sibling_threads;
 	char			*pmu_mappings;
-	char			*cpu_pmu_caps;
 	struct cpu_topology_map	*cpu;
 	struct cpu_cache_level	*caches;
 	int			 caches_cnt;
@@ -84,6 +90,7 @@ struct perf_env {
 	struct memory_node	*memory_nodes;
 	unsigned long long	 memory_bsize;
 	struct hybrid_node	*hybrid_nodes;
+	struct cpu_pmu_caps_node	*cpu_pmu_caps_nodes;
 #ifdef HAVE_LIBBPF_SUPPORT
 	/*
 	 * bpf_info_lock protects bpf rbtrees. This is needed because the
tools/perf/util/header.c +100 -14

163 lines not on this page · raw message

Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH v2 1/3] perf header: Support HYBRID_TOPOLOGY feature

In reply to Jin Yao
Quoted 40 lines · Jin Yao

It would be useful to let user know the hybrid topology. Adding HYBRID_TOPOLOGY feature in header to indicate the core cpus and the atom cpus.

With this patch,

For the perf.data generated on hybrid platform, reports the hybrid cpu list.

  root@otcpl-adl-s-2:~# perf report --header-only -I
  ...
  # hybrid cpu system:
  # cpu_core cpu list : 0-15
  # cpu_atom cpu list : 16-23

For the perf.data generated on non-hybrid platform, reports the message that HYBRID_TOPOLOGY is missing.

  root@kbl-ppc:~# perf report --header-only -I
  ...
  # missing features: TRACING_DATA BRANCH_STACK GROUP_DESC AUXTRACE STAT CLOCKID DIR_FORMAT COMPRESSED CLOCK_DATA HYBRID_TOPOLOGY
---
 .../Documentation/perf.data-file-format.txt   | 14 +++
 tools/perf/util/cputopo.c                     | 80 +++++++++++++++++
 tools/perf/util/cputopo.h                     | 13 +++
 tools/perf/util/env.c                         |  6 ++
 tools/perf/util/env.h                         |  7 ++
 tools/perf/util/header.c                      | 87 +++++++++++++++++++
 tools/perf/util/header.h                      |  1 +
 tools/perf/util/pmu-hybrid.h                  | 11 +++
 8 files changed, 219 insertions(+)
tools/perf/Documentation/perf.data-file-format.txt +0 -0
index 9ee96640744e..d9d82ca8aeb7 100644
@@ -402,6 +402,20 @@ struct {
 	u64 clockid_time_ns;

tools/perf/Documentation/perf.data-file-format.txt struct { · line 412

Quoted 10 lines
tools/perf/Documentation/perf.data-file-format.txt +8 -0
 };
 
+	HEADER_HYBRID_TOPOLOGY = 30,
+
+Indicate the hybrid CPUs. The format of data is as below.
+
+struct {
+	char *pmu_name;
+	char *cpus;
+};

this is missing the nr count, should be like:

struct {
	u32 nr;
	struct {
	     char *pmu_name;
	     char *cpus;
	} [nr]
}

jirka

author
#3 lore raw

Re: [PATCH v2 1/3] perf header: Support HYBRID_TOPOLOGY feature

Hi Jiri,

Quoted 62 lines · Jiri Olsa
Quoted 40 lines · Jin Yao

It would be useful to let user know the hybrid topology. Adding HYBRID_TOPOLOGY feature in header to indicate the core cpus and the atom cpus.

With this patch,

For the perf.data generated on hybrid platform, reports the hybrid cpu list.

   root@otcpl-adl-s-2:~# perf report --header-only -I
   ...
   # hybrid cpu system:
   # cpu_core cpu list : 0-15
   # cpu_atom cpu list : 16-23

For the perf.data generated on non-hybrid platform, reports the message that HYBRID_TOPOLOGY is missing.

   root@kbl-ppc:~# perf report --header-only -I
   ...
   # missing features: TRACING_DATA BRANCH_STACK GROUP_DESC AUXTRACE STAT CLOCKID DIR_FORMAT COMPRESSED CLOCK_DATA HYBRID_TOPOLOGY
---
  .../Documentation/perf.data-file-format.txt   | 14 +++
  tools/perf/util/cputopo.c                     | 80 +++++++++++++++++
  tools/perf/util/cputopo.h                     | 13 +++
  tools/perf/util/env.c                         |  6 ++
  tools/perf/util/env.h                         |  7 ++
  tools/perf/util/header.c                      | 87 +++++++++++++++++++
  tools/perf/util/header.h                      |  1 +
  tools/perf/util/pmu-hybrid.h                  | 11 +++
  8 files changed, 219 insertions(+)
tools/perf/Documentation/perf.data-file-format.txt +0 -0
index 9ee96640744e..d9d82ca8aeb7 100644
@@ -402,6 +402,20 @@ struct {
  	u64 clockid_time_ns;

tools/perf/Documentation/perf.data-file-format.txt struct { · line 412

Quoted 10 lines
tools/perf/Documentation/perf.data-file-format.txt +8 -0
  };
 
+	HEADER_HYBRID_TOPOLOGY = 30,
+
+Indicate the hybrid CPUs. The format of data is as below.
+
+struct {
+	char *pmu_name;
+	char *cpus;
+};

this is missing the nr count, should be like:

struct {
	u32 nr;
	struct {
	     char *pmu_name;
	     char *cpus;
	} [nr]
}
Quoted 2 lines

jirka

Yes, we should say the format of data is:

struct {
	u32 nr;
	struct {
		char *pmu_name;
		char *cpus;
	} [nr]
}

I will update 'perf.data-file-format.txt' in v3.

Thanks
Jin Yao