blob: 1ad46f3df6e76cd8994403b1c1ca72c14ec3553b [file] [log] [blame]
john stultz4c7ee8d2006-09-30 23:28:22 -07001/*
2 * linux/kernel/time/ntp.c
3 *
4 * NTP state machine interfaces and logic.
5 *
6 * This code was mainly moved from kernel/timer.c and kernel/time.c
7 * Please see those files for relevant copyright info and historical
8 * changelogs.
9 */
10
11#include <linux/mm.h>
12#include <linux/time.h>
Thomas Gleixner82644452007-07-21 04:37:37 -070013#include <linux/timer.h>
john stultz4c7ee8d2006-09-30 23:28:22 -070014#include <linux/timex.h>
Alexey Dobriyane8edc6e2007-05-21 01:22:52 +040015#include <linux/jiffies.h>
16#include <linux/hrtimer.h>
Alexey Dobriyanaa0ac362007-07-15 23:40:39 -070017#include <linux/capability.h>
Roman Zippel71abb3a2008-05-01 04:34:26 -070018#include <linux/math64.h>
Roman Zippel7dffa3c2008-05-01 04:34:41 -070019#include <linux/clocksource.h>
john stultz4c7ee8d2006-09-30 23:28:22 -070020#include <asm/timex.h>
21
Roman Zippelb0ee7552006-09-30 23:28:22 -070022/*
23 * Timekeeping variables
24 */
25unsigned long tick_usec = TICK_USEC; /* USER_HZ period (usec) */
26unsigned long tick_nsec; /* ACTHZ period (nsec) */
Roman Zippel8383c422008-05-01 04:34:39 -070027u64 tick_length;
28static u64 tick_length_base;
Roman Zippelb0ee7552006-09-30 23:28:22 -070029
Roman Zippel7dffa3c2008-05-01 04:34:41 -070030static struct hrtimer leap_timer;
31
Roman Zippel8f807f82006-09-30 23:28:25 -070032#define MAX_TICKADJ 500 /* microsecs */
33#define MAX_TICKADJ_SCALED (((u64)(MAX_TICKADJ * NSEC_PER_USEC) << \
Roman Zippel7fc5c782008-05-01 04:34:38 -070034 NTP_SCALE_SHIFT) / NTP_INTERVAL_FREQ)
john stultz4c7ee8d2006-09-30 23:28:22 -070035
36/*
37 * phase-lock loop variables
38 */
39/* TIME_ERROR prevents overwriting the CMOS clock */
Adrian Bunk70bc42f2006-09-30 23:28:29 -070040static int time_state = TIME_OK; /* clock synchronization status */
john stultz4c7ee8d2006-09-30 23:28:22 -070041int time_status = STA_UNSYNC; /* clock status bits */
Roman Zippel153b5d02008-05-01 04:34:37 -070042static long time_tai; /* TAI offset (s) */
Roman Zippelee9851b2008-05-01 04:34:32 -070043static s64 time_offset; /* time adjustment (ns) */
Adrian Bunk70bc42f2006-09-30 23:28:29 -070044static long time_constant = 2; /* pll time constant */
john stultz4c7ee8d2006-09-30 23:28:22 -070045long time_maxerror = NTP_PHASE_LIMIT; /* maximum error (us) */
46long time_esterror = NTP_PHASE_LIMIT; /* estimated error (us) */
Roman Zippel074b3b82008-05-01 04:34:34 -070047static s64 time_freq; /* frequency offset (scaled ns/s)*/
Adrian Bunk70bc42f2006-09-30 23:28:29 -070048static long time_reftime; /* time at last adjustment (s) */
john stultz4c7ee8d2006-09-30 23:28:22 -070049long time_adjust;
Roman Zippel10a398d2008-03-04 15:14:26 -080050static long ntp_tick_adj;
john stultz4c7ee8d2006-09-30 23:28:22 -070051
Adrian Bunk70bc42f2006-09-30 23:28:29 -070052static void ntp_update_frequency(void)
53{
john stultzf4304ab2007-02-16 01:27:26 -080054 u64 second_length = (u64)(tick_usec * NSEC_PER_USEC * USER_HZ)
Roman Zippel7fc5c782008-05-01 04:34:38 -070055 << NTP_SCALE_SHIFT;
56 second_length += (s64)ntp_tick_adj << NTP_SCALE_SHIFT;
Roman Zippel074b3b82008-05-01 04:34:34 -070057 second_length += time_freq;
Adrian Bunk70bc42f2006-09-30 23:28:29 -070058
john stultzf4304ab2007-02-16 01:27:26 -080059 tick_length_base = second_length;
Adrian Bunk70bc42f2006-09-30 23:28:29 -070060
Roman Zippel7fc5c782008-05-01 04:34:38 -070061 tick_nsec = div_u64(second_length, HZ) >> NTP_SCALE_SHIFT;
Roman Zippel71abb3a2008-05-01 04:34:26 -070062 tick_length_base = div_u64(tick_length_base, NTP_INTERVAL_FREQ);
Adrian Bunk70bc42f2006-09-30 23:28:29 -070063}
64
Roman Zippelee9851b2008-05-01 04:34:32 -070065static void ntp_update_offset(long offset)
66{
67 long mtemp;
68 s64 freq_adj;
69
70 if (!(time_status & STA_PLL))
71 return;
72
Roman Zippeleea83d82008-05-01 04:34:33 -070073 if (!(time_status & STA_NANO))
Roman Zippel9f14f662008-05-01 04:34:36 -070074 offset *= NSEC_PER_USEC;
Roman Zippelee9851b2008-05-01 04:34:32 -070075
76 /*
77 * Scale the phase adjustment and
78 * clamp to the operating range.
79 */
Roman Zippel9f14f662008-05-01 04:34:36 -070080 offset = min(offset, MAXPHASE);
81 offset = max(offset, -MAXPHASE);
Roman Zippelee9851b2008-05-01 04:34:32 -070082
83 /*
84 * Select how the frequency is to be controlled
85 * and in which mode (PLL or FLL).
86 */
87 if (time_status & STA_FREQHOLD || time_reftime == 0)
88 time_reftime = xtime.tv_sec;
89 mtemp = xtime.tv_sec - time_reftime;
90 time_reftime = xtime.tv_sec;
91
Roman Zippel9f14f662008-05-01 04:34:36 -070092 freq_adj = (s64)offset * mtemp;
Roman Zippel7fc5c782008-05-01 04:34:38 -070093 freq_adj <<= NTP_SCALE_SHIFT - 2 * (SHIFT_PLL + 2 + time_constant);
Roman Zippeleea83d82008-05-01 04:34:33 -070094 time_status &= ~STA_MODE;
95 if (mtemp >= MINSEC && (time_status & STA_FLL || mtemp > MAXSEC)) {
Roman Zippel7fc5c782008-05-01 04:34:38 -070096 freq_adj += div_s64((s64)offset << (NTP_SCALE_SHIFT - SHIFT_FLL),
Roman Zippel074b3b82008-05-01 04:34:34 -070097 mtemp);
Roman Zippeleea83d82008-05-01 04:34:33 -070098 time_status |= STA_MODE;
99 }
Roman Zippelee9851b2008-05-01 04:34:32 -0700100 freq_adj += time_freq;
Roman Zippel074b3b82008-05-01 04:34:34 -0700101 freq_adj = min(freq_adj, MAXFREQ_SCALED);
102 time_freq = max(freq_adj, -MAXFREQ_SCALED);
Roman Zippel9f14f662008-05-01 04:34:36 -0700103
Roman Zippel7fc5c782008-05-01 04:34:38 -0700104 time_offset = div_s64((s64)offset << NTP_SCALE_SHIFT, NTP_INTERVAL_FREQ);
Roman Zippelee9851b2008-05-01 04:34:32 -0700105}
106
Roman Zippelb0ee7552006-09-30 23:28:22 -0700107/**
108 * ntp_clear - Clears the NTP state variables
109 *
110 * Must be called while holding a write on the xtime_lock
111 */
112void ntp_clear(void)
113{
114 time_adjust = 0; /* stop active adjtime() */
115 time_status |= STA_UNSYNC;
116 time_maxerror = NTP_PHASE_LIMIT;
117 time_esterror = NTP_PHASE_LIMIT;
118
119 ntp_update_frequency();
120
121 tick_length = tick_length_base;
Roman Zippel3d3675c2006-09-30 23:28:25 -0700122 time_offset = 0;
Roman Zippelb0ee7552006-09-30 23:28:22 -0700123}
124
john stultz4c7ee8d2006-09-30 23:28:22 -0700125/*
Roman Zippel7dffa3c2008-05-01 04:34:41 -0700126 * Leap second processing. If in leap-insert state at the end of the
127 * day, the system clock is set back one second; if in leap-delete
128 * state, the system clock is set ahead one second.
129 */
130static enum hrtimer_restart ntp_leap_second(struct hrtimer *timer)
131{
132 enum hrtimer_restart res = HRTIMER_NORESTART;
133
134 write_seqlock_irq(&xtime_lock);
135
136 switch (time_state) {
137 case TIME_OK:
138 break;
139 case TIME_INS:
140 xtime.tv_sec--;
141 wall_to_monotonic.tv_sec++;
142 time_state = TIME_OOP;
143 printk(KERN_NOTICE "Clock: "
144 "inserting leap second 23:59:60 UTC\n");
145 leap_timer.expires = ktime_add_ns(leap_timer.expires,
146 NSEC_PER_SEC);
147 res = HRTIMER_RESTART;
148 break;
149 case TIME_DEL:
150 xtime.tv_sec++;
151 time_tai--;
152 wall_to_monotonic.tv_sec--;
153 time_state = TIME_WAIT;
154 printk(KERN_NOTICE "Clock: "
155 "deleting leap second 23:59:59 UTC\n");
156 break;
157 case TIME_OOP:
158 time_tai++;
159 time_state = TIME_WAIT;
160 /* fall through */
161 case TIME_WAIT:
162 if (!(time_status & (STA_INS | STA_DEL)))
163 time_state = TIME_OK;
164 break;
165 }
166 update_vsyscall(&xtime, clock);
167
168 write_sequnlock_irq(&xtime_lock);
169
170 return res;
171}
172
173/*
john stultz4c7ee8d2006-09-30 23:28:22 -0700174 * this routine handles the overflow of the microsecond field
175 *
176 * The tricky bits of code to handle the accurate clock support
177 * were provided by Dave Mills (Mills@UDEL.EDU) of NTP fame.
178 * They were originally developed for SUN and DEC kernels.
179 * All the kudos should go to Dave for this stuff.
180 */
181void second_overflow(void)
182{
Roman Zippel9f14f662008-05-01 04:34:36 -0700183 s64 time_adj;
john stultz4c7ee8d2006-09-30 23:28:22 -0700184
185 /* Bump the maxerror field */
Roman Zippel074b3b82008-05-01 04:34:34 -0700186 time_maxerror += MAXFREQ / NSEC_PER_USEC;
john stultz4c7ee8d2006-09-30 23:28:22 -0700187 if (time_maxerror > NTP_PHASE_LIMIT) {
188 time_maxerror = NTP_PHASE_LIMIT;
189 time_status |= STA_UNSYNC;
190 }
191
192 /*
Roman Zippelf1992392006-09-30 23:28:28 -0700193 * Compute the phase adjustment for the next second. The offset is
194 * reduced by a fixed factor times the time constant.
john stultz4c7ee8d2006-09-30 23:28:22 -0700195 */
Roman Zippelb0ee7552006-09-30 23:28:22 -0700196 tick_length = tick_length_base;
Roman Zippelf1992392006-09-30 23:28:28 -0700197 time_adj = shift_right(time_offset, SHIFT_PLL + time_constant);
Roman Zippel3d3675c2006-09-30 23:28:25 -0700198 time_offset -= time_adj;
Roman Zippel9f14f662008-05-01 04:34:36 -0700199 tick_length += time_adj;
john stultz4c7ee8d2006-09-30 23:28:22 -0700200
Roman Zippel8f807f82006-09-30 23:28:25 -0700201 if (unlikely(time_adjust)) {
202 if (time_adjust > MAX_TICKADJ) {
203 time_adjust -= MAX_TICKADJ;
204 tick_length += MAX_TICKADJ_SCALED;
205 } else if (time_adjust < -MAX_TICKADJ) {
206 time_adjust += MAX_TICKADJ;
207 tick_length -= MAX_TICKADJ_SCALED;
208 } else {
Roman Zippel8f807f82006-09-30 23:28:25 -0700209 tick_length += (s64)(time_adjust * NSEC_PER_USEC /
Roman Zippel7fc5c782008-05-01 04:34:38 -0700210 NTP_INTERVAL_FREQ) << NTP_SCALE_SHIFT;
Jim Houstonbb1d8602006-10-28 10:38:56 -0700211 time_adjust = 0;
Roman Zippel8f807f82006-09-30 23:28:25 -0700212 }
john stultz4c7ee8d2006-09-30 23:28:22 -0700213 }
214}
215
Thomas Gleixner82644452007-07-21 04:37:37 -0700216#ifdef CONFIG_GENERIC_CMOS_UPDATE
john stultz4c7ee8d2006-09-30 23:28:22 -0700217
Thomas Gleixner82644452007-07-21 04:37:37 -0700218/* Disable the cmos update - used by virtualization and embedded */
219int no_sync_cmos_clock __read_mostly;
220
221static void sync_cmos_clock(unsigned long dummy);
222
223static DEFINE_TIMER(sync_cmos_timer, sync_cmos_clock, 0, 0);
224
225static void sync_cmos_clock(unsigned long dummy)
john stultz4c7ee8d2006-09-30 23:28:22 -0700226{
Thomas Gleixner82644452007-07-21 04:37:37 -0700227 struct timespec now, next;
228 int fail = 1;
229
230 /*
231 * If we have an externally synchronized Linux clock, then update
232 * CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
233 * called as close as possible to 500 ms before the new second starts.
234 * This code is run on a timer. If the clock is set, that timer
235 * may not expire at the correct time. Thus, we adjust...
236 */
237 if (!ntp_synced())
238 /*
239 * Not synced, exit, do not restart a timer (if one is
240 * running, let it run out).
241 */
242 return;
243
244 getnstimeofday(&now);
David P. Reedfa6a1a52007-11-14 17:49:21 -0500245 if (abs(now.tv_nsec - (NSEC_PER_SEC / 2)) <= tick_nsec / 2)
Thomas Gleixner82644452007-07-21 04:37:37 -0700246 fail = update_persistent_clock(now);
247
Maciej W. Rozycki4ff4b9e2008-09-05 14:05:31 -0700248 next.tv_nsec = (NSEC_PER_SEC / 2) - now.tv_nsec - (TICK_NSEC / 2);
Thomas Gleixner82644452007-07-21 04:37:37 -0700249 if (next.tv_nsec <= 0)
250 next.tv_nsec += NSEC_PER_SEC;
251
252 if (!fail)
253 next.tv_sec = 659;
254 else
255 next.tv_sec = 0;
256
257 if (next.tv_nsec >= NSEC_PER_SEC) {
258 next.tv_sec++;
259 next.tv_nsec -= NSEC_PER_SEC;
260 }
261 mod_timer(&sync_cmos_timer, jiffies + timespec_to_jiffies(&next));
john stultz4c7ee8d2006-09-30 23:28:22 -0700262}
263
Thomas Gleixner82644452007-07-21 04:37:37 -0700264static void notify_cmos_timer(void)
265{
Tony Breeds298a5df2007-09-11 15:24:03 -0700266 if (!no_sync_cmos_clock)
Thomas Gleixner82644452007-07-21 04:37:37 -0700267 mod_timer(&sync_cmos_timer, jiffies + 1);
268}
269
270#else
271static inline void notify_cmos_timer(void) { }
272#endif
273
john stultz4c7ee8d2006-09-30 23:28:22 -0700274/* adjtimex mainly allows reading (and writing, if superuser) of
275 * kernel time-keeping variables. used by xntpd.
276 */
277int do_adjtimex(struct timex *txc)
278{
Roman Zippeleea83d82008-05-01 04:34:33 -0700279 struct timespec ts;
Roman Zippel7dffa3c2008-05-01 04:34:41 -0700280 long save_adjust, sec;
john stultz4c7ee8d2006-09-30 23:28:22 -0700281 int result;
282
283 /* In order to modify anything, you gotta be super-user! */
284 if (txc->modes && !capable(CAP_SYS_TIME))
285 return -EPERM;
286
287 /* Now we validate the data before disabling interrupts */
288
John Stultz52bfb362007-11-26 20:42:19 +0100289 if ((txc->modes & ADJ_OFFSET_SINGLESHOT) == ADJ_OFFSET_SINGLESHOT) {
Roman Zippeleea83d82008-05-01 04:34:33 -0700290 /* singleshot must not be used with any other mode bits */
291 if (txc->modes & ~ADJ_OFFSET_SS_READ)
john stultz4c7ee8d2006-09-30 23:28:22 -0700292 return -EINVAL;
John Stultz52bfb362007-11-26 20:42:19 +0100293 }
john stultz4c7ee8d2006-09-30 23:28:22 -0700294
john stultz4c7ee8d2006-09-30 23:28:22 -0700295 /* if the quartz is off by more than 10% something is VERY wrong ! */
296 if (txc->modes & ADJ_TICK)
297 if (txc->tick < 900000/USER_HZ ||
298 txc->tick > 1100000/USER_HZ)
299 return -EINVAL;
300
Roman Zippel7dffa3c2008-05-01 04:34:41 -0700301 if (time_state != TIME_OK && txc->modes & ADJ_STATUS)
302 hrtimer_cancel(&leap_timer);
303 getnstimeofday(&ts);
304
john stultz4c7ee8d2006-09-30 23:28:22 -0700305 write_seqlock_irq(&xtime_lock);
john stultz4c7ee8d2006-09-30 23:28:22 -0700306
307 /* Save for later - semantics of adjtime is to return old value */
Roman Zippel8f807f82006-09-30 23:28:25 -0700308 save_adjust = time_adjust;
john stultz4c7ee8d2006-09-30 23:28:22 -0700309
john stultz4c7ee8d2006-09-30 23:28:22 -0700310 /* If there are input parameters, then process them */
Roman Zippelee9851b2008-05-01 04:34:32 -0700311 if (txc->modes) {
Roman Zippeleea83d82008-05-01 04:34:33 -0700312 if (txc->modes & ADJ_STATUS) {
313 if ((time_status & STA_PLL) &&
314 !(txc->status & STA_PLL)) {
315 time_state = TIME_OK;
316 time_status = STA_UNSYNC;
317 }
318 /* only set allowed bits */
319 time_status &= STA_RONLY;
320 time_status |= txc->status & ~STA_RONLY;
Roman Zippel7dffa3c2008-05-01 04:34:41 -0700321
322 switch (time_state) {
323 case TIME_OK:
324 start_timer:
325 sec = ts.tv_sec;
326 if (time_status & STA_INS) {
327 time_state = TIME_INS;
328 sec += 86400 - sec % 86400;
329 hrtimer_start(&leap_timer, ktime_set(sec, 0), HRTIMER_MODE_ABS);
330 } else if (time_status & STA_DEL) {
331 time_state = TIME_DEL;
332 sec += 86400 - (sec + 1) % 86400;
333 hrtimer_start(&leap_timer, ktime_set(sec, 0), HRTIMER_MODE_ABS);
334 }
335 break;
336 case TIME_INS:
337 case TIME_DEL:
338 time_state = TIME_OK;
339 goto start_timer;
340 break;
341 case TIME_WAIT:
342 if (!(time_status & (STA_INS | STA_DEL)))
343 time_state = TIME_OK;
344 break;
345 case TIME_OOP:
346 hrtimer_restart(&leap_timer);
347 break;
348 }
Roman Zippeleea83d82008-05-01 04:34:33 -0700349 }
350
351 if (txc->modes & ADJ_NANO)
352 time_status |= STA_NANO;
353 if (txc->modes & ADJ_MICRO)
354 time_status &= ~STA_NANO;
john stultz4c7ee8d2006-09-30 23:28:22 -0700355
Roman Zippelee9851b2008-05-01 04:34:32 -0700356 if (txc->modes & ADJ_FREQUENCY) {
Roman Zippel074b3b82008-05-01 04:34:34 -0700357 time_freq = (s64)txc->freq * PPM_SCALE;
358 time_freq = min(time_freq, MAXFREQ_SCALED);
359 time_freq = max(time_freq, -MAXFREQ_SCALED);
john stultz4c7ee8d2006-09-30 23:28:22 -0700360 }
john stultz4c7ee8d2006-09-30 23:28:22 -0700361
Roman Zippeleea83d82008-05-01 04:34:33 -0700362 if (txc->modes & ADJ_MAXERROR)
Roman Zippelee9851b2008-05-01 04:34:32 -0700363 time_maxerror = txc->maxerror;
Roman Zippeleea83d82008-05-01 04:34:33 -0700364 if (txc->modes & ADJ_ESTERROR)
Roman Zippelee9851b2008-05-01 04:34:32 -0700365 time_esterror = txc->esterror;
john stultz4c7ee8d2006-09-30 23:28:22 -0700366
Roman Zippelee9851b2008-05-01 04:34:32 -0700367 if (txc->modes & ADJ_TIMECONST) {
Roman Zippeleea83d82008-05-01 04:34:33 -0700368 time_constant = txc->constant;
369 if (!(time_status & STA_NANO))
370 time_constant += 4;
371 time_constant = min(time_constant, (long)MAXTC);
372 time_constant = max(time_constant, 0l);
john stultz4c7ee8d2006-09-30 23:28:22 -0700373 }
john stultz4c7ee8d2006-09-30 23:28:22 -0700374
Roman Zippel153b5d02008-05-01 04:34:37 -0700375 if (txc->modes & ADJ_TAI && txc->constant > 0)
376 time_tai = txc->constant;
377
Roman Zippelee9851b2008-05-01 04:34:32 -0700378 if (txc->modes & ADJ_OFFSET) {
379 if (txc->modes == ADJ_OFFSET_SINGLESHOT)
380 /* adjtime() is independent from ntp_adjtime() */
381 time_adjust = txc->offset;
382 else
383 ntp_update_offset(txc->offset);
john stultz4c7ee8d2006-09-30 23:28:22 -0700384 }
Roman Zippelee9851b2008-05-01 04:34:32 -0700385 if (txc->modes & ADJ_TICK)
386 tick_usec = txc->tick;
john stultz4c7ee8d2006-09-30 23:28:22 -0700387
Roman Zippelee9851b2008-05-01 04:34:32 -0700388 if (txc->modes & (ADJ_TICK|ADJ_FREQUENCY|ADJ_OFFSET))
389 ntp_update_frequency();
390 }
Roman Zippeleea83d82008-05-01 04:34:33 -0700391
392 result = time_state; /* mostly `TIME_OK' */
Roman Zippelee9851b2008-05-01 04:34:32 -0700393 if (time_status & (STA_UNSYNC|STA_CLOCKERR))
john stultz4c7ee8d2006-09-30 23:28:22 -0700394 result = TIME_ERROR;
395
John Stultz52bfb362007-11-26 20:42:19 +0100396 if ((txc->modes == ADJ_OFFSET_SINGLESHOT) ||
Roman Zippelee9851b2008-05-01 04:34:32 -0700397 (txc->modes == ADJ_OFFSET_SS_READ))
john stultzd62ac212007-03-26 21:32:26 -0800398 txc->offset = save_adjust;
Roman Zippeleea83d82008-05-01 04:34:33 -0700399 else {
Roman Zippel9f14f662008-05-01 04:34:36 -0700400 txc->offset = shift_right(time_offset * NTP_INTERVAL_FREQ,
Roman Zippel7fc5c782008-05-01 04:34:38 -0700401 NTP_SCALE_SHIFT);
Roman Zippeleea83d82008-05-01 04:34:33 -0700402 if (!(time_status & STA_NANO))
403 txc->offset /= NSEC_PER_USEC;
404 }
Roman Zippel074b3b82008-05-01 04:34:34 -0700405 txc->freq = shift_right((s32)(time_freq >> PPM_SCALE_INV_SHIFT) *
406 (s64)PPM_SCALE_INV,
Roman Zippel7fc5c782008-05-01 04:34:38 -0700407 NTP_SCALE_SHIFT);
john stultz4c7ee8d2006-09-30 23:28:22 -0700408 txc->maxerror = time_maxerror;
409 txc->esterror = time_esterror;
410 txc->status = time_status;
411 txc->constant = time_constant;
Adrian Bunk70bc42f2006-09-30 23:28:29 -0700412 txc->precision = 1;
Roman Zippel074b3b82008-05-01 04:34:34 -0700413 txc->tolerance = MAXFREQ_SCALED / PPM_SCALE;
john stultz4c7ee8d2006-09-30 23:28:22 -0700414 txc->tick = tick_usec;
Roman Zippel153b5d02008-05-01 04:34:37 -0700415 txc->tai = time_tai;
john stultz4c7ee8d2006-09-30 23:28:22 -0700416
417 /* PPS is not implemented, so these are zero */
418 txc->ppsfreq = 0;
419 txc->jitter = 0;
420 txc->shift = 0;
421 txc->stabil = 0;
422 txc->jitcnt = 0;
423 txc->calcnt = 0;
424 txc->errcnt = 0;
425 txc->stbcnt = 0;
426 write_sequnlock_irq(&xtime_lock);
Roman Zippelee9851b2008-05-01 04:34:32 -0700427
Roman Zippeleea83d82008-05-01 04:34:33 -0700428 txc->time.tv_sec = ts.tv_sec;
429 txc->time.tv_usec = ts.tv_nsec;
430 if (!(time_status & STA_NANO))
431 txc->time.tv_usec /= NSEC_PER_USEC;
Roman Zippelee9851b2008-05-01 04:34:32 -0700432
Thomas Gleixner82644452007-07-21 04:37:37 -0700433 notify_cmos_timer();
Roman Zippelee9851b2008-05-01 04:34:32 -0700434
435 return result;
john stultz4c7ee8d2006-09-30 23:28:22 -0700436}
Roman Zippel10a398d2008-03-04 15:14:26 -0800437
438static int __init ntp_tick_adj_setup(char *str)
439{
440 ntp_tick_adj = simple_strtol(str, NULL, 0);
441 return 1;
442}
443
444__setup("ntp_tick_adj=", ntp_tick_adj_setup);
Roman Zippel7dffa3c2008-05-01 04:34:41 -0700445
446void __init ntp_init(void)
447{
448 ntp_clear();
449 hrtimer_init(&leap_timer, CLOCK_REALTIME, HRTIMER_MODE_ABS);
450 leap_timer.function = ntp_leap_second;
451}