High Resolution timers support in Fedora?

Ulrich Drepper drepper at redhat.com
Sun Oct 23 15:53:50 UTC 2005


Ernest L. Williams Jr. wrote:
> I would like to play with high resolution timers under linux and GCC.
> 
> Where is the function "gethrtime()" ?  

gethrtime on Solaris is using the cycle counters.  This is an unreliable
clock, at least on x86/x86-64 since the clock speed can vary and, more
importantly, the cycle counter value could vary between different
processors on the system.  Although the latter works correctly on most
small SMP machines it is not guaranteed.

Having said that, the C library provides the POSIX interfaces
clock_gettime and friends.  Before the kernel support was added to
support them, the clock_gettime interface for the CPU clocks was using
the rdtsc instruction on x86 and x86-64.  So the interfaces were really
equivalent to the gethrtime interface on Solaris.  With kernel support
available now these calls are syscalls but they still provide a high
resolution (still based on rdtsc data, but more reliable).  The big
difference is that now the CPU clock really only counts the time the
thread/process uses the CPU.  If you just need an incremental time, then
use CLOCK_REALTIME instead.  Its exported resolution isn't quite as high
but it runs continuously.

-- 
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 251 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/fedora-test-list/attachments/20051023/c8ee4d48/attachment.sig>


More information about the fedora-test-list mailing list