Debian Codegraph @

infra/bots/recipe_modules/flavor/resources/set_cpu_online.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 cpu = int(sys.argv[2])
13 value = int(sys.argv[3])
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 # If we try to echo 1 to an already online cpu, adb returns exit code 1.
22 # So, check the value before trying to write it.
23 prior_status = subprocess.check_output([ADB, 'shell', 'cat '
24 '/sys/devices/system/cpu/cpu%d/online' % cpu]).decode('utf-8').strip()
25 if prior_status == str(value):
26 print('CPU %d online already %d' % (cpu, value))
27 sys.exit()
28
29 subprocess.check_call([ADB, 'shell', 'echo %s > '
30 '/sys/devices/system/cpu/cpu%d/online' % (value, cpu)])
31 actual_status = subprocess.check_output([ADB, 'shell', 'cat '
32 '/sys/devices/system/cpu/cpu%d/online' % cpu]).decode('utf-8').strip()
33 if actual_status != str(value):
34 raise Exception('(actual, expected) (%s, %d)' % (actual_status, value))