linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* RE: timing an application
@ 2003-01-14 20:37 Howell, David P
  2003-01-14 21:34 ` David Mosberger
  0 siblings, 1 reply; 7+ messages in thread
From: Howell, David P @ 2003-01-14 20:37 UTC (permalink / raw)
  To: Maciej Soltysiak, linux-kernel

If this is on a IA32(Pentium II or later)/IA64 have you considered using
the processor TSC register to get interval timestamps? It's a lot
lighter weight and should give better resolution. When we have done this
we compared the tick values directly.

To convert TSC ticks to time the /proc/cpuinfo value for 'cpu MHz', see
the glibc get_clockfreq.c and hp_timing.h implementation for details.

Dave Howell

-----Original Message-----
From: Maciej Soltysiak [mailto:solt@dns.toxicfilms.tv] 
Sent: Tuesday, January 14, 2003 2:58 PM
To: linux-kernel@vger.kernel.org
Subject: timing an application

Hi,

being inspired by some book about optimizing c++ code i decided to do
timing of functions i wrote. I am using gettimeofday to set
two timeval structs and calculate the time between them.
But the results depend heavily on the load, also i reckon that this
is an innacurate timing.

Any ideas on timing a function, or a block of code? Maybe some kernel
timers or something.

Regards,
Maciej Soltysiak

-----BEGIN GEEK CODE BLOCK-----
VERSION: 3.1
GIT/MU d-- s:- a-- C++ UL++++$ P L++++ E- W- N- K- w--- O! M- V- PS+
PE++
Y+ PGP- t+ 5-- X+ R tv- b DI+ D---- G e++>+++ h! y?
-----END GEEK CODE BLOCK-----
-
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/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: timing an application
  2003-01-14 20:37 timing an application Howell, David P
@ 2003-01-14 21:34 ` David Mosberger
  0 siblings, 0 replies; 7+ messages in thread
From: David Mosberger @ 2003-01-14 21:34 UTC (permalink / raw)
  To: Howell, David P; +Cc: Maciej Soltysiak, linux-kernel

>>>>> On Tue, 14 Jan 2003 12:37:05 -0800, "Howell, David P" <david.p.howell@intel.com> said:

  Dave> If this is on a IA32(Pentium II or later)/IA64 have you
  Dave> considered using the processor TSC register to get interval
  Dave> timestamps? It's a lot lighter weight and should give better
  Dave> resolution. When we have done this we compared the tick values
  Dave> directly.

  Dave> To convert TSC ticks to time the /proc/cpuinfo value for 'cpu
  Dave> MHz', see the glibc get_clockfreq.c and hp_timing.h
  Dave> implementation for details.

Note that it's tricky to uses TSC/ITC on multiprocessors, especially
on large machines, on which the clocks for different CPUs may drift, etc.
It's much better to use the clock_gettime() routine:

  http://www.opengroup.org/onlinepubs/007908799/xsh/clock_getres.html

Where properly implemented, this will be both as fast and accurate.

	--david

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: timing an application
  2003-01-14 19:58 Maciej Soltysiak
  2003-01-14 20:07 ` Chris Friesen
  2003-01-14 20:20 ` Richard B. Johnson
@ 2003-01-14 22:09 ` Olaf Dietsche
  2 siblings, 0 replies; 7+ messages in thread
From: Olaf Dietsche @ 2003-01-14 22:09 UTC (permalink / raw)
  To: Maciej Soltysiak; +Cc: linux-kernel

Maciej Soltysiak <solt@dns.toxicfilms.tv> writes:

> being inspired by some book about optimizing c++ code i decided to do
> timing of functions i wrote. I am using gettimeofday to set
> two timeval structs and calculate the time between them.
> But the results depend heavily on the load, also i reckon that this
> is an innacurate timing.

You will get elapsed time, which is usually not the same as used cpu
time.

> Any ideas on timing a function, or a block of code? Maybe some kernel
> timers or something.

If you're timing/pofiling some user space functions, gprof should be
sufficient. If you want to profile kernel and module functions as
well, try oprofile at <http://oprofile.sourceforge.net/>. It is part
of the kernel since 2.5.43.

Regards, Olaf.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: timing an application
  2003-01-14 20:07 ` Chris Friesen
@ 2003-01-14 20:38   ` Corey Minyard
  0 siblings, 0 replies; 7+ messages in thread
From: Corey Minyard @ 2003-01-14 20:38 UTC (permalink / raw)
  To: Chris Friesen; +Cc: Maciej Soltysiak, linux-kernel

I have a patch at http://home.attbi.com/~minyard/highres-2.4.17.patch that
adds a config item that times CPU usage at microsecond resolution.  It's 
only
for the 2.4.17 kernel, I don't know what the porting effort would be for 
other
kernels.

It's not a great patch, it would need some work to be really clean from 
a code
quality point of view, but it does seem to work.  With it you can use 
getrusage()
to get the actual time your process has used between two points.  It 
works on
x86 and PPC.

Plus, obviously, this adds significant time to system calls and interrupts.

-Corey

Chris Friesen wrote:

> Maciej Soltysiak wrote:
>
>> Hi,
>>
>> being inspired by some book about optimizing c++ code i decided to do
>> timing of functions i wrote. I am using gettimeofday to set
>> two timeval structs and calculate the time between them.
>> But the results depend heavily on the load, also i reckon that this
>> is an innacurate timing.
>>
>> Any ideas on timing a function, or a block of code? Maybe some kernel
>> timers or something.
>
>
> gettimeofday() is accurate.  However, your task may be interrupted by
> other tasks, interrupts, etc.
>
> Your best bet may be to do many iterations of the routine in question 
> and then
> do some statistical analysis of the results.
>
> Chris
>
>
>



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: timing an application
  2003-01-14 19:58 Maciej Soltysiak
  2003-01-14 20:07 ` Chris Friesen
