Subject: kern/14058: time-of-day goes backwards
To: None <gnats-bugs@gnats.netbsd.org>
From: None <itohy@netbsd.org>
List: netbsd-bugs
Date: 09/25/2001 13:11:35
>Number:         14058
>Category:       kern
>Synopsis:       time-of-day goes backwards
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Sep 24 21:12:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     ITOH Yasufumi
>Release:        1.5Y (Sept. 23, 2001)
>Organization:
	
>Environment:
System: NetBSD fmv.my.domain 1.5Y NetBSD 1.5Y (FMV) #2: Mon Sep 24 18:41:05 JST 2001 itohy@fmv.my.domain:/w/src/sys/arch/i386/compile/FMV i386
Architecture: i386
Machine: i386

Tested on P54C 133MHz and MMX 166MHz
Running ntpd

>Description:
	The system time (time-of-day) occasionally goes backwards.

	It doesn't occur on 1.5T and 1.5X (Sept. 11, 2001) kernels
	(or at least, doesn't occur such often).

>How-To-Repeat:
	Here's a test program.  Save it as timetest.c .
	It issues gettimeofday system call continuously and print the
	time if the time goes backwards.

	% cc timetest.c
	% nice -20 ./a.out
	1001388478 833357 < 1001388478 843046
	1001388596 363895 < 1001388596 373576
	1001388864 198448 < 1001388864 207896
	1001389132 102678 < 1001389132 112550
	1001389165 605957 < 1001389165 615655
	1001389299 558052 < 1001389299 567758
	^C
	%

#include <stdio.h>
#include <sys/time.h>

main()
{
	struct timeval tv1, tv2;

	gettimeofday(&tv2, (struct timezone *) 0);

	for (;;) {
		gettimeofday(&tv1, (struct timezone *) 0);

		if (tv1.tv_sec < tv2.tv_sec ||
		    (tv1.tv_sec == tv2.tv_sec && tv1.tv_usec < tv2.tv_usec)) {
			printf("%d %d < %d %d\n",
			    tv1.tv_sec, tv1.tv_usec, tv2.tv_sec, tv2.tv_usec);
		}
		tv2 = tv1;
	}
}

>Fix:
	ENOCLUE

>Release-Note:
>Audit-Trail:
>Unformatted: