Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 15 Jul 2015 19:11:44 +0000 (UTC)
From:      Xin LI <delphij@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r285611 - stable/10/sys/kern
Message-ID:  <201507151911.t6FJBiCg025628@svnmir.geo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: delphij
Date: Wed Jul 15 19:11:43 2015
New Revision: 285611
URL: https://svnweb.freebsd.org/changeset/base/285611

Log:
  MFC r285424 (ian):
  
  Use the monotonic (uptime) counter rather than time-of-day to measure
  elapsed time between ntp_adjtime() clock offset adjustments.  This
  eliminates spurious frequency steering after a large clock step (such
  as a 1970->2015 step on a system with no battery-backed clock hardware).
  
  This problem was discovered after the import of ntpd 4.2.8, which does
  things in a slightly different (but still correct) order than the 4.2.4
  we had previously.  In particular, 4.2.4 would step the clock then
  immediately after use ntp_adjtime() to set the frequency and offset to
  zero, which captured the post-step time-of-day as a side effect.  In
  4.2.8, ntpd sets frequency and offset to zero before any initial clock
  step, capturing the time as 1970-ish, then when it next calls
  ntp_adjtime() it's with a non-zero offset measurement. This non-zero
  value gets multiplied by the apparent 45-year interval, which blows up
  into a completely bogus frequency steer.  That gets clamped to 500ppm,
  but that's still enough to make the clock drift so fast that ntpd has
  to keep stepping it every few minutes to compensate.
  
  Approved by:	re (gjb)

Modified:
  stable/10/sys/kern/kern_ntptime.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/kern/kern_ntptime.c
==============================================================================
--- stable/10/sys/kern/kern_ntptime.c	Wed Jul 15 18:49:15 2015	(r285610)
+++ stable/10/sys/kern/kern_ntptime.c	Wed Jul 15 19:11:43 2015	(r285611)
@@ -155,7 +155,7 @@ static long time_constant;		/* poll inte
 static long time_precision = 1;		/* clock precision (ns) */
 static long time_maxerror = MAXPHASE / 1000; /* maximum error (us) */
 long time_esterror = MAXPHASE / 1000; /* estimated error (us) */
-static long time_reftime;		/* time at last adjustment (s) */
+static long time_reftime;		/* uptime at last adjustment (s) */
 static l_fp time_offset;		/* time offset (ns) */
 static l_fp time_freq;			/* frequency offset (ns/s) */
 static l_fp time_adj;			/* tick adjust (ns/s) */
@@ -696,12 +696,12 @@ hardupdate(offset)
 	 * otherwise, the argument offset is used to compute it.
 	 */
 	if (time_status & STA_PPSFREQ && time_status & STA_PPSSIGNAL) {
-		time_reftime = time_second;
+		time_reftime = time_uptime;
 		return;
 	}
 	if (time_status & STA_FREQHOLD || time_reftime == 0)
-		time_reftime = time_second;
-	mtemp = time_second - time_reftime;
+		time_reftime = time_uptime;
+	mtemp = time_uptime - time_reftime;
 	L_LINT(ftemp, time_monitor);
 	L_RSHIFT(ftemp, (SHIFT_PLL + 2 + time_constant) << 1);
 	L_MPY(ftemp, mtemp);
@@ -714,7 +714,7 @@ hardupdate(offset)
 		L_ADD(time_freq, ftemp);
 		time_status |= STA_MODE;
 	}
-	time_reftime = time_second;
+	time_reftime = time_uptime;
 	if (L_GINT(time_freq) > MAXFREQ)
 		L_LINT(time_freq, MAXFREQ);
 	else if (L_GINT(time_freq) < -MAXFREQ)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201507151911.t6FJBiCg025628>