Linux-PM Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] cpuidle: cpu hotplug support
@ 2019-10-11  8:34 Zhenzhong Duan
  2019-10-13 17:48 ` kbuild test robot
  0 siblings, 1 reply; 2+ messages in thread
From: Zhenzhong Duan @ 2019-10-11  8:34 UTC (permalink / raw)
  To: linux-kernel; +Cc: rjw, daniel.lezcano, linux-pm, mtosatti, Zhenzhong Duan

Currently cpuidle driver doesn't support cpu hotplug. When
cpus != maxcpus cpuidle_register() will fail to register all cpus
past the online ones and thus fail to register the idle driver.
This is because cpuidle_add_sysfs() will return with -ENODEV as a
consequence from get_cpu_device() return no device for a non-existing
CPU.

At least cpuidle-haltpoll and intel_idle are making their own custom
code to support cpu hotplug.

This patch ease the work if we need to write a cpuidle driver with cpu
hotplug support in the future.

Signed-off-by: Zhenzhong Duan <zhenzhong.duan@oracle.com>
---
 drivers/cpuidle/cpuidle.c | 76 ++++++++++++++++++++++++++++++++---------------
 1 file changed, 52 insertions(+), 24 deletions(-)

diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
index 0895b98..3ce6d2d 100644
--- a/drivers/cpuidle/cpuidle.c
+++ b/drivers/cpuidle/cpuidle.c
@@ -558,6 +558,51 @@ static void __cpuidle_device_init(struct cpuidle_device *dev)
 	dev->next_hrtimer = 0;
 }
 
+static int cpuidle_cpu_online(unsigned int cpu)
+{
+	int ret;
+	struct cpuidle_device *device;
+	struct cpuidle_driver *drv;
+
+	device = &per_cpu(cpuidle_dev, cpu);
+	device->cpu = cpu;
+
+	drv = cpuidle_get_cpu_driver(device);
+	if (!drv || !cpumask_test_cpu(cpu, drv->cpumask))
+		return 0;
+
+#ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED
+	/*
+	 * On multiplatform for ARM, the coupled idle states could be
+	 * enabled in the kernel even if the cpuidle driver does not
+	 * use it. Note, coupled_cpus is a struct copy.
+	 */
+	if (coupled_cpus)
+		device->coupled_cpus = *coupled_cpus;
+#endif
+	ret = cpuidle_register_device(device);
+	if (ret)
+		pr_err("Failed to register cpuidle device for cpu%d\n", cpu);
+
+	return ret;
+}
+
+static int cpuidle_cpu_offline(unsigned int cpu)
+{
+	struct cpuidle_device *device;
+	struct cpuidle_driver *drv;
+
+	device = &per_cpu(cpuidle_dev, cpu);
+
+	drv = cpuidle_get_cpu_driver(device);
+	if (!drv || !cpumask_test_cpu(cpu, drv->cpumask))
+		return 0;
+
+	cpuidle_unregister_device(device);
+
+	return 0;
+}
+
 /**
  * __cpuidle_register_device - internal register function called before register
  * and enable routines
@@ -690,8 +735,8 @@ void cpuidle_unregister(struct cpuidle_driver *drv)
 int cpuidle_register(struct cpuidle_driver *drv,
 		     const struct cpumask *const coupled_cpus)
 {
-	int ret, cpu;
-	struct cpuidle_device *device;
+	int ret;
+	char cb_name[64];
 
 	ret = cpuidle_register_driver(drv);
 	if (ret) {
@@ -699,28 +744,11 @@ int cpuidle_register(struct cpuidle_driver *drv,
 		return ret;
 	}
 
-	for_each_cpu(cpu, drv->cpumask) {
-		device = &per_cpu(cpuidle_dev, cpu);
-		device->cpu = cpu;
-
-#ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED
-		/*
-		 * On multiplatform for ARM, the coupled idle states could be
-		 * enabled in the kernel even if the cpuidle driver does not
-		 * use it. Note, coupled_cpus is a struct copy.
-		 */
-		if (coupled_cpus)
-			device->coupled_cpus = *coupled_cpus;
-#endif
-		ret = cpuidle_register_device(device);
-		if (!ret)
-			continue;
-
-		pr_err("Failed to register cpuidle device for cpu%d\n", cpu);
-
-		cpuidle_unregister(drv);
-		break;
-	}
+	sprintf(cb_name, "cpuidle/%s:online", drv->name);
+	ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, cb_name,
+				cpuidle_cpu_online, cpuidle_cpu_offline);
+	if (ret < 0)
+		cpuidle_unregister_driver(drv);
 
 	return ret;
 }
-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] cpuidle: cpu hotplug support
  2019-10-11  8:34 [PATCH] cpuidle: cpu hotplug support Zhenzhong Duan
@ 2019-10-13 17:48 ` kbuild test robot
  0 siblings, 0 replies; 2+ messages in thread
From: kbuild test robot @ 2019-10-13 17:48 UTC (permalink / raw)
  To: Zhenzhong Duan
  Cc: kbuild-all, linux-kernel, rjw, daniel.lezcano, linux-pm,
	mtosatti, Zhenzhong Duan

[-- Attachment #1: Type: text/plain, Size: 2551 bytes --]

Hi Zhenzhong,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on pm/linux-next]
[cannot apply to v5.4-rc2 next-20191011]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Zhenzhong-Duan/cpuidle-cpu-hotplug-support/20191014-000932
base:   https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
config: mips-allmodconfig (attached as .config)
compiler: mips-linux-gcc (GCC) 7.4.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=7.4.0 make.cross ARCH=mips 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/cpuidle/cpuidle.c: In function 'cpuidle_cpu_online':
>> drivers/cpuidle/cpuidle.c:580:6: error: 'coupled_cpus' undeclared (first use in this function); did you mean 'total_cpus'?
     if (coupled_cpus)
         ^~~~~~~~~~~~
         total_cpus
   drivers/cpuidle/cpuidle.c:580:6: note: each undeclared identifier is reported only once for each function it appears in

vim +580 drivers/cpuidle/cpuidle.c

   560	
   561	static int cpuidle_cpu_online(unsigned int cpu)
   562	{
   563		int ret;
   564		struct cpuidle_device *device;
   565		struct cpuidle_driver *drv;
   566	
   567		device = &per_cpu(cpuidle_dev, cpu);
   568		device->cpu = cpu;
   569	
   570		drv = cpuidle_get_cpu_driver(device);
   571		if (!drv || !cpumask_test_cpu(cpu, drv->cpumask))
   572			return 0;
   573	
   574	#ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED
   575		/*
   576		 * On multiplatform for ARM, the coupled idle states could be
   577		 * enabled in the kernel even if the cpuidle driver does not
   578		 * use it. Note, coupled_cpus is a struct copy.
   579		 */
 > 580		if (coupled_cpus)
   581			device->coupled_cpus = *coupled_cpus;
   582	#endif
   583		ret = cpuidle_register_device(device);
   584		if (ret)
   585			pr_err("Failed to register cpuidle device for cpu%d\n", cpu);
   586	
   587		return ret;
   588	}
   589	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 62105 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-11  8:34 [PATCH] cpuidle: cpu hotplug support Zhenzhong Duan
2019-10-13 17:48 ` kbuild test robot

Linux-PM Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-pm/0 linux-pm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-pm linux-pm/ https://lore.kernel.org/linux-pm \
		linux-pm@vger.kernel.org
	public-inbox-index linux-pm

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-pm


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git