plugins: added sysfs plugin
This commit is contained in:
parent
075fc62ed6
commit
fc97d2b279
3 changed files with 60 additions and 3 deletions
|
|
@ -174,7 +174,7 @@ class Plugin(object):
|
|||
|
||||
def _merge_options(self, options):
|
||||
for key in options:
|
||||
if key in self._options or self.__class__.__name__ == "SysctlPlugin":
|
||||
if key in self._options or self.__class__.__name__ in ["SysctlPlugin", "SysfsPlugin"]:
|
||||
self._options[key] = options[key]
|
||||
else:
|
||||
log.warn("Unknown option '%s' for plugin '%s'." % (key, self.__class__.__name__))
|
||||
|
|
|
|||
55
tuned/plugins/plugin_sysfs.py
Normal file
55
tuned/plugins/plugin_sysfs.py
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import base
|
||||
import os.path
|
||||
from decorators import *
|
||||
import tuned.logs
|
||||
from subprocess import *
|
||||
import tuned.utils.commands
|
||||
|
||||
log = tuned.logs.get()
|
||||
|
||||
class SysfsPlugin(base.Plugin):
|
||||
"""
|
||||
Plugin for applying custom sysfs options, using specific plugins is preferred.
|
||||
"""
|
||||
|
||||
# TODO: resolve possible conflicts with sysctl settings from other plugins
|
||||
def _post_init(self):
|
||||
self._dynamic_tuning = False
|
||||
self._sysfs_original = {}
|
||||
self._sysfs = self._options
|
||||
|
||||
for key, value in self._sysfs.iteritems():
|
||||
self._sysfs_original[key] = self._read_sysfs(key)
|
||||
|
||||
@classmethod
|
||||
def tunable_devices(self):
|
||||
return ["sysfs"]
|
||||
|
||||
@classmethod
|
||||
def _get_default_options(cls):
|
||||
return {}
|
||||
|
||||
def _read_sysfs(self, sysfs_file):
|
||||
data = tuned.utils.commands.read_file(sysfs_file)
|
||||
value = None
|
||||
if len(data):
|
||||
value = tuned.utils.commands.get_active_option(data, False)
|
||||
return value
|
||||
|
||||
def _write_sysfs(self, sysfs_file, value):
|
||||
return tuned.utils.commands.write_to_file(sysfs_file, value)
|
||||
|
||||
def _apply_sysfs(self):
|
||||
for key, value in self._sysfs.iteritems():
|
||||
self._write_sysfs(key, value)
|
||||
return True
|
||||
|
||||
def _revert_sysfs(self):
|
||||
for key, value in self._sysfs_original.iteritems():
|
||||
self._write_sysfs(key, value)
|
||||
|
||||
def cleanup_commands(self):
|
||||
self._revert_sysfs()
|
||||
|
||||
def execute_commands(self):
|
||||
self._apply_sysfs()
|
||||
|
|
@ -49,11 +49,13 @@ def execute(args):
|
|||
# Helper for parsing kernel options like:
|
||||
# [always] never
|
||||
# It will return 'always'
|
||||
def get_active_option(options):
|
||||
def get_active_option(options, dosplit = True):
|
||||
m = re.match(r'.*\[([^\]]+)\].*', options)
|
||||
if m:
|
||||
return m.group(1)
|
||||
return options.split()[0]
|
||||
if dosplit:
|
||||
return options.split()[0]
|
||||
return options
|
||||
|
||||
def recommend_profile():
|
||||
profile = consts.DEFAULT_PROFILE
|
||||
|
|
|
|||
Loading…
Reference in a new issue