High-resolution timers for the linux kernel

This patch adds very low-overhead access to high-resolution process virtual time and, optionally, high-resolution virutalized user and system time. The timers are based on the CPU cycle counter and can be read at memory access speeds. Low overhead access to high-resolution process time is critical many profiling and benchmarking applications.

While other systems have offered access to high-resolution process time, they have required access through a system call interface.

This approach uses an extra per-pid entry, /proc/PID/hrtime, that contains timing values; these values can be mmapped into a user's address space. For convenience, a library is also provided that performs the mmaping and timer querying work for you.

These routines work both for a process timing itself and a process timing another process.

This work was done as part of the Paradyn Parallel Performance Tools project.


Processes that call hrtime_init and then fork will not get correct timing results when calling libhrtime functions from the child process. The parent process will continue to get correct results. This will be addressed with version 0.7 of the hrtime patch.

Release 0.6.1

Users of versions 0.6 and earlier are strongly encouraged to upgrade to the latest version of the library and patch. There was a bug in the kernel patch that caused page reference counting errors if a process had mmaped any timing page and then forked. Version 0.6.1 is an interim release that addresses this issue.

Changes since 0.6:

  • Added vm_open handler to kernel patch to fix reference counting bug
  • Updated patches to work with 2.2.18 and 2.4.0


  • libhrtime-0.6.1.tar.gz
  • hrtime-0.6.1-2.2.18.patch
  • hrtime-0.6.1-2.4.0.patch
  • Other patches and RPMS

    Release 0.6

    Changes since 0.5:

  • Added support to compile libhrtime as a shared library
  • Added support for compiling libhrtime into an RPM

    Release 0.5

    Changes since 0.4:
  • Cleanup of the kernel patch
  • Added self-query functions, permitting a small optimization for the common case
  • Tightened up the general querying functions a bit, function timings are now:
    get_hrtime       80 cycles
    get_hrvtime     110 cycles
    get_hrutime     116 cycles
    get_hrstime     103 cycles
    get_hrtime_self  71 cycles
    get_hrvtime_self 88 cycles
    get_hrutime_self 89 cycles
    get_hrstime_self 14 cycles
    These values were measured on a dual PIII 450.

    Release 0.4

    Release 0.4 is the first public release of the high-resolution timer patch and library.


  • get_hrtime.2: Process querying manpage
  • get_hrtime_self.2: Process self-querying manpage
  • get_hrtime_struct.2: Timer mapping manpage

    Both the latest patches and library source can be had via anonymous cvs:

    setenv CVSROOT :ext:anoncvs@cvs.jive.org:/cvs
    setenv CVS_RSH ssh
    cvs co libhrtime
    Official releases can be had at ftp://ftp.cs.wisc.edu/paradyn/timers/libhrtime/.