tick/timekeeping: Call update_wall_time outside the jiffies lock
[pandora-kernel.git] / kernel / time / timekeeping.c
index 3abf534..44b7e6b 100644 (file)
@@ -610,6 +610,7 @@ void timekeeping_set_tai_offset(s32 tai_offset)
        raw_spin_lock_irqsave(&timekeeper_lock, flags);
        write_seqcount_begin(&timekeeper_seq);
        __timekeeping_set_tai_offset(tk, tai_offset);
+       timekeeping_update(tk, TK_MIRROR | TK_CLOCK_WAS_SET);
        write_seqcount_end(&timekeeper_seq);
        raw_spin_unlock_irqrestore(&timekeeper_lock, flags);
        clock_was_set();
@@ -1255,7 +1256,7 @@ out_adjust:
 static inline unsigned int accumulate_nsecs_to_secs(struct timekeeper *tk)
 {
        u64 nsecps = (u64)NSEC_PER_SEC << tk->shift;
-       unsigned int action = 0;
+       unsigned int clock_set = 0;
 
        while (tk->xtime_nsec >= nsecps) {
                int leap;
@@ -1277,11 +1278,10 @@ static inline unsigned int accumulate_nsecs_to_secs(struct timekeeper *tk)
 
                        __timekeeping_set_tai_offset(tk, tk->tai_offset - leap);
 
-                       clock_was_set_delayed();
-                       action = TK_CLOCK_WAS_SET;
+                       clock_set = TK_CLOCK_WAS_SET;
                }
        }
-       return action;
+       return clock_set;
 }
 
 /**
@@ -1294,7 +1294,8 @@ static inline unsigned int accumulate_nsecs_to_secs(struct timekeeper *tk)
  * Returns the unconsumed cycles.
  */
 static cycle_t logarithmic_accumulation(struct timekeeper *tk, cycle_t offset,
-                                               u32 shift)
+                                               u32 shift,
+                                               unsigned int *clock_set)
 {
        cycle_t interval = tk->cycle_interval << shift;
        u64 raw_nsecs;
@@ -1308,7 +1309,7 @@ static cycle_t logarithmic_accumulation(struct timekeeper *tk, cycle_t offset,
        tk->cycle_last += interval;
 
        tk->xtime_nsec += tk->xtime_interval << shift;
-       accumulate_nsecs_to_secs(tk);
+       *clock_set |= accumulate_nsecs_to_secs(tk);
 
        /* Accumulate raw time */
        raw_nsecs = (u64)tk->raw_interval << shift;
@@ -1359,14 +1360,14 @@ static inline void old_vsyscall_fixup(struct timekeeper *tk)
  * update_wall_time - Uses the current clocksource to increment the wall time
  *
  */
-static void update_wall_time(void)
+void update_wall_time(void)
 {
        struct clocksource *clock;
        struct timekeeper *real_tk = &timekeeper;
        struct timekeeper *tk = &shadow_timekeeper;
        cycle_t offset;
        int shift = 0, maxshift;
-       unsigned int action;
+       unsigned int clock_set = 0;
        unsigned long flags;
 
        raw_spin_lock_irqsave(&timekeeper_lock, flags);
@@ -1401,7 +1402,8 @@ static void update_wall_time(void)
        maxshift = (64 - (ilog2(ntp_tick_length())+1)) - 1;
        shift = min(shift, maxshift);
        while (offset >= tk->cycle_interval) {
-               offset = logarithmic_accumulation(tk, offset, shift);
+               offset = logarithmic_accumulation(tk, offset, shift,
+                                                       &clock_set);
                if (offset < tk->cycle_interval<<shift)
                        shift--;
        }
@@ -1419,7 +1421,7 @@ static void update_wall_time(void)
         * Finally, make sure that after the rounding
         * xtime_nsec isn't larger than NSEC_PER_SEC
         */
-       action = accumulate_nsecs_to_secs(tk);
+       clock_set |= accumulate_nsecs_to_secs(tk);
 
        write_seqcount_begin(&timekeeper_seq);
        /* Update clock->cycle_last with the new value */
@@ -1435,10 +1437,12 @@ static void update_wall_time(void)
         * updating.
         */
        memcpy(real_tk, tk, sizeof(*tk));
-       timekeeping_update(real_tk, action);
+       timekeeping_update(real_tk, clock_set);
        write_seqcount_end(&timekeeper_seq);
 out:
        raw_spin_unlock_irqrestore(&timekeeper_lock, flags);
+       if (clock_set)
+               clock_was_set();
 }
 
 /**
@@ -1583,7 +1587,6 @@ struct timespec get_monotonic_coarse(void)
 void do_timer(unsigned long ticks)
 {
        jiffies_64 += ticks;
-       update_wall_time();
        calc_global_load(ticks);
 }
 
@@ -1698,12 +1701,14 @@ int do_adjtimex(struct timex *txc)
 
        if (tai != orig_tai) {
                __timekeeping_set_tai_offset(tk, tai);
-               update_pvclock_gtod(tk, true);
-               clock_was_set_delayed();
+               timekeeping_update(tk, TK_MIRROR | TK_CLOCK_WAS_SET);
        }
        write_seqcount_end(&timekeeper_seq);
        raw_spin_unlock_irqrestore(&timekeeper_lock, flags);
 
+       if (tai != orig_tai)
+               clock_was_set();
+
        ntp_notify_cmos_timer();
 
        return ret;
@@ -1739,4 +1744,5 @@ void xtime_update(unsigned long ticks)
        write_seqlock(&jiffies_lock);
        do_timer(ticks);
        write_sequnlock(&jiffies_lock);
+       update_wall_time();
 }