We are going to use simple shell commands to adjust the parameters of CPU frequency on a Raspberry PI box:
- Log in to a Raspberry Pi or another nonvirtualized Linux system.
- Switch to the root account:
$ sudo bash
#
- Get the current frequency of all CPU cores available in the system:
# cat /sys/devices/system/cpu/*/cpufreq/scaling_cur_freq
- Get all of the frequencies supported by the CPU:
# cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
- Get the available CPU-frequency governors:
# cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
- Now let's check which frequency governor is currently in use:
# cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
- Adjust the minimum frequency of the CPU to the highest supported:
# echo 1200000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
- Display the current frequencies again to understand the effect:
# cat /sys/devices/system/cpu/*/cpufreq/scaling_cur_freq
- Adjust the minimum frequency to the lowest supported:
# echo 600000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_fre
- Now let's check how the CPU frequency depends on the governor in use. Select a performance governor and get the current frequency:
# echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
# cat /sys/devices/system/cpu/*/cpufreq/scaling_cur_freq
- Select the powersave governor and observe the result:
# echo powersave > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
# cat /sys/devices/system/cpu/*/cpufreq/scaling_cur_freq
You can use a regular file API to implement the same logic in C++.