public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: george anzinger <george@mvista.com>
To: root@chaos.analogic.com
Cc: Jamie Lokier <lk@tantalophile.demon.co.uk>,
	"H. Peter Anvin" <hpa@zytor.com>,
	linux-kernel@vger.kernel.org, Alan Cox <alan@lxorguk.ukuu.org.uk>,
	Terje Eggestad <terje.eggestad@scali.com>,
	Ben Greear <greearb@candelatech.com>,
	Davide Libenzi <davidel@xmailserver.org>
Subject: Re: gettimeofday() system call timing curiosity
Date: Fri, 08 Mar 2002 12:40:11 -0800	[thread overview]
Message-ID: <3C8921AB.6DC37849@mvista.com> (raw)
In-Reply-To: <Pine.LNX.3.95.1020308134552.6627A-100000@chaos.analogic.com>

"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/

  parent reply	other threads:[~2002-03-08 20:41 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-06  3:41 a faster way to gettimeofday? Ben Greear
2002-03-06  3:58 ` Davide Libenzi
2002-03-06  4:20   ` Ben Greear
2002-03-06  4:31     ` Davide Libenzi
2002-03-06  4:34       ` Davide Libenzi
2002-03-07 14:14       ` a faster way to gettimeofday? rdtsc strangeness Terje Eggestad
2002-03-07 14:41         ` Alan Cox
2002-03-07 15:43           ` Terje Eggestad
2002-03-07 16:17             ` Alan Cox
2002-03-07 18:32             ` H. Peter Anvin
2002-03-08  1:32               ` Jamie Lokier
2002-03-08  1:35                 ` H. Peter Anvin
2002-03-08  1:57                   ` Jamie Lokier
2002-03-08 18:30                     ` gettimeofday() system call timing curiosity Jamie Lokier
2002-03-08 18:50                       ` H. Peter Anvin
2002-03-08 20:16                         ` Jamie Lokier
2002-03-08 20:30                           ` Davide Libenzi
2002-03-08 18:54                       ` Richard B. Johnson
2002-03-08 19:06                         ` johan.adolfsson
2002-03-08 19:16                           ` H. Peter Anvin
2002-03-08 19:45                           ` Richard B. Johnson
2002-03-08 20:29                             ` johan.adolfsson
2002-03-08 20:43                             ` Alan Cox
2002-03-09  3:03                               ` pjd
2002-03-09 18:51                                 ` Alan Cox
2002-03-09  3:15                             ` Kelsey Hudson
2002-03-08 19:19                         ` Alan Cox
2002-03-08 20:40                         ` george anzinger [this message]
2002-03-06 20:45     ` a faster way to gettimeofday? dean gaudet
2002-03-06 21:31       ` Chris Ball
2002-03-06 22:25         ` george anzinger
2002-03-07  0:04         ` vsyscalls Mark Mielke
2002-03-06 16:16 ` a faster way to gettimeofday? Chris Friesen
2002-03-06 16:54   ` Richard B. Johnson
2002-03-11 22:47 ` OBATA Noboru
2002-03-12 13:06   ` Jamie Lokier
2002-03-12 15:12     ` OBATA Noboru

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3C8921AB.6DC37849@mvista.com \
    --to=george@mvista.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=davidel@xmailserver.org \
    --cc=greearb@candelatech.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lk@tantalophile.demon.co.uk \
    --cc=root@chaos.analogic.com \
    --cc=terje.eggestad@scali.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox