blob: 1e80b592bce5d5039608f7872bae24b232741964 [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
Chris Redpath02caf0f2017-02-02 17:29:03 +000014 # Android Workload to run
15 bm_name = 'Geekbench'
16
17 # Default products to be collected
18 bm_collect = 'ftrace energy'
19
20 def benchmarkInit(self):
21 self.setupWorkload()
22 self.setupGovernor()
Chris Redpath02caf0f2017-02-02 17:29:03 +000023
Juri Lelli6604ad22017-04-14 15:30:16 +010024 def __init__(self, governor, test):
Chris Redpath02caf0f2017-02-02 17:29:03 +000025 self.governor = governor
26 self.test = test
Chris Redpath02caf0f2017-02-02 17:29:03 +000027 super(GeekbenchTest, self).__init__()
28
29 def setupWorkload(self):
30 # Create a results folder for each "governor/test"
31 self.out_dir = os.path.join(self.te.res_dir, governor)
32 try:
33 os.stat(self.out_dir)
34 except:
35 os.makedirs(self.out_dir)
36 # Setup workload parameters
37 self.bm_params = {
38 'test_name' : self.test
39 }
40
41 def setupGovernor(self):
42 try:
43 self.target.cpufreq.set_all_governors(self.governor);
44 except TargetError:
45 self._log.warning('Governor [%s] not available on target',
46 self.governor)
47 raise
48
49 # Setup schedutil parameters
50 if self.governor == 'schedutil':
51 rate_limit_us = 2000
52 # Different schedutil versions have different tunables
53 tunables = self.target.cpufreq.list_governor_tunables(0)
54 if 'rate_limit_us' in tunables:
55 tunables = {'rate_limit_us' : str(rate_limit_us)}
56 else:
57 assert ('up_rate_limit_us' in tunables and
58 'down_rate_limit_us' in tunables)
59 tunables = {
60 'up_rate_limit_us' : str(rate_limit_us),
61 'down_rate_limit_us' : str(rate_limit_us)
62 }
63
64 try:
65 for cpu_id in range(self.te.platform['cpus_count']):
66 self.target.cpufreq.set_governor_tunables(
67 cpu_id, 'schedutil', **tunables)
68 except TargetError as e:
69 self._log.warning('Failed to set schedutils parameters: {}'\
70 .format(e))
71 raise
72 self._log.info('Set schedutil.rate_limit_us=%d', rate_limit_us)
73
74 # Setup ondemand parameters
75 if self.governor == 'ondemand':
76 try:
77 for cpu_id in range(self.te.platform['cpus_count']):
78 tunables = self.target.cpufreq.get_governor_tunables(cpu_id)
79 self.target.cpufreq.set_governor_tunables(
80 cpu_id, 'ondemand',
81 **{'sampling_rate' : tunables['sampling_rate_min']})
82 except TargetError as e:
83 self._log.warning('Failed to set ondemand parameters: {}'\
84 .format(e))
85 raise
86 self._log.info('Set ondemand.sampling_rate to minimum supported')
87
88 # Report configured governor
89 governors = self.target.cpufreq.get_all_governors()
90 self._log.info('Using governors: %s', governors)
91
92# Run the benchmark in each of the supported governors
93
94governors = [
95 'performance',
96 'ondemand',
97 'interactive',
98 'sched',
99 'schedutil',
100 'powersave',
101]
102
103tests = [
104 'CPU',
105 'COMPUTE'
106]
107
Chris Redpath02caf0f2017-02-02 17:29:03 +0000108tests_remaining = len(governors) * len(tests)
109tests_completed = 0
110for governor in governors:
111 for test in tests:
112 tests_remaining -= 1
Chris Redpath02caf0f2017-02-02 17:29:03 +0000113 try:
Juri Lelli6604ad22017-04-14 15:30:16 +0100114 GeekbenchTest(governor, test)
Chris Redpath02caf0f2017-02-02 17:29:03 +0000115 tests_completed += 1
116 except:
117 # A test configuraion failed, continue with other tests
118 pass
Chris Redpath02caf0f2017-02-02 17:29:03 +0000119
120# We want to collect data from at least one governor
121assert(tests_completed >= 1)
122
123# vim :set tabstop=4 shiftwidth=4 expandtab