tuned icon indicating copy to clipboard operation
tuned copied to clipboard

Automatic switch profiles between AC and battery mode

Open sith-on-mars opened this issue 4 years ago • 4 comments

Could you add the function to automatically switch profiles between AC and battery mode in the future? For example, I can use the balanced profile in the AC mode and automatically switch to the powersave profile once I unplugged the laptop. I think TLP has this feature which comes in pretty handy.

sith-on-mars avatar Oct 05 '20 13:10 sith-on-mars

Tuned already reads udev events, so I think we could get the event. On my machine I am getting the following events:

KERNEL[5759.055142] change   /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:08/PNP0C09:00/PNP0C0A:01/power_supply/BAT1 (power_supply)
UDEV  [5759.062214] change   /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:08/PNP0C09:00/PNP0C0A:01/power_supply/BAT1 (power_supply)
KERNEL[5759.554613] change   /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:08/PNP0C09:00/ACPI0003:00/power_supply/AC (power_supply)
UDEV  [5759.559012] change   /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:08/PNP0C09:00/ACPI0003:00/power_supply/AC (power_supply)

I think we could filter for the power_supply event. The current power state can be also obtained from the /sys/class/power_supply/AC/online

The rules for switching could be incorporated into the /etc/tuned/recommend.conf, i.e. the current syntax could be extended. The only problem is that the recommend.conf file is evaluated upon start of Tuned. We will have to change it to re-evaluate it also on the power supply events. I.e. it should be doable without much changes to the current code. Also I think this feature could be beneficial. Patches are welcome.

yarda avatar Oct 05 '20 16:10 yarda

Currently, automatic switching can be achieved through customizing udev rules.

❯ cat /etc/udev/rules.d/98-discharging.rules
SUBSYSTEM=="power_supply", ATTR{status}=="Discharging", RUN+="/usr/bin/tuned-adm profile accelerator-performance"

❯ cat /etc/udev/rules.d/98-charging.rules
SUBSYSTEM=="power_supply", ATTR{status}=="Charging", RUN+="/usr/bin/tuned-adm profile laptop-battery-powersave"

everyx avatar May 08 '23 04:05 everyx

these rules didn't work here.

emanuelserpa avatar Jun 19 '24 01:06 emanuelserpa

This can now be done via tuned-ppd, see PR #616.

zacikpa avatar Jun 19 '24 06:06 zacikpa