Jump to content

High Precision Event Timer

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Orenburg1 (talk | contribs) at 09:35, 27 November 2011 (sp). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

The High Precision Event Timer is a hardware timer used in personal computers. It was developed jointly by Intel and Microsoft and has been incorporated in PC chipsets since circa 2005. Formerly referred to by Intel as a Multimedia Timer,[1] the term HPET was selected to avoid confusion with the multimedia timers software feature introduced in the MultiMedia Extensions to Windows 3.0.[2]

Older operating systems do not support HPET and can only use older timing facilities, such as the programmable interval timer or the real-time clock.

Features

An HPET chip consists of a 64-bit up-counter (main counter) counting at least at 10 MHz and a set of up to 256 comparators (at least 3). These comparators are 32- or 64-bit wide. The HPET is programmed via a memory mapped I/O window that is discoverable via ACPI. The HPET circuit in modern PCs is integrated into the southbridge chip.[note 1]

Each comparator can generate an interrupt when the least significant bits are equal to the corresponding bits of the 64-bit main counter value. The comparators can be put into one-shot mode or periodic mode, with at least one comparator supporting periodic mode and all of them supporting one-shot mode. In one-shot mode the comparator fires an interrupt once when the main counter reaches the value stored in the comparator's register, while in the periodic mode the interrupts are generated at specified intervals.

Comparators can be driven by the operating system, e.g. to provide one timer per CPU for scheduling, or by applications.

Applications

The HPET can produce periodic interrupts at a much higher resolution than the RTC and is often used to synchronize multimedia streams, providing smooth playback and reducing the need to use other timestamp calculations such as an X86-based CPU's RDTSC instruction.

Comparison to predecessors

HPET is meant to supplement and replace the 8254 programmable interval timer and the RTC's periodic interrupt function. Compared to these older timer circuits, the HPET has higher frequency (at least 10 MHz) and wider 64-bit counters (although they can be driven in 32-bit mode).[1]

While 8254 and RTC can, similarly to HPET, be put in one-shot mode, the set-up process is so slow that their one-shot mode is not used in practice for tasks requiring precise scheduling.[3] Instead, 8254 and RTC are typically used in periodic mode with very small time interval. For example, if an application needs to perform several short (some milliseconds, perhaps) waits, it is better to have a periodic timer running constantly with 1 ms period because of the high setup cost of an 8254 or RTC one-shot timer. This causes an interrupt on every millisecond even if the application needs to do actual work less frequently. With HPET, the extra interrupts can be avoided, because the set-up cost of a HPET one-shot timer is considerably smaller.

Compatibility

Operating systems designed before HPET existed cannot use HPET, so work only on hardware that has other timer facilities. Newer operating systems tend to be able to use either. Some hardware has both.

The following operating systems are known not to be able to use HPET: Windows XP,[note 2] Windows Server 2003, and earlier Windows versions, Linux kernels prior to 2.6.[note 3]

The following operating systems are known to be able to use HPET: Windows XP,[note 4] Windows 2008, Windows Vista, Windows 7, x86 based versions of Mac OS X, Linux operating systems using the 2.6 kernel, FreeBSD and OpenSolaris.

Problems

HPET is a continuously running timer that counts upward, not a one-shot device that counts down to zero, causes one interrupt and then stops. Since HPET compares the actual timer value and the programmed target value on equality rather than "greater or equal", interrupts can be missed if the target time has already passed when the comparator value is written into the chip's register. In the presence of non-maskable interrupts (such as System Management Interrupts) that do not have a hard upper bound on their execution time, this race condition requires time-consuming re-checks of the timer after setup and is hard to avoid completely. The difficulties are exacerbated if the comparator value is not synchronized with the timer immediately, but delayed by one or two ticks, as some chipsets do.[4]

See also

