timekeeping: Hold timekeepering locks in do_adjtimex and hardpps
[pandora-kernel.git] / kernel / time / timekeeping.c
index c5feb7a..d10bd73 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/pvclock_gtod.h>
 
 #include "tick-internal.h"
+#include "ntp_internal.h"
 
 static struct timekeeper timekeeper;
 static DEFINE_RAW_SPINLOCK(timekeeper_lock);
@@ -786,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);
@@ -1612,6 +1613,68 @@ ktime_t ktime_get_monotonic_offset(void)
 }
 EXPORT_SYMBOL_GPL(ktime_get_monotonic_offset);
 
+/**
+ * do_adjtimex() - Accessor function to NTP __do_adjtimex function
+ */
+int do_adjtimex(struct timex *txc)
+{
+       unsigned long flags;
+       struct timespec ts;
+       s32 tai, orig_tai;
+       int ret;
+
+       /* Validate the data before disabling interrupts */
+       ret = ntp_validate_timex(txc);
+       if (ret)
+               return ret;
+
+       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);
+       orig_tai = tai = timekeeping_get_tai_offset();
+
+       raw_spin_lock_irqsave(&timekeeper_lock, flags);
+       write_seqcount_begin(&timekeeper_seq);
+
+       ret = __do_adjtimex(txc, &ts, &tai);
+
+       write_seqcount_end(&timekeeper_seq);
+       raw_spin_unlock_irqrestore(&timekeeper_lock, flags);
+
+       if (tai != orig_tai)
+               timekeeping_set_tai_offset(tai);
+
+       return ret;
+}
+
+#ifdef CONFIG_NTP_PPS
+/**
+ * hardpps() - Accessor function to NTP __hardpps function
+ */
+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
+
 /**
  * xtime_update() - advances the timekeeping infrastructure
  * @ticks:     number of ticks, that have elapsed since the last call.