Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754831AbcKQSgT (ORCPT ); Thu, 17 Nov 2016 13:36:19 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:49657 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754694AbcKQSgS (ORCPT ); Thu, 17 Nov 2016 13:36:18 -0500 From: Sebastian Andrzej Siewior To: linux-kernel@vger.kernel.org Cc: rt@linuxtronix.de, Sebastian Andrzej Siewior , x86@kernel.org, Thomas Gleixner Subject: [PATCH 02/20] x86/cpuid: Convert to hotplug state machine Date: Thu, 17 Nov 2016 19:35:23 +0100 Message-Id: <20161117183541.8588-3-bigeasy@linutronix.de> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161117183541.8588-1-bigeasy@linutronix.de> References: <20161117183541.8588-1-bigeasy@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3412 Lines: 124 Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs. Cc: x86@kernel.org Signed-off-by: Sebastian Andrzej Siewior Signed-off-by: Thomas Gleixner --- arch/x86/kernel/cpuid.c | 54 ++++++++----------------------------------= ---- include/linux/cpuhotplug.h | 1 + 2 files changed, 10 insertions(+), 45 deletions(-) diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c index 2836de390f95..eaa272454fe4 100644 --- a/arch/x86/kernel/cpuid.c +++ b/arch/x86/kernel/cpuid.c @@ -115,7 +115,7 @@ static const struct file_operations cpuid_fops =3D { .open =3D cpuid_open, }; =20 -static int cpuid_device_create(int cpu) +static int cpuid_device_create(unsigned int cpu) { struct device *dev; =20 @@ -124,35 +124,12 @@ static int cpuid_device_create(int cpu) return PTR_ERR_OR_ZERO(dev); } =20 -static void cpuid_device_destroy(int cpu) +static int cpuid_device_destroy(unsigned int cpu) { device_destroy(cpuid_class, MKDEV(CPUID_MAJOR, cpu)); + return 0; } =20 -static int cpuid_class_cpu_callback(struct notifier_block *nfb, - unsigned long action, void *hcpu) -{ - unsigned int cpu =3D (unsigned long)hcpu; - int err =3D 0; - - switch (action) { - case CPU_UP_PREPARE: - err =3D cpuid_device_create(cpu); - break; - case CPU_UP_CANCELED: - case CPU_UP_CANCELED_FROZEN: - case CPU_DEAD: - cpuid_device_destroy(cpu); - break; - } - return notifier_from_errno(err); -} - -static struct notifier_block cpuid_class_cpu_notifier =3D -{ - .notifier_call =3D cpuid_class_cpu_callback, -}; - static char *cpuid_devnode(struct device *dev, umode_t *mode) { return kasprintf(GFP_KERNEL, "cpu/%u/cpuid", MINOR(dev->devt)); @@ -177,24 +154,17 @@ static int __init cpuid_init(void) } cpuid_class->devnode =3D cpuid_devnode; =20 - cpu_notifier_register_begin(); - for_each_online_cpu(i) { - err =3D cpuid_device_create(i); - if (err !=3D 0) - goto out_class; - } - __register_hotcpu_notifier(&cpuid_class_cpu_notifier); - cpu_notifier_register_done(); + err =3D cpuhp_setup_state(CPUHP_X86_CPUID_PREPARE, "x86/cpuid:prepare", + cpuid_device_create, cpuid_device_destroy); + if (err) + goto out_class; =20 err =3D 0; goto out; =20 out_class: i =3D 0; - for_each_online_cpu(i) { - cpuid_device_destroy(i); - } - cpu_notifier_register_done(); + cpuhp_remove_state(CPUHP_X86_CPUID_PREPARE); class_destroy(cpuid_class); out_chrdev: __unregister_chrdev(CPUID_MAJOR, 0, NR_CPUS, "cpu/cpuid"); @@ -204,15 +174,9 @@ static int __init cpuid_init(void) =20 static void __exit cpuid_exit(void) { - int cpu =3D 0; - - cpu_notifier_register_begin(); - for_each_online_cpu(cpu) - cpuid_device_destroy(cpu); + cpuhp_remove_state(CPUHP_X86_CPUID_PREPARE); class_destroy(cpuid_class); __unregister_chrdev(CPUID_MAJOR, 0, NR_CPUS, "cpu/cpuid"); - __unregister_hotcpu_notifier(&cpuid_class_cpu_notifier); - cpu_notifier_register_done(); } =20 module_init(cpuid_init); diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h index aea6c6a63139..2f9e083791c4 100644 --- a/include/linux/cpuhotplug.h +++ b/include/linux/cpuhotplug.h @@ -60,6 +60,7 @@ enum cpuhp_state { CPUHP_NET_FLOW_PREPARE, CPUHP_TOPOLOGY_PREPARE, CPUHP_X86_THERM_PREPARE, + CPUHP_X86_CPUID_PREPARE, CPUHP_TIMERS_DEAD, CPUHP_NOTF_ERR_INJ_PREPARE, CPUHP_MIPS_SOC_PREPARE, --=20 2.10.2