CPU时钟频率和QueryPerformanceCounter错了吗? [英] CPU clock frequency and thus QueryPerformanceCounter wrong?

查看:25
本文介绍了CPU时钟频率和QueryPerformanceCounter错了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 QueryPerformanceCounter 为一些代码计时.当代码开始报告明显错误的时间时,我感到震惊.要将 QPC 的结果转换为实时"时间,您需要除以从 QueryPerformanceFrequency 返回的频率,因此经过的时间为:

I am using QueryPerformanceCounter to time some code. I was shocked when the code starting reporting times that were clearly wrong. To convert the results of QPC into "real" time you need to divide by the frequency returned from QueryPerformanceFrequency, so the elapsed time is:

时间 = (QPC.end - QPC.start)/QPF

Time = (QPC.end - QPC.start)/QPF

重启后,QPF 频率从 2.7 GHz 变为 4.1 GHz.尽管使用 QPC 报告的时间确实发生了变化(下降了 2.7/4.1),但我认为实际硬件频率没有变化,因为运行程序的挂钟时间没有变化.

After a reboot, the QPF frequency changed from 2.7 GHz to 4.1 GHz. I do not think that the actual hardware frequency changed as the wall clock time of the running program did not change although the time reported using QPC did change (it dropped by 2.7/4.1).

MyComputer->属性显示:

MyComputer->Properties shows:

英特尔(R)奔腾(R)4 个 CPU 2.80 GHz;4.11 GHz;1.99 GB 内存;物理地址扩展

Intel(R) Pentium(R) 4 CPU 2.80 GHz; 4.11 GHz; 1.99 GB of RAM; Physical Address Extension

除此之外,系统似乎运行良好.

Other than this, the system seems to be working fine.

我将尝试重新启动以查看问题是否解决,但我担心这些关键性能计数器可能会在没有警告的情况下无效.

I will try a reboot to see if the problem clears, but I am concerned that these critical performance counters could become invalid without warning.

更新:

虽然我很欣赏答案,尤其是链接,但我没有受影响的芯片组之一,也没有自己变化的 CPU 时钟.从我读到的内容来看,QPC 和 QPF 基于 PCI 总线中的计时器,不受 CPU 时钟变化的影响.在我的情况下,奇怪的是 QPF 报告的 FREQUENCY 更改为不正确的值,并且此更改的频率也在 MyComputer -> Properties 中报告,我当然没有写.

While I appreciate the answers and especially the links, I do not have one of the affected chipsets nor to I have a CPU clock that varies itself. From what I have read, QPC and QPF are based on a timer in the PCI bus and not affected by changes in the CPU clock. The strange thing in my situation is that the FREQUENCY reported by QPF changed to an incorrect value and this changed frequency was also reported in MyComputer -> Properties which I certainly did not write.

重新启动解决了我的问题(QPF 现在报告正确的频率)但我假设如果您计划使用 QPC/QPF,您应该在信任它之前针对另一个计时器对其进行验证.

A reboot fixed my problem (QPF now reports the correct frequency) but I assume that if you are planning on using QPC/QPF you should validate it against another timer before trusting it.

推荐答案

显然存在一个已知的问题 在某些芯片组上带有 QPC,因此您可能需要确保没有这些芯片组.此外,一些双核 AMD 也可能导致问题.参见 sebbbi 的第二篇文章,他指出:

Apparently there is a known issue with QPC on some chipsets, so you may want to make sure you do not have those chipset. Additionally some dual core AMDs may also cause a problem. See the second post by sebbbi, where he states:

QueryPerformanceCounter() 和QueryPerformanceFrequency() 提供了一个更好的分辨率,但有不同的问题.例如在Windows XP,所有 AMD Athlon X2 dual核心 CPU 返回其中任何一个的 PC核心随机"(PC有时向后跳一点),除非你专门安装AMD双核驱动包来解决问题.我们没有注意到任何其他双核 CPU有类似的问题(p4 dual、p4 ht、core2 dual、core2 quad、phenom quad).

QueryPerformanceCounter() and QueryPerformanceFrequency() offer a bit better resolution, but have different issues. For example in Windows XP, all AMD Athlon X2 dual core CPUs return the PC of either of the cores "randomly" (the PC sometimes jumps a bit backwards), unless you specially install AMD dual core driver package to fix the issue. We haven't noticed any other dual+ core CPUs having similar issues (p4 dual, p4 ht, core2 dual, core2 quad, phenom quad).

从此答案.

这篇关于CPU时钟频率和QueryPerformanceCounter错了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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