From 8efa8c964c15983f97679fb8be1d0dc00a12556c Mon Sep 17 00:00:00 2001 From: Jan Vcelak Date: Fri, 4 May 2012 12:02:59 +0200 Subject: [PATCH] create usb plugin, remove autosuspend from cpu plugin --- tuned/plugins/plugin_cpu.py | 26 ---------------------- tuned/plugins/plugin_usb.py | 44 +++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 26 deletions(-) create mode 100644 tuned/plugins/plugin_usb.py diff --git a/tuned/plugins/plugin_cpu.py b/tuned/plugins/plugin_cpu.py index dd75053..e71ce5e 100644 --- a/tuned/plugins/plugin_cpu.py +++ b/tuned/plugins/plugin_cpu.py @@ -37,9 +37,6 @@ class CPULatencyPlugin(tuned.plugins.Plugin): self.register_command("cpu_multicore_powersave", self._set_cpu_multicore_powersave, self._revert_cpu_multicore_powersave) - self.register_command("enable_usb_autosupend", - self._set_enable_usb_autosupend, - self._revert_enable_usb_autosupend) @classmethod def _get_default_options(cls): @@ -50,7 +47,6 @@ class CPULatencyPlugin(tuned.plugins.Plugin): "latency" : None, "cpu_governor" : None, "cpu_multicore_powersave" : None, - "enable_usb_autosupend" : None, } def cleanup(self): @@ -121,25 +117,3 @@ class CPULatencyPlugin(tuned.plugins.Plugin): @command_revert("cpu", "cpu_multicore_powersave") def _revert_cpu_multicore_powersave(self, value): tuned.utils.commands.execute(["cpupower", "set", "-m", value]) - - #TODO: Move USB to different plugin, I'm just not sure which one... - @command("cpu", "enable_usb_autosupend") - def _set_enable_usb_autosupend(self, value): - old_value = {} - if value == "1" or value == "true": - value = "1" - elif value == "0" or value == "false": - value = "0" - else: - log.warn("Incorrect enable_bluetooth value.") - return - for sys_file in glob.glob("/sys/bus/usb/devices/*/power/autosuspend"): - old_value[sys_file] = tuned.utils.commands.read_file(sys_file) - tuned.utils.commands.write_to_file(sys_file, value) - - return old_value - - @command_revert("cpu", "enable_usb_autosupend") - def _revert_enable_usb_autosupend(self, values): - for sys_file, value in values.iteritems(): - tuned.utils.commands.write_to_file(sys_file, value) diff --git a/tuned/plugins/plugin_usb.py b/tuned/plugins/plugin_usb.py new file mode 100644 index 0000000..18299a9 --- /dev/null +++ b/tuned/plugins/plugin_usb.py @@ -0,0 +1,44 @@ +import tuned.plugins +import tuned.log + +class USBPlugin(tuned.plugins.Plugin): + """ + """ + + def __init__(self, devices, options): + super(self.__class__, self).__init__(devices, options) + + self.register_command("enable_usb_autosupend", + self._set_enable_usb_autosupend, + self._revert_enable_usb_autosupend) + + @classmethod + def _get_default_options(cls): + return { + "enable_usb_autosuspend": None, + } + + def update_tuning(self): + # FIXME: can we drop this method? + pass + + @command("usb", "enable_usb_autosupend") + def _set_enable_usb_autosupend(self, value): + old_value = {} + if value == "1" or value == "true": + value = "1" + elif value == "0" or value == "false": + value = "0" + else: + log.warn("Incorrect enable_usb_autosuspend value.") + return + for sys_file in glob.glob("/sys/bus/usb/devices/*/power/autosuspend"): + old_value[sys_file] = tuned.utils.commands.read_file(sys_file) + tuned.utils.commands.write_to_file(sys_file, value) + + return old_value + + @command_revert("usb", "enable_usb_autosupend") + def _revert_enable_usb_autosupend(self, values): + for sys_file, value in values.iteritems(): + tuned.utils.commands.write_to_file(sys_file, value)