[PATCH v5 1/7] perf env: Ensure failure broken topology file reads are always -1 encoded

Ian Rogers posted 7 patches 2 days, 22 hours ago
[PATCH v5 1/7] perf env: Ensure failure broken topology file reads are always -1 encoded
Posted by Ian Rogers 2 days, 22 hours ago
get_core_id returns 0 on success and a negative errno value on
error. Currently the error can only be -1, but fixing this to be any
errno value breaks perf:
https://lore.kernel.org/lkml/Zzu4Sdebve-NXEMX@google.com/
To avoid this, make sure all error values are written as -1.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/env.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c
index e2843ca2edd9..e890a52e01a6 100644
--- a/tools/perf/util/env.c
+++ b/tools/perf/util/env.c
@@ -326,10 +326,13 @@ int perf_env__read_cpu_topology_map(struct perf_env *env)
 
 	for (idx = 0; idx < nr_cpus; ++idx) {
 		struct perf_cpu cpu = { .cpu = idx };
+		int core_id   = cpu__get_core_id(cpu);
+		int socket_id = cpu__get_socket_id(cpu);
+		int die_id    = cpu__get_die_id(cpu);
 
-		env->cpu[idx].core_id	= cpu__get_core_id(cpu);
-		env->cpu[idx].socket_id	= cpu__get_socket_id(cpu);
-		env->cpu[idx].die_id	= cpu__get_die_id(cpu);
+		env->cpu[idx].core_id	= core_id >= 0 ? core_id : -1;
+		env->cpu[idx].socket_id	= socket_id >= 0 ? socket_id : -1;
+		env->cpu[idx].die_id	= die_id >= 0 ? die_id : -1;
 	}
 
 	env->nr_cpus_avail = nr_cpus;
-- 
2.47.0.338.g60cca15819-goog