Operations 20 min read

Understanding Leap Seconds and Their Impact on Linux Systems

The article explains why leap seconds are added to keep UTC aligned with Earth's rotation, describes the three time scales (UT1, TAI, UTC), details Linux kernel bugs caused by leap‑second handling across various versions, and offers mitigation scripts while discussing the future removal of leap seconds.

Tencent Cloud Developer
Tencent Cloud Developer
Tencent Cloud Developer
Understanding Leap Seconds and Their Impact on Linux Systems

This article explains the origin and purpose of leap seconds, describing how they are introduced to keep Coordinated Universal Time (UTC) aligned with Earth's irregular rotation. It outlines the three main time scales: Universal Time (UT1), Atomic Time (TAI), and UTC, and explains why occasional leap seconds are necessary.

The piece then details various methods used by operating systems to handle leap seconds, including NTP-synchronized systems, PTP (Precision Time Protocol) systems, and systems without time synchronization. It provides concrete examples of log messages and kernel behavior when a leap second is inserted.

Significant kernel issues are highlighted:

Deadlock in Linux kernels 2.6.22 and earlier when processing leap seconds due to conflicting xtime_lock usage.

Deadlock in kernels 2.6.25‑2.6.27 caused by printk() invoking the scheduler while holding xtime_lock.

Live‑lock and high CPU consumption in Linux 2.6.32 and 3.4 kernels during leap‑second insertion, caused by timers not being properly adjusted.

For each problem, the affected kernel versions are listed, along with patches or kernel commits that introduced fixes (e.g., commit b845b517 in 2.6.28, fixes in 3.4). The article also shows sample kernel stack traces and explains the root cause of the deadlocks.

Practical mitigation steps are provided, such as manually resetting the system clock with date -s "$(date)" to trigger clock_was_set(), and a custom program that detects early timer expirations caused by leap seconds and calls clock_settime(CLOCK_REALTIME, &ts) to correct the issue. The script can be scheduled via cron to run every 100 ms around the expected leap‑second moment.

The article concludes with a discussion on the upcoming decision to discontinue leap seconds after 2035, the implications for timekeeping, and the ongoing debate among scientific and industry communities.

Linux kernelleap secondNTPtime synchronizationsystem clock
Tencent Cloud Developer
Written by

Tencent Cloud Developer

Official Tencent Cloud community account that brings together developers, shares practical tech insights, and fosters an influential tech exchange community.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.