mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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>,
	george anzinger <george@mvista.com>
Subject: gettimeofday() system call timing curiosity
Date: Fri, 8 Mar 2002 18:30:49 +0000	[thread overview]
Message-ID: <20020308183049.A18247@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> <20020308013222.B14779@kushida.apsleyroad.org> <3C88157E.5010106@zytor.com> <20020308015701.C14779@kushida.apsleyroad.org>
In-Reply-To: <20020308015701.C14779@kushida.apsleyroad.org>; from lk@tantalophile.demon.co.uk on Fri, Mar 08, 2002 at 01:57:01AM +0000

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.

On my laptop, the median of rdtsc+gettimeofday+rdtsc times is 470 cycles
for most runs of 1000, but is occasionally 453 cycles.

Over runs of approx. 10^6 samples, about 1% of the samples take 453
cycles to executre and about 60% take 470 cycles to execute.  I have no
idea why the smallest is so rare!

This explains the anomalous measurement on my laptop: the quickest
samples of 453 cycles are quite rare (1-2%, not measured accurately),
over runs of 10^6 samples.  Nevertheless, occasionally over a run of
1000 samples, the median comes out as 453.  When that happens, over 10^6
samples only about 1-2% are considered valid, and this is not good
enough to get an accurate calibration method.

On all machines except my laptop, the percentage of samples over large
runs which execute in the minimum number of cycles is somewhat larger
(35-60% - it varies between runs), and that is enough that whether the
median selects the minimum or the next value up, the calibration
estimate is good.  On one PC, the two median measurement times are 461
and 479 cycles.

On the FreeBSD box I noticed a very curious effect.  The median
measurement time comes out as 695 or 712 cycles.  (Btw, showing Linux
has faster gettimeofday calls :-).  The curiousity is that if I
repeatedly run the program, I see something like 30 consecutive results
where the median came out at 695 cycles, then 50 consecutive results at
712 cycles, then another 30 or so at 695 cycles.

That shows there is something stateful going on - I would guess
something connected with the processor caches (but it's just a guess),
and doing 1000 iterations in a loop doesn't cause the timing to settle
down to the minimum time.

So there are: two oddities: why does my laptop have only a small
proportion of rdtsc+gettimeofday+rdtsc calls executing in the minimum
number of clock cycles, and why does FreeBSD show long runs with one
value alternating with long runs of another.

cheers,
-- Jamie

  reply	other threads:[~2002-03-08 18:31 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                     ` Jamie Lokier [this message]
2002-03-08 18:50                       ` gettimeofday() system call timing curiosity 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=20020308183049.A18247@kushida.apsleyroad.org \
    --to=lk@tantalophile.demon.co.uk \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=davidel@xmailserver.org \
    --cc=george@mvista.com \
    --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®