]> err.no Git - linux-2.6/blobdiff - arch/ia64/kernel/smp.c
Merge branch 'for-2.6.26' of master.kernel.org:/pub/scm/linux/kernel/git/jwboyer...
[linux-2.6] / arch / ia64 / kernel / smp.c
index 9f72838db26ec52c8c0fce68f31e7f6c8b032dbb..983296f1c813a3baeb34435258b9ff8af737a172 100644 (file)
@@ -98,8 +98,33 @@ unlock_ipi_calllock(void)
        spin_unlock_irq(&call_lock);
 }
 
+static inline void
+handle_call_data(void)
+{
+       struct call_data_struct *data;
+       void (*func)(void *info);
+       void *info;
+       int wait;
+
+       /* release the 'pointer lock' */
+       data = (struct call_data_struct *)call_data;
+       func = data->func;
+       info = data->info;
+       wait = data->wait;
+
+       mb();
+       atomic_inc(&data->started);
+       /* At this point the structure may be gone unless wait is true. */
+       (*func)(info);
+
+       /* Notify the sending CPU that the task is done. */
+       mb();
+       if (wait)
+               atomic_inc(&data->finished);
+}
+
 static void
-stop_this_cpu (void)
+stop_this_cpu(void)
 {
        /*
         * Remove this CPU:
@@ -138,44 +163,21 @@ handle_IPI (int irq, void *dev_id)
                        ops &= ~(1 << which);
 
                        switch (which) {
-                             case IPI_CALL_FUNC:
-                             {
-                                     struct call_data_struct *data;
-                                     void (*func)(void *info);
-                                     void *info;
-                                     int wait;
-
-                                     /* release the 'pointer lock' */
-                                     data = (struct call_data_struct *) call_data;
-                                     func = data->func;
-                                     info = data->info;
-                                     wait = data->wait;
-
-                                     mb();
-                                     atomic_inc(&data->started);
-                                     /*
-                                      * At this point the structure may be gone unless
-                                      * wait is true.
-                                      */
-                                     (*func)(info);
-
-                                     /* Notify the sending CPU that the task is done.  */
-                                     mb();
-                                     if (wait)
-                                             atomic_inc(&data->finished);
-                             }
-                             break;
-
-                             case IPI_CPU_STOP:
+                       case IPI_CALL_FUNC:
+                               handle_call_data();
+                               break;
+
+                       case IPI_CPU_STOP:
                                stop_this_cpu();
                                break;
 #ifdef CONFIG_KEXEC
-                             case IPI_KDUMP_CPU_STOP:
+                       case IPI_KDUMP_CPU_STOP:
                                unw_init_running(kdump_cpu_freeze, NULL);
                                break;
 #endif
-                             default:
-                               printk(KERN_CRIT "Unknown IPI on CPU %d: %lu\n", this_cpu, which);
+                       default:
+                               printk(KERN_CRIT "Unknown IPI on CPU %d: %lu\n",
+                                               this_cpu, which);
                                break;
                        }
                } while (ops);
@@ -209,6 +211,19 @@ send_IPI_allbutself (int op)
        }
 }
 
+/*
+ * Called with preemption disabled.
+ */
+static inline void
+send_IPI_mask(cpumask_t mask, int op)
+{
+       unsigned int cpu;
+
+       for_each_cpu_mask(cpu, mask) {
+                       send_IPI_single(cpu, op);
+       }
+}
+
 /*
  * Called with preemption disabled.
  */
@@ -346,7 +361,7 @@ smp_flush_tlb_mm (struct mm_struct *mm)
 }
 
 /*
- * Run a function on another CPU
+ * Run a function on a specific CPU
  *  <func>     The function to run. This must be fast and non-blocking.
  *  <info>     An arbitrary pointer to pass to the function.
  *  <nonatomic>        Currently unused.
@@ -366,9 +381,11 @@ smp_call_function_single (int cpuid, void (*func) (void *info), void *info, int
        int me = get_cpu(); /* prevent preemption and reschedule on another processor */
 
        if (cpuid == me) {
-               printk(KERN_INFO "%s: trying to call self\n", __FUNCTION__);
+               local_irq_disable();
+               func(info);
+               local_irq_enable();
                put_cpu();
-               return -EBUSY;
+               return 0;
        }
 
        data.func = func;
@@ -399,6 +416,75 @@ smp_call_function_single (int cpuid, void (*func) (void *info), void *info, int
 }
 EXPORT_SYMBOL(smp_call_function_single);
 
+/**
+ * smp_call_function_mask(): Run a function on a set of other CPUs.
+ * <mask>      The set of cpus to run on.  Must not include the current cpu.
+ * <func>      The function to run. This must be fast and non-blocking.
+ * <info>      An arbitrary pointer to pass to the function.
+ * <wait>      If true, wait (atomically) until function
+ *             has completed on other CPUs.
+ *
+ * Returns 0 on success, else a negative status code.
+ *
+ * If @wait is true, then returns once @func has returned; otherwise
+ * it returns just before the target cpu calls @func.
+ *
+ * You must not call this function with disabled interrupts or from a
+ * hardware interrupt handler or from a bottom half handler.
+ */
+int smp_call_function_mask(cpumask_t mask,
+                          void (*func)(void *), void *info,
+                          int wait)
+{
+       struct call_data_struct data;
+       cpumask_t allbutself;
+       int cpus;
+
+       spin_lock(&call_lock);
+       allbutself = cpu_online_map;
+       cpu_clear(smp_processor_id(), allbutself);
+
+       cpus_and(mask, mask, allbutself);
+       cpus = cpus_weight(mask);
+       if (!cpus) {
+               spin_unlock(&call_lock);
+               return 0;
+       }
+
+       /* Can deadlock when called with interrupts disabled */
+       WARN_ON(irqs_disabled());
+
+       data.func = func;
+       data.info = info;
+       atomic_set(&data.started, 0);
+       data.wait = wait;
+       if (wait)
+               atomic_set(&data.finished, 0);
+
+       call_data = &data;
+       mb(); /* ensure store to call_data precedes setting of IPI_CALL_FUNC*/
+
+       /* Send a message to other CPUs */
+       if (cpus_equal(mask, allbutself))
+               send_IPI_allbutself(IPI_CALL_FUNC);
+       else
+               send_IPI_mask(mask, IPI_CALL_FUNC);
+
+       /* Wait for response */
+       while (atomic_read(&data.started) != cpus)
+               cpu_relax();
+
+       if (wait)
+               while (atomic_read(&data.finished) != cpus)
+                       cpu_relax();
+       call_data = NULL;
+
+       spin_unlock(&call_lock);
+       return 0;
+
+}
+EXPORT_SYMBOL(smp_call_function_mask);
+
 /*
  * this function sends a 'generic call function' IPI to all other CPUs
  * in the system.
@@ -468,7 +554,7 @@ smp_send_stop (void)
        send_IPI_allbutself(IPI_CPU_STOP);
 }
 
-int __init
+int
 setup_profiling_timer (unsigned int multiplier)
 {
        return -EINVAL;