smp_call_function: get rid of the unused nonatomic/retry argument
[safe/jmp/linux-2.6] / kernel / time / tick-broadcast.c
index 8001d37..75e7185 100644 (file)
@@ -14,7 +14,7 @@
 #include <linux/cpu.h>
 #include <linux/err.h>
 #include <linux/hrtimer.h>
-#include <linux/irq.h>
+#include <linux/interrupt.h>
 #include <linux/percpu.h>
 #include <linux/profile.h>
 #include <linux/sched.h>
@@ -31,6 +31,12 @@ struct tick_device tick_broadcast_device;
 static cpumask_t tick_broadcast_mask;
 static DEFINE_SPINLOCK(tick_broadcast_lock);
 
+#ifdef CONFIG_TICK_ONESHOT
+static void tick_broadcast_clear_oneshot(int cpu);
+#else
+static inline void tick_broadcast_clear_oneshot(int cpu) { }
+#endif
+
 /*
  * Debugging: see timer_list.c
  */
@@ -49,7 +55,7 @@ cpumask_t *tick_get_broadcast_mask(void)
  */
 static void tick_broadcast_start_periodic(struct clock_event_device *bc)
 {
-       if (bc && bc->mode == CLOCK_EVT_MODE_SHUTDOWN)
+       if (bc)
                tick_setup_periodic(bc, 1);
 }
 
@@ -58,8 +64,9 @@ static void tick_broadcast_start_periodic(struct clock_event_device *bc)
  */
 int tick_check_broadcast_device(struct clock_event_device *dev)
 {
-       if (tick_broadcast_device.evtdev ||
-           (dev->features & CLOCK_EVT_FEAT_C3STOP))
+       if ((tick_broadcast_device.evtdev &&
+            tick_broadcast_device.evtdev->rating >= dev->rating) ||
+            (dev->features & CLOCK_EVT_FEAT_C3STOP))
                return 0;
 
        clockevents_exchange_device(NULL, dev);
@@ -99,8 +106,19 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
                cpu_set(cpu, tick_broadcast_mask);
                tick_broadcast_start_periodic(tick_broadcast_device.evtdev);
                ret = 1;
-       }
+       } else {
+               /*
+                * When the new device is not affected by the stop
+                * feature and the cpu is marked in the broadcast mask
+                * then clear the broadcast bit.
+                */
+               if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
+                       int cpu = smp_processor_id();
 
+                       cpu_clear(cpu, tick_broadcast_mask);
+                       tick_broadcast_clear_oneshot(cpu);
+               }
+       }
        spin_unlock_irqrestore(&tick_broadcast_lock, flags);
        return ret;
 }
@@ -108,9 +126,9 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
 /*
  * Broadcast the event to the cpus, which are set in the mask
  */
