Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import atexit | 5 import atexit |
| 6 import logging | 6 import logging |
| 7 | 7 |
| 8 from pylib import android_commands | 8 from pylib import android_commands |
| 9 from pylib.device import device_utils | 9 from pylib.device import device_utils |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 device = device_utils.DeviceUtils(device) | 21 device = device_utils.DeviceUtils(device) |
| 22 self._device = device | 22 self._device = device |
| 23 cpu_files = self._device.RunShellCommand( | 23 cpu_files = self._device.RunShellCommand( |
| 24 'ls -d /sys/devices/system/cpu/cpu[0-9]*') | 24 'ls -d /sys/devices/system/cpu/cpu[0-9]*') |
| 25 self._num_cpu_cores = len(cpu_files) | 25 self._num_cpu_cores = len(cpu_files) |
| 26 assert self._num_cpu_cores > 0, 'Failed to detect CPUs.' | 26 assert self._num_cpu_cores > 0, 'Failed to detect CPUs.' |
| 27 logging.info('Number of CPUs: %d', self._num_cpu_cores) | 27 logging.info('Number of CPUs: %d', self._num_cpu_cores) |
| 28 self._have_mpdecision = self._device.FileExists('/system/bin/mpdecision') | 28 self._have_mpdecision = self._device.FileExists('/system/bin/mpdecision') |
| 29 | 29 |
| 30 def SetHighPerfMode(self): | 30 def SetHighPerfMode(self): |
| 31 """Sets the highest possible performance mode for the device.""" | 31 """Sets the highest stable performance mode for the device.""" |
| 32 if not self._device.old_interface.IsRootEnabled(): | 32 if not self._device.old_interface.IsRootEnabled(): |
| 33 message = 'Need root for performance mode. Results may be NOISY!!' | 33 message = 'Need root for performance mode. Results may be NOISY!!' |
| 34 logging.warning(message) | 34 logging.warning(message) |
| 35 # Add an additional warning at exit, such that it's clear that any results | 35 # Add an additional warning at exit, such that it's clear that any results |
| 36 # may be different/noisy (due to the lack of intended performance mode). | 36 # may be different/noisy (due to the lack of intended performance mode). |
| 37 atexit.register(logging.warning, message) | 37 atexit.register(logging.warning, message) |
| 38 return | 38 return |
| 39 | |
| 40 product_model = self._device.old_interface.GetProductModel() | |
| 39 # TODO(epenner): Enable on all devices (http://crbug.com/383566) | 41 # TODO(epenner): Enable on all devices (http://crbug.com/383566) |
| 40 if 'Nexus 4' == self._device.old_interface.GetProductModel(): | 42 if 'Nexus 4' == product_model: |
| 41 self._ForceAllCpusOnline(True) | 43 self._ForceAllCpusOnline(True) |
| 42 if not self._AllCpusAreOnline(): | 44 if not self._AllCpusAreOnline(): |
| 43 logging.warning('Failed to force CPUs online. Results may be NOISY!') | 45 logging.warning('Failed to force CPUs online. Results may be NOISY!') |
| 44 self._SetScalingGovernorInternal('performance') | 46 self._SetScalingGovernorInternal('performance') |
| 47 elif 'Nexus 5' == product_model: | |
| 48 self._ForceAllCpusOnline(True) | |
| 49 if not self._AllCpusAreOnline(): | |
| 50 logging.warning('Failed to force CPUs online. Results may be NOISY!') | |
| 51 self._SetScalingGovernorInternal('performance') | |
| 52 self._SetScalingMaxFreq(1190400) | |
| 53 self._SetMaxGpuClock(200000000) | |
| 54 else: | |
| 55 self._SetScalingGovernorInternal('performance') | |
| 45 | 56 |
| 46 def SetPerfProfilingMode(self): | 57 def SetPerfProfilingMode(self): |
| 47 """Enables all cores for reliable perf profiling.""" | 58 """Enables all cores for reliable perf profiling.""" |
| 48 self._ForceAllCpusOnline(True) | 59 self._ForceAllCpusOnline(True) |
| 49 self._SetScalingGovernorInternal('performance') | 60 self._SetScalingGovernorInternal('performance') |
| 50 if not self._AllCpusAreOnline(): | 61 if not self._AllCpusAreOnline(): |
| 51 if not self._device.old_interface.IsRootEnabled(): | 62 if not self._device.old_interface.IsRootEnabled(): |
| 52 raise RuntimeError('Need root to force CPUs online.') | 63 raise RuntimeError('Need root to force CPUs online.') |
| 53 raise RuntimeError('Failed to force CPUs online.') | 64 raise RuntimeError('Failed to force CPUs online.') |
| 54 | 65 |
| 55 def SetDefaultPerfMode(self): | 66 def SetDefaultPerfMode(self): |
| 56 """Sets the performance mode for the device to its default mode.""" | 67 """Sets the performance mode for the device to its default mode.""" |
| 57 if not self._device.old_interface.IsRootEnabled(): | 68 if not self._device.old_interface.IsRootEnabled(): |
| 58 return | 69 return |
| 59 product_model = self._device.GetProp('ro.product.model') | 70 product_model = self._device.old_interface.GetProductModel() |
| 71 if 'Nexus 5' == product_model: | |
| 72 if self._AllCpusAreOnline(): | |
| 73 self._SetScalingMaxFreq(2265600) | |
| 74 self._SetMaxGpuClock(450000000) | |
| 75 | |
| 60 governor_mode = { | 76 governor_mode = { |
| 61 'GT-I9300': 'pegasusq', | 77 'GT-I9300': 'pegasusq', |
| 62 'Galaxy Nexus': 'interactive', | 78 'Galaxy Nexus': 'interactive', |
| 63 'Nexus 4': 'ondemand', | 79 'Nexus 4': 'ondemand', |
| 64 'Nexus 7': 'interactive', | 80 'Nexus 7': 'interactive', |
| 65 'Nexus 10': 'interactive' | 81 'Nexus 10': 'interactive' |
| 66 }.get(product_model, 'ondemand') | 82 }.get(product_model, 'ondemand') |
|
Sami
2014/10/15 13:29:17
Is this the right choice for Nexus 5? Please make
vmiura
2014/10/15 20:15:01
Done.
| |
| 67 self._SetScalingGovernorInternal(governor_mode) | 83 self._SetScalingGovernorInternal(governor_mode) |
| 68 self._ForceAllCpusOnline(False) | 84 self._ForceAllCpusOnline(False) |
| 69 | 85 |
| 70 def _SetScalingGovernorInternal(self, value): | 86 def _SetScalingGovernorInternal(self, value): |
| 71 cpu_cores = ' '.join([str(x) for x in range(self._num_cpu_cores)]) | 87 cpu_cores = ' '.join([str(x) for x in range(self._num_cpu_cores)]) |
| 72 script = ('for CPU in %s; do\n' | 88 script = ('for CPU in %s; do\n' |
| 73 ' FILE="/sys/devices/system/cpu/cpu$CPU/cpufreq/scaling_governor"\n' | 89 ' FILE="/sys/devices/system/cpu/cpu$CPU/cpufreq/scaling_governor"\n' |
| 74 ' test -e $FILE && echo %s > $FILE\n' | 90 ' test -e $FILE && echo %s > $FILE\n' |
| 75 'done\n') % (cpu_cores, value) | 91 'done\n') % (cpu_cores, value) |
| 76 logging.info('Setting scaling governor mode: %s', value) | 92 logging.info('Setting scaling governor mode: %s', value) |
| 77 self._device.RunShellCommand(script, as_root=True) | 93 self._device.RunShellCommand(script, as_root=True) |
| 78 | 94 |
| 95 def _SetScalingMaxFreq(self, value): | |
| 96 cpu_cores = ' '.join([str(x) for x in range(self._num_cpu_cores)]) | |
| 97 script = ('for CPU in %s; do\n' | |
| 98 ' FILE="/sys/devices/system/cpu/cpu$CPU/cpufreq/scaling_max_freq"\n' | |
| 99 ' test -e $FILE && echo %s > $FILE\n' | |
|
Sami
2014/10/15 13:29:17
nit: %s should really be a %d here, right?
vmiura
2014/10/15 20:15:01
Done.
| |
| 100 'done\n') % (cpu_cores, str(value)) | |
|
Sami
2014/10/15 13:29:17
Remove str() if you agree with above.
vmiura
2014/10/15 20:15:01
Done.
| |
| 101 self._device.RunShellCommand(script, as_root=True) | |
| 102 | |
| 103 def _SetMaxGpuClock(self, value): | |
| 104 self._device.WriteFile('/sys/class/kgsl/kgsl-3d0/max_gpuclk', | |
| 105 str(value), | |
| 106 as_root=True) | |
| 107 | |
| 79 def _AllCpusAreOnline(self): | 108 def _AllCpusAreOnline(self): |
| 80 for cpu in range(1, self._num_cpu_cores): | 109 for cpu in range(1, self._num_cpu_cores): |
| 81 online_path = PerfControl._CPU_ONLINE_FMT % cpu | 110 online_path = PerfControl._CPU_ONLINE_FMT % cpu |
| 82 # TODO(epenner): Investigate why file may be missing | 111 # TODO(epenner): Investigate why file may be missing |
| 83 # (http://crbug.com/397118) | 112 # (http://crbug.com/397118) |
| 84 if not self._device.FileExists(online_path) or \ | 113 if not self._device.FileExists(online_path) or \ |
| 85 self._device.ReadFile(online_path)[0] == '0': | 114 self._device.ReadFile(online_path)[0] == '0': |
| 86 return False | 115 return False |
| 87 return True | 116 return True |
| 88 | 117 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 106 | 135 |
| 107 if not self._have_mpdecision and not self._AllCpusAreOnline(): | 136 if not self._have_mpdecision and not self._AllCpusAreOnline(): |
| 108 logging.warning('Unexpected cpu hot plugging detected.') | 137 logging.warning('Unexpected cpu hot plugging detected.') |
| 109 | 138 |
| 110 if not force_online: | 139 if not force_online: |
| 111 return | 140 return |
| 112 | 141 |
| 113 for cpu in range(self._num_cpu_cores): | 142 for cpu in range(self._num_cpu_cores): |
| 114 online_path = PerfControl._CPU_ONLINE_FMT % cpu | 143 online_path = PerfControl._CPU_ONLINE_FMT % cpu |
| 115 self._device.WriteFile(online_path, '1', as_root=True) | 144 self._device.WriteFile(online_path, '1', as_root=True) |
| 145 | |
| OLD | NEW |