-
Notifications
You must be signed in to change notification settings - Fork 1
/
power-profiles
272 lines (245 loc) · 8.97 KB
/
power-profiles
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#!/bin/bash
# Made by SnipeX_ :)
# Edit variables at "/etc/power-profiles.conf"
#source "/usr/share/power-profiles.conf"
#if [ -f "/etc/power-profiles.conf" ]
#then
source "/etc/power-profiles.conf"
#fi
# integrated/dedicated GPU number
# It's going to be either card1 or card0
#IGPU=card0
#DGPU=card1
# set a delay of 5 seconds, so everything has the time to load-in and finalize before writing paths and stuff into the variables
sleep 5
# This probably (definitely) only works on AMD/NVIDIA systems!
if [[ $(cat /sys/class/drm/card0/device/vendor) == "0x1002" ]]
then
IGPU=card0
DGPU=card1
else
IGPU=card1
DGPU=card0
fi
echo "manual" > /sys/class/drm/$IGPU/device/power_dpm_force_performance_level
igpu_sclk_low() {
echo "0" > /sys/class/drm/$IGPU/device/pp_dpm_sclk #200MHz Shader clock
}
igpu_sclk_med() {
echo "0 1" > /sys/class/drm/$IGPU/device/pp_dpm_sclk #750MHz Shader clock
}
igpu_sclk_high() {
echo "0 1 2" > /sys/class/drm/$IGPU/device/pp_dpm_sclk #1750MHz Shader clock
}
igpu_mclk_low() {
echo "1" > /sys/class/drm/$IGPU/device/pp_dpm_mclk #400MHz Memory clock
}
igpu_mclk_high() {
echo "0 1" > /sys/class/drm/$IGPU/device/pp_dpm_mclk #1600MHz Memory clock
}
# If the iGPU's load goes above 90% the iGPU performance level will be set to "auto"
# If it's below the threshold after a certain amount of time the performance level will be set to "low"
igpu_custom_governor() {
echo " "
echo "entering gpu_custom_governor()"
if [[ $(cat /sys/class/drm/$IGPU/device/gpu_busy_percent) -gt 80 ]]
then
igpu_sclk_high
echo auto GPU USAGE IS ABOVE 80%
elif [[ $(cat /sys/class/drm/$IGPU/device/gpu_busy_percent) -lt 25 ]]
then
igpu_sclk_low
echo low GPU USAGE IS BELOW 30%
else
if [[ $(cat /sys/class/drm/$IGPU/device/power_dpm_force_performance_level) == low ]]
then
echo CURRENT PERFORMANCE MODE IS low BECAUSE THE USAGE IS ABOVE 30% AND BELOW 85%
else
echo CURRENT PERFORMANCE MODE IS auto BECAUSE THE USAGE HASNT DROPPED BELOW 30%
fi
fi
}
# Check if CPU Boostclock is enabled -> if yes -> put the performance level of the iGPU to "auto"
# -> if not -> continue to the gpu_governor function
## Why put the iGPU to the performance level "auto" when the boostclock is enabled?
## When the iGPU is set to "low" the memory clock drops to 400MHz and limits the CPU's performance to about 80% of its actual potential
igpu_shader_clock() {
echo " "
echo "entering igpu_shader_clock()"
if [[ $PS_IGPU_CUSTOM_GOVERNOR == 0 && $POWERPROFILE == power-saver ]]
then
igpu_sclk_$PS_IGPU_SHADER_CLOCK
echo IGPU set to $PS_IGPU_SHADER_CLOCK
elif [[ $B_IGPU_CUSTOM_GOVERNOR == 0 && $POWERPROFILE == balanced ]]
then
igpu_sclk_$B_IGPU_SHADER_CLOCK
echo IGPU set to $B_IGPU_SHADER_CLOCK
elif [[ $P_IGPU_CUSTOM_GOVERNOR == 0 && $POWERPROFILE == performance ]]
then
igpu_sclk_$P_IGPU_SHADER_CLOCK
echo IGPU set to $P_IGPU_SHADER_CLOCK
elif [[ $PS_IGPU_SHADER_CLOCK_ALWAYS_LOW == 1 && $POWERPROFILE == power-saver ]]
then
igpu_sclk_low
echo IGPU set to low
elif [[ $B_IGPU_SHADER_CLOCK_ALWAYS_LOW == 1 && $POWERPROFILE == balanced ]]
then
igpu_sclk_low
echo IGPU set to low
elif [[ $P_IGPU_SHADER_CLOCK_ALWAYS_LOW == 1 && $POWERPROFILE == performance ]]
then
igpu_sclk_low
echo IGPU set to low
else
igpu_custom_governor
fi
}
# If the dGPU becomes active then set the iGPU to performance level "auto"
# otherwise continue to the gpu_cpu_boostclock function
echo " "
gpu() {
echo "entering gpu()"
if [[ $(cat /sys/bus/pci/drivers/vfio-pci/0000:01:00.0/vendor) == 0x10de ]]
then
echo DGPU is used by vfio-pci "(VM)"
igpu_shader_clock
elif [[ $(cat /sys/class/drm/$DGPU/device/power/runtime_status) == active ]]
then
igpu_sclk_high
echo auto DGPU ACTIVE
else
igpu_shader_clock
fi
}
#cpu_usage() {
#USAGE=$(top -b -1 -w79 -p1 -n 1| tail -n +3 | head -16 | awk -Fid, '{print $1}' | cut -c 36-40 | cut -f1 -d"," | sort -n | head -1 | grep -o -E '[0-9]+' | head -1)
#echo $USAGE
#}
# this is a loop for "instantly" changing the parameters after changing the power profile
loop_val=45 # the number of times to loop, (gov_loop_val * 0.5) in seconds | so for a loop_val value of 90 the parameters will get set each time after around 45 seconds
loop() {
loop_var=0
while [[ $loop_var -lt $loop_val ]]
do
echo " "
update_vars
loop_var=$(($loop_var + 1))
echo $loop_var
if [[ $POWERPROFILE != $POWERPROFILE_CHANGE || $AC_STATE != $AC_CHANGE ]]
then
echo -e "powerprofile changed!" $POWERPROFILE_CHANGE "-->" $POWERPROFILE " " "AC state changed!" $AC_CHANGE "-->" $AC_STATE
POWERPROFILE_CHANGE=$(powerprofilesctl get)
AC_CHANGE=$(cat /sys/class/power_supply/AC0/online)
#echo $AC_STATE " / " $POWERPROFILE
#### Refresh-rate related stuff ####
if [[ $POWERPROFILE == power-saver && $AC_STATE == 0 ]]
then
echo "Changed FrameRate to 60hz"
systemctl --machine snipex@.host --user start 60hz.service
elif [[ ( $POWERPROFILE == balanced || $POWERPROFILE == performance ) && $AC_STATE == 0 ]]
then
echo "Changed FrameRate to 120hz"
systemctl --machine snipex@.host --user start 120hz.service
else
systemctl --machine snipex@.host --user start 120hz.service
fi
#### Refresh-rate related stuff (end) ####
loop_var=$loop_val
else
echo powerprofile and/or AC state not changed "($POWERPROFILE)" / "($AC_STATE)"
fi
gpu
#if [[ $PS_IGPU_CUSTOM_GOVERNOR == 1 && $POWERPROFILE == power-saver ]]
#then
# sleep 0.5
#elif [[ $B_IGPU_CUSTOM_GOVERNOR == 1 && $POWERPROFILE == balanced ]]
#then
# sleep 0.5
#elif [[ $P_IGPU_CUSTOM_GOVERNOR == 1 && $POWERPROFILE == performance ]]
#then
# sleep 0.5
#else
sleep 3
#fi
done
}
update_vars() {
POWERPROFILE=$(powerprofilesctl get)
AC_STATE=$(cat /sys/class/power_supply/AC0/online)
}
# main loop
while :
do
echo "manual" > /sys/class/drm/$IGPU/device/power_dpm_force_performance_level
update_vars
echo "entering while: do"
if [[ (($POWERPROFILE == power-saver && $PS_AC_DC_MANUAL == 0) || ($POWERPROFILE == balanced && $B_AC_DC_MANUAL == 0) || ($POWERPROFILE == performance && $P_AC_DC_MANUAL == 0)) ]]
then
if [[ $AC_STATE == 1 ]]
then
ryzenadj --max-performance
else
ryzenadj --power-saving
fi
elif [[ $POWERPROFILE == power-saver ]]
then
ryzenadj --$PS_AC_DC
elif [[ $POWERPROFILE == balanced ]]
then
ryzenadj --$B_AC_DC
elif [[ $POWERPROFILE == performance ]]
then
ryzenadj --$P_AC_DC
fi
echo $POWERPROFILE / $AC_STATE
case $POWERPROFILE in
power-saver)
ryzenadj -a $PS_A -b $PS_B -c $PS_C -k $PS_K -f $PS_F
echo $PS_GOVERNOR | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
echo $PS_CPU_MAX_FREQ | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq
systemctl set-property --runtime -- user.slice AllowedCPUs=$PS_ALLOWEDCPUS
systemctl set-property --runtime -- system.slice AllowedCPUs=$PS_ALLOWEDCPUS
systemctl set-property --runtime -- init.scope AllowedCPUs=$PS_ALLOWEDCPUS
igpu_mclk_$PS_IGPU_MEMORY_CLOCK
if [[ $PS_BOOSTCLOCK == 1 ]]
then
echo 1 > /sys/devices/system/cpu/cpufreq/boost
else
echo 0 > /sys/devices/system/cpu/cpufreq/boost
fi
loop
;;
balanced)
ryzenadj -a $B_A -b $B_B -c $B_C -k $B_K -f $B_F
echo $B_GOVERNOR | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
echo $B_CPU_MAX_FREQ | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq
systemctl set-property --runtime -- user.slice AllowedCPUs=$B_ALLOWEDCPUS
systemctl set-property --runtime -- system.slice AllowedCPUs=$B_ALLOWEDCPUS
systemctl set-property --runtime -- init.scope AllowedCPUs=$B_ALLOWEDCPUS
igpu_mclk_$B_IGPU_MEMORY_CLOCK
if [[ ($B_BOOSTCLOCK == 1) ]]
then
echo 1 > /sys/devices/system/cpu/cpufreq/boost
else
echo 0 > /sys/devices/system/cpu/cpufreq/boost
fi
loop
;;
performance)
ryzenadj -a $P_A -b $P_B -c $P_C -k $P_K -f $P_F
echo $P_GOVERNOR | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
echo $P_CPU_MAX_FREQ | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq
systemctl set-property --runtime -- user.slice AllowedCPUs=$P_ALLOWEDCPUS
systemctl set-property --runtime -- system.slice AllowedCPUs=$P_ALLOWEDCPUS
systemctl set-property --runtime -- init.scope AllowedCPUs=$P_ALLOWEDCPUS
igpu_mclk_$P_IGPU_MEMORY_CLOCK
if [[ $P_BOOSTCLOCK == 1 ]]
then
echo 1 > /sys/devices/system/cpu/cpufreq/boost
else
echo 0 > /sys/devices/system/cpu/cpufreq/boost
fi
loop
;;
esac
done