W
weiliu
Unregistered / Unconfirmed
GUEST, unregistred user!
大家都知道,CPU主频可以通过下列方式获取:
function CPUSpeed: Double;
const
DelayTime = 500;
var
TimerHi, TimerLo: DWORD;
PriorityClass, Priority: Integer;
begin
PriorityClass := GetPriorityClass(GetCurrentProcess);
Priority := GetThreadPriority(GetCurrentThread);
SetPriorityClass(GetCurrentProcess, REALTIME_PRIORITY_CLASS);
SetThreadPriority(GetCurrentThread, THREAD_PRIORITY_TIME_CRITICAL);
Sleep(10);
asm
dw 310Fh
mov TimerLo, eax
mov TimerHi, edx
end;
Sleep(DelayTime);
asm
dw 310Fh
sub eax, TimerLo
sbb edx, TimerHi
mov TimerLo, eax
mov TimerHi, edx
end;
SetThreadPriority(GetCurrentThread, Priority);
SetPriorityClass(GetCurrentProcess, PriorityClass);
Result := TimerLo / (1000.0 * DelayTime);
end;
现在问题是这样的,这样的获取方式,一般台式机的CPU问题不大,但在笔记本机器上,比如PM/CM/及AMD的移动处理器上就经常不准,还有,新鲜出炉的扣肉处理器也有时会测不准,但是同样新版的CPU-Z就能拿到准确的频率,大家从实际编程的角度出发看看如何能正确拿到CPU的主频。我想通过获得CPU目前的外频和倍频再来得出的话可能会准确点,但具体怎么做,大家谁有经验的?
function CPUSpeed: Double;
const
DelayTime = 500;
var
TimerHi, TimerLo: DWORD;
PriorityClass, Priority: Integer;
begin
PriorityClass := GetPriorityClass(GetCurrentProcess);
Priority := GetThreadPriority(GetCurrentThread);
SetPriorityClass(GetCurrentProcess, REALTIME_PRIORITY_CLASS);
SetThreadPriority(GetCurrentThread, THREAD_PRIORITY_TIME_CRITICAL);
Sleep(10);
asm
dw 310Fh
mov TimerLo, eax
mov TimerHi, edx
end;
Sleep(DelayTime);
asm
dw 310Fh
sub eax, TimerLo
sbb edx, TimerHi
mov TimerLo, eax
mov TimerHi, edx
end;
SetThreadPriority(GetCurrentThread, Priority);
SetPriorityClass(GetCurrentProcess, PriorityClass);
Result := TimerLo / (1000.0 * DelayTime);
end;
现在问题是这样的,这样的获取方式,一般台式机的CPU问题不大,但在笔记本机器上,比如PM/CM/及AMD的移动处理器上就经常不准,还有,新鲜出炉的扣肉处理器也有时会测不准,但是同样新版的CPU-Z就能拿到准确的频率,大家从实际编程的角度出发看看如何能正确拿到CPU的主频。我想通过获得CPU目前的外频和倍频再来得出的话可能会准确点,但具体怎么做,大家谁有经验的?