Commit 7851ac39 authored by Hanna V. Linder's avatar Hanna V. Linder Committed by Greg Kroah-Hartman

[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: default avatarHanna Linder <hannal@us.ibm.com>
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent 03769bf6
...@@ -37,6 +37,8 @@ ...@@ -37,6 +37,8 @@
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/cpu.h>
#include <linux/notifier.h>
#include <asm/processor.h> #include <asm/processor.h>
#include <asm/msr.h> #include <asm/msr.h>
...@@ -156,10 +158,48 @@ static struct file_operations cpuid_fops = { ...@@ -156,10 +158,48 @@ static struct file_operations cpuid_fops = {
.open = cpuid_open, .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 __init cpuid_init(void)
{ {
int i, err = 0; int i, err = 0;
struct class_device *class_err;
i = 0; i = 0;
if (register_chrdev(CPUID_MAJOR, "cpu/cpuid", &cpuid_fops)) { if (register_chrdev(CPUID_MAJOR, "cpu/cpuid", &cpuid_fops)) {
...@@ -174,19 +214,17 @@ int __init cpuid_init(void) ...@@ -174,19 +214,17 @@ int __init cpuid_init(void)
goto out_chrdev; goto out_chrdev;
} }
for_each_online_cpu(i) { for_each_online_cpu(i) {
class_err = class_simple_device_add(cpuid_class, MKDEV(CPUID_MAJOR, i), NULL, "cpu%d",i); err = cpuid_class_simple_device_add(i);
if (IS_ERR(class_err)) { if (err != 0)
err = PTR_ERR(class_err);
goto out_class; goto out_class;
}
} }
register_cpu_notifier(&cpuid_class_cpu_notifier);
err = 0; err = 0;
goto out; goto out;
out_class: out_class:
i = 0; cpuid_class_simple_device_remove();
for_each_online_cpu(i)
class_simple_device_remove(MKDEV(CPUID_MAJOR, i));
class_simple_destroy(cpuid_class); class_simple_destroy(cpuid_class);
out_chrdev: out_chrdev:
unregister_chrdev(CPUID_MAJOR, "cpu/cpuid"); unregister_chrdev(CPUID_MAJOR, "cpu/cpuid");
...@@ -196,11 +234,10 @@ int __init cpuid_init(void) ...@@ -196,11 +234,10 @@ int __init cpuid_init(void)
void __exit cpuid_exit(void) void __exit cpuid_exit(void)
{ {
int i = 0; cpuid_class_simple_device_remove();
for_each_online_cpu(i)
class_simple_device_remove(MKDEV(CPUID_MAJOR, i));
class_simple_destroy(cpuid_class); class_simple_destroy(cpuid_class);
unregister_chrdev(CPUID_MAJOR, "cpu/cpuid"); unregister_chrdev(CPUID_MAJOR, "cpu/cpuid");
unregister_cpu_notifier(&cpuid_class_cpu_notifier);
} }
module_init(cpuid_init); module_init(cpuid_init);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment