Update man page with cpu_power command

Update man page with cpu_power command
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-107914 RHEL-106070 RHEL-93776 RHEL-106068

Signed-off-by: John Kacur <jkacur@redhat.com>
This commit is contained in:
John Kacur 2025-08-06 16:13:18 -04:00
parent 04e0a19225
commit 0975cf7d36
5 changed files with 272 additions and 1 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

@ -0,0 +1,50 @@
From 84baeed49a3d3e0b6b20138cbfe5ecbcfdbc0d67 Mon Sep 17 00:00:00 2001
From: "John B. Wyatt IV" <jwyatt@redhat.com>
Date: Wed, 16 Jul 2025 16:23:27 -0400
Subject: [PATCH 1/4] tuna: Update man page with cpu_power command
[1] added support for the Python libcpupower bindings to control the
cpu power state. This patch documents those changes.
[1]
https://lore.kernel.org/linux-rt-users/20250409193136.44411-1-jwyatt@redhat.com/
Signed-off-by: John B. Wyatt IV <jwyatt@redhat.com>
Signed-off-by: John B. Wyatt IV <sageofredondo@gmail.com>
Signed-off-by: John Kacur <jkacur@redhat.com>
---
docs/tuna.8 | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/docs/tuna.8 b/docs/tuna.8
index 242389455f83..6e30537e9509 100644
--- a/docs/tuna.8
+++ b/docs/tuna.8
@@ -24,6 +24,24 @@ Log application details to file for given LOG-LEVEL
Print DEBUG level logging details to console
.SH "COMMANDS"
.TP
+\fBtuna cpu_power\fR
+usage: tuna-cmd.py cpu_power [-h] (-c CPU-LIST)
+
+Set or query the idle (power) states of all or a selection of cpus in the CPU-LIST. Modifiers \fB\-c\fR may be used to pass the CPU-LIST of cpus to perform the command on.
+
+optional arguments:
+ -h, --help show this help message and exit
+ -i, --idle-info Print general idle information for the selected CPUs, including
+ index values for IDLE-STATE.
+ -s, --status IDLE-STATE
+ Print whether IDLE-STATE is enabled on the selected CPUs.
+ -d, --disable IDLE-STATE
+ Disable IDLE-STATE on the selected CPUs.
+ -e, --enable IDLE-STATE
+ Enable IDLE-STATE on the selected CPUs.
+ -c CPU-LIST, --cpus CPU-LIST
+ CPU-LIST affected by commands
+.TP
\fBtuna isolate\fR
usage: tuna-cmd.py isolate [-h] (-c CPU-LIST | -S CPU-SOCKET-LIST | -N)
--
2.49.0

View File

@ -2,7 +2,7 @@
Name: tuna
Version: 0.19
Release: 13%{?dist}
Release: 14%{?dist}
License: GPL-2.0-only AND LGPL-2.1-only
Summary: Application tuning GUI & command line utility
Source: https://www.kernel.org/pub/software/utils/%{name}/%{name}-%{version}.tar.xz
@ -24,6 +24,10 @@ Patch6: 0003-tuna-utils-A-few-tweaks.patch
Patch7: tuna-Fix-string-syntax-warnings-with-raw-strings.patch
Patch8: 0001-tuna-Fix-help.py-syntax-warnings.patch
Patch9: 0002-tuna-help.py.patch
Patch10: tuna-Update-man-page-with-cpu_power-command.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
@ -77,6 +81,13 @@ done
%{_datadir}/polkit-1/actions/org.tuna.policy
%changelog
* Wed Aug 06 2025 John Kacur <jkacur@redhat.com> - 0.19-14
- Update man page with cpu_power command
- 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-107914 RHEL-106070 RHEL-93776 RHEL-106068
* Thu Jul 31 2025 John B. Wyatt IV <jwyatt@redhat.com> - 0.19-13
- Applied tuna: Fix help.py syntax warnings and tuna: help.py
- Requested to remove resolves statement from previous entry.