[PATCH 19/23] tuna: Fix setting a realtime scheduling policy

John Kacur
2025-11-07T18:58:19Z

According to the tuna documentation if a user specifies a real-time
scheduling policy then the default priority is 1 if not specified.

Fix this in the gui by explicitly setting it to one in
thread_set_attributes

There were also some incorrect debugging messages in
thread_set_attributes because the affinity was sometimes treated as a
list and sometimes treated as a set.

Fix this by converting the results of os.sched_getscheduler(pid) to a
list

Signed-off-by: John Kacur <jkacur@redhat.com>
---
tuna/gui/util.py | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/tuna/gui/util.py b/tuna/gui/util.py
index 92bd368179cc..68bd7578f1c8 100644
--- a/tuna/gui/util.py
+++ b/tuna/gui/util.py
@@ -68,6 +68,9 @@ def thread_set_attributes(pid_info, new_policy, new_prio, new_affinity, nr_cpus)
curr_prio = int(pid_info["stat"]["rt_priority"])
if new_policy == os.SCHED_OTHER:
new_prio = 0
+ if new_policy == os.SCHED_FIFO or new_policy == os.SCHED_RR:
+ if not new_prio:
+ new_prio = 1
if curr_policy != new_policy or curr_prio != new_prio:
param = os.sched_param(new_prio)
try:
@@ -82,6 +85,7 @@ def thread_set_attributes(pid_info, new_policy, new_prio, new_affinity, nr_cpus)
dialog.destroy()
return False

+
curr_policy = os.sched_getscheduler(pid)
if curr_policy != new_policy:
print(_("couldn't change pid %(pid)d from %(cpol)s(%(cpri)d) to %(npol)s(%(npri)d)!") % \
@@ -93,7 +97,7 @@ def thread_set_attributes(pid_info, new_policy, new_prio, new_affinity, nr_cpus)
changed = True

try:
- curr_affinity = os.sched_getaffinity(pid)
+ curr_affinity = list(os.sched_getaffinity(pid))
except OSError as err:
if err.args[0] == errno.ESRCH:
return False
@@ -116,7 +120,7 @@ def thread_set_attributes(pid_info, new_policy, new_prio, new_affinity, nr_cpus)
return invalid_affinity()

try:
- curr_affinity = os.sched_getaffinity(pid)
+ curr_affinity = list(os.sched_getaffinity(pid))
except OSError as err:
if err.args[0] == errno.ESRCH:
return False
--
2.51.1