Discussion:
[PATCH 0/2] Fixes to isolate sockets with tuna and python3
John Kacur
2018-12-04 12:01:13 UTC
Permalink
Please integrate the following two patches.

A problem was uncovered trying to isolate a socket using "tuna -S0 -i"

The problem was caused because python3 doesn't automatically supply a
method to compare class instances.

In addition, on hardware where trying to do this evokes an exception,
there was an a problem because exceptions are not iterable in python3.
To fix this you simply use the Exception args attribute

Repo: git://git.kernel.org/pub/scm/linux/kernel/git/jkacur/tuna.git
Branch: devel/tuna-py3

John Kacur (2):
tuna: sysfs.py: Add method to compare class cpu
tuna: Use exception args attribute for python3

tuna-cmd.py | 4 ++--
tuna/gui/util.py | 4 ++--
tuna/sysfs.py | 3 +++
tuna/tuna.py | 46 +++++++++++++++++++++++-----------------------
4 files changed, 30 insertions(+), 27 deletions(-)

--
2.19.2
_______________________________________________
tuna-devel mailing list -- tuna-***@lists.fedorahosted.org
To unsubscribe send an email to tuna-devel-***@lists.fedorahosted.org
Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedorahosted.org/archives/list/tu
John Kacur
2018-12-04 12:01:14 UTC
Permalink
In python3 you have to supply a method to compare class instances

Without this you get this kind of error

$ python3 sysfs.py
Traceback (most recent call last):
File "sysfs.py", line 97, in <module>
cpus = cpus()
File "sysfs.py", line 57, in __init__
self.reload()
File "sysfs.py", line 92, in reload
self.sockets[socket].sort()
TypeError: '<' not supported between instances of 'cpu' and 'cpu'

Signed-off-by: John Kacur <***@redhat.com>
---
tuna/sysfs.py | 3 +++
1 file changed, 3 insertions(+)

diff --git a/tuna/sysfs.py b/tuna/sysfs.py
index acc81d667753..8b8a988659ce 100755
--- a/tuna/sysfs.py
+++ b/tuna/sysfs.py
@@ -9,6 +9,9 @@ class cpu:
self.dir = "%s/%s" % (basedir, name)
self.reload()

+ def __lt__(self, other):
+ self.name < other.name
+
def readfile(self, name):
try:
f = open("%s/%s" % (self.dir, name))
--
2.19.2
_______________________________________________
tuna-devel mailing list -- tuna-***@lists.fedorahosted.org
To unsubscribe send an email to tuna-devel-***@lists.fedorahosted.org
Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedorahosted.org/archives/list/tuna-***@lists.fedor
John Kacur
2018-12-04 12:01:15 UTC
Permalink
In python3 exceptions are not interable, so use the args attribute

