Since Linux kernel version 3.10, the function clock_gettime()
now accept CLOCK_TAI
.
I didn't manage to find a detailed description of this clock. What is its epoch ?
EDIT 1: Just compared the output of CLOCK_REALTIME and CLOCK_TAI on my Linux 3.19 OS and it returns the exact same value (1442582497) !? Is CLOCK_REALTIME decremented at leap seconds ?
EDIT 2: According to this article, the difference between CLOCK_TAI and the (badly named) CLOCK_REALTIME should be the number of leap seconds.
EDIT 3: The reason CLOCK_TAI
and CLOCK_REALTIME
are the same time is explained in the article referenced in Edit 2. The emphasis is by me.
For applications where it would be possible to work with TAI time instead of UTC, the kernel provides a special CLOCK_TAI clock which does include leap seconds and doesn’t need to be corrected after leap second, avoiding the problem with backward jump in the time entirely. It’s implemented as a clock running at a fixed integral offset to CLOCK_REALTIME, which is atomically incremented by 1 when the CLOCK_REALTIME clock is stepped back on leap second. It was introduced in the Linux kernel version 3.10 and is available with the kernels shipped in RHEL7. Please note that the offset from CLOCK_REALTIME is initialized on boot to zero and neither ntpd nor chronyd set it by default to the correct value (currently 35). Switching to CLOCK_TAI in applications would of course require modifications to the code and possibly also all protocols that use the Unix representation of time.
Edit 4 : This answer obtained on Ask Ubuntu clarifies everything.