Timer Interrupt Sources
X86 related clocks from Brendan post on http://forum.osdev.org/viewtopic.php?p=277285&sid=e5be2757dbd0ffdab02081df2bec8863#p277285
Overview
Architecture | Discovery | Per CPU Core | Counter | Calibration Not Required | IRQ Frequency | Fixed Frequency IRQ | IRQ on terminal count | Access speed | ||
---|---|---|---|---|---|---|---|---|---|---|
RTC | x86 PC | {{No} | No | Yes | style="background: #ddffdd" | Yes | No | Slow ISA IO ports | |||
PIT | x86 PC | 6 PC | No | Yes | Local A | Yes | Slow ISA IO ports (or slow SMM emulation of ISA ports) | |||
ACPI Power Management Timer | x86 PC | ACPI tables (No}} | }} | { | Yes | Yes | es}} | No | IO ports (may or may not be "faster, non-ISA IO ports") | |
HPET | x86 PC | ACPI tables (}} | Yes | Yes | Yes |
= | style="background: #ddffdd" | Yes | style="background: #ddffdd" | Yes | 64-bit monotonically increasing at 10 MHz or better |y
Acce | style="background: #ddffdd" | Yes |Fast (typically memory mapped device) |- | TSC |x86 PC |ate/time)
Fixed frequency I| : Yes, | style="background: #ddffdd" | Yes | style="background: #ffdddd" | No | No IRQ avaialable | at fa | style="background: #ffdddd" | No |Very fast (built into CPU) |- |Local APIC timer (older) | x86 PC | to exist, but may be emulated by HPET)
Calibration: Not necessary
Access speed: Slow or ACPI tables ( slow SMM emul| ion of | style="background: #ffdddd" | No | style="background: #ffdddd" | No | Depends on CPU's bus / link speed, typically 100 Mhz or better (10 ns better) |nt: Yes | style="background: #ddffdd" | Yes |Very fast (built into CPU) |- |Local APIC timer (newer) |x86 PC |alibration: Not necessary
Access speed: IO ports (may or may not be "faster, non-ISA I or ACPI tables (r: Yes, 24-bit| r 32-bi | style="background: #ddffdd" | Yes | style="background: #ffdddd" | No | 64-bit monotonically increasing at CPU's clock speed (which can vary on old CPUs) | Timer] | style="background: #ddffdd" | Yes |Very fast (built into CPU) |- |Generic Timer |ARM | Always present |emory m | style="background: #ddffdd" | Yes | style="background: #ddffdd" | Yes |CNTP_CVAL and CNTV_CVAL system registers |Configurable | style="background: #ddffdd" | Yes |Very fast (built into CPU) |- | Local Timer | ARM | Always present |s, 100 | style="background: #ffdddd" | No | style="background: #ddffdd" | Yes | 38.4 MHz |]]
==T | style="background: #ddffdd" | Yes |Moderate (using MMIO) |- |System Timer |ARM/BCM | On BCM2835-2837 SoC (Raspberry Pi) |ncreas | style="background: #ddffdd" | Yes | style="background: #ddffdd" | Yes | Yes |hich ca | style="background: #ddffdd" | Yes |Moderate (using MMIO) |}
Precision
For counters; ignoring "emulated with something else", the options in order of best precision are: TSC, HPET, ACPI power management timer
For fixed frequency IRQ; ignoring "emulated with something else", the options in order of best precision are: local APIC timer, HPET, PIT, RTC
For IRQ on terminal count (e.g. needed for "tickless"); ignoring "emulated with something else", in order of best precision are: local APIC timer in TSC deadline mode, local APIC timer without TSC deadline mode, HPET, PIT
Emulation
Counters can be emulated in software using a fixed frequency IRQ (e.g. doing "tick++;" in the IRQ handler).
Fixed frequency IRQ can be emulated in software using IRQ on terminal count (e.g. just set the new count to the same value each time).
IRQ on terminal count can be emulated in software using a fixed frequency IRQ (e.g. doing "count--; if(count == 0)" in the IRQ handler).
Notes
A "counter" is something you poll when you need to know how much time has passed (e.g. for file system timestamps, measuring how much CPU time each thread consumed, etc).
For local APIC timer, there's one per CPU. This is important for scalability (rather than many CPUs fighting to access the same single timer).
A good OS would detect which timers exist and determine their capabilities; then use this information to select the best timers to use for each different purposes.