C or assembly code to find current cpu core speed

Posted by honestann on Ask Ubuntu See other posts from Ask Ubuntu or by honestann
Published on 2012-12-12T09:19:33Z Indexed on 2012/12/12 11:19 UTC
Read the original article Hit count: 388

Filed under:
|

How can my application efficiently determine the following information peroidically while it executes:

1: current speed of each of the 8 CPU cores.
2: which core the code is currently executing on.

My application is C and assembly-language, so any solution in either C or assembly-language is fine. This code needs to execute quickly, so creating, reading and processing a file generated by "cat /proc/cpuinfo" is much too slow.

The cores slow-down and speed-up automatically, probably to keep CPU temperature under control. Therefore, a one-time measure is not sufficient for my purposes.

My application already reads and subtracts the cpu cycle counter in assembly language to determine number of clock cycles, but my program cannot compute elapsed time in nanoseconds unless it knows the current clock frequency of the cpu cores (and which core the code is executing on). Thanks!

© Ask Ubuntu or respective owner

Related posts about clock

Related posts about multi-core