Skip to contentSkip to conversation

perf header: Support HYBRID_TOPOLOGY and HYBRID_CPU_PMU_CAPS

PATCH Superseded Jin Yao 2 participants 5 messages May 11, 2021 – May 14, 2021 perf events

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Jin Yao

author
#0 lore raw

v3 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.

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                      | 250 ++++++++++++++++--
 tools/perf/util/header.h                      |   2 +
 tools/perf/util/pmu-hybrid.h                  |  11 +
 8 files changed, 398 insertions(+), 19 deletions(-)
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH v3 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 v3 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 that is 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                      | 163 ++++++++++++++++--
 tools/perf/util/header.h                      |   1 +
 5 files changed, 176 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 +144 -19

247 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
#3 lore raw

Re: [PATCH v3 2/2] perf header: Support HYBRID_CPU_PMU_CAPS feature

On Tue, May 11, 2021 at 01:30:03PM +0800, Jin Yao wrote:

SNIP

Quoted 13 lines
tools/perf/Documentation/perf.data-file-format.txt +5 -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 {

tools/perf/Documentation/perf.data-file-format.txt Example: · line 436

Quoted 10 lines
tools/perf/Documentation/perf.data-file-format.txt +10 -0
+	u32 nr_pmu;
+	struct {
+		u32 nr_cpu_pmu_caps;
+		{
+			char	name[];
+			char	value[];
+		} [nr_cpu_pmu_caps];
+		char pmu_name[];
+	} [nr_pmu];
+};

when I saw it's similar to the previous one I thought we could have one big hybrid feature.. but that would be probably more complex and we might not be able to reuse the code as much as you did

Quoted 4 lines
tools/perf/Documentation/perf.data-file-format.txt +0 -0
 free_value:
@@ -3142,6 +3208,64 @@ static int process_cpu_pmu_caps(struct feat_fd *ff,
 	return -1;
 }

