_hardware_pixel_c.py 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. from _hardware import HardwareException, Expectation
  6. from _hardware_android import HardwareAndroid
  7. CPU_CLOCK_RATE = 1326000
  8. # If you run adb cat /sys/devices/57000000.gpu/pstate it shows all
  9. # possible configurations, with a * next to the current one.
  10. GPU_EMC_PROFILE = '04: core 307 MHz emc 1065 MHz a A d D *'
  11. GPU_EMC_PROFILE_ID = '04'
  12. class HardwarePixelC(HardwareAndroid):
  13. def __init__(self, adb):
  14. HardwareAndroid.__init__(self, adb)
  15. def __enter__(self):
  16. HardwareAndroid.__enter__(self)
  17. if not self._adb.is_root():
  18. return self
  19. self._adb.shell('\n'.join([
  20. # pylint: disable=line-too-long
  21. # Based on https://android.googlesource.com/platform/frameworks/base/+/master/libs/hwui/tests/scripts/prep_ryu.sh
  22. # All CPUs have the same scaling settings, so we only need to set it once
  23. '''
  24. stop thermal-engine
  25. stop perfd
  26. echo userspace > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
  27. echo %i > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
  28. echo %i > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
  29. echo %i > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed
  30. ''' % tuple(CPU_CLOCK_RATE for _ in range(3)),
  31. # turn off the fourth core. This will hopefully produce less heat, allowing
  32. # for more consistent results. 3 cores should be enough to run Ganesh,
  33. # the graphics driver, and the OS.
  34. '''
  35. echo 0 > /sys/devices/system/cpu/cpu3/online''',
  36. # lock gpu/emc clocks.
  37. '''
  38. chown root:root /sys/devices/57000000.gpu/pstate
  39. echo %s > /sys/devices/57000000.gpu/pstate''' % GPU_EMC_PROFILE_ID]))
  40. return self
  41. def filter_line(self, line):
  42. JUNK = ['NvRmPrivGetChipPlatform: Could not read platform information',
  43. 'Expected on kernels without fuse support, using silicon']
  44. return False if line in JUNK else HardwareAndroid.filter_line(self, line)
  45. def sanity_check(self):
  46. HardwareAndroid.sanity_check(self)
  47. if not self._adb.is_root():
  48. return
  49. # only issue one shell command in an attempt to minimize interference.
  50. result = self._adb.check('''\
  51. cat /sys/class/power_supply/bq27742-0/capacity \
  52. /sys/devices/system/cpu/online \
  53. /sys/class/thermal/thermal_zone7/temp \
  54. /sys/class/thermal/thermal_zone0/temp \
  55. /sys/class/thermal/thermal_zone1/temp \
  56. /sys/class/thermal/thermal_zone7/cdev1/cur_state \
  57. /sys/class/thermal/thermal_zone7/cdev0/cur_state
  58. for N in 0 1 2; do
  59. cat /sys/devices/system/cpu/cpu$N/cpufreq/scaling_cur_freq
  60. done
  61. cat /sys/devices/57000000.gpu/pstate | grep \*$''')
  62. expectations = \
  63. [Expectation(int, min_value=30, name='battery', sleeptime=30*60),
  64. Expectation(str, exact_value='0-2', name='online cpus'),
  65. Expectation(int, max_value=40000, name='skin temperature'),
  66. Expectation(int, max_value=86000, name='cpu temperature'),
  67. Expectation(int, max_value=87000, name='gpu temperature'),
  68. Expectation(int, exact_value=0, name='cpu throttle'),
  69. Expectation(int, exact_value=0, name='gpu throttle')] + \
  70. [Expectation(int, exact_value=CPU_CLOCK_RATE,
  71. name='cpu_%i clock rate' % i, sleeptime=30)
  72. for i in (0, 1, 2)] + \
  73. [Expectation(str, exact_value=GPU_EMC_PROFILE, name='gpu/emc profile')]
  74. Expectation.check_all(expectations, result.splitlines())