From ef5fc76d0e31a1b73ca03190b72ebe4410f42ae8 Mon Sep 17 00:00:00 2001 From: Juri Lelli Date: Wed, 13 Jun 2018 09:51:09 +0200 Subject: [PATCH] libs/rtapp: Make cpufreq module optional for rt-app calibration If cpufreq module is not used (e.g., KVM target) rt-app calibration should still work as usual, no need to set frequency to max in this case though. Remove the hard dependecy towards cpufreq module. Signed-off-by: Juri Lelli --- libs/wlgen/wlgen/rta.py | 51 ++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/libs/wlgen/wlgen/rta.py b/libs/wlgen/wlgen/rta.py index b26328b37..32f50109d 100644 --- a/libs/wlgen/wlgen/rta.py +++ b/libs/wlgen/wlgen/rta.py @@ -101,6 +101,39 @@ class RTA(Workload): # Setup RTA callbacks self.setCallback('postrun', self.__postrun) + @staticmethod + def __setGovernorsPerformance(target): + if 'cpufreq' not in target.modules: + log = logging.getLogger('RTApp') + log.warning('cpufreq module not loaded,' + ' skipping setting frequency to max') + return {} + + # Save previous governors + old_governors = {} + for domain in target.cpufreq.iter_domains(): + cpu = domain[0] + governor = target.cpufreq.get_governor(cpu) + tunables = target.cpufreq.get_governor_tunables(cpu) + old_governors[cpu] = governor, tunables + + target.cpufreq.set_all_governors('performance') + + return old_governors + + @staticmethod + def __restoreGovernors(target, old_governors): + if 'cpufreq' not in target.modules: + return + + # Restore previous governors + # Setting a governor & tunables for a cpu will set them for all cpus + # in the same clock domain, so only restoring them for one cpu + # per domain is enough to restore them all. + for cpu, (governor, tunables) in old_governors.iteritems(): + target.cpufreq.set_governor(cpu, governor) + target.cpufreq.set_governor_tunables(cpu, **tunables) + @staticmethod def calibrate(target): """ @@ -115,15 +148,7 @@ class RTA(Workload): # Setup logging log = logging.getLogger('RTApp') - # Save previous governors - old_governors = {} - for domain in target.cpufreq.iter_domains(): - cpu = domain[0] - governor = target.cpufreq.get_governor(cpu) - tunables = target.cpufreq.get_governor_tunables(cpu) - old_governors[cpu] = governor, tunables - - target.cpufreq.set_all_governors('performance') + old_governors = RTA.__setGovernorsPerformance(target) # Create calibration task max_rtprio = int(target.execute('ulimit -Hr').split('\r')[0]) @@ -154,13 +179,7 @@ class RTA(Workload): pload[cpu] = int(pload_match.group(1)) log.debug('>>> cpu%d: %d', cpu, pload[cpu]) - # Restore previous governors - # Setting a governor & tunables for a cpu will set them for all cpus - # in the same clock domain, so only restoring them for one cpu - # per domain is enough to restore them all. - for cpu, (governor, tunables) in old_governors.iteritems(): - target.cpufreq.set_governor(cpu, governor) - target.cpufreq.set_governor_tunables(cpu, **tunables) + RTA.__restoreGovernors(target, old_governors) log.info('Target RT-App calibration:') log.info("{" + ", ".join('"%r": %r' % (key, pload[key]) -- GitLab