RE: [GD-Windows] Get exact CPU frequency
Brought to you by:
vexxed72
From: Daniel V. <vo...@ep...> - 2002-07-15 20:23:49
|
In theory you should use QueryPerformanceCounter and Frequency but the following has worked fine for us so far: // CPU speed. guard(CheckCpuSpeed); FLOAT CpuSpeed; try { timeBeginPeriod( 1 ); GSecondsPerCycle = 1.f; for( INT i=0; i<3; i++ ) { LARGE_INTEGER StartCycles, EndCycles; volatile DOUBLE DoubleDummy = 0.0; volatile INT IntDummy = 0; __asm { rdtsc mov StartCycles.HighPart, edx mov StartCycles.LowPart, eax } DWORD StartMsec = timeGetTime(), EndMsec = StartMsec; while( EndMsec-StartMsec < 200 ) { DoubleDummy += appSqrt(DoubleDummy) + 3.14; IntDummy *= ((INT) (DoubleDummy) + 555) / 13; EndMsec = timeGetTime(); } __asm { rdtsc mov EndCycles.HighPart, edx mov EndCycles.LowPart, eax } DOUBLE C1 = (DOUBLE)(SQWORD)(((QWORD)StartCycles.LowPart) + ((QWORD)StartCycles.HighPart<<32)), C2 = (DOUBLE)(SQWORD)(((QWORD)EndCycles.LowPart) + ((QWORD)EndCycles.HighPart<<32)); GSecondsPerCycle = Min( GSecondsPerCycle, 1.0 / (1000.f * ( C2 - C1 ) / (EndMsec - StartMsec)) ); } timeEndPeriod( 1 ); debugf( NAME_Init, TEXT("CPU Speed=%f MHz"), 0.000001 / GSecondsPerCycle ); appStrcat( GMachineCPU, *FString::Printf(TEXT(" @ %d MHz"), appRound(0.000001 / GSecondsPerCycle) ) ); // gam } catch( ... ) { debugf( NAME_Init, TEXT("Timestamp not supported (Possibly 486 or Cyrix processor)") ); appStrcat( GMachineCPU, TEXT(" Unknown clock") ); // gam GSecondsPerCycle = 1; } -- Daniel, Epic Games Inc. > -----Original Message----- > From: gam...@li... > [mailto:gam...@li...]On > Behalf Of Andrew Grant > Sent: Monday, July 15, 2002 3:13 PM > To: Gam...@li... > Subject: RE: [GD-Windows] Get exact CPU frequency > > > a) I think the method you are using is only supported on some > OSs. A better > approach is to use RDTSC before and then after a known time period has > elapsed, taking measures for slight variations and errors. Try searching > Intels developers site. > > b) GetTickCount can be rather inaccurate, use > QueryPerformanceCounter/Frequency > > Andrew Grant- > Climax Brighton > > > > > -----Original Message----- > > From: Grisha Spivak [mailto:_g...@tu...] > > Sent: 15 July 2002 12:52 > > To: Gam...@li... > > Subject: [GD-Windows] Get exact CPU frequency > > > > > > How can I get exact CPU frequency? I need it for timer which > > uses RDTSC > > instruction. Currently I read '~MHz' value from > > HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcesso > > r\0, but it > > not exact - after 2 min running difference between my timer > > and GetTickCount > > is 15 ms. > > > > > > > > > > ------------------------------------------------------- > > This sf.net email is sponsored by:ThinkGeek > > Welcome to geek heaven. > > http://thinkgeek.com/sf > > _______________________________________________ > > Gamedevlists-windows mailing list > > Gam...@li... > > https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows > > Archives: > > http://sourceforge.net/mailarchive/forum.php?forum_id=555 > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Gamedevlists-windows mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_id=555 > |