Add and pre-enable a systemd service for powertop --auto-tune

On my system this saves about 0.4W while on battery power.

The major problem with `powertop --auto-tune` in general is that it
turns on USB auto-suspend, which can wreak havoc with input devices. To
prevent that, we then undo it for detected USB input devices.

This is a workaround for an upstream issue in Powertop, but it's a very
old issue and doesn't look like it's getting fixed anytime soon. See:

- https://github.com/fenrus75/powertop/issues/37
- https://github.com/fenrus75/powertop/issues/38
- https://github.com/fenrus75/powertop/issues/101
- https://github.com/fenrus75/powertop/issues/165
This commit is contained in:
Nate Graham
2025-08-24 16:16:47 -06:00
parent 599f27c914
commit e8402a4e4f
3 changed files with 30 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
# SPDX-FileCopyrightText: 2025 Nate Graham <nate@kde.org>
# Turn off USB auto-suspend for USB input devices, because
# this can make them borderline unusable.
set -e
INPUT_DEVICE_IDS=$(find /sys/bus/usb/drivers/usbhid -regex '.*\/[0-9:.-]+' -printf '%f\n' | cut --delimiter ":" --fields 1 | sort --unique)
for DEVICE_ID in $INPUT_DEVICE_IDS; do
DEVICE_PRETTY_NAME=$(cat /sys/bus/usb/devices/$DEVICE_ID/product)
echo "Disabling USB auto-suspend for device \"$DEVICE_PRETTY_NAME\" (with ID $DEVICE_ID)"
echo "on" >| "/sys/bus/usb/devices/$DEVICE_ID/power/control";
done

View File

@@ -15,6 +15,7 @@ enable systemd-zram-setup@zram0.service
enable systemd-oomd.service
enable bluetooth.service
enable cups.service
enable kde-linux-powertop.service
enable tuned.service
enable tuned-ppd.service
enable thermald.service

View File

@@ -0,0 +1,13 @@
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
# SPDX-FileCopyrightText: 2025 Nate Graham <nate@kde.org>
[Unit]
Description=Power tunings
[Service]
Type=oneshot
ExecStart=/usr/bin/powertop --auto-tune
ExecStartPost=/usr/bin/_kde-linux-disable-usb-autosuspend-for-input-devices
[Install]
WantedBy=multi-user.target sleep.target