Notes

  1. ^ On these highly integrated dies the BIOS often sets up the HPET incorrectly in the ACPI, initializing it correctly only in Intel 8253 mode. If the ACPI is not set up correctly the OS cannot list the HPET. And the BIOS and OS developers don't see the need to get Real Time support. So the HPET is only there to satisfy the systems high speed needs. If the HPET is set up correctly in the ACPI from BIOS then the ACPI MMIO page of the first HPET chip should be at 0xFED00000 and the second HPET at page 0xFED80000 (see the discussion for further information).
  2. ^ Windows XP, SP2 knows the HPET timer (as a device with PNP0103 identifier). When detected (for example, on Intel DQ45CB motherboard), Device Manager (START / SETTINGS / CONTROL_PANEL / SYSTEM / DEVICE_MANAGER) shows "High Precision Event Timer" device in "System devices" branch. But this device has no driver and is not used at all.
  3. ^ With a Linux kernel, you need the newer "rtc-cmos" hardware clock device driver rather than the original "rtc" driver.
  4. ^ On XP SP3 the IRQ0 and IRQ8 are often both mapped to a "High Precision Event Timer" when using the ACPI HAL (version 5.1.2600.5512), albeit that the QueryPerformanceFrequency API call returns a value related to the rated processor clock speed (e.g. 2.6GHz) rather than the Intel HPET spec'd value of 15MHz that you would get using Vista. This anomaly muddies the water about what is meant by "HPET" on such systems, but it is clearly not the 15MHz Intel device in those cases. On any system, the quoted frequency has to be stable in order to qualify for QueryPerformanceFrequency, so the quoted CPU-based clock speed is clearly not an ongoing reading of the CPU core frequency itself. However, its high value implicates the TSC (Time Stamp Counter) mechanism as being the basis of this apparent "HPET". Note that this IRQ mapping and clock relationship can be found both on Intel systems and AMD systems that are not using the /USEPMTIMER boot override. There can be concerns over the stability of the TSC-derived QueryPerformanceCounter readings on multicore systems as the actual frequency (i.e. not the reported frequency) may vary. Whilst the most recent ACPI HAL apparently includes code to synchronize the counters between processors, it is not entirely clear how it deals with variations in frequency under power management or the deliberate clock dither (spread-spectrum settings) that can be set in the BIOS. On both Intel and AMD machines using the ACPI HAL together with the /USEPMTIMER boot switch, the IRQs 0 & 8 will still report a HPET, but now the QueryPerformanceFrequency will report 3.579545MHz, which is the frequency of the PMTIMER. This has the express advantage of being independent of the CPU frequency and still provides a very reasonable sub-microscecond resolution and accuracy. With or without the /PMTIMER switch, the "event" part of the HPET specification can only be emulated, since neither underlying solution includes implicit hardware for aperiodic event triggering as described by the specification, and yet this is available via the timer API in XP (to a best possible resolution of 0.9766ms). This part of the specification is most probably still fulfilled by the RTC or similar device with the help of software, despite the fact that the device manager is quoting HPET in the IRQ0 and IRQ8 positions. So it appears that the term "High Precision Event Timer" was already being used to describe TSC (Time-Stamp-Counter) and PMTimer systems before the 15MHz Intel HPET came into being. So whilst it is true to say that only Vista and later Windows use the Intel 15MHz HPET, the terminology of HPET exists for Windows XP, albeit to a different specification and reduced capability. In short, XP SP3 "emulates" most of the HPET specification (drafted in 2002) in anticipation of a device that made its eventual appearance in PCs designed for Windows Vista by 2005.

References

  1. ^ a b Intel Corporation (2004), IA-PC HPET (High Precision Event Timers) Specification (revision 1.0a) (PDF), retrieved 2007-07-16 {{citation}}: Unknown parameter |month= ignored (help)
  2. ^ "Multimedia Timers". Microsoft. Retrieved 2010-10-20.
  3. ^ Guidelines For Providing Multimedia Timer Support, 2002-09-20, retrieved 2009-11-10
  4. ^ Thomas Gleixner, x86: hpet: Work around hardware stupidity, commit merged for Linux kernel 2.6.36-rc5