tools: cpupower: Fix error when running cpupower monitor
authorShreyas B. Prabhu <shreyas@linux.vnet.ibm.com>
Mon, 3 Aug 2015 06:16:00 +0000 (11:46 +0530)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 28 Aug 2015 23:38:16 +0000 (01:38 +0200)
get_cpu_topology() tries to get topology info from all cpus by reading
files in the topology sysfs dir. If a cpu is offlined, since it doesn't
have topology dir, this function fails and returns -1. This causes
functions relying on get_cpu_topology() to fail. For example-

$ cpupower monitor
Cannot read number of available processors

Fix this by skipping fetching topology info for offline cpus.

Signed-off-by: Shreyas B. Prabhu <shreyas@linux.vnet.ibm.com>
Reported-by: Pavaman Subramaniyam <pavsubra@linux.vnet.ibm.com>
Acked-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
tools/power/cpupower/utils/helpers/topology.c

index c13120af519b40aec94ce8055c946b1bcd426143..cea398c176e7f29057a24463f296300f8ce5f23f 100644 (file)
@@ -73,6 +73,8 @@ int get_cpu_topology(struct cpupower_topology *cpu_top)
        for (cpu = 0; cpu < cpus; cpu++) {
                cpu_top->core_info[cpu].cpu = cpu;
                cpu_top->core_info[cpu].is_online = sysfs_is_cpu_online(cpu);
+               if (!cpu_top->core_info[cpu].is_online)
+                       continue;
                if(sysfs_topology_read_file(
                        cpu,
                        "physical_package_id",