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