blob: 5d0b9f1ec4371bfe299527dc293246673907a1f0 [file] [log] [blame]
csmartdaltonbf41fa82016-09-23 11:36:11 -07001# Copyright 2016 Google Inc.
2#
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6from _hardware import HardwareException, Expectation
7from _hardware_android import HardwareAndroid
8
Kevin Lubicka3ecaf52018-03-14 11:01:03 -04009CPU_CLOCK_RATE = 1326000
10# If you run adb cat /sys/devices/57000000.gpu/pstate it shows all
11# possible configurations, with a * next to the current one.
12GPU_EMC_PROFILE = '04: core 307 MHz emc 1065 MHz a A d D *'
13GPU_EMC_PROFILE_ID = '04'
csmartdaltonbf41fa82016-09-23 11:36:11 -070014
15class HardwarePixelC(HardwareAndroid):
16 def __init__(self, adb):
17 HardwareAndroid.__init__(self, adb)
18
19 def __enter__(self):
Chris Dalton34d90552017-10-20 09:58:32 -060020 HardwareAndroid.__enter__(self)
csmartdaltone4fd0782016-11-09 08:41:23 -080021 if not self._adb.is_root():
Chris Dalton49b7ed32017-10-23 17:19:37 -060022 return self
csmartdaltonbf41fa82016-09-23 11:36:11 -070023
csmartdaltone4fd0782016-11-09 08:41:23 -080024 self._adb.shell('\n'.join([
Kevin Lubicka3ecaf52018-03-14 11:01:03 -040025 # pylint: disable=line-too-long
26 # Based on https://android.googlesource.com/platform/frameworks/base/+/master/libs/hwui/tests/scripts/prep_ryu.sh
27 # All CPUs have the same scaling settings, so we only need to set it once
csmartdaltone4fd0782016-11-09 08:41:23 -080028 '''
Kevin Lubicka3ecaf52018-03-14 11:01:03 -040029 stop thermal-engine
30 stop perfd
csmartdaltonb87642e2016-11-09 12:26:31 -080031
Kevin Lubicka3ecaf52018-03-14 11:01:03 -040032 echo userspace > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
33 echo %i > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
34 echo %i > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
35 echo %i > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed
36 ''' % tuple(CPU_CLOCK_RATE for _ in range(3)),
37 # turn off the fourth core. This will hopefully produce less heat, allowing
38 # for more consistent results. 3 cores should be enough to run Ganesh,
39 # the graphics driver, and the OS.
csmartdaltonb87642e2016-11-09 12:26:31 -080040 '''
41 echo 0 > /sys/devices/system/cpu/cpu3/online''',
csmartdaltonbf41fa82016-09-23 11:36:11 -070042
csmartdaltone4fd0782016-11-09 08:41:23 -080043 # lock gpu/emc clocks.
44 '''
csmartdaltonbf41fa82016-09-23 11:36:11 -070045 chown root:root /sys/devices/57000000.gpu/pstate
csmartdaltone4fd0782016-11-09 08:41:23 -080046 echo %s > /sys/devices/57000000.gpu/pstate''' % GPU_EMC_PROFILE_ID]))
csmartdaltonbf41fa82016-09-23 11:36:11 -070047
Chris Dalton49b7ed32017-10-23 17:19:37 -060048 return self
csmartdaltonbf41fa82016-09-23 11:36:11 -070049
Chris Dalton49b7ed32017-10-23 17:19:37 -060050 def filter_line(self, line):
51 JUNK = ['NvRmPrivGetChipPlatform: Could not read platform information',
52 'Expected on kernels without fuse support, using silicon']
53 return False if line in JUNK else HardwareAndroid.filter_line(self, line)
csmartdaltonbf41fa82016-09-23 11:36:11 -070054
55 def sanity_check(self):
56 HardwareAndroid.sanity_check(self)
57
csmartdaltone4fd0782016-11-09 08:41:23 -080058 if not self._adb.is_root():
csmartdaltonbf41fa82016-09-23 11:36:11 -070059 return
60
61 # only issue one shell command in an attempt to minimize interference.
csmartdaltone4fd0782016-11-09 08:41:23 -080062 result = self._adb.check('''\
csmartdaltonbf41fa82016-09-23 11:36:11 -070063 cat /sys/class/power_supply/bq27742-0/capacity \
csmartdaltonb87642e2016-11-09 12:26:31 -080064 /sys/devices/system/cpu/online \
csmartdaltonbf41fa82016-09-23 11:36:11 -070065 /sys/class/thermal/thermal_zone7/temp \
66 /sys/class/thermal/thermal_zone0/temp \
67 /sys/class/thermal/thermal_zone1/temp \
68 /sys/class/thermal/thermal_zone7/cdev1/cur_state \
69 /sys/class/thermal/thermal_zone7/cdev0/cur_state
csmartdaltonb87642e2016-11-09 12:26:31 -080070 for N in 0 1 2; do
csmartdaltonbf41fa82016-09-23 11:36:11 -070071 cat /sys/devices/system/cpu/cpu$N/cpufreq/scaling_cur_freq
72 done
73 cat /sys/devices/57000000.gpu/pstate | grep \*$''')
74
75 expectations = \
76 [Expectation(int, min_value=30, name='battery', sleeptime=30*60),
csmartdaltonb87642e2016-11-09 12:26:31 -080077 Expectation(str, exact_value='0-2', name='online cpus'),
csmartdaltonbf41fa82016-09-23 11:36:11 -070078 Expectation(int, max_value=40000, name='skin temperature'),
79 Expectation(int, max_value=86000, name='cpu temperature'),
80 Expectation(int, max_value=87000, name='gpu temperature'),
81 Expectation(int, exact_value=0, name='cpu throttle'),
82 Expectation(int, exact_value=0, name='gpu throttle')] + \
83 [Expectation(int, exact_value=CPU_CLOCK_RATE,
84 name='cpu_%i clock rate' % i, sleeptime=30)
csmartdaltonb87642e2016-11-09 12:26:31 -080085 for i in (0, 1, 2)] + \
csmartdaltonbf41fa82016-09-23 11:36:11 -070086 [Expectation(str, exact_value=GPU_EMC_PROFILE, name='gpu/emc profile')]
87
csmartdaltone4fd0782016-11-09 08:41:23 -080088 Expectation.check_all(expectations, result.splitlines())