• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
6from _hardware import HardwareException, Expectation
7from _hardware_android import HardwareAndroid
8
9CPU_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'
14
15class HardwarePixelC(HardwareAndroid):
16  def __init__(self, adb):
17    HardwareAndroid.__init__(self, adb)
18
19  def __enter__(self):
20    HardwareAndroid.__enter__(self)
21    if not self._adb.is_root():
22      return self
23
24    self._adb.shell('\n'.join([
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
28      '''
29      stop thermal-engine
30      stop perfd
31
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.
40      '''
41      echo 0 > /sys/devices/system/cpu/cpu3/online''',
42
43      # lock gpu/emc clocks.
44      '''
45      chown root:root /sys/devices/57000000.gpu/pstate
46      echo %s > /sys/devices/57000000.gpu/pstate''' % GPU_EMC_PROFILE_ID]))
47
48    return self
49
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)
54
55  def sanity_check(self):
56    HardwareAndroid.sanity_check(self)
57
58    if not self._adb.is_root():
59      return
60
61    # only issue one shell command in an attempt to minimize interference.
62    result = self._adb.check('''\
63      cat /sys/class/power_supply/bq27742-0/capacity \
64          /sys/devices/system/cpu/online \
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
70      for N in 0 1 2; do
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),
77       Expectation(str, exact_value='0-2', name='online cpus'),
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)
85       for i in (0, 1, 2)] + \
86      [Expectation(str, exact_value=GPU_EMC_PROFILE, name='gpu/emc profile')]
87
88    Expectation.check_all(expectations, result.splitlines())
89