Skip to content

Instantly share code, notes, and snippets.

@asdkant
Last active October 20, 2024 23:34
Show Gist options
  • Save asdkant/f5c85fde3f2d63e6ac4a090d36d248b0 to your computer and use it in GitHub Desktop.
Save asdkant/f5c85fde3f2d63e6ac4a090d36d248b0 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Based on the instructions in this thread:
# https://www.reddit.com/r/linux_gaming/comments/1g55nl6/amd_gpus_will_now_default_to_a_high_performance/
# /sys/class/drm/card1/device/power_dpm_force_performance_level
# https://www.kernel.org/doc/html/v5.0/gpu/amdgpu.html#power-dpm-force-performance-level
# manual
# auto|low|high|profile_standard|profile_min_sclk|profile_min_mclk|profile_peak
# /sys/class/drm/card1/device/pp_power_profile_mode
# 0 BOOTUP_DEFAULT
# 1 3D_FULL_SCREEN
# 2 POWER_SAVING
# 3 VIDEO
# 4 VR
# 5 COMPUTE
# 6 CUSTOM
#
# Bash completion function
#
# function _gpumode {
# # performance levels
# local PERF_LVS="auto low high manual profile_standard profile_min_sclk profile_min_mclk profile_peak"
# # power profiles
# local POWER_PROFILES="BOOTUP_DEFAULT 3D_FULL_SCREEN POWER_SAVING VIDEO VR COMPUTE CUSTOM"
# # variable that we are going to populate with autocomplete suggestions
# COMPREPLY=()
# local CURRENT_WORD=${COMP_WORDS[COMP_CWORD]}
# if [ "$COMP_CWORD" -eq 1 ] ; then
# COMPREPLY=($(compgen -W "$PERF_LVS" -- $CURRENT_WORD ))
# elif [ "$COMP_CWORD" -eq 2 ] && [ "${COMP_WORDS[1]}" == "manual" ] ; then
# COMPREPLY=($(compgen -o nosort -W "$POWER_PROFILES" -- $CURRENT_WORD))
# fi
# }
# complete -F _gpumode gpumode
read -r -d '' HELPMSG << EOM
GPU power mode setter
gpumode <performance level> [power profile]
allowed performance levels are:
- auto
- low
- high
- manual
- profile_standard
- profile_min_sclk
- profile_min_mclk
- profile_peak
see https://www.kernel.org/doc/html/v5.0/gpu/amdgpu.html#power-dpm-force-performance-level
allowed power profiles are (only used for manual performance level):
- 0 BOOTUP_DEFAULT
- 1 3D_FULL_SCREEN
- 2 POWER_SAVING
- 3 VIDEO
- 4 VR
- 5 COMPUTE
- 6 CUSTOM
EOM
exists(){
if [ "$2" != in ]; then
echo "Incorrect usage."
echo "Correct usage: exists {key} in {array}"
return
fi
eval '[ ${'$3'[$1]+muahaha} ]'
}
declare -A PP_DICT
PP_DICT["0"]="0" ; PP_DICT["BOOTUP_DEFAULT"]="0"
PP_DICT["1"]="1" ; PP_DICT["3D_FULL_SCREEN"]="1"
PP_DICT["2"]="2" ; PP_DICT["POWER_SAVING"]="2"
PP_DICT["3"]="3" ; PP_DICT["VIDEO"]="3"
PP_DICT["4"]="4" ; PP_DICT["VR"]="4"
PP_DICT["5"]="5" ; PP_DICT["COMPUTE"]="5"
PP_DICT["6"]="6" ; PP_DICT["CUSTOM"]="6"
# power_dpm_force_performance_level
PERF_LV=$1
# pp_power_profile_mode
PW_PROFILE=$2
case "$PERF_LV" in
auto|low|high|profile_standard|profile_min_sclk|profile_min_mclk|profile_peak)
echo -n "power_dpm_force_performance_level set to: "
echo $PERF_LV | sudo tee /sys/class/drm/card1/device/power_dpm_force_performance_level
;;
manual)
if ! exists $PW_PROFILE in PP_DICT ; then
echo "Power profile $PW_PROFILE does not exist" ; echo ; echo "$HELPMSG" ; echo ; exit 2
fi
echo -n "power_dpm_force_performance_level set to: "
echo $PERF_LV | sudo tee /sys/class/drm/card1/device/power_dpm_force_performance_level
echo -n "pp_power_profile_mode set to: "
echo ${PP_DICT["$PW_PROFILE"]} | sudo tee /sys/class/drm/card1/device/pp_power_profile_mode
;;
*)
echo "$HELPMSG" ; echo
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment