]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - kernel/stop_machine.c
[CPUFREQ] fix show_trans_table
[linux-2.6-omap-h63xx.git] / kernel / stop_machine.c
index 2c0aacc37c5513b0a3898f49e937683501f66ae2..0101aeef7ed79fbd62aba8d1043976a110cf1f6e 100644 (file)
@@ -1,12 +1,16 @@
-#include <linux/stop_machine.h>
-#include <linux/kthread.h>
-#include <linux/sched.h>
+/* Copyright 2005 Rusty Russell rusty@rustcorp.com.au IBM Corporation.
+ * GPL v2 and any later version.
+ */
 #include <linux/cpu.h>
 #include <linux/err.h>
-#include <linux/syscalls.h>
 #include <linux/kthread.h>
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <linux/stop_machine.h>
+#include <linux/syscalls.h>
+#include <linux/interrupt.h>
+
 #include <asm/atomic.h>
-#include <asm/semaphore.h>
 #include <asm/uaccess.h>
 
 /* Since we effect priority and affinity (both of which are visible
@@ -24,13 +28,14 @@ enum stopmachine_state {
 static enum stopmachine_state stopmachine_state;
 static unsigned int stopmachine_num_threads;
 static atomic_t stopmachine_thread_ack;
-static DECLARE_MUTEX(stopmachine_mutex);
 
-static int stopmachine(void *unused)
+static int stopmachine(void *cpu)
 {
        int irqs_disabled = 0;
        int prepared = 0;
 
+       set_cpus_allowed_ptr(current, &cpumask_of_cpu((int)(long)cpu));
+
        /* Ack: we are alive */
        smp_mb(); /* Theoretically the ack = 0 might not be on this CPU yet. */
        atomic_inc(&stopmachine_thread_ack);
@@ -40,6 +45,7 @@ static int stopmachine(void *unused)
                if (stopmachine_state == STOPMACHINE_DISABLE_IRQ 
                    && !irqs_disabled) {
                        local_irq_disable();
+                       hard_irq_disable();
                        irqs_disabled = 1;
                        /* Ack: irqs disabled. */
                        smp_mb(); /* Must read state first. */
@@ -84,28 +90,18 @@ static void stopmachine_set_state(enum stopmachine_state state)
 
 static int stop_machine(void)
 {
-       int ret = 0;
-       unsigned int i;
-       struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 };
-
-       /* One high-prio thread per cpu.  We'll do this one. */
-       sched_setscheduler(current, SCHED_FIFO, &param);
+       int i, ret = 0;
 
        atomic_set(&stopmachine_thread_ack, 0);
        stopmachine_num_threads = 0;
        stopmachine_state = STOPMACHINE_WAIT;
 
        for_each_online_cpu(i) {
-               struct task_struct *tsk;
                if (i == raw_smp_processor_id())
                        continue;
-               tsk = kthread_create(stopmachine, NULL, "stopmachine");
-               if (IS_ERR(tsk)) {
-                       ret = PTR_ERR(tsk);
+               ret = kernel_thread(stopmachine, (void *)(long)i,CLONE_KERNEL);
+               if (ret < 0)
                        break;
-               }
-               kthread_bind(tsk, i);
-               wake_up_process(tsk);
                stopmachine_num_threads++;
        }
 
@@ -116,7 +112,6 @@ static int stop_machine(void)
        /* If some failed, kill them all. */
        if (ret < 0) {
                stopmachine_set_state(STOPMACHINE_EXIT);
-               up(&stopmachine_mutex);
                return ret;
        }
 
@@ -126,6 +121,7 @@ static int stop_machine(void)
 
        /* Make them disable irqs. */
        local_irq_disable();
+       hard_irq_disable();
        stopmachine_set_state(STOPMACHINE_DISABLE_IRQ);
 
        return 0;
@@ -138,8 +134,7 @@ static void restart_machine(void)
        preempt_enable_no_resched();
 }
 
-struct stop_machine_data
-{
+struct stop_machine_data {
        int (*fn)(void *);
        void *data;
        struct completion done;
@@ -172,6 +167,7 @@ static int do_stop(void *_smdata)
 struct task_struct *__stop_machine_run(int (*fn)(void *), void *data,
                                       unsigned int cpu)
 {
+       static DEFINE_MUTEX(stopmachine_mutex);
        struct stop_machine_data smdata;
        struct task_struct *p;
 
@@ -179,7 +175,7 @@ struct task_struct *__stop_machine_run(int (*fn)(void *), void *data,
        smdata.data = data;
        init_completion(&smdata.done);
 
-       down(&stopmachine_mutex);
+       mutex_lock(&stopmachine_mutex);
 
        /* If they don't care which CPU fn runs on, bind to any online one. */
        if (cpu == NR_CPUS)
@@ -187,11 +183,15 @@ struct task_struct *__stop_machine_run(int (*fn)(void *), void *data,
 
        p = kthread_create(do_stop, &smdata, "kstopmachine");
        if (!IS_ERR(p)) {
+               struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 };
+
+               /* One high-prio thread per cpu.  We'll do this one. */
+               sched_setscheduler(p, SCHED_FIFO, &param);
                kthread_bind(p, cpu);
                wake_up_process(p);
                wait_for_completion(&smdata.done);
        }
-       up(&stopmachine_mutex);
+       mutex_unlock(&stopmachine_mutex);
        return p;
 }
 
@@ -201,13 +201,14 @@ int stop_machine_run(int (*fn)(void *), void *data, unsigned int cpu)
        int ret;
 
        /* No CPUs can come up or down during this. */
-       lock_cpu_hotplug();
+       get_online_cpus();
        p = __stop_machine_run(fn, data, cpu);
        if (!IS_ERR(p))
                ret = kthread_stop(p);
        else
                ret = PTR_ERR(p);
-       unlock_cpu_hotplug();
+       put_online_cpus();
 
        return ret;
 }
+EXPORT_SYMBOL_GPL(stop_machine_run);