Fix show_threads -t and show_irqs -q to not match everything if no match

Fix run command failing to apply BATCH policy
Add -U and -K to the move command
Resolves: RHEL-86862 RHEL-106065 RHEL-106066

Signed-off-by: John Kacur <jkacur@redhat.com>
This commit is contained in:
John Kacur 2025-08-06 13:59:13 -04:00
parent 176860966b
commit 22f5777720
4 changed files with 221 additions and 2 deletions

View File

@ -0,0 +1,66 @@
From 4e10e5b34593052e6ce4a166796b10c72f978efd Mon Sep 17 00:00:00 2001
From: John Kacur <jkacur@redhat.com>
Date: Thu, 5 Jun 2025 14:00:27 -0400
Subject: [PATCH 4/4] tuna: Add -U and -K to the move command
Add the following options to the move command (like in the show_threads
command)
-U, --no_uthreads Operations will not affect user threads
-K, --no_kthreads Operations will not affect kernel threads
Signed-off-by: John Kacur <jkacur@redhat.com>
---
tuna-cmd.py | 4 +++-
tuna/tuna.py | 7 ++++++-
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/tuna-cmd.py b/tuna-cmd.py
index 9496c61f0c2b..d0a3e6b7dbf8 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -174,6 +174,8 @@ def gen_parser():
move_group.add_argument('-N', '--nohz_full', **MODS['nohz_full'])
move.add_argument('-t', '--threads', **MODS['threads'])
move.add_argument('-q', '--irqs', **MODS['irqs'])
+ move.add_argument('-U', '--no_uthreads', **MODS['no_uthreads'])
+ move.add_argument('-K', '--no_kthreads', **MODS['no_kthreads'])
spread_group = spread.add_mutually_exclusive_group(required=True)
spread_group.add_argument('-c', '--cpus', **MODS['cpus'])
@@ -746,7 +748,7 @@ def main():
parser.error(f"tuna: {args.command} requires a thread/irq list!\n")
if args.thread_list:
- tuna.move_threads_to_cpu(args.cpu_list, args.thread_list, spread=spread)
+ tuna.move_threads_to_cpu(args.cpu_list, args.thread_list, args.uthreads, args.kthreads, spread=spread)
if args.irq_list:
tuna.move_irqs_to_cpu(args.cpu_list, args.irq_list, spread=spread)
diff --git a/tuna/tuna.py b/tuna/tuna.py
index 1380df0dadba..ef60c033362d 100755
--- a/tuna/tuna.py
+++ b/tuna/tuna.py
@@ -174,7 +174,7 @@ def is_hardirq_handler(self, pid):
except:
return False
-def move_threads_to_cpu(cpus, pid_list, set_affinity_warning=None, spread=False):
+def move_threads_to_cpu(cpus, pid_list, show_uthreads, show_kthreads, set_affinity_warning=None, spread=False):
changed = False
ps = procfs.pidstats()
@@ -183,6 +183,11 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning=None, spread=False)
new_affinity = cpus
last_cpu = max(cpus) + 1
for pid in pid_list:
+ iskth = iskthread(pid)
+ if not show_uthreads and not iskth:
+ continue
+ if not show_kthreads and iskth:
+ continue
if spread:
new_affinity = [cpus[cpu_idx]]
cpu_idx += 1
--
2.49.0

View File

@ -0,0 +1,31 @@
From 12633d556c48d4491eae3c25962591a2c9cd6c94 Mon Sep 17 00:00:00 2001
From: John Kacur <jkacur@redhat.com>
Date: Thu, 5 Jun 2025 11:54:42 -0400
Subject: [PATCH 3/4] tuna: Fix run command failing to apply BATCH policy
When using tuna run with -p BATCH the newly spawned process is created
with SCHED_OTHER instead of SCHED_BATCH
Fix this by calling thread_set_priority if the policy is not zero
Signed-off-by: John Kacur <jkacur@redhat.com>
---
tuna/tuna.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tuna/tuna.py b/tuna/tuna.py
index d4c3e2c1a661..1380df0dadba 100755
--- a/tuna/tuna.py
+++ b/tuna/tuna.py
@@ -621,7 +621,7 @@ def run_command(cmd, policy, rtprio, cpu_list, background):
if newpid == 0:
cmd_list = shlex.split(cmd)
pid = os.getpid()
- if rtprio:
+ if rtprio or policy:
try:
thread_set_priority(pid, policy, rtprio)
except (SystemError, OSError) as err:
--
2.49.0

View File

