Skip to content

Commit b149ee2

Browse files
john stultzLinus Torvalds
authored andcommitted
[PATCH] NTP: ntp-helper functions
This patch cleans up a commonly repeated set of changes to the NTP state variables by adding two helper inline functions: ntp_clear(): Clears the ntp state variables ntp_synced(): Returns 1 if the system is synced with a time server. This was compile tested for alpha, arm, i386, x86-64, ppc64, s390, sparc, sparc64. Signed-off-by: John Stultz <johnstul@us.ibm.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 6c231b7 commit b149ee2

27 files changed

Lines changed: 65 additions & 111 deletions

File tree

‎arch/alpha/kernel/time.c‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ irqreturn_t timer_interrupt(int irq, void *dev, struct pt_regs * regs)
149149
* CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
150150
* called as close as possible to 500 ms before the new second starts.
151151
*/
152-
if ((time_status & STA_UNSYNC) == 0
152+
if (ntp_synced()
153153
&& xtime.tv_sec > state.last_rtc_update + 660
154154
&& xtime.tv_nsec >= 500000 - ((unsigned) TICK_SIZE) / 2
155155
&& xtime.tv_nsec <= 500000 + ((unsigned) TICK_SIZE) / 2) {
@@ -502,10 +502,7 @@ do_settimeofday(struct timespec *tv)
502502
set_normalized_timespec(&xtime, sec, nsec);
503503
set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
504504

505-
time_adjust = 0; /* stop active adjtime() */
506-
time_status |= STA_UNSYNC;
507-
time_maxerror = NTP_PHASE_LIMIT;
508-
time_esterror = NTP_PHASE_LIMIT;
505+
ntp_clear();
509506

510507
write_sequnlock_irq(&xtime_lock);
511508
clock_was_set();

‎arch/arm/kernel/time.c‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static unsigned long next_rtc_update;
102102
*/
103103
static inline void do_set_rtc(void)
104104
{
105-
if (time_status & STA_UNSYNC || set_rtc == NULL)
105+
if (!ntp_synced() || set_rtc == NULL)
106106
return;
107107

108108
if (next_rtc_update &&
@@ -292,10 +292,7 @@ int do_settimeofday(struct timespec *tv)
292292
set_normalized_timespec(&xtime, sec, nsec);
293293
set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
294294

295-
time_adjust = 0; /* stop active adjtime() */
296-
time_status |= STA_UNSYNC;
297-
time_maxerror = NTP_PHASE_LIMIT;
298-
time_esterror = NTP_PHASE_LIMIT;
295+
ntp_clear();
299296
write_sequnlock_irq(&xtime_lock);
300297
clock_was_set();
301298
return 0;

‎arch/arm26/kernel/time.c‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static unsigned long next_rtc_update;
114114
*/
115115
static inline void do_set_rtc(void)
116116
{
117-
if (time_status & STA_UNSYNC || set_rtc == NULL)
117+
if (!ntp_synced() || set_rtc == NULL)
118118
return;
119119

120120
//FIXME - timespec.tv_sec is a time_t not unsigned long
@@ -189,10 +189,7 @@ int do_settimeofday(struct timespec *tv)
189189

190190
xtime.tv_sec = tv->tv_sec;
191191
xtime.tv_nsec = tv->tv_nsec;
192-
time_adjust = 0; /* stop active adjtime() */
193-
time_status |= STA_UNSYNC;
194-
time_maxerror = NTP_PHASE_LIMIT;
195-
time_esterror = NTP_PHASE_LIMIT;
192+
ntp_clear();
196193
write_sequnlock_irq(&xtime_lock);
197194
clock_was_set();
198195
return 0;

‎arch/cris/arch-v10/kernel/time.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
240240
* The division here is not time critical since it will run once in
241241
* 11 minutes
242242
*/
243-
if ((time_status & STA_UNSYNC) == 0 &&
243+
if (ntp_synced() &&
244244
xtime.tv_sec > last_rtc_update + 660 &&
245245
(xtime.tv_nsec / 1000) >= 500000 - (tick_nsec / 1000) / 2 &&
246246
(xtime.tv_nsec / 1000) <= 500000 + (tick_nsec / 1000) / 2) {

‎arch/cris/kernel/time.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,7 @@ int do_settimeofday(struct timespec *tv)
114114
set_normalized_timespec(&xtime, sec, nsec);
115115
set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
116116

117-
time_adjust = 0; /* stop active adjtime() */
118-
time_status |= STA_UNSYNC;
119-
time_maxerror = NTP_PHASE_LIMIT;
120-
time_esterror = NTP_PHASE_LIMIT;
117+
ntp_clear();
121118
write_sequnlock_irq(&xtime_lock);
122119
clock_was_set();
123120
return 0;

‎arch/frv/kernel/time.c‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static irqreturn_t timer_interrupt(int irq, void *dummy, struct pt_regs * regs)
8585
* CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
8686
* called as close as possible to 500 ms before the new second starts.
8787
*/
88-
if ((time_status & STA_UNSYNC) == 0 &&
88+
if (ntp_synced() &&
8989
xtime.tv_sec > last_rtc_update + 660 &&
9090
(xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 &&
9191
(xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2
@@ -216,10 +216,7 @@ int do_settimeofday(struct timespec *tv)
216216
set_normalized_timespec(&xtime, sec, nsec);
217217
set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
218218

219-
time_adjust = 0; /* stop active adjtime() */
220-
time_status |= STA_UNSYNC;
221-
time_maxerror = NTP_PHASE_LIMIT;
222-
time_esterror = NTP_PHASE_LIMIT;
219+
ntp_clear();
223220
write_sequnlock_irq(&xtime_lock);
224221
clock_was_set();
225222
return 0;

‎arch/h8300/kernel/time.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,7 @@ int do_settimeofday(struct timespec *tv)
116116

117117
xtime.tv_sec = tv->tv_sec;
118118
xtime.tv_nsec = tv->tv_nsec;
119-
time_adjust = 0; /* stop active adjtime() */
120-
time_status |= STA_UNSYNC;
121-
time_maxerror = NTP_PHASE_LIMIT;
122-
time_esterror = NTP_PHASE_LIMIT;
119+
ntp_clear();
123120
write_sequnlock_irq(&xtime_lock);
124121
clock_was_set();
125122
return 0;

‎arch/i386/kernel/time.c‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,7 @@ int do_settimeofday(struct timespec *tv)
194194
set_normalized_timespec(&xtime, sec, nsec);
195195
set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
196196

197-
time_adjust = 0; /* stop active adjtime() */
198-
time_status |= STA_UNSYNC;
199-
time_maxerror = NTP_PHASE_LIMIT;
200-
time_esterror = NTP_PHASE_LIMIT;
197+
ntp_clear();
201198
write_sequnlock_irq(&xtime_lock);
202199
clock_was_set();
203200
return 0;
@@ -347,7 +344,7 @@ static void sync_cmos_clock(unsigned long dummy)
347344
* This code is run on a timer. If the clock is set, that timer
348345
* may not expire at the correct time. Thus, we adjust...
349346
*/
350-
if ((time_status & STA_UNSYNC) != 0)
347+
if (!ntp_synced())
351348
/*
352349
* Not synced, exit, do not restart a timer (if one is
353350
* running, let it run out).

‎arch/m32r/kernel/time.c‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,7 @@ int do_settimeofday(struct timespec *tv)
171171
set_normalized_timespec(&xtime, sec, nsec);
172172
set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
173173

174-
time_adjust = 0; /* stop active adjtime() */
175-
time_status |= STA_UNSYNC;
176-
time_maxerror = NTP_PHASE_LIMIT;
177-
time_esterror = NTP_PHASE_LIMIT;
174+
ntp_clear();
178175
write_sequnlock_irq(&xtime_lock);
179176
clock_was_set();
180177

@@ -221,7 +218,7 @@ irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
221218
* called as close as possible to 500 ms before the new second starts.
222219
*/
223220
write_seqlock(&xtime_lock);
224-
if ((time_status & STA_UNSYNC) == 0
221+
if (ntp_synced()
225222
&& xtime.tv_sec > last_rtc_update + 660
226223
&& (xtime.tv_nsec / 1000) >= 500000 - ((unsigned)TICK_SIZE) / 2
227224
&& (xtime.tv_nsec / 1000) <= 500000 + ((unsigned)TICK_SIZE) / 2)

‎arch/m68k/kernel/time.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,7 @@ int do_settimeofday(struct timespec *tv)
166166
set_normalized_timespec(&xtime, sec, nsec);
167167
set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
168168

169-
time_adjust = 0; /* stop active adjtime() */
170-
time_status |= STA_UNSYNC;
171-
time_maxerror = NTP_PHASE_LIMIT;
172-
time_esterror = NTP_PHASE_LIMIT;
169+
ntp_clear();
173170
write_sequnlock_irq(&xtime_lock);
174171
clock_was_set();
175172
return 0;

0 commit comments

Comments
 (0)