shell script to undervolt AMD Ryzen laptops
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
amd_laptop_undervolt/powersave.sh

54 lines
1.1 KiB

#!/bin/sh
7 months ago
GOVERNOR="powersave"
apply_lm=true
while getopts 'hopPg:' opt; do
7 months ago
case $opt in
7 months ago
'h')
echo "Usage: powersave [-hopP] [-g governor]"
echo " -h this message"
echo " -o set governor to ondemand and activate laptop mode"
echo " -p set governor to powersave and activate laptop mode (default)"
echo " -P set governor to performance"
echo " -g governor set governor to the specified value"
exit 0
;;
'o')
GOVERNOR=ondemand
apply_lm=true
;;
'p')
GOVERNOR=powersave
apply_lm=true
;;
'P')
GOVERNOR=performance
apply_lm=false
;;
'g')
GOVERNOR=$OPTARG
apply_lm=false
;;
7 months ago
'?'|*) ;;
7 months ago
esac
done
shift $((OPTIND-1))
7 months ago
# set governor
CPUS="$(nproc)"
for c in $(seq 0 $((CPUS-1)))
do
echo $GOVERNOR > /sys/devices/system/cpu/"cpu$c"/cpufreq/scaling_governor
7 months ago
printf '[cpu %d] %s\n' "$c" "$(cat "/sys/devices/system/cpu/cpu$c/cpufreq/scaling_governor")"
7 months ago
done
7 months ago
if $apply_lm; then
# "5 is a sensible time" https://www.kernel.org/doc/Documentation/laptops/laptop-mode.txt
sysctl 'vm.laptop_mode=5'
else
# disable laptop_mode
sysctl 'vm.laptop_mode=0'
fi