aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/time
diff options
context:
space:
mode:
authorRoman Zippel <zippel@linux-m68k.org>2006-10-01 02:28:25 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-10-01 03:39:26 -0400
commit8f807f8d2137ba728d22820103131038639b68a9 (patch)
treecea8d4eedbffc17ea9a01808afacb0e02dbbe206 /kernel/time
parent3d3675cc3d04d7fd4bb11e8c1ea79e5ade4f5e44 (diff)
[PATCH] ntp: add time_adjust to tick length
This folds update_ntp_one_tick() into second_overflow() and adds time_adjust to the tick length, this makes time_next_adjust unnecessary. This slightly changes the adjtime() behaviour, instead of applying it to the next tick, it's applied to the next second. Signed-off-by: Roman Zippel <zippel@linux-m68k.org> Cc: john stultz <johnstul@us.ibm.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'kernel/time')
-rw-r--r--kernel/time/ntp.c71
1 files changed, 18 insertions, 53 deletions
diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index 238ce47ef09d..65223b7ed810 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -22,8 +22,9 @@ unsigned long tick_usec = TICK_USEC; /* USER_HZ period (usec) */
22unsigned long tick_nsec; /* ACTHZ period (nsec) */ 22unsigned long tick_nsec; /* ACTHZ period (nsec) */
23static u64 tick_length, tick_length_base; 23static u64 tick_length, tick_length_base;
24 24
25/* Don't completely fail for HZ > 500. */ 25#define MAX_TICKADJ 500 /* microsecs */
26int tickadj = 500/HZ ? : 1; /* microsecs */ 26#define MAX_TICKADJ_SCALED (((u64)(MAX_TICKADJ * NSEC_PER_USEC) << \
27 TICK_LENGTH_SHIFT) / HZ)
27 28
28/* 29/*
29 * phase-lock loop variables 30 * phase-lock loop variables
@@ -40,7 +41,6 @@ long time_esterror = NTP_PHASE_LIMIT; /* estimated error (us) */
40long time_freq; /* frequency offset (scaled ppm)*/ 41long time_freq; /* frequency offset (scaled ppm)*/
41long time_reftime; /* time at last adjustment (s) */ 42long time_reftime; /* time at last adjustment (s) */
42long time_adjust; 43long time_adjust;
43long time_next_adjust;
44 44
45/** 45/**
46 * ntp_clear - Clears the NTP state variables 46 * ntp_clear - Clears the NTP state variables
@@ -160,46 +160,19 @@ void second_overflow(void)
160 time_adj = max(time_adj, ((MAXPHASE / HZ) << SHIFT_UPDATE) / MINSEC); 160 time_adj = max(time_adj, ((MAXPHASE / HZ) << SHIFT_UPDATE) / MINSEC);
161 time_offset -= time_adj; 161 time_offset -= time_adj;
162 tick_length += (s64)time_adj << (TICK_LENGTH_SHIFT - SHIFT_UPDATE); 162 tick_length += (s64)time_adj << (TICK_LENGTH_SHIFT - SHIFT_UPDATE);
163}
164
165/*
166 * Returns how many microseconds we need to add to xtime this tick
167 * in doing an adjustment requested with adjtime.
168 */
169static long adjtime_adjustment(void)
170{
171 long time_adjust_step;
172
173 time_adjust_step = time_adjust;
174 if (time_adjust_step) {
175 /*
176 * We are doing an adjtime thing. Prepare time_adjust_step to
177 * be within bounds. Note that a positive time_adjust means we
178 * want the clock to run faster.
179 *
180 * Limit the amount of the step to be in the range
181 * -tickadj .. +tickadj
182 */
183 time_adjust_step = min(time_adjust_step, (long)tickadj);
184 time_adjust_step = max(time_adjust_step, (long)-tickadj);
185 }
186 return time_adjust_step;
187}
188 163
189/* in the NTP reference this is called "hardclock()" */ 164 if (unlikely(time_adjust)) {
190void update_ntp_one_tick(void) 165 if (time_adjust > MAX_TICKADJ) {
191{ 166 time_adjust -= MAX_TICKADJ;
192 long time_adjust_step; 167 tick_length += MAX_TICKADJ_SCALED;
193 168 } else if (time_adjust < -MAX_TICKADJ) {
194 time_adjust_step = adjtime_adjustment(); 169 time_adjust += MAX_TICKADJ;
195 if (time_adjust_step) 170 tick_length -= MAX_TICKADJ_SCALED;
196 /* Reduce by this step the amount of time left */ 171 } else {
197 time_adjust -= time_adjust_step; 172 time_adjust = 0;
198 173 tick_length += (s64)(time_adjust * NSEC_PER_USEC /
199 /* Changes by adjtime() do not take effect till next tick. */ 174 HZ) << TICK_LENGTH_SHIFT;
200 if (time_next_adjust != 0) { 175 }
201 time_adjust = time_next_adjust;
202 time_next_adjust = 0;
203 } 176 }
204} 177}
205 178
@@ -213,14 +186,7 @@ void update_ntp_one_tick(void)
213 */ 186 */
214u64 current_tick_length(void) 187u64 current_tick_length(void)
215{ 188{
216 u64 ret; 189 return tick_length;
217
218 /* calculate the finest interval NTP will allow.
219 */
220 ret = tick_length;
221 ret += (u64)(adjtime_adjustment() * 1000) << TICK_LENGTH_SHIFT;
222
223 return ret;
224} 190}
225 191
226 192
@@ -263,7 +229,7 @@ int do_adjtimex(struct timex *txc)
263 result = time_state; /* mostly `TIME_OK' */ 229 result = time_state; /* mostly `TIME_OK' */
264 230
265 /* Save for later - semantics of adjtime is to return old value */ 231 /* Save for later - semantics of adjtime is to return old value */
266 save_adjust = time_next_adjust ? time_next_adjust : time_adjust; 232 save_adjust = time_adjust;
267 233
268#if 0 /* STA_CLOCKERR is never set yet */ 234#if 0 /* STA_CLOCKERR is never set yet */
269 time_status &= ~STA_CLOCKERR; /* reset STA_CLOCKERR */ 235 time_status &= ~STA_CLOCKERR; /* reset STA_CLOCKERR */
@@ -310,8 +276,7 @@ int do_adjtimex(struct timex *txc)
310 if (txc->modes & ADJ_OFFSET) { /* values checked earlier */ 276 if (txc->modes & ADJ_OFFSET) { /* values checked earlier */
311 if (txc->modes == ADJ_OFFSET_SINGLESHOT) { 277 if (txc->modes == ADJ_OFFSET_SINGLESHOT) {
312 /* adjtime() is independent from ntp_adjtime() */ 278 /* adjtime() is independent from ntp_adjtime() */
313 if ((time_next_adjust = txc->offset) == 0) 279 time_adjust = txc->offset;
314 time_adjust = 0;
315 } 280 }
316 else if (time_status & STA_PLL) { 281 else if (time_status & STA_PLL) {
317 ltemp = txc->offset; 282 ltemp = txc->offset;