2022-06-04 16:38:40 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# script for tuned AMDGPU clock control
|
2022-06-13 02:20:10 +00:00
|
|
|
# configures GPU power/clock characteristics
|
|
|
|
# clocks/power in 3D are dynamic based on need/usage
|
2022-06-04 16:38:40 +00:00
|
|
|
#
|
2022-08-03 05:47:43 +00:00
|
|
|
# for 'amdgpu-default' tuned profiles, this will reset the characteristics to default
|
|
|
|
# for others this will apply overclocking settings -- leaving clock choices to the associated power profile (eg: VR)
|
|
|
|
#
|
2022-06-04 16:38:40 +00:00
|
|
|
# rendered by Ansible with environment-appropriate values:
|
|
|
|
# card #, eg: card0
|
2022-06-13 02:20:10 +00:00
|
|
|
# path to discovered sysfs device files (power/clock/voltage control)
|
|
|
|
#
|
|
|
|
# AMDGPU driver/sysfs references:
|
|
|
|
# https://01.org/linuxgraphics/gfx-docs/drm/gpu/amdgpu.html
|
|
|
|
# https://docs.kernel.org/gpu/amdgpu/thermal.html
|
2022-11-04 01:04:59 +00:00
|
|
|
|
|
|
|
{# done this way to avoid issues with the card number possibly shifting after playbook run #}
|
|
|
|
# dynamically determine the connected GPU using the DRM subsystem
|
2022-11-04 01:09:52 +00:00
|
|
|
CARD=$(/usr/bin/grep -ls ^connected /sys/class/drm/*/status | /usr/bin/grep -o 'card[0-9]' | /usr/bin/sort | /usr/bin/uniq | /usr/bin/sort -h | /usr/bin/tail -1)
|
2022-11-04 01:04:59 +00:00
|
|
|
|
2022-08-03 05:47:43 +00:00
|
|
|
{# begin the templated script for 'default' profiles to reset state #}
|
|
|
|
{% if 'default' in item.0.key %}
|
2022-06-13 02:20:10 +00:00
|
|
|
|
2022-08-03 05:47:43 +00:00
|
|
|
# set power state transition heuristics to default
|
2022-11-04 01:04:59 +00:00
|
|
|
echo '{{ item.0.value.pwrmode }}' | tee /sys/class/drm/"${CARD}"/device/pp_power_profile_mode
|
2022-06-13 02:20:10 +00:00
|
|
|
|
|
|
|
# set control mode back to auto
|
2022-08-03 05:47:43 +00:00
|
|
|
# attempts to dynamically set optimal power profile for (load) conditions
|
2022-11-04 01:04:59 +00:00
|
|
|
echo 'auto' | tee /sys/class/drm/"${CARD}"/device/power_dpm_force_performance_level
|
2022-06-04 16:38:40 +00:00
|
|
|
|
2022-06-13 02:20:10 +00:00
|
|
|
# reset any existing profile clock changes
|
2022-11-04 01:04:59 +00:00
|
|
|
echo 'r' | tee /sys/class/drm/"${CARD}"/device/pp_od_clk_voltage
|
2022-06-04 16:38:40 +00:00
|
|
|
|
2022-06-13 02:20:10 +00:00
|
|
|
# give default profile {{ power_max_default_multi * 100.0 |int }}% of the max power capability
|
2022-08-03 05:47:43 +00:00
|
|
|
# {{ power_cap_default|int/1000000 }} Watts of {{ power_max|int/1000000 }} total
|
2022-06-13 02:20:10 +00:00
|
|
|
echo '{{ power_cap_default }}' | tee {{ powercap_set.files.0.path }}
|
2022-08-03 05:47:43 +00:00
|
|
|
{% else %}
|
|
|
|
|
|
|
|
{# begin the templated script for non-default AMD GPU profiles, eg: 'VR' or '3D_FULL_SCREEN' #}
|
2022-06-04 16:38:40 +00:00
|
|
|
# set manual control mode
|
2022-08-03 05:47:43 +00:00
|
|
|
# allows control via 'pp_dpm_mclk', 'pp_dpm_sclk', 'pp_dpm_pcie', 'pp_dpm_fclk', and 'pp_power_profile_mode' files
|
|
|
|
# only interested in 'pp_power_profile_mode' for power and 'pp_dpm_mclk' for memory clock (flickering).
|
|
|
|
# GPU clocks are dynamic based on (load) condition
|
2022-11-04 01:04:59 +00:00
|
|
|
echo 'manual' | tee /sys/class/drm/"${CARD}"/device/power_dpm_force_performance_level
|
2022-06-04 16:38:40 +00:00
|
|
|
|
2022-08-03 05:47:43 +00:00
|
|
|
# set power state transition heuristics to '{{ item.0.key }}' profile
|
2022-11-04 01:04:59 +00:00
|
|
|
echo '{{ item.0.value.pwrmode }}' | tee /sys/class/drm/"${CARD}"/device/pp_power_profile_mode
|
2022-06-13 02:20:10 +00:00
|
|
|
|
|
|
|
# give this profile {{ power_max_custom_multi * 100.0 |int }}% of the max power capability
|
2022-08-03 05:47:43 +00:00
|
|
|
# {{ power_cap_custom|int/1000000 }} Watts of {{ power_max|int/1000000 }} total
|
2022-06-13 02:20:10 +00:00
|
|
|
echo '{{ power_cap_custom }}' | tee {{ powercap_set.files.0.path }}
|
|
|
|
|
2022-06-04 16:38:40 +00:00
|
|
|
# set the minimum GPU clock
|
2022-11-04 01:04:59 +00:00
|
|
|
echo 's 0 {{ gpu_clock_min }}' | tee /sys/class/drm/"${CARD}"/device/pp_od_clk_voltage
|
2022-06-04 16:38:40 +00:00
|
|
|
|
|
|
|
# set the maximum GPU clock
|
2022-11-04 01:04:59 +00:00
|
|
|
echo 's 1 {{ gpu_clock_max }}' | tee /sys/class/drm/"${CARD}"/device/pp_od_clk_voltage
|
2022-06-04 16:38:40 +00:00
|
|
|
|
|
|
|
# set the maximum GPU *memory* clock
|
2022-11-04 01:04:59 +00:00
|
|
|
echo 'm 1 {{ gpumem_clock_max }}' | tee /sys/class/drm/"${CARD}"/device/pp_od_clk_voltage
|
2022-06-09 00:27:06 +00:00
|
|
|
{% if gpu_mv_offset is defined %}
|
2022-06-13 02:20:10 +00:00
|
|
|
|
2022-06-09 00:27:06 +00:00
|
|
|
# offset GPU voltage {{ gpu_mv_offset }}mV
|
2022-11-04 01:04:59 +00:00
|
|
|
echo 'vo {{ gpu_mv_offset }}' | tee /sys/class/drm/"${CARD}"/device/pp_od_clk_voltage
|
2022-06-09 00:27:06 +00:00
|
|
|
{% endif %}
|
2022-06-04 16:38:40 +00:00
|
|
|
|
|
|
|
# commit the changes
|
2022-11-04 01:04:59 +00:00
|
|
|
echo 'c' | tee /sys/class/drm/"${CARD}"/device/pp_od_clk_voltage
|
2022-06-04 16:38:40 +00:00
|
|
|
|
2022-08-03 05:47:43 +00:00
|
|
|
# force GPU memory into highest clock (fix flickering)
|
|
|
|
# pp_dpm_*clk settings are unintuitive, giving profiles that may be used
|
|
|
|
# opt not to set the others (eg: sclk/fclk) - those should remain for benefits from the curve
|
2022-11-04 01:04:59 +00:00
|
|
|
echo '3' | tee /sys/class/drm/"${CARD}"/device/pp_dpm_mclk
|
2022-06-13 02:20:10 +00:00
|
|
|
{% endif %}
|