aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorRoman Zippel <zippel@linux-m68k.org>2008-05-01 07:34:34 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-05-01 11:03:58 -0400
commit074b3b87941c99bc0ce35385b5817924b1ed0c23 (patch)
treeaa2d11a2df37d631236a28713873023632f74a91 /kernel
parenteea83d896e318bda54be2d2770d2c5d6668d11db (diff)
ntp: increase time_freq resolution
This changes time_freq to a 64bit value and makes it static (the only outside user had no real need to modify it). Intermediate values were already 64bit, so the change isn't that big, but it saves a little in shifts by replacing SHIFT_NSEC with TICK_LENGTH_SHIFT. PPM_SCALE is then used to convert between user space and kernel space representation. Signed-off-by: Roman Zippel <zippel@linux-m68k.org> Cc: john stultz <johnstul@us.ibm.com> Cc: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/time/ntp.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index 3fc81066d7f..c6ae0c24989 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -39,7 +39,7 @@ static s64 time_offset; /* time adjustment (ns) */
39static long time_constant = 2; /* pll time constant */ 39static long time_constant = 2; /* pll time constant */
40long time_maxerror = NTP_PHASE_LIMIT; /* maximum error (us) */ 40long time_maxerror = NTP_PHASE_LIMIT; /* maximum error (us) */
41long time_esterror = NTP_PHASE_LIMIT; /* estimated error (us) */ 41long time_esterror = NTP_PHASE_LIMIT; /* estimated error (us) */
42long time_freq; /* frequency offset (scaled ppm)*/ 42static s64 time_freq; /* frequency offset (scaled ns/s)*/
43static long time_reftime; /* time at last adjustment (s) */ 43static long time_reftime; /* time at last adjustment (s) */
44long time_adjust; 44long time_adjust;
45static long ntp_tick_adj; 45static long ntp_tick_adj;
@@ -49,7 +49,7 @@ static void ntp_update_frequency(void)
49 u64 second_length = (u64)(tick_usec * NSEC_PER_USEC * USER_HZ) 49 u64 second_length = (u64)(tick_usec * NSEC_PER_USEC * USER_HZ)
50 << TICK_LENGTH_SHIFT; 50 << TICK_LENGTH_SHIFT;
51 second_length += (s64)ntp_tick_adj << TICK_LENGTH_SHIFT; 51 second_length += (s64)ntp_tick_adj << TICK_LENGTH_SHIFT;
52 second_length += (s64)time_freq << (TICK_LENGTH_SHIFT - SHIFT_NSEC); 52 second_length += time_freq;
53 53
54 tick_length_base = second_length; 54 tick_length_base = second_length;
55 55
@@ -86,16 +86,16 @@ static void ntp_update_offset(long offset)
86 time_reftime = xtime.tv_sec; 86 time_reftime = xtime.tv_sec;
87 87
88 freq_adj = time_offset * mtemp; 88 freq_adj = time_offset * mtemp;
89 freq_adj = shift_right(freq_adj, time_constant * 2 + 89 freq_adj <<= TICK_LENGTH_SHIFT - 2 * (SHIFT_PLL + 2 + time_constant);
90 (SHIFT_PLL + 2) * 2 - SHIFT_NSEC);
91 time_status &= ~STA_MODE; 90 time_status &= ~STA_MODE;
92 if (mtemp >= MINSEC && (time_status & STA_FLL || mtemp > MAXSEC)) { 91 if (mtemp >= MINSEC && (time_status & STA_FLL || mtemp > MAXSEC)) {
93 freq_adj += div_s64(time_offset << (SHIFT_NSEC - SHIFT_FLL), mtemp); 92 freq_adj += div_s64(time_offset << (TICK_LENGTH_SHIFT - SHIFT_FLL),
93 mtemp);
94 time_status |= STA_MODE; 94 time_status |= STA_MODE;
95 } 95 }
96 freq_adj += time_freq; 96 freq_adj += time_freq;
97 freq_adj = min(freq_adj, (s64)MAXFREQ_NSEC); 97 freq_adj = min(freq_adj, MAXFREQ_SCALED);
98 time_freq = max(freq_adj, (s64)-MAXFREQ_NSEC); 98 time_freq = max(freq_adj, -MAXFREQ_SCALED);
99 time_offset = div_s64(time_offset, NTP_INTERVAL_FREQ); 99 time_offset = div_s64(time_offset, NTP_INTERVAL_FREQ);
100 time_offset <<= SHIFT_UPDATE; 100 time_offset <<= SHIFT_UPDATE;
101} 101}
@@ -131,7 +131,7 @@ void second_overflow(void)
131 long time_adj; 131 long time_adj;
132 132
133 /* Bump the maxerror field */ 133 /* Bump the maxerror field */
134 time_maxerror += MAXFREQ >> SHIFT_USEC; 134 time_maxerror += MAXFREQ / NSEC_PER_USEC;
135 if (time_maxerror > NTP_PHASE_LIMIT) { 135 if (time_maxerror > NTP_PHASE_LIMIT) {
136 time_maxerror = NTP_PHASE_LIMIT; 136 time_maxerror = NTP_PHASE_LIMIT;
137 time_status |= STA_UNSYNC; 137 time_status |= STA_UNSYNC;
@@ -323,10 +323,9 @@ int do_adjtimex(struct timex *txc)
323 time_status &= ~STA_NANO; 323 time_status &= ~STA_NANO;
324 324
325 if (txc->modes & ADJ_FREQUENCY) { 325 if (txc->modes & ADJ_FREQUENCY) {
326 time_freq = min(txc->freq, MAXFREQ); 326 time_freq = (s64)txc->freq * PPM_SCALE;
327 time_freq = min(time_freq, -MAXFREQ); 327 time_freq = min(time_freq, MAXFREQ_SCALED);
328 time_freq = ((s64)time_freq * NSEC_PER_USEC) 328 time_freq = max(time_freq, -MAXFREQ_SCALED);
329 >> (SHIFT_USEC - SHIFT_NSEC);
330 } 329 }
331 330
332 if (txc->modes & ADJ_MAXERROR) 331 if (txc->modes & ADJ_MAXERROR)
@@ -369,14 +368,15 @@ int do_adjtimex(struct timex *txc)
369 if (!(time_status & STA_NANO)) 368 if (!(time_status & STA_NANO))
370 txc->offset /= NSEC_PER_USEC; 369 txc->offset /= NSEC_PER_USEC;
371 } 370 }
372 txc->freq = (time_freq / NSEC_PER_USEC) << 371 txc->freq = shift_right((s32)(time_freq >> PPM_SCALE_INV_SHIFT) *
373 (SHIFT_USEC - SHIFT_NSEC); 372 (s64)PPM_SCALE_INV,
373 TICK_LENGTH_SHIFT);
374 txc->maxerror = time_maxerror; 374 txc->maxerror = time_maxerror;
375 txc->esterror = time_esterror; 375 txc->esterror = time_esterror;
376 txc->status = time_status; 376 txc->status = time_status;
377 txc->constant = time_constant; 377 txc->constant = time_constant;
378 txc->precision = 1; 378 txc->precision = 1;
379 txc->tolerance = MAXFREQ; 379 txc->tolerance = MAXFREQ_SCALED / PPM_SCALE;
380 txc->tick = tick_usec; 380 txc->tick = tick_usec;
381 381
382 /* PPS is not implemented, so these are zero */ 382 /* PPS is not implemented, so these are zero */