Skip to content

Commit 22cfbbf

Browse files
john stultzIngo Molnar
authored andcommitted
ntp: adjust SHIFT_PLL to improve NTP convergence
The conversion to the ntpv4 reference model f199239 ("ntp: convert to the NTP4 reference model") in 2.6.19 added nanosecond resolution the adjtimex interface, but also changed the "stiffness" of the frequency adjustments, causing NTP convergence time to greatly increase. SHIFT_PLL, which reduces the stiffness of the freq adjustments, was designed to be inversely linked to HZ, and the reference value of 4 was designed for Unix systems using HZ=100. However Linux's clock steering code mostly independent of HZ. So this patch reduces the SHIFT_PLL value from 4 to 2, which causes NTPd behavior to match kernels prior to 2.6.19, greatly reducing convergence times, and improving close synchronization through environmental thermal changes. The patch also changes some l's to L's in nearby code to avoid misreading 50l as 501. [ Impact: tweak NTP algorithm for faster convergence ] Signed-off-by: John Stultz <[email protected]> Acked-by: Rik van Riel <[email protected]> Cc: [email protected] Signed-off-by: Andrew Morton <[email protected]> LKML-Reference: <[email protected]> Signed-off-by: Ingo Molnar <[email protected]>
1 parent 413f81e commit 22cfbbf

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

include/linux/timex.h

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,37 @@ struct timex {
170170
#include <asm/timex.h>
171171

172172
/*
173-
* SHIFT_KG and SHIFT_KF establish the damping of the PLL and are chosen
174-
* for a slightly underdamped convergence characteristic. SHIFT_KH
175-
* establishes the damping of the FLL and is chosen by wisdom and black
176-
* art.
173+
* SHIFT_PLL is used as a dampening factor to define how much we
174+
* adjust the frequency correction for a given offset in PLL mode.
175+
* It also used in dampening the offset correction, to define how
176+
* much of the current value in time_offset we correct for each
177+
* second. Changing this value changes the stiffness of the ntp
178+
* adjustment code. A lower value makes it more flexible, reducing
179+
* NTP convergence time. A higher value makes it stiffer, increasing
180+
* convergence time, but making the clock more stable.
177181
*
178-
* MAXTC establishes the maximum time constant of the PLL. With the
179-
* SHIFT_KG and SHIFT_KF values given and a time constant range from
180-
* zero to MAXTC, the PLL will converge in 15 minutes to 16 hours,
181-
* respectively.
182+
* In David Mills' nanokenrel reference implmentation SHIFT_PLL is 4.
183+
* However this seems to increase convergence time much too long.
184+
*
185+
* https://lists.ntp.org/pipermail/hackers/2008-January/003487.html
186+
*
187+
* In the above mailing list discussion, it seems the value of 4
188+
* was appropriate for other Unix systems with HZ=100, and that
189+
* SHIFT_PLL should be decreased as HZ increases. However, Linux's
190+
* clock steering implementation is HZ independent.
191+
*
192+
* Through experimentation, a SHIFT_PLL value of 2 was found to allow
193+
* for fast convergence (very similar to the NTPv3 code used prior to
194+
* v2.6.19), with good clock stability.
195+
*
196+
*
197+
* SHIFT_FLL is used as a dampening factor to define how much we
198+
* adjust the frequency correction for a given offset in FLL mode.
199+
* In David Mills' nanokenrel reference implmentation SHIFT_PLL is 2.
200+
*
201+
* MAXTC establishes the maximum time constant of the PLL.
182202
*/
183-
#define SHIFT_PLL 4 /* PLL frequency factor (shift) */
203+
#define SHIFT_PLL 2 /* PLL frequency factor (shift) */
184204
#define SHIFT_FLL 2 /* FLL frequency factor (shift) */
185205
#define MAXTC 10 /* maximum time constant (shift) */
186206

@@ -192,10 +212,10 @@ struct timex {
192212
#define SHIFT_USEC 16 /* frequency offset scale (shift) */
193213
#define PPM_SCALE ((s64)NSEC_PER_USEC << (NTP_SCALE_SHIFT - SHIFT_USEC))
194214
#define PPM_SCALE_INV_SHIFT 19
195-
#define PPM_SCALE_INV ((1ll << (PPM_SCALE_INV_SHIFT + NTP_SCALE_SHIFT)) / \
215+
#define PPM_SCALE_INV ((1LL << (PPM_SCALE_INV_SHIFT + NTP_SCALE_SHIFT)) / \
196216
PPM_SCALE + 1)
197217

198-
#define MAXPHASE 500000000l /* max phase error (ns) */
218+
#define MAXPHASE 500000000L /* max phase error (ns) */
199219
#define MAXFREQ 500000 /* max frequency error (ns/s) */
200220
#define MAXFREQ_SCALED ((s64)MAXFREQ << NTP_SCALE_SHIFT)
201221
#define MINSEC 256 /* min interval between updates (s) */

0 commit comments

Comments
 (0)