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

查看:18
本文介绍了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 Counter/Timers - 已经存在的标准计数器/定时器芯片自 PC 诞生以来的主板上(现在是芯片组内的一个功能块).这是 IRQ0 的传统来源,即在大多数旧操作系统中进行任务切换的定时器中断.

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.现代操作系统将使用它作为它们的任务调度中断(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天全站免登陆