finished wireless functions and video functions
This commit is contained in:
parent
0c64bf3926
commit
0c2b174bbf
3 changed files with 118 additions and 0 deletions
|
|
@ -4,6 +4,7 @@ import tuned.monitors
|
|||
from tuned.utils.commands import *
|
||||
import os
|
||||
import struct
|
||||
import glob
|
||||
|
||||
log = tuned.logs.get()
|
||||
|
||||
|
|
@ -30,6 +31,9 @@ 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):
|
||||
|
|
@ -39,6 +43,7 @@ class CPULatencyPlugin(tuned.plugins.Plugin):
|
|||
"latency_high" : 1000,
|
||||
"cpu_governor" : "",
|
||||
"cpu_multicore_powersave" : "",
|
||||
"enable_usb_autosupend" : "",
|
||||
}
|
||||
|
||||
def cleanup(self):
|
||||
|
|
@ -102,3 +107,25 @@ 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)
|
||||
|
|
|
|||
72
tuned/plugins/plugin_video.py
Normal file
72
tuned/plugins/plugin_video.py
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
import tuned.plugins
|
||||
import tuned.logs
|
||||
import tuned.monitors
|
||||
from tuned.utils.commands import *
|
||||
import os
|
||||
import struct
|
||||
import glob
|
||||
|
||||
log = tuned.logs.get()
|
||||
|
||||
STORAGE_CATEGORY = "video"
|
||||
|
||||
class VideoPlugin(tuned.plugins.Plugin):
|
||||
"""
|
||||
"""
|
||||
|
||||
def __init__(self, devices, options):
|
||||
"""
|
||||
"""
|
||||
super(self.__class__, self).__init__(None, options)
|
||||
|
||||
self._commands_run = False
|
||||
|
||||
if not tuned.utils.storage.Storage.get_instance().data.has_key(STORAGE_CATEGORY):
|
||||
tuned.utils.storage.Storage.get_instance().data[STORAGE_CATEGORY] = {}
|
||||
|
||||
self.register_command("radeon_powersave",
|
||||
self._set_radeon_powersave,
|
||||
self._revert_radeon_powersave)
|
||||
|
||||
@classmethod
|
||||
def _get_default_options(cls):
|
||||
return {
|
||||
"radeon_powersave" : "",
|
||||
}
|
||||
|
||||
def cleanup(self):
|
||||
self.cleanup_commands()
|
||||
|
||||
def update_tuning(self):
|
||||
if not self._commands_run:
|
||||
self.execute_commands()
|
||||
self._commands_run = True
|
||||
|
||||
@command(STORAGE_CATEGORY, "radeon_powersave")
|
||||
def _set_radeon_powersave(self, value):
|
||||
if not os.path.exists("/sys/class/drm/card0/device/power_method"):
|
||||
return ""
|
||||
|
||||
old_values = []
|
||||
if value in ["default", "auto", "low", "med", "high"]:
|
||||
power_profile = tuned.utils.commands.read_file("/sys/class/drm/card0/device/power_profile")
|
||||
power_method = tuned.utils.commands.read_file("/sys/class/drm/card0/device/power_method")
|
||||
old_values = [power_profile, power_method]
|
||||
|
||||
tuned.utils.commands.write_to_file("/sys/class/drm/card0/device/power_method", "profile")
|
||||
tuned.utils.commands.write_to_file("/sys/class/drm/card0/device/power_profile", value)
|
||||
elif value == "dynpm":
|
||||
power_profile = tuned.utils.commands.read_file("/sys/class/drm/card0/device/power_profile")
|
||||
power_method = tuned.utils.commands.read_file("/sys/class/drm/card0/device/power_method")
|
||||
old_values = [None, power_method]
|
||||
|
||||
tuned.utils.commands.write_to_file("/sys/class/drm/card0/device/power_method", "dynpm")
|
||||
return old_values
|
||||
|
||||
@command_revert(STORAGE_CATEGORY, "radeon_powersave")
|
||||
def _revert_radeon_powersave(self, values):
|
||||
power_profile, power_method = values
|
||||
|
||||
tuned.utils.commands.write_to_file("/sys/class/drm/card0/device/power_method", power_method)
|
||||
if power_profile:
|
||||
tuned.utils.commands.write_to_file("/sys/class/drm/card0/device/power_profile", power_profile)
|
||||
|
|
@ -23,11 +23,13 @@ class WirelessPlugin(tuned.plugins.Plugin):
|
|||
tuned.utils.storage.Storage.get_instance().data["wireless"] = {}
|
||||
|
||||
self.register_command("wifi_power_level", self._set_wifi_power_level)
|
||||
self.register_command("enable_bluetooth", self._set_enable_bluetooth)
|
||||
|
||||
@classmethod
|
||||
def _get_default_options(cls):
|
||||
return {
|
||||
"wifi_power_level" : "",
|
||||
"enable_bluetooth" : "",
|
||||
}
|
||||
|
||||
def cleanup(self):
|
||||
|
|
@ -71,3 +73,20 @@ class WirelessPlugin(tuned.plugins.Plugin):
|
|||
tuned.utils.commands.write_to_file(sys_file, power_level)
|
||||
|
||||
return old_value
|
||||
|
||||
@command("wireless", "enable_bluetooth")
|
||||
def _set_enable_bluetooth(self, value):
|
||||
old_value = "" # TODO: Set old_value properly
|
||||
if value == "1" or value == "true":
|
||||
tuned.utils.commands.execute(["modprobe", "hci_usb"])
|
||||
tuned.utils.commands.execute(["hciconfig", "hci0", "up"])
|
||||
elif value == "0" or value == "false":
|
||||
tuned.utils.commands.execute(["hciconfig", "hci0", "down"])
|
||||
tuned.utils.commands.execute(["rmmod", "hci_usb"])
|
||||
else:
|
||||
log.warn("Incorrect enable_bluetooth value.")
|
||||
return ""
|
||||
|
||||
return old_value
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue