Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752072AbdIVLDr (ORCPT ); Fri, 22 Sep 2017 07:03:47 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:51290 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751919AbdIVLDq (ORCPT ); Fri, 22 Sep 2017 07:03:46 -0400 From: Abhishek Goel To: trenn@suse.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Abhishek Goel Subject: [PATCH] cpupower : Fix cpupower working when cpu0 is offline Date: Fri, 22 Sep 2017 16:32:18 +0530 X-Mailer: git-send-email 2.9.3 X-TM-AS-MML: disable x-cbid: 17092211-0040-0000-0000-000003574C4A X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17092211-0041-0000-0000-00000CD81500 Message-Id: <20170922110218.120948-1-huntbag@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-09-22_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1709220154 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1732 Lines: 50 cpuidle_monitor used to assume that cpu0 is always online. Now the cpuidle_monitor function searches for the first online cpu and use it, instead of always using cpu0 which may not be online. Signed-off-by: Abhishek Goel --- tools/power/cpupower/utils/idle_monitor/cpuidle_sysfs.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/power/cpupower/utils/idle_monitor/cpuidle_sysfs.c b/tools/power/cpupower/utils/idle_monitor/cpuidle_sysfs.c index 1b5da00..adacf99 100644 --- a/tools/power/cpupower/utils/idle_monitor/cpuidle_sysfs.c +++ b/tools/power/cpupower/utils/idle_monitor/cpuidle_sysfs.c @@ -130,15 +130,23 @@ static struct cpuidle_monitor *cpuidle_register(void) { int num; char *tmp; + int first_online_cpu; + + for (num = 0; num < cpu_count; num++) { + if (cpupower_is_cpu_online(num)) + break; + }; + first_online_cpu = num; /* Assume idle state count is the same for all CPUs */ - cpuidle_sysfs_monitor.hw_states_num = cpuidle_state_count(0); + cpuidle_sysfs_monitor.hw_states_num = + cpuidle_state_count(first_online_cpu); if (cpuidle_sysfs_monitor.hw_states_num <= 0) return NULL; for (num = 0; num < cpuidle_sysfs_monitor.hw_states_num; num++) { - tmp = cpuidle_state_name(0, num); + tmp = cpuidle_state_name(first_online_cpu, num); if (tmp == NULL) continue; @@ -146,7 +154,7 @@ static struct cpuidle_monitor *cpuidle_register(void) strncpy(cpuidle_cstates[num].name, tmp, CSTATE_NAME_LEN - 1); free(tmp); - tmp = cpuidle_state_desc(0, num); + tmp = cpuidle_state_desc(first_online_cpu, num); if (tmp == NULL) continue; strncpy(cpuidle_cstates[num].desc, tmp, CSTATE_DESC_LEN - 1); -- 2.9.3