Currently, the ACPI power notify makes it once per system instead of once per-cpu.
And driver selects the notify on CPU0 to update idle states.
The same idle state is used for all CPUs. An avaiable power information
is obtained successfully from any CPUs can be used to populate the ACPI idle
states as acpi_processor_register_idle_driver() did.
So keep the same logical to get avaiable power information from online CPUs
instead of CPU0 to update idle states in power notify.
Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
drivers/acpi/processor_idle.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index cd4d1d8d70b0..8d3122a4e6d0 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -1332,19 +1332,26 @@ int acpi_processor_power_state_has_changed(struct acpi_processor *pr)
*
* The same idle state is used for all CPUs.
* The old idle state may not be usable anymore if fail to get
- * ACPI power information of CPU0.
+ * available ACPI power information from any online CPU.
* The cpuidle of all CPUs should be disabled.
*/
- ret = acpi_processor_get_power_info(pr);
+ ret = -ENODEV;
+ for_each_online_cpu(cpu) {
+ _pr = per_cpu(processors, cpu);
+ if (!_pr && !_pr->flags.power_setup_done)
+ continue;
+ ret = acpi_processor_get_power_info(_pr);
+ if (!ret) {
+ acpi_processor_setup_cpuidle_states(_pr);
+ break;
+ }
+ }
if (ret) {
/* Ensure cpuidle of offline CPUs are inavaliable. */
disable_cpuidle();
- pr_err("Get processor-%u power information failed, disable cpuidle of all CPUs\n",
- pr->id);
+ pr_err("No available ACPI power information, disable cpuidle of all CPUs.\n");
goto release_lock;
}
-
- acpi_processor_setup_cpuidle_states(pr);
enable_cpuidle();
/* Enable all cpuidle devices */
--
2.33.0
Hi Huisong,
kernel test robot noticed the following build warnings:
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Huisong-Li/cpuidle-Add-enable_cpuidle-interface/20251125-153615
base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
patch link: https://lore.kernel.org/r/20251125072933.3706006-4-lihuisong%40huawei.com
patch subject: [PATCH 3/3] ACPI: processor: idle: Update idle states from avaiable power information
config: i386-randconfig-141-20251126 (https://download.01.org/0day-ci/archive/20251127/202511272353.nOqEau6n-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
| Closes: https://lore.kernel.org/r/202511272353.nOqEau6n-lkp@intel.com/
smatch warnings:
drivers/acpi/processor_idle.c:1339 acpi_processor_power_state_has_changed() error: we previously assumed '_pr' could be null (see line 1339)
vim +/_pr +1339 drivers/acpi/processor_idle.c
a36a7fecfe6071 Sudeep Holla 2016-07-21 1294 int acpi_processor_power_state_has_changed(struct acpi_processor *pr)
46bcfad7a819bd Deepthi Dharwar 2011-10-28 1295 {
46bcfad7a819bd Deepthi Dharwar 2011-10-28 1296 int cpu;
46bcfad7a819bd Deepthi Dharwar 2011-10-28 1297 struct acpi_processor *_pr;
3d339dcbb56d8d Daniel Lezcano 2012-09-17 1298 struct cpuidle_device *dev;
ffff9603ddf90a Huisong Li 2025-11-25 1299 int ret = 0;
46bcfad7a819bd Deepthi Dharwar 2011-10-28 1300
46bcfad7a819bd Deepthi Dharwar 2011-10-28 1301 if (disabled_by_idle_boot_param())
46bcfad7a819bd Deepthi Dharwar 2011-10-28 1302 return 0;
46bcfad7a819bd Deepthi Dharwar 2011-10-28 1303
46bcfad7a819bd Deepthi Dharwar 2011-10-28 1304 if (!pr->flags.power_setup_done)
46bcfad7a819bd Deepthi Dharwar 2011-10-28 1305 return -ENODEV;
46bcfad7a819bd Deepthi Dharwar 2011-10-28 1306
46bcfad7a819bd Deepthi Dharwar 2011-10-28 1307 /*
46bcfad7a819bd Deepthi Dharwar 2011-10-28 1308 * FIXME: Design the ACPI notification to make it once per
46bcfad7a819bd Deepthi Dharwar 2011-10-28 1309 * system instead of once per-cpu. This condition is a hack
46bcfad7a819bd Deepthi Dharwar 2011-10-28 1310 * to make the code that updates C-States be called once.
46bcfad7a819bd Deepthi Dharwar 2011-10-28 1311 */
46bcfad7a819bd Deepthi Dharwar 2011-10-28 1312
9505626d7bfeb5 Paul E. McKenney 2012-02-28 1313 if (pr->id == 0 && cpuidle_get_driver() == &acpi_idle_driver) {
46bcfad7a819bd Deepthi Dharwar 2011-10-28 1314
46bcfad7a819bd Deepthi Dharwar 2011-10-28 1315 /* Protect against cpu-hotplug */
95ac706744de78 Sebastian Andrzej Siewior 2021-08-03 1316 cpus_read_lock();
6726655dfdd2dc Jiri Kosina 2014-09-03 1317 cpuidle_pause_and_lock();
46bcfad7a819bd Deepthi Dharwar 2011-10-28 1318
46bcfad7a819bd Deepthi Dharwar 2011-10-28 1319 /* Disable all cpuidle devices */
46bcfad7a819bd Deepthi Dharwar 2011-10-28 1320 for_each_online_cpu(cpu) {
46bcfad7a819bd Deepthi Dharwar 2011-10-28 1321 _pr = per_cpu(processors, cpu);
46bcfad7a819bd Deepthi Dharwar 2011-10-28 1322 if (!_pr || !_pr->flags.power_setup_done)
46bcfad7a819bd Deepthi Dharwar 2011-10-28 1323 continue;
3d339dcbb56d8d Daniel Lezcano 2012-09-17 1324 dev = per_cpu(acpi_cpuidle_device, cpu);
3d339dcbb56d8d Daniel Lezcano 2012-09-17 1325 cpuidle_disable_device(dev);
46bcfad7a819bd Deepthi Dharwar 2011-10-28 1326 }
46bcfad7a819bd Deepthi Dharwar 2011-10-28 1327
ffff9603ddf90a Huisong Li 2025-11-25 1328 /*
ffff9603ddf90a Huisong Li 2025-11-25 1329 * Update C-state information based on new power information.
ffff9603ddf90a Huisong Li 2025-11-25 1330 *
ffff9603ddf90a Huisong Li 2025-11-25 1331 * The same idle state is used for all CPUs.
ffff9603ddf90a Huisong Li 2025-11-25 1332 * The old idle state may not be usable anymore if fail to get
092a52b5417fd4 Huisong Li 2025-11-25 1333 * available ACPI power information from any online CPU.
ffff9603ddf90a Huisong Li 2025-11-25 1334 * The cpuidle of all CPUs should be disabled.
ffff9603ddf90a Huisong Li 2025-11-25 1335 */
092a52b5417fd4 Huisong Li 2025-11-25 1336 ret = -ENODEV;
092a52b5417fd4 Huisong Li 2025-11-25 1337 for_each_online_cpu(cpu) {
092a52b5417fd4 Huisong Li 2025-11-25 1338 _pr = per_cpu(processors, cpu);
092a52b5417fd4 Huisong Li 2025-11-25 @1339 if (!_pr && !_pr->flags.power_setup_done)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
if _pr is NULL this will crash. s/&&/||/
092a52b5417fd4 Huisong Li 2025-11-25 1340 continue;
092a52b5417fd4 Huisong Li 2025-11-25 1341 ret = acpi_processor_get_power_info(_pr);
092a52b5417fd4 Huisong Li 2025-11-25 1342 if (!ret) {
092a52b5417fd4 Huisong Li 2025-11-25 1343 acpi_processor_setup_cpuidle_states(_pr);
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
© 2016 - 2025 Red Hat, Inc.