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++?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With