lkml.org 
[lkml]   [1999]   [May]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
Subjectgettimeofday non-monotonic on 2.2.7 SMP
I know multiple processors are relatively rare, but hasn't *somebody*
else noticed the ill effects of gettimeofday returning earlier times?
On my 2xPIII-450 system, the following program does about 900K
gettimeofday's per second when otherwise idle, and 5-10 of them are
mis-ordered (usually by less than 10us, but if I start doing something
that causes a lot of complex interrupts, I see multiple-millisecond
clock hiccoughs). I've been tweeking arch/i386/kernel/time.c, but
haven't fixed it yet. Has anybody else tried?

d.

#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <iostream.h>
#include <stdio.h>

int
main( int, char ** )
{
time_t tick;
struct timeval tv[2];
bool prev = false;
int fwd = 0;
int back = 0;
int max = 0;
for ( ; ; ) {
gettimeofday( tv, 0 );
if (prev)
if (tv[0].tv_sec < tv[1].tv_sec ||
tv[0].tv_sec == tv[1].tv_sec && tv[0].tv_usec < tv[1].tv_usec){
unsigned long delta = ((tv[1].tv_sec - tv[0].tv_sec) * 1000000+
(tv[1].tv_usec - tv[0].tv_usec));
if (delta > max) max = delta;
++back;
} else
++fwd;
if (tick != tv[0].tv_sec && tv[0].tv_sec == tv[1].tv_sec + 1) {
tick = tv[0].tv_sec;
printf( "%.24s: fwd:%d/%d:back max %07lu\n",
ctime( &tv[0].tv_sec ), fwd, back, max );
fwd = back = 0;
max = 0;
}
prev = true;
tv[1] = tv[0];
}
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:51    [from the cache]
©2003-2011 Jasper Spaans