diff --git a/libs/utils/env.py b/libs/utils/env.py index ca025c23800e0081256b4ac14121744695066f63..cda7b4ed1ac580e2ffe570732a18d1d4f2a41160 100644 --- a/libs/utils/env.py +++ b/libs/utils/env.py @@ -24,6 +24,7 @@ import shutil import sys import time import unittest +import contextlib import devlib from devlib.utils.misc import memoized, which @@ -150,6 +151,33 @@ class TestEnv(ShareState): :type force_new: bool """ + critical_tasks = { + 'linux': [ + 'init', + 'systemd', + 'dbus', + 'sh', + 'ssh', + 'rsyslogd', + 'jbd2' + ], + 'android': [ + 'sh', 'adbd', + 'usb', 'transport', + # We don't actually need this task but on Google Pixel it apparently + # cannot be frozen, so the cgroup state gets stuck in FREEZING if we + # try to freeze it. + 'thermal-engine', + # Similar issue with HiKey960, the board will crash if this is frozen + # for too long. + 'watchdogd', + ] + } + """ + Dictionary mapping OS name to list of task names that we can't afford to + freeze when using freeeze_userspace. + """ + _initialized = False def __init__(self, target_conf=None, test_conf=None, wipe=True, @@ -1082,6 +1110,31 @@ class TestEnv(ShareState): def _feature(self, feature): return feature in self.conf['__features__'] + @contextlib.contextmanager + def freeze_userspace(self): + if 'cgroups' not in self.target.modules: + raise RuntimeError( + 'Failed to freeze userspace. Ensure "cgroups" module is listed ' + 'among modules in target/test configuration') + + controllers = [s.name for s in self.target.cgroups.list_subsystems()] + if 'freezer' not in controllers: + self._log.warning('No freezer cgroup controller on target. ' + 'Not freezing userspace') + yield + return + + exclude = self.critical_tasks[self.target.os] + self._log.info('Freezing all tasks except: %s', ','.join(exclude)) + self.target.cgroups.freeze(exclude) + + try: + yield + + finally: + self._log.info('Un-freezing userspace tasks') + self.target.cgroups.freeze(thaw=True) + IFCFG_BCAST_RE = re.compile( r'Bcast:(.*) ' ) diff --git a/libs/utils/executor.py b/libs/utils/executor.py index bacc26a22af2f39ef1aed379ecb9c287b5b46e2d..952a27962ab13ac53363d8f467699ff19196ec9a 100644 --- a/libs/utils/executor.py +++ b/libs/utils/executor.py @@ -175,33 +175,6 @@ class Executor(): """ - critical_tasks = { - 'linux': [ - 'init', - 'systemd', - 'dbus', - 'sh', - 'ssh', - 'rsyslogd', - 'jbd2' - ], - 'android': [ - 'sh', 'adbd', - 'usb', 'transport', - # We don't actually need this task but on Google Pixel it apparently - # cannot be frozen, so the cgroup state gets stuck in FREEZING if we - # try to freeze it. - 'thermal-engine', - # Similar issue with HiKey960, the board will crash if this is frozen - # for too long. - 'watchdogd', - ] - } - """ - Dictionary mapping OS name to list of task names that we can't afford to - freeze when using freeeze_userspace. - """ - def __init__(self, test_env, experiments_conf): # Initialize globals self._default_cgroup = None @@ -290,7 +263,11 @@ class Executor(): self.experiments.append(exp) # WORKLOAD: execution - self._wload_run(exp_idx, exp) + if self._target_conf_flag(tc, 'freeze_userspace'): + with self.te.freeze_userspace(): + self._wload_run(exp_idx, exp) + else: + self._wload_run(exp_idx, exp) exp_idx += 1 self._target_cleanup(tc) @@ -695,11 +672,6 @@ class Executor(): self._log.debug('out_dir set to [%s]', experiment.out_dir) os.system('mkdir -p ' + experiment.out_dir) - # Freeze all userspace tasks that we don't need for running tests - need_thaw = False - if self._target_conf_flag(tc, 'freeze_userspace'): - need_thaw = self._freeze_userspace() - # FTRACE: start (if a configuration has been provided) if self.te.ftrace and self._target_conf_flag(tc, 'ftrace'): self._log.warning('FTrace events collection enabled') @@ -732,33 +704,8 @@ class Executor(): self._log.info(' %s', stats_file.replace(self.te.res_dir, '')) - # Unfreeze the tasks we froze - if need_thaw: - self._thaw_userspace() - self._print_footer() - def _freeze_userspace(self): - if 'cgroups' not in self.target.modules: - raise RuntimeError( - 'Failed to freeze userspace. Ensure "cgroups" module is listed ' - 'among modules in target/test configuration') - controllers = [s.name for s in self.target.cgroups.list_subsystems()] - if 'freezer' not in controllers: - self._log.warning('No freezer cgroup controller on target. ' - 'Not freezing userspace') - return False - - exclude = self.critical_tasks[self.te.target.os] - self._log.info('Freezing all tasks except: %s', ','.join(exclude)) - self.te.target.cgroups.freeze(exclude) - return True - - - def _thaw_userspace(self): - self._log.info('Un-freezing userspace tasks') - self.te.target.cgroups.freeze(thaw=True) - ################################################################################ # Utility Functions ################################################################################ diff --git a/tests/eas/capacity_capping.config b/tests/eas/capacity_capping.config index d2515deb6c796d7ed7b37be40afdca7431bb62a2..15bb4506acd8ac451402952de78fafeac778276c 100644 --- a/tests/eas/capacity_capping.config +++ b/tests/eas/capacity_capping.config @@ -5,11 +5,12 @@ "MIGRATION_WINDOW": 0.75, "EXPECTED_BUSY_TIME_PCT": 99, "TEST_CONF": { - "modules": ["bl", "cpufreq"], + "modules": ["bl", "cpufreq", "cgroups" ], "tools": ["rt-app"], "ftrace" : { "events" : ["sched_switch"], "buffsize" : 10240 - } + }, + "flags" : [ "ftrace" ] } } diff --git a/tests/eas/capacity_capping.py b/tests/eas/capacity_capping.py index 3f828e3a5a5cd98dcc0d6a690f310f6cdd6b7505..d911bfb6679f8efb635ba933ac2e6010ffbfb175 100644 --- a/tests/eas/capacity_capping.py +++ b/tests/eas/capacity_capping.py @@ -83,6 +83,7 @@ class CapacityCappingTest(unittest.TestCase): """ + @classmethod def setUpClass(cls): cls.params = {} @@ -90,7 +91,8 @@ class CapacityCappingTest(unittest.TestCase): cls.trace_file = os.path.join(cls.env.res_dir, "cap_cap.dat") cls.populate_params() - cls.run_workload() + with cls.env.freeze_userspace(): + cls.run_workload() trace = trappy.FTrace(cls.trace_file) cls.sa = SchedMultiAssert(trace, cls.env.topology,