Re: gettimeofday() system call timing curiosity

From: george anzinger (george@mvista.com)
Date: Fri Mar 08 2002 - 15:40:11 EST


"Richard B. Johnson" wrote:
>
> On Fri, 8 Mar 2002, Jamie Lokier wrote:
>
> > Jamie Lokier wrote:
> > > It takes the median of 1000 samples of the TSC time taken to do a
> > > rdtsc/gettimeofday/rdtsc measurement, then uses that as the threshold
> > > for deciding which of the subsequent 1000000 measurements are accepted.
> > > Then linear regression through the accepted points.
> > >
> > > I see a couple of results there which suggests a probable fault in the
> > > filtering algorithm. Perhaps it should simply use the smallest TSC time
> > > taken as the threshold.
> >
> > I've looked more closely. Of all the machines I have access to, only my
> > laptop shows the anomolous measurements.
> >
> > It turns out that the median of "time in TSC cycles to do a
> > rdtsc+gettimeofday+rdtsc measurement" varies from run to run. It only
> > varies between two values, though.
> >
> [SNIPPED...]
>
> The following program clearly shows that Linux will not return the
> same gettimeofday values twice in succession. Since it provably takes
> less than 1 microsecond to make a system call on a modern machine,
> Linux must be waiting within the gettimeofday procedure long enough
> to make certain that the time has changed. This may be screwing up
> any performance measurments made with gettimeofday().
>
Balderdash!! It is easy to do if you machine is fast enough. On my
800MHZ PIII gettimeofday take about 0.7 micro seconds min. over about
100 calls, NO loop overhead.

-g

> #include <stdio.h>
> #include <sys/time.h>
>
> int main(void);
> int main()
> {
> struct timeval tv, pv;
> tv.tv_sec = tv.tv_usec = pv.tv_sec = pv.tv_usec = 0;
> for(;;)
> {
> (void)gettimeofday(&tv, NULL);
> if((tv.tv_sec != pv.tv_sec) || (tv.tv_usec != pv.tv_usec))
> printf("sec = %ld usec = %ld\n", tv.tv_sec, tv.tv_usec);
> else
> puts("The same!");
> pv = tv;
> }
> return 0;
> }
>
> Cheers,
> Dick Johnson
>
> Penguin : Linux version 2.4.18 on an i686 machine (797.90 BogoMips).
>
> Bill Gates? Who?

-- 
George           george@mvista.com
High-res-timers: http://sourceforge.net/projects/high-res-timers/
Real time sched: http://sourceforge.net/projects/rtsched/
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Fri Mar 15 2002 - 22:00:09 EST