clockevents: remove the suspend/resume workaround^Wthinko
[sfrench/cifs-2.6.git] / kernel / time / tick-broadcast.c
index 5567745470f7121a284401beec86c1868ed026ae..0962e0577660722b11d69171a8d4ce5a57017ad6 100644 (file)
@@ -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);
 }
 
@@ -99,8 +105,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;
 }
@@ -243,11 +260,18 @@ void tick_broadcast_on_off(unsigned long reason, int *oncpu)
 {
        int cpu = get_cpu();
 
-       if (cpu == *oncpu)
-               tick_do_broadcast_on_off(&reason);
-       else
-               smp_call_function_single(*oncpu, tick_do_broadcast_on_off,
-                                        &reason, 1, 1);
+       if (!cpu_isset(*oncpu, cpu_online_map)) {
+               printk(KERN_ERR "tick-braodcast: 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();
 }
 
@@ -292,7 +316,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);
@@ -307,12 +331,21 @@ int tick_resume_broadcast(void)
        spin_lock_irqsave(&tick_broadcast_lock, flags);
 
        bc = tick_broadcast_device.evtdev;
-       if (bc) {
-               if (tick_broadcast_device.mode == TICKDEV_MODE_PERIODIC &&
-                   !cpus_empty(tick_broadcast_mask))
-                       tick_broadcast_start_periodic(bc);
 
-               broadcast = cpu_isset(smp_processor_id(), tick_broadcast_mask);
+       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))
+                               tick_broadcast_start_periodic(bc);
+                       broadcast = cpu_isset(smp_processor_id(),
+                                             tick_broadcast_mask);
+                       break;
+               case TICKDEV_MODE_ONESHOT:
+                       broadcast = tick_resume_broadcast_oneshot(bc);
+                       break;
+               }
        }
        spin_unlock_irqrestore(&tick_broadcast_lock, flags);
 
@@ -347,6 +380,12 @@ 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);
+       return 0;
+}
+
 /*
  * Reprogram the broadcast device:
  *
@@ -461,6 +500,16 @@ 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
  */
@@ -496,20 +545,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);
 }