cpufreq-set
Updated CPU frequency scaling script
Submitted by soccerfiend on Mon, 2012-04-23 17:32This is an update to my earlier command line frequency scaling script. This version uses the dialog utility to provide a rudimentary GUI.
- #!/bin/bash
- # Wrapper to easily set the CPU Frequency Governor
- # dialog is a utility installed by default on all major Linux distributions.
- # But it is good to check availability of dialog utility on your Linux box.
- which dialog &> /dev/null
- [ $? -ne 0 ] && echo "Dialog utility is not available, please install it" && exit 1
- # Check that a valid governor is set
- # Creating an array with each of the CPUs numeric ID
- declare -a CPUs=( `cat /proc/cpuinfo |grep processor |cut -f 2 -d \:` )
- # Setting up the dialogue interface:
- dialog --clear --backtitle "Console Based CPU Governor Selection" --title "MAIN MENU" \
- --menu "Use [UP/DOWN] key to move" 18 100 6 \
- "performance" "Set for maximum performance, watch the temp!" \
- "ondemand" "Usually the default, scale speed up as required." \
- "conservative" "Conservatively scale up as required." \
- "powersave" "Maximum power savings or lowest temp." \
- "userspace" "Send control to a userspace application." \
- "EXIT" "TO EXIT" 2> menuchoices.$$
- # This computes the number of elements in the array, we use this to control our loop in the SetSpeed function
- elements="${#CPUs[*]}"
- SetSpeed ()
- {
Setting the CPU Frequency Govenor from the Command Line
Submitted by soccerfiend on Tue, 2011-11-15 10:34Most modern processors support some level of frequency scaling, that is they change the speed or frequency that they are running at in order to reduce energy consumption. You can usually change the frequency with a GUI app but what happens if there is no GUI running (on say a server). The command is called cpufreq-set. You can get details (like processor statistics and current governor in use. Both of these are provided by the cpufrequtils package which you can just apt-get or aptitude install
The problem is that cpufreq-set only sets one core or CPU at a time. On a dual or quad socket this could get quite tedious. Fortunately there is an easy solution.
- for each in `cat /proc/cpuinfo |grep processor |cut -f 2 -d \:` ;do sudo cpufreq-set -c $each -g performance ; done
What I do is run a small little bash script that iterates over all the CPUs and sets the governor to one set as a parameter to the script.
- #!/bin/bash
- # Wrapper to easily set the CPU Frequency Governor
- # Check that a valid governor is set
- GOVERNOR=$1
- USAGE="This script requires a CPU governor as an argument, which should be one of: conservative, ondemand, userspace, powersave, performance
- For example: cpuscale.sh ondemand"
- if [ "$#" = "0" ]; then
- echo "$USAGE"
- exit 1
- fi
- # Creating an array with each of the CPUs numeric ID