aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/xen/cpu_hotplug.c
diff options
context:
space:
mode:
authorAlex Nixon <alex.nixon@citrix.com>2008-08-22 06:52:15 -0400
committerIngo Molnar <mingo@elte.hu>2008-08-25 05:25:14 -0400
commitd68d82afd4c88e25763b23cd9cd4974573a3706f (patch)
tree42a3fb93a5cef70db7ad01fda1ed0dc68dbe6110 /drivers/xen/cpu_hotplug.c
parent8227dce7dc2cfdcc28ee0eadfb482a7ee77fba03 (diff)
xen: implement CPU hotplugging
Note the changes from 2.6.18-xen CPU hotplugging: A vcpu_down request from the remote admin via Xenbus both hotunplugs the CPU, and disables it by removing it from the cpu_present map, and removing its entry in /sys. A vcpu_up request from the remote admin only re-enables the CPU, and does not immediately bring the CPU up. A udev event is emitted, which can be caught by the user if he wishes to automatically re-up CPUs when available, or implement a more complex policy. Signed-off-by: Alex Nixon <alex.nixon@citrix.com> Acked-by: Jeremy Fitzhardinge <jeremy@goop.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'drivers/xen/cpu_hotplug.c')
-rw-r--r--drivers/xen/cpu_hotplug.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/drivers/xen/cpu_hotplug.c b/drivers/xen/cpu_hotplug.c
new file mode 100644
index 000000000000..1bc003536cdb
--- /dev/null
+++ b/drivers/xen/cpu_hotplug.c
@@ -0,0 +1,90 @@
1#include <linux/notifier.h>
2
3#include <xen/xenbus.h>
4
5#include <asm-x86/xen/hypervisor.h>
6#include <asm/cpu.h>
7
8static void enable_hotplug_cpu(int cpu)
9{
10 if (!cpu_present(cpu))
11 arch_register_cpu(cpu);
12
13 cpu_set(cpu, cpu_present_map);
14}
15
16static void disable_hotplug_cpu(int cpu)
17{
18 if (cpu_present(cpu))
19 arch_unregister_cpu(cpu);
20
21 cpu_clear(cpu, cpu_present_map);
22}
23
24static void vcpu_hotplug(unsigned int cpu)
25{
26 int err;
27 char dir[32], state[32];
28
29 if (!cpu_possible(cpu))
30 return;
31
32 sprintf(dir, "cpu/%u", cpu);
33 err = xenbus_scanf(XBT_NIL, dir, "availability", "%s", state);
34 if (err != 1) {
35 printk(KERN_ERR "XENBUS: Unable to read cpu state\n");
36 return;
37 }
38
39 if (strcmp(state, "online") == 0) {
40 enable_hotplug_cpu(cpu);
41 } else if (strcmp(state, "offline") == 0) {
42 (void)cpu_down(cpu);
43 disable_hotplug_cpu(cpu);
44 } else {
45 printk(KERN_ERR "XENBUS: unknown state(%s) on CPU%d\n",
46 state, cpu);
47 }
48}
49
50static void handle_vcpu_hotplug_event(struct xenbus_watch *watch,
51 const char **vec, unsigned int len)
52{
53 unsigned int cpu;
54 char *cpustr;
55 const char *node = vec[XS_WATCH_PATH];
56
57 cpustr = strstr(node, "cpu/");
58 if (cpustr != NULL) {
59 sscanf(cpustr, "cpu/%u", &cpu);
60 vcpu_hotplug(cpu);
61 }
62}
63
64static int setup_cpu_watcher(struct notifier_block *notifier,
65 unsigned long event, void *data)
66{
67 static struct xenbus_watch cpu_watch = {
68 .node = "cpu",
69 .callback = handle_vcpu_hotplug_event};
70
71 (void)register_xenbus_watch(&cpu_watch);
72
73 return NOTIFY_DONE;
74}
75
76static int __init setup_vcpu_hotplug_event(void)
77{
78 static struct notifier_block xsn_cpu = {
79 .notifier_call = setup_cpu_watcher };
80
81 if (!is_running_on_xen())
82 return -ENODEV;
83
84 register_xenstore_notifier(&xsn_cpu);
85
86 return 0;
87}
88
89arch_initcall(setup_vcpu_hotplug_event);
90