Skip to content

Instantly share code, notes, and snippets.

@csrutil
Created February 7, 2023 12:56
Show Gist options
  • Save csrutil/6fd7e5351b708b944d14dd26362aa960 to your computer and use it in GitHub Desktop.
Save csrutil/6fd7e5351b708b944d14dd26362aa960 to your computer and use it in GitHub Desktop.
scaling_governor
echo powersave > /tmp/scaling_governor
/etc/cron.hourly/scaling_governor
#!/usr/bin/env bash
#
# Auto set the scaling_governor
#
# /etc/cron.hourly/scaling_governor
#
# cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
# cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
hour=$(TZ=Asia/Shanghai date +"%H")
mode=powersave
if (( "$hour" >= 20 )); then
mode=powersave
elif (( "$hour" <= 8 )); then
mode=powersave
else
mode=ondemand
fi
[ -f /tmp/scaling_governor ] && mode=$(cat /tmp/scaling_governor)
if cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor | grep -q $mode; then
true
else
echo "$mode" | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
fi
logger -t scaling_governor "set scaling_governor to $mode"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment