public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Driver Core patches for 2.6.7
Date: Tue, 22 Jun 2004 10:41:50 -0700	[thread overview]
Message-ID: <1087926110895@kroah.com> (raw)
In-Reply-To: <10879261104131@kroah.com>

ChangeSet 1.1722.89.56, 2004/06/08 16:26:12-07:00, hannal@us.ibm.com

[PATCH] Add cpu hotplug support to cpuid.c

Here is the patch that uses a cpu hotplug callback, to allow dynamic support
of cpu id for classes in sysfs.

This patch applies on top of the one I sent out earlier that Greg included.
I do not have access to hardware that supports cpu hotswapping (virtually or not)
so have not been able to test that aspect of the patch. However, the original
functionality of listing static cpu's still works.

Please consider for testing or inclusion.

Signed-off-by: Hanna Linder <hannal@us.ibm.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>


 arch/i386/kernel/cpuid.c |   59 ++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 48 insertions(+), 11 deletions(-)


diff -Nru a/arch/i386/kernel/cpuid.c b/arch/i386/kernel/cpuid.c
--- a/arch/i386/kernel/cpuid.c	Tue Jun 22 09:47:45 2004
+++ b/arch/i386/kernel/cpuid.c	Tue Jun 22 09:47:45 2004
@@ -37,6 +37,8 @@
 #include <linux/smp_lock.h>
 #include <linux/fs.h>
 #include <linux/device.h>
+#include <linux/cpu.h>
+#include <linux/notifier.h>
 
 #include <asm/processor.h>
 #include <asm/msr.h>
@@ -156,10 +158,48 @@
 	.open = cpuid_open,
 };
 
+static void cpuid_class_simple_device_remove(void)
+{
+	int i = 0;
+	for_each_online_cpu(i)
+		class_simple_device_remove(MKDEV(CPUID_MAJOR, i));
+	return;
+}
+
+static int cpuid_class_simple_device_add(int i) 
+{
+	int err = 0;
+	struct class_device *class_err;
+
+	class_err = class_simple_device_add(cpuid_class, MKDEV(CPUID_MAJOR, i), NULL, "cpu%d",i);
+	if (IS_ERR(class_err)) {
+		err = PTR_ERR(class_err);
+	}
+	return err;
+}
+static int __devinit cpuid_class_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
+{
+	unsigned int cpu = (unsigned long)hcpu;
+
+	switch(action) {
+	case CPU_ONLINE:
+		cpuid_class_simple_device_add(cpu);
+		break;
+	case CPU_DEAD:
+		cpuid_class_simple_device_remove();
+		break;
+	}
+	return NOTIFY_OK;
+}
+
+static struct notifier_block cpuid_class_cpu_notifier =
+{
+	.notifier_call = cpuid_class_cpu_callback,
+};
+
 int __init cpuid_init(void)
 {
 	int i, err = 0;
-	struct class_device *class_err;
 	i = 0;
 
 	if (register_chrdev(CPUID_MAJOR, "cpu/cpuid", &cpuid_fops)) {
@@ -174,19 +214,17 @@
 		goto out_chrdev;
 	}
 	for_each_online_cpu(i) {
-		class_err = class_simple_device_add(cpuid_class, MKDEV(CPUID_MAJOR, i), NULL, "cpu%d",i);
-		if (IS_ERR(class_err)) {
-			err = PTR_ERR(class_err);
+		err = cpuid_class_simple_device_add(i);
+		if (err != 0) 
 			goto out_class;
-		}
 	}
+	register_cpu_notifier(&cpuid_class_cpu_notifier);
+
 	err = 0;
 	goto out;
 
 out_class:
-	i = 0;
-	for_each_online_cpu(i)
-		class_simple_device_remove(MKDEV(CPUID_MAJOR, i));
+	cpuid_class_simple_device_remove();
 	class_simple_destroy(cpuid_class);
 out_chrdev:
 	unregister_chrdev(CPUID_MAJOR, "cpu/cpuid");	
@@ -196,11 +234,10 @@
 
 void __exit cpuid_exit(void)
 {
-	int i = 0;
-	for_each_online_cpu(i)
-		class_simple_device_remove(MKDEV(CPUID_MAJOR, i));
+	cpuid_class_simple_device_remove();
 	class_simple_destroy(cpuid_class);
 	unregister_chrdev(CPUID_MAJOR, "cpu/cpuid");
+	unregister_cpu_notifier(&cpuid_class_cpu_notifier);
 }
 
 module_init(cpuid_init);


  reply	other threads:[~2004-06-22 18:07 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-22 17:19 [BK PATCH] Driver Core patches for 2.6.7 Greg KH
2004-06-22 17:41 ` [PATCH] " Greg KH
2004-06-22 17:41   ` Greg KH
2004-06-22 17:41     ` Greg KH
2004-06-22 17:41       ` Greg KH
2004-06-22 17:41         ` Greg KH
2004-06-22 17:41           ` Greg KH
2004-06-22 17:41             ` Greg KH
2004-06-22 17:41               ` Greg KH
2004-06-22 17:41                 ` Greg KH
2004-06-22 17:41                   ` Greg KH
2004-06-22 17:41                     ` Greg KH
2004-06-22 17:41                       ` Greg KH
2004-06-22 17:41                         ` Greg KH
2004-06-22 17:41                           ` Greg KH
2004-06-22 17:41                             ` Greg KH
2004-06-22 17:41                               ` Greg KH [this message]
2004-06-22 17:41                                 ` Greg KH
2004-06-22 17:41                                   ` Greg KH
2004-06-22 17:41                                     ` Greg KH
2004-06-22 17:41                                       ` Greg KH
2004-06-22 17:41                                         ` Greg KH
2004-06-22 17:41                                           ` Greg KH
2004-06-22 17:41                                             ` Greg KH
2004-06-22 17:41                                               ` Greg KH
2004-06-22 17:41                                                 ` Greg KH
2004-06-22 17:41                                                   ` Greg KH
2004-06-22 17:41                                                     ` Greg KH
2004-06-22 17:41                                                       ` Greg KH
2004-06-22 17:41                                                         ` Greg KH
2004-06-22 17:41                                                           ` Greg KH
2004-06-22 17:41                                                             ` Greg KH
2004-06-22 17:41                                                               ` Greg KH
2004-06-22 17:41                                                                 ` Greg KH
2004-06-22 17:41                                                                   ` Greg KH
2004-06-22 17:41                                                                     ` Greg KH
2004-06-22 23:21         ` Dmitry Torokhov
2004-06-22 23:31           ` Greg KH
2004-06-22 23:44             ` Dmitry Torokhov
2004-06-22 23:51               ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1087926110895@kroah.com \
    --to=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox