Notes / HPET


HPET is the High Precision Event Timer. HPET was designed by Microsoft and AMD to replace old timers like TSC and be the main timer for high-precision measurements. However, HPET didn’t become the main timer mainly because of the huge access time. On modern hardware and operating systems, HPET is usually disabled (the invariant TSC is used as the primary timestamp source), but it’s usually possible to enable it (if you want it for some reason).

According to hpet-specifications, section 2.2, the minimum HPET clock frequency is 10 MHz, but the actual HPET frequency is always 14.31818 MHz (see 14.31818 MHz).

Enabling/Disabling HPET on Windows

On Windows, you can enable or disable HPET with the help of the bcdedit (see BCDEdit Command-Line Options and BCDEdit /set).

To enable HPET, you should run it with /set useplatformclock true arguments and reboot your computer.

:: Enable HPET (reboot is required):
bcdedit /set useplatformclock true

It sets the useplatformclock value in Boot Manager which requires HPET instead of TSC. If you don’t want to use it anymore, you should delete this value by /deletevalue and reboot:

:: Disable HPET (reboot is required):
bcdedit /deletevalue useplatformclock

If you want to check, is HPET enabled or not, you should look for useplatformclock in the output of the following command:

bcdedit /enum

Enabling/Disabling HPET on Linux

On Linux, all the files related to time sources are typically placed in /sys/devices/system/clocksource/clocksource0/. You can look at the full list of available clock sources in available_clocksource. Here is an example of a machine that has TSC, HPET, and ACPI PM:


## Get available clocksource:

$ cat /sys/devices/system/clocksource/clocksource0/available_clocksource
tsc hpet acpi_pm

The current clock source can be found in `current_clocksource``:


## Get current clocksource:

$ cat /sys/devices/system/clocksource/clocksource0/current_clocksource
tsc

This value can be easily changed. For example, to enable HPET, you should run:


## Set current clocksource:

$ sudo /bin/sh -c \
  'echo hpet > /sys/devices/system/clocksource/clocksource0/current_clocksource'

Usually, HPET is disabled, but you shouldn’t assume that TSC is always the default. For example, you can encounter enabled HPET on many legacy servers (which didn’t have OS reinstallation for several years). It can be also enabled manually for some specific scenarios or because of the bugs. For example, there was a firmware bug in CentOS 7: “available_clocksource” contained only hpet acpi_pm without tsc (see stackoverflow-45803565).


References (7)