Ionela Voinescu | be0e4a3 | 2017-02-02 18:26:37 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | import os |
| 4 | from time import sleep |
| 5 | |
| 6 | # The workload class MUST be loaded before the LisaBenchmark |
| 7 | from android import Workload |
| 8 | from android import LisaBenchmark |
| 9 | |
| 10 | from devlib.exception import TargetError |
| 11 | |
| 12 | class VellamoTest(LisaBenchmark): |
| 13 | |
| 14 | bm_conf = { |
| 15 | |
| 16 | # Target platform and board |
| 17 | "platform" : 'android', |
| 18 | |
| 19 | # Define devlib modules to load |
| 20 | "modules" : [ |
| 21 | 'cpufreq', |
| 22 | ], |
| 23 | |
| 24 | # FTrace events to collect for all the tests configuration which have |
| 25 | # the "ftrace" flag enabled |
| 26 | "ftrace" : { |
| 27 | "events" : [ |
| 28 | "sched_switch", |
| 29 | "sched_overutilized", |
| 30 | "sched_contrib_scale_f", |
| 31 | "sched_load_avg_cpu", |
| 32 | "sched_load_avg_task", |
| 33 | "sched_tune_tasks_update", |
| 34 | "sched_boost_cpu", |
| 35 | "sched_boost_task", |
| 36 | "sched_energy_diff", |
| 37 | "cpu_frequency", |
| 38 | "cpu_idle", |
| 39 | "cpu_capacity", |
| 40 | ], |
| 41 | "buffsize" : 10 * 1024, |
| 42 | }, |
| 43 | |
| 44 | # Default EnergyMeter Configuration |
| 45 | "emeter" : { |
| 46 | "instrument" : "acme", |
| 47 | "channel_map" : { |
| 48 | "Device0" : 0, |
| 49 | } |
| 50 | }, |
| 51 | |
| 52 | # Tools required by the experiments |
| 53 | "tools" : [ 'trace-cmd' ], |
| 54 | |
| 55 | # Default results folder |
| 56 | "results_dir" : "AndroidVellamo", |
| 57 | |
| 58 | } |
| 59 | |
| 60 | # Android Workload to run |
| 61 | bm_name = 'Vellamo' |
| 62 | |
| 63 | # Default products to be collected |
| 64 | bm_collect = 'ftrace energy' |
| 65 | |
| 66 | def benchmarkInit(self): |
| 67 | self.setupWorkload() |
| 68 | self.setupGovernor() |
Ionela Voinescu | be0e4a3 | 2017-02-02 18:26:37 +0000 | [diff] [blame] | 69 | |
Juri Lelli | 6604ad2 | 2017-04-14 15:30:16 +0100 | [diff] [blame] | 70 | def __init__(self, governor, test): |
Ionela Voinescu | be0e4a3 | 2017-02-02 18:26:37 +0000 | [diff] [blame] | 71 | self.governor = governor |
| 72 | self.test = test |
Ionela Voinescu | be0e4a3 | 2017-02-02 18:26:37 +0000 | [diff] [blame] | 73 | super(VellamoTest, self).__init__() |
| 74 | |
| 75 | def setupWorkload(self): |
| 76 | # Create a results folder for each "governor/test" |
| 77 | self.out_dir = os.path.join(self.te.res_dir, governor, self.test) |
| 78 | try: |
| 79 | os.stat(self.out_dir) |
| 80 | except: |
| 81 | os.makedirs(self.out_dir) |
| 82 | # Setup workload parameters |
| 83 | self.bm_params = { |
| 84 | 'test_name' : self.test |
| 85 | } |
| 86 | |
| 87 | def setupGovernor(self): |
| 88 | try: |
| 89 | self.target.cpufreq.set_all_governors(self.governor); |
| 90 | except TargetError: |
| 91 | self._log.warning('Governor [%s] not available on target', |
| 92 | self.governor) |
| 93 | raise |
| 94 | |
| 95 | # Setup schedutil parameters |
| 96 | if self.governor == 'schedutil': |
| 97 | rate_limit_us = 2000 |
| 98 | # Different schedutil versions have different tunables |
| 99 | tunables = self.target.cpufreq.list_governor_tunables(0) |
| 100 | if 'rate_limit_us' in tunables: |
| 101 | tunables = {'rate_limit_us' : str(rate_limit_us)} |
| 102 | else: |
| 103 | assert ('up_rate_limit_us' in tunables and |
| 104 | 'down_rate_limit_us' in tunables) |
| 105 | tunables = { |
| 106 | 'up_rate_limit_us' : str(rate_limit_us), |
| 107 | 'down_rate_limit_us' : str(rate_limit_us) |
| 108 | } |
| 109 | |
| 110 | try: |
| 111 | for cpu_id in range(self.te.platform['cpus_count']): |
| 112 | self.target.cpufreq.set_governor_tunables( |
| 113 | cpu_id, 'schedutil', **tunables) |
| 114 | except TargetError as e: |
| 115 | self._log.warning('Failed to set schedutils parameters: {}'\ |
| 116 | .format(e)) |
| 117 | raise |
| 118 | self._log.info('Set schedutil.rate_limit_us=%d', rate_limit_us) |
| 119 | |
| 120 | # Setup ondemand parameters |
| 121 | if self.governor == 'ondemand': |
| 122 | try: |
| 123 | for cpu_id in range(self.te.platform['cpus_count']): |
| 124 | tunables = self.target.cpufreq.get_governor_tunables(cpu_id) |
| 125 | self.target.cpufreq.set_governor_tunables( |
| 126 | cpu_id, 'ondemand', |
| 127 | **{'sampling_rate' : tunables['sampling_rate_min']}) |
| 128 | except TargetError as e: |
| 129 | self._log.warning('Failed to set ondemand parameters: {}'\ |
| 130 | .format(e)) |
| 131 | raise |
| 132 | self._log.info('Set ondemand.sampling_rate to minimum supported') |
| 133 | |
| 134 | # Report configured governor |
| 135 | governors = self.target.cpufreq.get_all_governors() |
| 136 | self._log.info('Using governors: %s', governors) |
| 137 | |
| 138 | |
| 139 | # Run the benchmark in each of the supported governors |
| 140 | |
| 141 | governors = [ |
| 142 | 'performance', |
| 143 | 'ondemand', |
| 144 | 'interactive', |
| 145 | 'sched', |
| 146 | 'schedutil', |
| 147 | 'powersave' |
| 148 | ] |
| 149 | |
| 150 | tests = [ |
| 151 | 'BROWSER', |
| 152 | 'METAL', |
| 153 | 'MULTI' |
| 154 | ] |
| 155 | |
| 156 | |
Ionela Voinescu | be0e4a3 | 2017-02-02 18:26:37 +0000 | [diff] [blame] | 157 | tests_remaining = len(governors) * len(tests) |
| 158 | tests_completed = 0 |
| 159 | for governor in governors: |
| 160 | for test in tests: |
| 161 | tests_remaining -= 1 |
Ionela Voinescu | be0e4a3 | 2017-02-02 18:26:37 +0000 | [diff] [blame] | 162 | try: |
Juri Lelli | 6604ad2 | 2017-04-14 15:30:16 +0100 | [diff] [blame] | 163 | VellamoTest(governor, test) |
Ionela Voinescu | be0e4a3 | 2017-02-02 18:26:37 +0000 | [diff] [blame] | 164 | tests_completed += 1 |
| 165 | except: |
| 166 | # A test configuraion failed, continue with other tests |
| 167 | pass |
Ionela Voinescu | be0e4a3 | 2017-02-02 18:26:37 +0000 | [diff] [blame] | 168 | |
| 169 | # We want to collect data from at least one governor |
| 170 | assert(tests_completed >= 1) |
| 171 | |
| 172 | # vim :set tabstop=4 shiftwidth=4 expandtab |