使用HPET时QueryPerformanceFrequency是否准确? [英] Is QueryPerformanceFrequency accurate when using HPET?

查看:154
本文介绍了使用HPET时QueryPerformanceFrequency是否准确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在玩QueryPerformanceFrequency. 它曾经返回3.6 Mhz,但是对于我想做的事情还不够.

我已使用此命令bcdedit /set useplatformclock true启用了HPET.现在,它返回14.3 Mhz.太好了,更精确了……除了不是.我很快意识到我没有得到我期望的粒度.

如果我尝试轮询QueryPerformanceCounter直到它打勾,我可以得到的最小增量是11,这表示1.27Mhz.如果我尝试计算我在一秒钟内可以从QueryPerformanceCounter获得的不同值的数量,我就会得到1.26Mhz.

所以我想知道是否有一种方法可以真正充分利用14.3 Mhz?

我正在使用Windows 7、64位系统和Visual Studio 2008.

解决方案

使用HPET硬件作为QueryPerformanceCounter(QPC)的来源已知会带来较大的开销.

使用HPET配置时,QPC是一个昂贵的通话.

它提供了14.3 MHz的频率,表明具有很高的精度,但是正如您所发现的那样,它的调用速度还不足以真正解决该频率.

因此,只要硬件有能力,Microsoft就会将CPU时间戳计数器(TSC)用作QPC的源. TSC查询的开销要低得多.用于QPC的相关频率通常是CPU频率除以1024.通常也只有几个MHz.

在TSC模式下QPC的呼叫是如此之快,以至于许多连续的呼叫可能显示相同的结果(通常大约20-30个呼叫或15-20 ns/呼叫). 这样,您可以获得典型的分辨率. 0.3 us(在3.4 GHz CPU上).

在切换到HPET之前,您观察到3.6 MHz.这可能是系统ACPI PM计时器(3579545 Hz)的标志,它表明您在切换到HPET之前未在基于TSC的QPC上进行操作.

因此,无论哪种方式,运行HPET或ACPI PM计时器都会导致几MHz范围内的可用分辨率.由于对QPC的调用过于昂贵,因此两者都无法提供性能计数器频率(PCF)给出的完整分辨率.只有基于TSC的QPC足够快,并且能够对QPC进行超采样.

Microsoft最近刚刚发布了有关此问题的更多详细信息:

请参见获得高解析时间戳记(MSDN 2014).

这是一篇全面的文章,其中包含许多示例和详细说明.对于QPC的用户必须阅读.

...一种真正充分利用14.3 Mhz的方法?

不幸的是.

您可以从Windows Sysinternals运行Coreinfo.exe实用程序. Sysinternals已迁移到Microsoft technet.这是链接: Sysinternals系统信息实用程序.这将为您提供以下问题的答案:如何检查我的系统是否具有不变的TSC?

摘要:QPC基于TSC获得了最佳的分辨率/精度/粒度.

BTW::正确选择硬件作为QPC的资源还会影响新 解决方案

Using the HPET hardware as a source for QueryPerformanceCounter (QPC) is known to be assosiated with large overheads.

QPC is an expensive call when configured with HPET.

It provides 14.3 MHz which suggests high accuracy but as you found, it can't be called fast enough to actually resolve that frequency.

Therefore Microsoft has turned into the CPUs time stamp counter (TSC) as a source for QPC whenever the hardware is capable doing so. TSC queries have much lower overhead. The associated frequency used for QPC is typically the CPU frequency divided by 1024; also typically a few MHz.

The call of QPC in TSC mode is so fast that a lot of consecutive calls may show the same result (typically approx. 20-30 calls or 15 - 20 ns/call). This way you may obtain typical resolutions of approx. 0.3 us (on a 3.4 GHz CPU).

You observed 3.6 MHz before you switched to HPET. That's likely the signiture of the systems ACPI PM timer (3579545 Hz), which indicates that you were not operating on TSC based QPC before switching to HPET.

So either way, running HPET or ACPI PM timer results in a usable resoluion in the range of a few MHz. Both cannot expose the full resolution given by the performance counter frequency (PCF) because the call to QPC is too expensive. Only The TSC based QPC is fast enough and capable to actually oversample the QPC.

Microsoft has just recently released more detailed information about this matter:

See Acquiring high-resolution time stamps (MSDN 2014) for the details.

This is a comprehensive article with lots of examples and detailed description. A must read for users of QPC.

...a way to really use the 14.3 Mhz to their full extent ?

Unfortunately not.

You can run Coreinfo.exe utility from Windows Sysinternals. Sysinternals has moved to Microsoft technet. Here is the link: Sysinternals System Information Utilities. This will give you an answer to the question: How can I check if my system has a non-invariant TSC?

Summary: The best resolution/accuracy/granularty is obtained by QPC based on TSC.

BTW: The proper choice of hardware as resource for QPC also influences the call expense of the new GetSystemTimePreciseAsFileTime function (Windows 8 desktop and upwards) because it internally uses QPC.

这篇关于使用HPET时QueryPerformanceFrequency是否准确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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