]> Pileus Git - ~andy/linux/blobdiff - kernel/time/timekeeping.c
timekeeping: Simplify tai updating from do_adjtimex
[~andy/linux] / kernel / time / timekeeping.c
index f6c8a7279157dc36748eed56b01ef5ce561adcf0..f93f60cd97ad570767dbbfc6d38e5f0b7bfe4b88 100644 (file)
@@ -787,10 +787,10 @@ void __init timekeeping_init(void)
                boot.tv_nsec = 0;
        }
 
-       ntp_init();
-
        raw_spin_lock_irqsave(&timekeeper_lock, flags);
        write_seqcount_begin(&timekeeper_seq);
+       ntp_init();
+
        clock = clocksource_default_clock();
        if (clock->enable)
                clock->enable(clock);
@@ -1618,6 +1618,10 @@ EXPORT_SYMBOL_GPL(ktime_get_monotonic_offset);
  */
 int do_adjtimex(struct timex *txc)
 {
+       struct timekeeper *tk = &timekeeper;
+       unsigned long flags;
+       struct timespec ts;
+       s32 tai;
        int ret;
 
        /* Validate the data before disabling interrupts */
@@ -1625,9 +1629,31 @@ int do_adjtimex(struct timex *txc)
        if (ret)
                return ret;
 
-       return __do_adjtimex(txc);
-}
+       if (txc->modes & ADJ_SETOFFSET) {
+               struct timespec delta;
+               delta.tv_sec  = txc->time.tv_sec;
+               delta.tv_nsec = txc->time.tv_usec;
+               if (!(txc->modes & ADJ_NANO))
+                       delta.tv_nsec *= 1000;
+               ret = timekeeping_inject_offset(&delta);
+               if (ret)
+                       return ret;
+       }
 
+       getnstimeofday(&ts);
+
+       raw_spin_lock_irqsave(&timekeeper_lock, flags);
+       write_seqcount_begin(&timekeeper_seq);
+
+       tai = tk->tai_offset;
+       ret = __do_adjtimex(txc, &ts, &tai);
+
+       __timekeeping_set_tai_offset(tk, tai);
+       write_seqcount_end(&timekeeper_seq);
+       raw_spin_unlock_irqrestore(&timekeeper_lock, flags);
+
+       return ret;
+}
 
 #ifdef CONFIG_NTP_PPS
 /**
@@ -1635,7 +1661,15 @@ int do_adjtimex(struct timex *txc)
  */
 void hardpps(const struct timespec *phase_ts, const struct timespec *raw_ts)
 {
+       unsigned long flags;
+
+       raw_spin_lock_irqsave(&timekeeper_lock, flags);
+       write_seqcount_begin(&timekeeper_seq);
+
        __hardpps(phase_ts, raw_ts);
+
+       write_seqcount_end(&timekeeper_seq);
+       raw_spin_unlock_irqrestore(&timekeeper_lock, flags);
 }
 EXPORT_SYMBOL(hardpps);
 #endif