How to caluate cpu cycles as that of QueryPerformanceCounter
I have the following code in win32 to calculate cpu cycles using QueryPerformanceCounter()
LARGE_INTEGER ltime; <br>
UINT32 cycles; <br>
QueryPerformanceCounter(<ime);<br>
cycles = (UINT32) ((ltime.QuadPart >> 8) & 0xFFF开发者_如何学PythonFFFF);
How do I implement the same on ARM cortex A9 (panda board) running Ubuntu (OMAP4) ????
Your best bet would probably be to use clock_gettime
with either CLOCK_PROCESS_CPUTIME_ID
or CLOCK_THREAD_CPUTIME_ID
. (see clock_gettime)
That will give you "High-resolution per-process timer from the CPU" and "Thread-specific CPU-time clock", respectively.
Alternatively, one could sum up values returned by times
, but I guess that would be less precise as it also depends on the scheduler, whereas the above supposedly reads a performance counter from the CPU if possible.
精彩评论