amd_laptop_undervolt/powersave.sh

47 lines
965 B
Bash
Raw Normal View History

2023-01-25 16:33:34 +01:00
#!/bin/sh
2023-10-07 12:42:34 +02:00
GOVERNOR="powersave"
apply_lm=true
while getopts 'hopPg:' opt; do
case opt in
'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
;;
esac
''
done
shift $((OPTIND-1))
2023-01-25 16:33:34 +01:00
2023-10-07 12:42:34 +02:00
echo "$GOVERNOR" > /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
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