Clock and Timers

Here are some common clock and timer source on an embedded system, referred from clock and timer circuits, few timer and clock source are listed.

How to check your available clock source ?

check out sysfs

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

Real Time Clock

The real time clock (RTC) continuous to tick event when the PC is switched off, because it is energized by a small battery.

RTC is capable of issuing periodic interrupts at frequencies ranging between 2 Hz to 8192 Hz.

How linux use RTC ?

linux uses the RTC only to derive the time and date; however, it allows processes to program the RTC by acting the /dev/rtc device file.

Time Stamp Counter

Each Local CPU has it's own TSC, so it might not possible all CPU have the same TSC value.

Frequency of TSC may dynamically lower the frequency or voltage of the CPU to save battery power. When this happens, the frequency of the TSC changes while the ACPI PMT does not.

Programmable Interval Timer

Programmable Interval Timer, PIT, issues a special interrupt called timer interrupt, which notifies the kernel that one more time interval has elapsed.

Noted that PIT is not commonly used in Intel and ARM CPU.

CPU Local Timer

The CPU local timer is a device similar to the PIT described that can issue one-shot or periodic interrupts. It sends an interrupt only to it's processor, while the PIT raises a global interrupt, which may handled by any CPU in the system.

High Precision Event Timer

High precision event timer is also called HPET which provides a number of hardware timers that can be exploited by the kernel.

Basically, HPET includes up to eight 32 or 64 bits independent counters, each counter is driven by it's own clock signal, whose frequency must be at least 10MHz. therefore, the counter is increased at least once in 100 nanoseconds.

ACPI Power Management Timer

ACPI timer is yet another clock device included in almost all ACPI-based motherboards.

Comparison

Source Type Frequency CPU Arch Prefer
RTC clock 2 ~ 8192 Hz All (Intel/ARM)
TSC clock Intel 👍
PIT timer 1000 Hz 👎
CPU local timer timer All (Intel / ARM)
HPET timer 10M Hz Intel 👍👍
ACPI clock 3.58 Mhz All (Intel / ARM)