Subject: kern/2787: odd hz adjustment broken when adjtime() adjustment running
To: None <gnats-bugs@gnats.netbsd.org>
From: None <dennis@jnx.com>
List: netbsd-bugs
Date: 09/28/1996 17:52:57
>Number:         2787
>Category:       kern
>Synopsis:       odd hz adjustment broken when adjtime() adjustment running
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people (Kernel Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Sep 28 18:05:00 1996
>Last-Modified:
>Originator:     Dennis Ferguson
>Organization:
	Juniper Networks, Inc.
>Release:        1.2_ALPHA
>Environment:
	DEC Alpha, DEC pmax
System: NetBSD skank.jnx.com 1.2_ALPHA NetBSD 1.2_ALPHA (SKANKLIKE) #5: Sat Sep 28 14:34:02 PDT 1996 dennis@skank.jnx.com:/usr/src/sys/arch/i386/compile/SKANKLIKE i386


>Description:
	In kern/kern_clock.c, without NTP defined, the number of microseconds
	that hardclock() adds to time is computed as follows:

		/*
		 * Increment the time-of-day.  The increment is normally just
		 * ``tick''.  If the machine is one which has a clock frequency
		 * such that ``hz'' would not divide the second evenly into
		 * milliseconds, a periodic adjustment must be applied.  Finally,
		 * if we are still adjusting the time (see adjtime()),
		 * ``tickdelta'' may also be added in.
		 */
		ticks++;
		delta = tick;

	#ifndef NTP
		if (tickfix) {
			tickfixcnt++;
			if (tickfixcnt >= tickfixinterval) {
				delta += tickfix;
				tickfixcnt = 0;
			}
		}
	#endif /* !NTP */
		/* Imprecise 4bsd adjtime() handling */
		if (timedelta != 0) {
			delta = tick + tickdelta;
			timedelta -= tickdelta;
		}

	Note that (despite the comment to the contrary) when an adjtime()
	adjustment is running `delta' is reset, removing the `tickfix'
	added in above.  This makes the clock run less accurately when
	it is being adjusted than when it isn't.
>How-To-Repeat:
	Look at code about.  Or run xntp without the NTP code defined
	in the kernel.
>Fix:

*** kern_clock.c	1996/09/28 22:46:14	1.1
--- kern_clock.c	1996/09/29 00:32:36
***************
*** 419,425 ****
  #endif /* !NTP */
  	/* Imprecise 4bsd adjtime() handling */
  	if (timedelta != 0) {
! 		delta = tick + tickdelta;
  		timedelta -= tickdelta;
  	}
  
--- 419,425 ----
  #endif /* !NTP */
  	/* Imprecise 4bsd adjtime() handling */
  	if (timedelta != 0) {
! 		delta += tickdelta;
  		timedelta -= tickdelta;
  	}
  
>Audit-Trail:
>Unformatted: