blob: 02465b0186634920803374d2a70654b80cab6fdc [file] [log] [blame]
Chris Dalton34d90552017-10-20 09:58:32 -06001# 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
6from _hardware import HardwareException, Expectation
7from _hardware_android import HardwareAndroid
8from collections import namedtuple
9import itertools
10
11CPU_CLOCK_RATE = 1670400
Kevin Lubick08b44fa2018-03-07 08:22:53 -050012GPU_CLOCK_RATE = 315000000
Chris Dalton34d90552017-10-20 09:58:32 -060013
14DEVFREQ_DIRNAME = '/sys/class/devfreq'
15DEVFREQ_THROTTLE = 0.74
16DEVFREQ_BLACKLIST = ('b00000.qcom,kgsl-3d0', 'soc:qcom,kgsl-busmon',
17 'soc:qcom,m4m')
18DevfreqKnobs = namedtuple('knobs',
19 ('available_governors', 'available_frequencies',
20 'governor', 'min_freq', 'max_freq', 'cur_freq'))
21
22class HardwarePixel(HardwareAndroid):
23 def __init__(self, adb):
24 HardwareAndroid.__init__(self, adb)
25 self._discover_devfreqs()
26
27 def __enter__(self):
28 HardwareAndroid.__enter__(self)
Chris Dalton34d90552017-10-20 09:58:32 -060029 if not self._adb.is_root():
Chris Dalton49b7ed32017-10-23 17:19:37 -060030 return self
Chris Dalton34d90552017-10-20 09:58:32 -060031
Kevin Lubick4f16db62018-03-01 10:13:44 -050032 self._adb.shell('\n'.join([
Chris Dalton34d90552017-10-20 09:58:32 -060033 # enable and lock the two fast cores.
34 '''
Kevin Lubick08b44fa2018-03-07 08:22:53 -050035 stop thermal-engine
36 stop perfd
37
Chris Dalton34d90552017-10-20 09:58:32 -060038 for N in 3 2; do
39 echo 1 > /sys/devices/system/cpu/cpu$N/online
40 echo userspace > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_governor
41 echo %i > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_max_freq
42 echo %i > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_min_freq
43 echo %i > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_setspeed
44 done''' % tuple(CPU_CLOCK_RATE for _ in range(3)),
45
46 # turn off the two slow cores
47 '''
48 for N in 1 0; do
49 echo 0 > /sys/devices/system/cpu/cpu$N/online
50 done''',
51
Kevin Lubick08b44fa2018-03-07 08:22:53 -050052 # pylint: disable=line-too-long
53
54 # Set GPU bus and idle timer
55 # Set DDR frequency to max
56 # Set GPU to performance mode, 315 MHZ
57 # See https://android.googlesource.com/platform/frameworks/base/+/master/libs/hwui/tests/scripts/prep_marlfish.sh
Chris Dalton34d90552017-10-20 09:58:32 -060058 '''
59 echo 0 > /sys/class/kgsl/kgsl-3d0/bus_split
Chris Dalton34d90552017-10-20 09:58:32 -060060 echo 1 > /sys/class/kgsl/kgsl-3d0/force_clk_on
Kevin Lubick08b44fa2018-03-07 08:22:53 -050061 echo 10000 > /sys/class/kgsl/kgsl-3d0/idle_timer
62
63 echo 13763 > /sys/class/devfreq/soc:qcom,gpubw/min_freq
64
65 echo performance > /sys/class/kgsl/kgsl-3d0/devfreq/governor
Chris Dalton34d90552017-10-20 09:58:32 -060066 echo %i > /sys/class/kgsl/kgsl-3d0/devfreq/max_freq
67 echo %i > /sys/class/kgsl/kgsl-3d0/devfreq/min_freq
Chris Dalton34d90552017-10-20 09:58:32 -060068
Kevin Lubick08b44fa2018-03-07 08:22:53 -050069 echo 4 > /sys/class/kgsl/kgsl-3d0/max_pwrlevel
70 echo 4 > /sys/class/kgsl/kgsl-3d0/min_pwrlevel''' %
71 tuple(GPU_CLOCK_RATE for _ in range(2))]))
Chris Dalton34d90552017-10-20 09:58:32 -060072
Chris Dalton49b7ed32017-10-23 17:19:37 -060073 return self
Chris Dalton34d90552017-10-20 09:58:32 -060074
75 def sanity_check(self):
76 HardwareAndroid.sanity_check(self)
77
78 if not self._adb.is_root():
79 return
80
81 result = self._adb.check(' '.join(
82 ['cat',
83 '/sys/class/power_supply/battery/capacity',
84 '/sys/devices/system/cpu/online'] + \
85 ['/sys/devices/system/cpu/cpu%i/cpufreq/scaling_cur_freq' % i
86 for i in range(2, 4)] + \
Kevin Lubick08b44fa2018-03-07 08:22:53 -050087 ['/sys/kernel/debug/clk/bimc_clk/measure',
Chris Dalton34d90552017-10-20 09:58:32 -060088 '/sys/class/thermal/thermal_zone22/temp',
Kevin Lubick08b44fa2018-03-07 08:22:53 -050089 '/sys/class/thermal/thermal_zone23/temp']))
Chris Dalton34d90552017-10-20 09:58:32 -060090
91 expectations = \
92 [Expectation(int, min_value=30, name='battery', sleeptime=30*60),
93 Expectation(str, exact_value='2-3', name='online cpus')] + \
94 [Expectation(int, exact_value=CPU_CLOCK_RATE, name='cpu_%i clock rate' %i)
95 for i in range(2, 4)] + \
Kevin Lubick08b44fa2018-03-07 08:22:53 -050096 [Expectation(long, min_value=902390000, max_value=902409999,
Chris Dalton34d90552017-10-20 09:58:32 -060097 name='measured ddr clock', sleeptime=10),
98 Expectation(int, max_value=41000, name='pm8994_tz temperature'),
Kevin Lubick08b44fa2018-03-07 08:22:53 -050099 Expectation(int, max_value=40, name='msm_therm temperature')]
Chris Dalton34d90552017-10-20 09:58:32 -0600100
101 Expectation.check_all(expectations, result.splitlines())
102
103 def _discover_devfreqs(self):
104 self._devfreq_lock_cmds = list()
Chris Dalton34d90552017-10-20 09:58:32 -0600105 self._devfreq_sanity_knobs = list()
106 self._devfreq_sanity_expectations = list()
107
108 results = iter(self._adb.check('''\
109 KNOBS='%s'
110 for DEVICE in %s/*; do
111 if cd $DEVICE && ls $KNOBS >/dev/null; then
112 basename $DEVICE
113 cat $KNOBS
114 fi
115 done 2>/dev/null''' %
116 (' '.join(DevfreqKnobs._fields), DEVFREQ_DIRNAME)).splitlines())
117
118 while True:
119 batch = tuple(itertools.islice(results, 1 + len(DevfreqKnobs._fields)))
120 if not batch:
121 break
122
123 devfreq = batch[0]
124 if devfreq in DEVFREQ_BLACKLIST:
125 continue
126
127 path = '%s/%s' % (DEVFREQ_DIRNAME, devfreq)
128
129 knobs = DevfreqKnobs(*batch[1:])
130 if not 'performance' in knobs.available_governors.split():
131 print('WARNING: devfreq %s does not have performance governor' % path)
132 continue
133
134 self._devfreq_lock_cmds.append('echo performance > %s/governor' % path)
Chris Dalton34d90552017-10-20 09:58:32 -0600135
136 frequencies = map(int, knobs.available_frequencies.split())
137 if frequencies:
138 # choose the lowest frequency that is >= DEVFREQ_THROTTLE * max.
139 frequencies.sort()
140 target = DEVFREQ_THROTTLE * frequencies[-1]
141 idx = len(frequencies) - 1
142 while idx > 0 and frequencies[idx - 1] >= target:
143 idx -= 1
144 bench_frequency = frequencies[idx]
145 self._devfreq_lock_cmds.append('echo %i > %s/min_freq' %
146 (bench_frequency, path))
147 self._devfreq_lock_cmds.append('echo %i > %s/max_freq' %
148 (bench_frequency, path))
Chris Dalton34d90552017-10-20 09:58:32 -0600149 self._devfreq_sanity_knobs.append('%s/cur_freq' % path)
150 self._devfreq_sanity_expectations.append(
151 Expectation(int, exact_value=bench_frequency,
152 name='%s/cur_freq' % path))