csmartdalton | bf41fa8 | 2016-09-23 11:36:11 -0700 | [diff] [blame] | 1 | # 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 | |
| 6 | from _hardware import HardwareException, Expectation |
| 7 | from _hardware_android import HardwareAndroid |
| 8 | |
Kevin Lubick | a3ecaf5 | 2018-03-14 11:01:03 -0400 | [diff] [blame] | 9 | CPU_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. |
| 12 | GPU_EMC_PROFILE = '04: core 307 MHz emc 1065 MHz a A d D *' |
| 13 | GPU_EMC_PROFILE_ID = '04' |
csmartdalton | bf41fa8 | 2016-09-23 11:36:11 -0700 | [diff] [blame] | 14 | |
| 15 | class HardwarePixelC(HardwareAndroid): |
| 16 | def __init__(self, adb): |
| 17 | HardwareAndroid.__init__(self, adb) |
| 18 | |
| 19 | def __enter__(self): |
Chris Dalton | 34d9055 | 2017-10-20 09:58:32 -0600 | [diff] [blame] | 20 | HardwareAndroid.__enter__(self) |
csmartdalton | e4fd078 | 2016-11-09 08:41:23 -0800 | [diff] [blame] | 21 | if not self._adb.is_root(): |
Chris Dalton | 49b7ed3 | 2017-10-23 17:19:37 -0600 | [diff] [blame] | 22 | return self |
csmartdalton | bf41fa8 | 2016-09-23 11:36:11 -0700 | [diff] [blame] | 23 | |
csmartdalton | e4fd078 | 2016-11-09 08:41:23 -0800 | [diff] [blame] | 24 | self._adb.shell('\n'.join([ |
Kevin Lubick | a3ecaf5 | 2018-03-14 11:01:03 -0400 | [diff] [blame] | 25 | # 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 |
csmartdalton | e4fd078 | 2016-11-09 08:41:23 -0800 | [diff] [blame] | 28 | ''' |
Kevin Lubick | a3ecaf5 | 2018-03-14 11:01:03 -0400 | [diff] [blame] | 29 | stop thermal-engine |
| 30 | stop perfd |
csmartdalton | b87642e | 2016-11-09 12:26:31 -0800 | [diff] [blame] | 31 | |
Kevin Lubick | a3ecaf5 | 2018-03-14 11:01:03 -0400 | [diff] [blame] | 32 | 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. |
csmartdalton | b87642e | 2016-11-09 12:26:31 -0800 | [diff] [blame] | 40 | ''' |
| 41 | echo 0 > /sys/devices/system/cpu/cpu3/online''', |
csmartdalton | bf41fa8 | 2016-09-23 11:36:11 -0700 | [diff] [blame] | 42 | |
csmartdalton | e4fd078 | 2016-11-09 08:41:23 -0800 | [diff] [blame] | 43 | # lock gpu/emc clocks. |
| 44 | ''' |
csmartdalton | bf41fa8 | 2016-09-23 11:36:11 -0700 | [diff] [blame] | 45 | chown root:root /sys/devices/57000000.gpu/pstate |
csmartdalton | e4fd078 | 2016-11-09 08:41:23 -0800 | [diff] [blame] | 46 | echo %s > /sys/devices/57000000.gpu/pstate''' % GPU_EMC_PROFILE_ID])) |
csmartdalton | bf41fa8 | 2016-09-23 11:36:11 -0700 | [diff] [blame] | 47 | |
Chris Dalton | 49b7ed3 | 2017-10-23 17:19:37 -0600 | [diff] [blame] | 48 | return self |
csmartdalton | bf41fa8 | 2016-09-23 11:36:11 -0700 | [diff] [blame] | 49 | |
Chris Dalton | 49b7ed3 | 2017-10-23 17:19:37 -0600 | [diff] [blame] | 50 | 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) |
csmartdalton | bf41fa8 | 2016-09-23 11:36:11 -0700 | [diff] [blame] | 54 | |
| 55 | def sanity_check(self): |
| 56 | HardwareAndroid.sanity_check(self) |
| 57 | |
csmartdalton | e4fd078 | 2016-11-09 08:41:23 -0800 | [diff] [blame] | 58 | if not self._adb.is_root(): |
csmartdalton | bf41fa8 | 2016-09-23 11:36:11 -0700 | [diff] [blame] | 59 | return |
| 60 | |
| 61 | # only issue one shell command in an attempt to minimize interference. |
csmartdalton | e4fd078 | 2016-11-09 08:41:23 -0800 | [diff] [blame] | 62 | result = self._adb.check('''\ |
csmartdalton | bf41fa8 | 2016-09-23 11:36:11 -0700 | [diff] [blame] | 63 | cat /sys/class/power_supply/bq27742-0/capacity \ |
csmartdalton | b87642e | 2016-11-09 12:26:31 -0800 | [diff] [blame] | 64 | /sys/devices/system/cpu/online \ |
csmartdalton | bf41fa8 | 2016-09-23 11:36:11 -0700 | [diff] [blame] | 65 | /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 |
csmartdalton | b87642e | 2016-11-09 12:26:31 -0800 | [diff] [blame] | 70 | for N in 0 1 2; do |
csmartdalton | bf41fa8 | 2016-09-23 11:36:11 -0700 | [diff] [blame] | 71 | 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), |
csmartdalton | b87642e | 2016-11-09 12:26:31 -0800 | [diff] [blame] | 77 | Expectation(str, exact_value='0-2', name='online cpus'), |
csmartdalton | bf41fa8 | 2016-09-23 11:36:11 -0700 | [diff] [blame] | 78 | 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) |
csmartdalton | b87642e | 2016-11-09 12:26:31 -0800 | [diff] [blame] | 85 | for i in (0, 1, 2)] + \ |
csmartdalton | bf41fa8 | 2016-09-23 11:36:11 -0700 | [diff] [blame] | 86 | [Expectation(str, exact_value=GPU_EMC_PROFILE, name='gpu/emc profile')] |
| 87 | |
csmartdalton | e4fd078 | 2016-11-09 08:41:23 -0800 | [diff] [blame] | 88 | Expectation.check_all(expectations, result.splitlines()) |