ARM: mach-shmobile: add DMAC clock definitions on SH7372
[pandora-kernel.git] / kernel / hrtimer.c
index eabcbd7..a9205e3 100644 (file)
@@ -64,23 +64,21 @@ DEFINE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases) =
        .clock_base =
        {
                {
-                       .index = CLOCK_REALTIME,
-                       .get_time = &ktime_get_real,
-                       .resolution = KTIME_LOW_RES,
-               },
-               {
-                       .index = CLOCK_MONOTONIC,
+                       .index = HRTIMER_BASE_MONOTONIC,
+                       .clockid = CLOCK_MONOTONIC,
                        .get_time = &ktime_get,
                        .resolution = KTIME_LOW_RES,
                },
                {
-                       .index = CLOCK_BOOTTIME,
-                       .get_time = &ktime_get_boottime,
+                       .index = HRTIMER_BASE_REALTIME,
+                       .clockid = CLOCK_REALTIME,
+                       .get_time = &ktime_get_real,
                        .resolution = KTIME_LOW_RES,
                },
                {
-                       .index = CLOCK_REALTIME_COS,
-                       .get_time = &ktime_get_real,
+                       .index = HRTIMER_BASE_BOOTTIME,
+                       .clockid = CLOCK_BOOTTIME,
+                       .get_time = &ktime_get_boottime,
                        .resolution = KTIME_LOW_RES,
                },
        }
@@ -90,7 +88,6 @@ static const int hrtimer_clock_to_base_table[MAX_CLOCKS] = {
        [CLOCK_REALTIME]        = HRTIMER_BASE_REALTIME,
        [CLOCK_MONOTONIC]       = HRTIMER_BASE_MONOTONIC,
        [CLOCK_BOOTTIME]        = HRTIMER_BASE_BOOTTIME,
-       [CLOCK_REALTIME_COS]    = HRTIMER_BASE_REALTIME_COS,
 };
 
 static inline int hrtimer_clockid_to_base(clockid_t clock_id)
@@ -116,7 +113,6 @@ static void hrtimer_get_softirq_time(struct hrtimer_cpu_base *base)
        base->clock_base[HRTIMER_BASE_REALTIME].softirq_time = xtim;
        base->clock_base[HRTIMER_BASE_MONOTONIC].softirq_time = mono;
        base->clock_base[HRTIMER_BASE_BOOTTIME].softirq_time = boot;
-       base->clock_base[HRTIMER_BASE_REALTIME_COS].softirq_time = xtim;
 }
 
 /*
@@ -203,7 +199,7 @@ switch_hrtimer_base(struct hrtimer *timer, struct hrtimer_clock_base *base,
        struct hrtimer_cpu_base *new_cpu_base;
        int this_cpu = smp_processor_id();
        int cpu = hrtimer_get_target(this_cpu, pinned);
-       int basenum = hrtimer_clockid_to_base(base->index);
+       int basenum = base->index;
 
 again:
        new_cpu_base = &per_cpu(hrtimer_bases, cpu);
@@ -486,8 +482,6 @@ static inline void debug_deactivate(struct hrtimer *timer)
        trace_hrtimer_cancel(timer);
 }
 
-static void hrtimer_expire_cancelable(struct hrtimer_cpu_base *cpu_base);
-
 /* High resolution timer related functions */
 #ifdef CONFIG_HIGH_RES_TIMERS
 
@@ -663,7 +657,33 @@ static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer,
        return 0;
 }
 
-static void retrigger_next_event(void *arg);
+/*
+ * Retrigger next event is called after clock was set
+ *
+ * Called with interrupts disabled via on_each_cpu()
+ */
+static void retrigger_next_event(void *arg)
+{
+       struct hrtimer_cpu_base *base = &__get_cpu_var(hrtimer_bases);
+       struct timespec realtime_offset, xtim, wtm, sleep;
+
+       if (!hrtimer_hres_active())
+               return;
+
+       /* Optimized out for !HIGH_RES */
+       get_xtime_and_monotonic_and_sleep_offset(&xtim, &wtm, &sleep);
+       set_normalized_timespec(&realtime_offset, -wtm.tv_sec, -wtm.tv_nsec);
+
+       /* Adjust CLOCK_REALTIME offset */
+       raw_spin_lock(&base->lock);
+       base->clock_base[HRTIMER_BASE_REALTIME].offset =
+               timespec_to_ktime(realtime_offset);
+       base->clock_base[HRTIMER_BASE_BOOTTIME].offset =
+               timespec_to_ktime(sleep);
+
+       hrtimer_force_reprogram(base, 0);
+       raw_spin_unlock(&base->lock);
+}
 
 /*
  * Switch to high resolution mode
@@ -711,45 +731,10 @@ static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer,
        return 0;
 }
 static inline void hrtimer_init_hres(struct hrtimer_cpu_base *base) { }
+static inline void retrigger_next_event(void *arg) { }
 
 #endif /* CONFIG_HIGH_RES_TIMERS */
 
