

Example: A fixed interval of 100 times per second can provide a minimum resolution of 0.01s. It involves setting up a hardware device to send “ticks” at a fixed interval known to the OS, the OS keeps track of the time based on the received ticks. There are various types of hardware timers available in a system: Programmable Interval Timer (PIT), CMOS RTC, per-processor advance programmable interrupt controller (APIC), Advanced Configuration and Power Interface (ACPI) Timer, Timestamp Counter, High Precision Event Timer (HPET).īig words, will be discussed in this section. Hardware Clocks at an abstract level comprise of an oscillator set to a frequency which could be fixed or set by the operating system at boot. Monotonic Clocks often offer a higher resolution than Wall-Clock Timers. The absolute value of the timer is not useful as it based on counting time from an arbitrary point in the past, but rather monotonic clocks are useful for measuring durations with high certainty. CLOCK_MONOTONIC is a Monotonic Clock in Linux. The frequency rate of the timer might not be constant and be adjusted by synchronization algorithms, which means that one measured second might actually be a different amount of time from another measured second. CLOCK_REALTIME is a Wall-Clock timer in Linux.Ī Monotonic Clock is a constantly increasing timer which guarantees that it will never go backwards in time. This clock can go forward or backwards in time as desired by synchronization algorithms (NTP) or the user to represent the current time, due to this reason they are not recommended for measuring durations. Usually, wall-clock time is counted as the number of time units since Janu00:00:00 UTC or EPOCH. This represents the time as it will be on a wall-clock. The aim of this post is to learn the kinds of clocks and timing mechanism’s available on an x86 system, how they are virtualized by different hypervisors (with a focus on Hyper-V and WSL2) and what is the practical resolution of clocks and timers in both virtualized and bare-metal x86 systems accessible via programming languages like C or Golang.Ī system might have two kinds of clocks available to use in the system, a Wall-Clock Timer and a Monotonic Clock.
