Reading the nominal CPU frequency on Linux

Reading the nominal CPU frequency on Linux

Hi everyone, 

I'm trying to find out the ways in which it is possible to read the current frequency at which the CPU is operating in order to be able to make more sense of the results of RDTSC. 

It seems that on Linux the preferred way to read this value is to read from /dev/cpu/CPUID/msr, as the Intel PCM library does. However, where those file are read-protected, I find myself at a dead-end, since the RDMSR instruction must be run at privilege level 0. Is it really the best I can do to grep the Processor Brand String from CPUID.0x80000002-04 for its "GHz" portion (not that I imagine that reflects the current frequency)? Is there any other way to find out the current CPU frequency? 

Regards

Michael

4 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.

If the CPU has been kept up to speed for a fraction of a second, the CPU MHz field in /proc/cpuinfo shows you the base clock speed (not reflecting turbo mode) more accurately than the model name string. Under similar conditions, the ratio of rdtsc ticks to elapsed time should agree.

Thanks very much for your reply, Tim, much appreciated.

Regards

Michael

Michael,
You should note that the newer Intel processors have a fixed-frequency TSC, which increments at the base core frequency independent of the actual core frequency. On a linux system run "cat /proc/cpuinfo" and look in the "flags" field for "constant_tsc" to see if your processor has this property.
If you have performance monitor access, most Intel processors have counters for both the "reference" clock and the actual number of CPU (core) cycles. On Nehalem/Westmere and Sandy Bridge processors, for example, performance counter event 3C, mask 00 counts the actual number of unhalted core cycles, while event 3C, mask 01 counts the number of reference cycles (at 133 MHz for Nehalem/Westmere and 100 MHz for Sandy Bridge) while not halted. This does not give the instantaneous frequency, but it does provide the average frequency over the (unhalted portion of the) measurement interval.

John D. McCalpin, PhD
"Dr. Bandwidth"

Kommentar hinterlassen

Bitte anmelden, um einen Kommentar hinzuzufügen. Sie sind noch nicht Mitglied? Jetzt teilnehmen