在Windows 7中时钟如何工作? [英] How does the clock work in Windows 7?

查看:145
本文介绍了在Windows 7中时钟如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在某处阅读了此答案,但我不太清楚:

I have read this answer somewhere but I don't understand it exactly:


我了解Windows每增加curTimeIncrement $ b都会增加时钟$ b(156001
+-N)的值(156001
+-N)。但是,当使用GetSystemTime读取时钟时,例程在156001纳秒* 100间隔内插值到
是否会产生指示的精度?

I understand Windows increments the clock every curTimeIncrement (156001 100 nanoseconds) with the value of curTimeAdjustment (156001 +- N). But when the clock is read using GetSystemTime does the routine interpolate within the 156001 nanosecond*100 interval to produce the precision indicated?

有人可以尝试向我解释吗?

Can someone try to explain it to me?

什么是 curTimeIncrement curTimeAdjustment 和Windows如何做到这一点?

What is curTimeIncrement, curTimeAdjustment and how can Windows do this?

此操作对于获得准确时间有什么影响?

What is the effect for this on getting the accurate time?

仅适用于Windows 7还是其他OS Win8,Linux等吗?

Is that true just for windows 7 or also other OS Win8, Linux, etcetera?

推荐答案

GetSystemTimeAdjustment ()在Windows上。它告诉您如何调整时钟以使其赶上或慢下来以匹配实时。 真实是美国NIST这样的机构所保留的时间,它们具有原子钟,其准确性远远高于您的计算机内置时钟。

It refers to the values returned by GetSystemTimeAdjustment() on Windows. It tells you how the clock is being adjusted to catch up or slow down to match the real time. "Real" being the time kept by an institution like the NIST in the USA, they have an atomic clock whose accuracy is far, far higher than the clock built into your machine.

您机器中的实时时钟(RTC)的准确性有限,这是保持硬件价格合理的副作用,它通常每个月都会减少几秒钟。因此,操作系统会定期通过Internet与时间服务器联系,time.windows.com是Windows上的常见选择。

The Real Time Clock (RTC) in your machine has limited accuracy, a side-effect of keeping the hardware affordable, it tends to be off by a few seconds each month. So periodically the operating system contacts a time server through the Internet, time.windows.com is the common selection on Windows. Which tells it the current real time according to the atom clock oracle.

RTC的不精确性不是漂移的唯一来源,有时会故意改变实时性。添加 second秒以使时钟与地球的真实自转重新同步。目前的一天(24 x 60 x 60秒)太短了,每个世纪地球的自转速度都降低了约1.5毫秒,并且由于暴风雨和地震的发生,通常情况下它是不规则的。插入的leap秒弥补了这一点。最近一次添加是在今年6月30日世界标准时间23:59:60。 60不是拼写错误:)

The inaccuracy of the RTC is not the only source for drift, sometimes the real time is changed intentionally. Adding a leap second to resynchronize the clocks with the true rotation of the Earth. The current day (24 x 60 x 60 seconds) is a bit too short, the Earth's rotation is slowing down by ~1.5 msec every century and is in general irregular due to large storms and earth-quakes. The inserted leap second makes up for that. The most recent one was added on June 30th of this year at 23:59:60 UTC. 60 is not a typo :)

之前的操作是在2012年6月30日。臭名昭著的是,the秒的插入使很多Linux服务器崩溃了。 Google通过 Linux的第二个bug来了解更多信息。

The one previous to that was on June 30th, 2012. A bit notorious, the insertion of the leap second crashed a lot of Linux servers. Google "Linux leap second bug" to learn more about it.

通常,GetSystemTimeAdjustment()下面的机械试图避免这种情况,因此立即更改时间从时间服务器获取的值非常危险。软件通常会有一个艰难的假设,即时间稳定增长,反之则不行。就像在倒计时时两次观察同一时间一样。或由于the秒插入而观察到UTC的虚假时间,例如23:59:60。

Which is in general what the machinery underneath GetSystemTimeAdjustment() is trying to avoid, instantly changing the time with the value obtained from the time server is very dangerous. Software often has a hard assumption that time progresses steadily and misbehaves when it doesn't. Like observing the same time twice when the clock is set back. Or observing a fake time like 23:59:60 UTC due to the leap second insertion.

因此,并非如此,时钟每秒更新64次,即时钟滴答中断。或换句话说,刻度之间的1/64 = 0.015625,以纳秒156250为单位* 100单位。如果需要进行时钟调整,那么它不仅会增加156250,还会稍微增加或减少。这样,就可以将时钟与实际时间缓慢地重新同步,并避免软件混乱。

So it doesn't, the clock is updated 64 times per second, at the clock tick interrupt. Or in other words 1 / 64 = 0.015625 between ticks, 156250 in nanoseconds*100 units. If a clock adjustment needs to be made then it doesn't just add 156250 but slightly more or less. Thus slowly resynchronizing the clock to the true time and avoiding upsetting software.

这当然对绘制时钟的软件有不利的副作用。一种明显的方法是使用一秒钟的计时器。但是有时候这不是一秒钟,而是不会进行时间调整。然后,奈奎斯特的采样定理开始起作用,有时计时器滴答声根本不会更新时钟,或者会跳过一秒。值得注意的是,这并非很难保持精确的绘制时钟的唯一原因,计时器通知本身也总是会延迟。软件不能立即执行的副作用。实际上,这更可能是麻烦的根源,时钟调整只是锦上添花,更容易理解。

This of course has an unpleasant side-effect on software that paints a clock. An obvious way to do it is to use a one second timer. But sometimes that is not a second, it won't be when a time adjustment is in progress. Then Nyquist's sampling theorem comes into play, sometimes a timer tick does not update the clock at all or it skips a second. Notable is that this is not the only reason why it is hard to keep a painted clock accurate, the timer notification itself is always delayed as well. A side-effect of software not being able to instantly execute. This is in fact the much more likely source of trouble, the clock adjustment is just icing on the cake that's easier to understand.

尴尬的问题,奈奎斯特先生告诉我们您必须更频繁地采样以消除不良的混叠效果。因此,一种解决方法是将计时器设置为一个较小的时间间隔,例如15或31毫秒,足够短,以使用户不再观察到丢失的更新。

Awkward problem, Mr. Nyquist has taught us that you have to sample more frequently to eliminate undesirable aliasing effects. So a workaround is to just set the timer at a small interval, like 15 or 31 milliseconds, short enough for the user to no longer observe the missing update.

这篇关于在Windows 7中时钟如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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