[PATCH 0/2] recent patches backported to getopt branch
by John Kacur
These two patches have been backported to the getopt branch too.
John Kacur (2):
tuna: Fix matching irqs in ps_show_thread
tuna: Replace python_ethtool with builtin funtionality
tuna-cmd.py | 17 ++++++-----------
tuna/gui/irqview.py | 2 +-
tuna/new_eth.py | 37 +++++++++++++++++++++++++++++++++++++
tuna/tuna.py | 2 +-
4 files changed, 45 insertions(+), 13 deletions(-)
create mode 100755 tuna/new_eth.py
--
2.37.3
1 year, 6 months
[PATCH] tuna: Fix matching irqs in ps_show_thread
by John Kacur
To new format to match irqs is "irqs/"
We already test this when we call is_irq_thread(cmd):
With this fix if you do
tuna show_threads
You will get nic information that was previously missed such as
986 FIFO 50 9 69286 2 irq/164-iwlwifi:default_que
ue iwlwifi:default_queue
Signed-off-by: John Kacur <jkacur(a)redhat.com>
---
tuna-cmd.py | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/tuna-cmd.py b/tuna-cmd.py
index b13b25b8a801..80e27523acc6 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -351,17 +351,12 @@ def ps_show_thread(pid, affect_children, ps, has_ctxt_switch_info, sock_inodes,
try:
if not irqs:
irqs = procfs.interrupts()
- if cmd[:4] == "IRQ-":
- users = irqs[tuna.irq_thread_number(cmd)]["users"]
- for u in users:
- if u in get_nics():
- users[users.index(u)] = "%s(%s)" % (
- u, ethtool.get_module(u))
- users = ",".join(users)
- else:
- u = cmd[cmd.find('-') + 1:]
+ users = irqs[tuna.irq_thread_number(cmd)]["users"]
+ for u in users:
if u in get_nics():
- users = ethtool.get_module(u)
+ users[users.index(u)] = "%s(%s)" % (
+ u, ethtool.get_module(u))
+ users = ",".join(users)
except:
users = "Not found in /proc/interrupts!"
--
2.37.3
1 year, 6 months
[PATCH v2] tuna: Replace python_ethtool with builtin funtionality
by John Kacur
This patch replaces some the dependency on python_ethtool with some
simplified functions to achieve the same result.
Reviewed-by: Federico Pellegrin <fede(a)evolware.org>
- return 'tun' only if tun_flags exists
Signed-off-by: John Kacur <jkacur(a)redhat.com>
---
tuna-cmd.py | 2 +-
tuna/gui/irqview.py | 2 +-
tuna/new_eth.py | 37 +++++++++++++++++++++++++++++++++++++
tuna/tuna.py | 2 +-
4 files changed, 40 insertions(+), 3 deletions(-)
create mode 100755 tuna/new_eth.py
diff --git a/tuna-cmd.py b/tuna-cmd.py
index 9a3d3f32398b..b13b25b8a801 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -26,7 +26,7 @@ import fnmatch
import gettext
import locale
from functools import reduce
-import ethtool
+import tuna.new_eth as ethtool
import tuna.tuna_sched as tuna_sched
import procfs
from tuna import tuna, sysfs
diff --git a/tuna/gui/irqview.py b/tuna/gui/irqview.py
index 35fc3fd0b0ca..5143d6dc0df5 100755
--- a/tuna/gui/irqview.py
+++ b/tuna/gui/irqview.py
@@ -7,7 +7,7 @@ from gi.repository import Gtk
from gi.repository import GObject
import os
from functools import reduce
-import ethtool
+import tuna.new_eth as ethtool
import tuna.tuna_sched as tuna_sched
import gi
diff --git a/tuna/new_eth.py b/tuna/new_eth.py
new file mode 100755
index 000000000000..98f9179d5695
--- /dev/null
+++ b/tuna/new_eth.py
@@ -0,0 +1,37 @@
+# Copyright (C) 2022 John Kacur
+""" A few functions similar to ethtool """
+import os
+import socket
+
+def get_active_devices():
+ """ return a list of network devices """
+ ret = []
+
+ for device in socket.if_nameindex():
+ ret.append(device[1])
+
+ return ret
+
+def get_module(intf):
+ """ return the kernel module for the given network interface """
+ if intf == 'lo':
+ return ""
+ myp = f'/sys/class/net/{intf}/device/driver'
+ if os.path.exists(myp):
+ return os.path.basename(os.readlink(myp))
+ if os.path.exists(f'/sys/class/net/{intf}/bridge'):
+ return 'bridge'
+ if os.path.exists(f'/sys/class/net/{intf}/tun_flags'):
+ return 'tun'
+ return ""
+
+if __name__ == "__main__":
+ nics = get_active_devices()
+ print(f'nics = {nics}')
+
+ for intf in nics:
+ driver = get_module(intf)
+ if driver:
+ print(f'{intf}, {driver}')
+ else:
+ print(f'{intf}')
diff --git a/tuna/tuna.py b/tuna/tuna.py
index 30a5a570c9d4..43adb84079e4 100755
--- a/tuna/tuna.py
+++ b/tuna/tuna.py
@@ -9,7 +9,7 @@ import sys
import shlex
import fnmatch
import platform
-import ethtool
+import tuna.new_eth as ethtool
import procfs
from procfs import utilist
from tuna import help
--
2.37.3
1 year, 7 months
[PATCH] tuna: Replace python_ethtool with builtin funtionality
by John Kacur
This patch replaces some the dependency on python_ethtool with some
simplified functions to achieve the same result.
Signed-off-by: John Kacur <jkacur(a)redhat.com>
---
tuna-cmd.py | 2 +-
tuna/gui/irqview.py | 2 +-
tuna/new_eth.py | 37 +++++++++++++++++++++++++++++++++++++
tuna/tuna.py | 2 +-
4 files changed, 40 insertions(+), 3 deletions(-)
create mode 100755 tuna/new_eth.py
diff --git a/tuna-cmd.py b/tuna-cmd.py
index 9a3d3f32398b..b13b25b8a801 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -26,7 +26,7 @@ import fnmatch
import gettext
import locale
from functools import reduce
-import ethtool
+import tuna.new_eth as ethtool
import tuna.tuna_sched as tuna_sched
import procfs
from tuna import tuna, sysfs
diff --git a/tuna/gui/irqview.py b/tuna/gui/irqview.py
index 35fc3fd0b0ca..5143d6dc0df5 100755
--- a/tuna/gui/irqview.py
+++ b/tuna/gui/irqview.py
@@ -7,7 +7,7 @@ from gi.repository import Gtk
from gi.repository import GObject
import os
from functools import reduce
-import ethtool
+import tuna.new_eth as ethtool
import tuna.tuna_sched as tuna_sched
import gi
diff --git a/tuna/new_eth.py b/tuna/new_eth.py
new file mode 100755
index 000000000000..18c2b130da38
--- /dev/null
+++ b/tuna/new_eth.py
@@ -0,0 +1,37 @@
+# Copyright (C) 2022 John Kacur
+""" A few functions similar to ethtool """
+import os
+import socket
+
+def get_active_devices():
+ """ return a list of network devices """
+ ret = []
+
+ for device in socket.if_nameindex():
+ ret.append(device[1])
+
+ return ret
+
+def get_module(intf):
+ """ return the kernel module for the given network interface """
+ if intf == 'lo':
+ return ""
+ myp = f'/sys/class/net/{intf}/device/driver'
+ if os.path.exists(myp):
+ return os.path.basename(os.readlink(myp))
+ if os.path.exists(f'/sys/class/net/{intf}/bridge'):
+ return 'bridge'
+ if os.path.exists(f'/sys/class/net/{intf}'):
+ return 'tun'
+ return ""
+
+if __name__ == "__main__":
+ nics = get_active_devices()
+ print(f'nics = {nics}')
+
+ for intf in nics:
+ driver = get_module(intf)
+ if driver:
+ print(f'{intf}, {driver}')
+ else:
+ print(f'{intf}')
diff --git a/tuna/tuna.py b/tuna/tuna.py
index 30a5a570c9d4..43adb84079e4 100755
--- a/tuna/tuna.py
+++ b/tuna/tuna.py
@@ -9,7 +9,7 @@ import sys
import shlex
import fnmatch
import platform
-import ethtool
+import tuna.new_eth as ethtool
import procfs
from procfs import utilist
from tuna import help
--
2.37.3
1 year, 7 months
[PATCH] tuna: Add --sockets command line option
by Leah Leshchinsky
The getopt version of tuna implements the --sockets argument which is used
to specify a cpulist from the cpu sockets on a system. The --sockets
and --cpus arguments in the getopt version override each other, such
that 'tuna -S 0 -c 1,2' will cause a cpu_list of [1, 2].
In the argparse cli, add support for a --sockets argument used to specify a
cpulist and is mutually exclusive with the --cpus and --nohz_full arguments.
Signed-off-by: Leah Leshchinsky <lleshchi(a)redhat.com>
---
Apply to main branch
diff --git a/tuna-cmd.py b/tuna-cmd.py
index 554912057f03..9a3d3f32398b 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -112,7 +112,7 @@ def gen_parser():
"threads": dict(dest='thread_list', default=[], metavar='THREAD-LIST', type=threadstring_to_list, help="THREAD-LIST affected by commands"),
"irqs": dict(dest='irq_list', default=[], metavar='IRQ-LIST', type=irqstring_to_list, help="IRQ-LIST affect by commands"),
"cpus": dict(dest='cpu_list', default=[], metavar='CPU-LIST', type=tuna.cpustring_to_list, help='CPU-LIST affected by commands'),
- "sockets": dict(default=[], nargs='+', type=int, help="CPU-SOCKET-LIST affected by commands"),
+ "sockets": dict(dest='cpu_list', default=[], metavar='CPU-SOCKET-LIST', type=socketstring_to_list, help="CPU-SOCKET-LIST affected by commands"),
"show_sockets": dict(action='store_true', help='Show network sockets in use by threads'),
"cgroups": dict(action='store_true', dest='cgroups', help='Display the processes with the type of cgroups they are in'),
"affect_children": dict(action='store_true', help="Operation will affect children threads"),
@@ -159,20 +159,24 @@ def gen_parser():
isolate_group = isolate.add_mutually_exclusive_group(required=True)
isolate_group.add_argument('-c', '--cpus', **MODS['cpus'])
+ isolate_group.add_argument('-S', '--sockets', **MODS['sockets'])
isolate_group.add_argument('-N', '--nohz_full', **MODS['nohz_full'])
include_group = include.add_mutually_exclusive_group(required=True)
include_group.add_argument('-c', '--cpus', **MODS['cpus'])
+ include_group.add_argument('-S', '--sockets', **MODS['sockets'])
include_group.add_argument('-N', '--nohz_full', **MODS['nohz_full'])
move_group = move.add_mutually_exclusive_group(required=True)
move_group.add_argument('-c', '--cpus', **MODS['cpus'])
+ move_group.add_argument('-S', '--sockets', **MODS['sockets'])
move_group.add_argument('-N', '--nohz_full', **MODS['nohz_full'])
move.add_argument('-t', '--threads', **MODS['threads'])
move.add_argument('-q', '--irqs', **MODS['irqs'])
spread_group = spread.add_mutually_exclusive_group(required=True)
spread_group.add_argument('-c', '--cpus', **MODS['cpus'])
+ spread_group.add_argument('-S', '--sockets', **MODS['sockets'])
spread_group.add_argument('-N', '--nohz_full', **MODS['nohz_full'])
spread.add_argument('-t', '--threads', **MODS['threads'])
spread.add_argument('-q', '--irqs', **MODS['irqs'])
@@ -182,12 +186,18 @@ def gen_parser():
priority.add_argument('-C', '--affect_children', **MODS['affect_children'])
run.add_argument('run_command', **POS['run_command'])
- run.add_argument('-c', '--cpus', **MODS['cpus'])
+ run_group = run.add_mutually_exclusive_group(required=False)
+ run_group.add_argument('-c', '--cpus', **MODS['cpus'])
+ run_group.add_argument('-S', '--sockets', **MODS['sockets'])
+ run_group.add_argument('-N', '--nohz_full', **MODS['nohz_full'])
run.add_argument('-p', '--priority', **MODS['priority'])
run.add_argument('-b', '--background', **MODS['background'])
save.add_argument('filename', **POS['filename'])
- save.add_argument('-c', '--cpus', **MODS['cpus'])
+ save_group = save.add_mutually_exclusive_group(required=False)
+ save_group.add_argument('-c', '--cpus', **MODS['cpus'])
+ save_group.add_argument('-S', '--sockets', **MODS['sockets'])
+ save_group.add_argument('-N', '--nohz_full', **MODS['nohz_full'])
save.add_argument('-t', '--threads', **MODS['threads'])
apply.add_argument('profilename', **POS['profilename'])
@@ -195,6 +205,7 @@ def gen_parser():
show_threads_group1 = show_threads.add_mutually_exclusive_group(required=False)
show_threads_group1.add_argument('-c', '--cpus', **MODS['cpus'])
show_threads_group1.add_argument('-N', '--nohz_full', **MODS['nohz_full'])
+ show_threads_group1.add_argument('-S', '--sockets', **MODS['sockets'])
show_threads_group2 = show_threads.add_mutually_exclusive_group(required=False)
show_threads_group2.add_argument('-t', '--threads', **MODS['threads'])
show_threads_group2.add_argument('-q', '--irqs', **MODS['irqs'])
@@ -206,14 +217,21 @@ def gen_parser():
show_threads.add_argument('-n', '--show_sockets', **MODS['show_sockets'])
show_threads.add_argument('-G', '--cgroups', **MODS['cgroups'])
- show_irqs.add_argument('-c', '--cpus', **MODS['cpus'])
+
+ show_irqs_group = show_irqs.add_mutually_exclusive_group(required=False)
+ show_irqs_group.add_argument('-c', '--cpus', **MODS['cpus'])
+ show_irqs_group.add_argument('-N', '--nohz_full', **MODS['nohz_full'])
+ show_irqs_group.add_argument('-S', '--sockets', **MODS['sockets'])
show_irqs.add_argument('-q', '--irqs', **MODS['irqs'])
what_is.add_argument('thread_list', **POS['thread_list'])
gui.add_argument('-d', '--disable_perf', **MODS['disable_perf'])
gui.add_argument('-R', '--refresh', **MODS['refresh'])
- gui.add_argument('-c', '--cpus', **MODS['cpus'])
+ gui_group = gui.add_mutually_exclusive_group(required=False)
+ gui_group.add_argument('-c', '--cpus', **MODS['cpus'])
+ gui_group.add_argument('-N', '--nohz_full', **MODS['nohz_full'])
+ gui_group.add_argument('-S', '--sockets', **MODS['sockets'])
gui.add_argument('-U', '--no_uthreads', **MODS['no_uthreads'])
gui.add_argument('-K', '--no_kthreads', **MODS['no_kthreads'])
@@ -536,7 +554,6 @@ def irqstring_to_list(irqstr):
irq_list = []
irq_strings = list(set(irqstr.split(',')))
- print(irq_strings)
for s in irq_strings:
if s.isdigit():
irq_list.append(int(s))
@@ -546,6 +563,18 @@ def irqstring_to_list(irqstr):
irq_list += [int(i) for i in irq_list_str if i.isdigit()]
return irq_list
+def socketstring_to_list(socketstr):
+ cpu_list = []
+ socket_strings = list(set(socketstr.split(',')))
+ cpu_info = sysfs.cpus()
+
+ for s in socket_strings:
+ if s not in cpu_info.sockets:
+ print("tuna: invalid socket %(socket)s sockets available: %(available)s" %
+ {"socket": s,"available": ",".join(list(cpu_info.sockets.keys()))})
+ sys.exit(2)
+ cpu_list += [int(cpu.name[3:]) for cpu in cpu_info.sockets[s]]
+ return cpu_list
def pick_op(argument):
if argument == "":
--
2.31.1
1 year, 7 months