perf header: Add die information in CPU topology
PATCH 1/3 perf header: Add die information in CPU topology
From: Kan Liang <[email protected]>
With the new CPUID.1F, a new level type of CPU topology, 'die', is introduced. The 'die' information in CPU topology should be added in perf header.
To be compatible with old perf.data, the patch checks the section size before reading the die information. The new info is added at the end of the cpu_topology section, the old perf tool ignores the extra data. It never reads data crossing the section boundary.
The new perf tool with the patch can be used on legacy kernel. Add a new function check_x86_die_exists() to check if die topology information is supported by kernel. The function only check X86 and CPU 0. Assuming other CPUs have same topology.
Use similar method for core and socket to support die id and sibling dies string.
Add cpu_map__get_die_id() in cpumap.c to fetch die id information.
--- tools/perf/Documentation/perf.data-file-format.txt | 9 +- tools/perf/util/cpumap.c | 7 ++ tools/perf/util/cpumap.h | 1 + tools/perf/util/cputopo.c | 83 ++++++++++++++-- tools/perf/util/cputopo.h | 7 +- tools/perf/util/env.c | 1 + tools/perf/util/env.h | 3 + tools/perf/util/header.c | 104 +++++++++++++++++++-- 8 files changed, 193 insertions(+), 22 deletions(-)
tools/perf/Documentation/perf.data-file-format.txt +7 -2
@@ -153,7 +153,7 @@ struct { String lists defining the core and CPU threads topology. The string lists are followed by a variable length array -which contains core_id and socket_id of each cpu. +which contains core_id, die_id (for x86) and socket_id of each cpu. The number of entries can be determined by the size of the section minus the sizes of both string lists.
@@ -162,14 +162,19 @@ struct { struct perf_header_string_list threads; /* Variable length */ struct { uint32_t core_id; + uint32_t die_id; uint32_t socket_id; } cpus[nr]; /* Variable length records */ }; Example: - sibling cores : 0-3 + sibling cores : 0-8 + sibling dies : 0-3 + sibling dies : 4-7 sibling threads : 0-1 sibling threads : 2-3 + sibling threads : 4-5 + sibling threads : 6-7 HEADER_NUMA_TOPOLOGY = 14,
tools/perf/util/cpumap.c +7 -0
@@ -373,6 +373,13 @@ int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res,return 0 ; } +int cpu_map__get_die_id (int cpu) +{ +int value, ret =cpu__get_topology_int (cpu,"die_id" , &value); + +return ret ?: value; +} +int cpu_map__get_core_id (int cpu) {int value, ret =cpu__get_topology_int (cpu,"core_id" , &value);
tools/perf/util/cpumap.h +1 -0
@@ -25,6 +25,7 @@ size_t cpu_map__snprint_mask(struct cpu_map *map, char *buf, size_t size);size_t cpu_map__fprintf (struct cpu_map *map,FILE *fp);int cpu_map__get_socket_id (int cpu);int cpu_map__get_socket (struct cpu_map *map,int idx,void *data); +int cpu_map__get_die_id (int cpu);int cpu_map__get_core_id (int cpu);int cpu_map__get_core (struct cpu_map *map,int idx,void *data);int cpu_map__build_socket_map (struct cpu_map *cpus,struct cpu_map **sockp);
tools/perf/util/cputopo.c +73 -10
163 lines not on this page · raw message
tools/perf/util/cputopo.h +5 -2
@@ -7,8 +7,10 @@struct cpu_topology {u32 core_sib; +u32 die_sib;u32 thread_sib;char **core_siblings; +char **die_siblings;char **thread_siblings; };
@@ -24,8 +26,9 @@ struct numa_topology {struct numa_topology_node nodes[0 ]; }; -struct cpu_topology *cpu_topology__new (void ); -void cpu_topology__delete (struct cpu_topology *tp); +bool check_x86_die_exists (void ); +struct cpu_topology *cpu_topology__new (bool has_die); +void cpu_topology__delete (struct cpu_topology *tp,bool has_die);struct numa_topology *numa_topology__new (void );void numa_topology__delete (struct numa_topology *tp);
tools/perf/util/env.c +1 -0
@@ -246,6 +246,7 @@ int perf_env__read_cpu_topology_map(struct perf_env *env)for (cpu =0 ; cpu < nr_cpus; ++cpu) { env->cpu[cpu].core_id =cpu_map__get_core_id (cpu); env->cpu[cpu].socket_id =cpu_map__get_socket_id (cpu); + env->cpu[cpu].die_id =cpu_map__get_die_id (cpu); } env->nr_cpus_avail = nr_cpus;
tools/perf/util/env.h +3 -0
@@ -9,6 +9,7 @@struct cpu_topology_map {int socket_id; +int die_id;int core_id; };
@@ -49,6 +50,7 @@ struct perf_env {int nr_cmdline;int nr_sibling_cores; +int nr_sibling_dies;int nr_sibling_threads;int nr_numa_nodes;int nr_memory_nodes;
@@ -57,6 +59,7 @@ struct perf_env {char *cmdline;const char **cmdline_argv;char *sibling_cores; +char *sibling_dies;char *sibling_threads;char *pmu_mappings;struct cpu_topology_map *cpu;
tools/perf/util/header.c +96 -8
149 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 2/3 perf stat: Support per-die aggregation
From: Kan Liang <[email protected]>
It is useful to aggregate counts per die. E.g. Uncore becomes die-scope on Xeon Cascade Lake-AP.
Introduce a new option "--per-die" to support per-die aggregation.
The global id for each core has been changed to socket + die id + core id. The global id for each die is socket + die id.
Add die information for per-core aggregation. The output of per-core aggregation will be changed from "S0-C0" to "S0-D0-C0". Any scripts which rely on the output format of per-core aggregation probably be broken.
For perf stat record/report, there is no die information when processing the old perf.data. The per-die result will be the same as per-socket.
--- tools/perf/Documentation/perf-stat.txt | 10 +++++ tools/perf/builtin-stat.c | 73 +++++++++++++++++++++++++++++++--- tools/perf/util/cpumap.c | 48 +++++++++++++++++++--- tools/perf/util/cpumap.h | 9 ++++- tools/perf/util/stat-display.c | 27 +++++++++++-- tools/perf/util/stat-shadow.c | 1 + tools/perf/util/stat.c | 1 + tools/perf/util/stat.h | 1 + 8 files changed, 155 insertions(+), 15 deletions(-)
tools/perf/Documentation/perf-stat.txt +10 -0
@@ -200,6 +200,13 @@ use --per-socket in addition to -a. (system-wide). The output includes the socket number and the number of online processors on that socket. This is useful to gauge the amount of aggregation. +--per-die:: +Aggregate counts per processor die for system-wide mode measurements. This +is a useful mode to detect imbalance between dies. To enable this mode, +use --per-die in addition to -a. (system-wide). The output includes the +die number and the number of online processors on that die. This is +useful to gauge the amount of aggregation. + --per-core:: Aggregate counts per physical processor for system-wide mode measurements. This is a useful mode to detect imbalance between physical cores. To enable this mode,
@@ -239,6 +246,9 @@ Input file name. --per-socket:: Aggregate counts per processor socket for system-wide mode measurements. +--per-die:: +Aggregate counts per processor die for system-wide mode measurements. + --per-core:: Aggregate counts per physical processor for system-wide mode measurements.
tools/perf/builtin-stat.c +67 -6
136 lines not on this page · raw message
tools/perf/util/cpumap.c +43 -5
79 lines not on this page · raw message
tools/perf/util/cpumap.h +8 -1
@@ -26,9 +26,11 @@ size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp);int cpu_map__get_socket_id (int cpu);int cpu_map__get_socket (struct cpu_map *map,int idx,void *data);int cpu_map__get_die_id (int cpu); +int cpu_map__get_die (struct cpu_map *map,int idx,void *data);int cpu_map__get_core_id (int cpu);int cpu_map__get_core (struct cpu_map *map,int idx,void *data);int cpu_map__build_socket_map (struct cpu_map *cpus,struct cpu_map **sockp); +int cpu_map__build_die_map (struct cpu_map *cpus,struct cpu_map **diep);int cpu_map__build_core_map (struct cpu_map *cpus,struct cpu_map **corep);const struct cpu_map *cpu_map__online (void );/* thread unsafe */
@@ -44,7 +46,12 @@ static inline int cpu_map__socket(struct cpu_map *sock, int s)static inline int cpu_map__id_to_socket (int id) { -return id >>16 ; +return id >>24 ; +} + +static inline int cpu_map__id_to_die (int id) +{ +return (id >>16 ) &0xff ; }static inline int cpu_map__id_to_cpu (int id)
tools/perf/util/stat-display.c +24 -3
@@ -69,8 +69,9 @@ static void aggr_printout(struct perf_stat_config *config, {switch (config->aggr_mode) {case AGGR_CORE : - fprintf(config->output, "S%d-C%*d%s%*d%s", + fprintf(config->output, "S%d-D%d-C%*d%s%*d%s", cpu_map__id_to_socket(id), + cpu_map__id_to_die(id), config->csv_output ? 0 : -8, cpu_map__id_to_cpu(id), config->csv_sep,
@@ -78,6 +79,16 @@ static void aggr_printout(struct perf_stat_config *config, nr, config->csv_sep);break ; +case AGGR_DIE : +fprintf (config->output,"S%d-D%*d%s%*d%s" , +cpu_map__id_to_socket (id <<16 ), + config->csv_output ?0 :-8 , +cpu_map__id_to_die (id <<16 ), + config->csv_sep, + config->csv_output ?0 :4 , + nr, + config->csv_sep); +break ;case AGGR_SOCKET : fprintf(config->output, "S%*d%s%*d%s", config->csv_output ? 0 : -5,
@@ -89,8 +100,9 @@ static void aggr_printout(struct perf_stat_config *config,break ;case AGGR_NONE :if (evsel->percore) { -fprintf (config->output,"S%d-C%*d%s" , +fprintf (config->output,"S%d-D%d-C%*d%s" ,cpu_map__id_to_socket (id), +cpu_map__id_to_die (id), config->csv_output ?0 :-5 ,cpu_map__id_to_cpu (id), config->csv_sep); }else {
@@ -407,6 +419,7 @@ static void printout(struct perf_stat_config *config, int id, int nr, [AGGR_THREAD] = 1, [AGGR_NONE] = 1, [AGGR_SOCKET] = 2, + [AGGR_DIE] = 2, [AGGR_CORE] = 2, };
@@ -879,7 +892,8 @@ static void print_no_aggr_metric(struct perf_stat_config *config, }static int aggr_header_lens[] = { - [AGGR_CORE ] =18 , + [AGGR_CORE ] =24 , + [AGGR_DIE ] =18 , [AGGR_SOCKET ] =12 , [AGGR_NONE ] =6 , [AGGR_THREAD ] =24 ,
@@ -888,6 +902,7 @@ static int aggr_header_lens[] = {static const char *aggr_header_csv[] = { [AGGR_CORE ] ="core,cpus," , + [AGGR_DIE ] ="die,cpus" , [AGGR_SOCKET ] ="socket,cpus" , [AGGR_NONE ] ="cpu," , [AGGR_THREAD ] ="comm-pid," ,
@@ -954,6 +969,11 @@ static void print_interval(struct perf_stat_config *config,if (!metric_only)fprintf (output," counts %*s events\n" , unit_width,"unit" );break ; +case AGGR_DIE : +fprintf (output,"# time die cpus" ); +if (!metric_only) +fprintf (output," counts %*s events\n" , unit_width,"unit" ); +break ;case AGGR_CORE :fprintf (output,"# time core cpus" );if (!metric_only)
@@ -1165,6 +1185,7 @@ perf_evlist__print_counters(struct perf_evlist *evlist,switch (config->aggr_mode) {case AGGR_CORE : +case AGGR_DIE :case AGGR_SOCKET :print_aggr (config, evlist, prefix);break ;
tools/perf/util/stat-shadow.c +1 -0
@@ -12,6 +12,7 @@/* * AGGR_GLOBAL: Use CPU 0 * AGGR_SOCKET: Use first CPU of socket +* AGGR_DIE: Use first CPU of die * AGGR_CORE: Use first CPU of core * AGGR_NONE: Use matching CPU * AGGR_THREAD: Not supported?
tools/perf/util/stat.c +1 -0
@@ -272,6 +272,7 @@ process_counter_values(struct perf_stat_config *config, struct perf_evsel *evselswitch (config->aggr_mode) {case AGGR_THREAD :case AGGR_CORE : +case AGGR_DIE :case AGGR_SOCKET :case AGGR_NONE :if (!evsel->snapshot)
tools/perf/util/stat.h +1 -0
@@ -44,6 +44,7 @@ enum aggr_mode {AGGR_NONE ,AGGR_GLOBAL ,AGGR_SOCKET , +AGGR_DIE ,AGGR_CORE ,AGGR_THREAD , AGGR_UNSET,
Signature · 1 line
2.7.4
Re: [PATCH 2/3] perf stat: Support per-die aggregation
On Thu, May 23, 2019 at 01:41:20PM -0700, [email protected] wrote:
SNIP
Quoted 37 lines
tools/perf/builtin-stat.c +20
-4if (cpu_map__build_core_map (evsel_list->cpus, &stat_config.aggr_map)) {perror ("cannot build core map" );@@ -936,21 +957,41 @@ static int perf_env__get_socket(struct cpu_map *map, int idx, void *data)return cpu ==-1 ?-1 : env->cpu[cpu].socket_id; } +static int perf_env__get_die (struct cpu_map *map,int idx,void *data) +{ +struct perf_env *env = data; +int die =-1 , cpu =perf_env__get_cpu (env, map, idx); + +if (cpu !=-1 ) { +/* +* Encode socket in upper 8 bits +* die_id is relative to socket, +* we need a global id. So we combine +* socket + die id +*/ + die = (env->cpu[cpu].socket_id <<8 ) | + (env->cpu[cpu].die_id &0xff ); + } + +return die; +} +static int perf_env__get_core (struct cpu_map *map,int idx,void *data) {struct perf_env *env = data;int core =-1 , cpu =perf_env__get_cpu (env, map, idx);if (cpu !=-1 ) { -int socket_id = env->cpu[cpu].socket_id; -/* -* Encode socket in upper 16 bits -* core_id is relative to socket, and +* Encode socket in upper 24 bits
tools/perf/builtin-stat.c static int perf_env__get_socket(struct cpu_map *map, int idx, void *data) · line 994
Quoted 10 lines
tools/perf/builtin-stat.c +6
-2+* encode die id in upper 16 bits +* core_id is relative to socket and die, * we need a global id. So we combine -* socket + core id. +* socket + die id + core id */ - core = (socket_id <<16 ) | (env->cpu[cpu].core_id &0xffff ); + core = (env->cpu[cpu].socket_id <<24 ) | + (env->cpu[cpu].die_id <<16 ) | + (env->cpu[cpu].core_id &0xffff );
I guess we're still safe with 1 byte for socket and die id, but could we still check the size fits, and warn and bail out otherwise?
thanks,
jirka
PATCH 3/3 perf header: Rename "sibling cores" to "sibling sockets"
In reply to [email protected]From: Kan Liang <[email protected]>
The "sibling cores" actually shows the sibling CPUs of a socket. The name "sibling cores" is very misleading.
Rename "sibling cores" to "sibling sockets"
--- tools/perf/Documentation/perf.data-file-format.txt | 2 +- tools/perf/util/header.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf.data-file-format.txt +1 -1
@@ -168,7 +168,7 @@ struct { }; Example: - sibling cores : 0-8 + sibling sockets : 0-8 sibling dies : 0-3 sibling dies : 4-7 sibling threads : 0-1
tools/perf/util/header.c +1 -1
@@ -1465,7 +1465,7 @@ static void print_cpu_topology(struct feat_fd *ff, FILE *fp) str = ph->env.sibling_cores;for (i =0 ; i < nr; i++) { -fprintf (fp,"# sibling cores : %s\n" , str); +fprintf (fp,"# sibling sockets : %s\n" , str); str +=strlen (str) +1 ; }
Signature · 1 line
2.7.4
Re: [PATCH 3/3] perf header: Rename "sibling cores" to "sibling sockets"
Quoted 6 lines · On Thu, May 23, 2019 at 01:41:21PM -0700, [email protected] wrote:
From: Kan Liang <[email protected]>
The "sibling cores" actually shows the sibling CPUs of a socket. The name "sibling cores" is very misleading.
Rename "sibling cores" to "sibling sockets"
by checking on die topology, I found that thread_siblings_list is deprecated/renamed to core_cpus_list.. we should keep that in mind and support both
jirka
Quoted 36 lines
Signed-off-by Kan Liang <[email protected]>--- tools/perf/Documentation/perf.data-file-format.txt | 2 +- tools/perf/util/header.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)tools/perf/Documentation/perf.data-file-format.txt +1
-1@@ -168,7 +168,7 @@ struct { }; Example: - sibling cores : 0-8 + sibling sockets : 0-8 sibling dies : 0-3 sibling dies : 4-7 sibling threads : 0-1tools/perf/util/header.c +1
-1@@ -1465,7 +1465,7 @@ static void print_cpu_topology(struct feat_fd *ff, FILE *fp) str = ph->env.sibling_cores;for (i =0 ; i < nr; i++) { -fprintf (fp,"# sibling cores : %s\n" , str); +fprintf (fp,"# sibling sockets : %s\n" , str); str +=strlen (str) +1 ; }Signature · 1 line
2.7.4
Re: [PATCH 3/3] perf header: Rename "sibling cores" to "sibling sockets"
Quoted 12 lines · Jiri Olsa
Quoted 6 lines · On Thu, May 23, 2019 at 01:41:21PM -0700, [email protected] wrote:
From: Kan Liang <[email protected]>
The "sibling cores" actually shows the sibling CPUs of a socket. The name "sibling cores" is very misleading.
Rename "sibling cores" to "sibling sockets"
by checking on die topology, I found that
thread_siblings_listis deprecated/renamed tocore_cpus_list.. we should keep that in mind and support both
Sure, I will introduce THRD_SIB_FMT_NEW for the new name. #define THRD_SIB_FMT_NEW \
"%s/devices/system/cpu/cpu%d/topology/core_cpus_list"
I will check new name first, (if N/A, then check the old name), before parsing the topology information.
I will add the change in V2.
Thanks,
Kan
Quoted 38 lines
jirka
Quoted 36 lines
Signed-off-by Kan Liang <[email protected]>--- tools/perf/Documentation/perf.data-file-format.txt | 2 +- tools/perf/util/header.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)tools/perf/Documentation/perf.data-file-format.txt +1
-1@@ -168,7 +168,7 @@ struct { }; Example: - sibling cores : 0-8 + sibling sockets : 0-8 sibling dies : 0-3 sibling dies : 4-7 sibling threads : 0-1tools/perf/util/header.c +1
-1@@ -1465,7 +1465,7 @@ static void print_cpu_topology(struct feat_fd *ff, FILE *fp) str = ph->env.sibling_cores;for (i =0 ; i < nr; i++) { -fprintf (fp,"# sibling cores : %s\n" , str); +fprintf (fp,"# sibling sockets : %s\n" , str); str +=strlen (str) +1 ; }Signature · 1 line
2.7.4
On Thu, May 23, 2019 at 01:41:19PM -0700, [email protected] wrote:
SNIP
Quoted 10 lines
tools/perf/util/cputopo.c +1
-1@@ -88,7 +138,7 @@ static int build_cpu_topology(struct cpu_topology *tp, int cpu)return ret; } -void cpu_topology__delete (struct cpu_topology *tp) +void cpu_topology__delete (struct cpu_topology *tp,bool has_die) {u32 i;
tools/perf/util/cputopo.c void cpu_topology__delete(struct cpu_topology *tp) · line 151
Quoted 4 lines
tools/perf/util/cputopo.c +1
-0@@ -98,17 +148,22 @@ void cpu_topology__delete(struct cpu_topology *tp)for (i =0 ; i < tp->core_sib; i++)zfree (&tp->core_siblings[i]); +if (has_die) {
I think there's no need for has_die check in here, tp->die_sib will be zero, and also will tp->die_siblings[i]
jirka
Quoted 9 lines
tools/perf/util/cputopo.c +4
-0+for (i =0 ; i < tp->die_sib; i++) +zfree (&tp->die_siblings[i]); + } +for (i =0 ; i < tp->thread_sib; i++)zfree (&tp->thread_siblings[i]);free (tp); }
SNIP
On Thu, May 23, 2019 at 01:41:19PM -0700, [email protected] wrote:
SNIP
Quoted 54 lines
Add
cpu_map__get_die_id()incpumap.cto fetch die id information.Signed-off-by Kan Liang <[email protected]>--- tools/perf/Documentation/perf.data-file-format.txt | 9 +- tools/perf/util/cpumap.c | 7 ++ tools/perf/util/cpumap.h | 1 + tools/perf/util/cputopo.c | 83 ++++++++++++++-- tools/perf/util/cputopo.h | 7 +- tools/perf/util/env.c | 1 + tools/perf/util/env.h | 3 + tools/perf/util/header.c | 104 +++++++++++++++++++-- 8 files changed, 193 insertions(+), 22 deletions(-)tools/perf/Documentation/perf.data-file-format.txt +7
-2@@ -153,7 +153,7 @@ struct { String lists defining the core and CPU threads topology. The string lists are followed by a variable length array -which contains core_id and socket_id of each cpu. +which contains core_id, die_id (for x86) and socket_id of each cpu. The number of entries can be determined by the size of the section minus the sizes of both string lists.@@ -162,14 +162,19 @@ struct { struct perf_header_string_list threads; /* Variable length */ struct { uint32_t core_id; + uint32_t die_id; uint32_t socket_id; } cpus[nr]; /* Variable length records */ }; Example: - sibling cores : 0-3 + sibling cores : 0-8 + sibling dies : 0-3 + sibling dies : 4-7 sibling threads : 0-1 sibling threads : 2-3 + sibling threads : 4-5 + sibling threads : 6-7 HEADER_NUMA_TOPOLOGY = 14,tools/perf/util/cpumap.c +0
-0
tools/perf/util/cpumap.c int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res, · line 381
Quoted 9 lines
tools/perf/util/cpumap.c +6
-0@@ -373,6 +373,13 @@ int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res,return 0 ; } +int cpu_map__get_die_id (int cpu) +{ +int value, ret =cpu__get_topology_int (cpu,"die_id" , &value); + +return ret ?: value; +}
please put 'adding cpu_map__get_die_id function' into separate patch
thanks,
jirka
Quoted 17 lines
tools/perf/util/cpumap.c +1
-0+int cpu_map__get_core_id (int cpu) {int value, ret =cpu__get_topology_int (cpu,"core_id" , &value);tools/perf/util/cpumap.h +1
-0@@ -25,6 +25,7 @@ size_t cpu_map__snprint_mask(struct cpu_map *map, char *buf, size_t size);size_t cpu_map__fprintf (struct cpu_map *map,FILE *fp);int cpu_map__get_socket_id (int cpu);int cpu_map__get_socket (struct cpu_map *map,int idx,void *data); +int cpu_map__get_die_id (int cpu);int cpu_map__get_core_id (int cpu);int cpu_map__get_core (struct cpu_map *map,int idx,void *data);int cpu_map__build_socket_map (struct cpu_map *cpus,struct cpu_map **sockp);tools/perf/util/cputopo.c +0
-0
SNIP
On Thu, May 23, 2019 at 01:41:19PM -0700, [email protected] wrote:
SNIP
Quoted 36 lines
tools/perf/util/cputopo.c +11
-2@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-2.0 #include <sys/param.h> +#include <sys/utsname.h> #include <inttypes.h> #include <api/fs/fs.h> @@ -8,9 +9,10 @@#include "util.h" #include "env.h" -#define CORE_SIB_FMT \ "%s/devices/system/cpu/cpu%d/topology/core_siblings_list" +#define DIE_SIB_FMT \ + "%s/devices/system/cpu/cpu%d/topology/die_cpus_list"#define THRD_SIB_FMT \ "%s/devices/system/cpu/cpu%d/topology/thread_siblings_list"#define NODE_ONLINE_FMT \@@ -20,7 +22,26 @@#define NODE_CPULIST_FMT \ "%s/devices/system/node/node%d/cpulist" -static int build_cpu_topology (struct cpu_topology *tp,int cpu) +bool check_x86_die_exists (void ) +{ +char filename[MAXPATHLEN ]; +struct utsname uts; + +if (uname (&uts) <0 ) +return false; +
tools/perf/util/cputopo.c line 42
Quoted 10 lines
tools/perf/util/cputopo.c +10
-0+if (strncmp (uts.machine,"x86_64" ,6 )) +return false; + +scnprintf (filename,MAXPATHLEN ,DIE_SIB_FMT , +sysfs__mountpoint (),0 ); +if (access (filename,F_OK ) ==-1 ) +return false; + +return true; +}
we could rename this to:
static bool has_die(void)
{
static bool has_die;
if (initialized)
return has_die;
has_die = ...
initialized = true;
}and got rid of all those 'has_die' arguments below
Quoted 216 lines
tools/perf/util/cputopo.c +52
-8+ +static int build_cpu_topology (struct cpu_topology *tp,int cpu,bool has_die) {FILE *fp;char filename[MAXPATHLEN ];@@ -34,12 +55,12 @@ static int build_cpu_topology(struct cpu_topology *tp, int cpu) sysfs__mountpoint(), cpu); fp =fopen (filename,"r" );if (!fp) - goto try_threads; + goto try_dies; sret =getline (&buf, &len, fp);fclose (fp);if (sret <=0 ) - goto try_threads; + goto try_dies; p =strchr (buf,'\n' );if (p)@@ -57,6 +78,35 @@ static int build_cpu_topology(struct cpu_topology *tp, int cpu) } ret =0 ; +try_dies: +if (has_die) { +scnprintf (filename,MAXPATHLEN ,DIE_SIB_FMT , +sysfs__mountpoint (), cpu); + fp =fopen (filename,"r" ); +if (!fp) + goto try_threads; + + sret =getline (&buf, &len, fp); +fclose (fp); +if (sret <=0 ) + goto try_threads; + + p =strchr (buf,'\n' ); +if (p) + *p ='\0' ; + +for (i =0 ; i < tp->die_sib; i++) { +if (!strcmp (buf, tp->die_siblings[i])) +break ; + } +if (i == tp->die_sib) { + tp->die_siblings[i] = buf; + tp->die_sib++; + buf =NULL ; + len =0 ; + } + ret =0 ; + } try_threads:scnprintf (filename,MAXPATHLEN ,THRD_SIB_FMT ,sysfs__mountpoint (), cpu);@@ -88,7 +138,7 @@ static int build_cpu_topology(struct cpu_topology *tp, int cpu)return ret; } -void cpu_topology__delete (struct cpu_topology *tp) +void cpu_topology__delete (struct cpu_topology *tp,bool has_die) {u32 i;@@ -98,17 +148,22 @@ void cpu_topology__delete(struct cpu_topology *tp)for (i =0 ; i < tp->core_sib; i++)zfree (&tp->core_siblings[i]); +if (has_die) { +for (i =0 ; i < tp->die_sib; i++) +zfree (&tp->die_siblings[i]); + } +for (i =0 ; i < tp->thread_sib; i++)zfree (&tp->thread_siblings[i]);free (tp); } -struct cpu_topology *cpu_topology__new (void ) +struct cpu_topology *cpu_topology__new (bool has_die) {struct cpu_topology *tp =NULL ;void *addr; -u32 nr, i; +u32 nr, i, nr_addr;size_t sz;long ncpus;int ret =-1 ;@@ -126,7 +181,11 @@ struct cpu_topology *cpu_topology__new(void) nr = (u32)(ncpus &UINT_MAX ); sz = nr *sizeof (char *); - addr =calloc (1 ,sizeof (*tp) +2 * sz); +if (has_die) + nr_addr =3 ; +else + nr_addr =2 ; + addr =calloc (1 ,sizeof (*tp) + nr_addr * sz);if (!addr) goto out_free;@@ -134,13 +193,17 @@ struct cpu_topology *cpu_topology__new(void) addr +=sizeof (*tp); tp->core_siblings = addr; addr += sz; +if (has_die) { + tp->die_siblings = addr; + addr += sz; + } tp->thread_siblings = addr;for (i =0 ; i < nr; i++) {if (!cpu_map__has (map, i))continue ; - ret =build_cpu_topology (tp, i); + ret =build_cpu_topology (tp, i, has_die);if (ret <0 )break ; }@@ -148,7 +211,7 @@ struct cpu_topology *cpu_topology__new(void) out_free:cpu_map__put (map);if (ret) { -cpu_topology__delete (tp); +cpu_topology__delete (tp, has_die); tp =NULL ; }return tp;tools/perf/util/cputopo.h +5
-2@@ -7,8 +7,10 @@struct cpu_topology {u32 core_sib; +u32 die_sib;u32 thread_sib;char **core_siblings; +char **die_siblings;char **thread_siblings; };@@ -24,8 +26,9 @@ struct numa_topology {struct numa_topology_node nodes[0 ]; }; -struct cpu_topology *cpu_topology__new (void ); -void cpu_topology__delete (struct cpu_topology *tp); +bool check_x86_die_exists (void ); +struct cpu_topology *cpu_topology__new (bool has_die); +void cpu_topology__delete (struct cpu_topology *tp,bool has_die);struct numa_topology *numa_topology__new (void );void numa_topology__delete (struct numa_topology *tp);tools/perf/util/env.c +1
-0@@ -246,6 +246,7 @@ int perf_env__read_cpu_topology_map(struct perf_env *env)for (cpu =0 ; cpu < nr_cpus; ++cpu) { env->cpu[cpu].core_id =cpu_map__get_core_id (cpu); env->cpu[cpu].socket_id =cpu_map__get_socket_id (cpu); + env->cpu[cpu].die_id =cpu_map__get_die_id (cpu); } env->nr_cpus_avail = nr_cpus;tools/perf/util/env.h +3
-0@@ -9,6 +9,7 @@struct cpu_topology_map {int socket_id; +int die_id;int core_id; };@@ -49,6 +50,7 @@ struct perf_env {int nr_cmdline;int nr_sibling_cores; +int nr_sibling_dies;int nr_sibling_threads;int nr_numa_nodes;int nr_memory_nodes;@@ -57,6 +59,7 @@ struct perf_env {char *cmdline;const char **cmdline_argv;char *sibling_cores; +char *sibling_dies;char *sibling_threads;char *pmu_mappings;struct cpu_topology_map *cpu;tools/perf/util/header.c +4
-1@@ -561,8 +561,11 @@ static int write_cpu_topology(struct feat_fd *ff,struct cpu_topology *tp;u32 i;int ret, j; +bool has_die; - tp =cpu_topology__new (); + has_die =check_x86_die_exists (); + + tp =cpu_topology__new (has_die);if (!tp)return -1 ;
tools/perf/util/header.c static int write_cpu_topology(struct feat_fd *ff, · line 607
Quoted 6 lines
tools/perf/util/header.c +3
-0@@ -599,8 +602,29 @@ static int write_cpu_topology(struct feat_fd *ff,if (ret <0 )return ret; } + +if (!has_die) + goto done;
also the has_die() could stay static in util/cputopo.c, we can get the 'has_die state' from tp->die_sib != 0
Quoted 25 lines
tools/perf/util/header.c +19
-1+ + ret =do_write (ff, &tp->die_sib,sizeof (tp->die_sib)); +if (ret <0 ) + goto done; + +for (i =0 ; i < tp->die_sib; i++) { + ret =do_write_string (ff, tp->die_siblings[i]); +if (ret <0 ) + goto done; + } + +for (j =0 ; j < perf_env.nr_cpus_avail; j++) { + ret =do_write (ff, &perf_env.cpu[j].die_id, +sizeof (perf_env.cpu[j].die_id)); +if (ret <0 ) +return ret; + } + done: -cpu_topology__delete (tp); +cpu_topology__delete (tp, has_die);return ret; }
tools/perf/util/header.c static void print_cmdline(struct feat_fd *ff, FILE *fp) · line 1455
Quoted 4 lines
tools/perf/util/header.c +1
-0@@ -1428,6 +1452,8 @@ static void print_cmdline(struct feat_fd *ff, FILE *fp)fputc ('\n' , fp); } +static bool has_die;
same here.. you can use env->nr_sibling_dies instead of static bool
Quoted 44 lines
tools/perf/util/header.c +24
-6+static void print_cpu_topology (struct feat_fd *ff,FILE *fp) {struct perf_header *ph = ff->ph;@@ -1443,6 +1469,16 @@ static void print_cpu_topology(struct feat_fd *ff, FILE *fp) str +=strlen (str) +1 ; } +if (has_die) { + nr = ph->env.nr_sibling_dies; + str = ph->env.sibling_dies; + +for (i =0 ; i < nr; i++) { +fprintf (fp,"# sibling dies : %s\n" , str); + str +=strlen (str) +1 ; + } + } + nr = ph->env.nr_sibling_threads; str = ph->env.sibling_threads;@@ -1451,12 +1487,28 @@ static void print_cpu_topology(struct feat_fd *ff, FILE *fp) str +=strlen (str) +1 ; } -if (ph->env.cpu !=NULL ) { -for (i =0 ; i < cpu_nr; i++) -fprintf (fp,"# CPU %d: Core ID %d, Socket ID %d\n" , i, - ph->env.cpu[i].core_id, ph->env.cpu[i].socket_id); - }else -fprintf (fp,"# Core ID and Socket ID information is not available\n" ); +if (has_die) { +if (ph->env.cpu !=NULL ) { +for (i =0 ; i < cpu_nr; i++) +fprintf (fp,"# CPU %d: Core ID %d, " +"Die ID %d, Socket ID %d\n" , + i, ph->env.cpu[i].core_id, + ph->env.cpu[i].die_id, + ph->env.cpu[i].socket_id); + }else +fprintf (fp,"# Core ID, Die ID and Socket ID " +"information is not available\n" ); + }else { +if (ph->env.cpu !=NULL ) {
tools/perf/util/header.c static void print_cpu_topology(struct feat_fd *ff, FILE *fp) · line 1512
Quoted 10 lines
tools/perf/util/header.c +9
-0+for (i =0 ; i < cpu_nr; i++) +fprintf (fp,"# CPU %d: Core ID %d, " +"Socket ID %d\n" , + i, ph->env.cpu[i].core_id, + ph->env.cpu[i].socket_id); + }else +fprintf (fp,"# Core ID and Socket ID " +"information is not available\n" ); + } }
SNIP
thanks,
jirka
Quoted 64 lines · Jiri Olsa
On Thu, May 23, 2019 at 01:41:19PM -0700, [email protected] wrote:
SNIP
Quoted 36 lines
tools/perf/util/cputopo.c +11
-2@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-2.0 #include <sys/param.h> +#include <sys/utsname.h> #include <inttypes.h> #include <api/fs/fs.h> @@ -8,9 +9,10 @@#include "util.h" #include "env.h" -#define CORE_SIB_FMT \ "%s/devices/system/cpu/cpu%d/topology/core_siblings_list" +#define DIE_SIB_FMT \ + "%s/devices/system/cpu/cpu%d/topology/die_cpus_list"#define THRD_SIB_FMT \ "%s/devices/system/cpu/cpu%d/topology/thread_siblings_list"#define NODE_ONLINE_FMT \@@ -20,7 +22,26 @@#define NODE_CPULIST_FMT \ "%s/devices/system/node/node%d/cpulist" -static int build_cpu_topology (struct cpu_topology *tp,int cpu) +bool check_x86_die_exists (void ) +{ +char filename[MAXPATHLEN ]; +struct utsname uts; + +if (uname (&uts) <0 ) +return false; +tools/perf/util/cputopo.c line 42
Quoted 10 lines
tools/perf/util/cputopo.c +10
-0+if (strncmp (uts.machine,"x86_64" ,6 )) +return false; + +scnprintf (filename,MAXPATHLEN ,DIE_SIB_FMT , +sysfs__mountpoint (),0 ); +if (access (filename,F_OK ) ==-1 ) +return false; + +return true; +}we could rename this to:
static bool
has_die(void){ static bool has_die; if (initialized) return has_die; has_die = ... initialized = true; }
Quoted 1 line
and got rid of all those '
has_die' arguments below
Yes, we can rename the function to has_die(). It looks like all the 'has_die' arguments can be replaced either.
But why we want a "initialized" here? to cache the value? It looks like we only need to call has_die() once.
Thanks,
Kan
Quoted 319 lines
Quoted 217 lines
tools/perf/util/cputopo.c +52
-8+ +static int build_cpu_topology (struct cpu_topology *tp,int cpu,bool has_die) {FILE *fp;char filename[MAXPATHLEN ];@@ -34,12 +55,12 @@ static int build_cpu_topology(struct cpu_topology *tp, int cpu) sysfs__mountpoint(), cpu); fp =fopen (filename,"r" );if (!fp) - goto try_threads; + goto try_dies; sret =getline (&buf, &len, fp);fclose (fp);if (sret <=0 ) - goto try_threads; + goto try_dies; p =strchr (buf,'\n' );if (p)@@ -57,6 +78,35 @@ static int build_cpu_topology(struct cpu_topology *tp, int cpu) } ret =0 ; +try_dies: +if (has_die) { +scnprintf (filename,MAXPATHLEN ,DIE_SIB_FMT , +sysfs__mountpoint (), cpu); + fp =fopen (filename,"r" ); +if (!fp) + goto try_threads; + + sret =getline (&buf, &len, fp); +fclose (fp); +if (sret <=0 ) + goto try_threads; + + p =strchr (buf,'\n' ); +if (p) + *p ='\0' ; + +for (i =0 ; i < tp->die_sib; i++) { +if (!strcmp (buf, tp->die_siblings[i])) +break ; + } +if (i == tp->die_sib) { + tp->die_siblings[i] = buf; + tp->die_sib++; + buf =NULL ; + len =0 ; + } + ret =0 ; + } try_threads:scnprintf (filename,MAXPATHLEN ,THRD_SIB_FMT ,sysfs__mountpoint (), cpu);@@ -88,7 +138,7 @@ static int build_cpu_topology(struct cpu_topology *tp, int cpu)return ret; } -void cpu_topology__delete (struct cpu_topology *tp) +void cpu_topology__delete (struct cpu_topology *tp,bool has_die) {u32 i;@@ -98,17 +148,22 @@ void cpu_topology__delete(struct cpu_topology *tp)for (i =0 ; i < tp->core_sib; i++)zfree (&tp->core_siblings[i]); +if (has_die) { +for (i =0 ; i < tp->die_sib; i++) +zfree (&tp->die_siblings[i]); + } +for (i =0 ; i < tp->thread_sib; i++)zfree (&tp->thread_siblings[i]);free (tp); } -struct cpu_topology *cpu_topology__new (void ) +struct cpu_topology *cpu_topology__new (bool has_die) {struct cpu_topology *tp =NULL ;void *addr; -u32 nr, i; +u32 nr, i, nr_addr;size_t sz;long ncpus;int ret =-1 ;@@ -126,7 +181,11 @@ struct cpu_topology *cpu_topology__new(void) nr = (u32)(ncpus &UINT_MAX ); sz = nr *sizeof (char *); - addr =calloc (1 ,sizeof (*tp) +2 * sz); +if (has_die) + nr_addr =3 ; +else + nr_addr =2 ; + addr =calloc (1 ,sizeof (*tp) + nr_addr * sz);if (!addr) goto out_free;@@ -134,13 +193,17 @@ struct cpu_topology *cpu_topology__new(void) addr +=sizeof (*tp); tp->core_siblings = addr; addr += sz; +if (has_die) { + tp->die_siblings = addr; + addr += sz; + } tp->thread_siblings = addr;for (i =0 ; i < nr; i++) {if (!cpu_map__has (map, i))continue ; - ret =build_cpu_topology (tp, i); + ret =build_cpu_topology (tp, i, has_die);if (ret <0 )break ; }@@ -148,7 +211,7 @@ struct cpu_topology *cpu_topology__new(void) out_free:cpu_map__put (map);if (ret) { -cpu_topology__delete (tp); +cpu_topology__delete (tp, has_die); tp =NULL ; }return tp;tools/perf/util/cputopo.h +5
-2@@ -7,8 +7,10 @@struct cpu_topology {u32 core_sib; +u32 die_sib;u32 thread_sib;char **core_siblings; +char **die_siblings;char **thread_siblings; };@@ -24,8 +26,9 @@ struct numa_topology {struct numa_topology_node nodes[0 ]; }; -struct cpu_topology *cpu_topology__new (void ); -void cpu_topology__delete (struct cpu_topology *tp); +bool check_x86_die_exists (void ); +struct cpu_topology *cpu_topology__new (bool has_die); +void cpu_topology__delete (struct cpu_topology *tp,bool has_die);struct numa_topology *numa_topology__new (void );void numa_topology__delete (struct numa_topology *tp);tools/perf/util/env.c +1
-0@@ -246,6 +246,7 @@ int perf_env__read_cpu_topology_map(struct perf_env *env)for (cpu =0 ; cpu < nr_cpus; ++cpu) { env->cpu[cpu].core_id =cpu_map__get_core_id (cpu); env->cpu[cpu].socket_id =cpu_map__get_socket_id (cpu); + env->cpu[cpu].die_id =cpu_map__get_die_id (cpu); } env->nr_cpus_avail = nr_cpus;tools/perf/util/env.h +3
-0@@ -9,6 +9,7 @@struct cpu_topology_map {int socket_id; +int die_id;int core_id; };@@ -49,6 +50,7 @@ struct perf_env {int nr_cmdline;int nr_sibling_cores; +int nr_sibling_dies;int nr_sibling_threads;int nr_numa_nodes;int nr_memory_nodes;@@ -57,6 +59,7 @@ struct perf_env {char *cmdline;const char **cmdline_argv;char *sibling_cores; +char *sibling_dies;char *sibling_threads;char *pmu_mappings;struct cpu_topology_map *cpu;tools/perf/util/header.c +4
-1@@ -561,8 +561,11 @@ static int write_cpu_topology(struct feat_fd *ff,struct cpu_topology *tp;u32 i;int ret, j; +bool has_die; - tp =cpu_topology__new (); + has_die =check_x86_die_exists (); + + tp =cpu_topology__new (has_die);if (!tp)return -1 ;tools/perf/util/header.c static int write_cpu_topology(struct feat_fd *ff, · line 607
Quoted 6 lines
tools/perf/util/header.c +3
-0@@ -599,8 +602,29 @@ static int write_cpu_topology(struct feat_fd *ff,if (ret <0 )return ret; } + +if (!has_die) + goto done;also the
has_die()could stay static inutil/cputopo.c, we can get the 'has_diestate' fromtp->die_sib!= 0Quoted 25 lines
tools/perf/util/header.c +19
-1+ + ret =do_write (ff, &tp->die_sib,sizeof (tp->die_sib)); +if (ret <0 ) + goto done; + +for (i =0 ; i < tp->die_sib; i++) { + ret =do_write_string (ff, tp->die_siblings[i]); +if (ret <0 ) + goto done; + } + +for (j =0 ; j < perf_env.nr_cpus_avail; j++) { + ret =do_write (ff, &perf_env.cpu[j].die_id, +sizeof (perf_env.cpu[j].die_id)); +if (ret <0 ) +return ret; + } + done: -cpu_topology__delete (tp); +cpu_topology__delete (tp, has_die);return ret; }tools/perf/util/header.c static void print_cmdline(struct feat_fd *ff, FILE *fp) · line 1455
Quoted 4 lines
tools/perf/util/header.c +1
-0@@ -1428,6 +1452,8 @@ static void print_cmdline(struct feat_fd *ff, FILE *fp)fputc ('\n' , fp); } +static bool has_die;same here.. you can use
env->nr_sibling_diesinstead of static boolQuoted 44 lines
tools/perf/util/header.c +24
-6+static void print_cpu_topology (struct feat_fd *ff,FILE *fp) {struct perf_header *ph = ff->ph;@@ -1443,6 +1469,16 @@ static void print_cpu_topology(struct feat_fd *ff, FILE *fp) str +=strlen (str) +1 ; } +if (has_die) { + nr = ph->env.nr_sibling_dies; + str = ph->env.sibling_dies; + +for (i =0 ; i < nr; i++) { +fprintf (fp,"# sibling dies : %s\n" , str); + str +=strlen (str) +1 ; + } + } + nr = ph->env.nr_sibling_threads; str = ph->env.sibling_threads;@@ -1451,12 +1487,28 @@ static void print_cpu_topology(struct feat_fd *ff, FILE *fp) str +=strlen (str) +1 ; } -if (ph->env.cpu !=NULL ) { -for (i =0 ; i < cpu_nr; i++) -fprintf (fp,"# CPU %d: Core ID %d, Socket ID %d\n" , i, - ph->env.cpu[i].core_id, ph->env.cpu[i].socket_id); - }else -fprintf (fp,"# Core ID and Socket ID information is not available\n" ); +if (has_die) { +if (ph->env.cpu !=NULL ) { +for (i =0 ; i < cpu_nr; i++) +fprintf (fp,"# CPU %d: Core ID %d, " +"Die ID %d, Socket ID %d\n" , + i, ph->env.cpu[i].core_id, + ph->env.cpu[i].die_id, + ph->env.cpu[i].socket_id); + }else +fprintf (fp,"# Core ID, Die ID and Socket ID " +"information is not available\n" ); + }else { +if (ph->env.cpu !=NULL ) {tools/perf/util/header.c static void print_cpu_topology(struct feat_fd *ff, FILE *fp) · line 1512
Quoted 10 lines
tools/perf/util/header.c +9
-0+for (i =0 ; i < cpu_nr; i++) +fprintf (fp,"# CPU %d: Core ID %d, " +"Socket ID %d\n" , + i, ph->env.cpu[i].core_id, + ph->env.cpu[i].socket_id); + }else +fprintf (fp,"# Core ID and Socket ID " +"information is not available\n" ); + } }SNIP
thanks,
jirka
Quoted 64 lines · Kan
Quoted 61 lines · Jiri Olsa
On Thu, May 23, 2019 at 01:41:19PM -0700, [email protected] wrote:
SNIP
Quoted 33 lines
tools/perf/util/cputopo.c +11
-2@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-2.0 #include <sys/param.h> +#include <sys/utsname.h> #include <inttypes.h> #include <api/fs/fs.h> @@ -8,9 +9,10 @@#include "util.h" #include "env.h" -#define CORE_SIB_FMT \ "%s/devices/system/cpu/cpu%d/topology/core_siblings_list" +#define DIE_SIB_FMT \ + "%s/devices/system/cpu/cpu%d/topology/die_cpus_list"#define THRD_SIB_FMT \ "%s/devices/system/cpu/cpu%d/topology/thread_siblings_list"#define NODE_ONLINE_FMT \@@ -20,7 +22,26 @@#define NODE_CPULIST_FMT \ "%s/devices/system/node/node%d/cpulist" -static int build_cpu_topology (struct cpu_topology *tp,int cpu) +bool check_x86_die_exists (void ) +{ +char filename[MAXPATHLEN ]; +struct utsname uts; + +if (uname (&uts) <0 ) +return false; +tools/perf/util/cputopo.c line 41
Quoted 10 lines
tools/perf/util/cputopo.c +10
-0+if (strncmp (uts.machine,"x86_64" ,6 )) +return false; + +scnprintf (filename,MAXPATHLEN ,DIE_SIB_FMT , +sysfs__mountpoint (),0 ); +if (access (filename,F_OK ) ==-1 ) +return false; + +return true; +}we could rename this to:
static bool
has_die(void){ static bool has_die; if (initialized) return has_die; has_die = ... initialized = true; }
Quoted 7 lines
Quoted 1 line
and got rid of all those '
has_die' arguments belowYes, we can rename the function to
has_die(). It looks like all the 'has_die' arguments can be replaced either.But why we want a "initialized" here? to cache the value? It looks like we only need to call
has_die()once.
right, if it's called from one place then it's ok
thanks,
jirka
On Thu, May 23, 2019 at 01:41:19PM -0700, [email protected] wrote:
SNIP
tools/perf/util/cputopo.c static int build_cpu_topology(struct cpu_topology *tp, int cpu) · line 82
Quoted 12 lines
tools/perf/util/cputopo.c +3
-1if (sret <=0 ) - goto try_threads; + goto try_dies; p =strchr (buf,'\n' );if (p)@@ -57,6 +78,35 @@ static int build_cpu_topology(struct cpu_topology *tp, int cpu) } ret =0 ; +try_dies: +if (has_die) {
less depth..
if (!has_die()) goto try_threads; scnprintf(filename, MAXPATHLEN, DIE_SIB_FMT, sysfs__mountpoint(), cpu); ...
Quoted 29 lines
tools/perf/util/cputopo.c +27
-0+scnprintf (filename,MAXPATHLEN ,DIE_SIB_FMT , +sysfs__mountpoint (), cpu); + fp =fopen (filename,"r" ); +if (!fp) + goto try_threads; + + sret =getline (&buf, &len, fp); +fclose (fp); +if (sret <=0 ) + goto try_threads; + + p =strchr (buf,'\n' ); +if (p) + *p ='\0' ; + +for (i =0 ; i < tp->die_sib; i++) { +if (!strcmp (buf, tp->die_siblings[i])) +break ; + } +if (i == tp->die_sib) { + tp->die_siblings[i] = buf; + tp->die_sib++; + buf =NULL ; + len =0 ; + } + ret =0 ; + } try_threads: scnprintf(filename, MAXPATHLEN, THRD_SIB_FMT,
SNIP
Quoted 11 lines · On Thu, May 23, 2019 at 01:41:19PM -0700, [email protected] wrote:
From: Kan Liang <[email protected]>
With the new CPUID.1F, a new level type of CPU topology, 'die', is introduced. The 'die' information in CPU topology should be added in perf header.
To be compatible with old perf.data, the patch checks the section size before reading the die information. The new info is added at the end of the
cpu_topologysection, the old perf tool ignores the extra data. It never reads data crossing the section boundary.
Quoted 4 lines
The new perf tool with the patch can be used on legacy kernel. Add a new function
check_x86_die_exists()to check if die topology information is supported by kernel. The function only check X86 and CPU 0. Assuming other CPUs have same topology.
[jolsa@dell-r440-01 perf]$ sudo ./perf stat -e cycles --per-die -a -I 1000
# time die cpus counts unit events
1.000526089 S0-D0 20 6,828,029 cycles
1.000526089 S1-D0 20 2,609,924 cycles
2.002578005 S0-D0 20 5,280,361 cyclesthe title is shifted from the values
jirka