Skip to contentSkip to conversation

perf header: Support HYBRID_TOPOLOGY and HYBRID_CPU_PMU_CAPS

PATCH In review Jin Yao 2 participants 5 messages May 14, 2021 – May 18, 2021 perf events

lore
Share & tools
lore

Jin Yao

author
#0 lore raw

v4 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 HYBRID_CPU_PMU_CAPS feature in perf header is created to support multiple cpu pmus.

v4:
---
- Only minor update in '[PATCH v4 2/2] perf header: Support HYBRID_CPU_PMU_CAPS feature'.
1. Directly return process_per_cpu_pmu_caps() in process_cpu_pmu_caps. Remove the variable 'ret'.
2. Set 'ret = -1' if (!n->pmu_name) in process_hybrid_cpu_pmu_caps().

v3:
---
- For "[PATCH v3 1/2] perf header: Support HYBRID_TOPOLOGY feature", update HEADER_HYBRID_TOPOLOGY format in perf.data-file-format.txt.

- For "[PATCH v3 2/2] perf header: Support HYBRID_CPU_PMU_CAPS feature", Don't extend the original CPU_PMU_CAPS to support hybrid cpu pmus. Instead, create a new feature 'HYBRID_CPU_PMU_CAPS' in header.

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 (2):
perf header: Support HYBRID_TOPOLOGY feature perf header: Support HYBRID_CPU_PMU_CAPS feature

 .../Documentation/perf.data-file-format.txt   |  33 +++
 tools/perf/util/cputopo.c                     |  80 ++++++
 tools/perf/util/cputopo.h                     |  13 +
 tools/perf/util/env.c                         |  12 +
 tools/perf/util/env.h                         |  16 ++
 tools/perf/util/header.c                      | 249 ++++++++++++++++--
 tools/perf/util/header.h                      |   2 +
 tools/perf/util/pmu-hybrid.h                  |  11 +
 8 files changed, 397 insertions(+), 19 deletions(-)
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH v4 1/2 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   | 17 ++++
 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, 222 insertions(+)
tools/perf/Documentation/perf.data-file-format.txt +17 -0
index 9ee96640744e..fbee9e580ee4 100644
@@ -402,6 +402,23 @@ struct {
 	u64 clockid_time_ns;
 };
 
+	HEADER_HYBRID_TOPOLOGY = 30,
+
+Indicate the hybrid CPUs. The format of data is as below.
+
+struct {
+	u32 nr;
+	struct {
+		char pmu_name[];
+		char cpus[];
+	} [nr]; /* Variable length records */
+};
+
+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
#2 lore raw

PATCH v4 2/2 perf header: Support HYBRID_CPU_PMU_CAPS feature

In reply to Jin Yao

Perf has supported CPU_PMU_CAPS feature to display a list of cpu PMU capabilities. But on hybrid platform, it may have several cpu pmus (such as, "cpu_core" and "cpu_atom"). The CPU_PMU_CAPS feature is hard to extend to support multiple cpu pmus well if it needs to be compatible for the case of old perf data file + new perf tool.

So for better compatibility we now create a new feature HYBRID_CPU_PMU_CAPS in header.

For the perf.data 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
  # missing features: TRACING_DATA BRANCH_STACK GROUP_DESC AUXTRACE STAT CLOCKID DIR_FORMAT COMPRESSED CPU_PMU_CAPS CLOCK_DATA

For the perf.data generated on non-hybrid platform

  root@kbl-ppc:~# perf report --header-only -I
  # cpu pmu capabilities: branches=32, max_precise=3, pmu_name=skylake
  # missing features: TRACING_DATA BRANCH_STACK GROUP_DESC AUXTRACE STAT CLOCKID DIR_FORMAT COMPRESSED CLOCK_DATA HYBRID_TOPOLOGY HYBRID_CPU_PMU_CAPS
---
 .../Documentation/perf.data-file-format.txt   |  16 ++
 tools/perf/util/env.c                         |   6 +
 tools/perf/util/env.h                         |   9 +
 tools/perf/util/header.c                      | 162 ++++++++++++++++--
 tools/perf/util/header.h                      |   1 +
 5 files changed, 175 insertions(+), 19 deletions(-)
tools/perf/Documentation/perf.data-file-format.txt +16 -0
index fbee9e580ee4..e6ff8c898ada 100644
@@ -419,6 +419,22 @@ Example:
   cpu_core cpu list : 0-15
   cpu_atom cpu list : 16-23
 
+	HEADER_HYBRID_CPU_PMU_CAPS = 31,
+
+	A list of hybrid CPU PMU capabilities.
+
+struct {
+	u32 nr_pmu;
+	struct {
+		u32 nr_cpu_pmu_caps;
+		{
+			char	name[];
+			char	value[];
+		} [nr_cpu_pmu_caps];
+		char pmu_name[];
+	} [nr_pmu];
+};
+
 	other bits are reserved and should ignored for now
 	HEADER_FEAT_BITS	= 256,
 
