From b4ddf474480d0398b216f4a56b6a12df592ee582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Lyson=C4=9Bk?= Date: Mon, 28 May 2018 14:30:06 +0200 Subject: [PATCH] scheduler: Add a function for checking if a task is a kthread MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a function for checking if a task is a kernel thread. Signed-off-by: Ondřej Lysoněk --- tuned/plugins/plugin_scheduler.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tuned/plugins/plugin_scheduler.py b/tuned/plugins/plugin_scheduler.py index 35fb550..f5325ca 100644 --- a/tuned/plugins/plugin_scheduler.py +++ b/tuned/plugins/plugin_scheduler.py @@ -189,6 +189,11 @@ class SchedulerPlugin(base.Plugin): log.error("Failed to set scheduling parameters of PID %d: %s" % (pid, e)) + # process is a procfs.process object + # Raises OSError, IOError + def _is_kthread(self, process): + return process["stat"]["flags"] & procfs.pidstat.PF_KTHREAD != 0 + # Return codes: # 0 - Affinity is fixed # 1 - Affinity is changeable @@ -201,7 +206,7 @@ class SchedulerPlugin(base.Plugin): if process["stat"].is_bound_to_cpu(): if process["stat"]["state"] == "Z": log.debug("Affinity of zombie task with PID %d cannot be changed, the task's affinity mask is fixed." % pid) - elif process["stat"]["flags"] & procfs.pidstat.PF_KTHREAD != 0: + elif self._is_kthread(process): log.debug("Affinity of kernel thread with PID %d cannot be changed, the task's affinity mask is fixed." % pid) else: log.warn("Affinity of task with PID %d cannot be changed, the task's affinity mask is fixed." % pid)