c - CLOCK_TAI 的纪元是什么?

标签 c linux time posix tai-time

从 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/

相关文章:

c# - 如何使 WCF 服务服务器-客户端时差独立?

c - 是否可以在每条指令后转储内存?

c - 在内核空间中实现可变参数的可移植方法?

serialization - 跨平台时区序列化

linux - 跟踪特定的 IP 和端口

c - 窗口没有出现在屏幕上

python - 如何将 Dataframe 时间增加 5 分钟间隔?

c - 逐行读取文件,将整数存储在数组中

c - fork 进程的执行顺序

node.js - 使用 ssh 在 linux 服务器上启动 nodejs 应用程序-如果我关闭 ssh 连接,应用程序停止为什么?)