From f3f05e426f05a5418fda1d0f8eb87a673e08ae85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Lyson=C4=9Bk?= Date: Sun, 3 Jun 2018 10:58:32 +0200 Subject: [PATCH] scheduler: Prevent a traceback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a new method for restoring original CPU affinity of processes _restore_ps_affinity() and call that in _instance_init() instead of _instance_unapply_static(). _instance_unapply_static() touches instance._terminate, which does not yet exist at that point (_instance_init always gets a fresh instance object). The reason this was not a problem in the past is that the true branch of "if len(instance._scheduler_original) > 0:" was never executed, because instance._scheduler_original was never correctly saved to storage. The next commit in this patch series fixes that. Signed-off-by: Ondřej Lysoněk --- tuned/plugins/plugin_scheduler.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tuned/plugins/plugin_scheduler.py b/tuned/plugins/plugin_scheduler.py index 890c2b3..6905bd1 100644 --- a/tuned/plugins/plugin_scheduler.py +++ b/tuned/plugins/plugin_scheduler.py @@ -57,7 +57,7 @@ class SchedulerPlugin(base.Plugin): instance._scheduler_original = self._storage.get(self._scheduler_storage_key(instance), {}) if len(instance._scheduler_original) > 0: log.info("recovering scheduling settings from previous run") - self._instance_unapply_static(instance) + self._restore_ps_affinity(instance) instance._scheduler_original = {} self._storage.unset(self._scheduler_storage_key(instance)) @@ -274,13 +274,8 @@ class SchedulerPlugin(base.Plugin): instance._thread = threading.Thread(target = self._thread_code, args = [instance]) instance._thread.start() - def _instance_unapply_static(self, instance, full_rollback = False): - super(SchedulerPlugin, self)._instance_unapply_static(instance, full_rollback) + def _restore_ps_affinity(self, instance): ps = self.get_processes() - if self._daemon and instance._runtime_tuning: - instance._terminate.set() - instance._thread.join() - for pid, vals in list(instance._scheduler_original.items()): # if command line for the pid didn't change, it's very probably the same process try: @@ -289,6 +284,15 @@ class SchedulerPlugin(base.Plugin): self._set_affinity(pid, vals[3]) except KeyError as e: pass + instance._scheduler_original = {} + self._storage.unset(self._scheduler_storage_key(instance)) + + def _instance_unapply_static(self, instance, full_rollback = False): + super(SchedulerPlugin, self)._instance_unapply_static(instance, full_rollback) + if self._daemon and instance._runtime_tuning: + instance._terminate.set() + instance._thread.join() + self._restore_ps_affinity(instance) def _add_pid(self, instance, pid, r): cmd = self.get_process(pid)