tools/perf/Documentation/perf.data-file-format.txt static int process_cpu_pmu_caps(struct feat_fd *ff, · line 3219

Quoted 10 lines
tools/perf/Documentation/perf.data-file-format.txt +9 -0
 
+static int process_cpu_pmu_caps(struct feat_fd *ff,
+				void *data __maybe_unused)
+{
+	int ret;
+
+	ret = process_per_cpu_pmu_caps(ff, &ff->ph->env.nr_cpu_pmu_caps,
+				       &ff->ph->env.cpu_pmu_caps,
+				       &ff->ph->env.max_branches);
+	return ret;

why the 'ret' var? could be just:

return process_per_cpu_pmu_caps(...

Quoted 22 lines
tools/perf/Documentation/perf.data-file-format.txt +22 -0
+}
+
+static int process_hybrid_cpu_pmu_caps(struct feat_fd *ff,
+				       void *data __maybe_unused)
+{
+	struct hybrid_cpc_node *nodes;
+	u32 nr_pmu, i;
+	int ret;
+
+	if (do_read_u32(ff, &nr_pmu))
+		return -1;
+
+	if (!nr_pmu) {
+		pr_debug("hybrid cpu pmu capabilities not available\n");
+		return 0;
+	}
+
+	nodes = zalloc(sizeof(*nodes) * nr_pmu);
+	if (!nodes)
+		return -ENOMEM;
+
+	for (i = 0; i < nr_pmu; i++) {

tools/perf/Documentation/perf.data-file-format.txt static int process_cpu_pmu_caps(struct feat_fd *ff, · line 3251

Quoted 10 lines
tools/perf/Documentation/perf.data-file-format.txt +10 -0
+		struct hybrid_cpc_node *n = &nodes[i];
+
+		ret = process_per_cpu_pmu_caps(ff, &n->nr_cpu_pmu_caps,
+					       &n->cpu_pmu_caps,
+					       &n->max_branches);
+		if (ret)
+			goto err;
+
+		n->pmu_name = do_read_string(ff);
+		if (!n->pmu_name)

should you set 'ret = -1' in here?

other than this both patches look good to me

thanks,
jirka

Quoted 10 lines
tools/perf/Documentation/perf.data-file-format.txt +10 -0
+			goto err;
+	}
+
+	ff->ph->env.nr_hybrid_cpc_nodes = nr_pmu;
+	ff->ph->env.hybrid_cpc_nodes = nodes;
+	return 0;
+
+err:
+	for (i = 0; i < nr_pmu; i++) {
+		free(nodes[i].cpu_pmu_caps);

SNIP

author
#4 lore raw

Re: [PATCH v3 2/2] perf header: Support HYBRID_CPU_PMU_CAPS feature

Hi Jiri,

Quoted 23 lines · Jiri Olsa

On Tue, May 11, 2021 at 01:30:03PM +0800, Jin Yao wrote:

SNIP

Quoted 19 lines
tools/perf/Documentation/perf.data-file-format.txt +11 -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[];
Quoted 9 lines

tools/perf/Documentation/perf.data-file-format.txt Example: · line 436

Quoted 4 lines
tools/perf/Documentation/perf.data-file-format.txt +4 -0
+		} [nr_cpu_pmu_caps];
+		char pmu_name[];
+	} [nr_pmu];
+};

when I saw it's similar to the previous one I thought we could have one big hybrid feature.. but that would be probably more complex and we might not be able to reuse the code as much as you did

Yes. Actually I had the same idea before but as you said the code would be more complex.

Quoted 18 lines
Quoted 5 lines
tools/perf/Documentation/perf.data-file-format.txt +0 -0
  free_value:
@@ -3142,6 +3208,64 @@ static int process_cpu_pmu_caps(struct feat_fd *ff,
  	return -1;
  }

tools/perf/Documentation/perf.data-file-format.txt static int process_cpu_pmu_caps(struct feat_fd *ff, · line 3219

Quoted 10 lines
tools/perf/Documentation/perf.data-file-format.txt +9 -0
 
+static int process_cpu_pmu_caps(struct feat_fd *ff,
+				void *data __maybe_unused)
+{
+	int ret;
+
+	ret = process_per_cpu_pmu_caps(ff, &ff->ph->env.nr_cpu_pmu_caps,
+				       &ff->ph->env.cpu_pmu_caps,
+				       &ff->ph->env.max_branches);
+	return ret;

why the 'ret' var? could be just:

Quoted 2 lines

return process_per_cpu_pmu_caps(...

OK, I will fix it in v4.

Quoted 26 lines
Quoted 26 lines
tools/perf/Documentation/perf.data-file-format.txt +26 -0
+}
+
+static int process_hybrid_cpu_pmu_caps(struct feat_fd *ff,
+				       void *data __maybe_unused)
+{
+	struct hybrid_cpc_node *nodes;
+	u32 nr_pmu, i;
+	int ret;
+
+	if (do_read_u32(ff, &nr_pmu))
+		return -1;
+
+	if (!nr_pmu) {
+		pr_debug("hybrid cpu pmu capabilities not available\n");
+		return 0;
+	}
+
+	nodes = zalloc(sizeof(*nodes) * nr_pmu);
+	if (!nodes)
+		return -ENOMEM;
+
+	for (i = 0; i < nr_pmu; i++) {
+		struct hybrid_cpc_node *n = &nodes[i];
+
+		ret = process_per_cpu_pmu_caps(ff, &n->nr_cpu_pmu_caps,
+					       &n->cpu_pmu_caps,
Quoted 9 lines

tools/perf/Documentation/perf.data-file-format.txt static int process_cpu_pmu_caps(struct feat_fd *ff, · line 3251

Quoted 6 lines
tools/perf/Documentation/perf.data-file-format.txt +6 -0
+					       &n->max_branches);
+		if (ret)
+			goto err;
+
+		n->pmu_name = do_read_string(ff);
+		if (!n->pmu_name)

should you set 'ret = -1' in here?

Yes, I should add 'ret = -1' before 'n->pmu_name = do_read_string(ff);'.

Quoted 2 lines

other than this both patches look good to me

Thanks, I will prepare v4 soon.

Thanks
Jin Yao

Quoted 16 lines

thanks,
jirka

Quoted 10 lines
tools/perf/Documentation/perf.data-file-format.txt +10 -0
+			goto err;
+	}
+
+	ff->ph->env.nr_hybrid_cpc_nodes = nr_pmu;
+	ff->ph->env.hybrid_cpc_nodes = nodes;
+	return 0;
+
+err:
+	for (i = 0; i < nr_pmu; i++) {
+		free(nodes[i].cpu_pmu_caps);

SNIP