[PATCH v3 2/3] cpupower: let the core == -1 check handle failed topology reads
From: Ali Ahmet Memis
Date: Thu Aug 06 2026 - 13:56:41 EST
When physical_package_id or core_id cannot be read, get_cpu_topology()
sets pkg and core to -1 and skips the rest of the iteration. The check
below them exists to give such an entry a defined core_cpu_list:
if (cpu_top->core_info[cpu].core == -1) {
strncpy(cpu_top->core_info[cpu].core_cpu_list, "-1", CPULIST_BUFFER);
continue;
}
The two continue statements above it mean it never runs for the entries it
was written for, since a CPU whose topology cannot be read is exactly the
case it describes. Nothing between the reads and that check needs skipping,
so drop the continue statements and let it do its job.
Suggested-by: Shuah Khan <skhan@xxxxxxxxxxxxxxxxxxx>
Signed-off-by: Ali Ahmet Memis <ali@xxxxxxxxxxxxxx>
---
tools/power/cpupower/lib/cpupower.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/tools/power/cpupower/lib/cpupower.c b/tools/power/cpupower/lib/cpupower.c
index 559b04f4387e..3d7e22ed1fd7 100644
--- a/tools/power/cpupower/lib/cpupower.c
+++ b/tools/power/cpupower/lib/cpupower.c
@@ -184,7 +184,6 @@ int get_cpu_topology(struct cpupower_topology *cpu_top)
&(cpu_top->core_info[cpu].pkg)) < 0) {
cpu_top->core_info[cpu].pkg = -1;
cpu_top->core_info[cpu].core = -1;
- continue;
}
if(sysfs_topology_read_file(
cpu,
@@ -192,7 +191,6 @@ int get_cpu_topology(struct cpupower_topology *cpu_top)
&(cpu_top->core_info[cpu].core)) < 0) {
cpu_top->core_info[cpu].pkg = -1;
cpu_top->core_info[cpu].core = -1;
- continue;
}
if (cpu_top->core_info[cpu].core == -1) {
strncpy(cpu_top->core_info[cpu].core_cpu_list, "-1", CPULIST_BUFFER);
--
2.55.0