Signed-off-by: John Kacur <***@redhat.com>
---
tuna-cmd.py | 4 ++--
tuna/gui/util.py | 4 ++--
tuna/tuna.py | 46 +++++++++++++++++++++++-----------------------
3 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/tuna-cmd.py b/tuna-cmd.py
index 8068695ae6df..e4182231d80f 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -182,7 +182,7 @@ def ps_show_thread(pid, affect_children, ps,
try:
affinity = format_affinity(schedutils.get_affinity(pid))
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
return
raise e

@@ -264,7 +264,7 @@ def ps_show(ps, affect_children, thread_list, cpu_list,
try:
affinity = schedutils.get_affinity(pid)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
raise e
if cpu_list and not set(cpu_list).intersection(set(affinity)):
diff --git a/tuna/gui/util.py b/tuna/gui/util.py
index 73eceae23ab7..9e30ed92bd4c 100755
--- a/tuna/gui/util.py
+++ b/tuna/gui/util.py
@@ -86,7 +86,7 @@ def thread_set_attributes(pid_info, new_policy, new_prio, new_affinity, nr_cpus)
try:
curr_affinity = schedutils.get_affinity(pid)
except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
- if e[0] == 3:
+ if e.args[0] == 3:
return False
raise e

@@ -109,7 +109,7 @@ def thread_set_attributes(pid_info, new_policy, new_prio, new_affinity, nr_cpus)
try:
curr_affinity = schedutils.get_affinity(pid)
except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
- if e[0] == 3:
+ if e.args[0] == 3:
return False
raise e

diff --git a/tuna/tuna.py b/tuna/tuna.py
index 9f9267863871..4b1a77bcfa9f 100755
--- a/tuna/tuna.py
+++ b/tuna/tuna.py
@@ -193,7 +193,7 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None,
try:
curr_affinity = schedutils.get_affinity(pid)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
curr_affinity = None
raise e
@@ -202,7 +202,7 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None,
schedutils.set_affinity(pid, new_affinity)
curr_affinity = schedutils.get_affinity(pid)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
curr_affinity == None
raise e
@@ -231,7 +231,7 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None,
try:
curr_affinity = schedutils.get_affinity(tid)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
raise e
if set(curr_affinity) != set(new_affinity):
@@ -239,7 +239,7 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None,
schedutils.set_affinity(tid, new_affinity)
curr_affinity = schedutils.get_affinity(tid)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
raise e
if set(curr_affinity) == set(new_affinity):
@@ -251,10 +251,10 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None,
(_("could not change %(pid)d affinity to %(new_affinity)s") % \
{'pid':pid, 'new_affinity':new_affinity}))
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
# process died
continue
- elif e[0] == errno.EINVAL: # unmovable thread)
+ elif e.args[0] == errno.EINVAL: # unmovable thread)
print("thread %(pid)d cannot be moved as requested" %{'pid':pid}, file=stderr)
continue
raise e
@@ -301,7 +301,7 @@ def move_irqs_to_cpu(cpus, irq_list, spread = False):
try:
schedutils.set_affinity(pid, new_affinity)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
unprocessed.append(i)
changed -= 1
continue
@@ -336,9 +336,9 @@ def isolate_cpus(cpus, nr_cpus):
try:
affinity = schedutils.get_affinity(pid)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
- elif e[0] == errno.EINVAL:
+ elif e.args[0] == errno.EINVAL:
print("Function:", fname, ",", e.strerror, file=sys.stderr)
sys.exit(2)
raise e
@@ -348,9 +348,9 @@ def isolate_cpus(cpus, nr_cpus):
try:
schedutils.set_affinity(pid, affinity)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
- elif e[0] == errno.EINVAL:
+ elif e.args[0] == errno.EINVAL:
print("Function:", fname, ",", e.strerror, file=sys.stderr)
sys.exit(2)
raise e
@@ -364,9 +364,9 @@ def isolate_cpus(cpus, nr_cpus):
try:
affinity = schedutils.get_affinity(tid)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
- elif e[0] == errno.EINVAL:
+ elif e.args[0] == errno.EINVAL:
print("Function:", fname, ",", e.strerror, file=sys.stderr)
sys.exit(2)
raise e
@@ -376,9 +376,9 @@ def isolate_cpus(cpus, nr_cpus):
try:
schedutils.set_affinity(tid, affinity)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
- elif e[0] == errno.EINVAL:
+ elif e.args[0] == errno.EINVAL:
print("Function:", fname, ",", e.strerror, file=sys.stderr)
sys.exit(2)
raise e
@@ -416,7 +416,7 @@ def include_cpus(cpus, nr_cpus):
try:
affinity = schedutils.get_affinity(pid)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
raise e
if set(affinity).intersection(set(cpus)) != set(cpus):
@@ -425,7 +425,7 @@ def include_cpus(cpus, nr_cpus):
try:
schedutils.set_affinity(pid, affinity)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
raise e

@@ -438,7 +438,7 @@ def include_cpus(cpus, nr_cpus):
try:
affinity = schedutils.get_affinity(tid)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
raise e
if set(affinity).intersection(set(cpus)) != set(cpus):
@@ -447,7 +447,7 @@ def include_cpus(cpus, nr_cpus):
try:
schedutils.set_affinity(tid, affinity)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
raise e

@@ -515,7 +515,7 @@ def thread_filtered(tid, cpus_filtered, show_kthreads, show_uthreads):
try:
affinity = schedutils.get_affinity(tid)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
return False
raise e

@@ -554,7 +554,7 @@ def threads_set_priority(tids, parm, affect_children = False):
try:
thread_set_priority(tid, policy, rtprio)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
raise e
if affect_children:
@@ -563,7 +563,7 @@ def threads_set_priority(tids, parm, affect_children = False):
try:
thread_set_priority(child, policy, rtprio)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
raise e

@@ -594,7 +594,7 @@ def get_kthread_sched_tunings(proc = None):
policy = schedutils.get_scheduler(pid)
affinity = schedutils.get_affinity(pid)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
raise e
percpu = iskthread(pid) and \
--
2.19.2
_______________________________________________
tuna-devel mailing list -- tuna-***@lists.fedorahosted.org
To unsubscribe send an email to tuna-devel-***@lists.fedorahosted.org
Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedorahosted.org/archives/list/tuna-***@lists.fedor
Loading...