hrtimer: Unconfuse switch_hrtimer_base() a bit
[deliverable/linux.git] / kernel / time / hrtimer.c
index 55575d4f253c672afba781fad03652294d101f51..5c4fe50e47d301f4276277a586353f8ff16dda01 100644 (file)
@@ -183,7 +183,7 @@ struct hrtimer_cpu_base *get_target_base(struct hrtimer_cpu_base *base,
                                         int pinned)
 {
        if (pinned || !base->migration_enabled)
-               return this_cpu_ptr(&hrtimer_bases);
+               return base;
        return &per_cpu(hrtimer_bases, get_nohz_timer_target());
 }
 #else
@@ -191,23 +191,32 @@ static inline
 struct hrtimer_cpu_base *get_target_base(struct hrtimer_cpu_base *base,
                                         int pinned)
 {
-       return this_cpu_ptr(&hrtimer_bases);
+       return base;
 }
 #endif
 
 /*
- * Switch the timer base to the current CPU when possible.
+ * We switch the timer base to a power-optimized selected CPU target,
+ * if:
+ *     - NO_HZ_COMMON is enabled
+ *     - timer migration is enabled
+ *     - the timer callback is not running
+ *     - the timer is not the first expiring timer on the new target
+ *
+ * If one of the above requirements is not fulfilled we move the timer
+ * to the current CPU or leave it on the previously assigned CPU if
+ * the timer callback is currently running.
  */
 static inline struct hrtimer_clock_base *
 switch_hrtimer_base(struct hrtimer *timer, struct hrtimer_clock_base *base,
                    int pinned)
 {
-       struct hrtimer_cpu_base *new_cpu_base, *this_base;
+       struct hrtimer_cpu_base *new_cpu_base, *this_cpu_base;
        struct hrtimer_clock_base *new_base;
        int basenum = base->index;
 
-       this_base = this_cpu_ptr(&hrtimer_bases);
-       new_cpu_base = get_target_base(this_base, pinned);
+       this_cpu_base = this_cpu_ptr(&hrtimer_bases);
+       new_cpu_base = get_target_base(this_cpu_base, pinned);
 again:
        new_base = &new_cpu_base->clock_base[basenum];
 
@@ -229,19 +238,19 @@ again:
                raw_spin_unlock(&base->cpu_base->lock);
                raw_spin_lock(&new_base->cpu_base->lock);
 
-               if (new_cpu_base != this_base &&
+               if (new_cpu_base != this_cpu_base &&
                    hrtimer_check_target(timer, new_base)) {
                        raw_spin_unlock(&new_base->cpu_base->lock);
                        raw_spin_lock(&base->cpu_base->lock);
-                       new_cpu_base = this_base;
+                       new_cpu_base = this_cpu_base;
                        timer->base = base;
                        goto again;
                }
                timer->base = new_base;
        } else {
-               if (new_cpu_base != this_base &&
+               if (new_cpu_base != this_cpu_base &&
                    hrtimer_check_target(timer, new_base)) {
-                       new_cpu_base = this_base;
+                       new_cpu_base = this_cpu_base;
                        goto again;
                }
        }
This page took 0.030061 seconds and 5 git commands to generate.