Re: Where is gethrtime()?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 2005-10-24 at 06:29 -0600, Nelson H. F. Beebe wrote:
> Ernesto L. Williams, Jr. <ernesto@xxxxxxxx> asks about the
> availability of high-resolution timers, and whether the gethrtime()
> function is found only on Solaris.  
> 
> Although this question is off-topic on the gcc-help list, it may
> nevertheless be of interest to readers, because it is question that
> many of us have probably raised, and for which Unix vendors and
> programming-language standards bodies have provided little help.
> Today, with GHz clocks on modern processors, the 60 and 100 ticks per
> second of the default CPU timer is completely inadequate for serious
> profiling.
> 
> The profiling version of awk, pawk, that I prepared in 2002 has some
> notes and code on the topic.  This is an interest of mine, and pawk is
> available at:
> 
> 	ftp://ftp.math.utah.edu/pub pawk
> 	http://www.math.utah.edu/pub/pawk
> 
> There are implementations in pawk of high-resolution timers in
> cpuclock.c for GNU/Linux on PowerPC, Sun Solaris, and for the
> DEC/Compaq/HP Alpha architecture.  The files README.PROFILE, mail.txt,
> and TIMER.NOTES record additional information that I collected.
> 
> If others on this list of new information to contribute that would
> extend coverage to other platforms, I'll be happy to make an updated
> version of cpuclock.c, and prepare an improved version of the
> TIMER.NOTES file.

I ask this question on the Fedora mailing list after realizing this was
the wrong place.  However, I did receive the following response from one
of the developers:

======== message from Ulrich Drepper =================================

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


===========================================================================


Thanks,
Ernesto


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux