aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/time
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/time')
-rw-r--r--kernel/time/ntp.c23
1 files changed, 11 insertions, 12 deletions
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 }