Subject: gettimeofday goes backwards
To: None <port-i386@netbsd.org>
From: Brad du Plessis <bradd@cat.co.za>
List: port-i386
Date: 06/01/2007 08:39:15
Hi all,

I've got 3 different fields systems all with identical hardware running 
NetBSD 3.1_RC2 that exhibit symptoms of the problem reported in PR #14058.

Hardware:
Motherboard: DFI G7V-600B REV. B
CPU: Celeron 2.6GHz

I modified the test code used to reproduce the problem slightly so that 
the process wasn't too expensive (these systems are in the field).

#include <stdio.h>
#include <sys/time.h>
#include <unistd.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;
		usleep(50000);
	}
}

And running normally (without renicing the process as per the PR test):

# ./timetest
1180629841 868089 < 1180629843 366779

This happened after running for a few hours.

To answer the obvious questions:
1) No, ntp is not running.
2) No, the time hasn't been set back manually.

It should be noted also that over the period in which the time went 
backwards the system appeared to lose almost 30 seconds!

Has anyone got any idea what could be causing this? The jump back in 
time here is larger than anything reported in PR 14058.

Any help would be much appreciated!
Thanks,
 Brad