Bug 156481 - [kernel] [patch] kernel incorrectly reports PPS jitter with accurate measurements
Summary: [kernel] [patch] kernel incorrectly reports PPS jitter with accurate measurem...
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-18 20:50 UTC by Ian Lepore
Modified: 2015-08-02 22:14 UTC (History)
1 user (show)

See Also:
bugmeister: mfc-stable8?
bugmeister: mfc-stable9?
bugmeister: mfc-stable10?


Attachments
patch-ppsjitter-kern_ntptime.c (1.11 KB, text/plain)
2011-04-18 20:50 UTC, Ian Lepore
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ian Lepore 2011-04-18 20:50:04 UTC
The kernel maintains an acceptable-jitter threshold based on a running 
average of the measurement magnitude.  After receiving a series of small 
delta measurements the jitter threshold is reduced to less than the 
measurement resolution, so that when a measurement crosses a timer tick 
boundary and pops a resolution-sized delta it gets flagged as jitter.  

On one of our systems that uses a timecounter running at ~2.8 mhz (so the 
measurement resolution is approximately 357 nanoseconds), a printf was 
added to the code that checks for pps jitter and the data it logged 
confirms the problem: 

Apr 13 10:57:49 kernel: u_nsec 351 popcorn threshold 32 is 4*pps_jitter 8)
Apr 13 10:59:13 kernel: u_nsec 352 popcorn threshold 24 is 4*pps_jitter 6)
Apr 13 11:00:51 kernel: u_nsec 352 popcorn threshold 20 is 4*pps_jitter 5)
Apr 13 11:03:01 kernel: u_nsec 354 popcorn threshold 8 is 4*pps_jitter 2)

In the pathological worst case the jitter threshold can get reduced to 
zero and any non-zero measurement is flagged as jitter:

Apr 13 11:05:59 kernel: u_nsec 1 popcorn threshold 0 is 4*pps_jitter 0)
Apr 13 11:06:02 kernel: u_nsec 2 popcorn threshold 0 is 4*pps_jitter 0)
Apr 13 11:06:03 kernel: u_nsec 1 popcorn threshold 0 is 4*pps_jitter 0)
Apr 13 11:06:05 kernel: u_nsec 2 popcorn threshold 0 is 4*pps_jitter 0)
Apr 13 11:06:07 kernel: u_nsec 3 popcorn threshold 0 is 4*pps_jitter 0)
Apr 13 11:06:08 kernel: u_nsec 2 popcorn threshold 0 is 4*pps_jitter 0)
Apr 13 11:06:10 kernel: u_nsec 3 popcorn threshold 0 is 4*pps_jitter 0)
Apr 13 11:06:11 kernel: u_nsec 1 popcorn threshold 0 is 4*pps_jitter 0)

Our FreeBSD-based timekeeping products get into this pathological 
condition and ntpd fills syslog with "kernel time sync enabled" messages 
where the status bits continually toggle between 2101 and 2303 (the jitter 
bit toggles more or less at random every 16 seconds).

Fix: The following patch uses two times the timer tick duration as a floor
value for the jitter threshold, so that a series of small-delta 
measurements don't cause subsequent small deltas to be counted as jitter.

It should apply cleanly to any FreeBSD version from 6.2 through -current.

Fix sponsored by: Symmetricom, Inc
Comment 1 dfilter service freebsd_committer 2012-08-16 03:35:54 UTC
Author: imp
Date: Thu Aug 16 02:35:44 2012
New Revision: 239320
URL: http://svn.freebsd.org/changeset/base/239320

Log:
  Limit popcorn limit to something sane (either 2ns or 2 ticks if that's
  longer).
  
  PR:		156481
  Submitted by:	Ian Lepore

Modified:
  head/sys/kern/kern_ntptime.c

Modified: head/sys/kern/kern_ntptime.c
==============================================================================
--- head/sys/kern/kern_ntptime.c	Thu Aug 16 00:53:23 2012	(r239319)
+++ head/sys/kern/kern_ntptime.c	Thu Aug 16 02:35:44 2012	(r239320)
@@ -832,8 +832,15 @@ hardpps(tsp, nsec)
 	 * discarded. otherwise, if so enabled, the time offset is
 	 * updated. We can tolerate a modest loss of data here without
 	 * much degrading time accuracy.
-	 */
-	if (u_nsec > (pps_jitter << PPS_POPCORN)) {
+	 *
+	 * The measurements being checked here were made with the system
+	 * timecounter, so the popcorn threshold is not allowed to fall below
+	 * the number of nanoseconds in two ticks of the timecounter.  For a
+	 * timecounter running faster than 1 GHz the lower bound is 2ns, just
+	 * to avoid a nonsensical threshold of zero.
+	*/
+	if (u_nsec > lmax(pps_jitter << PPS_POPCORN, 
+	    2 * (NANOSECOND / (long)qmin(NANOSECOND, tc_getfrequency())))) {
 		time_status |= STA_PPSJITTER;
 		pps_jitcnt++;
 	} else if (time_status & STA_PPSTIME) {
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
Comment 2 Warner Losh freebsd_committer 2012-08-16 03:36:10 UTC
State Changed
From-To: open->patched

Committed the fix, after careful review.
Comment 3 Hiren Panchasara freebsd_committer 2015-08-02 22:14:24 UTC
Based on comment #2.