Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.