[BUG] The power-profiles-daemon reverts to the wrong gear after a game launched by the game-performance script exits.
Problem Description
I had configured my KDE settings to switch to performance mode when plugged in and to balance mode when using battery, and I had also enabled "Limit maximum charge level" (though this shouldn't have any effect).
However, every time I launch Counter-Strike 2 on Steam using the launch option LD_PRELOAD="" prime-run game-performance mangohud %command% -..., after exiting, I always find that my original performance mode has been switched back to balance.
Device Info
output from cachyos_bugreport.sh
MY GUESS: This is most likely another minor issue with PPD's internal implementation. I worked around the game-performance script to fix it.
#!/usr/bin/env bash
if ! command -v powerprofilesctl &>/dev/null; then
echo "Error: powerprofilesctl not found" >&2
exit 1
fi
# 1. Capture the initial state
PREVIOUS_PROFILE=$(powerprofilesctl get 2>/dev/null)
TARGET_PROFILE="performance"
# 2. Check if performance profile is even available
if ! powerprofilesctl list | grep -q "${TARGET_PROFILE}:"; then
exec "$@"
fi
# 3. Logic: If we are already in performance mode, don't use 'launch'
# 'launch' creates a temporary hold that resets to 'balanced' on exit.
# By skipping 'launch' when already in performance, we avoid the reset.
if [ "$PREVIOUS_PROFILE" = "$TARGET_PROFILE" ]; then
if [ -n "$GAME_PERFORMANCE_SCREENSAVER_ON" ]; then
exec "$@"
else
# Still inhibit sleep/screensaver, but don't touch power profiles
exec systemd-inhibit --why "Game is running (Performance already active)" -- "$@"
fi
fi
# 4. If we are NOT in performance mode, use 'launch' to switch temporarily
# and then explicitly restore the PREVIOUS_PROFILE after the game exits.
run_game() {
if [ -z "$GAME_PERFORMANCE_SCREENSAVER_ON" ]; then
systemd-inhibit --why "CachyOS game-performance is running" \
powerprofilesctl launch -p "$TARGET_PROFILE" \
-r "Launched with CachyOS game-performance utility" -- "$@"
else
powerprofilesctl launch -p "$TARGET_PROFILE" \
-r "Launched with CachyOS game-performance utility" -- "$@"
fi
# 5. Safety net: Explicitly restore the previous profile
# This fixes cases where 'launch' defaults back to 'balanced'
powerprofilesctl set "$PREVIOUS_PROFILE"
}
run_game "$@"
If there's no problem pls merge.
I have that issue too, and it doesn't seem intentional because it didn't do it in before. It feels weird to be in power save, boot a game and have it switch to performance (which I want), then have it go to balanced (which I don't want since I want it back to power save.
I think the logic should indeed be:
- Save profile currently in use
- Change to performance
- Once app closes, changes back to saved profile
On your script, the fact that it skips launch is useless because it would:
- Save the profile currently in use (performance)
- Use
launchto change to performance - Once the app closes, it'd switch to balance because launch will end, but then switch to performance to restore saved profile
However, I think it's a bug from powerprofiledaemon and not related to the script, as this behavior wasn't happening before, it'd be safe to check there
Hi all,
We are working currently on switching away from power-profiles-daemon and then will look with the migration also into this issue and improve the situation
Oh, with that switch, is the switching already planned? Or are you still looking into alternative? And if you do switch, will it be ppd compliant (like tuned-ppd)? So that people can use the built in profile change in KDE for example?
Oh, with that switch, is the switching already planned? Or are you still looking into alternative? And if you do switch, will it be ppd compliant (like
tuned-ppd)? So that people can use the built in profile change in KDE for example?
Yes, its planned. It will be an own fork of tuned(-ppd.
I have that issue too, and it doesn't seem intentional because it didn't do it in before. It feels weird to be in power save, boot a game and have it switch to performance (which I want), then have it go to balanced (which I don't want since I want it back to power save.
I think the logic should indeed be:
- Save profile currently in use
- Change to performance
- Once app closes, changes back to saved profile
On your script, the fact that it skips launch is useless because it would:
- Save the profile currently in use (performance)
- Use
launchto change to performance- Once the app closes, it'd switch to balance because launch will end, but then switch to performance to restore saved profile
However, I think it's a bug from powerprofiledaemon and not related to the script, as this behavior wasn't happening before, it'd be safe to check there
Appreciated for the advise. But since the project will migrate to tuneD, let's just let them cook.