If the CPU supports CPUID and RTDSC, try this:
uint32 GetCpuSpeed(){ int timeStart = 0; int timeStop = 0; unsigned long StartTicks = 0; unsigned long EndTicks = 0; unsigned long TotalTicks = 0; unsigned long cpuSpeed = 0; timeStart = timeGetTime(); // Get tick edge for( ; ; ) { timeStop = timeGetTime(); if ( (timeStop-timeStart) > 1 ) // rollover past 1 { __asm{ xor eax, eax xor ebx, ebx xor ecx, ecx xor edx, edx _emit 0x0f // CPUID _emit 0xa2 _emit 0x0f // RTDSC _emit 0x31 mov [StartTicks], eax // Tick counter starts here } break; } } timeStart = timeStop; for( ; ; ) { timeStop = timeGetTime(); if ( (timeStop-timeStart) > 1000 ) // one second { __asm{ xor eax, eax xor ebx, ebx xor ecx, ecx xor edx, edx _emit 0x0f // CPUID _emit 0xa2 _emit 0x0f // RDTSC _emit 0x31 mov [EndTicks], eax } break; } } TotalTicks = EndTicks-StartTicks; // total cpuSpeed = TotalTicks/1000000; // speed return((uint32)cpuSpeed);}
Edited by - blazter on July 28, 2000 11:15:02 PM
Edited by - Blazter on July 28, 2000 11:17:19 PM