现代 PC 的内部时钟有多精确?

发布于 2024-08-28 02:36:11 字数 178 浏览 7 评论 0原文

我知道 10 年前,典型的时钟精度等于系统时钟周期,范围为 10-30 毫秒。在过去的几年里,精度得到了多个步骤的提高。如今,有多种方法可以测量纳秒级的时间间隔。然而,通常的框架返回的时间精度仍然只有 15ms 左右。

哪些步骤会降低精度?怎么可能以纳秒为单位进行测量?为什么我们的精度仍然经常低于微秒(例如在 .NET 中)?

I know that 10 years ago, typical clock precision equaled a system-tick, which was in the range of 10-30ms. Over the past years, precision was increased in multiple steps. Nowadays, there are ways to measure time intervals in nanoseconds. However, usual frameworks still return time with a precision of only around 15ms.

Which steps decrease the precision? How is it possible to measure in nanoseconds? Why are we still often getting worse-than-microsecond precision, for instance in .NET?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

审判长 2024-09-04 02:36:11

这确实是个人电脑历史上的一个特征。
最初的 IBM-PC 使用一种称为实时时钟的芯片,该芯片由电池供电(您还记得需要更换这些电池吗?)这些芯片在机器关闭时运行并保持时间。它们的频率为 32.768 kHz(2^15 周期/秒),这使得在 16 位系统上计算时间变得很容易。
然后将该实时时钟写入 CMOS,在旧操作系统中可通过中断系统使用该时钟。

Microsoft 和 Intel 推出了一项名为“高精度事件计时器”的新标准,指定时钟速度为 10MHz
http://www.intel.com/hardwaredesign/hpetspec_1.pdf
甚至较新的 PC 架构也采用了这一点并将其置于北桥控制器上,并且 HPET 可以调谐到 100MHz 甚至更高。
在 10Mhz 下,我们应该能够获得 100 纳秒的分辨率,在 100MHZ 下,我们应该能够获得 10 纳秒的分辨率。

已知以下操作系统无法使用 HPET:Windows XP、Windows Server 2003 以及更早的 Windows 版本、较早的 Linux 版本

已知以下操作系统能够使用 HPET:Windows Vista、Windows 2008、Windows 7 、基于 x86 版本的 Mac OS X、使用 2.6 内核的 Linux 操作系统和 FreeBSD。

对于 Linux 内核,您需要更新的“rtc-cmos”硬件时钟设备驱动程序,而不是原始的“rtc”驱动程序

综上所述,我们如何访问这个额外的分辨率?
我可以从以前的 stackoverflow 文章中剪切和粘贴,但不行 - 只需搜索 HPET,您就会找到有关如何让更精细的计时器工作的答案

It really is a feature of the history of the PC.
The original IBM-PC used a chip called the Real Time Clock which was battery backed up (Do you remember needing to change the batteries on these ?) These operated when the machine was powered off and kept the time. The frequency of these was 32.768 kHz (2^15 cycles/second) which made it easy to calculate time on a 16 bit system.
This real time clock was then written to CMOS which was available via an interrupt system in older operating systems.

A newer standard is out from Microsoft and Intel called High Precision Event Timer which specifies a clock speed of 10MHz
http://www.intel.com/hardwaredesign/hpetspec_1.pdf
Even newer PC architectures take this and put it on the Northbridge controller and the HPET can tun at 100MHz or even greater.
At 10Mhz we should be able to get a resolution of 100 nano-seconds and at 100MHZ we should be able to get 10 nano-second resolution.

The following operating systems are known not to be able to use HPET: Windows XP, Windows Server 2003, and earlier Windows versions, older Linux versions

The following operating systems are known to be able to use HPET: Windows Vista, Windows 2008, Windows 7, x86 based versions of Mac OS X, Linux operating systems using the 2.6 kernel and FreeBSD.

With a Linux kernel, you need the newer "rtc-cmos" hardware clock device driver rather than the original "rtc" driver

All that said how do we access this extra resolution?
I could cut and paste from previous stackoverflow articles, but not - Just search for HPET and you will find the answers on how to get finer timers working

楠木可依 2024-09-04 02:36:11

我今天在 MSDN 上读到了一篇关于此问题的博客文章, 在这里阅读,它很好地涵盖了该主题。它强调 C# 的 DateTime,但它是普遍适用的。

I literally read a blog post on MSDN about this today, read it here, it covers the topic pretty well. It has an emphasis on C#'s DateTime but it's universally applicable.

初见你 2024-09-04 02:36:11

嗯,到目前为止,我还没有看到任何 PC 能够将准确(实时)时间保持在 100 毫秒/天以上。在过去 40 年左右的时间里,我所有的 PC 中的实时时间总是要么快要么慢,并且每天可能会漂移 2 或 3 秒。其主要原因是驱动时钟电路的 PC 晶体振荡器(无论频率如何)的精度。在普通计算机中,这些振荡器从未校准到其标称频率,甚至没有对由于 PC 外壳内温度变化而导致的频率漂移进行基本补偿。

Well, so far I haven't seen any PC, which would keep accurate (real) time to better than say 100 ms/day. In all my PCs in the past 40 years or so the real time is always either fast or slow and can drift as much as 2 or 3 seconds/day. The main reason for this is the accuracy of the PCs crystal oscillator (regardless of frequency), which is driving the clock circuitry. In run-in-the-mill computers those oscillators are NEVER calibrated to their nominal frequency and there is not even rudimentary compensation for frequency drift because of changing temperatures within the PC enclosure.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文