Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / kernel / cpu.c
index 628f4cc..fe2b8d0 100644 (file)
 #include <asm/semaphore.h>
 
 /* This protects CPUs going up and down... */
-DECLARE_MUTEX(cpucontrol);
+static DECLARE_MUTEX(cpucontrol);
 
-static struct notifier_block *cpu_chain;
+static BLOCKING_NOTIFIER_HEAD(cpu_chain);
 
-/* Need to know about CPUs going up/down? */
-int register_cpu_notifier(struct notifier_block *nb)
+#ifdef CONFIG_HOTPLUG_CPU
+static struct task_struct *lock_cpu_hotplug_owner;
+static int lock_cpu_hotplug_depth;
+
+static int __lock_cpu_hotplug(int interruptible)
 {
-       int ret;
+       int ret = 0;
+
+       if (lock_cpu_hotplug_owner != current) {
+               if (interruptible)
+                       ret = down_interruptible(&cpucontrol);
+               else
+                       down(&cpucontrol);
+       }
+
+       /*
+        * Set only if we succeed in locking
+        */
+       if (!ret) {
+               lock_cpu_hotplug_depth++;
+               lock_cpu_hotplug_owner = current;
+       }
 
-       if ((ret = down_interruptible(&cpucontrol)) != 0)
-               return ret;
-       ret = notifier_chain_register(&cpu_chain, nb);
-       up(&cpucontrol);
        return ret;
 }
+
+void lock_cpu_hotplug(void)
+{
+       __lock_cpu_hotplug(0);
+}
+EXPORT_SYMBOL_GPL(lock_cpu_hotplug);
+
+void unlock_cpu_hotplug(void)
+{
+       if (--lock_cpu_hotplug_depth == 0) {
+               lock_cpu_hotplug_owner = NULL;
+               up(&cpucontrol);
+       }
+}
+EXPORT_SYMBOL_GPL(unlock_cpu_hotplug);
+
+int lock_cpu_hotplug_interruptible(void)
+{
+       return __lock_cpu_hotplug(1);
+}
+EXPORT_SYMBOL_GPL(lock_cpu_hotplug_interruptible);
+#endif /* CONFIG_HOTPLUG_CPU */
+
+/* Need to know about CPUs going up/down? */
+int register_cpu_notifier(struct notifier_block *nb)
+{
+       return blocking_notifier_chain_register(&cpu_chain, nb);
+}
 EXPORT_SYMBOL(register_cpu_notifier);
 
 void unregister_cpu_notifier(struct notifier_block *nb)
 {
-       down(&cpucontrol);
-       notifier_chain_unregister(&cpu_chain, nb);
-       up(&cpucontrol);
+       blocking_notifier_chain_unregister(&cpu_chain, nb);
 }
 EXPORT_SYMBOL(unregister_cpu_notifier);
 
@@ -63,19 +103,15 @@ static int take_cpu_down(void *unused)
 {
        int err;
 
-       /* Take offline: makes arch_cpu_down somewhat easier. */
-       cpu_clear(smp_processor_id(), cpu_online_map);
-
        /* Ensure this CPU doesn't handle any more interrupts. */
        err = __cpu_disable();
        if (err < 0)
-               cpu_set(smp_processor_id(), cpu_online_map);
-       else
-               /* Force idle task to run as soon as we yield: it should
-                  immediately notice cpu is offline and die quickly. */
-               sched_idle_next();
+               return err;
 
-       return err;
+       /* Force idle task to run as soon as we yield: it should
+          immediately notice cpu is offline and die quickly. */
+       sched_idle_next();
+       return 0;
 }
 
 int cpu_down(unsigned int cpu)
@@ -97,7 +133,7 @@ int cpu_down(unsigned int cpu)
                goto out;
        }
 
-       err = notifier_call_chain(&cpu_chain, CPU_DOWN_PREPARE,
+       err = blocking_notifier_call_chain(&cpu_chain, CPU_DOWN_PREPARE,
                                                (void *)(long)cpu);
        if (err == NOTIFY_BAD) {
                printk("%s: attempt to take down CPU %u failed\n",
@@ -115,7 +151,7 @@ int cpu_down(unsigned int cpu)
        p = __stop_machine_run(take_cpu_down, NULL, cpu);
        if (IS_ERR(p)) {
                /* CPU didn't die: tell everyone.  Can't complain. */
-               if (notifier_call_chain(&cpu_chain, CPU_DOWN_FAILED,
+               if (blocking_notifier_call_chain(&cpu_chain, CPU_DOWN_FAILED,
                                (void *)(long)cpu) == NOTIFY_BAD)
                        BUG();
 
@@ -138,8 +174,8 @@ int cpu_down(unsigned int cpu)
        put_cpu();
 
        /* CPU is completely dead: tell everyone.  Too late to complain. */
-       if (notifier_call_chain(&cpu_chain, CPU_DEAD, (void *)(long)cpu)
-           == NOTIFY_BAD)
+       if (blocking_notifier_call_chain(&cpu_chain, CPU_DEAD,
+                       (void *)(long)cpu) == NOTIFY_BAD)
                BUG();
 
        check_for_tasks(cpu);
@@ -159,14 +195,15 @@ int __devinit cpu_up(unsigned int cpu)
        int ret;
        void *hcpu = (void *)(long)cpu;
 
-       if ((ret = down_interruptible(&cpucontrol)) != 0)
+       if ((ret = lock_cpu_hotplug_interruptible()) != 0)
                return ret;
 
        if (cpu_online(cpu) || !cpu_present(cpu)) {
                ret = -EINVAL;
                goto out;
        }
-       ret = notifier_call_chain(&cpu_chain, CPU_UP_PREPARE, hcpu);
+
+       ret = blocking_notifier_call_chain(&cpu_chain, CPU_UP_PREPARE, hcpu);
        if (ret == NOTIFY_BAD) {
                printk("%s: attempt to bring up CPU %u failed\n",
                                __FUNCTION__, cpu);
@@ -178,16 +215,16 @@ int __devinit cpu_up(unsigned int cpu)
        ret = __cpu_up(cpu);
        if (ret != 0)
                goto out_notify;
-       if (!cpu_online(cpu))
-               BUG();
+       BUG_ON(!cpu_online(cpu));
 
        /* Now call notifier in preparation. */
-       notifier_call_chain(&cpu_chain, CPU_ONLINE, hcpu);
+       blocking_notifier_call_chain(&cpu_chain, CPU_ONLINE, hcpu);
 
 out_notify:
        if (ret != 0)
-               notifier_call_chain(&cpu_chain, CPU_UP_CANCELED, hcpu);
+               blocking_notifier_call_chain(&cpu_chain,
+                               CPU_UP_CANCELED, hcpu);
 out:
-       up(&cpucontrol);
+       unlock_cpu_hotplug();
        return ret;
 }