Skip to content

Commit

Permalink
Merge pull request #627 from zacikpa/tuned-adm-profile-check
Browse files Browse the repository at this point in the history
Re-check dbus when (re)starting TuneD from tuned-adm profile
  • Loading branch information
yarda authored May 23, 2024
2 parents 0fb790c + 8255b1f commit de2cf68
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
3 changes: 2 additions & 1 deletion tuned-adm.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ def check_log_level(value):
result = False

profile_dirs = config.get_list(consts.CFG_PROFILE_DIRS, consts.CFG_DEF_PROFILE_DIRS)
dbus = config.get_bool(consts.CFG_DAEMON, consts.CFG_DEF_DAEMON)
daemon = config.get_bool(consts.CFG_DAEMON, consts.CFG_DEF_DAEMON)
dbus = daemon and config.get_bool(consts.CFG_ENABLE_DBUS, consts.CFG_DEF_ENABLE_DBUS)

try:
admin = tuned.admin.Admin(profile_dirs, dbus, debug, asynco, timeout, log_level)
Expand Down
39 changes: 23 additions & 16 deletions tuned/admin/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@ def __init__(self, profile_dirs, dbus = True, debug = False,
self._log_token = None
self._log_level = log_level
self._profile_recommender = ProfileRecommender()
if self._dbus:
self._controller = tuned.admin.DBusController(consts.DBUS_BUS, consts.DBUS_INTERFACE, consts.DBUS_OBJECT, debug)
try:
self._controller.set_signal_handler(consts.SIGNAL_PROFILE_CHANGED, self._signal_profile_changed_cb)
except TunedAdminDBusException as e:
self._error(e)
self._dbus = False
self._dbus_working = self._init_dbus() if self._dbus else False

def _init_dbus(self):
self._controller = tuned.admin.DBusController(consts.DBUS_BUS, consts.DBUS_INTERFACE, consts.DBUS_OBJECT, self._debug)
try:
self._controller.set_signal_handler(consts.SIGNAL_PROFILE_CHANGED, self._signal_profile_changed_cb)
return True
except TunedAdminDBusException as e:
self._error(e)
return False

def _error(self, message):
print(message, file=sys.stderr)
Expand Down Expand Up @@ -70,24 +73,24 @@ def action(self, action_name, *args, **kwargs):
try:
action_dbus = getattr(self, "_action_dbus_" + action_name)
except AttributeError as e:
self._dbus = False
self._dbus_working = False
try:
action = getattr(self, "_action_" + action_name)
except AttributeError as e:
if not self._dbus:
if not self._dbus_working:
self._error(str(e) + ", action '%s' is not implemented" % action_name)
return False
if self._dbus:
if self._dbus_working:
try:
self._controller.set_on_exit_action(
self._log_capture_finish)
self._controller.set_action(action_dbus, *args, **kwargs)
res = self._controller.run()
except TunedAdminDBusException as e:
self._error(e)
self._dbus = False
self._dbus_working = False

if not self._dbus:
if not self._dbus_working:
res = action(*args, **kwargs)
return res

Expand Down Expand Up @@ -299,16 +302,20 @@ def _action_dbus_profile(self, profiles):
def _restart_tuned(self):
print("Trying to (re)start tuned...")
(ret, msg) = self._cmd.execute(["service", "tuned", "restart"])
if ret == 0:
print("TuneD (re)started, changes applied.")
else:
print("TuneD (re)start failed, you need to (re)start TuneD by hand for changes to apply.")
if ret != 0:
raise TunedException("TuneD (re)start failed, you need to (re)start TuneD by hand.")
print("TuneD (re)started.")

def _set_profile(self, profile_name, manual):
if profile_name in self._profiles_locator.get_known_names():
try:
if self._dbus:
self._restart_tuned()
if self._init_dbus():
return self._action_dbus_profile([profile_name])
self._cmd.save_active_profile(profile_name, manual)
self._restart_tuned()
print("TuneD is not active on the DBus, not checking whether the profile was successfully applied.")
return True
except TunedException as e:
self._error(str(e))
Expand Down

0 comments on commit de2cf68

Please sign in to comment.