Windows上的时钟漂移 [英] Clock drift on Windows

查看:240
本文介绍了Windows上的时钟漂移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了一种Windows服务,该服务可以跟踪业务事件。它使用Windows时钟为事件加时间戳。但是,底层时钟可能会发生相当大的漂移(例如,每分钟损失几秒钟),尤其是在CPU努力工作时。我们的服务器使用Windows时间服务与域控制器保持同步,该域控制器在后台使用NTP,但是同步频率由域策略控制,并且在任何情况下,即使每分钟同步也仍然会产生很大的漂移。除了使用硬件时钟外,还有什么其他方法可以使时钟更稳定?

解决方案

时钟滴答应该是可预测的,但在大多数PC硬件上-因为并非为实时系统设计-其他I / O设备中断的优先级高于时钟滴答中断,并且某些驱动程序在中断服务中进行大量处理例程而不是将其推迟到延迟过程调用(DPC),这意味着系统可能不会

其他因素包括总线主控I / O控制器会从时钟窃听器中窃取许多内存总线周期CPU,导致它在相当长的一段时间内缺乏内存总线带宽。



正如其他人所说,随着组件值的变化,时钟生成硬件也可能会改变其频率。 te



Windows允许调整每个中断上添加到实时时钟的滴答数:请参阅SetSystemTimeAdjustment。但是,只有在可预测的时钟偏斜的情况下,这才起作用。如果时钟仅略微关闭,则SNTP客户端( Windows时间服务)将调整此偏斜,以使时钟的滴答声稍微快一些或慢些,从而趋向于正确的时间。


I've developed a Windows service which tracks business events. It uses the Windows clock to timestamp events. However, the underlying clock can drift quite dramatically (e.g. losing a few seconds per minute), particularly when the CPUs are working hard. Our servers use the Windows Time Service to stay in sync with domain controllers, which uses NTP under the hood, but the sync frequency is controlled by domain policy, and in any case even syncing every minute would still allow significant drift. Are there any techniques we can use to keep the clock more stable, other than using hardware clocks?

解决方案

Clock ticks should be predictable, but on most PC hardware - because they're not designed for real-time systems - other I/O device interrupts have priority over the clock tick interrupt, and some drivers do extensive processing in the interrupt service routine rather than defer it to a deferred procedure call (DPC), which means the system may not be able to serve the clock tick interrupt until (sometimes) long after it was signalled.

Other factors include bus-mastering I/O controllers which steal many memory bus cycles from the CPU, causing it to be starved of memory bus bandwidth for significant periods.

As others have said, the clock-generation hardware may also vary its frequency as component values change with temperature.

Windows does allow the amount of ticks added to the real-time clock on every interrupt to be adjusted: see SetSystemTimeAdjustment. This would only work if you had a predictable clock skew, however. If the clock is only slightly off, the SNTP client ("Windows Time" service) will adjust this skew to make the clock tick slightly faster or slower to trend towards the correct time.

这篇关于Windows上的时钟漂移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