Return-Path: Received: from mail-cys01nam02on0106.outbound.protection.outlook.com ([104.47.37.106]:53792 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752467AbeAXEO0 (ORCPT ); Tue, 23 Jan 2018 23:14:26 -0500 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Abhishek Goel , Shuah Khan , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 005/100] cpupower : Fix cpupower working when cpu0 is offline Date: Wed, 24 Jan 2018 04:14:23 +0000 Message-ID: <20180124041414.32065-5-alexander.levin@microsoft.com> References: <20180124041414.32065-1-alexander.levin@microsoft.com> In-Reply-To: <20180124041414.32065-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Abhishek Goel [ Upstream commit dbdc468f35ee827cab2753caa1c660bdb832243a ] cpuidle_monitor used to assume that cpu0 is always online which is not a valid assumption on POWER machines. This patch fixes this by getting the cpu on which the current thread is running, instead of always using cpu0 for monitoring which may not be online. Signed-off-by: Abhishek Goel Signed-off-by: Shuah Khan Signed-off-by: Sasha Levin --- tools/power/cpupower/utils/idle_monitor/cpuidle_sysfs.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/power/cpupower/utils/idle_monitor/cpuidle_sysfs.c b/tool= s/power/cpupower/utils/idle_monitor/cpuidle_sysfs.c index 1b5da0066ebf..5b3205f16217 100644 --- a/tools/power/cpupower/utils/idle_monitor/cpuidle_sysfs.c +++ b/tools/power/cpupower/utils/idle_monitor/cpuidle_sysfs.c @@ -130,15 +130,18 @@ static struct cpuidle_monitor *cpuidle_register(void) { int num; char *tmp; + int this_cpu; + + this_cpu =3D sched_getcpu(); =20 /* Assume idle state count is the same for all CPUs */ - cpuidle_sysfs_monitor.hw_states_num =3D cpuidle_state_count(0); + cpuidle_sysfs_monitor.hw_states_num =3D cpuidle_state_count(this_cpu); =20 if (cpuidle_sysfs_monitor.hw_states_num <=3D 0) return NULL; =20 for (num =3D 0; num < cpuidle_sysfs_monitor.hw_states_num; num++) { - tmp =3D cpuidle_state_name(0, num); + tmp =3D cpuidle_state_name(this_cpu, num); if (tmp =3D=3D NULL) continue; =20 @@ -146,7 +149,7 @@ static struct cpuidle_monitor *cpuidle_register(void) strncpy(cpuidle_cstates[num].name, tmp, CSTATE_NAME_LEN - 1); free(tmp); =20 - tmp =3D cpuidle_state_desc(0, num); + tmp =3D cpuidle_state_desc(this_cpu, num); if (tmp =3D=3D NULL) continue; strncpy(cpuidle_cstates[num].desc, tmp, CSTATE_DESC_LEN - 1); --=20 2.11.0