@ 2003-01-14 20:20 ` Richard B. Johnson
  2003-01-14 22:09 ` Olaf Dietsche
  2 siblings, 0 replies; 7+ messages in thread
From: Richard B. Johnson @ 2003-01-14 20:20 UTC (permalink / raw)
  To: Maciej Soltysiak; +Cc: linux-kernel

[-- Attachment #1: Type: TEXT/PLAIN, Size: 978 bytes --]

On Tue, 14 Jan 2003, Maciej Soltysiak wrote:

> Hi,
> 
> being inspired by some book about optimizing c++ code i decided to do
> timing of functions i wrote. I am using gettimeofday to set
> two timeval structs and calculate the time between them.
> But the results depend heavily on the load, also i reckon that this
> is an innacurate timing.
> 
> Any ideas on timing a function, or a block of code? Maybe some kernel
> timers or something.
> 
> Regards,
> Maciej Soltysiak
> 

Easy!  Use the rdtsc instruction to obtain the number of CPU cycles
that occur between two subsequent calls. There will be some 'noise'
because of interrupt activity so make many tests, put the results
into an array, remove the slowest and the fastest, then average
the remaining data. That's good enough for "government projects".

Cheers,
Dick Johnson
Penguin : Linux version 2.4.18 on an i686 machine (797.90 BogoMips).
Why is the government concerned about the lunatic fringe? Think about it.


[-- Attachment #2: Type: APPLICATION/octet-stream, Size: 7787 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: timing an application
  2003-01-14 19:58 Maciej Soltysiak
@ 2003-01-14 20:07 ` Chris Friesen
  2003-01-14 20:38   ` Corey Minyard
  2003-01-14 20:20 ` Richard B. Johnson
  2003-01-14 22:09 ` Olaf Dietsche
  2 siblings, 1 reply; 7+ messages in thread
From: Chris Friesen @ 2003-01-14 20:07 UTC (permalink / raw)
  To: Maciej Soltysiak; +Cc: linux-kernel

Maciej Soltysiak wrote:
> Hi,
> 
> being inspired by some book about optimizing c++ code i decided to do
> timing of functions i wrote. I am using gettimeofday to set
> two timeval structs and calculate the time between them.
> But the results depend heavily on the load, also i reckon that this
> is an innacurate timing.
> 
> Any ideas on timing a function, or a block of code? Maybe some kernel
> timers or something.

gettimeofday() is accurate.  However, your task may be interrupted by
other tasks, interrupts, etc.

Your best bet may be to do many iterations of the routine in question and then
do some statistical analysis of the results.

Chris



-- 
Chris Friesen                    | MailStop: 043/33/F10
Nortel Networks                  | work: (613) 765-0557
3500 Carling Avenue              | fax:  (613) 765-2986
Nepean, ON K2H 8E9 Canada        | email: cfriesen@nortelnetworks.com


^ permalink raw reply	[flat|nested] 7+ messages in thread

* timing an application
@ 2003-01-14 19:58 Maciej Soltysiak
  2003-01-14 20:07 ` Chris Friesen
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Maciej Soltysiak @ 2003-01-14 19:58 UTC (permalink / raw)
  To: linux-kernel

Hi,

being inspired by some book about optimizing c++ code i decided to do
timing of functions i wrote. I am using gettimeofday to set
two timeval structs and calculate the time between them.
But the results depend heavily on the load, also i reckon that this
is an innacurate timing.

Any ideas on timing a function, or a block of code? Maybe some kernel
timers or something.

Regards,
Maciej Soltysiak

-----BEGIN GEEK CODE BLOCK-----
VERSION: 3.1
GIT/MU d-- s:- a-- C++ UL++++$ P L++++ E- W- N- K- w--- O! M- V- PS+ PE++
Y+ PGP- t+ 5-- X+ R tv- b DI+ D---- G e++>+++ h! y?
-----END GEEK CODE BLOCK-----

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2003-01-14 22:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-14 20:37 timing an application Howell, David P
2003-01-14 21:34 ` David Mosberger
  -- strict thread matches above, loose matches on Subject: below --
2003-01-14 19:58 Maciej Soltysiak
2003-01-14 20:07 ` Chris Friesen
2003-01-14 20:38   ` Corey Minyard
2003-01-14 20:20 ` Richard B. Johnson
2003-01-14 22:09 ` Olaf Dietsche

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).