Hi,

this patch creates a new file: cpuhotplug.c.  The content is the xenbus 
handler part of smpboot.c.  The purpose is to be able to share this part with 
other architectures.

Tested by compiling on i386.

Tristan.
# HG changeset patch
# User [EMAIL PROTECTED]
# Node ID 3aa29135597a5c85464dfb85b69217aeae6465fd
# Parent  14717dedba028c7e98bff1f67c6e9e25b42b5661
Xenbus vcpu hotplug control moved to cpuhotplug.c
So that this code can be easily shared with other architecture.

Signed-off-by: Tristan Gingold <[EMAIL PROTECTED]>

diff -r 14717dedba02 -r 3aa29135597a linux-2.6-xen-sparse/drivers/xen/core/Makefile
--- a/linux-2.6-xen-sparse/drivers/xen/core/Makefile	Sun May 21 20:15:58 2006 +0100
+++ b/linux-2.6-xen-sparse/drivers/xen/core/Makefile	Mon May 22 09:53:42 2006 +0200
@@ -7,5 +7,6 @@ obj-$(CONFIG_PROC_FS) += xen_proc.o
 obj-$(CONFIG_PROC_FS) += xen_proc.o
 obj-$(CONFIG_NET)     += skbuff.o
 obj-$(CONFIG_SMP)     += smpboot.o
+obj-$(CONFIG_HOTPLUG_CPU) += cpuhotplug.o
 obj-$(CONFIG_SYSFS)   += hypervisor_sysfs.o
 obj-$(CONFIG_XEN_SYSFS) += xen_sysfs.o
diff -r 14717dedba02 -r 3aa29135597a linux-2.6-xen-sparse/drivers/xen/core/smpboot.c
--- a/linux-2.6-xen-sparse/drivers/xen/core/smpboot.c	Sun May 21 20:15:58 2006 +0100
+++ b/linux-2.6-xen-sparse/drivers/xen/core/smpboot.c	Mon May 22 09:53:42 2006 +0200
@@ -83,7 +83,7 @@ unsigned int maxcpus = NR_CPUS;
  * Set of CPUs that remote admin software will allow us to bring online.
  * Notified to us via xenbus.
  */
-static cpumask_t xenbus_allowed_cpumask;
+cpumask_t xenbus_allowed_cpumask;
 
 /* Set of CPUs that local admin will allow us to bring online. */
 static cpumask_t local_allowed_cpumask = CPU_MASK_ALL;
@@ -342,6 +342,7 @@ static int local_cpu_hotplug_request(voi
 }
 
 #ifdef CONFIG_HOTPLUG_CPU
