Cleanup governor.sh script

pull/853/head
Jeffrey Walton 2019-06-05 23:21:00 -04:00
parent 29a30b74b0
commit ed4996f652
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
1 changed files with 10 additions and 10 deletions

View File

@ -4,22 +4,22 @@
# accurate benchmark results. To move from a low energy state to a higher # accurate benchmark results. To move from a low energy state to a higher
# one, run 'governor.sh performance'. To move back to a low power state # one, run 'governor.sh performance'. To move back to a low power state
# run 'governor.sh powersave' or 'governor.sh ondemand' or reboot. The script # run 'governor.sh powersave' or 'governor.sh ondemand' or reboot. The script
# is based on code by Andy Polyakov, http://www.openssl.org/~appro/cryptogams/. # based on code by Andy Polyakov, http://www.openssl.org/~appro/cryptogams/.
# Fixup ancient Bash # Fixup ancient Bash
# https://unix.stackexchange.com/q/468579/56041 # https://unix.stackexchange.com/q/468579/56041
if [[ -z "$BASH_SOURCE" ]]; then if [[ -z "${BASH_SOURCE[0]}" ]]; then
BASH_SOURCE="$0" BASH_SOURCE="$0"
fi fi
if [[ "$EUID" -ne 0 ]]; then if [[ "$EUID" -ne 0 ]]; then
echo "This script must be run as root" echo "This script must be run as root"
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 [[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 1 || return 1
fi fi
if [ "x$1" = "x" ]; then if [ "x$1" = "x" ]; then
echo "usage: $0 on[demand]|pe[rformance]|po[wersave]|us[erspace]?" echo "usage: $0 on[demand]|pe[rformance]|po[wersave]|us[erspace]?"
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 [[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 1 || return 1
fi fi
# "on demand" may result in a "invalid write argument" or similar # "on demand" may result in a "invalid write argument" or similar
@ -34,34 +34,34 @@ case $1 in
esac esac
if [ -z "$governor" ]; then if [ -z "$governor" ]; then
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 [[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 1 || return 1
fi fi
cpus=$(ls /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor 2>/dev/null) cpus=$(ls /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor 2>/dev/null)
if [ -z "$cpus" ]; then if [ -z "$cpus" ]; then
echo "Failed to read CPU system device tree" echo "Failed to read CPU system device tree"
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 [[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 1 || return 1
fi fi
echo "Current CPU governor scaling settings:" echo "Current CPU governor scaling settings:"
count=0 count=0
for cpu in $cpus; do for cpu in $cpus; do
echo " CPU $count:" $(cat "$cpu") echo " CPU $count: $(cat "$cpu")"
((count++)) ((count++))
done done
if [ "x$governor" != "x" ]; then if [ "x$governor" != "x" ]; then
for cpu in $cpus; do for cpu in $cpus; do
echo $governor > $cpu echo "$governor" > "$cpu"
done done
fi fi
echo "New CPU governor scaling settings:" echo "New CPU governor scaling settings:"
count=0 count=0
for cpu in $cpus; do for cpu in $cpus; do
echo " CPU $count:" $(cat "$cpu") echo " CPU $count: $(cat "$cpu")"
((count++)) ((count++))
done done
[[ "$0" = "$BASH_SOURCE" ]] && exit 0 || return 0 [[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 0 || return 0