aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--kernel/time/ntp.c44
1 files changed, 30 insertions, 14 deletions
diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index f1abad738579..ee437e1445d1 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -103,10 +103,27 @@ static void ntp_update_frequency(void)
103 tick_length_base = new_base; 103 tick_length_base = new_base;
104} 104}
105 105
106static inline s64 ntp_update_offset_fll(s64 freq_adj, s64 offset64, long secs)
107{
108 time_status &= ~STA_MODE;
109
110 if (secs < MINSEC)
111 return freq_adj;
112
113 if (!(time_status & STA_FLL) && (secs <= MAXSEC))
114 return freq_adj;
115
116 freq_adj += div_s64(offset64 << (NTP_SCALE_SHIFT - SHIFT_FLL), secs);
117 time_status |= STA_MODE;
118
119 return freq_adj;
120}
121
106static void ntp_update_offset(long offset) 122static void ntp_update_offset(long offset)
107{ 123{
108 long mtemp;
109 s64 freq_adj; 124 s64 freq_adj;
125 s64 offset64;
126 long secs;
110 127
111 if (!(time_status & STA_PLL)) 128 if (!(time_status & STA_PLL))
112 return; 129 return;
@@ -127,22 +144,21 @@ static void ntp_update_offset(long offset)
127 */ 144 */
128 if (time_status & STA_FREQHOLD || time_reftime == 0) 145 if (time_status & STA_FREQHOLD || time_reftime == 0)
129 time_reftime = xtime.tv_sec; 146 time_reftime = xtime.tv_sec;
130 mtemp = xtime.tv_sec - time_reftime; 147
148 secs = xtime.tv_sec - time_reftime;
131 time_reftime = xtime.tv_sec; 149 time_reftime = xtime.tv_sec;
132 150
133 freq_adj = (s64)offset * mtemp; 151 offset64 = offset;
134 freq_adj <<= NTP_SCALE_SHIFT - 2 * (SHIFT_PLL + 2 + time_constant); 152 freq_adj = (offset64 * secs) <<
135 time_status &= ~STA_MODE; 153 (NTP_SCALE_SHIFT - 2 * (SHIFT_PLL + 2 + time_constant));
136 if (mtemp >= MINSEC && (time_status & STA_FLL || mtemp > MAXSEC)) { 154
137 freq_adj += div_s64((s64)offset << (NTP_SCALE_SHIFT - SHIFT_FLL), 155 freq_adj = ntp_update_offset_fll(freq_adj, offset64, secs);
138 mtemp); 156
139 time_status |= STA_MODE; 157 freq_adj = min(freq_adj + time_freq, MAXFREQ_SCALED);
140 } 158
141 freq_adj += time_freq; 159 time_freq = max(freq_adj, -MAXFREQ_SCALED);
142 freq_adj = min(freq_adj, MAXFREQ_SCALED);
143 time_freq = max(freq_adj, -MAXFREQ_SCALED);
144 160
145 time_offset = div_s64((s64)offset << NTP_SCALE_SHIFT, NTP_INTERVAL_FREQ); 161 time_offset = div_s64(offset64 << NTP_SCALE_SHIFT, NTP_INTERVAL_FREQ);
146} 162}
147 163
148/** 164/**