How it works...

Similar to USB power management, the CPU-frequency management system API is exposed via sysfs. We can read and modify its parameters as regular text files.

We can find all settings related to CPU cores under the /sys/devices/system/cpu/ directory. Configuration parameters are grouped by CPU cores in subdirectories named after each code index, such as cpu1, cpu2, and so on. 

We are interested in several parameters related to CPU frequencies management that live in the cpufreq subdirectory of each core. Let's read the current frequency of all available cores:

# cat /sys/devices/system/cpu/*/cpufreq/scaling_cur_freq

We can see that all cores have the same frequency, 600 MHz (the cpufreq subsystem uses KHz as a measurement unit ...

Get Embedded Programming with Modern C++ Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.