First test with set_elevator command. It works only for single device so far...
This commit is contained in:
parent
b21a9bb990
commit
7658d29985
4 changed files with 58 additions and 9 deletions
|
|
@ -15,7 +15,7 @@ class Command(object):
|
|||
|
||||
@property
|
||||
def name(self):
|
||||
return self._desc
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def desc(self):
|
||||
|
|
|
|||
39
tuned/commands/command_set_elevator.py
Normal file
39
tuned/commands/command_set_elevator.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import tuned.commands
|
||||
import tuned.logs
|
||||
import os
|
||||
import struct
|
||||
|
||||
log = tuned.logs.get()
|
||||
|
||||
class SetElevatorCommand(tuned.commands.Command):
|
||||
"""
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
"""
|
||||
super(self.__class__, self).__init__("set_elevator")
|
||||
|
||||
def execute(self, args):
|
||||
dev = args[0];
|
||||
elevator = args[1]
|
||||
old_args = [dev, ""]
|
||||
|
||||
try:
|
||||
f = open(os.path.join("/sys/block/", dev, "queue/scheduler"), "r")
|
||||
old_args[1] = f.read()
|
||||
f.close()
|
||||
except (OSError,IOError) as e:
|
||||
log.error("Getting elevator of %s error: %s" % (dev, e))
|
||||
|
||||
log.debug("Applying elevator: %s < %s" % (dev, elevator))
|
||||
try:
|
||||
f = open(os.path.join("/sys/block/", dev, "queue/scheduler"), "w")
|
||||
f.write(elevator)
|
||||
f.close()
|
||||
except (OSError,IOError) as e:
|
||||
log.error("Setting elevator on %s error: %s" % (dev, e))
|
||||
return old_args
|
||||
|
||||
def revert(self, args):
|
||||
self.execute(args)
|
||||
|
|
@ -10,13 +10,13 @@ log = tuned.logs.get()
|
|||
class CommandRepository(tuned.patterns.Singleton):
|
||||
def __init__(self):
|
||||
super(self.__class__, self).__init__()
|
||||
self._loader = tuned.utils.PluginLoader("tuned.commands", "command_", tuned.plugins.Command)
|
||||
self._loader = tuned.utils.PluginLoader("tuned.commands", "command_", tuned.commands.Command)
|
||||
self._commands = {}
|
||||
|
||||
storage = tuned.utils.storage.Storage.get_instance()
|
||||
if storage.data.has_key("commands"):
|
||||
for command_name, args in data["sysctl"].iteritems():
|
||||
self._execute(command_name, args)
|
||||
self._revert(command_name, args)
|
||||
|
||||
storage.data["commands"] = {}
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ class CommandRepository(tuned.patterns.Singleton):
|
|||
# Store the previously set values
|
||||
storage = tuned.utils.storage.Storage.get_instance()
|
||||
|
||||
if not storage.data["commands"].has_key(command_name)
|
||||
if not storage.data["commands"].has_key(command_name):
|
||||
storage.data["commands"][command_name] = previous_args
|
||||
storage.save()
|
||||
else:
|
||||
|
|
@ -43,6 +43,15 @@ class CommandRepository(tuned.patterns.Singleton):
|
|||
# in a row and show error instead?
|
||||
pass
|
||||
|
||||
def _revert(self, command_name, args):
|
||||
# Load command on-the-fly
|
||||
if not self._commands.has_key(command_name):
|
||||
self._load_command(command_name)
|
||||
|
||||
# Execute command and get the previously set values.
|
||||
log.debug("reverting command %s with args %s" % (command_name, unicode(args)))
|
||||
self._commands[command_name].revert(args)
|
||||
|
||||
def revert(self, command_name):
|
||||
storage = tuned.utils.storage.Storage.get_instance()
|
||||
if not storage.data["commands"].has_key(command_name):
|
||||
|
|
@ -57,10 +66,10 @@ class CommandRepository(tuned.patterns.Singleton):
|
|||
try:
|
||||
command_cls = self._loader.load(command_name)
|
||||
command_instance = command_cls()
|
||||
self._commands[command_instance.name](command_instance)
|
||||
self._commands[command_instance.name] = command_instance
|
||||
return command_instance
|
||||
except Exception as exception:
|
||||
command_exception = tuned.plugins.exception.LoadCommandException(command_name, exception)
|
||||
command_exception = tuned.commands.exception.LoadCommandException(command_name, exception)
|
||||
raise command_exception
|
||||
|
||||
def delete(self, command_name):
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import os, copy
|
|||
import tuned.plugins
|
||||
import tuned.logs
|
||||
import tuned.monitors
|
||||
import tuned.commands
|
||||
import struct
|
||||
|
||||
log = tuned.logs.get()
|
||||
|
|
@ -136,13 +137,13 @@ class DiskPlugin(tuned.plugins.Plugin):
|
|||
for dev in self.devidle.keys():
|
||||
if self.devidle[dev]["LEVEL"] > 0:
|
||||
os.system("hdparm -S0 -B255 /dev/"+dev+" > /dev/null 2>&1")
|
||||
self._revert_elevator(dev)
|
||||
tuned.commands.get_repository().revert("set_elevator")
|
||||
|
||||
def update_tuning(self):
|
||||
load = self._load_monitor.get_load()
|
||||
for dev, devload in load.iteritems():
|
||||
if not self._elevator_set:
|
||||
self._apply_elevator(dev)
|
||||
if not self._elevator_set and len(self._options["elevator"]) != 0:
|
||||
tuned.commands.get_repository().execute("set_elevator", [dev, self._options["elevator"]])
|
||||
|
||||
self._init_stats(dev)
|
||||
self._update_stats(dev, devload)
|
||||
|
|
|
|||
Loading…
Reference in a new issue