-/*
- * Retrigger next event is called after clock was set
- *
- * Called with interrupts disabled via on_each_cpu()
- */
-static void retrigger_next_event(void *arg)
-{
-       struct hrtimer_cpu_base *base = &__get_cpu_var(hrtimer_bases);
-       struct timespec realtime_offset, xtim, wtm, sleep;
-
-       if (!hrtimer_hres_active()) {
-               raw_spin_lock(&base->lock);
-               hrtimer_expire_cancelable(base);
-               raw_spin_unlock(&base->lock);
-               return;
-       }
-
-       /* Optimized out for !HIGH_RES */
-       get_xtime_and_monotonic_and_sleep_offset(&xtim, &wtm, &sleep);
-       set_normalized_timespec(&realtime_offset, -wtm.tv_sec, -wtm.tv_nsec);
-
-       /* Adjust CLOCK_REALTIME offset */
-       raw_spin_lock(&base->lock);
-       base->clock_base[HRTIMER_BASE_REALTIME].offset =
-               timespec_to_ktime(realtime_offset);
-       base->clock_base[HRTIMER_BASE_BOOTTIME].offset =
-               timespec_to_ktime(sleep);
-       base->clock_base[HRTIMER_BASE_REALTIME_COS].offset =
-               timespec_to_ktime(realtime_offset);
-
-       hrtimer_expire_cancelable(base);
-
-       hrtimer_force_reprogram(base, 0);
-       raw_spin_unlock(&base->lock);
-}
-
 /*
  * Clock realtime was set
  *
@@ -763,8 +748,11 @@ static void retrigger_next_event(void *arg)
  */
 void clock_was_set(void)
 {
+#ifdef CONFIG_HIGH_RES_TIMERS
        /* Retrigger the CPU local events everywhere */
        on_each_cpu(retrigger_next_event, NULL, 1);
+#endif
+       timerfd_clock_was_set();
 }
 
 /*
@@ -777,6 +765,7 @@ void hrtimers_resume(void)
                  KERN_INFO "hrtimers_resume() called with IRQs enabled!");
 
        retrigger_next_event(NULL);
+       timerfd_clock_was_set();
 }
 
 static inline void timer_stats_hrtimer_set_start_info(struct hrtimer *timer)
@@ -871,6 +860,7 @@ static int enqueue_hrtimer(struct hrtimer *timer,
        debug_activate(timer);
 
        timerqueue_add(&base->active, &timer->node);
+       base->cpu_base->active_bases |= 1 << base->index;
 
        /*
         * HRTIMER_STATE_ENQUEUED is or'ed to the current state to preserve the
@@ -912,6 +902,8 @@ static void __remove_hrtimer(struct hrtimer *timer,
 #endif
        }
        timerqueue_del(&base->active, &timer->node);
+       if (!timerqueue_getnext(&base->active))
+               base->cpu_base->active_bases &= ~(1 << base->index);
 out:
        timer->state = newstate;
 }
@@ -1240,22 +1232,6 @@ static void __run_hrtimer(struct hrtimer *timer, ktime_t *now)
        timer->state &= ~HRTIMER_STATE_CALLBACK;
 }
 
-static void hrtimer_expire_cancelable(struct hrtimer_cpu_base *cpu_base)
-{
-       struct timerqueue_node *node;
-       struct hrtimer_clock_base *base;
-       ktime_t now = ktime_get_real();
-
-       base = &cpu_base->clock_base[HRTIMER_BASE_REALTIME_COS];
-
-       while ((node = timerqueue_getnext(&base->active))) {
-                       struct hrtimer *timer;
-
-                       timer = container_of(node, struct hrtimer, node);
-                       __run_hrtimer(timer, &now);
-       }
-}
-
 #ifdef CONFIG_HIGH_RES_TIMERS
 
 /*
@@ -1265,7 +1241,6 @@ static void hrtimer_expire_cancelable(struct hrtimer_cpu_base *cpu_base)
 void hrtimer_interrupt(struct clock_event_device *dev)
 {
        struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
-       struct hrtimer_clock_base *base;
        ktime_t expires_next, now, entry_time, delta;
        int i, retries = 0;
 
@@ -1287,12 +1262,15 @@ retry:
         */
        cpu_base->expires_next.tv64 = KTIME_MAX;
 
-       base = cpu_base->clock_base;
-
        for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) {
-               ktime_t basenow;
+               struct hrtimer_clock_base *base;
                struct timerqueue_node *node;
+               ktime_t basenow;
+
+               if (!(cpu_base->active_bases & (1 << i)))
+                       continue;
 
+               base = cpu_base->clock_base + i;
                basenow = ktime_add(now, base->offset);
 
                while ((node = timerqueue_getnext(&base->active))) {
@@ -1325,7 +1303,6 @@ retry:
 
                        __run_hrtimer(timer, &basenow);
                }
-               base++;
        }
 
        /*
@@ -1556,7 +1533,7 @@ long __sched hrtimer_nanosleep_restart(struct restart_block *restart)
        struct timespec __user  *rmtp;
        int ret = 0;
 
-       hrtimer_init_on_stack(&t.timer, restart->nanosleep.index,
+       hrtimer_init_on_stack(&t.timer, restart->nanosleep.clockid,
                                HRTIMER_MODE_ABS);
        hrtimer_set_expires_tv64(&t.timer, restart->nanosleep.expires);
 
@@ -1608,7 +1585,7 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
 
        restart = &current_thread_info()->restart_block;
        restart->fn = hrtimer_nanosleep_restart;
-       restart->nanosleep.index = t.timer.base->index;
+       restart->nanosleep.clockid = t.timer.base->clockid;
        restart->nanosleep.rmtp = rmtp;
        restart->nanosleep.expires = hrtimer_get_expires_tv64(&t.timer);