diff --git a/tuned/plugins/plugin_cpu.py b/tuned/plugins/plugin_cpu.py index 217bc9a..e3092df 100644 --- a/tuned/plugins/plugin_cpu.py +++ b/tuned/plugins/plugin_cpu.py @@ -75,8 +75,7 @@ class CPULatencyPlugin(base.Plugin): def _is_cpu_online(self, device): sd = str(device) - # CPU0 is always online - return sd == "cpu0" or self._cmd.read_file("/sys/devices/system/cpu/%s/online" % sd).strip() == "1" + return self._cmd.is_cpu_online(str(device).replace("cpu", "")) def _instance_init(self, instance): instance._has_static_tuning = True diff --git a/tuned/profiles/functions/function_cpulist2hex.py b/tuned/profiles/functions/function_cpulist2hex.py new file mode 100644 index 0000000..2aacb13 --- /dev/null +++ b/tuned/profiles/functions/function_cpulist2hex.py @@ -0,0 +1,19 @@ +import os +import tuned.logs +import base +from tuned.utils.commands import commands + +log = tuned.logs.get() + +class cpulist2hex(base.Function): + """ + Conversion function: converts CPU list to hexadecimal CPU mask + """ + def __init__(self): + # arbitrary number of arguments + super(self.__class__, self).__init__("cpulist2hex", 0) + + def execute(self, args): + if not super(self.__class__, self).execute(args): + return None + return self._cmd.cpulist2hex(",".join(args)) diff --git a/tuned/profiles/functions/function_cpus_online.py b/tuned/profiles/functions/function_cpus_online.py new file mode 100644 index 0000000..d036ba6 --- /dev/null +++ b/tuned/profiles/functions/function_cpus_online.py @@ -0,0 +1,21 @@ +import os +import tuned.logs +import base +from tuned.utils.commands import commands + +log = tuned.logs.get() + +class cpus_online(base.Function): + """ + Checks whether CPUs from list are online, returns list containing + only online CPUs + """ + def __init__(self): + # arbitrary number of arguments + super(self.__class__, self).__init__("cpus_online", 0) + + def execute(self, args): + if not super(self.__class__, self).execute(args): + return None + cpus = ",".join(args) + return ",".join(filter(lambda cpu: self._cmd.is_cpu_online(cpu), cpus.split(","))) diff --git a/tuned/profiles/functions/function_hex2cpulist.py b/tuned/profiles/functions/function_hex2cpulist.py new file mode 100644 index 0000000..76338f9 --- /dev/null +++ b/tuned/profiles/functions/function_hex2cpulist.py @@ -0,0 +1,19 @@ +import os +import tuned.logs +import base +from tuned.utils.commands import commands + +log = tuned.logs.get() + +class hex2cpulist(base.Function): + """ + Conversion function: converts hexadecimal CPU mask to CPU list + """ + def __init__(self): + # one argument + super(self.__class__, self).__init__("hex2cpulist", 1) + + def execute(self, args): + if not super(self.__class__, self).execute(args): + return None + return ",".join(self._cmd.hex2cpulist(args[0])) diff --git a/tuned/profiles/functions/function_kb2s.py b/tuned/profiles/functions/function_kb2s.py index 7bdb381..d5deabd 100644 --- a/tuned/profiles/functions/function_kb2s.py +++ b/tuned/profiles/functions/function_kb2s.py @@ -8,7 +8,7 @@ class kb2s(base.Function): Conversion function: kbytes to sectors """ def __init__(self): - # 1 argument + # one argument super(self.__class__, self).__init__("kb2s", 1) def execute(self, args): diff --git a/tuned/profiles/functions/function_s2kb.py b/tuned/profiles/functions/function_s2kb.py index f7e03da..021d103 100644 --- a/tuned/profiles/functions/function_s2kb.py +++ b/tuned/profiles/functions/function_s2kb.py @@ -8,7 +8,7 @@ class s2kb(base.Function): Conversion function: sectors to kbytes """ def __init__(self): - # 1 argument + # one argument super(self.__class__, self).__init__("s2kb", 1) def execute(self, args): diff --git a/tuned/profiles/functions/functions.py b/tuned/profiles/functions/functions.py index 335a0b9..3489cf6 100644 --- a/tuned/profiles/functions/functions.py +++ b/tuned/profiles/functions/functions.py @@ -43,6 +43,6 @@ class Functions(): def expand(self, s): if s is None: return s - r = re.compile(r'(? 0: + if m & 1: + cpus.append(str(cpu)) + m >>= 1 + cpu += 1 + return cpus + + # Unpacks CPU list, i.e. 1-3 will be converted to 1, 2, 3 + def unpack_cpulist(self, l): + rl = [] + if l is None: + return l + ll = str(l).split(",") + for v in ll: + vl = v.split("-") + try: + if len(vl) > 1: + rl += range(int(vl[0]), int(vl[1]) + 1) + else: + rl.append(int(vl[0])) + except ValueError: + return None + return sorted(list(set(rl))) + + # Converts CPU list to hexadecimal CPU mask + def cpulist2hex(self, l): + if l is None: + return None + m = 0 + ul = self.unpack_cpulist(l) + if ul is None: + return None + for v in self.unpack_cpulist(l): + m |= pow(2, v) + return "0x%08x" % m + def recommend_profile(self): profile = consts.DEFAULT_PROFILE for f in consts.LOAD_DIRECTORIES: