[PATCH 1/2] tuna: Print warning if setting affinity results in EBUSY and continue
by John Kacur
When trying to isolate a CPU, if a device uses SCHED_DEADLINE and admission
control is enabled, setting the affinity will result in the error EBUSY.
tuna should print a warning that this pid could not be moved, and
continue.
The user can either ignore the warning or use other measures to isolate
the cpu such as booting with isolcpus or turning off admission control
and rerunning the tuna isolate command and then turning admission
control back on.
Signed-off-by: John Kacur <jkacur(a)redhat.com>
---
tuna/tuna.py | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tuna/tuna.py b/tuna/tuna.py
index 591206d9b4e1..f25eb3d10923 100755
--- a/tuna/tuna.py
+++ b/tuna/tuna.py
@@ -360,6 +360,10 @@ def isolate_cpus(cpus, nr_cpus):
if err.args[0] == errno.EINVAL:
print("Function:", fname, ",", err.strerror, file=sys.stderr)
sys.exit(2)
+ if err.args[0] == errno.EBUSY:
+ comm = ps[pid].stat["comm"]
+ print(f'Warning: Unable to isolate pid {pid} [{comm}]')
+ continue
raise err
if "threads" not in ps[pid]:
--
2.31.1
2 years, 1 month
[PATCH] tuna: Improve sysfs.py
by John Kacur
Improve sysfs.py
- Add docstring comments to classes and functions
- Make the code more readable by using os.path.join on file components
- Initialize class variables in the __init__ when possible
- Use "with" for opening files where possible
- and __repr__ to classes for debugging purposes
- Specify the type of exception where possible (replace bare exceptions)
- Replace old style has_key with __contains__
Signed-off-by: John Kacur <jkacur(a)redhat.com>
---
tuna/sysfs.py | 48 +++++++++++++++++++++++++++++++++++++-----------
1 file changed, 37 insertions(+), 11 deletions(-)
diff --git a/tuna/sysfs.py b/tuna/sysfs.py
index bce96af2f7b5..1c903e106a44 100755
--- a/tuna/sysfs.py
+++ b/tuna/sysfs.py
@@ -1,38 +1,54 @@
# -*- python -*-
# -*- coding: utf-8 -*-
+"""
+classes for /sys/devices/system/cpu/
+so we can get topology information and do CPU hotplug operations
+"""
import os
+
class cpu:
+ """
+ class to query if a cpu is online or not
+ and to bring a cpu online or to take it offline
+ """
+
def __init__(self, basedir, name):
self.name = name
- self.dir = "%s/%s" % (basedir, name)
+ self.dir = os.path.join(basedir, name)
+ self.online = None
self.reload()
def __lt__(self, other):
# Previously it is assumed that name[:3] == "cpu" and name[3].isdigit(), so:
- int(self.name[3:]) < int(other.name[3:])
+ return int(self.name[3:]) < int(other.name[3:])
def readfile(self, name):
+ """ read file "name", typically the per cpu "online" file """
try:
- f = open("%s/%s" % (self.dir, name))
- value = f.readline().strip()
- f.close()
+ with open(os.path.join(self.dir, name)) as f:
+ value = f.readline().strip()
+ return value
except:
raise
- return value
+
+ def __repr__(self):
+ return f'name={self.name}, online={self.online}, physical_package_id={self.physical_package_id}'
def reload_online(self):
+ """ read the "online" file """
self.online = True
try:
self.online = self.readfile("online") == "1"
- except:
+ except FileNotFoundError:
# boot CPU, usually cpu0, can't be brought offline, so
# lacks the file and non root users can't read. In both
# cases assume CPU is online.
pass
def reload(self):
+ """ Load or reload the values of this class """
self.reload_online()
if self.online:
try:
@@ -43,17 +59,20 @@ class cpu:
self.physical_package_id = None
def set_online(self, online=True):
+ """ Turn a cpu on or off using the online file """
try:
- f = open("%s/online" % self.dir, "w")
- f.write("%d\n" % (online and 1 or 0))
- f.close()
+ with open(os.path.join(self.dir, "online"), "w") as f:
+ f.write("1" if online else "0")
except:
pass
self.reload_online()
return online == self.online
+
class cpus:
+ """ a class that creates a dictionary of cpu information keyed by cpu """
+
def __init__(self, basedir="/sys/devices/system/cpu"):
self.basedir = basedir
self.cpus = {}
@@ -65,12 +84,17 @@ class cpus:
return self.cpus[key]
def keys(self):
+ """ Returns a list of keys, for example a key could be cpu9 """
return list(self.cpus.keys())
- def has_key(self, key):
+ def __contains__(self, key):
return key in self.cpus
+ def __repr__(self):
+ return f'cpus={self.cpus}, sockets={self.sockets}, nr_cpus={self.nr_cpus}'
+
def reload(self):
+ """ load or reload the values of this class """
sockets_to_sort = []
for name in os.listdir(self.basedir):
if name[:3] != "cpu" or not name[3].isdigit():
@@ -96,9 +120,11 @@ class cpus:
for socket in sockets_to_sort:
self.sockets[socket].sort(key=lambda x: int(x.name[3:]))
+
if __name__ == '__main__':
cpus = cpus()
+ print(f'{cpus}')
for socket in list(cpus.sockets.keys()):
print("Socket %s" % socket)
--
2.31.1
2 years, 1 month
[PATCH] tuna: A few simple spelling / grammar fixes in comments
by John Kacur
A few simple spelling / grammer fixes in comments
Signed-off-by: John Kacur <jkacur(a)redhat.com>
---
tuna/tuna.py | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/tuna/tuna.py b/tuna/tuna.py
index 0cd8c3f9bf77..591206d9b4e1 100755
--- a/tuna/tuna.py
+++ b/tuna/tuna.py
@@ -67,8 +67,7 @@ def iskthread(pid):
f.close()
if line:
return False
- # Zombies also doesn't have smaps entries, so check the
- # state:
+ # Zombies also don't have smaps entries, so check the state:
try:
p = procfs.pidstat(pid)
except:
@@ -318,7 +317,7 @@ def affinity_remove_cpus(affinity, cpus, nr_cpus):
return affinity
-# Shound be moved to python_linux_procfs.interrupts, shared with interrupts.parse_affinity, etc.
+# Should be moved to python_linux_procfs.interrupts, shared with interrupts.parse_affinity, etc.
def parse_irq_affinity_filename(filename, nr_cpus):
try:
f = open("/proc/irq/%s" % filename)
--
2.31.1
2 years, 1 month
[PATCH 1/4] tuna: Replace unnecessary comprehension
by John Kacur
Simplify by replacing unnecessary list comprehension
with a simple list
Signed-off-by: John Kacur <jkacur(a)redhat.com>
---
tuna-cmd.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tuna-cmd.py b/tuna-cmd.py
index 8dfad9e4ab94..122d09a0de2a 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -650,7 +650,7 @@ def main():
save(cpu_list, thread_list, a)
elif o in ("-S", "--sockets"):
(op, a) = pick_op(a)
- sockets = [socket for socket in a.split(",")]
+ sockets = list(a.split(','))
if not cpu_list:
cpu_list = []
--
2.31.1
2 years, 1 month
[PATCH] tuna: Add distinction between --spread and --move to error message
by Leah Leshchinsky
Currently, the command `tuna --cpus=CPU-LIST --spread` generates an
error with the warning "tuna: --move requires a list of threads/irqs!".
Similarly, when the command `tuna --threads=THREAD-LIST --spread` is
run, it generates the warning "tuna: --move requires a cpu list!".
This can be confusing to the user, especially with commands that use both
the "--spread" and "--move" flags. The warning should specify "--spread"
when that is the source of the error.
Check whether the argument is a move or spread and update the warning
string accordingly.
Signed-off-by: Leah Leshchinsky <lleshchi(a)redhat.com>
---
tuna-cmd.py | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/tuna-cmd.py b/tuna-cmd.py
index 8617966..8dfad9e 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -633,15 +633,14 @@ def main():
elif o in ("-n", "--show_sockets"):
show_sockets = True
elif o in ("-m", "--move", "-x", "--spread"):
+ spread = o in ("-x", "--spread")
if not cpu_list:
- print("tuna: --move " + _("requires a cpu list!"))
+ print("tuna: %s " % ("--spread" if spread else "--move") + _("requires a cpu list!"))
sys.exit(2)
if not (thread_list or irq_list):
- print("tuna: --move " + _("requires a list of threads/irqs!"))
+ print("tuna: %s " % ("--spread" if spread else "--move") + _("requires a list of threads/irqs!"))
sys.exit(2)
- spread = o in ("-x", "--spread")
-
if thread_list:
tuna.move_threads_to_cpu(cpu_list, thread_list, spread=spread)
--
2.27.0
2 years, 1 month
[PATCH] tuna: Change tuna.spec to define version of python
by John Kacur
Although the old tuna.spec file is only being used to retrieve the
VERSION from the makefile, it is causing errors by not explicitly
defining the version of python it uses.
For example, if you type, 'make tags', you get
error: attempt to use unversioned python, define %__python to /usr/bin/python2 or /usr/bin/python3 explicitly
error: query of specfile rpm/SPECS/tuna.spec failed, can't parse
Fix this by explicitly defining the version of python in the spec file.
Signed-off-by: John Kacur <jkacur(a)redhat.com>
---
rpm/SPECS/tuna.spec | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/rpm/SPECS/tuna.spec b/rpm/SPECS/tuna.spec
index 2ab5511081d5..eca96c833265 100644
--- a/rpm/SPECS/tuna.spec
+++ b/rpm/SPECS/tuna.spec
@@ -1,6 +1,3 @@
-%{!?python_sitelib: %define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
-%{!?python_ver: %define python_ver %(%{__python} -c "import sys ; print(sys.version[:3])")}
-
Name: tuna
Version: 0.15
Release: 1%{?dist}
@@ -46,11 +43,11 @@ priority is changed, be it using tuna or plain chrt & taskset.
%setup -q
%build
-%{__python} setup.py build
+%{python3} setup.py build
%install
rm -rf %{buildroot}
-%{__python} setup.py install --skip-build --root %{buildroot}
+%{python3} setup.py install --skip-build --root %{buildroot}
mkdir -p %{buildroot}/%{_sysconfdir}/tuna/
mkdir -p %{buildroot}/{%{_bindir},%{_datadir}/tuna/help/kthreads,%{_mandir}/man8}
mkdir -p %{buildroot}/%{_datadir}/polkit-1/actions/
@@ -80,11 +77,11 @@ rm -rf %{buildroot}
%defattr(-,root,root,-)
%doc ChangeLog
%if "%{python_ver}" >= "2.5"
-%{python_sitelib}/*.egg-info
+%{python2_sitelib}/*.egg-info
%endif
%{_bindir}/tuna
%{_datadir}/tuna/
-%{python_sitelib}/tuna/
+%{python3_sitelib}/tuna/
%{_mandir}/man8/tuna.8*
%{_sysconfdir}/tuna.conf
%{_sysconfdir}/tuna/*
--
2.31.1
2 years, 1 month
[PATCH] tuna: Specify Gtk version before import to prevent warning
by John Kacur
When running tuna --config_file_list
there is a warning about Gtk being imported without specifying a version
first.
Fix this using gi.require.version before the import like in tuna/tuna_gui.py
Signed-off-by: John Kacur <jkacur(a)redhat.com>
---
tuna/config.py | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tuna/config.py b/tuna/config.py
index 5d6848c5f314..09d26dd87029 100644
--- a/tuna/config.py
+++ b/tuna/config.py
@@ -7,7 +7,10 @@ import codecs
import configparser
from time import localtime, strftime
from subprocess import Popen, PIPE, STDOUT, call
+import gi
+gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
+
TUNED_CONF = """[sysctl]\n"""
--
2.31.1
2 years, 1 month