Automatically change cpu frequency governor
I understand from this question that Ubuntu is now using "Intel P-State", and that as a result, there are only two governor options: performance, and powersave.
But is it possible to automatically switch to powersave when on battery, and performance when a charger is connected? I'm surprised that this functionality isn't already implemented by default.
You can use acpid to manage acpi events such as connecting to AC adapter. /etc/acpi/hadler.sh can be configured to change cpu governor on acpi events.
#/etc/acpi/handler.sh
ac_adapter)
case "$2" in
AC*)
case "$4" in
00000000)
echo "powersave" >/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
;;
00000001)
echo "performance" >/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
;;
esac
;;
*) logger "ACPI action undefined: $2" ;;
esac
;;
If you use tlp, you can set
CPU_SCALING_GOVERNOR_ON_AC=performance
on /etc/default/tlp /etc/tlp.conf to do the same.