Chris Dalton | 117d972 | 2018-04-27 17:10:39 -0600 | [diff] [blame] | 1 | # Copyright 2018 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 Expectation |
| 7 | from _hardware_android import HardwareAndroid |
| 8 | |
| 9 | CPU_CLOCK_RATE = 2035200 |
| 10 | MEM_CLOCK_RATE = 13763 |
| 11 | GPU_CLOCK_RATE = 670000000 |
| 12 | GPU_POWER_LEVEL = 1 # lower is faster, minimum is 0 |
| 13 | |
| 14 | class HardwarePixel2(HardwareAndroid): |
| 15 | def __init__(self, adb): |
| 16 | HardwareAndroid.__init__(self, adb) |
| 17 | |
| 18 | def __enter__(self): |
| 19 | HardwareAndroid.__enter__(self) |
| 20 | if not self._adb.is_root(): |
| 21 | return self |
| 22 | |
| 23 | self._adb.shell('\n'.join([ |
| 24 | ''' |
| 25 | stop thermal-engine |
| 26 | stop perfd''', |
| 27 | |
| 28 | # turn off the slow cores and one fast core |
| 29 | ''' |
| 30 | for N in 0 1 2 3 7; do |
| 31 | echo 0 > /sys/devices/system/cpu/cpu$N/online |
| 32 | done''', |
| 33 | |
| 34 | # lock 3 fast cores: two for Skia and one for the OS |
| 35 | ''' |
| 36 | for N in 4 5 6; do |
| 37 | echo 1 > /sys/devices/system/cpu/cpu$N/online |
| 38 | echo userspace > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_governor |
| 39 | echo %i > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_max_freq |
| 40 | echo %i > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_min_freq |
| 41 | echo %i > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_setspeed |
| 42 | done''' % tuple(CPU_CLOCK_RATE for _ in range(3)), |
| 43 | |
| 44 | # Set GPU bus and idle timer |
| 45 | ''' |
| 46 | echo 0 > /sys/class/kgsl/kgsl-3d0/bus_split''', |
| 47 | # csmartdalton, 4-26-2018: this line hangs my device |
| 48 | # echo 1 > /sys/class/kgsl/kgsl-3d0/force_clk_on |
| 49 | ''' |
| 50 | echo 10000 > /sys/class/kgsl/kgsl-3d0/idle_timer''', |
| 51 | |
| 52 | # Set mem frequency to max |
| 53 | ''' |
| 54 | echo %i > /sys/class/devfreq/soc\:qcom,gpubw/min_freq |
| 55 | echo %i > /sys/class/devfreq/soc\:qcom,gpubw/max_freq |
| 56 | echo %i > /sys/class/devfreq/soc\:qcom,cpubw/min_freq |
| 57 | echo %i > /sys/class/devfreq/soc\:qcom,cpubw/max_freq |
| 58 | echo %i > /sys/class/devfreq/soc\:qcom,mincpubw/min_freq |
| 59 | echo %i > /sys/class/devfreq/soc\:qcom,mincpubw/max_freq |
| 60 | echo %i > /sys/class/devfreq/soc\:qcom,memlat-cpu0/min_freq |
| 61 | echo %i > /sys/class/devfreq/soc\:qcom,memlat-cpu0/max_freq''' % |
| 62 | tuple(MEM_CLOCK_RATE for _ in range(8)), |
| 63 | |
| 64 | # Set GPU to performance mode |
| 65 | ''' |
| 66 | echo performance > /sys/class/kgsl/kgsl-3d0/devfreq/governor |
| 67 | echo %i > /sys/class/kgsl/kgsl-3d0/devfreq/max_freq |
| 68 | echo %i > /sys/class/kgsl/kgsl-3d0/devfreq/min_freq''' % |
| 69 | tuple(GPU_CLOCK_RATE for _ in range(2)), |
| 70 | |
| 71 | # Set GPU power level |
| 72 | ''' |
| 73 | echo %i > /sys/class/kgsl/kgsl-3d0/max_pwrlevel |
| 74 | echo %i > /sys/class/kgsl/kgsl-3d0/min_pwrlevel''' % |
| 75 | tuple(GPU_POWER_LEVEL for _ in range(2))])) |
| 76 | |
| 77 | assert('msm_therm' == self._adb.check(\ |
| 78 | 'cat /sys/class/thermal/thermal_zone10/type').strip()) |
| 79 | assert('pm8998_tz' == self._adb.check(\ |
| 80 | 'cat /sys/class/thermal/thermal_zone7/type').strip()) |
| 81 | |
| 82 | return self |
| 83 | |
| 84 | def sanity_check(self): |
| 85 | HardwareAndroid.sanity_check(self) |
| 86 | |
| 87 | if not self._adb.is_root(): |
| 88 | return |
| 89 | |
| 90 | result = self._adb.check(' '.join( |
| 91 | ['cat', |
| 92 | '/sys/class/power_supply/battery/capacity', |
| 93 | '/sys/devices/system/cpu/online'] + \ |
| 94 | ['/sys/devices/system/cpu/cpu%i/cpufreq/scaling_cur_freq' % i |
| 95 | for i in range(4, 7)] + \ |
| 96 | # Unfortunately we can't monitor the gpu clock: |
| 97 | # |
| 98 | # /sys/class/kgsl/kgsl-3d0/devfreq/cur_freq |
| 99 | # |
| 100 | # It doesn't respect the min_freq/max_freq values when not under load. |
| 101 | ['/sys/kernel/debug/clk/bimc_clk/measure', |
| 102 | '/sys/class/kgsl/kgsl-3d0/temp', |
| 103 | '/sys/class/kgsl/kgsl-3d0/throttling', |
| 104 | '/sys/class/thermal/thermal_zone10/temp', |
| 105 | '/sys/class/thermal/thermal_zone7/temp'])) |
| 106 | |
| 107 | expectations = \ |
| 108 | [Expectation(int, min_value=30, name='battery', sleeptime=30*60), |
| 109 | Expectation(str, exact_value='4-6', name='online cpus')] + \ |
| 110 | [Expectation(int, exact_value=CPU_CLOCK_RATE, name='cpu_%i clock rate' %i) |
| 111 | for i in range(4, 7)] + \ |
| 112 | [Expectation(long, min_value=902390000, max_value=902409999, |
| 113 | name='measured ddr clock', sleeptime=10), |
| 114 | Expectation(int, max_value=750, name='gpu temperature'), |
| 115 | Expectation(int, exact_value=1, name='gpu throttling'), |
| 116 | Expectation(int, max_value=75, name='msm_therm temperature'), |
| 117 | Expectation(int, max_value=75000, name='pm8998_tz temperature')] |
| 118 | |
| 119 | Expectation.check_all(expectations, result.splitlines()) |