diff --git a/libs/utils/env.py b/libs/utils/env.py index 2857f35a2c3d517315e18471641fb72930d28587..7891094cbaa6c54fe9f4ff96c77a80c84c35302c 100644 --- a/libs/utils/env.py +++ b/libs/utils/env.py @@ -151,6 +151,22 @@ class TestEnv(ShareState): :type force_new: bool """ + critical_tasks = { + 'linux': ['init', 'systemd', 'sh', 'ssh'], + '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' + ] + } + """ + 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, @@ -1008,6 +1024,32 @@ class TestEnv(ShareState): def _feature(self, feature): return feature in self.conf['__features__'] + def freeze_userspace(self): + self.need_thaw = False + 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.target.os] + self._log.info('Freezing all tasks except: %s', ','.join(exclude)) + self.target.cgroups.freeze(exclude) + self.need_thaw = True + return True + + def thaw_userspace(self): + if self.need_thaw: + self._log.info('Un-freezing userspace tasks') + self.target.cgroups.freeze(thaw=True) + else: + self._log.error('Trying to un-freeze tasks without first freezing. ' + 'Not unfreezing userspace') + IFCFG_BCAST_RE = re.compile( r'Bcast:(.*) ' ) diff --git a/libs/utils/executor.py b/libs/utils/executor.py index 7c7060b22fed9703c23816b4fd1155d0055d7a78..dd67305cb25e99a6dd85db88d6540394a6774036 100644 --- a/libs/utils/executor.py +++ b/libs/utils/executor.py @@ -168,21 +168,6 @@ class Executor(): :type experiments_conf: dict """ - critical_tasks = { - 'linux': ['init', 'systemd', 'sh', 'ssh'], - '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' - ] - } - """ - 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 @@ -672,7 +657,7 @@ class Executor(): # 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() + need_thaw = self.te.freeze_userspace() # FTRACE: start (if a configuration has been provided) if self.te.ftrace and self._target_conf_flag(tc, 'ftrace'): @@ -708,31 +693,10 @@ class Executor(): # Unfreeze the tasks we froze if need_thaw: - self._thaw_userspace() + self.te.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..fd6b60fd3abff716646c2e2b27107cfaea9e79c0 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 = {} @@ -126,6 +127,7 @@ class CapacityCappingTest(unittest.TestCase): wload.conf(kind="profile", params=cls.params) phase_duration = WORKLOAD_DURATION_S / 3. + cls.env.freeze_userspace() cls.env.ftrace.start() wload.run(out_dir=cls.env.res_dir, background=True) @@ -150,6 +152,7 @@ class CapacityCappingTest(unittest.TestCase): cls.env.ftrace.stop() cls.env.ftrace.get_trace(cls.trace_file) + cls.env.thaw_userspace() def check_residencies(self, cpus, cpus_name, window, phase_description): """Helper function to check the residencies of all busy threads on a