diff --git a/tuned/daemon/daemon.py b/tuned/daemon/daemon.py index d87d8cd0..b1ab159d 100644 --- a/tuned/daemon/daemon.py +++ b/tuned/daemon/daemon.py @@ -19,27 +19,28 @@ def __init__(self, unit_manager, profile_loader, profile_names=None, config=None self._daemon = consts.CFG_DEF_DAEMON self._sleep_interval = int(consts.CFG_DEF_SLEEP_INTERVAL) self._update_interval = int(consts.CFG_DEF_UPDATE_INTERVAL) - self._dynamic_tuning = consts.CFG_DEF_DYNAMIC_TUNING self._recommend_command = True self._rollback = consts.CFG_DEF_ROLLBACK + dynamic_plugins = [] if config is not None: self._daemon = config.get_bool(consts.CFG_DAEMON, consts.CFG_DEF_DAEMON) self._sleep_interval = int(config.get(consts.CFG_SLEEP_INTERVAL, consts.CFG_DEF_SLEEP_INTERVAL)) self._update_interval = int(config.get(consts.CFG_UPDATE_INTERVAL, consts.CFG_DEF_UPDATE_INTERVAL)) - self._dynamic_tuning = config.get_bool(consts.CFG_DYNAMIC_TUNING, consts.CFG_DEF_DYNAMIC_TUNING) self._recommend_command = config.get_bool(consts.CFG_RECOMMEND_COMMAND, consts.CFG_DEF_RECOMMEND_COMMAND) self._rollback = config.get(consts.CFG_ROLLBACK, consts.CFG_DEF_ROLLBACK) + dynamic_plugins = config.get(consts.CFG_DYNAMIC_PLUGINS, []) self._application = application + self._periodic_tuning = any(plugin.uses_periodic_tuning() for plugin in dynamic_plugins) if self._sleep_interval <= 0: self._sleep_interval = int(consts.CFG_DEF_SLEEP_INTERVAL) if self._update_interval == 0: - self._dynamic_tuning = False + self._periodic_tuning = False elif self._update_interval < self._sleep_interval: self._update_interval = self._sleep_interval self._sleep_cycles = self._update_interval // self._sleep_interval - log.info("using sleep interval of %d second(s)" % self._sleep_interval) - if self._dynamic_tuning: - log.info("dynamic tuning is enabled (can be overridden by plugins)") + if self._periodic_tuning: + log.info("using sleep interval of %d second(s)" % self._sleep_interval) + log.info("periodic tuning is enabled") log.info("using update interval of %d second(s) (%d times of the sleep interval)" % (self._sleep_cycles * self._sleep_interval, self._sleep_cycles)) self._profile_recommender = ProfileRecommender(is_hardcoded = not self._recommend_command) @@ -217,7 +218,7 @@ def _thread_code(self): # For more details see TuneD rhbz#917587. _sleep_cnt = self._sleep_cycles while not self._cmd.wait(self._terminate, self._sleep_interval): - if self._dynamic_tuning: + if self._periodic_tuning: _sleep_cnt -= 1 if _sleep_cnt <= 0: _sleep_cnt = self._sleep_cycles diff --git a/tuned/plugins/base.py b/tuned/plugins/base.py index 9c053eb5..c7292d6f 100644 --- a/tuned/plugins/base.py +++ b/tuned/plugins/base.py @@ -61,6 +61,10 @@ def supports_static_tuning(cls): def supports_dynamic_tuning(cls): raise NotImplementedError() + @classmethod + def uses_periodic_tuning(cls): + raise NotImplementedError() + # # Plugin configuration manipulation and helpers. # @@ -310,7 +314,7 @@ def instance_update_tuning(self, instance): """ if not instance.active: return - if instance.dynamic_tuning_enabled: + if instance.dynamic_tuning_enabled and self.uses_periodic_tuning(): self._run_for_each_device(instance, self._instance_update_dynamic, instance.processed_devices.copy()) def instance_unapply_tuning(self, instance, rollback = consts.ROLLBACK_SOFT): @@ -322,6 +326,7 @@ def instance_unapply_tuning(self, instance, rollback = consts.ROLLBACK_SOFT): if instance.dynamic_tuning_enabled: self._run_for_each_device(instance, self._instance_unapply_dynamic, instance.processed_devices) + self._instance_deinit_dynamic(instance) if instance.static_tuning_enabled: self._call_device_script(instance, instance.script_post, "unapply", instance.processed_devices, @@ -351,11 +356,14 @@ def _instance_unapply_static(self, instance, rollback = consts.ROLLBACK_SOFT): def _instance_init_dynamic(self, instance): pass + def _instance_deinit_dynamic(self, instance): + pass + def _instance_apply_dynamic(self, instance, device): for option in [opt for opt in self._options_used_by_dynamic if self._storage_get(instance, self._commands[opt], device) is None]: self._check_and_save_value(instance, self._commands[option], device) - - self._instance_update_dynamic(instance, device) + if self.uses_periodic_tuning(): + self._instance_update_dynamic(instance, device) def _instance_unapply_dynamic(self, instance, device): pass diff --git a/tuned/plugins/plugin_cpu.py b/tuned/plugins/plugin_cpu.py index 2204eecb..998896fe 100644 --- a/tuned/plugins/plugin_cpu.py +++ b/tuned/plugins/plugin_cpu.py @@ -217,6 +217,10 @@ def supports_static_tuning(cls): def supports_dynamic_tuning(cls): return True + @classmethod + def uses_periodic_tuning(cls): + return True + def _init_devices(self): self._devices_supported = True self._free_devices = set() diff --git a/tuned/plugins/plugin_disk.py b/tuned/plugins/plugin_disk.py index 7b133929..b95c37ba 100644 --- a/tuned/plugins/plugin_disk.py +++ b/tuned/plugins/plugin_disk.py @@ -103,6 +103,10 @@ def supports_static_tuning(cls): def supports_dynamic_tuning(cls): return True + @classmethod + def uses_periodic_tuning(cls): + return True + def _init_devices(self): super(DiskPlugin, self)._init_devices() self._devices_supported = True diff --git a/tuned/plugins/plugin_eeepc_she.py b/tuned/plugins/plugin_eeepc_she.py index 7c605494..cd192701 100644 --- a/tuned/plugins/plugin_eeepc_she.py +++ b/tuned/plugins/plugin_eeepc_she.py @@ -44,6 +44,10 @@ def supports_static_tuning(cls): def supports_dynamic_tuning(cls): return True + @classmethod + def uses_periodic_tuning(cls): + return True + @classmethod def _get_config_options(self): return { diff --git a/tuned/plugins/plugin_net.py b/tuned/plugins/plugin_net.py index 9e11cd82..44ec1bc9 100644 --- a/tuned/plugins/plugin_net.py +++ b/tuned/plugins/plugin_net.py @@ -167,6 +167,10 @@ def supports_static_tuning(cls): def supports_dynamic_tuning(cls): return True + @classmethod + def uses_periodic_tuning(cls): + return True + def _init_devices(self): self._devices_supported = True self._free_devices = set()