forked from redhat-performance/tuned
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request redhat-performance#579 from zacikpa/ppd-daemon
PPD-to-TuneD API translation daemon
- Loading branch information
Showing
17 changed files
with
528 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/python3 -Es | ||
import sys | ||
import os | ||
import dbus | ||
import signal | ||
from dbus.mainloop.glib import DBusGMainLoop | ||
from tuned import exports | ||
from tuned.ppd import controller | ||
import tuned.consts as consts | ||
|
||
|
||
def handle_signal(signal_number, handler): | ||
def handler_wrapper(_signal_number, _frame): | ||
if signal_number == _signal_number: | ||
handler() | ||
signal.signal(signal_number, handler_wrapper) | ||
|
||
if __name__ == "__main__": | ||
if os.geteuid() != 0: | ||
print("Superuser permissions are required to run the daemon.", file=sys.stderr) | ||
sys.exit(1) | ||
|
||
DBusGMainLoop(set_as_default=True) | ||
bus = dbus.SystemBus() | ||
try: | ||
tuned_object = bus.get_object(consts.DBUS_BUS, consts.DBUS_OBJECT) | ||
except dbus.exceptions.DBusException: | ||
print("TuneD not found on the DBus, ensure that it is running.", file=sys.stderr) | ||
sys.exit(1) | ||
tuned_iface = dbus.Interface(tuned_object, consts.DBUS_INTERFACE) | ||
|
||
controller = controller.Controller(bus, tuned_iface) | ||
|
||
handle_signal(signal.SIGINT, controller.terminate) | ||
handle_signal(signal.SIGTERM, controller.terminate) | ||
handle_signal(signal.SIGHUP, controller.load_config) | ||
|
||
dbus_exporter = exports.dbus_with_properties.DBusExporterWithProperties( | ||
consts.PPD_DBUS_BUS, consts.PPD_DBUS_INTERFACE, consts.PPD_DBUS_OBJECT, consts.PPD_NAMESPACE | ||
) | ||
|
||
exports.register_exporter(dbus_exporter) | ||
exports.register_object(controller) | ||
controller.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -264,6 +264,17 @@ Requires: %{name} = %{version} | |
%description profiles-openshift | ||
Additional TuneD profile(s) optimized for OpenShift. | ||
|
||
%package ppd | ||
Summary: PPD compatibility daemon | ||
Requires: %{name} = %{version} | ||
# The compatibility daemon is swappable for power-profiles-daemon | ||
Provides: ppd-service | ||
Conflicts: ppd-service | ||
|
||
%description ppd | ||
An API translation daemon that allows applications to easily transition | ||
to TuneD from power-profiles-daemon (PPD). | ||
|
||
%prep | ||
%autosetup -p1 -n %{name}-%{version}%{?prerel2} | ||
|
||
|
@@ -276,6 +287,7 @@ make html %{make_python_arg} | |
|
||
%install | ||
make install DESTDIR=%{buildroot} DOCDIR=%{docdir} %{make_python_arg} | ||
make install-ppd DESTDIR=%{buildroot} DOCDIR=%{docdir} %{make_python_arg} | ||
%if 0%{?rhel} | ||
sed -i 's/\(dynamic_tuning[ \t]*=[ \t]*\).*/\10/' %{buildroot}%{_sysconfdir}/tuned/tuned-main.conf | ||
%endif | ||
|
@@ -556,6 +568,14 @@ fi | |
%{_prefix}/lib/tuned/openshift-node | ||
%{_mandir}/man7/tuned-profiles-openshift.7* | ||
|
||
%files ppd | ||
%{_sbindir}/tuned-ppd | ||
%{_unitdir}/tuned-ppd.service | ||
%{_datadir}/dbus-1/system-services/net.hadess.PowerProfiles.service | ||
%{_datadir}/dbus-1/system.d/net.hadess.PowerProfiles.conf | ||
%{_datadir}/polkit-1/actions/net.hadess.PowerProfiles.policy | ||
%config(noreplace) %{_sysconfdir}/tuned/ppd.conf | ||
|
||
%changelog | ||
* Tue Aug 29 2023 Jaroslav Škarvada <[email protected]> - 2.21.0-1 | ||
- new release | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from inspect import ismethod | ||
from dbus.service import method, signal | ||
from dbus import PROPERTIES_IFACE | ||
from dbus.exceptions import DBusException | ||
from tuned.exports.dbus_exporter import DBusExporter | ||
|
||
|
||
class DBusExporterWithProperties(DBusExporter): | ||
def __init__(self, bus_name, interface_name, object_name, namespace): | ||
super(DBusExporterWithProperties, self).__init__(bus_name, interface_name, object_name, namespace) | ||
self._property_setters = {} | ||
self._property_getters = {} | ||
|
||
def Get(_, interface_name, property_name): | ||
if interface_name != self._interface_name: | ||
raise DBusException("Unknown interface: %s" % interface_name) | ||
if property_name not in self._property_getters: | ||
raise DBusException("No such property: %s" % property_name) | ||
getter = self._property_getters[property_name] | ||
return getter() | ||
|
||
def Set(_, interface_name, property_name, value): | ||
if interface_name != self._interface_name: | ||
raise DBusException("Unknown interface: %s" % interface_name) | ||
if property_name not in self._property_setters: | ||
raise DBusException("No such property: %s" % property_name) | ||
setter = self._property_setters[property_name] | ||
setter(value) | ||
|
||
def GetAll(_, interface_name): | ||
if interface_name != self._interface_name: | ||
raise DBusException("Unknown interface: %s" % interface_name) | ||
return {name: getter() for name, getter in self._property_getters.items()} | ||
|
||
def PropertiesChanged(_, interface_name, changed_properties, invalidated_properties): | ||
if interface_name != self._interface_name: | ||
raise DBusException("Unknown interface: %s" % interface_name) | ||
|
||
self._dbus_methods["Get"] = method(PROPERTIES_IFACE, in_signature="ss", out_signature="v")(Get) | ||
self._dbus_methods["Set"] = method(PROPERTIES_IFACE, in_signature="ssv")(Set) | ||
self._dbus_methods["GetAll"] = method(PROPERTIES_IFACE, in_signature="s", out_signature="a{sv}")(GetAll) | ||
self._dbus_methods["PropertiesChanged"] = signal(PROPERTIES_IFACE, signature="sa{sv}as")(PropertiesChanged) | ||
self._signals.add("PropertiesChanged") | ||
|
||
def property_changed(self, property_name, value): | ||
self.send_signal("PropertiesChanged", self._interface_name, {property_name: value}, {}) | ||
|
||
def property_getter(self, method, property_name): | ||
if not ismethod(method): | ||
raise Exception("Only bound methods can be exported.") | ||
if property_name in self._property_getters: | ||
raise Exception("A getter for this property is already registered.") | ||
self._property_getters[property_name] = method | ||
|
||
def property_setter(self, method, property_name): | ||
if not ismethod(method): | ||
raise Exception("Only bound methods can be exported.") | ||
if property_name in self._property_setters: | ||
raise Exception("A setter for this property is already registered.") | ||
self._property_setters[property_name] = method |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from tuned.utils.config_parser import ConfigParser, Error | ||
from tuned.exceptions import TunedException | ||
import os | ||
|
||
PPD_POWER_SAVER = "power-saver" | ||
PPD_PERFORMANCE = "performance" | ||
|
||
MAIN_SECTION = "main" | ||
PROFILES_SECTION = "profiles" | ||
DEFAULT_PROFILE_OPTION = "default" | ||
|
||
|
||
class PPDConfig: | ||
def __init__(self, config_file): | ||
self.load_from_file(config_file) | ||
|
||
@property | ||
def default_profile(self): | ||
return self._default_profile | ||
|
||
@property | ||
def ppd_to_tuned(self): | ||
return self._ppd_to_tuned | ||
|
||
@property | ||
def tuned_to_ppd(self): | ||
return self._tuned_to_ppd | ||
|
||
def load_from_file(self, config_file): | ||
cfg = ConfigParser() | ||
|
||
if not os.path.isfile(config_file): | ||
raise TunedException("Configuration file '%s' does not exist" % config_file) | ||
try: | ||
cfg.read(config_file) | ||
except Error: | ||
raise TunedException("Error parsing the configuration file '%s'" % config_file) | ||
|
||
if PROFILES_SECTION not in cfg: | ||
raise TunedException("Missing profiles section in the configuration file '%s'" % config_file) | ||
self._ppd_to_tuned = dict(cfg[PROFILES_SECTION]) | ||
|
||
if not all(isinstance(mapped_profile, str) for mapped_profile in self._ppd_to_tuned.values()): | ||
raise TunedException("Invalid profile mapping in the configuration file '%s'" % config_file) | ||
|
||
if len(set(self._ppd_to_tuned.values())) != len(self._ppd_to_tuned): | ||
raise TunedException("Duplicate profile mapping in the configuration file '%s'" % config_file) | ||
self._tuned_to_ppd = {v: k for k, v in self._ppd_to_tuned.items()} | ||
|
||
if PPD_POWER_SAVER not in self._ppd_to_tuned: | ||
raise TunedException("Missing power-saver profile in the configuration file '%s'" % config_file) | ||
|
||
if PPD_PERFORMANCE not in self._ppd_to_tuned: | ||
raise TunedException("Missing performance profile in the configuration file '%s'" % config_file) | ||
|
||
if MAIN_SECTION not in cfg or DEFAULT_PROFILE_OPTION not in cfg[MAIN_SECTION]: | ||
raise TunedException("Missing default profile in the configuration file '%s'" % config_file) | ||
|
||
self._default_profile = cfg[MAIN_SECTION][DEFAULT_PROFILE_OPTION] | ||
if self._default_profile not in self._ppd_to_tuned: | ||
raise TunedException("Unknown default profile '%s'" % self._default_profile) |
Oops, something went wrong.