Debian Codegraph @

libs/hwui/tests/scripts/prep_generic.sh

raw symbols SCIP
1 #
2 # Copyright (C) 2018 The Android Open Source Project
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16
17 #################################################################
18 ###
19 ### DO NOT MODIFY THIS FILE
20 ### This is a copy of androidx's benchmark/lockClocks.sh
21 ### Make changes there instead then copy here!
22 ###
23 #################################################################
24
25 # This script can be used to lock device clocks to stable levels for comparing
26 # different versions of software. Since the clock levels are not necessarily
27 # indicative of real world behavior, this should **never** be used to compare
28 # performance between different device models.
29
30 # Fun notes for maintaining this file:
31 # $((arithmetic expressions)) can deal with ints > INT32_MAX, but if compares cannot. This is
32 # why we use MHz.
33 # $((arithmetic expressions)) can sometimes evaluate right-to-left. This is why we use parens.
34 # Everything below the initial host-check isn't bash - Android uses mksh
35 # mksh allows `\n` in an echo, bash doesn't
36 # can't use `awk`
37 # can't use `sed`
38 # can't use `cut` on < L
39 # can't use `expr` on < L
40
41 ARG_CORES=${1:-big}
42
43 CPU_TARGET_FREQ_PERCENT=50
44 GPU_TARGET_FREQ_PERCENT=50
45
46 if [scip-shell system . . `[`. "`command -v getprop`" == "" ]; then
47 if [scip-shell system . . `[`. -n "`command -v adb`" ]; then
48 echoscip-shell system . . echo. ""
49 echoscip-shell system . . echo. "Pushing $0 and running it on device..."
50 dest=/data/local/tmp/`basenamescip-shell system . . basename. $0`
51 adb push $0 ${dest}
52 adb shell ${dest} $@
53 adb shell rm ${dest}
54 exit
55 else
56 echoscip-shell system . . echo. "Could not find adb. Options are:"
57 echoscip-shell system . . echo. " 1. Ensure adb is on your \$PATH"
58 echoscip-shell system . . echo. " 2. Use './gradlew lockClocks'"
59 echoscip-shell system . . echo. " 3. Manually adb push this script to your device, and run it there"
60 exit -1
61 fi
62 fi
63
64 # require root
65 if [[ `id` != "uid=0"* ]]; then
66 echoscip-shell system . . echo. "Not running as root, cannot lock clocks, aborting"
67 exit -1
68 fi
69
70 DEVICE=`getprop ro.product.device`
71 MODEL=`getprop ro.product.model`
72
73 if [scip-shell system . . `[`. "$ARG_CORES" == "big" ]; then
74 CPU_IDEAL_START_FREQ_KHZ=0
75 elif [scip-shell system . . `[`. "$ARG_CORES" == "little" ]; then
76 CPU_IDEAL_START_FREQ_KHZ=100000000 ## finding min of max freqs, so start at 100M KHz (100 GHz)
77 else
78 echoscip-shell system . . echo. "Invalid argument \$1 for ARG_CORES, should be 'big' or 'little', but was $ARG_CORES"
79 exit -1
80 fi
81
82 function_core_checkscip-shell shell android-platform-frameworks-base 1:14~beta1-5 function_core_check().() {
83 if [scip-shell system . . `[`. "$ARG_CORES" == "big" ]; then
84 [scip-shell system . . `[`. $1 -gt $2 ]
85 elif [scip-shell system . . `[`. "$ARG_CORES" == "little" ]; then
86 [scip-shell system . . `[`. $1 -lt $2 ]
87 else
88 echoscip-shell system . . echo. "Invalid argument \$1 for ARG_CORES, should be 'big' or 'little', but was $ARG_CORES"
89 exit -1
90 fi
91 }
92
93 function_setup_goscip-shell shell android-platform-frameworks-base 1:14~beta1-5 function_setup_go().() {
94 if [scip-shell system . . `[`. -f /d/fpsgo/common/force_onoffscip-shell filesystem . . `/d/fpsgo/common/force_onoff`. ]; then
95 # Disable fpsgo
96 echoscip-shell system . . echo. 0 > /d/fpsgo/common/force_onoffscip-shell filesystem . . `/d/fpsgo/common/force_onoff`.
97 fpsgoState=`catscip-shell system . . cat. /d/fpsgo/common/force_onoffscip-shell filesystem . . `/d/fpsgo/common/force_onoff`.`
98 if [scip-shell system . . `[`. "$fpsgoState" != "0" ] && [scip-shell system . . `[`. "$fpsgoState" != "force off" ]; then
99 echoscip-shell system . . echo. "Failed to disable fpsgo"
100 exit -1
101 fi
102 fi
103 }
104
105 # Find the min or max (little vs big) of CPU max frequency, and lock cores of the selected type to
106 # an available frequency that's >= $CPU_TARGET_FREQ_PERCENT% of max. Disable other cores.
107 function_lock_cpuscip-shell shell android-platform-frameworks-base 1:14~beta1-5 function_lock_cpu().() {
108 CPU_BASE=/sys/devices/system/cpuscip-shell filesystem . . `/sys/devices/system/cpu`.
109 GOV=cpufreq/scaling_governor
110
111 # Options to make clock locking on go devices more sticky.
112 function_setup_goscip-shell shell android-platform-frameworks-base 1:14~beta1-5 function_setup_go().
113
114 # Find max CPU freq, and associated list of available freqs
115 cpuIdealFreq=$CPU_IDEAL_START_FREQ_KHZ
116 cpuAvailFreqCmpr=0
117 cpuAvailFreq=0
118 enableIndices=''
119 disableIndices=''
120 cpu=0
121 while [scip-shell system . . `[`. -d ${CPU_BASE}/cpu${cpu}/cpufreq ]; do
122 # Try to enable core, so we can find its frequencies.
123 # Note: In cases where the online file is inaccessible, it represents a
124 # core which cannot be turned off, so we simply assume it is enabled if
125 # this command fails.
126 if [scip-shell system . . `[`. -f "$CPU_BASE/cpu$cpu/online" ]; then
127 echoscip-shell system . . echo. 1 > ${CPU_BASE}/cpu${cpu}/online || truescip-shell system . . true.
128 fi
129
130 # set userspace governor on all CPUs to ensure freq scaling is disabled
131 echoscip-shell system . . echo. userspace > ${CPU_BASE}/cpu${cpu}/${GOV}
132
133 maxFreq=`catscip-shell system . . cat. ${CPU_BASE}/cpu$cpu/cpufreq/cpuinfo_max_freq`
134 availFreq=`catscip-shell system . . cat. ${CPU_BASE}/cpu$cpu/cpufreq/scaling_available_frequencies`
135 availFreqCmpr=${availFreq// /-}
136
137 if (function_core_checkscip-shell shell android-platform-frameworks-base 1:14~beta1-5 function_core_check(). $maxFreq $cpuIdealFreq); then
138 # new min/max of max freq, look for cpus with same max freq and same avail freq list
139 cpuIdealFreq=${maxFreq}
140 cpuAvailFreq=${availFreq}
141 cpuAvailFreqCmpr=${availFreqCmpr}
142
143 if [scip-shell system . . `[`. -z "$disableIndices" ]; then
144 disableIndices="$enableIndices"
145 else
146 disableIndices="$disableIndices $enableIndices"
147 fi
148 enableIndices=${cpu}
149 elif [scip-shell system . . `[`. ${maxFreq} == ${cpuIdealFreq} ] && [scip-shell system . . `[`. ${availFreqCmpr} == ${cpuAvailFreqCmpr} ]; then
150 enableIndices="$enableIndices $cpu"
151 else
152 if [scip-shell system . . `[`. -z "$disableIndices" ]; then
153 disableIndices="$cpu"
154 else
155 disableIndices="$disableIndices $cpu"
156 fi
157 fi
158
159 cpu=$(($cpu + 1))
160 done
161
162 # check that some CPUs will be enabled
163 if [scip-shell system . . `[`. -z "$enableIndices" ]; then
164 echoscip-shell system . . echo. "Failed to find any $ARG_CORES cores to enable, aborting."
165 exit -1
166 fi
167
168 # Chose a frequency to lock to that's >= $CPU_TARGET_FREQ_PERCENT% of max
169 # (below, 100M = 1K for KHz->MHz * 100 for %)
170 TARGET_FREQ_MHZ=$(( ($cpuIdealFreq * $CPU_TARGET_FREQ_PERCENT) / 100000 ))
171 chosenFreq=0
172 chosenFreqDiff=100000000
173 for freq in ${cpuAvailFreq}; do
174 freqMhz=$(( ${freq} / 1000 ))
175 if [scip-shell system . . `[`. ${freqMhz} -ge ${TARGET_FREQ_MHZ} ]; then
176 newChosenFreqDiff=$(( $freq - $TARGET_FREQ_MHZ ))
177 if [scip-shell system . . `[`. $newChosenFreqDiff -lt $chosenFreqDiff ]; then
178 chosenFreq=${freq}
179 chosenFreqDiff=$(( $chosenFreq - $TARGET_FREQ_MHZ ))
180 fi
181 fi
182 done
183
184 # Lock wembley clocks using high-priority op code method.
185 # This block depends on the shell utility awk, which is only available on API 27+
186 if [scip-shell system . . `[`. "$DEVICE" == "wembley" ]; then
187 # Get list of available frequencies to lock to by parsing the op-code list.
188 AVAIL_OP_FREQS=`catscip-shell system . . cat. /proc/cpufreq/MT_CPU_DVFS_LL/cpufreq_oppidxscip-shell filesystem . . `/proc/cpufreq/MT_CPU_DVFS_LL/cpufreq_oppidx`. \
189 | awkscip-shell system . . awk. '{print $2}' \
190 | tailscip-shell system . . tail. -n +3 \
191 | while read line; do
192 echoscip-shell system . . echo. "${line:1:${#line}-2}"
193 done`
194
195 # Compute the closest available frequency to the desired frequency, $chosenFreq.
196 # This assumes the op codes listen in /proc/cpufreq/MT_CPU_DVFS_LL/cpufreq_oppidx are listed
197 # in order and 0-indexed.
198 opCode=-1
199 opFreq=0
200 currOpCode=-1
201 for currOpFreq in $AVAIL_OP_FREQS; do
202 currOpCode=$((currOpCode + 1))
203
204 prevDiff=$((chosenFreq-opFreq))
205 prevDiff=`function_abs $prevDiff`
206 currDiff=$((chosenFreq-currOpFreq))
207 currDiff=`function_abs $currDiff`
208 if [scip-shell system . . `[`. $currDiff -lt $prevDiff ]; then
209 opCode="$currOpCode"
210 opFreq="$currOpFreq"
211 fi
212 done
213
214 echoscip-shell system . . echo. "$opCode" > /proc/ppm/policy/ut_fix_freq_idxscip-shell filesystem . . `/proc/ppm/policy/ut_fix_freq_idx`.
215 fi
216
217 # enable 'big' CPUs
218 for cpu in ${enableIndices}; do
219 freq=${CPU_BASE}/cpu$cpu/cpufreq
220
221 # Try to enable core, so we can find its frequencies.
222 # Note: In cases where the online file is inaccessible, it represents a
223 # core which cannot be turned off, so we simply assume it is enabled if
224 # this command fails.
225 if [scip-shell system . . `[`. -f "$CPU_BASE/cpu$cpu/online" ]; then
226 echoscip-shell system . . echo. 1 > ${CPU_BASE}/cpu${cpu}/online || truescip-shell system . . true.
227 fi
228
229 # scaling_max_freq must be set before scaling_min_freq
230 echoscip-shell system . . echo. ${chosenFreq} > ${freq}/scaling_max_freq
231 echoscip-shell system . . echo. ${chosenFreq} > ${freq}/scaling_min_freq
232 echoscip-shell system . . echo. ${chosenFreq} > ${freq}/scaling_setspeed
233
234 # Give system a bit of time to propagate the change to scaling_setspeed.
235 sleepscip-shell system . . sleep. 0.1
236
237 # validate setting the freq worked
238 obsCur=`catscip-shell system . . cat. ${freq}/scaling_cur_freq`
239 obsMin=`catscip-shell system . . cat. ${freq}/scaling_min_freq`
240 obsMax=`catscip-shell system . . cat. ${freq}/scaling_max_freq`
241 if [scip-shell system . . `[`. "$obsCur" -ne "$chosenFreq" ] || [scip-shell system . . `[`. "$obsMin" -ne "$chosenFreq" ] || [scip-shell system . . `[`. "$obsMax" -ne "$chosenFreq" ]; then
242 echoscip-shell system . . echo. "Failed to set CPU$cpu to $chosenFreq Hz! Aborting..."
243 echoscip-shell system . . echo. "scaling_cur_freq = $obsCur"
244 echoscip-shell system . . echo. "scaling_min_freq = $obsMin"
245 echoscip-shell system . . echo. "scaling_max_freq = $obsMax"
246 exit -1
247 fi
248 done
249
250 # disable other CPUs (Note: important to enable big cores first!)
251 for cpu in ${disableIndices}; do
252 echoscip-shell system . . echo. 0 > ${CPU_BASE}/cpu${cpu}/online
253 done
254
255 echoscip-shell system . . echo. "=================================="
256 echoscip-shell system . . echo. "Locked CPUs ${enableIndices// /,} to $chosenFreq / $cpuIdealFreq KHz"
257 echoscip-shell system . . echo. "Disabled CPUs ${disableIndices// /,}"
258 echoscip-shell system . . echo. "=================================="
259 }
260
261 # Returns the absolute value of the first arg passed to this helper.
262 function_absscip-shell shell android-platform-frameworks-base 1:14~beta1-5 function_abs().() {
263 n=$1
264 if [scip-shell system . . `[`. $n -lt 0 ]; then
265 echoscip-shell system . . echo. "$((n * -1 ))"
266 else
267 echoscip-shell system . . echo. "$n"
268 fi
269 }
270
271 # If we have a Qualcomm GPU, find its max frequency, and lock to
272 # an available frequency that's >= GPU_TARGET_FREQ_PERCENT% of max.
273 function_lock_gpu_kgslscip-shell shell android-platform-frameworks-base 1:14~beta1-5 function_lock_gpu_kgsl().() {
274 if [scip-shell system . . `[`. ! -d /sys/class/kgsl/kgsl-3d0/scip-shell filesystem . . `/sys/class/kgsl/kgsl-3d0/`. ]; then
275 # not kgsl, abort
276 echoscip-shell system . . echo. "Currently don't support locking GPU clocks of $MODEL ($DEVICE)"
277 return -1
278 fi
279 if [scip-shell system . . `[`. ${DEVICE} == "walleye" ] || [scip-shell system . . `[`. ${DEVICE} == "taimen" ]; then
280 # Workaround crash
281 echoscip-shell system . . echo. "Unable to lock GPU clocks of $MODEL ($DEVICE)"
282 return -1
283 fi
284
285 GPU_BASE=/sys/class/kgsl/kgsl-3d0scip-shell filesystem . . `/sys/class/kgsl/kgsl-3d0`.
286
287 gpuMaxFreq=0
288 gpuAvailFreq=`catscip-shell system . . cat. $GPU_BASE/devfreq/available_frequencies`
289 for freq in ${gpuAvailFreq}; do
290 if [scip-shell system . . `[`. ${freq} -gt ${gpuMaxFreq} ]; then
291 gpuMaxFreq=${freq}
292 fi
293 done
294
295 # (below, 100M = 1M for MHz * 100 for %)
296 TARGET_FREQ_MHZ=$(( (${gpuMaxFreq} * ${GPU_TARGET_FREQ_PERCENT}) / 100000000 ))
297
298 chosenFreq=${gpuMaxFreq}
299 index=0
300 chosenIndex=0
301 for freq in ${gpuAvailFreq}; do
302 freqMhz=$(( ${freq} / 1000000 ))
303 if [scip-shell system . . `[`. ${freqMhz} -ge ${TARGET_FREQ_MHZ} ] && [scip-shell system . . `[`. ${chosenFreq} -ge ${freq} ]; then
304 # note avail freq are generally in reverse order, so we don't break out of this loop
305 chosenFreq=${freq}
306 chosenIndex=${index}
307 fi
308 index=$(($index + 1))
309 done
310 lastIndex=$(($index - 1))
311
312 firstFreq=`function_cut_first_from_space_seperated_list $gpuAvailFreq`
313
314 if [scip-shell system . . `[`. ${gpuMaxFreq} != ${firstFreq} ]; then
315 # pwrlevel is index of desired freq among available frequencies, from highest to lowest.
316 # If gpuAvailFreq appears to be in-order, reverse the index
317 chosenIndex=$(($lastIndex - $chosenIndex))
318 fi
319
320 echoscip-shell system . . echo. 0 > ${GPU_BASE}/bus_split
321 echoscip-shell system . . echo. 1 > ${GPU_BASE}/force_clk_on
322 echoscip-shell system . . echo. 10000 > ${GPU_BASE}/idle_timer
323
324 echoscip-shell system . . echo. performance > ${GPU_BASE}/devfreq/governor
325
326 # NOTE: we store in min/max twice, because we don't know if we're increasing
327 # or decreasing, and it's invalid to try and set min > max, or max < min
328 echoscip-shell system . . echo. ${chosenFreq} > ${GPU_BASE}/devfreq/min_freq
329 echoscip-shell system . . echo. ${chosenFreq} > ${GPU_BASE}/devfreq/max_freq
330 echoscip-shell system . . echo. ${chosenFreq} > ${GPU_BASE}/devfreq/min_freq
331 echoscip-shell system . . echo. ${chosenFreq} > ${GPU_BASE}/devfreq/max_freq
332 echoscip-shell system . . echo. ${chosenIndex} > ${GPU_BASE}/min_pwrlevel
333 echoscip-shell system . . echo. ${chosenIndex} > ${GPU_BASE}/max_pwrlevel
334 echoscip-shell system . . echo. ${chosenIndex} > ${GPU_BASE}/min_pwrlevel
335 echoscip-shell system . . echo. ${chosenIndex} > ${GPU_BASE}/max_pwrlevel
336
337 obsCur=`catscip-shell system . . cat. ${GPU_BASE}/devfreq/cur_freq`
338 obsMin=`catscip-shell system . . cat. ${GPU_BASE}/devfreq/min_freq`
339 obsMax=`catscip-shell system . . cat. ${GPU_BASE}/devfreq/max_freq`
340 if [scip-shell system . . `[`. obsCur -ne ${chosenFreq} ] || [scip-shell system . . `[`. obsMin -ne ${chosenFreq} ] || [scip-shell system . . `[`. obsMax -ne ${chosenFreq} ]; then
341 echoscip-shell system . . echo. "Failed to set GPU to $chosenFreq Hz! Aborting..."
342 echoscip-shell system . . echo. "cur_freq = $obsCur"
343 echoscip-shell system . . echo. "min_freq = $obsMin"
344 echoscip-shell system . . echo. "max_freq = $obsMax"
345 echoscip-shell system . . echo. "index = $chosenIndex"
346 exit -1
347 fi
348 echoscip-shell system . . echo. "Locked GPU to $chosenFreq / $gpuMaxFreq Hz"
349 }
350
351 # cut is not available on some devices (Nexus 5 running LRX22C).
352 function_cut_first_from_space_seperated_listscip-shell shell android-platform-frameworks-base 1:14~beta1-5 function_cut_first_from_space_seperated_list().() {
353 list=$1
354
355 for freq in $list; do
356 echoscip-shell system . . echo. $freq
357 break
358 done
359 }
360
361 # kill processes that manage thermals / scaling
362 stop thermal-engine || truescip-shell system . . true.
363 stop perfd || truescip-shell system . . true.
364 stop vendor.thermal-engine || truescip-shell system . . true.
365 stop vendor.perfd || truescip-shell system . . true.
366 setprop vendor.powerhal.init 0 || truescip-shell system . . true.
367 setprop ctl.interface_restart [email protected]::IPower/default || truescip-shell system . . true.
368
369 function_lock_cpuscip-shell shell android-platform-frameworks-base 1:14~beta1-5 function_lock_cpu().
370
371 if [scip-shell system . . `[`. "$DEVICE" -ne "wembley" ]; then
372 function_lock_gpu_kgslscip-shell shell android-platform-frameworks-base 1:14~beta1-5 function_lock_gpu_kgsl().
373 else
374 echoscip-shell system . . echo. "Unable to lock gpu clocks of $MODEL ($DEVICE)."
375 fi
376
377 # Memory bus - hardcoded per-device for now
378 if [scip-shell system . . `[`. ${DEVICE} == "marlin" ] || [scip-shell system . . `[`. ${DEVICE} == "sailfish" ]; then
379 echoscip-shell system . . echo. 13763 > /sys/class/devfreq/soc:qcom,gpubw/max_freqscip-shell filesystem . . `/sys/class/devfreq/soc:qcom,gpubw/max_freq`.
380 else
381 echoscip-shell system . . echo. "Unable to lock memory bus of $MODEL ($DEVICE)."
382 fi
383
384 echoscip-shell system . . echo. "$DEVICE clocks have been locked - to reset, reboot the device"