2004-03-31 21:11:54

by Chuck Lever

[permalink] [raw]
Subject: timer question

hi all-

i'm looking for a way to do microsecond resolution timing in the RPC
client. i need a timer or timestamp function that is fairly cheap, that i
can call on any hardware platform, and that i can invoke from inside a
bottom half.

any suggestions?

- Chuck Lever
--
corporate: <cel at netapp dot com>
personal: <chucklever at bigfoot dot com>


2004-03-31 21:33:38

by Richard B. Johnson

[permalink] [raw]
Subject: Re: timer question

On Wed, 31 Mar 2004, Chuck Lever wrote:

> hi all-
>
> i'm looking for a way to do microsecond resolution timing in the RPC
> client. i need a timer or timestamp function that is fairly cheap, that i
> can call on any hardware platform, and that i can invoke from inside a
> bottom half.
>
> any suggestions?
>
> - Chuck Lever

If you find one, we'd all like to use it! The Intel machines,
after the i486, have the rdtsc instruction which will return
the number of CPU clocks that have occurred since the chip was
turned ON. It can be calibrated upon startup so you know how
many clocks occur in a second.


Cheers,
Dick Johnson
Penguin : Linux version 2.4.24 on an i686 machine (797.90 BogoMips).
Note 96.31% of all statistics are fiction.


2004-04-01 06:10:29

by Chris Friesen

[permalink] [raw]
Subject: Re: timer question

Richard B. Johnson wrote:
> On Wed, 31 Mar 2004, Chuck Lever wrote:
>
>
>>hi all-
>>
>>i'm looking for a way to do microsecond resolution timing in the RPC
>>client. i need a timer or timestamp function that is fairly cheap, that i
>>can call on any hardware platform, and that i can invoke from inside a
>>bottom half.
>>
>>any suggestions?

As Dick Johnson said, x86 has rdtsc. PowerPC has the mftbr, which is
equivalent. MIPS has something similar.

Many architectures have something, but currently it has to be coded for
each.

One thing that might be nice would be a common API to get a high-res
timestamp, something like a 64-bit nano_uptime, which would be good for
uptimes of up to 524 years at nanosecond precision. Or else you could
just use timespec, although its not as nice on actual 64-bit machines.

Chris