OLD | NEW |
1 # Copyright 2016 Google Inc. | 1 # Copyright 2016 Google Inc. |
2 # | 2 # |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 from _hardware import HardwareException, Expectation | 6 from _hardware import HardwareException, Expectation |
7 from _hardware_android import HardwareAndroid | 7 from _hardware_android import HardwareAndroid |
8 | 8 |
9 CPU_CLOCK_RATE = 1836000 | 9 CPU_CLOCK_RATE = 1836000 |
10 GPU_EMC_PROFILE = '0c: core 921 MHz emc 1600 MHz a A d D *' | 10 GPU_EMC_PROFILE = '0c: core 921 MHz emc 1600 MHz a A d D *' |
(...skipping 10 matching lines...) Expand all Loading... |
21 def __exit__(self, exception_type, exception_value, exception_traceback): | 21 def __exit__(self, exception_type, exception_value, exception_traceback): |
22 HardwareAndroid.__exit__(self, exception_type, | 22 HardwareAndroid.__exit__(self, exception_type, |
23 exception_value, exception_traceback) | 23 exception_value, exception_traceback) |
24 self._unlock_clocks() | 24 self._unlock_clocks() |
25 | 25 |
26 def _lock_clocks(self): | 26 def _lock_clocks(self): |
27 if not self._adb.is_root(): | 27 if not self._adb.is_root(): |
28 return | 28 return |
29 | 29 |
30 self._adb.shell('\n'.join([ | 30 self._adb.shell('\n'.join([ |
31 # lock cpu clocks. | 31 # turn on and lock the first 3 cores. |
32 ''' | 32 ''' |
33 for N in $(seq 0 3); do | 33 for N in 0 1 2; do |
| 34 echo 1 > /sys/devices/system/cpu/cpu$N/online |
34 echo userspace > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_governor | 35 echo userspace > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_governor |
| 36 echo %i > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_max_freq |
| 37 echo %i > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_min_freq |
35 echo %i > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_setspeed | 38 echo %i > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_setspeed |
36 done''' % CPU_CLOCK_RATE, | 39 done''' % tuple(CPU_CLOCK_RATE for _ in range(3)), |
| 40 |
| 41 # turn off the fourth core. |
| 42 ''' |
| 43 echo 0 > /sys/devices/system/cpu/cpu3/online''', |
37 | 44 |
38 # lock gpu/emc clocks. | 45 # lock gpu/emc clocks. |
39 ''' | 46 ''' |
40 chown root:root /sys/devices/57000000.gpu/pstate | 47 chown root:root /sys/devices/57000000.gpu/pstate |
41 echo %s > /sys/devices/57000000.gpu/pstate''' % GPU_EMC_PROFILE_ID])) | 48 echo %s > /sys/devices/57000000.gpu/pstate''' % GPU_EMC_PROFILE_ID])) |
42 | 49 |
43 def _unlock_clocks(self): | 50 def _unlock_clocks(self): |
44 if not self._adb.is_root(): | 51 if not self._adb.is_root(): |
45 return | 52 return |
46 | 53 |
47 self._adb.shell('\n'.join([ | 54 self._adb.shell('\n'.join([ |
48 # unlock gpu/emc clocks. | 55 # unlock gpu/emc clocks. |
49 ''' | 56 ''' |
50 echo auto > /sys/devices/57000000.gpu/pstate | 57 echo auto > /sys/devices/57000000.gpu/pstate |
51 chown system:system /sys/devices/57000000.gpu/pstate''', | 58 chown system:system /sys/devices/57000000.gpu/pstate''', |
52 | 59 |
53 # unlock cpu clocks. | 60 # turn the fourth core back on. |
54 ''' | 61 ''' |
55 for N in $(seq 0 3); do | 62 echo 1 > /sys/devices/system/cpu/cpu3/online''', |
| 63 |
| 64 # unlock the first 3 cores. |
| 65 ''' |
| 66 for N in 2 1 0; do |
| 67 echo 1912500 > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_max_freq |
| 68 echo 51000 > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_min_freq |
56 echo 0 > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_setspeed | 69 echo 0 > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_setspeed |
57 echo interactive >/sys/devices/system/cpu/cpu$N/cpufreq/scaling_governor | 70 echo interactive >/sys/devices/system/cpu/cpu$N/cpufreq/scaling_governor |
58 done'''])) | 71 done'''])) |
59 | 72 |
60 def sanity_check(self): | 73 def sanity_check(self): |
61 HardwareAndroid.sanity_check(self) | 74 HardwareAndroid.sanity_check(self) |
62 | 75 |
63 if not self._adb.is_root(): | 76 if not self._adb.is_root(): |
64 return | 77 return |
65 | 78 |
66 # only issue one shell command in an attempt to minimize interference. | 79 # only issue one shell command in an attempt to minimize interference. |
67 result = self._adb.check('''\ | 80 result = self._adb.check('''\ |
68 cat /sys/class/power_supply/bq27742-0/capacity \ | 81 cat /sys/class/power_supply/bq27742-0/capacity \ |
| 82 /sys/devices/system/cpu/online \ |
69 /sys/class/thermal/thermal_zone7/temp \ | 83 /sys/class/thermal/thermal_zone7/temp \ |
70 /sys/class/thermal/thermal_zone0/temp \ | 84 /sys/class/thermal/thermal_zone0/temp \ |
71 /sys/class/thermal/thermal_zone1/temp \ | 85 /sys/class/thermal/thermal_zone1/temp \ |
72 /sys/class/thermal/thermal_zone7/cdev1/cur_state \ | 86 /sys/class/thermal/thermal_zone7/cdev1/cur_state \ |
73 /sys/class/thermal/thermal_zone7/cdev0/cur_state | 87 /sys/class/thermal/thermal_zone7/cdev0/cur_state |
74 for N in $(seq 0 3); do | 88 for N in 0 1 2; do |
75 cat /sys/devices/system/cpu/cpu$N/cpufreq/scaling_cur_freq | 89 cat /sys/devices/system/cpu/cpu$N/cpufreq/scaling_cur_freq |
76 done | 90 done |
77 cat /sys/devices/57000000.gpu/pstate | grep \*$''') | 91 cat /sys/devices/57000000.gpu/pstate | grep \*$''') |
78 | 92 |
79 expectations = \ | 93 expectations = \ |
80 [Expectation(int, min_value=30, name='battery', sleeptime=30*60), | 94 [Expectation(int, min_value=30, name='battery', sleeptime=30*60), |
| 95 Expectation(str, exact_value='0-2', name='online cpus'), |
81 Expectation(int, max_value=40000, name='skin temperature'), | 96 Expectation(int, max_value=40000, name='skin temperature'), |
82 Expectation(int, max_value=86000, name='cpu temperature'), | 97 Expectation(int, max_value=86000, name='cpu temperature'), |
83 Expectation(int, max_value=87000, name='gpu temperature'), | 98 Expectation(int, max_value=87000, name='gpu temperature'), |
84 Expectation(int, exact_value=0, name='cpu throttle'), | 99 Expectation(int, exact_value=0, name='cpu throttle'), |
85 Expectation(int, exact_value=0, name='gpu throttle')] + \ | 100 Expectation(int, exact_value=0, name='gpu throttle')] + \ |
86 [Expectation(int, exact_value=CPU_CLOCK_RATE, | 101 [Expectation(int, exact_value=CPU_CLOCK_RATE, |
87 name='cpu_%i clock rate' % i, sleeptime=30) | 102 name='cpu_%i clock rate' % i, sleeptime=30) |
88 for i in range(4)] + \ | 103 for i in (0, 1, 2)] + \ |
89 [Expectation(str, exact_value=GPU_EMC_PROFILE, name='gpu/emc profile')] | 104 [Expectation(str, exact_value=GPU_EMC_PROFILE, name='gpu/emc profile')] |
90 | 105 |
91 Expectation.check_all(expectations, result.splitlines()) | 106 Expectation.check_all(expectations, result.splitlines()) |
92 | 107 |
93 def sleep(self, sleeptime): | 108 def sleep(self, sleeptime): |
94 self._unlock_clocks() | 109 self._unlock_clocks() |
95 HardwareAndroid.sleep(self, sleeptime) | 110 HardwareAndroid.sleep(self, sleeptime) |
96 self._lock_clocks() | 111 self._lock_clocks() |
OLD | NEW |