From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755490AbcKQSlw (ORCPT ); Thu, 17 Nov 2016 13:41:52 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:49659 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754775AbcKQSgT (ORCPT ); Thu, 17 Nov 2016 13:36:19 -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 03/20] x86/msr: Convert to hotplug state machine Date: Thu, 17 Nov 2016 19:35:24 +0100 Message-Id: <20161117183541.8588-4-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 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/msr.c | 56 +++++++++---------------------------------= ---- include/linux/cpuhotplug.h | 1 + 2 files changed, 11 insertions(+), 46 deletions(-) diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c index 7f3550acde1b..43a125b5c5dc 100644 --- a/arch/x86/kernel/msr.c +++ b/arch/x86/kernel/msr.c @@ -180,7 +180,7 @@ static const struct file_operations msr_fops =3D { .compat_ioctl =3D msr_ioctl, }; =20 -static int msr_device_create(int cpu) +static int msr_device_create(unsigned int cpu) { struct device *dev; =20 @@ -189,34 +189,12 @@ static int msr_device_create(int cpu) return PTR_ERR_OR_ZERO(dev); } =20 -static void msr_device_destroy(int cpu) +static int msr_device_destroy(unsigned int cpu) { device_destroy(msr_class, MKDEV(MSR_MAJOR, cpu)); + return 0; } =20 -static int msr_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 msr_device_create(cpu); - break; - case CPU_UP_CANCELED: - case CPU_UP_CANCELED_FROZEN: - case CPU_DEAD: - msr_device_destroy(cpu); - break; - } - return notifier_from_errno(err); -} - -static struct notifier_block __refdata msr_class_cpu_notifier =3D { - .notifier_call =3D msr_class_cpu_callback, -}; - static char *msr_devnode(struct device *dev, umode_t *mode) { return kasprintf(GFP_KERNEL, "cpu/%u/msr", MINOR(dev->devt)); @@ -224,8 +202,7 @@ static char *msr_devnode(struct device *dev, umode_t *m= ode) =20 static int __init msr_init(void) { - int i, err =3D 0; - i =3D 0; + int err; =20 if (__register_chrdev(MSR_MAJOR, 0, NR_CPUS, "cpu/msr", &msr_fops)) { pr_err("unable to get major %d for msr\n", MSR_MAJOR); @@ -239,23 +216,16 @@ static int __init msr_init(void) } msr_class->devnode =3D msr_devnode; =20 - cpu_notifier_register_begin(); - for_each_online_cpu(i) { - err =3D msr_device_create(i); - if (err !=3D 0) - goto out_class; - } - __register_hotcpu_notifier(&msr_class_cpu_notifier); - cpu_notifier_register_done(); + err =3D cpuhp_setup_state(CPUHP_X86_MSR_PREPARE, "x86/msr:prepare", + msr_device_create, msr_device_destroy); + if (err) + goto out_class; =20 err =3D 0; goto out; =20 out_class: - i =3D 0; - for_each_online_cpu(i) - msr_device_destroy(i); - cpu_notifier_register_done(); + cpuhp_remove_state(CPUHP_X86_MSR_PREPARE); class_destroy(msr_class); out_chrdev: __unregister_chrdev(MSR_MAJOR, 0, NR_CPUS, "cpu/msr"); @@ -265,15 +235,9 @@ static int __init msr_init(void) =20 static void __exit msr_exit(void) { - int cpu =3D 0; - - cpu_notifier_register_begin(); - for_each_online_cpu(cpu) - msr_device_destroy(cpu); class_destroy(msr_class); __unregister_chrdev(MSR_MAJOR, 0, NR_CPUS, "cpu/msr"); - __unregister_hotcpu_notifier(&msr_class_cpu_notifier); - cpu_notifier_register_done(); + cpuhp_remove_state(CPUHP_X86_MSR_PREPARE); } =20 module_init(msr_init); diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h index 2f9e083791c4..6506dce8343a 100644 --- a/include/linux/cpuhotplug.h +++ b/include/linux/cpuhotplug.h @@ -61,6 +61,7 @@ enum cpuhp_state { CPUHP_TOPOLOGY_PREPARE, CPUHP_X86_THERM_PREPARE, CPUHP_X86_CPUID_PREPARE, + CPUHP_X86_MSR_PREPARE, CPUHP_TIMERS_DEAD, CPUHP_NOTF_ERR_INJ_PREPARE, CPUHP_MIPS_SOC_PREPARE, --=20 2.10.2