From: Jamie Lokier <lk@tantalophile.demon.co.uk>
To: "H. Peter Anvin" <hpa@zytor.com>
Cc: 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: a faster way to gettimeofday? rdtsc strangeness
Date: Fri, 8 Mar 2002 01:32:23 +0000 [thread overview]
Message-ID: <20020308013222.B14779@kushida.apsleyroad.org> (raw)
In-Reply-To: <E16iz57-0002SW-00@the-village.bc.nu> <1015515815.4373.61.camel@pc-16.office.scali.no> <a68bo4$b18$1@cesium.transmeta.com>
In-Reply-To: <a68bo4$b18$1@cesium.transmeta.com>; from hpa@zytor.com on Thu, Mar 07, 2002 at 10:32:36AM -0800
H. Peter Anvin wrote:
> > Can /proc/cpuinfo really be trusted in figuring out how long a cycle is?
>
> It uses RDTSC, so yes.
Yes and no. The kernel's measurement isn't as accurate as it could be.
I have some code which calibrates TSC cycles against gettimeofday().
Considering that gettimeofday() works by using the kernel's frequency
estimate that it shows in /proc/cpuinfo, the results from the code
should match /proc/cpuinfo very precisely ndeed.
However, over a million gettimeofday() calls, the frequency of the 100Hz
tick would tend to dominate the result, showing any error in the
kernel's estimate which appears in /proc/cpuinfo (which is derived from
measuring the length of a 100Hz tick in TSC cycles).
With 10^6 gettimeofday() calls, and linear regression through the set of
measurements when an interrupt didn't happen (checked by reading TSC
before and after the system call and filtering on the minimum), I get
superb results on a FreeBSD box:
Kernel reports clock frequency: 746.154 MHz
Measured clock frequency: 746.154 MHz
On various Linux boxes, however:
Kernel reports clock frequency: 596.924 MHz
Measured clock frequency: 596.929 MHz
Kernel reports clock frequency: 866.708 MHz
Measured clock frequency: 866.675 MHz
Kernel reports clock frequency: 664.597 MHz
Measured clock frequency: 664.582 MHz
Kernel reports clock frequency: 366.601 MHz
Measured clock frequency: 366.584 MHz
As you can see, the kernel consistently overestimates the CPU clock
frequency, or more precisely it overestimates the number of cycles in a
"100Hz" system clock tick. This is something that could be improved in
the kernel code, as FreeBSD demonstrates. Note that the clock frequency
probably varies by a similar order of magnitude to this error due to
thermal and power variation anyway. But it would be nice if the
measurements matched as they do in FreeBSD!
I have one of those laptops that Alan mentioned which does change the
CPU clock rate. It's a Toshiba 4070CDT, here running in fast then slow
mode:
Kernel reports clock frequency: 366.601 MHz
Measured clock frequency: 366.584 MHz
Kernel reports clock frequency: 366.601 MHz
Measured clock frequency: 184.503 MHz
It can switch between fast and slow modes while a program is running,
which occurs either when you press a special key combination, or the
mains power cuts off.
enjoy,
-- Jamie
next prev parent reply other threads:[~2002-03-08 1:33 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 [this message]
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=20020308013222.B14779@kushida.apsleyroad.org \
--to=lk@tantalophile.demon.co.uk \
--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=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
all inboxes | Powered by JetHome®