From cc0679e40fbd433d14443b7ee87f99711c8b2667 Mon Sep 17 00:00:00 2001 From: Patrick Bellasi Date: Fri, 15 Jun 2018 14:40:50 +0100 Subject: [PATCH] module: sched: add support to get/set scheduler features Scheduler features are a debbugging mechanism which allows to tune at run-time some (usually experimental) features of the Linux scheduler. Let's add a proper API abstraction to easily access the list of supported features and tune them. Signed-off-by: Patrick Bellasi --- devlib/module/sched.py | 52 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/devlib/module/sched.py b/devlib/module/sched.py index a719dcf..a05725b 100644 --- a/devlib/module/sched.py +++ b/devlib/module/sched.py @@ -21,6 +21,7 @@ from past.builtins import basestring from devlib.module import Module from devlib.utils.misc import memoized +from devlib.utils.types import boolean class SchedProcFSNode(object): @@ -305,6 +306,57 @@ class SchedModule(Module): path = '/proc/sys/kernel/sched_' + attr self.target.write_value(path, value, verify) + @property + @memoized + def has_debug(self): + if self.target.config.get('SCHED_DEBUG') != 'y': + return False; + return self.target.file_exists('/sys/kernel/debug/sched_features') + + def get_features(self): + """ + Get the status of each sched feature + + :returns: a dictionary of features and their "is enabled" status + """ + if not self.has_debug: + raise RuntimeError("sched_features not available") + feats = self.target.read_value('/sys/kernel/debug/sched_features') + features = {} + for feat in feats.split(): + value = True + if feat.startswith('NO'): + feat = feat.replace('NO_', '', 1) + value = False + features[feat] = value + return features + + def set_feature(self, feature, enable, verify=True): + """ + Set the status of a specified scheduler feature + + :param feature: the feature name to set + :param enable: true to enable the feature, false otherwise + + :raise ValueError: if the specified enable value is not bool + :raise RuntimeError: if the specified feature cannot be set + """ + if not self.has_debug: + raise RuntimeError("sched_features not available") + feature = feature.upper() + feat_value = feature + if not boolean(enable): + feat_value = 'NO_' + feat_value + self.target.write_value('/sys/kernel/debug/sched_features', + feat_value, verify=False) + if not verify: + return + msg = 'Failed to set {}, feature not supported?'.format(feat_value) + features = self.get_features() + feat_value = features.get(feature, not enable) + if feat_value != enable: + raise RuntimeError(msg) + def get_cpu_sd_info(self, cpu): """ :returns: An object view of /proc/sys/kernel/sched_domain/cpu/*