Description
System properties dialog shows hardcoded CPU frequency equal to 1.00 GHz.
The algorithm found on one of the forums. It works well in Windows (tested on different computers), but in ROS, its readings are somewhat overestimated. Perhaps there are errors in ROS, because of which the result differs from the result in Windows. As if there were no, based on it, you can calculate the actual frequency of the processor and use its value for the needs of the system. Test programm attached.
function GetCPUSpeed: Double; |
const DelayTime = 500; |
var
|
TimerHi : DWORD;
|
TimerLo : DWORD;
|
PriorityClass : Integer; |
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 // rdtsc |
MOV TimerLo, EAX
|
MOV TimerHi, EDX
|
end; |
Sleep(DelayTime);
|
asm |
DW 310Fh // rdtsc |
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; |