From e8402a4e4f10d40917a3d4e8489eee4b8a6d3432 Mon Sep 17 00:00:00 2001 From: Nate Graham Date: Sun, 24 Aug 2025 16:16:47 -0600 Subject: [PATCH] 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 --- ...nux-disable-usb-autosuspend-for-input-devices | 16 ++++++++++++++++ .../systemd/system-preset/50-kde-linux.preset | 1 + .../systemd/system/kde-linux-powertop.service | 13 +++++++++++++ 3 files changed, 30 insertions(+) create mode 100755 mkosi.extra/usr/bin/_kde-linux-disable-usb-autosuspend-for-input-devices create mode 100644 mkosi.extra/usr/lib/systemd/system/kde-linux-powertop.service diff --git a/mkosi.extra/usr/bin/_kde-linux-disable-usb-autosuspend-for-input-devices b/mkosi.extra/usr/bin/_kde-linux-disable-usb-autosuspend-for-input-devices new file mode 100755 index 0000000..ee4db99 --- /dev/null +++ b/mkosi.extra/usr/bin/_kde-linux-disable-usb-autosuspend-for-input-devices @@ -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 + +# 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 diff --git a/mkosi.extra/usr/lib/systemd/system-preset/50-kde-linux.preset b/mkosi.extra/usr/lib/systemd/system-preset/50-kde-linux.preset index 61bc22f..39ecda3 100644 --- a/mkosi.extra/usr/lib/systemd/system-preset/50-kde-linux.preset +++ b/mkosi.extra/usr/lib/systemd/system-preset/50-kde-linux.preset @@ -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 diff --git a/mkosi.extra/usr/lib/systemd/system/kde-linux-powertop.service b/mkosi.extra/usr/lib/systemd/system/kde-linux-powertop.service new file mode 100644 index 0000000..b49e809 --- /dev/null +++ b/mkosi.extra/usr/lib/systemd/system/kde-linux-powertop.service @@ -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 + +[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