tuna: Fix show_threads -t and show_irqs -q
PATCH 1/3 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 <[email protected]>
--- tuna-cmd.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)
tuna-cmd.py +21 -2
@@ -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
Signature · 1 line
2.49.0
PATCH 2/3 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 <[email protected]>
--- tuna/tuna.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tuna/tuna.py +1 -1
@@ -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:
Signature · 1 line
2.49.0
PATCH 3/3 tuna: Add -U and -K to the move command
In reply to John KacurAdd 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 <[email protected]>
--- tuna-cmd.py | 4 +++- tuna/tuna.py | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-)
tuna-cmd.py +3 -1
@@ -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)
tuna/tuna.py +6 -1
@@ -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
Signature · 1 line
2.49.0