x86处理器中的时间源 [英] Time sources in x86 processors

查看:115
本文介绍了x86处理器中的时间源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道可以用来测量时间的x86指令吗?
是否可以通过软件访问导致任务切换的计时器?

Does anybody know x86 instructions that can be used to measure time? Is the timer that leads to task switches accessible by software?

推荐答案

如何在x86平台上测量时间:

Ways to measure time on an x86 platform:


  • 实时时钟-操作系统的时间和日期来源。 1秒精度。标准PC中唯一可用来测量绝对时间的时间源。

  • Real Time Clock - The source of time and date for your OS. 1 second precision. The only time source in a standard PC that can be used to measure absolute time.

8254计数器/计时器-自PC诞生以来,主板上一直存在的标准计数器/计时器芯片(现在是芯片组内部的功能块)。这是IRQ0的传统来源,它是在大多数较旧的OS中执行任务切换的计时器中断。

8254 Counter/Timers - A standard counter/timer chip that has been present on motherboards since the dawn of PC (now a functional block inside the chipset). This is the traditional source of IRQ0, the timer interrupt that does task switching in most older OSes.

RDTSC汇编指令-计算CPU时钟周期。有关某些用法的详细信息,请参见Anon ymous发布的答案。您可以在x86上找到时间源的最高精确度。但是,它有些准确性。

RDTSC assembly instruction - Counts CPU clock cycles. See the answer Anon ymous posted for some usage details. Pretty much the highest level of precision you can find for a time source on x86. However, it has some gotchas with accuracy. Also the most convenient option if you are writing in assembly.

RDTSCP汇编指令-与RDTSC类似,但已序列化,这解决了一些精度问题,有关汇编语言,这也是最方便的选择。 RDTSC。仅在最新的处理器上找到。

RDTSCP assembly instruction - Similar to RDTSC, but is serialized, which resolves some of the accuracy issues with RDTSC. Only found on the newest processors.

HPET -引入围绕PC的Core Duo时代。旨在替代古老的8254。现代OS会将其用作任务调度中断(Vista和更高版本)

HPET - Introduced around the Core Duo era of PCs. Intended to be a replacement for the venerable 8254. Modern OSes will use this as their task scheduling interrupt (Vista and later)

芯片组中的专有计时器-一些芯片组内置有用于电源管理和多媒体功能的特殊计时器。假设您使用的是固定功能的嵌入式系统而不是通用PC,有时您可以为自己的应用程序抢占这些功能。

Proprietary Timers in the Chipset - Some chipsets have special timers built into them for Power Management and Multimedia functions. You can sometimes commandeer these for your own application, assuming you are dealing with a fixed-function embedded system and not a general purpose PC.

请注意,根据您的操作系统和硬件,并非所有这些选项都可用。如果您在现代操作系统(Windows,Linux)上运行,它将根据自己的计时需求来控制8254 / HPET,因此您将无法使用它们。

Note that not all of these options will be available to you depending on your OS and Hardware. If you are running under a modern OS (Windows, Linux), it will take control of the 8254/HPET for its own timing needs, and thus they will be unavailable for you.

在现代操作系统下,通常最好使用操作系统提供的计时功能。操作系统开发人员可能已经解决了很多问题,如果您尝试使用它,您将自己遇到这些问题。 (请注意,操作系统可能提供多种计时功能。选择适合您的应用程序的计时功能。)

Under a modern Operating System, it is usually best to use the OS-provided timing functions. The OS developers have probably worked out a lot of the issues that you will run into on your own if you try to use it. (Note that the OS may provide multiple timing functions. Pick the one that is suitable for your application.)

这篇关于x86处理器中的时间源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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