Skip to content

Instantly share code, notes, and snippets.

@rowan-m
Created November 10, 2017 15:27
Show Gist options
  • Save rowan-m/67b8d7c14208a9f35fb71003c5ac5860 to your computer and use it in GitHub Desktop.
Save rowan-m/67b8d7c14208a9f35fb71003c5ac5860 to your computer and use it in GitHub Desktop.
Toggle CPU power governor
#!/bin/bash
CURRENT_GOVERNOR=`cpufreq-info -p | grep -oE '[^ ]+$'`;
NEW_GOVERNOR='performance';
echo "Current governor: $CURRENT_GOVERNOR";
if [ "$CURRENT_GOVERNOR" == "performance" ]; then
NEW_GOVERNOR="powersave";
fi
read -r -p "Set governor to '$NEW_GOVERNOR'? [Y/n]" response
response=${response,,} # tolower
if [[ $response =~ ^(yes|y| ) ]] || [[ -z $response ]]; then
sudo echo -n "Setting governor to: $NEW_GOVERNOR on CPUs [ ";
MAX_CPU=`cpufreq-info | grep -c analyzing`
CUR_CPU=0
while [ $CUR_CPU -lt $MAX_CPU ]; do
sudo cpufreq-set --cpu $CUR_CPU --related --governor $NEW_GOVERNOR;
echo -n "$CUR_CPU "
let CUR_CPU=CUR_CPU+1;
done
echo ']';
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment