如何检测如果RDTSC返回一个恒定的速率计数器值?速率、计数器、RDTSC

由网友(只是偶尔想起你)分享简介:这似乎从AMD和英特尔执行RDTSC作为一个恒定的速率计数器大多数较新的CPU,避免了因频率的问题,改变为像TurboBoost或省电设置的结果。It seems most newer CPUs from both AMD and Intel implement rdtsc as a constant rate co...

这似乎从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.

阅读全文

相关推荐

最新文章