Skip site navigation (1) Skip section navigation (2)

gettimeofday() goes backwards on FreeBSD 4.9

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Marc G(dot) Fournier" <scrappy(at)postgresql(dot)org>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: gettimeofday() goes backwards on FreeBSD 4.9
Date: 2003-11-28 20:33:21
Message-ID: 764.1070051601@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-hackers
I said:
> I'm wondering if there's an actual bug in gettimeofday() in this
> platform, such that once in a while it returns a value that's off
> a minute or so ...

Whoa.  Try the following test program.  Then send it in to your friendly
local BSD hackers ....

> uname -a
FreeBSD pgsql74.hub.org 4.9-PRERELEASE FreeBSD 4.9-PRERELEASE #3: Sat Sep 20 14:16:48 ADT 2003     root(at)neptune(dot)hub(dot)org:/usr/obj/usr/src/sys/kernel  i386

> ./a.out
out of order tv_sec: 1070050646 939970, prev 1070051342 516165
out of order tv_sec: 1070051342 789127, prev 1070050646 939970
out of order tv_usec: 1070051342 789127, prev 1070050646 939970
out of order tv_sec: 1070050654 690255, prev 1070051350 216448
out of order tv_sec: 1070051350 402412, prev 1070050654 690255
out of order tv_usec: 1070051350 402412, prev 1070050654 690255
out of order tv_sec: 1070050672 990359, prev 1070051368 416546
out of order tv_sec: 1070051368 501648, prev 1070050672 990359
out of order tv_usec: 1070051368 501648, prev 1070050672 990359
out of order tv_sec: 1070050672 990363, prev 1070051368 516557
out of order tv_sec: 1070051368 700227, prev 1070050672 990363
out of order tv_usec: 1070051368 700227, prev 1070050672 990363
out of order tv_sec: 1070050675 740524, prev 1070051371 216718
out of order tv_sec: 1070051371 346521, prev 1070050675 740524
out of order tv_usec: 1070051371 346521, prev 1070050675 740524
out of order tv_sec: 1070050676 440415, prev 1070051371 916605
out of order tv_usec: 1070050676 440415, prev 1070051371 916605
out of order tv_sec: 1070051372 238348, prev 1070050676 440415
out of order tv_usec: 1070051372 238348, prev 1070050676 440415
^C
> 

			regards, tom lane


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

int
main()
{
	struct timeval prevtime;
	struct timeval curtime;

	gettimeofday(&prevtime, NULL);

	for (;;)
	{
		gettimeofday(&curtime, NULL);

		if (curtime.tv_usec < 0 || curtime.tv_usec >= 1000000)
			fprintf(stderr, "bogus tv_usec: %ld %ld, prev %ld %ld\n",
					(long int) curtime.tv_sec,
					(long int) curtime.tv_usec,
					(long int) prevtime.tv_sec,
					(long int) prevtime.tv_usec);

		if (curtime.tv_sec < prevtime.tv_sec ||
			curtime.tv_sec > prevtime.tv_sec + 1)
			fprintf(stderr, "out of order tv_sec: %ld %ld, prev %ld %ld\n",
					(long int) curtime.tv_sec,
					(long int) curtime.tv_usec,
					(long int) prevtime.tv_sec,
					(long int) prevtime.tv_usec);

		if (curtime.tv_usec < prevtime.tv_usec &&
			curtime.tv_sec != prevtime.tv_sec + 1)
			fprintf(stderr, "out of order tv_usec: %ld %ld, prev %ld %ld\n",
					(long int) curtime.tv_sec,
					(long int) curtime.tv_usec,
					(long int) prevtime.tv_sec,
					(long int) prevtime.tv_usec);

		prevtime = curtime;
	}

	return 0;
}

In response to

Responses

pgsql-hackers by date

Next:From: Rod TaylorDate: 2003-11-28 20:40:42
Subject: Re: $Id$ -> $PostgreSQL$ Change
Previous:From: Marc G. FournierDate: 2003-11-28 20:31:51
Subject: Re: about explain analyze

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group