3

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.

  • Actually there is no need to set to performance, Intel powersave is very intelligent. But it is possible. – Pilot6 Feb 09 '17 at 22:08
  • Ah, so under load, powersave defaults to a low frequency, but like 'ondemand', automatically increases the frequency? In that case, does that mean that there is no way to actually restrict the CPU? (and is that a good thing?) I'm wondering if it'd be better to force tasks to take longer, allowing longer battery as well, which is useful when reading while background processes may cause frequency spikes. – user8437812 Feb 09 '17 at 22:09
  • 2
    Do not mix up the old powersave and pstate powersave. The Intel powersave is better than ondemand in performance. That is why old states have been dropped. – Pilot6 Feb 09 '17 at 22:10
  • Energy consumption with modern processors is a difficult subject. It is not obvious if allowing a task to run faster, and thus allowing the CPU to go into a deep idle state sooner saves energy compared to having the task run slower. The subject is often referred to as "race to idle". The answer is processor and workflow dependent. I have an older Intel i7, which tends to favor slower CPU speeds for maximum energy savings. However some newer i7s tend to favor faster CPU speeds and more time in deep idle for maximum energy savings. Turbo frequencies tend to consume more power. – Doug Smythies Feb 10 '17 at 00:15
  • @DougSmythies, It does actually seem that my computer is consuming significantly more power than before (even on new batteries), so I should probably try measuring power draw. Perhaps current draw over 1 minute, with a task that takes 20 seconds with turbo and, perhaps, 40 seconds without turbo. Are there any other benefits of using P-State? – user8437812 Feb 10 '17 at 08:31
  • Use turbostat (available in the linux-tools-common package (I think)) to measure processor energy consumption over a period of time. 1 minute is too short, because you want to dilute the influence of the turbostat program itself. Just run that task say 10 times (from a shell script), and run turbostat for 420 seconds. sudo turbostat -J --debug sleep 420 – Doug Smythies Feb 10 '17 at 14:48
  • be careful of other factors, such as cron hourly or whatever. I only use Ubuntu server edition, and so do not have a lot of other stuff running. You might have to repeat the test about 10 times to determine and reject anomalies. – Doug Smythies Feb 10 '17 at 14:55

1 Answers1

3

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.

Mah35h
  • 161