Commit f8d89a78 authored by Jaroslav Škarvada's avatar Jaroslav Škarvada

refs #40, daemon: added global config for dynamic_tuning

Added initial global config (/etc/tuned/tuned-main.conf) and
possibility to globally enable / disable dynamic tunings.

resolves: rhbz#1006427
Signed-off-by: default avatarJaroslav Škarvada <jskarvad@redhat.com>
parent 15ec06ae
......@@ -14,7 +14,7 @@ archive: clean
cp AUTHORS COPYING INSTALL README $(VERSIONED_NAME)
cp tuned.py tuned.spec tuned.service tuned.tmpfiles Makefile tuned-adm.py \
tuned.bash dbus.conf recommend.conf $(VERSIONED_NAME)
tuned.bash dbus.conf recommend.conf tuned-main.conf $(VERSIONED_NAME)
cp -a doc experiments man profiles systemtap tuned $(VERSIONED_NAME)
tar cjf $(VERSIONED_NAME).tar.bz2 $(VERSIONED_NAME)
......@@ -48,6 +48,7 @@ install:
# configuration files
mkdir -p $(DESTDIR)/etc/tuned
install -m 0644 tuned-main.conf $(DESTDIR)/etc/tuned/tuned-main.conf
# None profile in the moment, autodetection will be used
echo -n > $(DESTDIR)/etc/tuned/active_profile
......
.TH "tuned-main.conf" "5" "15 Oct 2013" "Jaroslav Škarvada" "tuned-main.conf file format description"
.SH NAME
tuned-main.conf \- Tuned global configuratio file
.SH SYNOPSIS
.B /etc/tuned/tuned-main.conf
.SH DESCRIPTION
This man page documents format of the Tuned global configuration file.
The \fItuned-main.conf\fR file uses the ini-file format.
.TP
.BI dynamic_tuning= BOOL
This defines whether the dynamic tuning is enabled. It is boolean value.
It can be \fBTrue\fR or \fB1\fR if the dynamic tuning is enabled and
\fBFalse\fR or \fB0\fR if disabled. In such case only the static tuning
will be used.
.SH EXAMPLE
.nf
dynamic_tuning = 1
.fi
.SH FILES
.I /etc/tuned/tuned-main.conf
.SH "SEE ALSO"
.LP
tuned(8)
.SH AUTHOR
Written by Jaroslav Škarvada <jskarvad@redhat.com>.
.SH REPORTING BUGS
Report bugs to <power-management@lists.fedoraproject.org>.
# Global tuned configuration file.
# Dynamicaly tune devices, if disabled only static tuning will be used.
dynamic_tuning = 1
......@@ -58,7 +58,9 @@ It can be also used to fine tune your system for specific scenarios.
%install
make install DESTDIR=%{buildroot}
%if 0%{?rhel}
sed -i 's/\(dynamic_tuning[ \t]*=[ \t]*\).*/\10/' %{buildroot}%{_sysconfdir}/tuned/tuned-main.conf
%endif
%post
%systemd_post tuned.service
......@@ -109,6 +111,7 @@ sed -i 's|.*/\([^/]\+\)/[^\.]\+\.conf|\1|' /etc/tuned/active_profile
%{_prefix}/lib/tuned
%dir %{_sysconfdir}/tuned
%config(noreplace) %{_sysconfdir}/tuned/active_profile
%config(noreplace) %{_sysconfdir}/tuned/tuned-main.conf
%{_sysconfdir}/tmpfiles.d
%{_sysconfdir}/dbus-1/system.d/com.redhat.tuned.conf
%{_unitdir}/tuned.service
......
GLOBAL_CONFIG_FILE = "/etc/tuned/tuned.conf"
ACTIVE_PROFILE_FILE = "/etc/tuned/active_profile"
AUTODETECT_FILE = "recommend.conf"
DAEMONIZE_PARENT_TIMEOUT = 5
......@@ -13,3 +14,5 @@ LOG_FILE_MAXBYTES = 100*1000
LOG_FILE = "/var/log/tuned/tuned.log"
PID_FILE = "/run/tuned/tuned.pid"
SYSTEM_RELEASE_FILE = "/etc/system-release-cpe"
# default configuration
CFG_DEF_DYNAMIC_TUNING = True
from tuned import storage, units, monitors, plugins, profiles, exports, hardware
from tuned.exceptions import TunedException
from configobj import ConfigObj
from validate import Validator
import tuned.logs
import controller
import daemon
......@@ -23,7 +25,13 @@ class Application(object):
device_matcher = hardware.DeviceMatcher()
plugin_instance_factory = plugins.instance.Factory()
plugins_repository = plugins.Repository(monitors_repository, storage_factory, hardware_inventory, device_matcher, plugin_instance_factory)
self.config = self._load_global_config()
if self.config.get("dynamic_tuning"):
log.info("dynamic tuning is globally enabled")
else:
log.info("dynamic tuning is globally disabled")
plugins_repository = plugins.Repository(monitors_repository, storage_factory, hardware_inventory, device_matcher, plugin_instance_factory, self.config)
unit_manager = units.Manager(plugins_repository, monitors_repository)
profile_factory = profiles.Factory()
......@@ -31,6 +39,7 @@ class Application(object):
profile_locator = profiles.Locator(consts.LOAD_DIRECTORIES)
profile_loader = profiles.Loader(profile_locator, profile_factory, profile_merger)
self._daemon = daemon.Daemon(unit_manager, profile_loader, profile_name)
self._controller = controller.Controller(self._daemon)
......@@ -161,6 +170,22 @@ class Application(object):
else:
sys.exit(1)
def _load_global_config(self, file_name = consts.GLOBAL_CONFIG_FILE):
"""
Loads global configuration file.
"""
log.debug("reading and parsing global configuration file '%s'" % consts.GLOBAL_CONFIG_FILE)
try:
config = ConfigObj(file_name, configspec=["dynamic_tuning = boolean(default=%s)" % consts.CFG_DEF_DYNAMIC_TUNING], raise_errors = True, file_error = True)
except IOError as e:
raise TunedException("Global tuned configuration file '%s' not found." % file_name)
except ConfigObjError as e:
raise TunedException("Error parsing global tuned configuration file '%s'." % file_name)
vdt = Validator()
if (not config.validate(vdt, copy=True)):
raise TunedException("Global tuned configuration file '%s' is not valid." % file_name)
return config
@property
def daemon(self):
return self._daemon
......
import tuned.consts as consts
import tuned.logs
import collections
......@@ -13,7 +14,7 @@ class Plugin(object):
Intentionally a lot of logic is included in the plugin to increase plugin flexibility.
"""
def __init__(self, monitors_repository, storage_factory, hardware_inventory, device_matcher, instance_factory):
def __init__(self, monitors_repository, storage_factory, hardware_inventory, device_matcher, instance_factory, global_cfg):
"""Plugin constructor."""
self._storage = storage_factory.create(self.__class__.__name__)
......@@ -26,6 +27,7 @@ class Plugin(object):
self._init_commands()
self._init_devices()
self._global_cfg = global_cfg
self._has_dynamic_options = False
self._options_used_by_dynamic = self._get_config_options_used_by_dynamic()
......@@ -179,7 +181,7 @@ class Plugin(object):
if instance.has_static_tuning:
self._instance_apply_static(instance)
if instance.has_dynamic_tuning:
if instance.has_dynamic_tuning and self._global_cfg.get("dynamic_tuning", consts.CFG_DEF_DYNAMIC_TUNING):
self._run_for_each_device(instance, self._instance_apply_dynamic)
def instance_update_tuning(self, instance):
......@@ -188,14 +190,14 @@ class Plugin(object):
"""
if not instance.active:
return
if instance.has_dynamic_tuning:
if instance.has_dynamic_tuning and self._global_cfg.get("dynamic_tuning", consts.CFG_DEF_DYNAMIC_TUNING):
self._run_for_each_device(instance, self._instance_update_dynamic)
def instance_unapply_tuning(self, instance):
"""
Remove all tunings applied by the plugin instance.
"""
if instance.has_dynamic_tuning:
if instance.has_dynamic_tuning and self._global_cfg.get("dynamic_tuning", consts.CFG_DEF_DYNAMIC_TUNING):
self._run_for_each_device(instance, self._instance_unapply_dynamic)
if instance.has_static_tuning:
self._instance_unapply_static(instance)
......
......@@ -8,7 +8,7 @@ __all__ = ["Repository"]
class Repository(PluginLoader):
def __init__(self, monitor_repository, storage_factory, hardware_inventory, device_matcher, plugin_instance_factory):
def __init__(self, monitor_repository, storage_factory, hardware_inventory, device_matcher, plugin_instance_factory, global_cfg):
super(self.__class__, self).__init__()
self._plugins = set()
self._monitor_repository = monitor_repository
......@@ -16,6 +16,7 @@ class Repository(PluginLoader):
self._hardware_inventory = hardware_inventory
self._device_matcher = device_matcher
self._plugin_instance_factory = plugin_instance_factory
self._global_cfg = global_cfg
@property
def plugins(self):
......@@ -29,7 +30,7 @@ class Repository(PluginLoader):
def create(self, plugin_name):
log.debug("creating plugin %s" % plugin_name)
plugin_cls = self.load_plugin(plugin_name)
plugin_instance = plugin_cls(self._monitor_repository, self._storage_factory, self._hardware_inventory, self._device_matcher, self._plugin_instance_factory)
plugin_instance = plugin_cls(self._monitor_repository, self._storage_factory, self._hardware_inventory, self._device_matcher, self._plugin_instance_factory, self._global_cfg)
self._plugins.add(plugin_instance)
return plugin_instance
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment