CPU Scaling script

I’m posting this thinking someone might find it useful. At one time I was calling this from cron, setting CPU scaling to performance from 8-5 and setting it to on demand all other times.  I got smarter and now let the kernel take care of itself.

#!/bin/bash

function morepower {
for X in $(grep processor /proc/cpuinfo |awk '{print $3}'); do echo "Processor $X Current: $(cat /sys/devices/system/cpu/cpu$X/cpufreq/scaling_governor)" ; done
if [ "$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor)" = "performance" ]; then
echo "At max power"
else
for X in $(grep processor /proc/cpuinfo |awk '{print $3}'); do
printf "Setting Processor $X to "
sudo echo "performance" |sudo tee -a /sys/devices/system/cpu/cpu$X/cpufreq/scaling_governor
done
fi
}

function lesspower {
for X in $(grep processor /proc/cpuinfo |awk '{print $3}'); do echo "Processor $X Current: $(cat /sys/devices/system/cpu/cpu$X/cpufreq/scaling_governor)" ; done
if [ "$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor)" = "ondemand" ]; then
echo "At ondemand"
else
for X in $(grep processor /proc/cpuinfo |awk '{print $3}'); do
printf "Setting Processor $X to "
sudo echo "ondemand" |sudo tee -a /sys/devices/system/cpu/cpu$X/cpufreq/scaling_governor
done
fi
}

usage () {
echo "Usage: $0 lesspower|morepower"
exit 1
}

 

[ ! "$1" ] && usage
[ ! $# = 1 ] && usage

 

case "$1" in

less|lesspower)
lesspower
;;
more|morepower)
morepower
;;
*)
usage
esac

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*