Debian Codegraph @

infra/bots/recipe_modules/flavor/resources/set_gpu_scaling.py

raw
1 # Copyright 2024 Google LLC
2 #
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 import os
7 import subprocess
8 import sys
9 import time
10
11 ADB = sys.argv[1]
12 freq = sys.argv[2]
13 idle_timer = "10000"
14
15 log = subprocess.check_output([ADB, 'root']).decode('utf-8')
16 # check for message like 'adbd cannot run as root in production builds'
17 print(log)
18 if 'cannot' in log:
19 raise Exception('adb root failed')
20
21 subprocess.check_output([ADB, 'shell', 'stop', 'thermald']).decode('utf-8')
22
23 subprocess.check_output([ADB, 'shell', 'echo "%s" > '
24 '/sys/class/kgsl/kgsl-3d0/gpuclk' % freq]).decode('utf-8')
25
26 actual_freq = subprocess.check_output([ADB, 'shell', 'cat '
27 '/sys/class/kgsl/kgsl-3d0/gpuclk']).decode('utf-8').strip()
28 if actual_freq != freq:
29 raise Exception('Frequency (actual, expected) (%s, %s)'
30 % (actual_freq, freq))
31
32 subprocess.check_call([ADB, 'shell', 'echo "%s" > '
33 '/sys/class/kgsl/kgsl-3d0/idle_timer' % idle_timer])
34
35 actual_timer = subprocess.check_output([ADB, 'shell', 'cat '
36 '/sys/class/kgsl/kgsl-3d0/idle_timer']).decode('utf-8').strip()
37 if actual_timer != idle_timer:
38 raise Exception('idle_timer (actual, expected) (%s, %s)'
39 % (actual_timer, idle_timer))
40
41 for s in ['force_bus_on', 'force_rail_on', 'force_clk_on']:
42 subprocess.check_call([ADB, 'shell', 'echo "1" > '
43 '/sys/class/kgsl/kgsl-3d0/%s' % s])
44 actual_set = subprocess.check_output([ADB, 'shell', 'cat '
45 '/sys/class/kgsl/kgsl-3d0/%s' % s]).decode('utf-8').strip()
46 if actual_set != "1":
47 raise Exception('%s (actual, expected) (%s, 1)'
48 % (s, actual_set))