-int tick_do_broadcast(cpumask_t mask)
+static void tick_do_broadcast(cpumask_t mask)
 {
-       int ret = 0, cpu = smp_processor_id();
+       int cpu = smp_processor_id();
        struct tick_device *td;
 
        /*
@@ -120,7 +138,6 @@ int tick_do_broadcast(cpumask_t mask)
                cpu_clear(cpu, mask);
                td = &per_cpu(tick_cpu_device, cpu);
                td->evtdev->event_handler(td->evtdev);
-               ret = 1;
        }
 
        if (!cpus_empty(mask)) {
@@ -133,9 +150,7 @@ int tick_do_broadcast(cpumask_t mask)
                cpu = first_cpu(mask);
                td = &per_cpu(tick_cpu_device, cpu);
                td->evtdev->broadcast(mask);
-               ret = 1;
        }
-       return ret;
 }
 
 /*
@@ -159,8 +174,6 @@ static void tick_do_periodic_broadcast(void)
  */
 static void tick_handle_periodic_broadcast(struct clock_event_device *dev)
 {
-       dev->next_event.tv64 = KTIME_MAX;
-
        tick_do_periodic_broadcast();
 
        /*
@@ -201,26 +214,33 @@ static void tick_do_broadcast_on_off(void *why)
        bc = tick_broadcast_device.evtdev;
 
        /*
-        * Is the device in broadcast mode forever or is it not
-        * affected by the powerstate ?
+        * Is the device not affected by the powerstate ?
         */
-       if (!dev || !tick_device_is_functional(dev) ||
-           !(dev->features & CLOCK_EVT_FEAT_C3STOP))
+       if (!dev || !(dev->features & CLOCK_EVT_FEAT_C3STOP))
+               goto out;
+
+       if (!tick_device_is_functional(dev))
                goto out;
 
-       if (*reason == CLOCK_EVT_NOTIFY_BROADCAST_ON) {
+       switch (*reason) {
+       case CLOCK_EVT_NOTIFY_BROADCAST_ON:
+       case CLOCK_EVT_NOTIFY_BROADCAST_FORCE:
                if (!cpu_isset(cpu, tick_broadcast_mask)) {
                        cpu_set(cpu, tick_broadcast_mask);
                        if (td->mode == TICKDEV_MODE_PERIODIC)
                                clockevents_set_mode(dev,
                                                     CLOCK_EVT_MODE_SHUTDOWN);
                }
-       } else {
+               if (*reason == CLOCK_EVT_NOTIFY_BROADCAST_FORCE)
+                       dev->features |= CLOCK_EVT_FEAT_DUMMY;
+               break;
+       case CLOCK_EVT_NOTIFY_BROADCAST_OFF:
                if (cpu_isset(cpu, tick_broadcast_mask)) {
                        cpu_clear(cpu, tick_broadcast_mask);
                        if (td->mode == TICKDEV_MODE_PERIODIC)
                                tick_setup_periodic(dev, 0);
                }
+               break;
        }
 
        if (cpus_empty(tick_broadcast_mask))
@@ -241,21 +261,12 @@ out:
  */
 void tick_broadcast_on_off(unsigned long reason, int *oncpu)
 {
-       int cpu = get_cpu();
-
-       if (!cpu_isset(*oncpu, cpu_online_map)) {
-               printk(KERN_ERR "tick-braodcast: ignoring broadcast for "
+       if (!cpu_isset(*oncpu, cpu_online_map))
+               printk(KERN_ERR "tick-broadcast: ignoring broadcast for "
                       "offline CPU #%d\n", *oncpu);
-       } else {
-
-               if (cpu == *oncpu)
-                       tick_do_broadcast_on_off(&reason);
-               else
-                       smp_call_function_single(*oncpu,
-                                                tick_do_broadcast_on_off,
-                                                &reason, 1, 1);
-       }
-       put_cpu();
+       else
+               smp_call_function_single(*oncpu, tick_do_broadcast_on_off,
+                                        &reason, 1);
 }
 
 /*
@@ -299,7 +310,7 @@ void tick_suspend_broadcast(void)
        spin_lock_irqsave(&tick_broadcast_lock, flags);
 
        bc = tick_broadcast_device.evtdev;
-       if (bc && tick_broadcast_device.mode == TICKDEV_MODE_PERIODIC)
+       if (bc)
                clockevents_set_mode(bc, CLOCK_EVT_MODE_SHUTDOWN);
 
        spin_unlock_irqrestore(&tick_broadcast_lock, flags);
@@ -316,6 +327,8 @@ int tick_resume_broadcast(void)
        bc = tick_broadcast_device.evtdev;
 
        if (bc) {
+               clockevents_set_mode(bc, CLOCK_EVT_MODE_RESUME);
+
                switch (tick_broadcast_device.mode) {
                case TICKDEV_MODE_PERIODIC:
                        if(!cpus_empty(tick_broadcast_mask))
@@ -364,38 +377,7 @@ static int tick_broadcast_set_event(ktime_t expires, int force)
 int tick_resume_broadcast_oneshot(struct clock_event_device *bc)
 {
        clockevents_set_mode(bc, CLOCK_EVT_MODE_ONESHOT);
-
-       if(!cpus_empty(tick_broadcast_oneshot_mask))
-               tick_broadcast_set_event(ktime_get(), 1);
-
-       return cpu_isset(smp_processor_id(), tick_broadcast_oneshot_mask);
-}
-
-/*
- * Reprogram the broadcast device:
- *
- * Called with tick_broadcast_lock held and interrupts disabled.
- */
-static int tick_broadcast_reprogram(void)
-{
-       ktime_t expires = { .tv64 = KTIME_MAX };
-       struct tick_device *td;
-       int cpu;
-
-       /*
-        * Find the event which expires next:
-        */
-       for (cpu = first_cpu(tick_broadcast_oneshot_mask); cpu != NR_CPUS;
-            cpu = next_cpu(cpu, tick_broadcast_oneshot_mask)) {
-               td = &per_cpu(tick_cpu_device, cpu);
-               if (td->evtdev->next_event.tv64 < expires.tv64)
-                       expires = td->evtdev->next_event;
-       }
-
-       if (expires.tv64 == KTIME_MAX)
-               return 0;
-
-       return tick_broadcast_set_event(expires, 0);
+       return 0;
 }
 
 /*
@@ -405,12 +387,13 @@ static void tick_handle_oneshot_broadcast(struct clock_event_device *dev)
 {
        struct tick_device *td;
        cpumask_t mask;
-       ktime_t now;
+       ktime_t now, next_event;
        int cpu;
 
        spin_lock(&tick_broadcast_lock);
 again:
        dev->next_event.tv64 = KTIME_MAX;
+       next_event.tv64 = KTIME_MAX;
        mask = CPU_MASK_NONE;
        now = ktime_get();
        /* Find all expired events */
@@ -419,19 +402,31 @@ again:
                td = &per_cpu(tick_cpu_device, cpu);
                if (td->evtdev->next_event.tv64 <= now.tv64)
                        cpu_set(cpu, mask);
+               else if (td->evtdev->next_event.tv64 < next_event.tv64)
+                       next_event.tv64 = td->evtdev->next_event.tv64;
        }
 
        /*
-        * Wakeup the cpus which have an expired event. The broadcast
-        * device is reprogrammed in the return from idle code.
+        * Wakeup the cpus which have an expired event.
+        */
+       tick_do_broadcast(mask);
+
+       /*
+        * Two reasons for reprogram:
+        *
+        * - The global event did not expire any CPU local
+        * events. This happens in dyntick mode, as the maximum PIT
+        * delta is quite small.
+        *
+        * - There are pending events on sleeping CPUs which were not
+        * in the event mask
         */
-       if (!tick_do_broadcast(mask)) {
+       if (next_event.tv64 != KTIME_MAX) {
                /*
-                * The global event did not expire any CPU local
-                * events. This happens in dyntick mode, as the
-                * maximum PIT delta is quite small.
+                * Rearm the broadcast device. If event expired,
+                * repeat the above
                 */
-               if (tick_broadcast_reprogram())
+               if (tick_broadcast_set_event(next_event, 0))
                        goto again;
        }
        spin_unlock(&tick_broadcast_lock);
@@ -485,16 +480,24 @@ out:
        spin_unlock_irqrestore(&tick_broadcast_lock, flags);
 }
 
+/*
+ * Reset the one shot broadcast for a cpu
+ *
+ * Called with tick_broadcast_lock held
+ */
+static void tick_broadcast_clear_oneshot(int cpu)
+{
+       cpu_clear(cpu, tick_broadcast_oneshot_mask);
+}
+
 /**
- * tick_broadcast_setup_highres - setup the broadcast device for highres
+ * tick_broadcast_setup_oneshot - setup the broadcast device
  */
 void tick_broadcast_setup_oneshot(struct clock_event_device *bc)
 {
-       if (bc->mode != CLOCK_EVT_MODE_ONESHOT) {
-               bc->event_handler = tick_handle_oneshot_broadcast;
-               clockevents_set_mode(bc, CLOCK_EVT_MODE_ONESHOT);
-               bc->next_event.tv64 = KTIME_MAX;
-       }
+       bc->event_handler = tick_handle_oneshot_broadcast;
+       clockevents_set_mode(bc, CLOCK_EVT_MODE_ONESHOT);
+       bc->next_event.tv64 = KTIME_MAX;
 }
 
 /*
@@ -520,20 +523,17 @@ void tick_broadcast_switch_to_oneshot(void)
  */
 void tick_shutdown_broadcast_oneshot(unsigned int *cpup)
 {
-       struct clock_event_device *bc;
        unsigned long flags;
        unsigned int cpu = *cpup;
 
        spin_lock_irqsave(&tick_broadcast_lock, flags);
 
-       bc = tick_broadcast_device.evtdev;
+       /*
+        * Clear the broadcast mask flag for the dead cpu, but do not
+        * stop the broadcast device!
+        */
        cpu_clear(cpu, tick_broadcast_oneshot_mask);
 
-       if (tick_broadcast_device.mode == TICKDEV_MODE_ONESHOT) {
-               if (bc && cpus_empty(tick_broadcast_oneshot_mask))
-                       clockevents_set_mode(bc, CLOCK_EVT_MODE_SHUTDOWN);
-       }
-
        spin_unlock_irqrestore(&tick_broadcast_lock, flags);
 }