blob: 6cd1df5b4a0535d4493eeff6b853e84a178c3a69 [file] [log] [blame]
Chris Redpath02caf0f2017-02-02 17:29:03 +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 GeekbenchTest(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" : "AndroidGeekbench",
57
58 }
59
60 # Android Workload to run
61 bm_name = 'Geekbench'
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(GeekbenchTest, 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)
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# Run the benchmark in each of the supported governors
149
150governors = [
151 'performance',
152 'ondemand',
153 'interactive',
154 'sched',
155 'schedutil',
156 'powersave',
157]
158
159tests = [
160 'CPU',
161 'COMPUTE'
162]
163
164# Reboot device only the first time
165do_reboot = True
166tests_remaining = len(governors) * len(tests)
167tests_completed = 0
168for governor in governors:
169 for test in tests:
170 tests_remaining -= 1
171 delay_after_s = 30 if tests_remaining else 0
172 try:
173 GeekbenchTest(governor, test, do_reboot, delay_after_s)
174 tests_completed += 1
175 except:
176 # A test configuraion failed, continue with other tests
177 pass
178 do_reboot = False
179
180# We want to collect data from at least one governor
181assert(tests_completed >= 1)
182
183# vim :set tabstop=4 shiftwidth=4 expandtab