mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Terje Eggestad <terje.eggestad@scali.com>
To: Davide Libenzi <davidel@xmailserver.org>
Cc: Ben Greear <greearb@candelatech.com>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: a faster way to gettimeofday? rdtsc strangeness
Date: 07 Mar 2002 15:14:56 +0100	[thread overview]
Message-ID: <1015510496.4373.58.camel@pc-16.office.scali.no> (raw)
In-Reply-To: <Pine.LNX.4.44.0203052024540.1475-100000@blue1.dev.mcafeelabs.com>
In-Reply-To: <Pine.LNX.4.44.0203052024540.1475-100000@blue1.dev.mcafeelabs.com>

One word of caution.

If you have a CPU that begin throttling it usually cut the CPU clock in
half and the rdtsc counter count half a fast.

You *should* actually call gettimeofday every few seconds (> 10) to
correct offset.

If you have a SMP system with impropper cooling you actually get into
trouble since you may have one CPU throttling alot and the other don't.
Then the rdtsc of the two CPU's may be quite different.
Have actually seen machines where sleep 1 took 1.2-1.4 secs!

TJ

On Wed, 2002-03-06 at 05:31, Davide Libenzi wrote:
> On Tue, 5 Mar 2002, Ben Greear wrote:
> 
> >
> >
> > Davide Libenzi wrote:
> >
> > > On Tue, 5 Mar 2002, Ben Greear wrote:
> > >
> > >
> > >>I have a program that I very often need to calculate the current
> > >>time, with milisecond accuracy.  I've been using gettimeofday(),
> > >>but gprof shows it's taking a significant (10% or so) amount of
> > >>time.  Is there a faster (and perhaps less portable?) way to get
> > >>the time information on x86?  My program runs as root, so should
> > >>have any permissions it needs to use some backdoor hack if that
> > >>helps!
> > >>
> > >
> > > If you're on x86 you can use collect rdtsc samples and convert them to ms.
> > > You'll get even more then ms accuracy.
> >
> >
> > Can I do this from user space?  If so, any examples or docs
> > you can point me to?
> >
> > Also, I'm looking primarily for a speed increase, not an accuracy
> > increase.
> 
> 
>     #include <linux/timex.h>
> 
> 
>     unsigned long long mscurr;
>     cycles_t cys, cye, mscycles;
>     struct timespec ts1, ts2;
> 
>     clock_gettime(CLOCK_REALTIME, &ts1);
>     cys = get_cycles();
>     sleep(1);
>     clock_gettime(CLOCK_REALTIME, &ts2);
>     cye = get_cycles();
>     mscycles = (cye - cys) / ((ts2.tv_sec - ts1.tv_sec) * 1000 +
> 		(ts2.tv_nsec - ts1.tv_nsec) / 1000000);
> 
> 
> 
>     mscurr = ts2.tv_sec * 1000 + ts2.tv_nsec * 1000000 + (get_cycles() - cye) / mscycles;
> 
> 
> 
> 
> 
> - Davide
> 
> 
> -
> 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/
-- 
_________________________________________________________________________

Terje Eggestad                  mailto:terje.eggestad@scali.no
Scali Scalable Linux Systems    http://www.scali.com

Olaf Helsets Vei 6              tel:    +47 22 62 89 61 (OFFICE)
P.O.Box 150, Oppsal                     +47 975 31 574  (MOBILE)
N-0619 Oslo                     fax:    +47 22 62 89 51
NORWAY            
_________________________________________________________________________


  parent reply	other threads:[~2002-03-07 14:15 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       ` Terje Eggestad [this message]
2002-03-07 14:41         ` a faster way to gettimeofday? rdtsc strangeness 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
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=1015510496.4373.58.camel@pc-16.office.scali.no \
    --to=terje.eggestad@scali.com \
    --cc=davidel@xmailserver.org \
    --cc=greearb@candelatech.com \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®