Re: gettimeofday() goes backwards on FreeBSD 4.9

From: Darcy Buskermolen <darcy(at)wavefire(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Marc G(dot) Fournier" <scrappy(at)postgresql(dot)org>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: gettimeofday() goes backwards on FreeBSD 4.9
Date: 2003-11-28 23:53:15
Message-ID: 200311281553.15808.darcy@wavefire.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On November 28, 2003 12:33 pm, Tom Lane wrote:
> 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
>

I've been running this code on a pair of FreeBSD (i386) boxen, for some time
now, one of which is a 4.8-STABLE, the other is a 5.2-BETA.

In 10 minutes of execution the 4.8 box has only shown the following:

out of order tv_sec: 1070063393 115226, prev 1070063391 381087
out of order tv_usec: 1070063393 115226, prev 1070063391 381087

the 5.2 box, hasn't outputed anything. I'm goignt o run this test on some
other boxen I have and see what/ifany results are happening.

>
> 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;
> }
>
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend

--
Darcy Buskermolen
Wavefire Technologies Corp.
ph: 250.717.0200
fx: 250.763.1759
http://www.wavefire.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2003-11-29 00:14:33 Re: gettimeofday() goes backwards on FreeBSD 4.9
Previous Message Tom Lane 2003-11-28 22:38:10 Re: Date bug in PG