[PATCH] aio compat patches
[linux-2.6/history.git] / kernel / cpu.c
blob4c0ada2b99aef932a71a6ed9ee74175b69c9d322
1 /* CPU control.
2 * (C) 2001 Rusty Russell
3 * This code is licenced under the GPL.
4 */
5 #include <linux/proc_fs.h>
6 #include <linux/smp.h>
7 #include <linux/init.h>
8 #include <linux/notifier.h>
9 #include <linux/sched.h>
10 #include <linux/unistd.h>
11 #include <asm/semaphore.h>
13 /* This protects CPUs going up and down... */
14 DECLARE_MUTEX(cpucontrol);
16 static struct notifier_block *cpu_chain = NULL;
18 /* Need to know about CPUs going up/down? */
19 int register_cpu_notifier(struct notifier_block *nb)
21 return notifier_chain_register(&cpu_chain, nb);
24 void unregister_cpu_notifier(struct notifier_block *nb)
26 notifier_chain_unregister(&cpu_chain,nb);
29 int __devinit cpu_up(unsigned int cpu)
31 int ret;
32 void *hcpu = (void *)(long)cpu;
34 if ((ret = down_interruptible(&cpucontrol)) != 0)
35 return ret;
37 if (cpu_online(cpu)) {
38 ret = -EINVAL;
39 goto out;
41 ret = notifier_call_chain(&cpu_chain, CPU_UP_PREPARE, hcpu);
42 if (ret == NOTIFY_BAD) {
43 printk("%s: attempt to bring up CPU %u failed\n",
44 __FUNCTION__, cpu);
45 ret = -EINVAL;
46 goto out_notify;
49 /* Arch-specific enabling code. */
50 ret = __cpu_up(cpu);
51 if (ret != 0)
52 goto out_notify;
53 if (!cpu_online(cpu))
54 BUG();
56 /* Now call notifier in preparation. */
57 printk("CPU %u IS NOW UP!\n", cpu);
58 notifier_call_chain(&cpu_chain, CPU_ONLINE, hcpu);
60 out_notify:
61 if (ret != 0)
62 notifier_call_chain(&cpu_chain, CPU_UP_CANCELED, hcpu);
63 out:
64 up(&cpucontrol);
65 return ret;