From 6168d5e2e65142aeef213491c9ebed776f031b08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20=C5=A0karvada?= Date: Mon, 8 Jun 2015 14:21:50 +0200 Subject: [PATCH] functions: added 'cpulist_invert' built-in function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Inverts list of CPUs (makes its complement). For the complement it gets number of present CPUs from the /sys/devices/system/cpu/present, e.g. system with 4 CPUs (0-3), the inversion of list "0,2,3" will be "1". Related: rhbz#1225135 Signed-off-by: Jaroslav Škarvada --- .../functions/function_cpulist_invert.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tuned/profiles/functions/function_cpulist_invert.py diff --git a/tuned/profiles/functions/function_cpulist_invert.py b/tuned/profiles/functions/function_cpulist_invert.py new file mode 100644 index 0000000..39fa369 --- /dev/null +++ b/tuned/profiles/functions/function_cpulist_invert.py @@ -0,0 +1,24 @@ +import os +import tuned.logs +import base +from tuned.utils.commands import commands + +log = tuned.logs.get() + +class cpulist_invert(base.Function): + """ + Inverts list of CPUs (makes its complement). For the complement it + gets number of present CPUs from the /sys/devices/system/cpu/present, + e.g. system with 4 CPUs (0-3), the inversion of list "0,2,3" will be + "1" + """ + def __init__(self): + # arbitrary number of arguments + super(self.__class__, self).__init__("cpulist_online", 0) + + def execute(self, args): + if not super(self.__class__, self).execute(args): + return None + cpus = self._cmd.cpulist_unpack(",".join(args)) + present = self._cmd.cpulist_unpack(self._cmd.read_file("/sys/devices/system/cpu/present")) + return ",".join(str(v) for v in set(present) - set(cpus))