How TSC-to-HPET Clock Source Downgrade Degrades Database Performance
This article explains why Linux kernels automatically switch from the high-performance TSC clock source to the slower HPET timer, details the technical differences between them, quantifies the 10-50% database throughput drop caused by the switch, and provides step-by-step troubleshooting commands to detect and resolve the issue.
Reading font
1. CPU Clock Sources in Linux
Linux servers default to the CPU's built-in Time Stamp Counter (TSC) as the system clock source for the lowest time-read latency. When the kernel's clocksource watchdog detects TSC anomalies — such as count drift, desynchronization, or stoppage — it automatically downgrades to the motherboard's High Precision Event Timer (HPET) . This switch significantly increases time-acquisition overhead, which is amplified in high-frequency timestamp workloads like databases.
Database systems are time-sensitive: transaction lifecycle management, write-ahead logging (WAL), concurrency control, and replication all call system time frequently. The overhead amplification from TSC-to-HPET switching manifests as throughput drops, higher CPU usage, and increased latency in high-concurrency OLTP scenarios.
2. Technical Differences Between TSC and HPET
2.1 TSC (Time Stamp Counter)
Access mode: User-space reads via RDTSC / RDTSCP instructions — no syscall, no context switch. Typical latency: 1–5 ns.
Frequency evolution: Three generations: (1) early TSC tied to CPU core frequency (varies with Turbo Boost/SpeedStep); (2) constant_tsc fixes count rate at base frequency, immune to P-state changes; (3) nonstop_tsc / invariant_tsc continues counting in deep C-states — the most stable form.
Synchronization: Each physical core maintains its own TSC register; cross-core and cross-NUMA offsets depend on BIOS calibration, creating inherent skew risk.
2.2 HPET (High Precision Event Timer)
Access mode: Requires syscall ( clock_gettime / gettimeofday), kernel MMIO read of motherboard PCH/southbridge hardware, then conversion. Typical latency: 50–200 ns plus context-switch overhead.
Frequency: Independent crystal oscillator, fixed at 14.31818 MHz (some platforms 100 MHz), unaffected by CPU power management.
Synchronization: Single global hardware counter shared by all cores — naturally consistent across sockets and NUMA nodes.
2.3 Core Comparison
The article includes a comparison table (image) and architecture diagrams (images) showing:
TSC path: user-space rdtsc → per-core register → ultra-low latency but per-core counters with cross-NUMA desync risk.
HPET path: syscall → kernel → MMIO bus → global HPET hardware → higher latency but globally consistent timebase.
Watchdog mechanism: kernel clocksource watchdog uses HPET as reference, periodically verifies TSC accuracy; when drift exceeds threshold, triggers automatic downgrade.
3. Automatic TSC-to-HPET Switch Trigger Mechanism
3.1 Kernel Verification Logic
At boot, TSC registers as highest-priority clocksource with watchdog enabled, using HPET (or PIT) as reference.
Watchdog thread samples TSC vs reference every ~0.5 seconds, computes deviation rate.
If deviation exceeds 500 ppm (parts per million) continuously, TSC marked unstable and kernel switches to next reliable clocksource (usually HPET).
Switch logged in dmesg:
clocksource: timekeeping watchdog: Marking clocksource tsc as unstable; switching to clocksource hpet.
3.2 Six Typical Trigger Scenarios
Deep C-state sleep halts TSC: On CPUs lacking nonstop_tsc, entering C6/C7 stops TSC; wakeup leaves gap uncompensated, causing drift. Common on servers with power-saving enabled under low load.
Multi-socket NUMA TSC desync: Each socket has independent TSC domain; BIOS initial calibration has microsecond-level skew. Long-term thermal drift and crystal variance widen cross-socket offset until watchdog trips. This is the most common cause in production database servers.
P-state frequency scaling: On CPUs without constant_tsc, TSC rate follows core frequency; Turbo Boost and SpeedStep changes accumulate drift.
BIOS/firmware bugs or misconfiguration: Faulty TSC calibration logic, enabled deep-sleep options (e.g., "CPU C6 report"), missing virtualization TSC passthrough settings.
Virtualization incompatibilities: VM migration across heterogeneous host CPUs, unstable host TSC passed through, lack of hardware-assisted TSC virtualization.
Hardware faults: CPU clock circuit failure, motherboard crystal drift — rare but indicative of hardware failure.
4. Performance Impact on Database Systems
Switching trades timestamp-read performance for global time stability. Impact spans three layers:
4.1 Root Causes of Degradation
Time-acquisition overhead increases 10–100×: Database core paths (transaction start/commit/snapshot timestamps, WAL logging, lock timeouts, deadlock detection, session timeouts, monitoring) all call timestamps. TSC: few ns user-space; HPET: syscall + MMIO + context switch.
Syscall and context-switch surge: Each timestamp read now traps to kernel, invalidating CPU caches, raising scheduler overhead. perf stat shows spike in clock_gettime calls and cs (context switches).
Timer scheduling jitter: Background tasks (checkpoints, dirty-page flush, log archive) rely on high-precision timers; HPET's higher interrupt latency introduces jitter, potentially causing I/O spikes.
4.2 Quantified Impact by Workload
General OLTP: TPS down 10–20%, CPU usage up 10–20%, avg latency up 20–30%.
High-frequency small transactions: Degradation up to 30–50% due to many timestamp calls per transaction.
OLAP/analytical: Low timestamp frequency; impact <5%, usually negligible.
4.3 Positive Side Effects
Eliminates timestamp reordering and time-going-backward anomalies, protecting transaction log correctness and data consistency.
Prevents cross-NUMA time skew from causing false lock timeouts or replication lag miscalculation.
Improves long-term time stability, reducing risk of clock-induced outages.
5. Troubleshooting and Optimization Guide
5.1 Confirmation and Localization Steps
Observe sudden slow-SQL surge: normally tens of ms, now seconds; slow-log shows high kernel CPU time.
Check CPU breakdown: sys CPU portion rises , indicating abnormal kernel scheduling overhead.
Profile with perf: database process spends >70% time in read_hpet — primary suspect.
Verify current clocksource:
cat /sys/devices/system/clocksource/clocksource0/current_clocksourceOutput hpet confirms switch; tsc is normal.
Check switch logs:
dmesg | grep -i "clocksource|tsc.*unstable|switching"Look for
Marking clocksource tsc as unstable; switching to clocksource hpet.
Inspect TSC hardware flags:
grep -E "constant_tsc|nonstop_tsc|invariant_tsc" /proc/cpuinfoMissing flags indicate lack of stable TSC support — a root cause candidate.
5.2 Root-Cause Investigation Directions
BIOS config: deep C-states (C6/C7) enabled? power-saving mode? TSC sync calibration enabled?
Firmware version: outdated BIOS/BMC with known TSC bugs?
Virtualization: VM? recent live migration? host TSC stable?
In the author's case, hardware-level issue was confirmed; replacing the CPU and rebooting restored normal operation.
6. Summary
TSC and HPET embody "peak performance" vs "global stability" design philosophies. TSC leverages CPU-native registers for nanosecond latency; HPET uses dedicated motherboard hardware for cross-core consistency. The kernel's watchdog downgrade is a fail-safe strategy sacrificing performance for reliability.
For database systems, this switch can cause 20–30% performance regression . In production — especially on multi-NUMA-node, multi-socket servers — prioritize investigating hardware-layer causes of TSC instability (BIOS, firmware, CPU hardware) and restore TSC as clocksource (e.g., via CPU replacement) to recover performance.
For questions about attribution, corrections or content rights, please contactand we will review it promptly.