blob: 8afea22467e645568022fb38d9e9321ed05a0b12 [file] [log] [blame]
Ionela Voinescube0e4a32017-02-02 18:26:37 +00001#!/usr/bin/python
2
3import os
4from time import sleep
5
6# The workload class MUST be loaded before the LisaBenchmark
7from android import Workload
8from android import LisaBenchmark
9
10from devlib.exception import TargetError
11
12class 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()
69 if self.reboot:
70 self.reboot_target()
71
72 def benchmarkFinalize(self):
73 if self.delay_after_s:
74 self._log.info("Waiting %d[s] before to continue...",
75 self.delay_after_s)
76 sleep(self.delay_after_s)
77
78 def __init__(self, governor, test, reboot=False, delay_after_s=0):
79 self.reboot = reboot
80 self.governor = governor
81 self.test = test
82 self.delay_after_s = delay_after_s
83 super(VellamoTest, self).__init__()
84
85 def setupWorkload(self):
86 # Create a results folder for each "governor/test"
87 self.out_dir = os.path.join(self.te.res_dir, governor, self.test)
88 try:
89 os.stat(self.out_dir)
90 except:
91 os.makedirs(self.out_dir)
92 # Setup workload parameters
93 self.bm_params = {
94 'test_name' : self.test
95 }
96
97 def setupGovernor(self):
98 try:
99 self.target.cpufreq.set_all_governors(self.governor);
100 except TargetError:
101 self._log.warning('Governor [%s] not available on target',
102 self.governor)
103 raise
104
105 # Setup schedutil parameters
106 if self.governor == 'schedutil':
107 rate_limit_us = 2000
108 # Different schedutil versions have different tunables
109 tunables = self.target.cpufreq.list_governor_tunables(0)
110 if 'rate_limit_us' in tunables:
111 tunables = {'rate_limit_us' : str(rate_limit_us)}
112 else:
113 assert ('up_rate_limit_us' in tunables and
114 'down_rate_limit_us' in tunables)
115 tunables = {
116 'up_rate_limit_us' : str(rate_limit_us),
117 'down_rate_limit_us' : str(rate_limit_us)
118 }
119
120 try:
121 for cpu_id in range(self.te.platform['cpus_count']):
122 self.target.cpufreq.set_governor_tunables(
123 cpu_id, 'schedutil', **tunables)
124 except TargetError as e:
125 self._log.warning('Failed to set schedutils parameters: {}'\
126 .format(e))
127 raise
128 self._log.info('Set schedutil.rate_limit_us=%d', rate_limit_us)
129
130 # Setup ondemand parameters
131 if self.governor == 'ondemand':
132 try:
133 for cpu_id in range(self.te.platform['cpus_count']):
134 tunables = self.target.cpufreq.get_governor_tunables(cpu_id)
135 self.target.cpufreq.set_governor_tunables(
136 cpu_id, 'ondemand',
137 **{'sampling_rate' : tunables['sampling_rate_min']})
138 except TargetError as e:
139 self._log.warning('Failed to set ondemand parameters: {}'\
140 .format(e))
141 raise
142 self._log.info('Set ondemand.sampling_rate to minimum supported')
143
144 # Report configured governor
145 governors = self.target.cpufreq.get_all_governors()
146 self._log.info('Using governors: %s', governors)
147
148
149# Run the benchmark in each of the supported governors
150
151governors = [
152 'performance',
153 'ondemand',
154 'interactive',
155 'sched',
156 'schedutil',
157 'powersave'
158]
159
160tests = [
161 'BROWSER',
162 'METAL',
163 'MULTI'
164]
165
166
167# Reboot device only the first time
168do_reboot = True
169tests_remaining = len(governors) * len(tests)
170tests_completed = 0
171for governor in governors:
172 for test in tests:
173 tests_remaining -= 1
174 delay_after_s = 30 if tests_remaining else 0
175 try:
176 VellamoTest(governor, test, do_reboot, delay_after_s)
177 tests_completed += 1
178 except:
179 # A test configuraion failed, continue with other tests
180 pass
181 do_reboot = False
182
183# We want to collect data from at least one governor
184assert(tests_completed >= 1)
185
186# vim :set tabstop=4 shiftwidth=4 expandtab