Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Linux get CPU nominal frequency

I need to get a CPU nominal frequency under Linux within C++ code. As far as I know, the /proc/cpuinfo contains a current frequency.

Is /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq

always reliable as nominal frequency in kHz?

Or is there a better way to get this information from C++?

like image 821
Dejwi Avatar asked Oct 30 '22 13:10

Dejwi


1 Answers

C++ doesn't have any means to access this value, it doesn't even assume there is such a value. Even in your case, you are just looking at one of the CPUs, not all of them. This means that you will have to do something OS-dependent, which you can probably build in C++.

Anyhow, do you know of any tool providing that number? Get its sourcecode and see how it does it! Other than that, I'd look at /proc/cpuinfo and build the average of the "cpu MHz" values there. The /proc filesystem is basically a predecessor of the /sys filesystem, but the info should be the same.

like image 118
Ulrich Eckhardt Avatar answered Nov 02 '22 09:11

Ulrich Eckhardt