From: "Jakob Østergaard" <jakob@unthought.net>
To: Chris Friesen <cfriesen@nortelnetworks.com>
Cc: mcuss@cdlsystems.com, linux-kernel@vger.kernel.org
Subject: Re: Measuring execution time
Date: Wed, 16 Jan 2002 22:47:19 +0100 [thread overview]
Message-ID: <20020116224719.M2830@unthought.net> (raw)
In-Reply-To: <Pine.LNX.4.33.0201151409270.1744-100000@barbarella.hawaga.org.uk> <042f01c19e13$6da6f4f0$160e10ac@hades> <3C45B715.926A0BA0@nortelnetworks.com>
In-Reply-To: <3C45B715.926A0BA0@nortelnetworks.com>; from cfriesen@nortelnetworks.com on Wed, Jan 16, 2002 at 12:23:33PM -0500
On Wed, Jan 16, 2002 at 12:23:33PM -0500, Chris Friesen wrote:
> Mark Cuss wrote:
>
> > I am working on optimizing some software and would like to be able to
> > measure how long an instruction takes (down to the clock cycle of the CPU).
> > I recall reading somewhere about a kernel time measurement called a "Jiffy"
> > and figured that it would probably apply to this.
> >
> > If anyone has any tips on how to figure out how to do this I'd really
> > appreciate it.
>
> Jiffies are quite coarse-grained. On x86 you want the rdtsc instruction, while
> on ppc you want mfrtcu/mfrtcl or mftbu/mftb depending on the version of the
> chip. These are used as inline assembly, and if you do a google search you
> should be able to find code snippets.
However, rdtsc will completely change how your decoders fill, how busy your
execution units are, it will interfere with every singe stage in the CPU
from the fetch logic to the retirement and write buffer.
Your cycle will not behave "as usual" if you put rdtscs around it.
I usually put an rdtsc in the very beginning of a routine, and an rdtsc
at the end. Then I have the assembly following the last rdtsc increment
a counter in an array (after a bounds check). The index in the array
is the number of clock cycles I spent.
After running the function some thousands of times, you will have a nice
histogram in your array, usually with some skewed bell-like curve (you can
see many interesting kinds of double/triple bells etc. all depending on
your code).
Changing just one or two instructions in the function, then re-running the
code and re-plotting the histogram, will displace the peak of the bell curve
in some direction. This will tell you how your change affected the code
in "typical number of clock cycles".
--
................................................................
: jakob@unthought.net : And I see the elder races, :
:.........................: putrid forms of man :
: Jakob Østergaard : See him rise and claim the earth, :
: OZ9ABN : his downfall is at hand. :
:.........................:............{Konkhra}...............:
next prev parent reply other threads:[~2002-01-16 22:20 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-01-15 16:01 [ANNOUNCE][PATCH] New fs to control access to system resources Olaf Dietsche
2002-01-15 16:53 ` Richard Gooch
2002-01-15 17:38 ` Wichert Akkerman
2002-01-15 17:54 ` Richard Gooch
2002-01-15 17:48 ` Olaf Dietsche
2002-01-16 19:05 ` Andreas Ferber
2002-01-15 22:13 ` Ben Clifford
2002-01-15 22:24 ` Measuring execution time Mark Cuss
2002-01-16 17:23 ` Chris Friesen
2002-01-16 17:53 ` Richard B. Johnson
2002-01-16 21:47 ` Jakob Østergaard [this message]
2002-01-16 17:18 ` [ANNOUNCE][PATCH] New fs to control access to system resources Olaf Dietsche
2002-01-16 18:26 ` Ben Clifford
2002-01-17 0:34 ` Olaf Dietsche
2002-01-15 22:51 ` CaT
2002-01-15 23:00 ` David Weinehall
2002-01-15 23:13 ` CaT
2002-01-16 4:19 ` dean gaudet
2002-01-16 17:18 ` Olaf Dietsche
2002-01-16 18:12 ` dean gaudet
2002-01-17 0:34 ` Olaf Dietsche
2002-01-16 18:51 ` Andreas Ferber
2002-01-16 13:38 ` gmack
2002-01-16 23:06 ` Greg KH
2002-01-17 9:26 ` Andreas Ferber
2002-01-18 19:38 ` Greg KH
2002-01-18 15:36 ` Anthony DeRobertis
2002-01-18 18:22 ` Olaf Dietsche
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=20020116224719.M2830@unthought.net \
--to=jakob@unthought.net \
--cc=cfriesen@nortelnetworks.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mcuss@cdlsystems.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