@ -0,0 +1,113 @@
From 1cfc9be610290f992299071d79031762cccbe2e6 Mon Sep 17 00:00:00 2001
From: John Kacur <jkacur@redhat.com>
Date: Fri, 30 May 2025 15:26:41 -0400
Subject: [PATCH 2/4] tuna: Fix show_threads -t and show_irqs -q
Fix show_threads -t and show_irqs -q to not match everything if there is
no match.
jkacur@fionn:~/src/tuna$ ./tuna-cmd.py show_threads | wc -l
428
jkacur@fionn:~/src/tuna$ ./tuna-cmd.py show_threads -t "nosuchthread" | wc -l
0
jkacur@fionn:~/src/tuna$ ./tuna-cmd.py show_threads -t "Isolated*" | wc -l
55
jkacur@fionn:~/src/tuna$ ./tuna-cmd.py show_irqs -q "iwlwifi*" | wc -l
14
jkacur@fionn:~/src/tuna$ ./tuna-cmd.py show_irqs | wc -l
58
jkacur@fionn:~/src/tuna$ ./tuna-cmd.py show_irqs -q "nosuchirq" | wc -l
0
Signed-off-by: John Kacur <jkacur@redhat.com>
---
tuna-cmd.py | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/tuna-cmd.py b/tuna-cmd.py
index 4997eaa5de92..9496c61f0c2b 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -79,6 +79,7 @@ except:
ps = None
irqs = None
+match_requested = False
class HelpMessageParser(argparse.ArgumentParser):
def error(self, message):
@@ -391,6 +392,8 @@ def ps_show(ps, affect_children, thread_list, cpu_list,
irq_list_numbers, show_uthreads, show_kthreads,
has_ctxt_switch_info, sock_inodes, sock_inode_re, cgroups, compact):
+ global match_requested
+
ps_list = []
for pid in list(ps.keys()):
iskth = tuna.iskthread(pid)
@@ -422,7 +425,11 @@ def ps_show(ps, affect_children, thread_list, cpu_list,
raise e
if cpu_list and not set(cpu_list).intersection(set(affinity)):
continue
- ps_list.append(pid)
+ if match_requested and thread_list and pid in thread_list:
+ ps_list.append(pid)
+ elif not match_requested:
+ ps_list.append(pid)
+
ps_list.sort()
@@ -498,6 +505,7 @@ def find_drivers_by_users(users):
def show_irqs(irq_list, cpu_list):
global irqs
+ global match_requested
if not irqs:
irqs = procfs.interrupts()
@@ -515,7 +523,11 @@ def show_irqs(irq_list, cpu_list):
if cpu_list and not set(cpu_list).intersection(set(affinity)):
continue
- sorted_irqs.append(irqn)
+
+ if match_requested and irq_list and irqn in irq_list:
+ sorted_irqs.append(irqn)
+ elif not match_requested:
+ sorted_irqs.append(irqn)
sorted_irqs.sort()
for irq in sorted_irqs:
@@ -540,6 +552,9 @@ def do_list_op(op, current_list, op_list):
def threadstring_to_list(threadstr):
global ps
+ global match_requested
+ if threadstr:
+ match_requested = True
thread_list = []
thread_strings = list(set(threadstr.split(',')))
for s in thread_strings:
@@ -555,6 +570,9 @@ def threadstring_to_list(threadstr):
def irqstring_to_list(irqstr):
+ global match_requested
+ if irqstr:
+ match_requested = True
irq_list = []
irq_strings = list(set(irqstr.split(',')))
for s in irq_strings:
@@ -636,6 +654,7 @@ def nohz_full_to_cpu():
_(" needs nohz_full=cpulist on the kernel command line"))
sys.exit(2)
+
def main():
global ps
--
2.49.0

View File

@ -1,6 +1,6 @@
Name: tuna
Version: 0.19
Release: 7%{?dist}
Release: 8%{?dist}
License: GPL-2.0-only AND LGPL-2.1-only
Summary: Application tuning GUI & command line utility
URL: https://git.kernel.org/pub/scm/utils/tuna/tuna.git
@ -23,6 +23,9 @@ Patch07: tuna-replace-match-with-if-statements-as-a-workaroun.patch
Patch08: tuna-Fix-string-syntax-warnings-with-raw-strings.patch
Patch09: 0001-tuna-Fix-help.py-syntax-warnings.patch
Patch10: 0002-tuna-help.py.patch
Patch11: tuna-Fix-show_threads-t-and-show_irqs-q.patch
Patch12: tuna-Fix-run-command-failing-to-apply-BATCH-policy.patch
Patch13: tuna-Add-U-and-K-to-the-move-command.patch
%description
Provides interface for changing scheduler and IRQ tunables, at whole CPU and at
@ -34,7 +37,7 @@ Can be used as a command line utility without requiring the GUI libraries to be
installed.
%prep
%autosetup -p1
%autosetup -v -p1
%build
%py3_build
@ -76,6 +79,12 @@ done
%{_datadir}/polkit-1/actions/org.tuna.policy
%changelog
* Wed Aug 06 2025 John Kacur <jkacur@redhat.com> - 0.19-8
- Fix show_threads -t and show_irqs -q to not match everything if no match
- Fix run command failing to apply BATCH policy
- Add -U and -K to the move command
Resolves: RHEL-86862 RHEL-106065 RHEL-106066
* Thu Jul 31 2025 John B. Wyatt IV <jwyatt@redhat.com> - 0.19-7
- Applied tuna: Fix help.py syntax warnings and tuna: help.py
Resolves: RHEL-106289