组装CPU频率测量算法 [英] Assembly CPU frequency measuring algorithm
问题描述
用于测量处理器频率的常用算法有哪些?
What are the common algorithms being used to measure the processor frequency?
推荐答案
Core Duo 之后的 Intel CPU 支持两个 Model-Specific 寄存器,称为 IA32_MPERF 和 IA32_APERF.
MPERF以CPU支持的最大频率计数,APERF以当前实际频率计数.
Intel CPUs after Core Duo support two Model-Specific registers called IA32_MPERF and IA32_APERF.
MPERF counts at the maximum frequency the CPU supports, while APERF counts at the actual current frequency.
实际频率由下式给出:
您可以通过此流程阅读它们
You can read them with this flow
; read MPERF
mov ecx, 0xe7
rdmsr
mov mperf_var_lo, eax
mov mperf_var_hi, edx
; read APERF
mov ecx, 0xe8
rdmsr
mov aperf_var_lo, eax
mov aperf_var_hi, edx
但注意rdmsr是特权指令,只能在ring 0中运行.
but note that rdmsr is a privileged instruction and can run only in ring 0.
我不知道操作系统是否提供了一个接口来读取这些,虽然它们的主要用途是用于电源管理,所以它可能没有提供这样的接口.
I don't know if the OS provides an interface to read these, though their main usage is for power management, so it might not provide such an interface.
这篇关于组装CPU频率测量算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!