tools/perf/util/env.c +6 -0
index 744ae87b5bfa..1bea5b29b12d 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_hybrid_cpc_nodes; i++) {
+		zfree(&env->hybrid_cpc_nodes[i].cpu_pmu_caps);
+		zfree(&env->hybrid_cpc_nodes[i].pmu_name);
+	}
+	zfree(&env->hybrid_cpc_nodes);
 }
 
 void perf_env__init(struct perf_env *env __maybe_unused)
tools/perf/util/env.h +9 -0
index e5e5deebe68d..6824a7423a2d 100644
@@ -42,6 +42,13 @@ struct hybrid_node {
 	char	*cpus;
 };
 
+struct hybrid_cpc_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;
@@ -65,6 +72,7 @@ struct perf_env {
 	int			nr_groups;
 	int			nr_cpu_pmu_caps;
 	int			nr_hybrid_nodes;
+	int			nr_hybrid_cpc_nodes;
 	char			*cmdline;
 	const char		**cmdline_argv;
 	char			*sibling_cores;
@@ -84,6 +92,7 @@ struct perf_env {
 	struct memory_node	*memory_nodes;
 	unsigned long long	 memory_bsize;
 	struct hybrid_node	*hybrid_nodes;
+	struct hybrid_cpc_node	*hybrid_cpc_nodes;
 #ifdef HAVE_LIBBPF_SUPPORT
 	/*
 	 * bpf_info_lock protects bpf rbtrees. This is needed because the
tools/perf/util/header.c +143 -19

246 lines not on this page · raw message

tools/perf/util/header.h +1 -0
index 3f12ec0eb84e..ae6b1cf19a7d 100644
@@ -46,6 +46,7 @@ enum {
 	HEADER_CPU_PMU_CAPS,
 	HEADER_CLOCK_DATA,
 	HEADER_HYBRID_TOPOLOGY,
+	HEADER_HYBRID_CPU_PMU_CAPS,
 	HEADER_LAST_FEATURE,
 	HEADER_FEAT_BITS	= 256,
 };
Signature · 1 line
2.17.1
Acked-by on the v4 series
#3 lore raw
In reply to Jin Yao
Quoted 9 lines · Jin Yao

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 HYBRID_CPU_PMU_CAPS feature in perf header is created to support multiple cpu pmus.

Quoted 6 lines

v4:
---
- Only minor update in '[PATCH v4 2/2] perf header: Support HYBRID_CPU_PMU_CAPS feature'.
1. Directly return process_per_cpu_pmu_caps() in process_cpu_pmu_caps. Remove the variable 'ret'.
2. Set 'ret = -1' if (!n->pmu_name) in process_hybrid_cpu_pmu_caps().

thanks,
jirka

Quoted 39 lines

v3:
---
- For "[PATCH v3 1/2] perf header: Support HYBRID_TOPOLOGY feature", update HEADER_HYBRID_TOPOLOGY format in perf.data-file-format.txt.

- For "[PATCH v3 2/2] perf header: Support HYBRID_CPU_PMU_CAPS feature", Don't extend the original CPU_PMU_CAPS to support hybrid cpu pmus. Instead, create a new feature 'HYBRID_CPU_PMU_CAPS' in header.

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 (2):
perf header: Support HYBRID_TOPOLOGY feature perf header: Support HYBRID_CPU_PMU_CAPS feature

 .../Documentation/perf.data-file-format.txt   |  33 +++
 tools/perf/util/cputopo.c                     |  80 ++++++
 tools/perf/util/cputopo.h                     |  13 +
 tools/perf/util/env.c                         |  12 +
 tools/perf/util/env.h                         |  16 ++
 tools/perf/util/header.c                      | 249 ++++++++++++++++--
 tools/perf/util/header.h                      |   2 +
 tools/perf/util/pmu-hybrid.h                  |  11 +
 8 files changed, 397 insertions(+), 19 deletions(-)
Signature · 1 line
2.17.1
author
#4 lore raw

Hi Jiri,

Quoted 16 lines · Jiri Olsa
Quoted 9 lines · Jin Yao

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 HYBRID_CPU_PMU_CAPS feature in perf header is created to support multiple cpu pmus.

Quoted 6 lines

v4:
---
- Only minor update in '[PATCH v4 2/2] perf header: Support HYBRID_CPU_PMU_CAPS feature'.
1. Directly return process_per_cpu_pmu_caps() in process_cpu_pmu_caps. Remove the variable 'ret'.
2. Set 'ret = -1' if (!n->pmu_name) in process_hybrid_cpu_pmu_caps().

Quoted 5 lines

thanks,
jirka

Thanks so much!

I have some followup patches which depend on this patchset. I will post them after this patchset is applied.

Thanks
Jin Yao