Created
May 7, 2023 21:31
-
-
Save ewagner12/9aceec16fcde58471401e673097beac6 to your computer and use it in GitHub Desktop.
Small script to set CPU EPP (tested on amd-pstate-epp)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# path to relevant sysfs parameters | |
eppPath=/sys/devices/system/cpu/cpufreq | |
# read available EPP profiles from cpu0 | |
if [ -e "$eppPath"/policy0/energy_performance_available_preferences ]; then | |
availableEPP=$(sed -e 's/ *$//' -e 's/ /|/g' <<<$(cat "$eppPath"/policy0/energy_performance_available_preferences)) | |
else | |
echo "EPP parameters not found. Check if scaling governor supports EPP and if eppPath in script is correct" | |
exit 1 | |
fi | |
# check input for specified EPP, otherwise use power EPP | |
shopt -s extglob | |
availableEPPglob='@('$availableEPP')' | |
case $1 in | |
-h|--help) | |
echo "Sets the EPP of all cpus to the desired level." | |
echo "Example: eppSetup.sh balance_performance" | |
echo "Sets the EPP to balance_performance" | |
echo "Valid arguments are: $availableEPP" | |
exit 0 | |
;; | |
$availableEPPglob) | |
pref="$1" | |
;; | |
*) | |
pref=power | |
;; | |
esac | |
# check if the script is run as root | |
if [ "$(whoami)" != "root" ]; then | |
echo "You need to run the script with root privileges. Attempting to raise via sudo:" | |
sudo "${0}" "$@" | |
exit $? | |
fi | |
# set EPP on all CPUs | |
for cpuX in "$eppPath"/policy*; do | |
echo "$pref" > "$cpuX"/energy_performance_preference | |
done | |
echo "Set EPP to $pref" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment