CLOCK_TAI 的纪元是多少?

What is the epoch of CLOCK_TAI?

自 Linux 内核版本 3.10 起,函数 clock_gettime() 现在接受 CLOCK_TAI

我没能找到这个时钟的详细描述。它的时代是什么?

编辑 1:刚刚比较了 CLOCK_REALTIME 和 CLOCK_TAI 在我的 Linux 3.19 OS 上的输出,它 returns 完全相同的值 (1442582497) !? CLOCK_REALTIME 是否在闰秒时递减?

编辑 2:根据 this article,CLOCK_TAI 和(命名错误的)CLOCK_REALTIME 之间的区别应该是闰秒。

EDIT 3: CLOCK_TAICLOCK_REALTIME 是同一时间的原因在编辑 2 中引用的文章中有解释。重点是我.

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.

编辑 4 : This answer 在 Ask Ubuntu 上获得澄清了一切。

CLOCK_TAI is basically designed as CLOCK_REALTIME(UTC) + tai_offset.  

因此 timeval/timespec 的 usec/nsec 部分应该相同。

CLOCK_MONOTONIC: Zeroed at boot.  

CLOCK_TAI = CLOCK_MONOTONIC + tai_mon_offset    

CLOCK_REALTIME(UTC) = CLOCK_TAI - tai_utc_offset  

但出于性能考虑(CLOCK_REALTIME是什么应用 锤击最多),在 Linux 中,我们实际上将其结构化为:

CLOCK_REALTIME: Initialized at boot from RTC  
CLOCK_MONOTONIC: CLOCK_REALTIME - wall_to_monotonic  
CLOCK_TAI: CLOCK_REALTIME + tai_offset

所以CLOCK_REALTIME and CLOCK_TAI return the same because the kernel parameter tai_offset is zero.

使用adjtimex(timex tmx)检查并读取值。我认为如果 ntpd 足够新 (>4.2.6) 并且有闰秒文件,它会设置它。它也可能能够从上游服务器获取它,但我无法验证。当 运行 为 root 时,调用 adjtimex() 可以手动设置 tai_offset

我的参考here and here