aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/timex.h9
-rw-r--r--kernel/time/ntp.c23
2 files changed, 13 insertions, 19 deletions
diff --git a/include/linux/timex.h b/include/linux/timex.h
index 48c3376dce71..9fbdd12a52f1 100644
--- a/include/linux/timex.h
+++ b/include/linux/timex.h
@@ -76,27 +76,22 @@
76#define MAXTC 10 /* maximum time constant (shift) */ 76#define MAXTC 10 /* maximum time constant (shift) */
77 77
78/* 78/*
79 * The SHIFT_UPDATE define establishes the decimal point of the
80 * time_offset variable which represents the current offset with
81 * respect to standard time.
82 *
83 * SHIFT_USEC defines the scaling (shift) of the time_freq and 79 * SHIFT_USEC defines the scaling (shift) of the time_freq and
84 * time_tolerance variables, which represent the current frequency 80 * time_tolerance variables, which represent the current frequency
85 * offset and maximum frequency tolerance. 81 * offset and maximum frequency tolerance.
86 */ 82 */
87#define SHIFT_UPDATE (SHIFT_HZ + 1) /* time offset scale (shift) */
88#define SHIFT_USEC 16 /* frequency offset scale (shift) */ 83#define SHIFT_USEC 16 /* frequency offset scale (shift) */
89#define PPM_SCALE (NSEC_PER_USEC << (TICK_LENGTH_SHIFT - SHIFT_USEC)) 84#define PPM_SCALE (NSEC_PER_USEC << (TICK_LENGTH_SHIFT - SHIFT_USEC))
90#define PPM_SCALE_INV_SHIFT 20 85#define PPM_SCALE_INV_SHIFT 20
91#define PPM_SCALE_INV ((1ll << (PPM_SCALE_INV_SHIFT + TICK_LENGTH_SHIFT)) / \ 86#define PPM_SCALE_INV ((1ll << (PPM_SCALE_INV_SHIFT + TICK_LENGTH_SHIFT)) / \
92 PPM_SCALE + 1) 87 PPM_SCALE + 1)
93 88
94#define MAXPHASE 512000L /* max phase error (us) */ 89#define MAXPHASE 500000000l /* max phase error (ns) */
95#define MAXFREQ 500000 /* max frequency error (ns/s) */ 90#define MAXFREQ 500000 /* max frequency error (ns/s) */
96#define MAXFREQ_SCALED ((s64)MAXFREQ << TICK_LENGTH_SHIFT) 91#define MAXFREQ_SCALED ((s64)MAXFREQ << TICK_LENGTH_SHIFT)
97#define MINSEC 256 /* min interval between updates (s) */ 92#define MINSEC 256 /* min interval between updates (s) */
98#define MAXSEC 2048 /* max interval between updates (s) */ 93#define MAXSEC 2048 /* max interval between updates (s) */
99#define NTP_PHASE_LIMIT (MAXPHASE << 5) /* beyond max. dispersion */ 94#define NTP_PHASE_LIMIT ((MAXPHASE / NSEC_PER_USEC) << 5) /* beyond max. dispersion */
100 95
101/* 96/*
102 * syscall interface - used (mainly by NTP daemon) 97 * syscall interface - used (mainly by NTP daemon)
diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index c6ae0c249891..44491de312a0 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -65,16 +65,15 @@ static void ntp_update_offset(long offset)
65 if (!(time_status & STA_PLL)) 65 if (!(time_status & STA_PLL))
66 return; 66 return;
67 67
68 time_offset = offset;
69 if (!(time_status & STA_NANO)) 68 if (!(time_status & STA_NANO))
70 time_offset *= NSEC_PER_USEC; 69 offset *= NSEC_PER_USEC;
71 70
72 /* 71 /*
73 * Scale the phase adjustment and 72 * Scale the phase adjustment and
74 * clamp to the operating range. 73 * clamp to the operating range.
75 */ 74 */
76 time_offset = min(time_offset, (s64)MAXPHASE * NSEC_PER_USEC); 75 offset = min(offset, MAXPHASE);
77 time_offset = max(time_offset, (s64)-MAXPHASE * NSEC_PER_USEC); 76 offset = max(offset, -MAXPHASE);
78 77
79 /* 78 /*
80 * Select how the frequency is to be controlled 79 * Select how the frequency is to be controlled
@@ -85,19 +84,19 @@ static void ntp_update_offset(long offset)
85 mtemp = xtime.tv_sec - time_reftime; 84 mtemp = xtime.tv_sec - time_reftime;
86 time_reftime = xtime.tv_sec; 85 time_reftime = xtime.tv_sec;
87 86
88 freq_adj = time_offset * mtemp; 87 freq_adj = (s64)offset * mtemp;
89 freq_adj <<= TICK_LENGTH_SHIFT - 2 * (SHIFT_PLL + 2 + time_constant); 88 freq_adj <<= TICK_LENGTH_SHIFT - 2 * (SHIFT_PLL + 2 + time_constant);
90 time_status &= ~STA_MODE; 89 time_status &= ~STA_MODE;
91 if (mtemp >= MINSEC && (time_status & STA_FLL || mtemp > MAXSEC)) { 90 if (mtemp >= MINSEC && (time_status & STA_FLL || mtemp > MAXSEC)) {
92 freq_adj += div_s64(time_offset << (TICK_LENGTH_SHIFT - SHIFT_FLL), 91 freq_adj += div_s64((s64)offset << (TICK_LENGTH_SHIFT - SHIFT_FLL),
93 mtemp); 92 mtemp);
94 time_status |= STA_MODE; 93 time_status |= STA_MODE;
95 } 94 }
96 freq_adj += time_freq; 95 freq_adj += time_freq;
97 freq_adj = min(freq_adj, MAXFREQ_SCALED); 96 freq_adj = min(freq_adj, MAXFREQ_SCALED);
98 time_freq = max(freq_adj, -MAXFREQ_SCALED); 97 time_freq = max(freq_adj, -MAXFREQ_SCALED);
99 time_offset = div_s64(time_offset, NTP_INTERVAL_FREQ); 98
100 time_offset <<= SHIFT_UPDATE; 99 time_offset = div_s64((s64)offset << TICK_LENGTH_SHIFT, NTP_INTERVAL_FREQ);
101} 100}
102 101
103/** 102/**
@@ -128,7 +127,7 @@ void ntp_clear(void)
128 */ 127 */
129void second_overflow(void) 128void second_overflow(void)
130{ 129{
131 long time_adj; 130 s64 time_adj;
132 131
133 /* Bump the maxerror field */ 132 /* Bump the maxerror field */
134 time_maxerror += MAXFREQ / NSEC_PER_USEC; 133 time_maxerror += MAXFREQ / NSEC_PER_USEC;
@@ -184,7 +183,7 @@ void second_overflow(void)
184 tick_length = tick_length_base; 183 tick_length = tick_length_base;
185 time_adj = shift_right(time_offset, SHIFT_PLL + time_constant); 184 time_adj = shift_right(time_offset, SHIFT_PLL + time_constant);
186 time_offset -= time_adj; 185 time_offset -= time_adj;
187 tick_length += (s64)time_adj << (TICK_LENGTH_SHIFT - SHIFT_UPDATE); 186 tick_length += time_adj;
188 187
189 if (unlikely(time_adjust)) { 188 if (unlikely(time_adjust)) {
190 if (time_adjust > MAX_TICKADJ) { 189 if (time_adjust > MAX_TICKADJ) {
@@ -363,8 +362,8 @@ int do_adjtimex(struct timex *txc)
363 (txc->modes == ADJ_OFFSET_SS_READ)) 362 (txc->modes == ADJ_OFFSET_SS_READ))
364 txc->offset = save_adjust; 363 txc->offset = save_adjust;
365 else { 364 else {
366 txc->offset = ((long)shift_right(time_offset, SHIFT_UPDATE)) * 365 txc->offset = shift_right(time_offset * NTP_INTERVAL_FREQ,
367 NTP_INTERVAL_FREQ; 366 TICK_LENGTH_SHIFT);
368 if (!(time_status & STA_NANO)) 367 if (!(time_status & STA_NANO))
369 txc->offset /= NSEC_PER_USEC; 368 txc->offset /= NSEC_PER_USEC;
370 } 369 }