Home | History | Annotate | Download | only in skpbench
      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 
      6 from _hardware import HardwareException, Expectation
      7 from _hardware_android import HardwareAndroid
      8 
      9 CPU_CLOCK_RATE = 1836000
     10 GPU_EMC_PROFILE = '0c: core 921 MHz emc 1600 MHz a A d D *'
     11 GPU_EMC_PROFILE_ID = '0c'
     12 
     13 class HardwarePixelC(HardwareAndroid):
     14   def __init__(self, adb):
     15     HardwareAndroid.__init__(self, adb)
     16 
     17   def __enter__(self):
     18     self._lock_clocks()
     19     return HardwareAndroid.__enter__(self)
     20 
     21   def __exit__(self, exception_type, exception_value, exception_traceback):
     22     HardwareAndroid.__exit__(self, exception_type,
     23                              exception_value, exception_traceback)
     24     self._unlock_clocks()
     25 
     26   def filter_line(self, line):
     27     JUNK = ['NvRmPrivGetChipPlatform: Could not read platform information',
     28             'Expected on kernels without fuse support, using silicon']
     29     return False if line in JUNK else HardwareAndroid.filter_line(self, line)
     30 
     31   def _lock_clocks(self):
     32     if not self._adb.is_root():
     33       return
     34 
     35     self._adb.shell('\n'.join([
     36       # turn on and lock the first 3 cores.
     37       '''
     38       for N in 0 1 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 fourth core.
     47       '''
     48       echo 0 > /sys/devices/system/cpu/cpu3/online''',
     49 
     50       # lock gpu/emc clocks.
     51       '''
     52       chown root:root /sys/devices/57000000.gpu/pstate
     53       echo %s > /sys/devices/57000000.gpu/pstate''' % GPU_EMC_PROFILE_ID]))
     54 
     55   def _unlock_clocks(self):
     56     if not self._adb.is_root():
     57       return
     58 
     59     self._adb.shell('\n'.join([
     60       # unlock gpu/emc clocks.
     61       '''
     62       echo auto > /sys/devices/57000000.gpu/pstate
     63       chown system:system /sys/devices/57000000.gpu/pstate''',
     64 
     65       # turn the fourth core back on.
     66       '''
     67       echo 1 > /sys/devices/system/cpu/cpu3/online''',
     68 
     69       # unlock the first 3 cores.
     70       '''
     71       for N in 2 1 0; do
     72         echo 1912500 > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_max_freq
     73         echo 51000 > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_min_freq
     74         echo 0 > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_setspeed
     75         echo interactive >/sys/devices/system/cpu/cpu$N/cpufreq/scaling_governor
     76       done''']))
     77 
     78   def sanity_check(self):
     79     HardwareAndroid.sanity_check(self)
     80 
     81     if not self._adb.is_root():
     82       return
     83 
     84     # only issue one shell command in an attempt to minimize interference.
     85     result = self._adb.check('''\
     86       cat /sys/class/power_supply/bq27742-0/capacity \
     87           /sys/devices/system/cpu/online \
     88           /sys/class/thermal/thermal_zone7/temp \
     89           /sys/class/thermal/thermal_zone0/temp \
     90           /sys/class/thermal/thermal_zone1/temp \
     91           /sys/class/thermal/thermal_zone7/cdev1/cur_state \
     92           /sys/class/thermal/thermal_zone7/cdev0/cur_state
     93       for N in 0 1 2; do
     94         cat /sys/devices/system/cpu/cpu$N/cpufreq/scaling_cur_freq
     95       done
     96       cat /sys/devices/57000000.gpu/pstate | grep \*$''')
     97 
     98     expectations = \
     99       [Expectation(int, min_value=30, name='battery', sleeptime=30*60),
    100        Expectation(str, exact_value='0-2', name='online cpus'),
    101        Expectation(int, max_value=40000, name='skin temperature'),
    102        Expectation(int, max_value=86000, name='cpu temperature'),
    103        Expectation(int, max_value=87000, name='gpu temperature'),
    104        Expectation(int, exact_value=0, name='cpu throttle'),
    105        Expectation(int, exact_value=0, name='gpu throttle')] + \
    106       [Expectation(int, exact_value=CPU_CLOCK_RATE,
    107                    name='cpu_%i clock rate' % i, sleeptime=30)
    108        for i in (0, 1, 2)] + \
    109       [Expectation(str, exact_value=GPU_EMC_PROFILE, name='gpu/emc profile')]
    110 
    111     Expectation.check_all(expectations, result.splitlines())
    112 
    113   def sleep(self, sleeptime):
    114     self._unlock_clocks()
    115     HardwareAndroid.sleep(self, sleeptime)
    116     self._lock_clocks()
    117