Skip to content

Commit a0399cd

Browse files
committed
Allow non-default dynamic tuning implementations
Let plugins choose between the default (periodic) dynamic tuning and their own implementation. If a plugin uses the default periodic tuning, it must implement the update_tuning method which is then periodically called by the main daemon thread. Non-periodic implementations may, e.g., start their own threads.
1 parent a3fff7b commit a0399cd

File tree

6 files changed

+35
-10
lines changed

6 files changed

+35
-10
lines changed

tuned/daemon/daemon.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,28 @@ def __init__(self, unit_manager, profile_loader, profile_names=None, config=None
1919
self._daemon = consts.CFG_DEF_DAEMON
2020
self._sleep_interval = int(consts.CFG_DEF_SLEEP_INTERVAL)
2121
self._update_interval = int(consts.CFG_DEF_UPDATE_INTERVAL)
22-
self._dynamic_tuning = consts.CFG_DEF_DYNAMIC_TUNING
2322
self._recommend_command = True
2423
self._rollback = consts.CFG_DEF_ROLLBACK
24+
dynamic_plugins = []
2525
if config is not None:
2626
self._daemon = config.get_bool(consts.CFG_DAEMON, consts.CFG_DEF_DAEMON)
2727
self._sleep_interval = int(config.get(consts.CFG_SLEEP_INTERVAL, consts.CFG_DEF_SLEEP_INTERVAL))
2828
self._update_interval = int(config.get(consts.CFG_UPDATE_INTERVAL, consts.CFG_DEF_UPDATE_INTERVAL))
29-
self._dynamic_tuning = config.get_bool(consts.CFG_DYNAMIC_TUNING, consts.CFG_DEF_DYNAMIC_TUNING)
3029
self._recommend_command = config.get_bool(consts.CFG_RECOMMEND_COMMAND, consts.CFG_DEF_RECOMMEND_COMMAND)
3130
self._rollback = config.get(consts.CFG_ROLLBACK, consts.CFG_DEF_ROLLBACK)
31+
dynamic_plugins = config.get(consts.CFG_DYNAMIC_PLUGINS, [])
3232
self._application = application
33+
self._periodic_tuning = any(plugin.uses_periodic_tuning() for plugin in dynamic_plugins)
3334
if self._sleep_interval <= 0:
3435
self._sleep_interval = int(consts.CFG_DEF_SLEEP_INTERVAL)
3536
if self._update_interval == 0:
36-
self._dynamic_tuning = False
37+
self._periodic_tuning = False
3738
elif self._update_interval < self._sleep_interval:
3839
self._update_interval = self._sleep_interval
3940
self._sleep_cycles = self._update_interval // self._sleep_interval
40-
log.info("using sleep interval of %d second(s)" % self._sleep_interval)
41-
if self._dynamic_tuning:
42-
log.info("dynamic tuning is enabled (can be overridden by plugins)")
41+
if self._periodic_tuning:
42+
log.info("using sleep interval of %d second(s)" % self._sleep_interval)
43+
log.info("periodic tuning is enabled")
4344
log.info("using update interval of %d second(s) (%d times of the sleep interval)" % (self._sleep_cycles * self._sleep_interval, self._sleep_cycles))
4445

4546
self._profile_recommender = ProfileRecommender(is_hardcoded = not self._recommend_command)
@@ -215,7 +216,7 @@ def _thread_code(self):
215216
# For more details see TuneD rhbz#917587.
216217
_sleep_cnt = self._sleep_cycles
217218
while not self._cmd.wait(self._terminate, self._sleep_interval):
218-
if self._dynamic_tuning:
219+
if self._periodic_tuning:
219220
_sleep_cnt -= 1
220221
if _sleep_cnt <= 0:
221222
_sleep_cnt = self._sleep_cycles

tuned/plugins/base.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ def supports_static_tuning(cls):
6161
def supports_dynamic_tuning(cls):
6262
raise NotImplementedError()
6363

64+
@classmethod
65+
def uses_periodic_tuning(cls):
66+
raise NotImplementedError()
67+
6468
#
6569
# Plugin configuration manipulation and helpers.
6670
#
@@ -309,7 +313,7 @@ def instance_update_tuning(self, instance):
309313
"""
310314
if not instance.active:
311315
return
312-
if instance.dynamic_tuning_enabled:
316+
if instance.dynamic_tuning_enabled and self.uses_periodic_tuning():
313317
self._run_for_each_device(instance, self._instance_update_dynamic, instance.processed_devices.copy())
314318

315319
def instance_unapply_tuning(self, instance, rollback = consts.ROLLBACK_SOFT):
@@ -321,6 +325,7 @@ def instance_unapply_tuning(self, instance, rollback = consts.ROLLBACK_SOFT):
321325

322326
if instance.dynamic_tuning_enabled:
323327
self._run_for_each_device(instance, self._instance_unapply_dynamic, instance.processed_devices)
328+
self._instance_deinit_dynamic(instance)
324329
if instance.static_tuning_enabled:
325330
self._call_device_script(instance, instance.script_post,
326331
"unapply", instance.processed_devices,
@@ -350,11 +355,14 @@ def _instance_unapply_static(self, instance, rollback = consts.ROLLBACK_SOFT):
350355
def _instance_init_dynamic(self, instance):
351356
pass
352357

358+
def _instance_deinit_dynamic(self, instance):
359+
pass
360+
353361
def _instance_apply_dynamic(self, instance, device):
354362
for option in [opt for opt in self._options_used_by_dynamic if self._storage_get(instance, self._commands[opt], device) is None]:
355363
self._check_and_save_value(instance, self._commands[option], device)
356-
357-
self._instance_update_dynamic(instance, device)
364+
if self.uses_periodic_tuning():
365+
self._instance_update_dynamic(instance, device)
358366

359367
def _instance_unapply_dynamic(self, instance, device):
360368
pass

tuned/plugins/plugin_cpu.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ def supports_static_tuning(cls):
217217
def supports_dynamic_tuning(cls):
218218
return True
219219

220+
@classmethod
221+
def uses_periodic_tuning(cls):
222+
return True
223+
220224
def _init_devices(self):
221225
self._devices_supported = True
222226
self._free_devices = set()

tuned/plugins/plugin_disk.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ def supports_static_tuning(cls):
103103
def supports_dynamic_tuning(cls):
104104
return True
105105

106+
@classmethod
107+
def uses_periodic_tuning(cls):
108+
return True
109+
106110
def _init_devices(self):
107111
super(DiskPlugin, self)._init_devices()
108112
self._devices_supported = True

tuned/plugins/plugin_eeepc_she.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ def supports_static_tuning(cls):
4444
def supports_dynamic_tuning(cls):
4545
return True
4646

47+
@classmethod
48+
def uses_periodic_tuning(cls):
49+
return True
50+
4751
@classmethod
4852
def _get_config_options(self):
4953
return {

tuned/plugins/plugin_net.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ def supports_static_tuning(cls):
167167
def supports_dynamic_tuning(cls):
168168
return True
169169

170+
@classmethod
171+
def uses_periodic_tuning(cls):
172+
return True
173+
170174
def _init_devices(self):
171175
self._devices_supported = True
172176
self._free_devices = set()

0 commit comments

Comments
 (0)