Chris Dalton | 34d9055 | 2017-10-20 09:58:32 -0600 | [diff] [blame] | 1 | # Copyright 2017 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 | |
Chris Dalton | 117d972 | 2018-04-27 17:10:39 -0600 | [diff] [blame] | 6 | from _hardware import Expectation |
Chris Dalton | 34d9055 | 2017-10-20 09:58:32 -0600 | [diff] [blame] | 7 | from _hardware_android import HardwareAndroid |
Chris Dalton | 34d9055 | 2017-10-20 09:58:32 -0600 | [diff] [blame] | 8 | |
| 9 | CPU_CLOCK_RATE = 1670400 |
Kevin Lubick | 08b44fa | 2018-03-07 08:22:53 -0500 | [diff] [blame] | 10 | GPU_CLOCK_RATE = 315000000 |
Chris Dalton | 34d9055 | 2017-10-20 09:58:32 -0600 | [diff] [blame] | 11 | |
Chris Dalton | 34d9055 | 2017-10-20 09:58:32 -0600 | [diff] [blame] | 12 | class HardwarePixel(HardwareAndroid): |
| 13 | def __init__(self, adb): |
| 14 | HardwareAndroid.__init__(self, adb) |
Chris Dalton | 34d9055 | 2017-10-20 09:58:32 -0600 | [diff] [blame] | 15 | |
| 16 | def __enter__(self): |
| 17 | HardwareAndroid.__enter__(self) |
Chris Dalton | 34d9055 | 2017-10-20 09:58:32 -0600 | [diff] [blame] | 18 | if not self._adb.is_root(): |
Chris Dalton | 49b7ed3 | 2017-10-23 17:19:37 -0600 | [diff] [blame] | 19 | return self |
Chris Dalton | 34d9055 | 2017-10-20 09:58:32 -0600 | [diff] [blame] | 20 | |
Kevin Lubick | 4f16db6 | 2018-03-01 10:13:44 -0500 | [diff] [blame] | 21 | self._adb.shell('\n'.join([ |
Chris Dalton | 34d9055 | 2017-10-20 09:58:32 -0600 | [diff] [blame] | 22 | # enable and lock the two fast cores. |
| 23 | ''' |
Kevin Lubick | 08b44fa | 2018-03-07 08:22:53 -0500 | [diff] [blame] | 24 | stop thermal-engine |
| 25 | stop perfd |
| 26 | |
Chris Dalton | 34d9055 | 2017-10-20 09:58:32 -0600 | [diff] [blame] | 27 | for N in 3 2; do |
| 28 | echo 1 > /sys/devices/system/cpu/cpu$N/online |
| 29 | echo userspace > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_governor |
| 30 | echo %i > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_max_freq |
| 31 | echo %i > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_min_freq |
| 32 | echo %i > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_setspeed |
| 33 | done''' % tuple(CPU_CLOCK_RATE for _ in range(3)), |
| 34 | |
| 35 | # turn off the two slow cores |
| 36 | ''' |
| 37 | for N in 1 0; do |
| 38 | echo 0 > /sys/devices/system/cpu/cpu$N/online |
| 39 | done''', |
| 40 | |
Kevin Lubick | 08b44fa | 2018-03-07 08:22:53 -0500 | [diff] [blame] | 41 | # pylint: disable=line-too-long |
| 42 | |
| 43 | # Set GPU bus and idle timer |
| 44 | # Set DDR frequency to max |
| 45 | # Set GPU to performance mode, 315 MHZ |
| 46 | # See https://android.googlesource.com/platform/frameworks/base/+/master/libs/hwui/tests/scripts/prep_marlfish.sh |
Chris Dalton | 34d9055 | 2017-10-20 09:58:32 -0600 | [diff] [blame] | 47 | ''' |
| 48 | echo 0 > /sys/class/kgsl/kgsl-3d0/bus_split |
Chris Dalton | 34d9055 | 2017-10-20 09:58:32 -0600 | [diff] [blame] | 49 | echo 1 > /sys/class/kgsl/kgsl-3d0/force_clk_on |
Kevin Lubick | 08b44fa | 2018-03-07 08:22:53 -0500 | [diff] [blame] | 50 | echo 10000 > /sys/class/kgsl/kgsl-3d0/idle_timer |
| 51 | |
| 52 | echo 13763 > /sys/class/devfreq/soc:qcom,gpubw/min_freq |
| 53 | |
| 54 | echo performance > /sys/class/kgsl/kgsl-3d0/devfreq/governor |
Chris Dalton | 34d9055 | 2017-10-20 09:58:32 -0600 | [diff] [blame] | 55 | echo %i > /sys/class/kgsl/kgsl-3d0/devfreq/max_freq |
| 56 | echo %i > /sys/class/kgsl/kgsl-3d0/devfreq/min_freq |
Chris Dalton | 34d9055 | 2017-10-20 09:58:32 -0600 | [diff] [blame] | 57 | |
Kevin Lubick | 08b44fa | 2018-03-07 08:22:53 -0500 | [diff] [blame] | 58 | echo 4 > /sys/class/kgsl/kgsl-3d0/max_pwrlevel |
| 59 | echo 4 > /sys/class/kgsl/kgsl-3d0/min_pwrlevel''' % |
| 60 | tuple(GPU_CLOCK_RATE for _ in range(2))])) |
Chris Dalton | 34d9055 | 2017-10-20 09:58:32 -0600 | [diff] [blame] | 61 | |
Chris Dalton | 49b7ed3 | 2017-10-23 17:19:37 -0600 | [diff] [blame] | 62 | return self |
Chris Dalton | 34d9055 | 2017-10-20 09:58:32 -0600 | [diff] [blame] | 63 | |
| 64 | def sanity_check(self): |
| 65 | HardwareAndroid.sanity_check(self) |
| 66 | |
| 67 | if not self._adb.is_root(): |
| 68 | return |
| 69 | |
| 70 | result = self._adb.check(' '.join( |
| 71 | ['cat', |
| 72 | '/sys/class/power_supply/battery/capacity', |
| 73 | '/sys/devices/system/cpu/online'] + \ |
| 74 | ['/sys/devices/system/cpu/cpu%i/cpufreq/scaling_cur_freq' % i |
| 75 | for i in range(2, 4)] + \ |
Kevin Lubick | 08b44fa | 2018-03-07 08:22:53 -0500 | [diff] [blame] | 76 | ['/sys/kernel/debug/clk/bimc_clk/measure', |
Chris Dalton | 34d9055 | 2017-10-20 09:58:32 -0600 | [diff] [blame] | 77 | '/sys/class/thermal/thermal_zone22/temp', |
Kevin Lubick | 08b44fa | 2018-03-07 08:22:53 -0500 | [diff] [blame] | 78 | '/sys/class/thermal/thermal_zone23/temp'])) |
Chris Dalton | 34d9055 | 2017-10-20 09:58:32 -0600 | [diff] [blame] | 79 | |
| 80 | expectations = \ |
| 81 | [Expectation(int, min_value=30, name='battery', sleeptime=30*60), |
| 82 | Expectation(str, exact_value='2-3', name='online cpus')] + \ |
| 83 | [Expectation(int, exact_value=CPU_CLOCK_RATE, name='cpu_%i clock rate' %i) |
| 84 | for i in range(2, 4)] + \ |
Kevin Lubick | 08b44fa | 2018-03-07 08:22:53 -0500 | [diff] [blame] | 85 | [Expectation(long, min_value=902390000, max_value=902409999, |
Chris Dalton | 34d9055 | 2017-10-20 09:58:32 -0600 | [diff] [blame] | 86 | name='measured ddr clock', sleeptime=10), |
| 87 | Expectation(int, max_value=41000, name='pm8994_tz temperature'), |
Kevin Lubick | 08b44fa | 2018-03-07 08:22:53 -0500 | [diff] [blame] | 88 | Expectation(int, max_value=40, name='msm_therm temperature')] |
Chris Dalton | 34d9055 | 2017-10-20 09:58:32 -0600 | [diff] [blame] | 89 | |
| 90 | Expectation.check_all(expectations, result.splitlines()) |