aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/alpha/kernel/time.c7
-rw-r--r--arch/arm/kernel/time.c7
-rw-r--r--arch/arm26/kernel/time.c7
-rw-r--r--arch/cris/arch-v10/kernel/time.c2
-rw-r--r--arch/cris/kernel/time.c5
-rw-r--r--arch/frv/kernel/time.c7
-rw-r--r--arch/h8300/kernel/time.c5
-rw-r--r--arch/i386/kernel/time.c7
-rw-r--r--arch/m32r/kernel/time.c7
-rw-r--r--arch/m68k/kernel/time.c5
-rw-r--r--arch/m68knommu/kernel/time.c7
-rw-r--r--arch/mips/kernel/sysirix.c5
-rw-r--r--arch/mips/kernel/time.c7
-rw-r--r--arch/mips/sgi-ip27/ip27-timer.c2
-rw-r--r--arch/parisc/kernel/time.c5
-rw-r--r--arch/ppc/kernel/time.c7
-rw-r--r--arch/ppc64/kernel/time.c7
-rw-r--r--arch/s390/kernel/time.c5
-rw-r--r--arch/sh/kernel/time.c7
-rw-r--r--arch/sh64/kernel/time.c7
-rw-r--r--arch/sparc/kernel/pcic.c5
-rw-r--r--arch/sparc/kernel/time.c7
-rw-r--r--arch/sparc64/kernel/time.c2
-rw-r--r--arch/v850/kernel/time.c7
-rw-r--r--arch/x86_64/kernel/time.c7
-rw-r--r--arch/xtensa/kernel/time.c7
-rw-r--r--include/linux/timex.h23
27 files changed, 65 insertions, 111 deletions
diff --git a/arch/alpha/kernel/time.c b/arch/alpha/kernel/time.c
index 8226c5cd788c..67be50b7d80a 100644
--- a/arch/alpha/kernel/time.c
+++ b/arch/alpha/kernel/time.c
@@ -149,7 +149,7 @@ irqreturn_t timer_interrupt(int irq, void *dev, struct pt_regs * regs)
149 * CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be 149 * CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
150 * called as close as possible to 500 ms before the new second starts. 150 * called as close as possible to 500 ms before the new second starts.
151 */ 151 */
152 if ((time_status & STA_UNSYNC) == 0 152 if (ntp_synced()
153 && xtime.tv_sec > state.last_rtc_update + 660 153 && xtime.tv_sec > state.last_rtc_update + 660
154 && xtime.tv_nsec >= 500000 - ((unsigned) TICK_SIZE) / 2 154 && xtime.tv_nsec >= 500000 - ((unsigned) TICK_SIZE) / 2
155 && xtime.tv_nsec <= 500000 + ((unsigned) TICK_SIZE) / 2) { 155 && xtime.tv_nsec <= 500000 + ((unsigned) TICK_SIZE) / 2) {
@@ -502,10 +502,7 @@ do_settimeofday(struct timespec *tv)
502 set_normalized_timespec(&xtime, sec, nsec); 502 set_normalized_timespec(&xtime, sec, nsec);
503 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec); 503 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
504 504
505 time_adjust = 0; /* stop active adjtime() */ 505 ntp_clear();
506 time_status |= STA_UNSYNC;
507 time_maxerror = NTP_PHASE_LIMIT;
508 time_esterror = NTP_PHASE_LIMIT;
509 506
510 write_sequnlock_irq(&xtime_lock); 507 write_sequnlock_irq(&xtime_lock);
511 clock_was_set(); 508 clock_was_set();
diff --git a/arch/arm/kernel/time.c b/arch/arm/kernel/time.c
index 8880482dcbff..69449a818dcc 100644
--- a/arch/arm/kernel/time.c
+++ b/arch/arm/kernel/time.c
@@ -102,7 +102,7 @@ static unsigned long next_rtc_update;
102 */ 102 */
103static inline void do_set_rtc(void) 103static inline void do_set_rtc(void)
104{ 104{
105 if (time_status & STA_UNSYNC || set_rtc == NULL) 105 if (!ntp_synced() || set_rtc == NULL)
106 return; 106 return;
107 107
108 if (next_rtc_update && 108 if (next_rtc_update &&
@@ -292,10 +292,7 @@ int do_settimeofday(struct timespec *tv)
292 set_normalized_timespec(&xtime, sec, nsec); 292 set_normalized_timespec(&xtime, sec, nsec);
293 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec); 293 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
294 294
295 time_adjust = 0; /* stop active adjtime() */ 295 ntp_clear();
296 time_status |= STA_UNSYNC;
297 time_maxerror = NTP_PHASE_LIMIT;
298 time_esterror = NTP_PHASE_LIMIT;
299 write_sequnlock_irq(&xtime_lock); 296 write_sequnlock_irq(&xtime_lock);
300 clock_was_set(); 297 clock_was_set();
301 return 0; 298 return 0;
diff --git a/arch/arm26/kernel/time.c b/arch/arm26/kernel/time.c
index 549a6b2e177e..e66aedd02fad 100644
--- a/arch/arm26/kernel/time.c
+++ b/arch/arm26/kernel/time.c
@@ -114,7 +114,7 @@ static unsigned long next_rtc_update;
114 */ 114 */
115static inline void do_set_rtc(void) 115static inline void do_set_rtc(void)
116{ 116{
117 if (time_status & STA_UNSYNC || set_rtc == NULL) 117 if (!ntp_synced() || set_rtc == NULL)
118 return; 118 return;
119 119
120//FIXME - timespec.tv_sec is a time_t not unsigned long 120//FIXME - timespec.tv_sec is a time_t not unsigned long
@@ -189,10 +189,7 @@ int do_settimeofday(struct timespec *tv)
189 189
190 xtime.tv_sec = tv->tv_sec; 190 xtime.tv_sec = tv->tv_sec;
191 xtime.tv_nsec = tv->tv_nsec; 191 xtime.tv_nsec = tv->tv_nsec;
192 time_adjust = 0; /* stop active adjtime() */ 192 ntp_clear();
193 time_status |= STA_UNSYNC;
194 time_maxerror = NTP_PHASE_LIMIT;
195 time_esterror = NTP_PHASE_LIMIT;
196 write_sequnlock_irq(&xtime_lock); 193 write_sequnlock_irq(&xtime_lock);
197 clock_was_set(); 194 clock_was_set();
198 return 0; 195 return 0;
diff --git a/arch/cris/arch-v10/kernel/time.c b/arch/cris/arch-v10/kernel/time.c
index 6b7b4e0802e3..dc3dfe9b4a1a 100644
--- a/arch/cris/arch-v10/kernel/time.c
+++ b/arch/cris/arch-v10/kernel/time.c
@@ -240,7 +240,7 @@ timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
240 * The division here is not time critical since it will run once in 240 * The division here is not time critical since it will run once in
241 * 11 minutes 241 * 11 minutes
242 */ 242 */
243 if ((time_status & STA_UNSYNC) == 0 && 243 if (ntp_synced() &&
244 xtime.tv_sec > last_rtc_update + 660 && 244 xtime.tv_sec > last_rtc_update + 660 &&
245 (xtime.tv_nsec / 1000) >= 500000 - (tick_nsec / 1000) / 2 && 245 (xtime.tv_nsec / 1000) >= 500000 - (tick_nsec / 1000) / 2 &&
246 (xtime.tv_nsec / 1000) <= 500000 + (tick_nsec / 1000) / 2) { 246 (xtime.tv_nsec / 1000) <= 500000 + (tick_nsec / 1000) / 2) {
diff --git a/arch/cris/kernel/time.c b/arch/cris/kernel/time.c
index fa2d4323da25..a2d99b4aedcd 100644
--- a/arch/cris/kernel/time.c
+++ b/arch/cris/kernel/time.c
@@ -114,10 +114,7 @@ int do_settimeofday(struct timespec *tv)
114 set_normalized_timespec(&xtime, sec, nsec); 114 set_normalized_timespec(&xtime, sec, nsec);
115 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec); 115 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
116 116
117 time_adjust = 0; /* stop active adjtime() */ 117 ntp_clear();
118 time_status |= STA_UNSYNC;
119 time_maxerror = NTP_PHASE_LIMIT;
120 time_esterror = NTP_PHASE_LIMIT;
121 write_sequnlock_irq(&xtime_lock); 118 write_sequnlock_irq(&xtime_lock);
122 clock_was_set(); 119 clock_was_set();
123 return 0; 120 return 0;
diff --git a/arch/frv/kernel/time.c b/arch/frv/kernel/time.c
index 075db6644694..8d6558b00e44 100644
--- a/arch/frv/kernel/time.c
+++ b/arch/frv/kernel/time.c
@@ -85,7 +85,7 @@ static irqreturn_t timer_interrupt(int irq, void *dummy, struct pt_regs * regs)
85 * CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be 85 * CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
86 * called as close as possible to 500 ms before the new second starts. 86 * called as close as possible to 500 ms before the new second starts.
87 */ 87 */
88 if ((time_status & STA_UNSYNC) == 0 && 88 if (ntp_synced() &&
89 xtime.tv_sec > last_rtc_update + 660 && 89 xtime.tv_sec > last_rtc_update + 660 &&
90 (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 && 90 (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 &&
91 (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2 91 (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2
@@ -216,10 +216,7 @@ int do_settimeofday(struct timespec *tv)
216 set_normalized_timespec(&xtime, sec, nsec); 216 set_normalized_timespec(&xtime, sec, nsec);
217 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec); 217 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
218 218
219 time_adjust = 0; /* stop active adjtime() */ 219 ntp_clear();
220 time_status |= STA_UNSYNC;
221 time_maxerror = NTP_PHASE_LIMIT;
222 time_esterror = NTP_PHASE_LIMIT;
223 write_sequnlock_irq(&xtime_lock); 220 write_sequnlock_irq(&xtime_lock);
224 clock_was_set(); 221 clock_was_set();
225 return 0; 222 return 0;
diff --git a/arch/h8300/kernel/time.c b/arch/h8300/kernel/time.c
index 8a600218334d..af8c5d2057dd 100644
--- a/arch/h8300/kernel/time.c
+++ b/arch/h8300/kernel/time.c
@@ -116,10 +116,7 @@ int do_settimeofday(struct timespec *tv)
116 116
117 xtime.tv_sec = tv->tv_sec; 117 xtime.tv_sec = tv->tv_sec;
118 xtime.tv_nsec = tv->tv_nsec; 118 xtime.tv_nsec = tv->tv_nsec;
119 time_adjust = 0; /* stop active adjtime() */ 119 ntp_clear();
120 time_status |= STA_UNSYNC;
121 time_maxerror = NTP_PHASE_LIMIT;
122 time_esterror = NTP_PHASE_LIMIT;
123 write_sequnlock_irq(&xtime_lock); 120 write_sequnlock_irq(&xtime_lock);
124 clock_was_set(); 121 clock_was_set();
125 return 0; 122 return 0;
diff --git a/arch/i386/kernel/time.c b/arch/i386/kernel/time.c
index 9b94d84a6c3b..eefea7c55008 100644
--- a/arch/i386/kernel/time.c
+++ b/arch/i386/kernel/time.c
@@ -194,10 +194,7 @@ int do_settimeofday(struct timespec *tv)
194 set_normalized_timespec(&xtime, sec, nsec); 194 set_normalized_timespec(&xtime, sec, nsec);
195 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec); 195 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
196 196
197 time_adjust = 0; /* stop active adjtime() */ 197 ntp_clear();
198 time_status |= STA_UNSYNC;
199 time_maxerror = NTP_PHASE_LIMIT;
200 time_esterror = NTP_PHASE_LIMIT;
201 write_sequnlock_irq(&xtime_lock); 198 write_sequnlock_irq(&xtime_lock);
202 clock_was_set(); 199 clock_was_set();
203 return 0; 200 return 0;
@@ -347,7 +344,7 @@ static void sync_cmos_clock(unsigned long dummy)
347 * This code is run on a timer. If the clock is set, that timer 344 * This code is run on a timer. If the clock is set, that timer
348 * may not expire at the correct time. Thus, we adjust... 345 * may not expire at the correct time. Thus, we adjust...
349 */ 346 */
350 if ((time_status & STA_UNSYNC) != 0) 347 if (!ntp_synced())
351 /* 348 /*
352 * Not synced, exit, do not restart a timer (if one is 349 * Not synced, exit, do not restart a timer (if one is
353 * running, let it run out). 350 * running, let it run out).
diff --git a/arch/m32r/kernel/time.c b/arch/m32r/kernel/time.c
index 8a2b77bc5749..539c562cd54d 100644
--- a/arch/m32r/kernel/time.c
+++ b/arch/m32r/kernel/time.c
@@ -171,10 +171,7 @@ int do_settimeofday(struct timespec *tv)
171 set_normalized_timespec(&xtime, sec, nsec); 171 set_normalized_timespec(&xtime, sec, nsec);
172 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec); 172 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
173 173
174 time_adjust = 0; /* stop active adjtime() */ 174 ntp_clear();
175 time_status |= STA_UNSYNC;
176 time_maxerror = NTP_PHASE_LIMIT;
177 time_esterror = NTP_PHASE_LIMIT;
178 write_sequnlock_irq(&xtime_lock); 175 write_sequnlock_irq(&xtime_lock);
179 clock_was_set(); 176 clock_was_set();
180 177
@@ -221,7 +218,7 @@ irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
221 * called as close as possible to 500 ms before the new second starts. 218 * called as close as possible to 500 ms before the new second starts.
222 */ 219 */
223 write_seqlock(&xtime_lock); 220 write_seqlock(&xtime_lock);
224 if ((time_status & STA_UNSYNC) == 0 221 if (ntp_synced()
225 && xtime.tv_sec > last_rtc_update + 660 222 && xtime.tv_sec > last_rtc_update + 660
226 && (xtime.tv_nsec / 1000) >= 500000 - ((unsigned)TICK_SIZE) / 2 223 && (xtime.tv_nsec / 1000) >= 500000 - ((unsigned)TICK_SIZE) / 2
227 && (xtime.tv_nsec / 1000) <= 500000 + ((unsigned)TICK_SIZE) / 2) 224 && (xtime.tv_nsec / 1000) <= 500000 + ((unsigned)TICK_SIZE) / 2)
diff --git a/arch/m68k/kernel/time.c b/arch/m68k/kernel/time.c
index e47e19588525..4ec95e3cb874 100644
--- a/arch/m68k/kernel/time.c
+++ b/arch/m68k/kernel/time.c
@@ -166,10 +166,7 @@ int do_settimeofday(struct timespec *tv)
166 set_normalized_timespec(&xtime, sec, nsec); 166 set_normalized_timespec(&xtime, sec, nsec);
167 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec); 167 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
168 168
169 time_adjust = 0; /* stop active adjtime() */ 169 ntp_clear();
170 time_status |= STA_UNSYNC;
171 time_maxerror = NTP_PHASE_LIMIT;
172 time_esterror = NTP_PHASE_LIMIT;
173 write_sequnlock_irq(&xtime_lock); 170 write_sequnlock_irq(&xtime_lock);
174 clock_was_set(); 171 clock_was_set();
175 return 0; 172 return 0;
diff --git a/arch/m68knommu/kernel/time.c b/arch/m68knommu/kernel/time.c
index 5c3ca671627c..b17c1ecba966 100644
--- a/arch/m68knommu/kernel/time.c
+++ b/arch/m68knommu/kernel/time.c
@@ -68,7 +68,7 @@ static irqreturn_t timer_interrupt(int irq, void *dummy, struct pt_regs * regs)
68 * CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be 68 * CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
69 * called as close as possible to 500 ms before the new second starts. 69 * called as close as possible to 500 ms before the new second starts.
70 */ 70 */
71 if ((time_status & STA_UNSYNC) == 0 && 71 if (ntp_synced() &&
72 xtime.tv_sec > last_rtc_update + 660 && 72 xtime.tv_sec > last_rtc_update + 660 &&
73 (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 && 73 (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 &&
74 (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2) { 74 (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2) {
@@ -178,10 +178,7 @@ int do_settimeofday(struct timespec *tv)
178 set_normalized_timespec(&xtime, sec, nsec); 178 set_normalized_timespec(&xtime, sec, nsec);
179 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec); 179 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
180 180
181 time_adjust = 0; /* stop active adjtime() */ 181 ntp_clear();
182 time_status |= STA_UNSYNC;
183 time_maxerror = NTP_PHASE_LIMIT;
184 time_esterror = NTP_PHASE_LIMIT;
185 write_sequnlock_irq(&xtime_lock); 182 write_sequnlock_irq(&xtime_lock);
186 clock_was_set(); 183 clock_was_set();
187 return 0; 184 return 0;
diff --git a/arch/mips/kernel/sysirix.c b/arch/mips/kernel/sysirix.c
index f3bf0e43b8bb..b46595462717 100644
--- a/arch/mips/kernel/sysirix.c
+++ b/arch/mips/kernel/sysirix.c
@@ -632,10 +632,7 @@ asmlinkage int irix_stime(int value)
632 write_seqlock_irq(&xtime_lock); 632 write_seqlock_irq(&xtime_lock);
633 xtime.tv_sec = value; 633 xtime.tv_sec = value;
634 xtime.tv_nsec = 0; 634 xtime.tv_nsec = 0;
635 time_adjust = 0; /* stop active adjtime() */ 635 ntp_clear();
636 time_status |= STA_UNSYNC;
637 time_maxerror = NTP_PHASE_LIMIT;
638 time_esterror = NTP_PHASE_LIMIT;
639 write_sequnlock_irq(&xtime_lock); 636 write_sequnlock_irq(&xtime_lock);
640 637
641 return 0; 638 return 0;
diff --git a/arch/mips/kernel/time.c b/arch/mips/kernel/time.c
index 648c82292ed6..0dd0df7a3b04 100644
--- a/arch/mips/kernel/time.c
+++ b/arch/mips/kernel/time.c
@@ -223,10 +223,7 @@ int do_settimeofday(struct timespec *tv)
223 set_normalized_timespec(&xtime, sec, nsec); 223 set_normalized_timespec(&xtime, sec, nsec);
224 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec); 224 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
225 225
226 time_adjust = 0; /* stop active adjtime() */ 226 ntp_clear();
227 time_status |= STA_UNSYNC;
228 time_maxerror = NTP_PHASE_LIMIT;
229 time_esterror = NTP_PHASE_LIMIT;
230 227
231 write_sequnlock_irq(&xtime_lock); 228 write_sequnlock_irq(&xtime_lock);
232 clock_was_set(); 229 clock_was_set();
@@ -442,7 +439,7 @@ irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
442 * called as close as possible to 500 ms before the new second starts. 439 * called as close as possible to 500 ms before the new second starts.
443 */ 440 */
444 write_seqlock(&xtime_lock); 441 write_seqlock(&xtime_lock);
445 if ((time_status & STA_UNSYNC) == 0 && 442 if (ntp_synced() &&
446 xtime.tv_sec > last_rtc_update + 660 && 443 xtime.tv_sec > last_rtc_update + 660 &&
447 (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 && 444 (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 &&
448 (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2) { 445 (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2) {
diff --git a/arch/mips/sgi-ip27/ip27-timer.c b/arch/mips/sgi-ip27/ip27-timer.c
index 8c1b96fffa76..cddf1cedf007 100644
--- a/arch/mips/sgi-ip27/ip27-timer.c
+++ b/arch/mips/sgi-ip27/ip27-timer.c
@@ -118,7 +118,7 @@ again:
118 * RTC clock accordingly every ~11 minutes. Set_rtc_mmss() has to be 118 * RTC clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
119 * called as close as possible to when a second starts. 119 * called as close as possible to when a second starts.
120 */ 120 */
121 if ((time_status & STA_UNSYNC) == 0 && 121 if (ntp_synced() &&
122 xtime.tv_sec > last_rtc_update + 660 && 122 xtime.tv_sec > last_rtc_update + 660 &&
123 (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 && 123 (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 &&
124 (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2) { 124 (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2) {
diff --git a/arch/parisc/kernel/time.c b/arch/parisc/kernel/time.c
index 6cf7407344ba..7ff67f8e9f8c 100644
--- a/arch/parisc/kernel/time.c
+++ b/arch/parisc/kernel/time.c
@@ -188,10 +188,7 @@ do_settimeofday (struct timespec *tv)
188 set_normalized_timespec(&xtime, sec, nsec); 188 set_normalized_timespec(&xtime, sec, nsec);
189 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec); 189 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
190 190
191 time_adjust = 0; /* stop active adjtime() */ 191 ntp_clear();
192 time_status |= STA_UNSYNC;
193 time_maxerror = NTP_PHASE_LIMIT;
194 time_esterror = NTP_PHASE_LIMIT;
195 } 192 }
196 write_sequnlock_irq(&xtime_lock); 193 write_sequnlock_irq(&xtime_lock);
197 clock_was_set(); 194 clock_was_set();
diff --git a/arch/ppc/kernel/time.c b/arch/ppc/kernel/time.c
index bf4ddca5e853..a3c5281a5d2d 100644
--- a/arch/ppc/kernel/time.c
+++ b/arch/ppc/kernel/time.c
@@ -169,7 +169,7 @@ void timer_interrupt(struct pt_regs * regs)
169 * We should have an rtc call that only sets the minutes and 169 * We should have an rtc call that only sets the minutes and
170 * seconds like on Intel to avoid problems with non UTC clocks. 170 * seconds like on Intel to avoid problems with non UTC clocks.
171 */ 171 */
172 if ( ppc_md.set_rtc_time && (time_status & STA_UNSYNC) == 0 && 172 if ( ppc_md.set_rtc_time && ntp_synced() &&
173 xtime.tv_sec - last_rtc_update >= 659 && 173 xtime.tv_sec - last_rtc_update >= 659 &&
174 abs((xtime.tv_nsec / 1000) - (1000000-1000000/HZ)) < 500000/HZ && 174 abs((xtime.tv_nsec / 1000) - (1000000-1000000/HZ)) < 500000/HZ &&
175 jiffies - wall_jiffies == 1) { 175 jiffies - wall_jiffies == 1) {
@@ -271,10 +271,7 @@ int do_settimeofday(struct timespec *tv)
271 */ 271 */
272 last_rtc_update = new_sec - 658; 272 last_rtc_update = new_sec - 658;
273 273
274 time_adjust = 0; /* stop active adjtime() */ 274 ntp_clear();
275 time_status |= STA_UNSYNC;
276 time_maxerror = NTP_PHASE_LIMIT;
277 time_esterror = NTP_PHASE_LIMIT;
278 write_sequnlock_irqrestore(&xtime_lock, flags); 275 write_sequnlock_irqrestore(&xtime_lock, flags);
279 clock_was_set(); 276 clock_was_set();
280 return 0; 277 return 0;
diff --git a/arch/ppc64/kernel/time.c b/arch/ppc64/kernel/time.c
index 91ef95ccda4f..9939c206afa4 100644
--- a/arch/ppc64/kernel/time.c
+++ b/arch/ppc64/kernel/time.c
@@ -128,7 +128,7 @@ static __inline__ void timer_check_rtc(void)
128 * We should have an rtc call that only sets the minutes and 128 * We should have an rtc call that only sets the minutes and
129 * seconds like on Intel to avoid problems with non UTC clocks. 129 * seconds like on Intel to avoid problems with non UTC clocks.
130 */ 130 */
131 if ( (time_status & STA_UNSYNC) == 0 && 131 if (ntp_synced() &&
132 xtime.tv_sec - last_rtc_update >= 659 && 132 xtime.tv_sec - last_rtc_update >= 659 &&
133 abs((xtime.tv_nsec/1000) - (1000000-1000000/HZ)) < 500000/HZ && 133 abs((xtime.tv_nsec/1000) - (1000000-1000000/HZ)) < 500000/HZ &&
134 jiffies - wall_jiffies == 1) { 134 jiffies - wall_jiffies == 1) {
@@ -435,10 +435,7 @@ int do_settimeofday(struct timespec *tv)
435 */ 435 */
436 last_rtc_update = new_sec - 658; 436 last_rtc_update = new_sec - 658;
437 437
438 time_adjust = 0; /* stop active adjtime() */ 438 ntp_clear();
439 time_status |= STA_UNSYNC;
440 time_maxerror = NTP_PHASE_LIMIT;
441 time_esterror = NTP_PHASE_LIMIT;
442 439
443 delta_xsec = mulhdu( (tb_last_stamp-do_gtod.varp->tb_orig_stamp), 440 delta_xsec = mulhdu( (tb_last_stamp-do_gtod.varp->tb_orig_stamp),
444 do_gtod.varp->tb_to_xs ); 441 do_gtod.varp->tb_to_xs );
diff --git a/arch/s390/kernel/time.c b/arch/s390/kernel/time.c
index 8ca485676780..2fd75da15495 100644
--- a/arch/s390/kernel/time.c
+++ b/arch/s390/kernel/time.c
@@ -139,10 +139,7 @@ int do_settimeofday(struct timespec *tv)
139 set_normalized_timespec(&xtime, sec, nsec); 139 set_normalized_timespec(&xtime, sec, nsec);
140 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec); 140 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
141 141
142 time_adjust = 0; /* stop active adjtime() */ 142 ntp_clear();
143 time_status |= STA_UNSYNC;
144 time_maxerror = NTP_PHASE_LIMIT;
145 time_esterror = NTP_PHASE_LIMIT;
146 write_sequnlock_irq(&xtime_lock); 143 write_sequnlock_irq(&xtime_lock);
147 clock_was_set(); 144 clock_was_set();
148 return 0; 145 return 0;
diff --git a/arch/sh/kernel/time.c b/arch/sh/kernel/time.c
index d5f5aedde0a3..02ca69918d7c 100644
--- a/arch/sh/kernel/time.c
+++ b/arch/sh/kernel/time.c
@@ -215,10 +215,7 @@ int do_settimeofday(struct timespec *tv)
215 set_normalized_timespec(&xtime, sec, nsec); 215 set_normalized_timespec(&xtime, sec, nsec);
216 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec); 216 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
217 217
218 time_adjust = 0; /* stop active adjtime() */ 218 ntp_clear();
219 time_status |= STA_UNSYNC;
220 time_maxerror = NTP_PHASE_LIMIT;
221 time_esterror = NTP_PHASE_LIMIT;
222 write_sequnlock_irq(&xtime_lock); 219 write_sequnlock_irq(&xtime_lock);
223 clock_was_set(); 220 clock_was_set();
224 221
@@ -252,7 +249,7 @@ static inline void do_timer_interrupt(int irq, struct pt_regs *regs)
252 * RTC clock accordingly every ~11 minutes. Set_rtc_mmss() has to be 249 * RTC clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
253 * called as close as possible to 500 ms before the new second starts. 250 * called as close as possible to 500 ms before the new second starts.
254 */ 251 */
255 if ((time_status & STA_UNSYNC) == 0 && 252 if (ntp_synced() &&
256 xtime.tv_sec > last_rtc_update + 660 && 253 xtime.tv_sec > last_rtc_update + 660 &&
257 (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 && 254 (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 &&
258 (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2) { 255 (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2) {
diff --git a/arch/sh64/kernel/time.c b/arch/sh64/kernel/time.c
index 926c6fc0619c..f4a62a10053c 100644
--- a/arch/sh64/kernel/time.c
+++ b/arch/sh64/kernel/time.c
@@ -247,10 +247,7 @@ int do_settimeofday(struct timespec *tv)
247 set_normalized_timespec(&xtime, sec, nsec); 247 set_normalized_timespec(&xtime, sec, nsec);
248 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec); 248 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
249 249
250 time_adjust = 0; /* stop active adjtime() */ 250 ntp_clear();
251 time_status |= STA_UNSYNC;
252 time_maxerror = NTP_PHASE_LIMIT;
253 time_esterror = NTP_PHASE_LIMIT;
254 write_sequnlock_irq(&xtime_lock); 251 write_sequnlock_irq(&xtime_lock);
255 clock_was_set(); 252 clock_was_set();
256 253
@@ -328,7 +325,7 @@ static inline void do_timer_interrupt(int irq, struct pt_regs *regs)
328 * RTC clock accordingly every ~11 minutes. Set_rtc_mmss() has to be 325 * RTC clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
329 * called as close as possible to 500 ms before the new second starts. 326 * called as close as possible to 500 ms before the new second starts.
330 */ 327 */
331 if ((time_status & STA_UNSYNC) == 0 && 328 if (ntp_synced() &&
332 xtime.tv_sec > last_rtc_update + 660 && 329 xtime.tv_sec > last_rtc_update + 660 &&
333 (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 && 330 (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 &&
334 (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2) { 331 (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2) {
diff --git a/arch/sparc/kernel/pcic.c b/arch/sparc/kernel/pcic.c
index 597d3ff6ad68..36a40697b8d6 100644
--- a/arch/sparc/kernel/pcic.c
+++ b/arch/sparc/kernel/pcic.c
@@ -840,10 +840,7 @@ static int pci_do_settimeofday(struct timespec *tv)
840 840
841 xtime.tv_sec = tv->tv_sec; 841 xtime.tv_sec = tv->tv_sec;
842 xtime.tv_nsec = tv->tv_nsec; 842 xtime.tv_nsec = tv->tv_nsec;
843 time_adjust = 0; /* stop active adjtime() */ 843 ntp_clear();
844 time_status |= STA_UNSYNC;
845 time_maxerror = NTP_PHASE_LIMIT;
846 time_esterror = NTP_PHASE_LIMIT;
847 return 0; 844 return 0;
848} 845}
849 846
diff --git a/arch/sparc/kernel/time.c b/arch/sparc/kernel/time.c
index 3b759aefc170..bc015e980341 100644
--- a/arch/sparc/kernel/time.c
+++ b/arch/sparc/kernel/time.c
@@ -139,7 +139,7 @@ irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs * regs)
139 139
140 140
141 /* Determine when to update the Mostek clock. */ 141 /* Determine when to update the Mostek clock. */
142 if ((time_status & STA_UNSYNC) == 0 && 142 if (ntp_synced() &&
143 xtime.tv_sec > last_rtc_update + 660 && 143 xtime.tv_sec > last_rtc_update + 660 &&
144 (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 && 144 (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 &&
145 (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2) { 145 (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2) {
@@ -554,10 +554,7 @@ static int sbus_do_settimeofday(struct timespec *tv)
554 set_normalized_timespec(&xtime, sec, nsec); 554 set_normalized_timespec(&xtime, sec, nsec);
555 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec); 555 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
556 556
557 time_adjust = 0; /* stop active adjtime() */ 557 ntp_clear();
558 time_status |= STA_UNSYNC;
559 time_maxerror = NTP_PHASE_LIMIT;
560 time_esterror = NTP_PHASE_LIMIT;
561 return 0; 558 return 0;
562} 559}
563 560
diff --git a/arch/sparc64/kernel/time.c b/arch/sparc64/kernel/time.c
index 362b9c26871b..3f08a32f51a1 100644
--- a/arch/sparc64/kernel/time.c
+++ b/arch/sparc64/kernel/time.c
@@ -449,7 +449,7 @@ static inline void timer_check_rtc(void)
449 static long last_rtc_update; 449 static long last_rtc_update;
450 450
451 /* Determine when to update the Mostek clock. */ 451 /* Determine when to update the Mostek clock. */
452 if ((time_status & STA_UNSYNC) == 0 && 452 if (ntp_synced() &&
453 xtime.tv_sec > last_rtc_update + 660 && 453 xtime.tv_sec > last_rtc_update + 660 &&
454 (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 && 454 (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 &&
455 (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2) { 455 (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2) {
diff --git a/arch/v850/kernel/time.c b/arch/v850/kernel/time.c
index f722a268238a..ea3fd8844ff0 100644
--- a/arch/v850/kernel/time.c
+++ b/arch/v850/kernel/time.c
@@ -66,7 +66,7 @@ static irqreturn_t timer_interrupt (int irq, void *dummy, struct pt_regs *regs)
66 * CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be 66 * CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
67 * called as close as possible to 500 ms before the new second starts. 67 * called as close as possible to 500 ms before the new second starts.
68 */ 68 */
69 if ((time_status & STA_UNSYNC) == 0 && 69 if (ntp_synced() &&
70 xtime.tv_sec > last_rtc_update + 660 && 70 xtime.tv_sec > last_rtc_update + 660 &&
71 (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 && 71 (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 &&
72 (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2) { 72 (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2) {
@@ -169,10 +169,7 @@ int do_settimeofday(struct timespec *tv)
169 xtime.tv_sec = tv->tv_sec; 169 xtime.tv_sec = tv->tv_sec;
170 xtime.tv_nsec = tv->tv_nsec; 170 xtime.tv_nsec = tv->tv_nsec;
171 171
172 time_adjust = 0; /* stop active adjtime () */ 172 ntp_clear();
173 time_status |= STA_UNSYNC;
174 time_maxerror = NTP_PHASE_LIMIT;
175 time_esterror = NTP_PHASE_LIMIT;
176 173
177 write_sequnlock_irq (&xtime_lock); 174 write_sequnlock_irq (&xtime_lock);
178 clock_was_set(); 175 clock_was_set();
diff --git a/arch/x86_64/kernel/time.c b/arch/x86_64/kernel/time.c
index 2b5d9da912a2..7b6abe058253 100644
--- a/arch/x86_64/kernel/time.c
+++ b/arch/x86_64/kernel/time.c
@@ -176,10 +176,7 @@ int do_settimeofday(struct timespec *tv)
176 set_normalized_timespec(&xtime, sec, nsec); 176 set_normalized_timespec(&xtime, sec, nsec);
177 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec); 177 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
178 178
179 time_adjust = 0; /* stop active adjtime() */ 179 ntp_clear();
180 time_status |= STA_UNSYNC;
181 time_maxerror = NTP_PHASE_LIMIT;
182 time_esterror = NTP_PHASE_LIMIT;
183 180
184 write_sequnlock_irq(&xtime_lock); 181 write_sequnlock_irq(&xtime_lock);
185 clock_was_set(); 182 clock_was_set();
@@ -471,7 +468,7 @@ static irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
471 * off) isn't likely to go away much sooner anyway. 468 * off) isn't likely to go away much sooner anyway.
472 */ 469 */
473 470
474 if ((~time_status & STA_UNSYNC) && xtime.tv_sec > rtc_update && 471 if (ntp_synced() && xtime.tv_sec > rtc_update &&
475 abs(xtime.tv_nsec - 500000000) <= tick_nsec / 2) { 472 abs(xtime.tv_nsec - 500000000) <= tick_nsec / 2) {
476 set_rtc_mmss(xtime.tv_sec); 473 set_rtc_mmss(xtime.tv_sec);
477 rtc_update = xtime.tv_sec + 660; 474 rtc_update = xtime.tv_sec + 660;
diff --git a/arch/xtensa/kernel/time.c b/arch/xtensa/kernel/time.c
index e07287db5a40..1ac7d5ce7456 100644
--- a/arch/xtensa/kernel/time.c
+++ b/arch/xtensa/kernel/time.c
@@ -122,10 +122,7 @@ int do_settimeofday(struct timespec *tv)
122 set_normalized_timespec(&xtime, sec, nsec); 122 set_normalized_timespec(&xtime, sec, nsec);
123 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec); 123 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
124 124
125 time_adjust = 0; /* stop active adjtime() */ 125 ntp_clear();
126 time_status |= STA_UNSYNC;
127 time_maxerror = NTP_PHASE_LIMIT;
128 time_esterror = NTP_PHASE_LIMIT;
129 write_sequnlock_irq(&xtime_lock); 126 write_sequnlock_irq(&xtime_lock);
130 return 0; 127 return 0;
131} 128}
@@ -184,7 +181,7 @@ again:
184 next += CCOUNT_PER_JIFFY; 181 next += CCOUNT_PER_JIFFY;
185 do_timer (regs); /* Linux handler in kernel/timer.c */ 182 do_timer (regs); /* Linux handler in kernel/timer.c */
186 183
187 if ((time_status & STA_UNSYNC) == 0 && 184 if (ntp_synced() &&
188 xtime.tv_sec - last_rtc_update >= 659 && 185 xtime.tv_sec - last_rtc_update >= 659 &&
189 abs((xtime.tv_nsec/1000)-(1000000-1000000/HZ))<5000000/HZ && 186 abs((xtime.tv_nsec/1000)-(1000000-1000000/HZ))<5000000/HZ &&
190 jiffies - wall_jiffies == 1) { 187 jiffies - wall_jiffies == 1) {
diff --git a/include/linux/timex.h b/include/linux/timex.h
index 74fdd07d3792..7e050a2cc35b 100644
--- a/include/linux/timex.h
+++ b/include/linux/timex.h
@@ -260,6 +260,29 @@ extern long pps_calcnt; /* calibration intervals */
260extern long pps_errcnt; /* calibration errors */ 260extern long pps_errcnt; /* calibration errors */
261extern long pps_stbcnt; /* stability limit exceeded */ 261extern long pps_stbcnt; /* stability limit exceeded */
262 262
263/**
264 * ntp_clear - Clears the NTP state variables
265 *
266 * Must be called while holding a write on the xtime_lock
267 */
268static inline void ntp_clear(void)
269{
270 time_adjust = 0; /* stop active adjtime() */
271 time_status |= STA_UNSYNC;
272 time_maxerror = NTP_PHASE_LIMIT;
273 time_esterror = NTP_PHASE_LIMIT;
274}
275
276/**
277 * ntp_synced - Returns 1 if the NTP status is not UNSYNC
278 *
279 */
280static inline int ntp_synced(void)
281{
282 return !(time_status & STA_UNSYNC);
283}
284
285
263#ifdef CONFIG_TIME_INTERPOLATION 286#ifdef CONFIG_TIME_INTERPOLATION
264 287
265#define TIME_SOURCE_CPU 0 288#define TIME_SOURCE_CPU 0