Commit f1992393 authored by Roman Zippel's avatar Roman Zippel Committed by Linus Torvalds

[PATCH] ntp: convert to the NTP4 reference model

This converts the kernel ntp model into a model which matches the nanokernel
reference implementations.  The previous patches already increased the
resolution and precision of the computations, so that this conversion becomes
quite simple.

<linux@horizon.com> explains:

The original NTP kernel interface was defined in units of microseconds.
That's what Linux implements.  As computers have gotten faster and can now
split microseconds easily, a new kernel interface using nanosecond units was
defined ("the nanokernel", confusing as that name is to OS hackers), and
there's an STA_NANO bit in the adjtimex() status field to tell the application
which units it's using.

The current ntpd supports both, but Linux loses some possible timing
resolution because of quantization effects, and the ntpd hackers would really
like to be able to drop the backwards compatibility code.

Ulrich Windl has been maintaining a patch set to do the conversion for years,
but it's hard to keep in sync.
Signed-off-by: default avatarRoman Zippel <zippel@linux-m68k.org>
Cc: john stultz <johnstul@us.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 04b617e7
...@@ -69,10 +69,9 @@ ...@@ -69,10 +69,9 @@
* zero to MAXTC, the PLL will converge in 15 minutes to 16 hours, * zero to MAXTC, the PLL will converge in 15 minutes to 16 hours,
* respectively. * respectively.
*/ */
#define SHIFT_KG 6 /* phase factor (shift) */ #define SHIFT_PLL 4 /* PLL frequency factor (shift) */
#define SHIFT_KF 16 /* PLL frequency factor (shift) */ #define SHIFT_FLL 2 /* FLL frequency factor (shift) */
#define SHIFT_KH 2 /* FLL frequency factor (shift) */ #define MAXTC 10 /* maximum time constant (shift) */
#define MAXTC 6 /* maximum time constant (shift) */
/* /*
* The SHIFT_SCALE define establishes the decimal point of the time_phase * The SHIFT_SCALE define establishes the decimal point of the time_phase
...@@ -97,8 +96,8 @@ ...@@ -97,8 +96,8 @@
#define MAXPHASE 512000L /* max phase error (us) */ #define MAXPHASE 512000L /* max phase error (us) */
#define MAXFREQ (512L << SHIFT_USEC) /* max frequency error (ppm) */ #define MAXFREQ (512L << SHIFT_USEC) /* max frequency error (ppm) */
#define MAXFREQ_NSEC (512000L << SHIFT_NSEC) /* max frequency error (ppb) */ #define MAXFREQ_NSEC (512000L << SHIFT_NSEC) /* max frequency error (ppb) */
#define MINSEC 16L /* min interval between updates (s) */ #define MINSEC 256 /* min interval between updates (s) */
#define MAXSEC 1200L /* max interval between updates (s) */ #define MAXSEC 2048 /* max interval between updates (s) */
#define NTP_PHASE_LIMIT (MAXPHASE << 5) /* beyond max. dispersion */ #define NTP_PHASE_LIMIT (MAXPHASE << 5) /* beyond max. dispersion */
/* /*
......
...@@ -145,18 +145,11 @@ void second_overflow(void) ...@@ -145,18 +145,11 @@ void second_overflow(void)
} }
/* /*
* Compute the phase adjustment for the next second. In PLL mode, the * Compute the phase adjustment for the next second. The offset is
* offset is reduced by a fixed factor times the time constant. In FLL * reduced by a fixed factor times the time constant.
* mode the offset is used directly. In either mode, the maximum phase
* adjustment for each second is clamped so as to spread the adjustment
* over not more than the number of seconds between updates.
*/ */
tick_length = tick_length_base; tick_length = tick_length_base;
time_adj = time_offset; time_adj = shift_right(time_offset, SHIFT_PLL + time_constant);
if (!(time_status & STA_FLL))
time_adj = shift_right(time_adj, SHIFT_KG + time_constant);
time_adj = min(time_adj, -((MAXPHASE / HZ) << SHIFT_UPDATE) / MINSEC);
time_adj = max(time_adj, ((MAXPHASE / HZ) << SHIFT_UPDATE) / MINSEC);
time_offset -= time_adj; time_offset -= time_adj;
tick_length += (s64)time_adj << (TICK_LENGTH_SHIFT - SHIFT_UPDATE); tick_length += (s64)time_adj << (TICK_LENGTH_SHIFT - SHIFT_UPDATE);
...@@ -200,7 +193,7 @@ void __attribute__ ((weak)) notify_arch_cmos_timer(void) ...@@ -200,7 +193,7 @@ void __attribute__ ((weak)) notify_arch_cmos_timer(void)
int do_adjtimex(struct timex *txc) int do_adjtimex(struct timex *txc)
{ {
long ltemp, mtemp, save_adjust; long ltemp, mtemp, save_adjust;
s64 freq_adj; s64 freq_adj, temp64;
int result; int result;
/* In order to modify anything, you gotta be super-user! */ /* In order to modify anything, you gotta be super-user! */
...@@ -270,7 +263,7 @@ int do_adjtimex(struct timex *txc) ...@@ -270,7 +263,7 @@ int do_adjtimex(struct timex *txc)
result = -EINVAL; result = -EINVAL;
goto leave; goto leave;
} }
time_constant = txc->constant; time_constant = min(txc->constant + 4, (long)MAXTC);
} }
if (txc->modes & ADJ_OFFSET) { /* values checked earlier */ if (txc->modes & ADJ_OFFSET) { /* values checked earlier */
...@@ -298,26 +291,20 @@ int do_adjtimex(struct timex *txc) ...@@ -298,26 +291,20 @@ int do_adjtimex(struct timex *txc)
time_reftime = xtime.tv_sec; time_reftime = xtime.tv_sec;
mtemp = xtime.tv_sec - time_reftime; mtemp = xtime.tv_sec - time_reftime;
time_reftime = xtime.tv_sec; time_reftime = xtime.tv_sec;
freq_adj = 0;
if (time_status & STA_FLL) { freq_adj = (s64)time_offset * mtemp;
if (mtemp >= MINSEC) { freq_adj = shift_right(freq_adj, time_constant * 2 +
freq_adj = (s64)time_offset << (SHIFT_NSEC - SHIFT_KH); (SHIFT_PLL + 2) * 2 - SHIFT_NSEC);
if (mtemp >= MINSEC && (time_status & STA_FLL || mtemp > MAXSEC)) {
temp64 = (s64)time_offset << (SHIFT_NSEC - SHIFT_FLL);
if (time_offset < 0) { if (time_offset < 0) {
freq_adj = -freq_adj; temp64 = -temp64;
do_div(freq_adj, mtemp); do_div(temp64, mtemp);
freq_adj = -freq_adj; freq_adj -= temp64;
} else } else {
do_div(freq_adj, mtemp); do_div(temp64, mtemp);
} else /* calibration interval too short (p. 12) */ freq_adj += temp64;
result = TIME_ERROR; }
} else { /* PLL mode */
if (mtemp < MAXSEC) {
freq_adj = (s64)ltemp * mtemp;
freq_adj = shift_right(freq_adj,(time_constant +
time_constant +
SHIFT_KF - SHIFT_NSEC));
} else /* calibration interval too long (p. 12) */
result = TIME_ERROR;
} }
freq_adj += time_freq; freq_adj += time_freq;
freq_adj = min(freq_adj, (s64)MAXFREQ_NSEC); freq_adj = min(freq_adj, (s64)MAXFREQ_NSEC);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment