From be8b87d5592187f692ba22318a2aff8cfc45d065 Mon Sep 17 00:00:00 2001 From: Valentin Schneider Date: Mon, 18 Mar 2019 16:21:50 +0000 Subject: [PATCH] module/sched: Fix/simplify procfs packing behaviour Back when I first wrote this I tried to make something smart that would automatically detect which procfs entries to pack into a mapping, the condition to do so being "the entry ends with a digit and there is another entry with the same name but a different digit". I wrongly assumed this would always work for the sched_domain entries, but it's possible to have a domain with a single group and thus a single "group0" entry. Since we know which entries we want to pack, let's hard-code these and be less smart about it. --- devlib/module/sched.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/devlib/module/sched.py b/devlib/module/sched.py index 63125fc..ce99d6d 100644 --- a/devlib/module/sched.py +++ b/devlib/module/sched.py @@ -52,6 +52,12 @@ class SchedProcFSNode(object): _re_procfs_node = re.compile(r"(?P.*\D)(?P\d+)$") + PACKABLE_ENTRIES = [ + "cpu", + "domain", + "group" + ] + @staticmethod def _ends_with_digits(node): if not isinstance(node, basestring): @@ -71,18 +77,19 @@ class SchedProcFSNode(object): """ :returns: The name of the procfs node """ - return re.search(SchedProcFSNode._re_procfs_node, node).group("name") + match = re.search(SchedProcFSNode._re_procfs_node, node) + if match: + return match.group("name") - @staticmethod - def _packable(node, entries): + return node + + @classmethod + def _packable(cls, node): """ :returns: Whether it makes sense to pack a node into a common entry """ return (SchedProcFSNode._ends_with_digits(node) and - any([SchedProcFSNode._ends_with_digits(x) and - SchedProcFSNode._node_digits(x) != SchedProcFSNode._node_digits(node) and - SchedProcFSNode._node_name(x) == SchedProcFSNode._node_name(node) - for x in entries])) + SchedProcFSNode._node_name(node) in cls.PACKABLE_ENTRIES) @staticmethod def _build_directory(node_name, node_data): @@ -119,7 +126,7 @@ class SchedProcFSNode(object): # Find which entries can be packed into a common entry packables = { node : SchedProcFSNode._node_name(node) + "s" - for node in list(nodes.keys()) if SchedProcFSNode._packable(node, list(nodes.keys())) + for node in list(nodes.keys()) if SchedProcFSNode._packable(node) } self._dyn_attrs = {}