1 #include <linux/notifier.h>
3 #include <xen/xenbus.h>
5 #include <asm/xen/hypervisor.h>
8 static void enable_hotplug_cpu(int cpu)
10 if (!cpu_present(cpu))
11 arch_register_cpu(cpu);
13 set_cpu_present(cpu, true);
16 static void disable_hotplug_cpu(int cpu)
19 arch_unregister_cpu(cpu);
21 set_cpu_present(cpu, false);
24 static int vcpu_online(unsigned int cpu)
27 char dir[32], state[32];
29 sprintf(dir, "cpu/%u", cpu);
30 err = xenbus_scanf(XBT_NIL, dir, "availability", "%s", state);
32 printk(KERN_ERR "XENBUS: Unable to read cpu state\n");
36 if (strcmp(state, "online") == 0)
38 else if (strcmp(state, "offline") == 0)
41 printk(KERN_ERR "XENBUS: unknown state(%s) on CPU%d\n", state, cpu);
44 static void vcpu_hotplug(unsigned int cpu)
46 if (!cpu_possible(cpu))
49 switch (vcpu_online(cpu)) {
51 enable_hotplug_cpu(cpu);
55 disable_hotplug_cpu(cpu);
62 static void handle_vcpu_hotplug_event(struct xenbus_watch *watch,
63 const char **vec, unsigned int len)
67 const char *node = vec[XS_WATCH_PATH];
69 cpustr = strstr(node, "cpu/");
71 sscanf(cpustr, "cpu/%u", &cpu);
76 static int setup_cpu_watcher(struct notifier_block *notifier,
77 unsigned long event, void *data)
80 static struct xenbus_watch cpu_watch = {
82 .callback = handle_vcpu_hotplug_event};
84 (void)register_xenbus_watch(&cpu_watch);
86 for_each_possible_cpu(cpu) {
87 if (vcpu_online(cpu) == 0) {
89 cpu_clear(cpu, cpu_present_map);
96 static int __init setup_vcpu_hotplug_event(void)
98 static struct notifier_block xsn_cpu = {
99 .notifier_call = setup_cpu_watcher };
101 if (!xen_pv_domain())
104 register_xenstore_notifier(&xsn_cpu);
109 arch_initcall(setup_vcpu_hotplug_event);