cpupower: Fix checks for CPU existence
authorBen Hutchings <ben@decadent.org.uk>
Thu, 3 Nov 2016 21:25:26 +0000 (15:25 -0600)
committerBen Hutchings <ben@decadent.org.uk>
Thu, 28 Sep 2017 17:27:56 +0000 (18:27 +0100)
Calls to cpufreq_cpu_exists(cpu) were converted to
cpupower_is_cpu_online(cpu) when libcpupower was introduced and the
former function was deleted.  However, cpupower_is_cpu_online()
returns 1 on success whereas cpufreq_cpu_exists() returned 0 on
success.  It also does not distinguish physically absent and offline
CPUs, and does not set errno.

cpufreq-set has already been fixed (commit c25badc9ceb6).

In cpufreq-bench, which prints an error message for offline CPUs,
properly distinguish and report the zero and negative cases.

Fixes: ac5a181d065d ("cpupower: Add cpuidle parts into library")
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Gbp-Pq: Topic bugfix/all
Gbp-Pq: Name cpupower-fix-checks-for-cpu-existence.patch

tools/power/cpupower/bench/system.c

index c25a74ae51baef13bfa5609d2957af76941597f6..fd1bb3790ceb45538d7e46248ba06cbfd9f1f8df 100644 (file)
@@ -58,12 +58,19 @@ long long int get_time()
 
 int set_cpufreq_governor(char *governor, unsigned int cpu)
 {
+       int rc;
 
        dprintf("set %s as cpufreq governor\n", governor);
 
-       if (cpupower_is_cpu_online(cpu) != 0) {
-               perror("cpufreq_cpu_exists");
-               fprintf(stderr, "error: cpu %u does not exist\n", cpu);
+       rc = cpupower_is_cpu_online(cpu);
+       if (rc != 1) {
+               if (rc < 0)
+                       fprintf(stderr, "cpupower_is_cpu_online: %s\n",
+                               strerror(-rc));
+               else
+                       fprintf(stderr,
+                               "error: cpu %u is offline or does not exist\n",
+                               cpu);
                return -1;
        }