From patchwork Tue Apr 18 02:31:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Hutchings X-Patchwork-Id: 9684889 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 77173602C2 for ; Tue, 18 Apr 2017 02:31:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6730E2621D for ; Tue, 18 Apr 2017 02:31:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 58FA027E5A; Tue, 18 Apr 2017 02:31:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A82062621D for ; Tue, 18 Apr 2017 02:31:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754873AbdDRCbU (ORCPT ); Mon, 17 Apr 2017 22:31:20 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:45131 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754831AbdDRCbU (ORCPT ); Mon, 17 Apr 2017 22:31:20 -0400 Received: from ben by shadbolt.decadent.org.uk with local (Exim 4.84_2) (envelope-from ) id 1d0IvG-0006xC-VT; Tue, 18 Apr 2017 03:31:19 +0100 Date: Tue, 18 Apr 2017 03:31:18 +0100 From: Ben Hutchings To: Thomas Renninger Cc: linux-pm@vger.kernel.org Message-ID: <20170418023118.GD4152@decadent.org.uk> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: ben@decadent.org.uk Subject: [PATCH] cpupower: Fix checks for CPU existence X-SA-Exim-Version: 4.2.1 (built Mon, 26 Dec 2011 16:24:06 +0000) X-SA-Exim-Scanned: Yes (on shadbolt.decadent.org.uk) Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- a/tools/power/cpupower/bench/system.c +++ b/tools/power/cpupower/bench/system.c @@ -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; }