+extern void vcpu_hotplug(unsigned int cpu);
 
 /*
  * Initialize cpu_present_map late to skip SMP boot code in init/main.c.
@@ -354,46 +355,6 @@ static int __init initialize_cpu_present
 	return 0;
 }
 core_initcall(initialize_cpu_present_map);
-
-static void vcpu_hotplug(unsigned int cpu)
-{
-	int err;
-	char dir[32], state[32];
-
-	if ((cpu >= NR_CPUS) || !cpu_possible(cpu))
-		return;
-
-	sprintf(dir, "cpu/%d", cpu);
-	err = xenbus_scanf(XBT_NULL, dir, "availability", "%s", state);
-	if (err != 1) {
-		printk(KERN_ERR "XENBUS: Unable to read cpu state\n");
-		return;
-	}
-
-	if (strcmp(state, "online") == 0) {
-		cpu_set(cpu, xenbus_allowed_cpumask);
-		(void)cpu_up(cpu);
-	} else if (strcmp(state, "offline") == 0) {
-		cpu_clear(cpu, xenbus_allowed_cpumask);
-		(void)cpu_down(cpu);
-	} else {
-		printk(KERN_ERR "XENBUS: unknown state(%s) on CPU%d\n",
-		       state, cpu);
-	}
-}
-
-static void handle_vcpu_hotplug_event(
-	struct xenbus_watch *watch, const char **vec, unsigned int len)
-{
-	int cpu;
-	char *cpustr;
-	const char *node = vec[XS_WATCH_PATH];
-
-	if ((cpustr = strstr(node, "cpu/")) != NULL) {
-		sscanf(cpustr, "cpu/%d", &cpu);
-		vcpu_hotplug(cpu);
-	}
-}
 
 static int smpboot_cpu_notify(struct notifier_block *notifier,
 			      unsigned long action, void *hcpu)
@@ -411,41 +372,17 @@ static int smpboot_cpu_notify(struct not
 	return NOTIFY_OK;
 }
 
-static int setup_cpu_watcher(struct notifier_block *notifier,
-			      unsigned long event, void *data)
-{
-	int i;
-
-	static struct xenbus_watch cpu_watch = {
-		.node = "cpu",
-		.callback = handle_vcpu_hotplug_event,
-		.flags = XBWF_new_thread };
-	(void)register_xenbus_watch(&cpu_watch);
-
-	if (!(xen_start_info->flags & SIF_INITDOMAIN)) {
-		for_each_cpu(i)
-			vcpu_hotplug(i);
-		printk(KERN_INFO "Brought up %ld CPUs\n",
-		       (long)num_online_cpus());
-	}
-
-	return NOTIFY_DONE;
-}
-
-static int __init setup_vcpu_hotplug_event(void)
+static int __init setup_vcpu_hotplug_notifier(void)
 {
 	static struct notifier_block hotplug_cpu = {
 		.notifier_call = smpboot_cpu_notify };
-	static struct notifier_block xsn_cpu = {
-		.notifier_call = setup_cpu_watcher };
 
 	register_cpu_notifier(&hotplug_cpu);
-	register_xenstore_notifier(&xsn_cpu);
-
-	return 0;
-}
-
-arch_initcall(setup_vcpu_hotplug_event);
+
+	return 0;
+}
+
+arch_initcall(setup_vcpu_hotplug_notifier);
 
 int smp_suspend(void)
 {
diff -r 14717dedba02 -r 3aa29135597a linux-2.6-xen-sparse/drivers/xen/core/cpuhotplug.c
--- /dev/null	Thu Jan  1 00:00:00 1970 +0000
+++ b/linux-2.6-xen-sparse/drivers/xen/core/cpuhotplug.c	Mon May 22 09:53:42 2006 +0200
@@ -0,0 +1,93 @@
+#include <linux/module.h>
+#include <linux/config.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/smp_lock.h>
+#include <linux/notifier.h>
+#include <linux/cpu.h>
+#include <linux/percpu.h>
+#include <xen/evtchn.h>
+#include <xen/interface/vcpu.h>
+#include <xen/xenbus.h>
+#include <asm/hypervisor.h>
+
+#ifdef CONFIG_HOTPLUG_CPU
+extern cpumask_t xenbus_allowed_cpumask;
+
+void vcpu_hotplug(unsigned int cpu)
+{
+	int err;
+	char dir[32], state[32];
+
+	if ((cpu >= NR_CPUS) || !cpu_possible(cpu))
+		return;
+
+	sprintf(dir, "cpu/%d", cpu);
+	err = xenbus_scanf(XBT_NULL, dir, "availability", "%s", state);
+	if (err != 1) {
+		printk(KERN_ERR "XENBUS: Unable to read cpu state\n");
+		return;
+	}
+
+	if (strcmp(state, "online") == 0) {
+		cpu_set(cpu, xenbus_allowed_cpumask);
+		(void)cpu_up(cpu);
+	} else if (strcmp(state, "offline") == 0) {
+		cpu_clear(cpu, xenbus_allowed_cpumask);
+		(void)cpu_down(cpu);
+	} else {
+		printk(KERN_ERR "XENBUS: unknown state(%s) on CPU%d\n",
+		       state, cpu);
+	}
+}
+
+static void handle_vcpu_hotplug_event(
+	struct xenbus_watch *watch, const char **vec, unsigned int len)
+{
+	int cpu;
+	char *cpustr;
+	const char *node = vec[XS_WATCH_PATH];
+
+	if ((cpustr = strstr(node, "cpu/")) != NULL) {
+		sscanf(cpustr, "cpu/%d", &cpu);
+		vcpu_hotplug(cpu);
+	}
+}
+
+static int setup_cpu_watcher(struct notifier_block *notifier,
+			      unsigned long event, void *data)
+{
+	int i;
+
+	static struct xenbus_watch cpu_watch = {
+		.node = "cpu",
+		.callback = handle_vcpu_hotplug_event,
+		.flags = XBWF_new_thread };
+	(void)register_xenbus_watch(&cpu_watch);
+
+	if (!(xen_start_info->flags & SIF_INITDOMAIN)) {
+		for_each_cpu(i)
+			vcpu_hotplug(i);
+		printk(KERN_INFO "Brought up %ld CPUs\n",
+		       (long)num_online_cpus());
+	}
+
+	return NOTIFY_DONE;
+}
+
+static int __init setup_vcpu_hotplug_event(void)
+{
+	static struct notifier_block xsn_cpu = {
+		.notifier_call = setup_cpu_watcher };
+
+	if (!is_running_on_xen())
+		return -ENODEV;
+
+	register_xenstore_notifier(&xsn_cpu);
+
+	return 0;
+}
+
+arch_initcall(setup_vcpu_hotplug_event);
+#endif
_______________________________________________
Xen-ia64-devel mailing list
Xen-ia64-devel@lists.xensource.com
http://lists.xensource.com/xen-ia64-devel

Reply via email to