Discussion:
[PATCH] drivers: base: update cpu offline info when do hotplug
Neil Zhang
2014-10-20 03:29:08 UTC
Permalink
The current per-cpu offline info won't be updated if it is
hotplugged in/out by a kernel governer.
Let's update it via cpu notifier.

Signed-off-by: Neil Zhang <***@marvell.com>
---
drivers/base/cpu.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)

diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 006b1bc..9d61824 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -418,10 +418,35 @@ static void __init cpu_dev_register_generic(void)
#endif
}

+static int device_hotplug_notifier(struct notifier_block *nfb,
+ unsigned long action, void *hcpu)
+{
+ unsigned int cpu = (unsigned long)hcpu;
+ struct device *dev = get_cpu_device(cpu);
+ int ret;
+
+ switch (action & ~CPU_TASKS_FROZEN) {
+ case CPU_ONLINE:
+ dev->offline = false;
+ ret = NOTIFY_OK;
+ break;
+ case CPU_DYING:
+ dev->offline = true;
+ ret = NOTIFY_OK;
+ break;
+ default:
+ ret = NOTIFY_DONE;
+ break;
+ }
+
+ return ret;
+}
+
void __init cpu_dev_init(void)
{
if (subsys_system_register(&cpu_subsys, cpu_root_attr_groups))
panic("Failed to register CPU subsystem");

cpu_dev_register_generic();
+ cpu_notifier(device_hotplug_notifier, 0);
}
--
1.7.9.5
Greg KH
2014-10-20 04:43:40 UTC
Permalink
Post by Neil Zhang
The current per-cpu offline info won't be updated if it is
hotplugged in/out by a kernel governer.
Let's update it via cpu notifier.
---
drivers/base/cpu.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 006b1bc..9d61824 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -418,10 +418,35 @@ static void __init cpu_dev_register_generic(void)
#endif
}
+static int device_hotplug_notifier(struct notifier_block *nfb,
+ unsigned long action, void *hcpu)
+{
+ unsigned int cpu = (unsigned long)hcpu;
+ struct device *dev = get_cpu_device(cpu);
+ int ret;
+
+ switch (action & ~CPU_TASKS_FROZEN) {
+ dev->offline = false;
+ ret = NOTIFY_OK;
+ break;
+ dev->offline = true;
+ ret = NOTIFY_OK;
+ break;
+ ret = NOTIFY_DONE;
+ break;
+ }
+
+ return ret;
+}
+
void __init cpu_dev_init(void)
{
if (subsys_system_register(&cpu_subsys, cpu_root_attr_groups))
panic("Failed to register CPU subsystem");
cpu_dev_register_generic();
+ cpu_notifier(device_hotplug_notifier, 0);
}
How much noise is this going to cause on a big/little system that
constantly hot unplug/plugs processors all of the time?

greg k-h
Neil Zhang
2014-10-20 06:39:23 UTC
Permalink
Greg,

-----Original Message-----
From: Greg KH [mailto:***@linuxfoundation.org]
Sent: 2014年10月20日 12:44
To: Neil Zhang
Cc: linux-***@vger.kernel.org
Subject: Re: [PATCH] drivers: base: update cpu offline info when do hotplug
The current per-cpu offline info won't be updated if it is hotplugged
in/out by a kernel governer.
Let's update it via cpu notifier.
---
drivers/base/cpu.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c index
006b1bc..9d61824 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -418,10 +418,35 @@ static void __init
cpu_dev_register_generic(void) #endif }
+static int device_hotplug_notifier(struct notifier_block *nfb,
+ unsigned long action, void *hcpu) {
+ unsigned int cpu = (unsigned long)hcpu;
+ struct device *dev = get_cpu_device(cpu);
+ int ret;
+
+ switch (action & ~CPU_TASKS_FROZEN) {
+ dev->offline = false;
+ ret = NOTIFY_OK;
+ break;
+ dev->offline = true;
+ ret = NOTIFY_OK;
+ break;
+ ret = NOTIFY_DONE;
+ break;
+ }
+
+ return ret;
+}
+
void __init cpu_dev_init(void)
{
if (subsys_system_register(&cpu_subsys, cpu_root_attr_groups))
panic("Failed to register CPU subsystem");
cpu_dev_register_generic();
+ cpu_notifier(device_hotplug_notifier, 0);
}
How much noise is this going to cause on a big/little system that constantly hot unplug/plugs processors all of the time?

