How to do it...

We are going to use simple shell commands to adjust the parameters of CPU frequency on a Raspberry PI box: 

  1. Log in to a Raspberry Pi or another nonvirtualized Linux system.
  2. Switch to the root account:
$ sudo bash
#
  1. Get the current frequency of all CPU cores available in the system:
# cat /sys/devices/system/cpu/*/cpufreq/scaling_cur_freq
  1. Get all of the frequencies supported by the CPU:
# cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
  1. Get the available CPU-frequency governors:
# cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors

  1. Now let's check which frequency governor is currently in use:
# cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor 
  1. Adjust the minimum frequency of the CPU to the highest supported:
# echo 1200000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
  1. Display the current frequencies again to understand the effect:
# cat /sys/devices/system/cpu/*/cpufreq/scaling_cur_freq
  1. Adjust the minimum frequency to the lowest supported:
# echo 600000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_fre
  1. 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
  1. 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++.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.36.30