* Weird time() effect in linux/AXP
@ 1999-07-31 4:00 bmeyer
1999-08-04 4:00 ` Barking Dog
1999-08-04 4:00 ` Robert Harley
0 siblings, 2 replies; 3+ messages in thread
From: bmeyer @ 1999-07-31 4:00 UTC (permalink / raw)
While playing around with some portable high-precision timing code,
I have run into a rather weird effect in which the result of time(NULL)
actually _decreases_ momentarily. That means that a call to time() may
give a result of x, and a _subsequent_ call might give a result of x-1.
Needless to say, that wreaks havoc on my code, and probably is not too
good for any other time-related code, either.
The same problem occurs with the gettimeofday function, which gives more
information...
Here is a little C program to test it:
=========
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
#include <unistd.h>
int main(int argc, char** argv)
{
struct timeval tv1,tv2;
gettimeofday(&tv1,NULL);
while (1) {
gettimeofday(&tv2,NULL);
if (tv1.tv_sec!=tv2.tv_sec) {
printf("%d %d.%06d<->%d.%06d\n",
tv2.tv_sec-tv1.tv_sec,
tv1.tv_sec,tv1.tv_usec,
tv2.tv_sec,tv2.tv_usec);
}
tv1=tv2;
}
}
=========
When run on my Alphas (Kernel 2.2.0pre7ac4, libc-2.0.7, one machine a
433MHz 21164, the other a 533MHz 21164PC), the output will mostly consist
of lines starting with "1", as one should expect (and does indeed get
on linux.x86 all the time).
But every now and again, sometimes as often as twice a minute, sometimes
only every ten minutes or so, a line starts with "-1", indicating that time
just went backwards.
Here is an example:
=======
1 933410708.999994<->933410709.000004
1 933410709.998043<->933410710.002138
-1 933410710.002138<->933410709.998180
1 933410709.999995<->933410710.000005
1 933410710.999994<->933410711.000005
=======
The actual "wrong" answer from gettimeofday is in the second line starting with
"1".
This shows an interesting aspects of the problem: The gettimeofday function
simply "jumps the gun" by about 4 milliseconds, for no apparent reason.
Any ideas?
Bernie
--
Older man declare war. But it is youth who must fight and die
Herbert Hoover
US President 1929-33
At the Republican National Convention, 27 June 1944
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: Weird time() effect in linux/AXP
1999-07-31 4:00 Weird time() effect in linux/AXP bmeyer
@ 1999-08-04 4:00 ` Barking Dog
1999-08-04 4:00 ` Robert Harley
1 sibling, 0 replies; 3+ messages in thread
From: Barking Dog @ 1999-08-04 4:00 UTC (permalink / raw)
In article <7nuiau$cg$1@wombat.cs.monash.edu.au>,
bmeyer@bruce.cs.monash.edu.au wrote:
> While playing around with some portable high-precision timing code,
> I have run into a rather weird effect in which the result of time
(NULL)
> actually _decreases_ momentarily. That means that a call to time() may
> give a result of x, and a _subsequent_ call might give a result of x-
1.
> Needless to say, that wreaks havoc on my code, and probably is not too
> good for any other time-related code, either.
You wouldn't happen to br running [x]ntpd, would you?
Just checking
-Barking Dog
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Weird time() effect in linux/AXP
1999-07-31 4:00 Weird time() effect in linux/AXP bmeyer
1999-08-04 4:00 ` Barking Dog
@ 1999-08-04 4:00 ` Robert Harley
1 sibling, 0 replies; 3+ messages in thread
From: Robert Harley @ 1999-08-04 4:00 UTC (permalink / raw)
bmeyer@bruce.cs.monash.edu.au writes:
> While playing around with some portable high-precision timing code,
> I have run into a rather weird effect in which the result of time(NULL)
> actually _decreases_ momentarily. [...]
> But every now and again, sometimes as often as twice a minute, sometimes
> only every ten minutes or so, a line starts with "-1", indicating that time
> just went backwards.
I ran your program for about 20 hours on my 500 MHz Miata with no "-1" lines.
!?!?
Rob.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1999-08-04 4:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1999-07-31 4:00 Weird time() effect in linux/AXP bmeyer
1999-08-04 4:00 ` Barking Dog
1999-08-04 4:00 ` Robert Harley
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox