CachyOS-Settings icon indicating copy to clipboard operation
CachyOS-Settings copied to clipboard

[BUG] The power-profiles-daemon reverts to the wrong gear after a game launched by the game-performance script exits.

Open Zhuocheng-Lang opened this issue 9 months ago • 5 comments

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.

Zhuocheng-Lang avatar Mar 04 '26 16:03 Zhuocheng-Lang

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:

  1. Save profile currently in use
  2. Change to performance
  3. Once app closes, changes back to saved profile

On your script, the fact that it skips launch is useless because it would:

  1. Save the profile currently in use (performance)
  2. Use launch to change to performance
  3. 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

The10axe avatar Mar 19 '26 12:03 The10axe

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

ptr1337 avatar Mar 19 '26 17:03 ptr1337

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?

The10axe avatar Mar 19 '26 19:03 The10axe

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.

ptr1337 avatar Mar 19 '26 19:03 ptr1337

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:

  1. Save profile currently in use
  2. Change to performance
  3. Once app closes, changes back to saved profile

On your script, the fact that it skips launch is useless because it would:

  1. Save the profile currently in use (performance)
  2. Use launch to change to performance
  3. 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.

Zhuocheng-Lang avatar Mar 20 '26 03:03 Zhuocheng-Lang