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

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

问题描述

似乎来自 AMD 和 Intel 的大多数较新的 CPU 都将 rdtsc 实现为恒定速率计数器,从而避免了由于 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-State、C-State 和停止授权转换(例如 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天全站免登陆