| john stultz | 4c7ee8d | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * linux/kernel/time/ntp.c | 
|  | 3 | * | 
|  | 4 | * NTP state machine interfaces and logic. | 
|  | 5 | * | 
|  | 6 | * This code was mainly moved from kernel/timer.c and kernel/time.c | 
|  | 7 | * Please see those files for relevant copyright info and historical | 
|  | 8 | * changelogs. | 
|  | 9 | */ | 
|  | 10 |  | 
|  | 11 | #include <linux/mm.h> | 
|  | 12 | #include <linux/time.h> | 
|  | 13 | #include <linux/timex.h> | 
|  | 14 |  | 
|  | 15 | #include <asm/div64.h> | 
|  | 16 | #include <asm/timex.h> | 
|  | 17 |  | 
| Roman Zippel | b0ee755 | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 18 | /* | 
|  | 19 | * Timekeeping variables | 
|  | 20 | */ | 
|  | 21 | unsigned long tick_usec = TICK_USEC; 		/* USER_HZ period (usec) */ | 
|  | 22 | unsigned long tick_nsec;			/* ACTHZ period (nsec) */ | 
|  | 23 | static u64 tick_length, tick_length_base; | 
|  | 24 |  | 
| Roman Zippel | 8f807f8 | 2006-09-30 23:28:25 -0700 | [diff] [blame] | 25 | #define MAX_TICKADJ		500		/* microsecs */ | 
|  | 26 | #define MAX_TICKADJ_SCALED	(((u64)(MAX_TICKADJ * NSEC_PER_USEC) << \ | 
| john stultz | f4304ab | 2007-02-16 01:27:26 -0800 | [diff] [blame] | 27 | TICK_LENGTH_SHIFT) / NTP_INTERVAL_FREQ) | 
| john stultz | 4c7ee8d | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 28 |  | 
|  | 29 | /* | 
|  | 30 | * phase-lock loop variables | 
|  | 31 | */ | 
|  | 32 | /* TIME_ERROR prevents overwriting the CMOS clock */ | 
| Adrian Bunk | 70bc42f | 2006-09-30 23:28:29 -0700 | [diff] [blame] | 33 | static int time_state = TIME_OK;	/* clock synchronization status	*/ | 
| john stultz | 4c7ee8d | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 34 | int time_status = STA_UNSYNC;		/* clock status bits		*/ | 
| Adrian Bunk | 70bc42f | 2006-09-30 23:28:29 -0700 | [diff] [blame] | 35 | static long time_offset;		/* time adjustment (ns)		*/ | 
|  | 36 | static long time_constant = 2;		/* pll time constant		*/ | 
| john stultz | 4c7ee8d | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 37 | long time_maxerror = NTP_PHASE_LIMIT;	/* maximum error (us)		*/ | 
|  | 38 | long time_esterror = NTP_PHASE_LIMIT;	/* estimated error (us)		*/ | 
| Roman Zippel | dc6a43e | 2006-09-30 23:28:24 -0700 | [diff] [blame] | 39 | long time_freq;				/* frequency offset (scaled ppm)*/ | 
| Adrian Bunk | 70bc42f | 2006-09-30 23:28:29 -0700 | [diff] [blame] | 40 | static long time_reftime;		/* time at last adjustment (s)	*/ | 
| john stultz | 4c7ee8d | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 41 | long time_adjust; | 
| john stultz | 4c7ee8d | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 42 |  | 
| Adrian Bunk | 70bc42f | 2006-09-30 23:28:29 -0700 | [diff] [blame] | 43 | #define CLOCK_TICK_OVERFLOW	(LATCH * HZ - CLOCK_TICK_RATE) | 
|  | 44 | #define CLOCK_TICK_ADJUST	(((s64)CLOCK_TICK_OVERFLOW * NSEC_PER_SEC) / \ | 
|  | 45 | (s64)CLOCK_TICK_RATE) | 
|  | 46 |  | 
|  | 47 | static void ntp_update_frequency(void) | 
|  | 48 | { | 
| john stultz | f4304ab | 2007-02-16 01:27:26 -0800 | [diff] [blame] | 49 | u64 second_length = (u64)(tick_usec * NSEC_PER_USEC * USER_HZ) | 
|  | 50 | << TICK_LENGTH_SHIFT; | 
|  | 51 | second_length += (s64)CLOCK_TICK_ADJUST << TICK_LENGTH_SHIFT; | 
|  | 52 | second_length += (s64)time_freq << (TICK_LENGTH_SHIFT - SHIFT_NSEC); | 
| Adrian Bunk | 70bc42f | 2006-09-30 23:28:29 -0700 | [diff] [blame] | 53 |  | 
| john stultz | f4304ab | 2007-02-16 01:27:26 -0800 | [diff] [blame] | 54 | tick_length_base = second_length; | 
| Adrian Bunk | 70bc42f | 2006-09-30 23:28:29 -0700 | [diff] [blame] | 55 |  | 
| john stultz | f4304ab | 2007-02-16 01:27:26 -0800 | [diff] [blame] | 56 | do_div(second_length, HZ); | 
|  | 57 | tick_nsec = second_length >> TICK_LENGTH_SHIFT; | 
|  | 58 |  | 
|  | 59 | do_div(tick_length_base, NTP_INTERVAL_FREQ); | 
| Adrian Bunk | 70bc42f | 2006-09-30 23:28:29 -0700 | [diff] [blame] | 60 | } | 
|  | 61 |  | 
| Roman Zippel | b0ee755 | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 62 | /** | 
|  | 63 | * ntp_clear - Clears the NTP state variables | 
|  | 64 | * | 
|  | 65 | * Must be called while holding a write on the xtime_lock | 
|  | 66 | */ | 
|  | 67 | void ntp_clear(void) | 
|  | 68 | { | 
|  | 69 | time_adjust = 0;		/* stop active adjtime() */ | 
|  | 70 | time_status |= STA_UNSYNC; | 
|  | 71 | time_maxerror = NTP_PHASE_LIMIT; | 
|  | 72 | time_esterror = NTP_PHASE_LIMIT; | 
|  | 73 |  | 
|  | 74 | ntp_update_frequency(); | 
|  | 75 |  | 
|  | 76 | tick_length = tick_length_base; | 
| Roman Zippel | 3d3675c | 2006-09-30 23:28:25 -0700 | [diff] [blame] | 77 | time_offset = 0; | 
| Roman Zippel | b0ee755 | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 78 | } | 
|  | 79 |  | 
| john stultz | 4c7ee8d | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 80 | /* | 
|  | 81 | * this routine handles the overflow of the microsecond field | 
|  | 82 | * | 
|  | 83 | * The tricky bits of code to handle the accurate clock support | 
|  | 84 | * were provided by Dave Mills (Mills@UDEL.EDU) of NTP fame. | 
|  | 85 | * They were originally developed for SUN and DEC kernels. | 
|  | 86 | * All the kudos should go to Dave for this stuff. | 
|  | 87 | */ | 
|  | 88 | void second_overflow(void) | 
|  | 89 | { | 
| Roman Zippel | 3d3675c | 2006-09-30 23:28:25 -0700 | [diff] [blame] | 90 | long time_adj; | 
| john stultz | 4c7ee8d | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 91 |  | 
|  | 92 | /* Bump the maxerror field */ | 
| Roman Zippel | 97eebe1 | 2006-09-30 23:28:26 -0700 | [diff] [blame] | 93 | time_maxerror += MAXFREQ >> SHIFT_USEC; | 
| john stultz | 4c7ee8d | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 94 | if (time_maxerror > NTP_PHASE_LIMIT) { | 
|  | 95 | time_maxerror = NTP_PHASE_LIMIT; | 
|  | 96 | time_status |= STA_UNSYNC; | 
|  | 97 | } | 
|  | 98 |  | 
|  | 99 | /* | 
|  | 100 | * Leap second processing. If in leap-insert state at the end of the | 
|  | 101 | * day, the system clock is set back one second; if in leap-delete | 
|  | 102 | * state, the system clock is set ahead one second. The microtime() | 
|  | 103 | * routine or external clock driver will insure that reported time is | 
|  | 104 | * always monotonic. The ugly divides should be replaced. | 
|  | 105 | */ | 
|  | 106 | switch (time_state) { | 
|  | 107 | case TIME_OK: | 
|  | 108 | if (time_status & STA_INS) | 
|  | 109 | time_state = TIME_INS; | 
|  | 110 | else if (time_status & STA_DEL) | 
|  | 111 | time_state = TIME_DEL; | 
|  | 112 | break; | 
|  | 113 | case TIME_INS: | 
|  | 114 | if (xtime.tv_sec % 86400 == 0) { | 
|  | 115 | xtime.tv_sec--; | 
|  | 116 | wall_to_monotonic.tv_sec++; | 
|  | 117 | /* | 
|  | 118 | * The timer interpolator will make time change | 
|  | 119 | * gradually instead of an immediate jump by one second | 
|  | 120 | */ | 
|  | 121 | time_interpolator_update(-NSEC_PER_SEC); | 
|  | 122 | time_state = TIME_OOP; | 
|  | 123 | clock_was_set(); | 
|  | 124 | printk(KERN_NOTICE "Clock: inserting leap second " | 
|  | 125 | "23:59:60 UTC\n"); | 
|  | 126 | } | 
|  | 127 | break; | 
|  | 128 | case TIME_DEL: | 
|  | 129 | if ((xtime.tv_sec + 1) % 86400 == 0) { | 
|  | 130 | xtime.tv_sec++; | 
|  | 131 | wall_to_monotonic.tv_sec--; | 
|  | 132 | /* | 
|  | 133 | * Use of time interpolator for a gradual change of | 
|  | 134 | * time | 
|  | 135 | */ | 
|  | 136 | time_interpolator_update(NSEC_PER_SEC); | 
|  | 137 | time_state = TIME_WAIT; | 
|  | 138 | clock_was_set(); | 
|  | 139 | printk(KERN_NOTICE "Clock: deleting leap second " | 
|  | 140 | "23:59:59 UTC\n"); | 
|  | 141 | } | 
|  | 142 | break; | 
|  | 143 | case TIME_OOP: | 
|  | 144 | time_state = TIME_WAIT; | 
|  | 145 | break; | 
|  | 146 | case TIME_WAIT: | 
|  | 147 | if (!(time_status & (STA_INS | STA_DEL))) | 
|  | 148 | time_state = TIME_OK; | 
|  | 149 | } | 
|  | 150 |  | 
|  | 151 | /* | 
| Roman Zippel | f199239 | 2006-09-30 23:28:28 -0700 | [diff] [blame] | 152 | * Compute the phase adjustment for the next second. The offset is | 
|  | 153 | * reduced by a fixed factor times the time constant. | 
| john stultz | 4c7ee8d | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 154 | */ | 
| Roman Zippel | b0ee755 | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 155 | tick_length = tick_length_base; | 
| Roman Zippel | f199239 | 2006-09-30 23:28:28 -0700 | [diff] [blame] | 156 | time_adj = shift_right(time_offset, SHIFT_PLL + time_constant); | 
| Roman Zippel | 3d3675c | 2006-09-30 23:28:25 -0700 | [diff] [blame] | 157 | time_offset -= time_adj; | 
|  | 158 | tick_length += (s64)time_adj << (TICK_LENGTH_SHIFT - SHIFT_UPDATE); | 
| john stultz | 4c7ee8d | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 159 |  | 
| Roman Zippel | 8f807f8 | 2006-09-30 23:28:25 -0700 | [diff] [blame] | 160 | if (unlikely(time_adjust)) { | 
|  | 161 | if (time_adjust > MAX_TICKADJ) { | 
|  | 162 | time_adjust -= MAX_TICKADJ; | 
|  | 163 | tick_length += MAX_TICKADJ_SCALED; | 
|  | 164 | } else if (time_adjust < -MAX_TICKADJ) { | 
|  | 165 | time_adjust += MAX_TICKADJ; | 
|  | 166 | tick_length -= MAX_TICKADJ_SCALED; | 
|  | 167 | } else { | 
| Roman Zippel | 8f807f8 | 2006-09-30 23:28:25 -0700 | [diff] [blame] | 168 | tick_length += (s64)(time_adjust * NSEC_PER_USEC / | 
| john stultz | f4304ab | 2007-02-16 01:27:26 -0800 | [diff] [blame] | 169 | NTP_INTERVAL_FREQ) << TICK_LENGTH_SHIFT; | 
| Jim Houston | bb1d860 | 2006-10-28 10:38:56 -0700 | [diff] [blame] | 170 | time_adjust = 0; | 
| Roman Zippel | 8f807f8 | 2006-09-30 23:28:25 -0700 | [diff] [blame] | 171 | } | 
| john stultz | 4c7ee8d | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 172 | } | 
|  | 173 | } | 
|  | 174 |  | 
|  | 175 | /* | 
|  | 176 | * Return how long ticks are at the moment, that is, how much time | 
|  | 177 | * update_wall_time_one_tick will add to xtime next time we call it | 
|  | 178 | * (assuming no calls to do_adjtimex in the meantime). | 
|  | 179 | * The return value is in fixed-point nanoseconds shifted by the | 
|  | 180 | * specified number of bits to the right of the binary point. | 
|  | 181 | * This function has no side-effects. | 
|  | 182 | */ | 
|  | 183 | u64 current_tick_length(void) | 
|  | 184 | { | 
| Roman Zippel | 8f807f8 | 2006-09-30 23:28:25 -0700 | [diff] [blame] | 185 | return tick_length; | 
| john stultz | 4c7ee8d | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 186 | } | 
|  | 187 |  | 
|  | 188 |  | 
|  | 189 | void __attribute__ ((weak)) notify_arch_cmos_timer(void) | 
|  | 190 | { | 
|  | 191 | return; | 
|  | 192 | } | 
|  | 193 |  | 
|  | 194 | /* adjtimex mainly allows reading (and writing, if superuser) of | 
|  | 195 | * kernel time-keeping variables. used by xntpd. | 
|  | 196 | */ | 
|  | 197 | int do_adjtimex(struct timex *txc) | 
|  | 198 | { | 
|  | 199 | long ltemp, mtemp, save_adjust; | 
| Roman Zippel | f199239 | 2006-09-30 23:28:28 -0700 | [diff] [blame] | 200 | s64 freq_adj, temp64; | 
| john stultz | 4c7ee8d | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 201 | int result; | 
|  | 202 |  | 
|  | 203 | /* In order to modify anything, you gotta be super-user! */ | 
|  | 204 | if (txc->modes && !capable(CAP_SYS_TIME)) | 
|  | 205 | return -EPERM; | 
|  | 206 |  | 
|  | 207 | /* Now we validate the data before disabling interrupts */ | 
|  | 208 |  | 
|  | 209 | if ((txc->modes & ADJ_OFFSET_SINGLESHOT) == ADJ_OFFSET_SINGLESHOT) | 
|  | 210 | /* singleshot must not be used with any other mode bits */ | 
|  | 211 | if (txc->modes != ADJ_OFFSET_SINGLESHOT) | 
|  | 212 | return -EINVAL; | 
|  | 213 |  | 
|  | 214 | if (txc->modes != ADJ_OFFSET_SINGLESHOT && (txc->modes & ADJ_OFFSET)) | 
|  | 215 | /* adjustment Offset limited to +- .512 seconds */ | 
|  | 216 | if (txc->offset <= - MAXPHASE || txc->offset >= MAXPHASE ) | 
|  | 217 | return -EINVAL; | 
|  | 218 |  | 
|  | 219 | /* if the quartz is off by more than 10% something is VERY wrong ! */ | 
|  | 220 | if (txc->modes & ADJ_TICK) | 
|  | 221 | if (txc->tick <  900000/USER_HZ || | 
|  | 222 | txc->tick > 1100000/USER_HZ) | 
|  | 223 | return -EINVAL; | 
|  | 224 |  | 
|  | 225 | write_seqlock_irq(&xtime_lock); | 
|  | 226 | result = time_state;	/* mostly `TIME_OK' */ | 
|  | 227 |  | 
|  | 228 | /* Save for later - semantics of adjtime is to return old value */ | 
| Roman Zippel | 8f807f8 | 2006-09-30 23:28:25 -0700 | [diff] [blame] | 229 | save_adjust = time_adjust; | 
| john stultz | 4c7ee8d | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 230 |  | 
|  | 231 | #if 0	/* STA_CLOCKERR is never set yet */ | 
|  | 232 | time_status &= ~STA_CLOCKERR;		/* reset STA_CLOCKERR */ | 
|  | 233 | #endif | 
|  | 234 | /* If there are input parameters, then process them */ | 
|  | 235 | if (txc->modes) | 
|  | 236 | { | 
|  | 237 | if (txc->modes & ADJ_STATUS)	/* only set allowed bits */ | 
|  | 238 | time_status =  (txc->status & ~STA_RONLY) | | 
|  | 239 | (time_status & STA_RONLY); | 
|  | 240 |  | 
|  | 241 | if (txc->modes & ADJ_FREQUENCY) {	/* p. 22 */ | 
|  | 242 | if (txc->freq > MAXFREQ || txc->freq < -MAXFREQ) { | 
|  | 243 | result = -EINVAL; | 
|  | 244 | goto leave; | 
|  | 245 | } | 
| john stultz | f4304ab | 2007-02-16 01:27:26 -0800 | [diff] [blame] | 246 | time_freq = ((s64)txc->freq * NSEC_PER_USEC) | 
|  | 247 | >> (SHIFT_USEC - SHIFT_NSEC); | 
| john stultz | 4c7ee8d | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 248 | } | 
|  | 249 |  | 
|  | 250 | if (txc->modes & ADJ_MAXERROR) { | 
|  | 251 | if (txc->maxerror < 0 || txc->maxerror >= NTP_PHASE_LIMIT) { | 
|  | 252 | result = -EINVAL; | 
|  | 253 | goto leave; | 
|  | 254 | } | 
|  | 255 | time_maxerror = txc->maxerror; | 
|  | 256 | } | 
|  | 257 |  | 
|  | 258 | if (txc->modes & ADJ_ESTERROR) { | 
|  | 259 | if (txc->esterror < 0 || txc->esterror >= NTP_PHASE_LIMIT) { | 
|  | 260 | result = -EINVAL; | 
|  | 261 | goto leave; | 
|  | 262 | } | 
|  | 263 | time_esterror = txc->esterror; | 
|  | 264 | } | 
|  | 265 |  | 
|  | 266 | if (txc->modes & ADJ_TIMECONST) {	/* p. 24 */ | 
|  | 267 | if (txc->constant < 0) {	/* NTP v4 uses values > 6 */ | 
|  | 268 | result = -EINVAL; | 
|  | 269 | goto leave; | 
|  | 270 | } | 
| Roman Zippel | f199239 | 2006-09-30 23:28:28 -0700 | [diff] [blame] | 271 | time_constant = min(txc->constant + 4, (long)MAXTC); | 
| john stultz | 4c7ee8d | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 272 | } | 
|  | 273 |  | 
|  | 274 | if (txc->modes & ADJ_OFFSET) {	/* values checked earlier */ | 
|  | 275 | if (txc->modes == ADJ_OFFSET_SINGLESHOT) { | 
|  | 276 | /* adjtime() is independent from ntp_adjtime() */ | 
| Roman Zippel | 8f807f8 | 2006-09-30 23:28:25 -0700 | [diff] [blame] | 277 | time_adjust = txc->offset; | 
| john stultz | 4c7ee8d | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 278 | } | 
|  | 279 | else if (time_status & STA_PLL) { | 
| Roman Zippel | 04b617e | 2006-09-30 23:28:27 -0700 | [diff] [blame] | 280 | ltemp = txc->offset * NSEC_PER_USEC; | 
| john stultz | 4c7ee8d | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 281 |  | 
|  | 282 | /* | 
|  | 283 | * Scale the phase adjustment and | 
|  | 284 | * clamp to the operating range. | 
|  | 285 | */ | 
| Roman Zippel | 04b617e | 2006-09-30 23:28:27 -0700 | [diff] [blame] | 286 | time_offset = min(ltemp, MAXPHASE * NSEC_PER_USEC); | 
|  | 287 | time_offset = max(time_offset, -MAXPHASE * NSEC_PER_USEC); | 
| john stultz | 4c7ee8d | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 288 |  | 
|  | 289 | /* | 
|  | 290 | * Select whether the frequency is to be controlled | 
|  | 291 | * and in which mode (PLL or FLL). Clamp to the operating | 
|  | 292 | * range. Ugly multiply/divide should be replaced someday. | 
|  | 293 | */ | 
|  | 294 |  | 
|  | 295 | if (time_status & STA_FREQHOLD || time_reftime == 0) | 
|  | 296 | time_reftime = xtime.tv_sec; | 
|  | 297 | mtemp = xtime.tv_sec - time_reftime; | 
|  | 298 | time_reftime = xtime.tv_sec; | 
| Roman Zippel | f199239 | 2006-09-30 23:28:28 -0700 | [diff] [blame] | 299 |  | 
|  | 300 | freq_adj = (s64)time_offset * mtemp; | 
|  | 301 | freq_adj = shift_right(freq_adj, time_constant * 2 + | 
|  | 302 | (SHIFT_PLL + 2) * 2 - SHIFT_NSEC); | 
|  | 303 | if (mtemp >= MINSEC && (time_status & STA_FLL || mtemp > MAXSEC)) { | 
|  | 304 | temp64 = (s64)time_offset << (SHIFT_NSEC - SHIFT_FLL); | 
|  | 305 | if (time_offset < 0) { | 
|  | 306 | temp64 = -temp64; | 
|  | 307 | do_div(temp64, mtemp); | 
|  | 308 | freq_adj -= temp64; | 
|  | 309 | } else { | 
|  | 310 | do_div(temp64, mtemp); | 
|  | 311 | freq_adj += temp64; | 
|  | 312 | } | 
| john stultz | 4c7ee8d | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 313 | } | 
| Roman Zippel | 04b617e | 2006-09-30 23:28:27 -0700 | [diff] [blame] | 314 | freq_adj += time_freq; | 
|  | 315 | freq_adj = min(freq_adj, (s64)MAXFREQ_NSEC); | 
|  | 316 | time_freq = max(freq_adj, (s64)-MAXFREQ_NSEC); | 
| john stultz | f4304ab | 2007-02-16 01:27:26 -0800 | [diff] [blame] | 317 | time_offset = (time_offset / NTP_INTERVAL_FREQ) | 
|  | 318 | << SHIFT_UPDATE; | 
| john stultz | 4c7ee8d | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 319 | } /* STA_PLL */ | 
|  | 320 | } /* txc->modes & ADJ_OFFSET */ | 
| Roman Zippel | b0ee755 | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 321 | if (txc->modes & ADJ_TICK) | 
| john stultz | 4c7ee8d | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 322 | tick_usec = txc->tick; | 
| Roman Zippel | b0ee755 | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 323 |  | 
| Roman Zippel | dc6a43e | 2006-09-30 23:28:24 -0700 | [diff] [blame] | 324 | if (txc->modes & (ADJ_TICK|ADJ_FREQUENCY|ADJ_OFFSET)) | 
| Roman Zippel | b0ee755 | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 325 | ntp_update_frequency(); | 
| john stultz | 4c7ee8d | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 326 | } /* txc->modes */ | 
|  | 327 | leave:	if ((time_status & (STA_UNSYNC|STA_CLOCKERR)) != 0) | 
|  | 328 | result = TIME_ERROR; | 
|  | 329 |  | 
|  | 330 | if ((txc->modes & ADJ_OFFSET_SINGLESHOT) == ADJ_OFFSET_SINGLESHOT) | 
|  | 331 | txc->offset	   = save_adjust; | 
| Roman Zippel | 3d3675c | 2006-09-30 23:28:25 -0700 | [diff] [blame] | 332 | else | 
| john stultz | f4304ab | 2007-02-16 01:27:26 -0800 | [diff] [blame] | 333 | txc->offset    = shift_right(time_offset, SHIFT_UPDATE) | 
|  | 334 | * NTP_INTERVAL_FREQ / 1000; | 
|  | 335 | txc->freq	   = (time_freq / NSEC_PER_USEC) | 
|  | 336 | << (SHIFT_USEC - SHIFT_NSEC); | 
| john stultz | 4c7ee8d | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 337 | txc->maxerror	   = time_maxerror; | 
|  | 338 | txc->esterror	   = time_esterror; | 
|  | 339 | txc->status	   = time_status; | 
|  | 340 | txc->constant	   = time_constant; | 
| Adrian Bunk | 70bc42f | 2006-09-30 23:28:29 -0700 | [diff] [blame] | 341 | txc->precision	   = 1; | 
| Roman Zippel | 97eebe1 | 2006-09-30 23:28:26 -0700 | [diff] [blame] | 342 | txc->tolerance	   = MAXFREQ; | 
| john stultz | 4c7ee8d | 2006-09-30 23:28:22 -0700 | [diff] [blame] | 343 | txc->tick	   = tick_usec; | 
|  | 344 |  | 
|  | 345 | /* PPS is not implemented, so these are zero */ | 
|  | 346 | txc->ppsfreq	   = 0; | 
|  | 347 | txc->jitter	   = 0; | 
|  | 348 | txc->shift	   = 0; | 
|  | 349 | txc->stabil	   = 0; | 
|  | 350 | txc->jitcnt	   = 0; | 
|  | 351 | txc->calcnt	   = 0; | 
|  | 352 | txc->errcnt	   = 0; | 
|  | 353 | txc->stbcnt	   = 0; | 
|  | 354 | write_sequnlock_irq(&xtime_lock); | 
|  | 355 | do_gettimeofday(&txc->time); | 
|  | 356 | notify_arch_cmos_timer(); | 
|  | 357 | return(result); | 
|  | 358 | } |