From 6ab5e5e4abdef3be239744e0584b7720d0a76840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20=C5=A0karvada?= Date: Sun, 24 May 2020 17:32:39 +0200 Subject: [PATCH] Allow override of detected architecture MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There should be a way for administrators and testers to force loading of architecture specific tuning. For example, if there is some specific tuning for some platforms with specific CPUIDs and the vendor will release new compatible platform with the new CPUID, there needs to be a way for administrator to use the tuning on the new platform without waiting for the Tuned profile update or without the need to customize the profile. This commit adds two main config options: uname_string cpuinfo_string If unset (commented), which is the default, runtime detection will be used, i.e. 'uname' will be called and '/proc/cpuinfo' will be read. If set, content of the variables will be used instead of the runtime detection. For example by setting: uname_string = aarch64 It's possible to pretend that Tuned is running on the 64-bit ARM. Signed-off-by: Jaroslav Škarvada --- tuned-main.conf | 10 ++++++++++ tuned/consts.py | 2 ++ tuned/daemon/application.py | 2 +- tuned/units/manager.py | 16 +++++++++++----- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/tuned-main.conf b/tuned-main.conf index 40c4be2..aeb9e4e 100644 --- a/tuned-main.conf +++ b/tuned-main.conf @@ -39,3 +39,13 @@ log_file_count = 2 # Log file max size log_file_max_size = 1MB + +# Preset system uname string for architecture specific tuning. +# It can be used to force tuning for specific architecture. +# If commented, "uname" will be called to fill its content. +# uname_string = x86_64 + +# Preset system cpuinfo string for architecture specific tuning. +# It can be used to force tuning for specific architecture. +# If commented, "/proc/cpuinfo" will be read to fill its content. +# cpuinfo_string = Intel diff --git a/tuned/consts.py b/tuned/consts.py index 40928ec..e68205b 100644 --- a/tuned/consts.py +++ b/tuned/consts.py @@ -71,6 +71,8 @@ CFG_RECOMMEND_COMMAND = "recommend_command" CFG_REAPPLY_SYSCTL = "reapply_sysctl" CFG_DEFAULT_INSTANCE_PRIORITY = "default_instance_priority" CFG_UDEV_BUFFER_SIZE = "udev_buffer_size" +CFG_UNAME_STRING = "uname_string" +CFG_CPUINFO_STRING = "cpuinfo_string" # no_daemon mode CFG_DEF_DAEMON = True diff --git a/tuned/daemon/application.py b/tuned/daemon/application.py index 396106b..18d54ce 100644 --- a/tuned/daemon/application.py +++ b/tuned/daemon/application.py @@ -41,7 +41,7 @@ class Application(object): def_instance_priority = int(self.config.get(consts.CFG_DEFAULT_INSTANCE_PRIORITY, consts.CFG_DEF_DEFAULT_INSTANCE_PRIORITY)) unit_manager = units.Manager( plugins_repository, monitors_repository, - def_instance_priority, hardware_inventory) + def_instance_priority, hardware_inventory, self.config) profile_factory = profiles.Factory() profile_merger = profiles.Merger() diff --git a/tuned/units/manager.py b/tuned/units/manager.py index 2fee283..56d255e 100644 --- a/tuned/units/manager.py +++ b/tuned/units/manager.py @@ -6,6 +6,7 @@ import tuned.exceptions import tuned.logs import tuned.plugins.exceptions import tuned.consts as consts +from tuned.utils.global_config import GlobalConfig from tuned.utils.commands import commands log = tuned.logs.get() @@ -18,7 +19,7 @@ class Manager(object): """ def __init__(self, plugins_repository, monitors_repository, - def_instance_priority, hardware_inventory): + def_instance_priority, hardware_inventory, config = None): super(Manager, self).__init__() self._plugins_repository = plugins_repository self._monitors_repository = monitors_repository @@ -26,6 +27,7 @@ class Manager(object): self._hardware_inventory = hardware_inventory self._instances = [] self._plugins = [] + self._config = config or GlobalConfig() self._cmd = commands() @property @@ -43,15 +45,19 @@ class Manager(object): def _unit_matches_cpuinfo(self, unit): if unit.cpuinfo_regex is None: return True - return re.search(unit.cpuinfo_regex, - self._cmd.read_file("/proc/cpuinfo"), + cpuinfo_string = self._config.get(consts.CFG_CPUINFO_STRING) + if cpuinfo_string is None: + cpuinfo_string = self._cmd.read_file("/proc/cpuinfo") + return re.search(unit.cpuinfo_regex, cpuinfo_string, re.MULTILINE) is not None def _unit_matches_uname(self, unit): if unit.uname_regex is None: return True - return re.search(unit.uname_regex, - " ".join(os.uname()), + uname_string = self._config.get(consts.CFG_UNAME_STRING) + if uname_string is None: + uname_string = " ".join(os.uname()) + return re.search(unit.uname_regex, uname_string, re.MULTILINE) is not None def create(self, instances_config):