Can you explain more what kind of noise will be introduced on a big/little system?
As I know IKS on arm will use cpu_suspend way to power down a core.
But I don't know well about other architectures.
Please give your suggestions.
Th
Greg KH
2014-10-20 06:48:26 UTC
Permalink
Post by Neil Zhang
Post by Greg KH
How much noise is this going to cause on a big/little system that
constantly hot unplug/plugs processors all of the time?
Can you explain more what kind of noise will be introduced on a big/little system?
Have you tested this on such a machine?
Post by Neil Zhang
As I know IKS on arm will use cpu_suspend way to power down a core.
Are you sure that it also doesn't use that same functionality to drop a
processor to save power?

Why do you need/want this notification? What are you going to do with
this information that you don't already have?

thanks,

greg k-h
Neil Zhang
2014-10-20 07:40:48 UTC
Permalink
Greg,


-----Original Message-----
From: Greg KH [mailto:***@linuxfoundation.org]
Sent: 2014年10月20日 14:48
To: Neil Zhang
Cc: linux-***@vger.kernel.org
Subject: Re: [PATCH] drivers: base: update cpu offline info when do hotplug
Post by Neil Zhang
Post by Greg KH
How much noise is this going to cause on a big/little system that
constantly hot unplug/plugs processors all of the time?
Can you explain more what kind of noise will be introduced on a big/little system?
Have you tested this on such a machine?

I didn't have such kind of machine on hand.
Can anyone has such machine to verify it?
Thanks!
Post by Neil Zhang
As I know IKS on arm will use cpu_suspend way to power down a core.
Are you sure that it also doesn't use that same functionality to drop a processor to save power?

As I know it use cpu_suspend to switch out a processor in IKS and there is no cpu hotplug notifier in this procedure.


Why do you need/want this notification? What are you going to do with this information that you don't already have?

The offline won't be updated if an in kernel hotplug governor plug in / out a core which cause the sysfs interface report a wrong status.


thanks,

greg k-h
Dan Streetman
2014-10-20 17:02:39 UTC
Permalink
Post by Neil Zhang
Greg,
-----Original Message-----
Sent: 2014=E5=B9=B410=E6=9C=8820=E6=97=A5 14:48
To: Neil Zhang
Subject: Re: [PATCH] drivers: base: update cpu offline info when do h=
otplug
Post by Neil Zhang
Post by Greg KH
How much noise is this going to cause on a big/little system that
constantly hot unplug/plugs processors all of the time?
Can you explain more what kind of noise will be introduced on a big/=
little system?
Post by Neil Zhang
Have you tested this on such a machine?
I didn't have such kind of machine on hand.
Can anyone has such machine to verify it?
Thanks!
I tested this on a ppc PowerVM system, using dlpar operations to
remove/add cpus.

Without this patch the cpu online nodes get out of sync with the main
online node (and the actual state of the cpus), because they aren't
updated as the cpus are brought up/down:

[***@br10p02 cpu]$ pwd
/sys/devices/system/cpu
[***@br10p02 cpu]$ cat online
0-39
[***@br10p02 cpu]$ for n in {0..47} ; do test $( cat cpu$n/online )
-eq 1 && echo -n "$n " ; done ; echo ""
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47


While with the patch, the cpu online nodes are kept up to date as the
cpus are brought up/down:

[***@br10p02 cpu]$ pwd
/sys/devices/system/cpu
[***@br10p02 cpu]$ cat online
0-39
[***@br10p02 cpu]$ for n in {0..47} ; do test $( cat cpu$n/online )
-eq 1 && echo -n "$n " ; done ; echo ""
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
27 28 29 30 31 32 33 34 35 36 37 38 39


=46eel free to add
Post by Neil Zhang
As I know IKS on arm will use cpu_suspend way to power down a core.
Are you sure that it also doesn't use that same functionality to drop=
a processor to save power?
Post by Neil Zhang
As I know it use cpu_suspend to switch out a processor in IKS and the=
re is no cpu hotplug notifier in this procedure.
Post by Neil Zhang
Why do you need/want this notification? What are you going to do wit=
h this information that you don't already have?
Post by Neil Zhang
The offline won't be updated if an in kernel hotplug governor plug in=
/ out a core which cause the sysfs interface report a wrong status.
Post by Neil Zhang
thanks,
greg k-h
Best Regards,
Neil Zhang
Loading...