Skip to content

Instantly share code, notes, and snippets.

@librehat
Created February 10, 2015 23:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save librehat/4a3dee3a090fe4df0523 to your computer and use it in GitHub Desktop.
Save librehat/4a3dee3a090fe4df0523 to your computer and use it in GitHub Desktop.
A script for setting CPU frequency that I mainly use for my odroid-u3
#!/bin/bash
# change cpu frequency
max_cap=`cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq`
min_cap=`cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq`
# lowest ~ 1.71GHz by default
max_freq=1710000
min_freq=$min_cap
# or you can specify by arguments
while getopts ":a::i:" opt; do
case $opt in
a)
max_freq=$OPTARG
;;
i)
min_freq=$OPTARG
;;
\?)
echo "Invalid option -$OPTARG"
echo "Usage: ./setcpu.sh [OPTIONS]"
echo "Options:"
echo -e " -a:\tSpecify maximum CPU frequency"
echo -e " -i:\tSpecify minimum CPU frequency"
exit 1
;;
esac
done
if [ $max_freq -gt $max_cap ]; then
echo "ERROR: Maximum CPU frequency $max_freq is higher than the highest value you can set: $max_cap"
exit 2
fi
if [ $min_freq -lt $min_cap ]; then
echo "ERROR: Minimum CPU frequency $min_freq is lower than the lowest value you can set: $min_cap"
exit 2
fi
if [ $max_freq -gt 1710000 ]; then
echo "WARNING: Maximum CPU frequency $max_freq is a bit too high"
fi
# set one core affects cpu 0, 1, 2, 3 simultaneously
su -c "echo $max_freq > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq"
su -c "echo $min_freq > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq"
echo "Maximum CPU frequency is set to `cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq`"
echo "Minimum CPU frequency is set to `cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq`"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment