forked from dasunsrule32/radeon-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvega-power-control
executable file
·150 lines (141 loc) · 5.19 KB
/
vega-power-control
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash
#
# Script to set AMD Vega clock/voltage/profile settings.
#
# authored-by: Aaron Echols
# email: atechols at gmail dot com
#
# NOTES:
#
# This script has been released under the GNU GENERAL PUBLIC LICENSE.
# Please contribute to the upstream author at:
# https://github.com/dasunsrule32/radeon-scripts
#
# Install Instructions:
#
# https://github.com/dasunsrule32/radeon-scripts/blob/master/systemd/INSTALL-vega-power-control.md
#
# Variables:
# ----------
DEBUG=0 # Enable (1) or Disable (0) DEBUG.
AMDSYSFILE="power_dpm_force_performance_level" # ADM SYSFS file to search for.
SYSPATH=$(awk '{print}' <<< `find /sys/devices -name $AMDSYSFILE -type f -exec dirname {} \;`) # Autodetect SYSFS path.
HWMONPATH="hwmon/hwmon0"
KERNELVER=$(awk -F. '{print $1$2}' <<< `uname -r`) # Get kernel version.
KERNELREQ="415" # Minimum required kernel version for script.
KERNELREQPOW="420" # Kernel version required for POWERCAP control.
POWERCAP="0" # Enable (1) or Disable (0) AMD powercap settings, requires DEFAULTDPMPERFLVL set to manual.
DEFAULTDPMSTATE="balanced" # Set power profile, options: battery (Won't work with discrete cards), balanced, performance.
DEFAULTDPMPERFLVL="auto" # Default to auto, possible options are: auto, low, high, manual. See docs for more options.
HWDEVID=`cut -c 3- <<< cat $SYSPATH/device` # Get device ID for card.
SUBSYSDEV=`cut -c 3- <<< cat $SYSPATH/subsystem_device` # Get Subsystem device ID for card.
SUBSYSVEN=`cut -c 3- <<< cat $SYSPATH/subsystem_vendor` # Get Subsystem vendor ID for card.
SUBSYSID="$SUBSYSVEN:$SUBSYSDEV" # Get Subsystem ID for card.
HWID="$SUBSYSVEN:$HWDEVID" # Get hardware ID for card.
# Constant Variables:
# ------------------
# Vendor IDs:
# Reference: https://www.amd.com/en/support/kb/faq/gpu-55#faq-Subsystem-Vendor-ID-and-Device-ID
# Device hunt: https://devicehunt.com
AMD="1002"
ASUSTEK="1043"
CLUB3D="196D"
DIAMOND="1092"
GECUBE="18BC"
GIGABYTE="17AF"
HIS="17AF"
JETWAY="16F3"
MSI="1462"
SAPPHIRE="1DA2"
POWERCOLOR="148C"
VISIONTEK="1545"
XFX="1682"
ACER="1025"
APPLE="106B"
DELL="1028"
GATEWAY="107B"
HP="103C"
LENOVO="17AA"
SONY="104D"
TOSHIBA="1179"
# Functions:
# ----------
# Echo a string value that is passed
echo_text() {
echo -e >&2 "$@";
}
# Main body:
# ----------
# Check if root:
if [[ $EUID -ne 0 ]]; then
echo_text "You need to be root to run this script..."
exit 1
fi
# Check if kernel version is new enough:
if [ $KERNELVER -lt $KERNELREQ ]; then
echo_text "Kernel is too old, exiting..."
exit 2
else
echo_text "Kernel requirements met, continuing..."
fi
# Echo Hardware/Subsystem ID when DEBUG is enabled:
if [ $DEBUG -eq 1 ]; then
echo_text "Device ID: $HWID"
echo_text "Subsystem ID: $SUBSYSID"
fi
# Set profile (auto|manual):
if [ "$DEFAULTDPMPERFLVL" == "auto" ]; then
POWERDPMPERFLVL=`cat $SYSPATH/power_dpm_force_performance_level`
if [ $DEBUG -eq 1 ]; then
echo_text "Current state: $POWERDPMPERFLVL"
fi
# Set back to defaults if manual profile was set previously:
if [ "$POWERDPMPERFLVL" != "auto" ]; then
echo_text "Restoring to factory default settings..."
echo "$DEFAULTDPMPERFLVL" > "$SYSPATH/power_dpm_force_performance_level"
echo "r" > "$SYSPATH/pp_od_clk_voltage"
echo "c" > "$SYSPATH/pp_od_clk_voltage"
fi
# power_dpm_state is for older AMD cards only.
# FROM THE DOCS: The power_dpm_state file is a legacy interface and is
# only provided for backwards compatibility.
#
# TODO: Set a check on this block to differentiate
# VEGA/POLARIS, etc.
echo_text "Setting profile to: $DEFAULTDPMSTATE..."
echo "$DEFAULTDPMSTATE" > "$SYSPATH/power_dpm_state"
elif [ "$DEFAULTDPMPERFLVL" == "manual" ]; then
# TODO: Add for loop to use custom values for p-states, clocks and volt-
# ages per device. We can use an array to get the values for specific cards.
# This will require the refactoring of device/model detection.
#
# Set GPU frequencies/voltages:
echo_text "Applying custom power settings..."
echo "$DEFAULTDPMPERFLVL" > "$SYSPATH/power_dpm_force_performance_level"
echo "s 0 852 800" > "$SYSPATH/pp_od_clk_voltage"
echo "s 1 991 900" > "$SYSPATH/pp_od_clk_voltage"
echo "s 2 1084 910" > "$SYSPATH/pp_od_clk_voltage"
echo "s 3 1138 930" > "$SYSPATH/pp_od_clk_voltage"
echo "s 4 1200 945" > "$SYSPATH/pp_od_clk_voltage"
echo "s 5 1400 955" > "$SYSPATH/pp_od_clk_voltage"
echo "s 6 1500 970" > "$SYSPATH/pp_od_clk_voltage"
echo "s 7 1600 1000" > "$SYSPATH/pp_od_clk_voltage"
# Set memory frequencies/voltages:
echo "m 0 167 800" > "$SYSPATH/pp_od_clk_voltage"
echo "m 1 500 850" > "$SYSPATH/pp_od_clk_voltage"
echo "m 2 800 910" > "$SYSPATH/pp_od_clk_voltage"
echo "m 3 1000 1000" > "$SYSPATH/pp_od_clk_voltage"
# Set Power consumption - Requires Kernel 4.20+:
if [ $KERNELVER -ge $KERNELREQPOW ]; then
if [ $DEBUG -eq 1 ]; then
echo_text "Kernel Version: $KERNELVER"
fi
if [ $POWERCAP -eq 1 ]; then
echo_text "Adjusting AMD Power Cap"
# To set the allowed maximum power consumption of the GPU to e.g. 220 Watts (Default wattage):
echo 220000000 > "$SYSPATH/$HWMONPATH/power1_cap"
fi
fi
# Commit power changes:
echo "c" > "$SYSPATH/pp_od_clk_voltage"
fi