Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make game-performance wrapper script also consider tuned-ppd #127

Open
Laertes87 opened this issue Jan 28, 2025 · 4 comments
Open

Make game-performance wrapper script also consider tuned-ppd #127

Laertes87 opened this issue Jan 28, 2025 · 4 comments

Comments

@Laertes87
Copy link

Currently the script only consideres powerprofilesctl to switch power profiles. If you instead use tuned-ppd, the script actually fails without starting the game/command it is supposed to start.

So it would be nice if the script either doesn't fail and instead just runs the command without switching the power profile, or (which would be even nicer) the script automatically consideres tuned-ppd (via tuned-adm) to switch to the power profile "throughput-performance".

Background for this:
When using CachyOS-Settings with a distribution like Fedora, the script runs into a "powerprofilesctl not found" error. This is due to Fedora using tuned-ppd over power-profiles-daemon by default. So in the worst case using this wrapper script should simply have no effect in my opinion.

Is this something worth considering?

@1Naim
Copy link
Member

1Naim commented Jan 28, 2025

the script automatically consideres tuned-ppd (via tuned-adm) to switch to the power profile "throughput-performance".

Unless something has changed since v2.24.0, neither tuned nor tuned-ppd support switching on-demand per application like powerprofilesctl launch so this would be impossible to do.

So in the worst case using this wrapper script should simply have no effect in my opinion.

ppd is a hard requirement for this script and all the script does is call powerprofilesctl. Letting the script run when ppd isn't found doesn't really make sense in that case. Users should just omit this from launch options or so :)

@Laertes87
Copy link
Author

That's fair. And no, tuned-ppd does not support switching on-demand. It is still something that would have to be done kind of manually within the script by getting the current power profile, setting the new power profile, executing the actual command and then reverting to the initial profile after the execution of the command is finished or canceled.

@dougg0k
Copy link

dougg0k commented Jan 31, 2025

But other than that, isnt all that powerprofilesctl launch does is change the profile? You can just set a command to a line before and after $@.

@Laertes87
Copy link
Author

Laertes87 commented Jan 31, 2025

I'm currently using this script which essentially does the same but with tuned-ppd:

#!/usr/bin/bash

# Function to revert the profile
revert_profile() {
    echo "Reverting to the previous power profile: $CURRENT_PROFILE"
    tuned-adm profile "$CURRENT_PROFILE"
}

# Check if the tuned-adm command exists
if ! command -v tuned-adm &>/dev/null; then
    echo "Error: tuned-adm not found" >&2
    exit  1
fi

# Get the current power profile
CURRENT_PROFILE=$(tuned-adm active | awk -F': ' '{print $2}')
if [ -z "$CURRENT_PROFILE" ]; then
    echo "Error: Failed to retrieve the current power profile."
    exit 1
fi

echo "Current power profile: $CURRENT_PROFILE"

# Don't fail if the CPU driver doesn't support performance power profile
if ! tuned-adm list | grep -q 'throughput-performance'; then
    exec "$@"
fi

# Change the power profile to throughput-performance
echo "Switching to power profile: throughput-performance"
if ! tuned-adm profile throughput-performance; then
    echo "Error: Failed to switch to throughput-performance profile."
    exit 1
fi

# Trap signals to revert the profile if the script is interrupted
trap revert_profile EXIT INT TERM

# Run the specified command
echo "Running command: $*"
"$@"

# Revert the profile after the command finishes
revert_profile

I just thought that it could be made part of the game-performance script to have some added flexibility for people who are using tuned-ppd over power-profiles-daemon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants