[sldev] Linux cpu frequency
Dzonatas
dzonatas at dzonux.net
Sat Jun 2 19:34:22 PDT 2007
I just tested a little tidbit, and I was surprised it was accurate even
on a virtualized Linux.
in CProcessor::GetCPUFrequency()
struct timeval tv_start, tv_end;
U64 start, end;
F64 secs_start, secs_end;
gettimeofday(&tv_start, NULL);
start = get_cpu_clock_count();
usleep(uiMeasureMSecs);
gettimeofday(&tv_end, NULL);
end = get_cpu_clock_count();
secs_start = (F64)tv_start.tv_usec / 1000000.0f +
(F64)tv_start.tv_sec;
secs_end = (F64)tv_end.tv_usec / 1000000.0f + (F64)tv_end.tv_sec;
return ( uqwFrequency = (F64)(end - start) / (secs_end - secs_start)
/ 1000000 );
That'll work for a default method for any x86 Unix that supports
usleep() and an accurate gettimeofday().
Now to test /proc and /sys before this is used...
--
More information about the SLDev
mailing list