June 1, 2019

Linux Power Consumption Tuning

The two tools I use for tuning the power consumption of Linux are PowerTop and TLP.

Linux Power Consumption Tuning

The two tools I use for tuning the power consumption of Linux are PowerTop and TLP. Under Fedora the following commands can be used to activate the corresponding power saving services at boot time:

Enable and Disable TLP Service

[root@linux etc]# sudo systemctl disable tlp
[root@linux etc]# sudo systemctl enable tlp

Enable and Disable PowerTop Service

[root@linux etc]# sudo systemctl disable powertop.service
[root@linux etc]# sudo systemctl enable powertop.service

Fixing Weired Keyboard and Mouse Behavior

On my machine I am having problems with the aggressive power saving of powertop. The power conserving powers of powertop are greater than those of tlp and for this reason I want to test a work-around.

It seems that the problem only applies to external HID devices that are plugged into the USB system. Internal HID like the trackpad and the keyboard seem to be fine. The idea is now to unplug everything from the notebook. Start powertop and then manually tune every tunable to 'good'. Then apply those settings with each booting – applying eg USB autosuspend only to those devices that are internal to the notebook. External devices will then not be suspended. This is fine, because if those external devices are connected, then in my setup the machine is also connected to a power source.

I found the following commands to tune all settings to lowest possible power consumption for the bare xiaomi mi air 13 (2018) notebook:

echo '1500' > '/proc/sys/vm/dirty_writeback_centisecs';
echo '0' > '/proc/sys/kernel/nmi_watchdog';
echo 'min_power' > '/sys/class/scsi_host/host0/link_power_management_policy';
echo 'min_power' > '/sys/class/scsi_host/host1/link_power_management_policy';
echo 'auto' > '/sys/bus/i2c/devices/i2c-0/device/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:00.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:1f.3/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:01:00.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:14.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:02:00.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:1f.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:1f.2/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:17.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:03:00.0/power/control';

The problem is, that after plugging my usb-c monitor at my desk, all these tuneables are reset. So this idea seems not to be stable if you plan to plug and unplug from your powered desk-setup. I think I will resort to the tlp for now :\

It seems like tlp is performing about 3 Watts worse (powertop --auto-tune: 4.5W vs. tlp auto: 7.5W) because of this single tuneable:

echo 'auto' > '/sys/bus/pci/devices/0000:01:00.0/power/control';

Which is connected to the power management of the dedicated GPU.

Solution

I now realize that tlp is way mightier than powertop. After browsing through the documentation (https://linrunner.de/en/tlp/docs/tlp-linux-advanced-power-management.html) and the detailed configuration (https://linrunner.de/en/tlp/docs/tlp-configuration.html) im am impressed by the options to choose from. For now I will rely on wisely choosen defaults by the tlp devs :D

The only thing to adapt is to set the power managment of Nvidia gpu of the hybrid graphics adapter to 'auto' with a tiny systemd service, since this is missed by the tlp configuration.

A bootup script within a systemd os can be realized with a script in eg. /usr/bin/gpu-pm-auto like so:

#!/bin/sh                                                                   

echo 'auto' > '/sys/bus/pci/devices/0000:01:00.0/power/control'

and the corresponding service in eg. /etc/systemd/system/gpu-pm-auto.service:

[Unit]
Description=set the power manager of the hybrid nvidia gpu to 'auto'

[Service]
Type=oneshot
ExecStart=/usr/bin/gpu-pm-auto

[Install]
WantedBy=multi-user.target

The systemd service is enabled by:

systemctl enable gpu-pm-auto.service

The final measurement was done with minimal screen brightness and at desktop idle using powertop just for the power measurement.

tlp on tlp off
nvidia gpu pm on 7.0W 6.7W
nvidia gpu pm auto 2.7W 2.8W

From the data it becomes evident that the biggest impackt on power consumption comes from the nvidia gpu power manager. Therefore I will use tlp in combination with the gpu-pm-auto script as described above.

Performance Battery vs AC

I have used the CPU test of the Phoronix testing tool to measure the performance difference between the tlp battery and tlp ac mode. The performance impact is, in numbers, significant. Here the results can be found: https://openbenchmarking.org/result/1909175-SP-WITHTLPBA07,1909179-SP-WITHTLPAC57

Addendum

Performance comparison using the Phoronix test suit against a similar speced Dell XPS 13 i7-8550U https://openbenchmarking.org/result/1909177-SP-1801159TY48