Wednesday, February 15, 2017

Read, Modify CPU frequency & Governors in Linux from command Line

Hi Folks welcome to my blog..

I have a short post in changing CPU frequency & governors from command line on a Linux machine. I am using BeagleBoneBlack booted to shell with minimal file-system generated from build-root with Kernel version 3.8.13.

I am at shell prompt as a sudo user.

Reading CPU information: We get the CPU information reading the cpuinfo file in proc file-system.

# cat /proc/cpuinfo



Reading CPU frequency & governors:

Change directory to  /sys/bus/cpu/devices/cpu0/cpufreq

# cd /sys/bus/cpu/devices/cpu0/cpufreq
# ls




To get the available CPU frequencies for  scaling read the below file.
# cat scaling_available_frequencies



To get the current CPU frequency, read the below file.
# cat cpuinfo_cur_freq



CPU is currently running at 1GHz

To read the current CPU governor, read the below file
# cat scaling_available_governors





similarly to read the current CPU governor read the below file
# cat scaling_governor



Changing CPU frequency

In order to change the CPU frequency, we have to change the CPU governor to userspace. This allows to run the CPU at user specified frequencies.

In case of ondemand governor we can set the scaling_max_freq & scaling_min_freq, but we cannot set a specific frequency from the available list of CPU frequencies.

For more details read the following link: https://wiki.archlinux.org/index.php/CPU_frequency_scaling

# echo userspace > scaling_governor
# echo  600000 > scaling_setspeed

#cat cpuinfo_cur_freq





Changing CPU frequency to 600MHz, we can set only values available under scaling_available_frequencies



Now you change the CPU governor to ondemand and try to modify the scaling_max_freq & scaling_min_freq  frequencies and observe the effect when you try to change the CPU current frequency.

Thanks for your time. Please feel free to post your comments.




5 comments: