Table Of Contents:
Contents
Description
The objective of the HRT project is to implement the POSIX 1003.1b Section 14 (Clocks and Timers) API in Linux. This includes support for high resolution timers - that is, timers with accuracy better than 1 jiffy.
When the project started, the POSIX clocks and timers APIs were not supported by Linux. Over time, the clocks and timers APIs have been adopted, with the only outstanding part being support for high resolution timers within these APIs.
Rationale
Currently, timers in Linux are only supported at a resolution of 1 jiffy. The length of a jiffy is dependent on the value of HZ in the Linux kernel, and is 1 millisecond on i386 and some other platforms, and 10 milliseconds on most embedded platforms.
Higher resolution timers are needed to allow the system to wake up and process data at more accurate intervals.
Resources
Projects
hrtimers - Thomas Gleixner's patch
One project to support high resolution timers is Thomas Gleixner's hrtimers.
Thomas gave a presentation at the Ottawa Linux Symposium, July 2006, presenting the current status of hrtimers. The presentation is here: http://www.tglx.de/projects/hrtimers/ols2006-hrtimers.pdf
As of July 2006, "generic clock sources" was accepted into Linus' mainline kernel tree (2.6.18-rc??). This means it should be appear in the mainline 2.6.18 kernel version, when that is available. hrtimers should soon follow, likely appearing in 2.6.19.
In February of 2006, James Perkins of WindRiver wrote:
- ktimers has been obsoleted by hrtimers, and the core of hrtimers was merged and is present in Linus' 2.6.16-rc2. hrtimers is used as the base for itimers, nanosleep, and posix-timers. hrtimers are well-described by
Jonathan Corbet at http://lwn.net/Articles/167897/ Since only the core of hrtimers is in 2.6.16-rc2, the hrtimers generally use the system timer as their tick source and run at HZ. John Stultz' generalized time source code has not yet been merged. Thomas Gleixner is maintaining his git tree and has graciously published patches at
http://www.tglx.de/projects/hrtimers/ that include generalized clocksource, new timeofday patches, and get you the real "high resolution" timers for a subset of architectures. High-res timers work is experimental and shifting and has been focusing on getting x86 working first, if this is adequate for you and you can use 2.6.16 kernels it's recommended, and let us all know of any problems or improvements. In contrast, the previous implementation that George Anzinger lead provides a fairly comprehensive set of functionality, back in the 2.6.8-2.6.10 era, but it isn't an active project at this time.
Note that the current HRT maintainers objected to this characterization.
HRT - Geoge Anzinger's patch
Prior to hrtimers, the main patch which provided high resolution timers was George Anzinger's patch.The official HRT site for this patch is at:
Specifications
RtwgPTSpec_R2 - CELF 1.0 Specification, Section on Posix Timers
Downloads
Patch
CELF's patch archive page: PatchArchive
- Tom Rini has posted some patches for earlier 2.6 kernels at:
Utility programs
How To Use
[not described yet.]
How to validate
There are test programs in a user-space support package.
Sample Results
[Examples of use with measurement of the effects.]
Case Study 1
Case Study 2
Status
- Status: implemented
- Architecture Support:
- (for each arch, one of: unknown, patches apply, compiles, runs, works, accepted)
- i386: works
- ARM: unknown
- PPC: works
- MIPS: unknown
- SH: unknown
Future Work/Action Items
Here is a list of things that could be worked on for this feature:
- Documentation
- Testing
Old information (for 2.4 kernel)
The High Resolution Timers system allows a user space program to be wake up from a timer event with better accuracy, when using the POSIX timer APIs. Without this system, the best accuracy that can be obtained for timer events is 1 jiffy. This depends on the setting of HZ in the kernel. In the 2.4 kernel, HZ was set to 100, which means that the best accuracy you could get on a timer wakeup in user space was 10 milliseconds.
Put differently, if you asked for a timer event in 500 microseconds, you would wake up in 10 milliseconds (at least).
To support this feature on a particular board, you have to add a kernel driver that uses a timer on the system and supports the interface documented in:
include/linux/hrtime.h (in the CELF tree)
Additional documentation about this feature is available in
Documentation/high-res-timers/
Patches for high-res timers were first presented at the time of kernel version 2.5.47, in November, 2002. See http://lwn.net/Articles/14538/
