forked from airockchip/rknn_model_zoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scaling_frequency.sh
331 lines (290 loc) · 11.4 KB
/
scaling_frequency.sh
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
chip_name=0
freq_set_status=0
usage()
{
echo "USAGE: ./scaling_frequency.sh -c {chip_name} [-h]"
echo " -c: chip_name, such as rv1126 / rk3588"
echo " -h: Help"
}
# print_and_compare_result want result
print_and_compare_result()
{
# echo "compare result"
echo " try set "$1
echo " query "$2
if [ $1 == $2 ];then
echo " Seting Success"
else
echo " Seting Failed"
freq_set_status=-1
fi
}
# print_not_support_adjust {device} {freq want} {freq want}
print_not_support_adjust()
{
echo "Firmware seems not support seting $1 frequency"
echo " wanted "$2
echo " check "$3
}
# MAIN FUNCTION HERE #
vaild=0
if [ $# == 0 ]; then
usage
exit 0
fi
while getopts "c:dc" arg
do
case $arg in
c)
chip_name=$OPTARG
;;
h)
usage
exit 0
;;
?)
usage
exit 1
;;
esac
done
if [ $chip_name == 'rv1126' ]; then
seting_strategy=1
CPU_freq=1512000
NPU_freq=934000000
DDR_freq=924000000
elif [ $chip_name == 'rv1109' ]; then
seting_strategy=1
CPU_freq=1512000
NPU_freq=594000000
DDR_freq=924000000
elif [ $chip_name == 'rk1808' ]; then
seting_strategy=1
# CPU_freq=1512000
CPU_freq=1200000
NPU_freq=792000000
DDR_freq=924000000
elif [ $chip_name == 'rk3399pro' ]; then
seting_strategy=2
CPU_freq=1512000
NPU_freq=792000000
DDR_freq=934000000
elif [ $chip_name == 'rk3562' ]; then
seting_strategy=6
CPU_freq=2000000
NPU_freq=1000000000
DDR_freq=1560000000
elif [ $chip_name == 'rk3566' ]; then
seting_strategy=3
CPU_freq=1800000
NPU_freq=1000000000
DDR_freq=1056000000
elif [ $chip_name == 'rk3568' ]; then
seting_strategy=3
CPU_freq=1800000
NPU_freq=1000000000
DDR_freq=1560000000
elif [ $chip_name == 'rk3588' ]; then
seting_strategy=4
CPU_freq=2256000
NPU_freq=1000000000
DDR_freq=2112000000
elif [ $chip_name == 'rk3576' ]; then
seting_strategy=7
CPU_freq=2016000
NPU_freq=1000000000
DDR_freq=2112000000
elif [ $chip_name == 'rv1106' ]; then
seting_strategy=5
CPU_freq=1608000
NPU_freq=500000000
DDR_freq=924000000
elif [ $chip_name == 'rv1103' ]; then
seting_strategy=5
CPU_freq=1608000
NPU_freq=500000000
DDR_freq=924000000
else
echo "$chip_name not recognize"
exit 1
fi
echo "Try seting frequency for "${chip_name}
echo " Setting strategy as $seting_strategy"
echo " NPU seting to "$NPU_freq
echo " CPU seting to "$CPU_freq
echo " DDR seting to "$DDR_freq
case $seting_strategy in
0)
echo "seting strategy not implement now"
;;
# for rk1808, rv1126, rv1109
1)
echo "CPU: seting frequency"
echo userspace > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo $CPU_freq > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed
CPU_cur_freq=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq)
print_and_compare_result $CPU_freq $CPU_cur_freq
echo "NPU: seting frequency"
echo userspace > /sys/class/devfreq/ffbc0000.npu/governor
echo $NPU_freq > /sys/class/devfreq/ffbc0000.npu/userspace/set_freq
NPU_cur_freq=$(cat /sys/class/devfreq/ffbc0000.npu/cur_freq)
print_and_compare_result $NPU_freq $NPU_cur_freq
echo "DDR: seting frequency"
if [ $chip_name == 'rk1808' ]; then
cur_freq=$(cat /sys/kernel/debug/clk/clk_summary | grep pll_dpll | awk '{split($0,a," "); print a[4]}')
else
cur_freq=$(cat /sys/kernel/debug/clk/clk_summary | grep pll_dpll | awk '{split($0,a," "); print a[5]}')
fi
DDR_cur_freq="`expr $cur_freq \* 2`"
print_not_support_adjust DDR $DDR_freq $DDR_cur_freq
;;
# for rk3399pro
2)
echo "seting strategy not implement for rk3399pro now"
;;
# for rk3566, rk3568
3)
echo "CPU: seting frequency"
echo userspace > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor
echo $CPU_freq > /sys/devices/system/cpu/cpufreq/policy0/scaling_setspeed
CPU_cur_freq=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq)
print_and_compare_result $CPU_freq $CPU_cur_freq
echo "NPU: seting frequency"
echo userspace > /sys/class/devfreq/fde40000.npu/governor
echo $NPU_freq > /sys/class/devfreq/fde40000.npu/userspace/set_freq
NPU_cur_freq=$(cat /sys/devices/platform/fde40000.npu/devfreq/fde40000.npu/cur_freq)
print_and_compare_result $NPU_freq $NPU_cur_freq
echo "DDR: seting frequency"
echo userspace > /sys/class/devfreq/dmc/governor
echo $DDR_freq > /sys/class/devfreq/dmc/userspace/set_freq
DDR_cur_freq=$(cat /sys/class/devfreq/dmc/cur_freq)
print_and_compare_result $DDR_freq $DDR_cur_freq
;;
# for rk3588
4)
echo "CPU: seting frequency"
echo " Core0"
echo userspace > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor
echo 1800000 > /sys/devices/system/cpu/cpufreq/policy0/scaling_setspeed
CPU_cur_freq=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq)
print_and_compare_result 1800000 $CPU_cur_freq
echo " Core4"
echo userspace > /sys/devices/system/cpu/cpufreq/policy4/scaling_governor
echo $CPU_freq > /sys/devices/system/cpu/cpufreq/policy4/scaling_setspeed
CPU_cur_freq=$(cat /sys/devices/system/cpu/cpu4/cpufreq/cpuinfo_cur_freq)
print_and_compare_result $CPU_freq $CPU_cur_freq
echo " Core6"
echo userspace > /sys/devices/system/cpu/cpufreq/policy6/scaling_governor
echo $CPU_freq > /sys/devices/system/cpu/cpufreq/policy6/scaling_setspeed
CPU_cur_freq=$(cat /sys/devices/system/cpu/cpu6/cpufreq/cpuinfo_cur_freq)
print_and_compare_result $CPU_freq $CPU_cur_freq
echo "NPU: seting frequency"
if [ -e /sys/class/devfreq/fdab0000.npu/governor ];then
echo userspace > /sys/class/devfreq/fdab0000.npu/governor
echo $NPU_freq > /sys/class/devfreq/fdab0000.npu/userspace/set_freq
NPU_cur_freq=$(cat /sys/class/devfreq/fdab0000.npu/cur_freq)
elif [ -e /sys/class/devfreq/devfreq0/governor ];then
echo performance > /sys/class/devfreq/devfreq0/governor
NPU_cur_freq=$(cat /sys/class/devfreq/devfreq0/cur_freq)
else
NPU_cur_freq=$(cat /sys/kernel/debug/clk/scmi_clk_npu/clk_rate)
fi
print_not_support_adjust NPU $NPU_freq $NPU_cur_freq
echo "DDR: seting frequency"
if [ -e /sys/class/devfreq/dmc/governor ];then
echo userspace > /sys/class/devfreq/dmc/governor
echo $DDR_freq > /sys/class/devfreq/dmc/userspace/set_freq
DDR_cur_freq=$(cat /sys/class/devfreq/dmc/cur_freq)
print_and_compare_result $DDR_freq $DDR_cur_freq
else
print_not_support_adjust DDR $DDR_freq
$DDR_cur_freq=$(cat /sys/kernel/debug/clk/clk_summary | grep scmi_clk_ddr)
echo $DDR_cur_freq
fi
;;
# rv1106, rv1103
5)
echo "CPU: seting frequency"
echo userspace > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor
echo $CPU_freq > /sys/devices/system/cpu/cpufreq/policy0/scaling_setspeed
CPU_cur_freq=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq)
print_and_compare_result $CPU_freq $CPU_cur_freq
echo "NPU: seting frequency"
# echo " no strategy to seting DDR frequency"
# echo $NPU_freq > /sys/kernel/debug/clk/aclk_npu_root/clk_rate
echo $NPU_freq > /sys/kernel/debug/clk/clk_500m_src/clk_rate
NPU_cur_freq=$(cat /sys/kernel/debug/clk/clk_summary | grep aclk_npu_root | awk '{split($0,a," "); print a[5]}')
print_and_compare_result $NPU_freq $NPU_cur_freq
echo "DDR: seting frequency"
echo " no strategy to seting DDR frequency"
cur_freq=$(cat /sys/kernel/debug/clk/clk_summary | grep clk_core_ddrc_src | awk '{split($0,a," "); print a[5]}')
DDR_cur_freq="`expr $cur_freq \* 2`"
print_and_compare_result $DDR_freq $DDR_cur_freq
;;
# rk3562
6)
echo "CPU: seting frequency"
echo userspace > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor
echo $CPU_freq > /sys/devices/system/cpu/cpufreq/policy0/scaling_setspeed
CPU_cur_freq=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq)
print_and_compare_result $CPU_freq $CPU_cur_freq
echo "NPU: seting frequency"
echo userspace > /sys/devices/platform/ff300000.npu/devfreq/ff300000.npu/governor
echo $NPU_freq > /sys/devices/platform/ff300000.npu/devfreq/ff300000.npu/userspace/set_freq
NPU_cur_freq=$(cat /sys/class/devfreq/ff300000.npu/cur_freq)
print_and_compare_result $NPU_freq $NPU_cur_freq
echo "DDR: seting frequency"
if [ -e /sys/class/devfreq/dmc/governor ];then
echo userspace > /sys/class/devfreq/dmc/governor
echo $DDR_freq > /sys/class/devfreq/dmc/userspace/set_freq
DDR_cur_freq=$(cat /sys/class/devfreq/dmc/cur_freq)
else
DDR_cur_freq=$(cat /sys/kernel/debug/clk/clk_summary | grep scmi_clk_ddr | awk '{split($0,a," "); print a[5]}')
fi
print_not_support_adjust DDR $DDR_freq $DDR_cur_freq
;;
# rk3576
7)
echo "CPU: seting frequency"
echo " Core0"
echo userspace > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor
echo 1800000 > /sys/devices/system/cpu/cpufreq/policy0/scaling_setspeed
CPU_cur_freq=$(cat /sys/devices/system/cpu/cpufreq/policy0/scaling_cur_freq)
print_and_compare_result 1800000 $CPU_cur_freq
echo " Core4"
echo userspace > /sys/devices/system/cpu/cpufreq/policy4/scaling_governor
echo $CPU_freq > /sys/devices/system/cpu/cpufreq/policy4/scaling_setspeed
CPU_cur_freq=$(cat /sys/devices/system/cpu/cpufreq/policy4/scaling_cur_freq)
print_and_compare_result $CPU_freq $CPU_cur_freq
echo "NPU: seting frequency"
echo userspace > /sys/devices/platform/27700000.npu/devfreq/27700000.npu/governor
echo $NPU_freq > /sys/class/devfreq/27700000.npu/userspace/set_freq
NPU_cur_freq=$(cat /sys/class/devfreq/27700000.npu/cur_freq)
print_and_compare_result $NPU_freq $NPU_cur_freq
echo "DDR: seting frequency"
if [ -e /sys/class/devfreq/dmc/governor ];then
echo userspace > /sys/class/devfreq/dmc/governor
echo $DDR_freq > /sys/class/devfreq/dmc/userspace/set_freq
DDR_cur_freq=$(cat /sys/class/devfreq/dmc/cur_freq)
else
DDR_cur_freq=$(cat /sys/kernel/debug/clk/clk_summary | grep scmi_clk_ddr | awk '{split($0,a," "); print a[5]}')
fi
print_not_support_adjust DDR $DDR_freq $DDR_cur_freq
;;
*)
echo "seting strategy not implement now"
;;
esac
echo "freq set" > ./freq_set_status
echo "CPU: "$CPU_freq >> ./freq_set_status
echo "NPU: "$NPU_freq >> ./freq_set_status
echo "DDR: "$DDR_freq >> ./freq_set_status
echo "freq query" >> ./freq_set_status
echo "CPU: "$CPU_cur_freq >> ./freq_set_status
echo "NPU: "$NPU_cur_freq >> ./freq_set_status
echo "DDR: "$DDR_cur_freq >> ./freq_set_status
if [ $freq_set_status == 0 ];then
echo "Seting Success" >> ./freq_set_status
else
echo "Seting Failed" >> ./freq_set_status
fi