如何检测如果RDTSC返回一个恒定的速率计数器值? [英] How to detect if RDTSC returns a constant rate counter value?

查看:165
本文介绍了如何检测如果RDTSC返回一个恒定的速率计数器值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎从AMD和英特尔执行RDTSC作为一个恒定的速率计数器大多数较新的CPU,避免了因频率的问题,改变为像TurboBoost或省电设置的结果。

It seems most newer CPUs from both AMD and Intel implement rdtsc as a constant rate counter, avoiding the issues caused by frequency changing as a result of things like TurboBoost or power saving settings.

由于RDTSC是很多更适合比QueryPerformanceCounter的性能测试,由于其低得多的开销,我想用它只要有可能。

As rdtsc is a lot more suitable for performance measurements than QueryPerformanceCounter because of its much lower overhead, I would like to use it whenever possible.

我如何可以检测可靠,如果RDTSC是一个恒定的速率计数器与否?

How can I detect reliably if the rdtsc is a constant rate counter or not?

推荐答案

您可以使用 CPUID 来告诉你。从的文档的CPUID Fn8000_0007_EDX位8:

You can use CPUID to tell you. From the docs on CPUID Fn8000_0007_EDX bit 8:

TscInvariant:TSC不变。该TSC率被确保为所有P状态,C状态不变,并停止资助过渡(如STPCLK节流);因此将TSC是适合使用作为时间的来源。 0 =没有这样的保证是由软件和应避免试图使用TSC作为时间的源

TscInvariant: TSC invariant. The TSC rate is ensured to be invariant across all P-States, C-States, and stop grant transitions (such as STPCLK Throttling); therefore the TSC is suitable for use as a source of time. 0 = No such guarantee is made and software should avoid attempting to use the TSC as a source of time.

这篇关于如何检测如果RDTSC返回一个恒定的速率计数器值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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