public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* strange nonmonotonic behavior of gettimeoftheday
@ 2001-03-02  5:30 John Being
  2001-03-02 15:07 ` Eli Carter
  2001-03-02 15:08 ` strange nonmonotonic behavior of gettimeoftheday -- seen similar problem on PPC Christopher Friesen
  0 siblings, 2 replies; 11+ messages in thread
From: John Being @ 2001-03-02  5:30 UTC (permalink / raw)
  To: linux-kernel; +Cc: olonho

I've got following problem with 2.2.17 (Redhat stock kernel)
Linux ***** 2.2.17-14 #1 Mon Feb 5 14:57:25 EST 2001 i586 unknown
on AMD K6,  VIA Technologies VT 82C586, Compaq Presario XL119.
Following C program
#include <stdio.h>
#include <sys/time.h>
#include <unistd.h>
#include <time.h>
#define ABS(x) (x < 0 ? -x : x)
#define TIME_T struct timeval
#define TIME_DIFF_T long
#define GET_TIME(x) gettimeofday(&x, NULL)
#define TIME_DIFF(x1, x2) ((x2.tv_sec - x1.tv_sec)*1000000 + (x2.tv_usec - 
x1.tv_usec))
int main(int argc, char** argv)
{
   TIME_T t1, t2;
   TIME_DIFF_T d;

   GET_TIME(t2);
   while (1) {
     GET_TIME(t1);
     d = TIME_DIFF(t2, t1);
     if (d > 500000 || d < 0) {
             fprintf(stderr, "Leap found: %ld msec\n", d);
             return 0;
     }
     t2 = t1;
   }
return 1;

gives following result on box in question
root@******:# ./clo
Leap found: -1687 msec
and prints nothing on all other  my boxes.
This gives me bunch of troubles with occasional hang ups and I found nothing 
in kernel archives at 
http://www.uwsg.indiana.edu/hypermail/linux/kernel/index.html
just some notes about smth like this for SMP boxes with ntp. Is this issue 
known, and how can I fix it?

  Thanks.


_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.


^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: strange nonmonotonic behavior of gettimeoftheday -- seen similar problem on PPC
@ 2001-03-03  4:22 Doug Siebert
  2001-03-03 13:18 ` Alan Cox
  0 siblings, 1 reply; 11+ messages in thread
From: Doug Siebert @ 2001-03-03  4:22 UTC (permalink / raw)
  To: linux-kernel

"Richard B. Johnson" wrote:
>
>I think it's a math problem in the test code. Try this:
>
[code deleted]
>
>Note that two subsequent calls to gettimeofday() must not return the 
>same time even if your CPU runs infinitely fast. I haven't seen any 
>kernel in the past few years that fails this test.


I find that claim to be pretty ridiculous, I have never seen such a
thing in any standard.  I was writing code allowing the for '='
condition five years ago, because I was assuming that it might live
long enough for this sort of thing to start happening.  Simple defensive
programming (probably smart even if POSIX was to declare this to be
the case)

So then I was I was curious if I could find any systems fast enough to
violate this.  I didn't have to look far, my new laptop with a 600MHz
Pentium III (running kernel 2.2.16, not that it matters) hits the "break"
in your program (i.e., same time from the two gettimeofday() calls) every
single time I run it.  If I add another identical call to gettimeofday()
immediately after the second one, that makes the result of the (now)
third call 1us greater so the code loops as you intended.

What you claim may have been true due to the inability of CPUs to execute
two system calls within a microsecond, but that horse has now left the
barn.  You will need to request a getnanotimeofday() be created if you
want to allow two consecutive calls to always return different values
(modulo SMP systems and ~13 more years of Moore's Law)

-- 
Douglas Siebert
douglas-siebert@uiowa.edu

A computer without Microsoft software is like chocolate cake without ketchup.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2001-03-03 22:40 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-03-02  5:30 strange nonmonotonic behavior of gettimeoftheday John Being
2001-03-02 15:07 ` Eli Carter
2001-03-02 15:08 ` strange nonmonotonic behavior of gettimeoftheday -- seen similar problem on PPC Christopher Friesen
2001-03-02 15:40   ` Richard B. Johnson
2001-03-02 18:25     ` george anzinger
2001-03-02 19:14       ` Richard B. Johnson
2001-03-02 20:09         ` george anzinger
2001-03-03  7:42         ` Mike Galbraith
2001-03-03 22:40     ` dean gaudet
  -- strict thread matches above, loose matches on Subject: below --
2001-03-03  4:22 Doug Siebert
2001-03-03 13:18 ` Alan Cox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox