From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111c93,8e7d44dfbd29e767,start X-Google-Attributes: gid111c93,public From: bmeyer@bruce.cs.monash.edu.au Subject: Weird time() effect in linux/AXP Date: 1999/07/31 Message-ID: <7nuiau$cg$1@wombat.cs.monash.edu.au>#1/1 X-Deja-AN: 507344745 Organization: This is innd taking over... NNTP-Posting-Date: Sun, 01 Aug 1999 02:18:41 EST Reply-To: bmeyer@bruce.cs.monash.edu.au Newsgroups: comp.os.linux.alpha 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 #include #include #include 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