gpt4 book ai didi

c - CLOCK_TAI 的纪元是什么?

转载 作者:IT王子 更新时间:2023-10-29 01:13:43 25 4
gpt4 key购买 nike

从 Linux 内核版本 3.10 开始,函数 clock_gettime() 现在接受 CLOCK_TAI

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

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

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

编辑 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 和 CLOCK_TAI 返回相同的值,因为内核参数 tai_offset 为零。

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

我的引用 herehere

关于c - CLOCK_TAI 的纪元是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32652688/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com