Re: [PATCH V2] Driver cpu: update online when cpu_up/down besides sysfs

From: Rafael J. Wysocki
Date: Mon Oct 27 2014 - 17:39:05 EST


On 10/27/2014 3:59 AM, Neil Zhang wrote:
The current per-cpu offline info won't be updated when we use
any other method besides sysfs to call cpu_up/down.
Thus the cpu/online can't reflect the real online status.

This patch is going to fix the issue introduced by commit
0902a9044fa5b7a0456ea4daacec2c2b3189ba8c (Driver core:
Use generic offline/online for CPU offline/online)

CC: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>
Tested-by: Dan Streetman <ddstreet@xxxxxxxx>
Signed-off-by: Neil Zhang <zhangwm@xxxxxxxxxxx>

Oh dear, no.

Please first tell me what exactly the problem you're seeing is.

---
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);
}

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/