|
|
29a993 |
From 876beba81c6b213e0fe4755409142cddb78e344d Mon Sep 17 00:00:00 2001
|
|
|
29a993 |
From: John Kacur <jkacur@redhat.com>
|
|
|
29a993 |
Date: Tue, 12 Sep 2017 23:35:39 +0100
|
|
|
29a993 |
Subject: [PATCH 1/2] tuna: Use errno codes instead of numbers
|
|
|
29a993 |
|
|
|
29a993 |
Use errno codes instead of numbers since they
|
|
|
29a993 |
are self documenting.
|
|
|
29a993 |
|
|
|
29a993 |
Simplify the comments as a result
|
|
|
29a993 |
|
|
|
29a993 |
Signed-off-by: John Kacur <jkacur@redhat.com>
|
|
|
29a993 |
---
|
|
|
29a993 |
tuna-cmd.py | 12 +++++-----
|
|
|
29a993 |
tuna/tuna.py | 78 ++++++++++++++++++++++++++++++------------------------------
|
|
|
29a993 |
2 files changed, 45 insertions(+), 45 deletions(-)
|
|
|
29a993 |
|
|
|
29a993 |
diff --git a/tuna-cmd.py b/tuna-cmd.py
|
|
|
29a993 |
index 39666c7c77f1..f0c5c0662ebd 100755
|
|
|
29a993 |
--- a/tuna-cmd.py
|
|
|
29a993 |
+++ b/tuna-cmd.py
|
|
|
29a993 |
@@ -14,7 +14,7 @@
|
|
|
29a993 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
29a993 |
# General Public License for more details.
|
|
|
29a993 |
|
|
|
29a993 |
-import getopt, ethtool, fnmatch, os, procfs, re, schedutils, sys
|
|
|
29a993 |
+import getopt, ethtool, fnmatch, errno, os, procfs, re, schedutils, sys
|
|
|
29a993 |
from tuna import tuna, sysfs
|
|
|
29a993 |
|
|
|
29a993 |
import gettext
|
|
|
29a993 |
@@ -180,8 +180,8 @@ def ps_show_thread(pid, affect_children, ps,
|
|
|
29a993 |
global irqs
|
|
|
29a993 |
try:
|
|
|
29a993 |
affinity = format_affinity(schedutils.get_affinity(pid))
|
|
|
29a993 |
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
- if e[0] == 3:
|
|
|
29a993 |
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
+ if e[0] == errno.ESRCH:
|
|
|
29a993 |
return
|
|
|
29a993 |
raise e
|
|
|
29a993 |
|
|
|
29a993 |
@@ -262,8 +262,8 @@ def ps_show(ps, affect_children, thread_list, cpu_list,
|
|
|
29a993 |
continue
|
|
|
29a993 |
try:
|
|
|
29a993 |
affinity = schedutils.get_affinity(pid)
|
|
|
29a993 |
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
- if e[0] == 3:
|
|
|
29a993 |
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
+ if e[0] == errno.ESRCH:
|
|
|
29a993 |
continue
|
|
|
29a993 |
raise e
|
|
|
29a993 |
if cpu_list and not set(cpu_list).intersection(set(affinity)):
|
|
|
29a993 |
@@ -558,7 +558,7 @@ def main():
|
|
|
29a993 |
else:
|
|
|
29a993 |
try:
|
|
|
29a993 |
tuna.threads_set_priority(thread_list, a, affect_children)
|
|
|
29a993 |
- except (SystemError, OSError) as err: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
+ except (SystemError, OSError) as err: # old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
print "tuna: %s" % err
|
|
|
29a993 |
sys.exit(2)
|
|
|
29a993 |
elif o in ("-P", "--show_threads"):
|
|
|
29a993 |
diff --git a/tuna/tuna.py b/tuna/tuna.py
|
|
|
29a993 |
index 9aab16a409d2..562c7fcf92d9 100755
|
|
|
29a993 |
--- a/tuna/tuna.py
|
|
|
29a993 |
+++ b/tuna/tuna.py
|
|
|
29a993 |
@@ -1,7 +1,7 @@
|
|
|
29a993 |
# -*- python -*-
|
|
|
29a993 |
# -*- coding: utf-8 -*-
|
|
|
29a993 |
|
|
|
29a993 |
-import copy, ethtool, os, procfs, re, schedutils, sys, shlex
|
|
|
29a993 |
+import copy, ethtool, errno, os, procfs, re, schedutils, sys, shlex
|
|
|
29a993 |
import help, fnmatch
|
|
|
29a993 |
from procfs import utilist
|
|
|
29a993 |
|
|
|
29a993 |
@@ -209,8 +209,8 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None,
|
|
|
29a993 |
try:
|
|
|
29a993 |
try:
|
|
|
29a993 |
curr_affinity = schedutils.get_affinity(pid)
|
|
|
29a993 |
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
- if e[0] == 3: # 'No such process'
|
|
|
29a993 |
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
+ if e[0] == errno.ESRCH:
|
|
|
29a993 |
continue
|
|
|
29a993 |
curr_affinity = None
|
|
|
29a993 |
raise e
|
|
|
29a993 |
@@ -218,8 +218,8 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None,
|
|
|
29a993 |
try:
|
|
|
29a993 |
schedutils.set_affinity(pid, new_affinity)
|
|
|
29a993 |
curr_affinity = schedutils.get_affinity(pid)
|
|
|
29a993 |
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
- if e[0] == 3: # 'No such process'
|
|
|
29a993 |
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
+ if e[0] == errno.ESRCH:
|
|
|
29a993 |
continue
|
|
|
29a993 |
curr_affinity == None
|
|
|
29a993 |
raise e
|
|
|
29a993 |
@@ -247,16 +247,16 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None,
|
|
|
29a993 |
for tid in threads.keys():
|
|
|
29a993 |
try:
|
|
|
29a993 |
curr_affinity = schedutils.get_affinity(tid)
|
|
|
29a993 |
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
- if e[0] == 3:
|
|
|
29a993 |
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
+ if e[0] == errno.ESRCH:
|
|
|
29a993 |
continue
|
|
|
29a993 |
raise e
|
|
|
29a993 |
if set(curr_affinity) != set(new_affinity):
|
|
|
29a993 |
try:
|
|
|
29a993 |
schedutils.set_affinity(tid, new_affinity)
|
|
|
29a993 |
curr_affinity = schedutils.get_affinity(tid)
|
|
|
29a993 |
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
- if e[0] == 3:
|
|
|
29a993 |
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
+ if e[0] == errno.ESRCH:
|
|
|
29a993 |
continue
|
|
|
29a993 |
raise e
|
|
|
29a993 |
if set(curr_affinity) == set(new_affinity):
|
|
|
29a993 |
@@ -267,12 +267,12 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None,
|
|
|
29a993 |
print "move_threads_to_cpu: %s " % \
|
|
|
29a993 |
(_("could not change %(pid)d affinity to %(new_affinity)s") % \
|
|
|
29a993 |
{'pid':pid, 'new_affinity':new_affinity})
|
|
|
29a993 |
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
- if e[0] == 3:
|
|
|
29a993 |
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
+ if e[0] == errno.ESRCH:
|
|
|
29a993 |
# process died
|
|
|
29a993 |
continue
|
|
|
29a993 |
- elif e[0] == 22: # (22, EINVAL - unmovable thread)
|
|
|
29a993 |
- print "thread %(pid)d cannot be moved as requested" %{'pid':pid}
|
|
|
29a993 |
+ elif e[0] == errno.EINVAL: # unmovable thread)
|
|
|
29a993 |
+ print >> stderr, "thread %(pid)d cannot be moved as requested" %{'pid':pid}
|
|
|
29a993 |
continue
|
|
|
29a993 |
raise e
|
|
|
29a993 |
return changed
|
|
|
29a993 |
@@ -317,8 +317,8 @@ def move_irqs_to_cpu(cpus, irq_list, spread = False):
|
|
|
29a993 |
pid = int(pid[0])
|
|
|
29a993 |
try:
|
|
|
29a993 |
schedutils.set_affinity(pid, new_affinity)
|
|
|
29a993 |
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
- if e[0] == 3:
|
|
|
29a993 |
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
+ if e[0] == errno.ESRCH:
|
|
|
29a993 |
unprocessed.append(i)
|
|
|
29a993 |
changed -= 1
|
|
|
29a993 |
continue
|
|
|
29a993 |
@@ -351,8 +351,8 @@ def isolate_cpus(cpus, nr_cpus):
|
|
|
29a993 |
continue
|
|
|
29a993 |
try:
|
|
|
29a993 |
affinity = schedutils.get_affinity(pid)
|
|
|
29a993 |
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
- if e[0] == 3:
|
|
|
29a993 |
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
+ if e[0] == errno.ESRCH:
|
|
|
29a993 |
continue
|
|
|
29a993 |
raise e
|
|
|
29a993 |
if set(affinity).intersection(set(cpus)):
|
|
|
29a993 |
@@ -360,8 +360,8 @@ def isolate_cpus(cpus, nr_cpus):
|
|
|
29a993 |
affinity = affinity_remove_cpus(affinity, cpus, nr_cpus)
|
|
|
29a993 |
try:
|
|
|
29a993 |
schedutils.set_affinity(pid, affinity)
|
|
|
29a993 |
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
- if e[0] == 3:
|
|
|
29a993 |
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
+ if e[0] == errno.ESRCH:
|
|
|
29a993 |
continue
|
|
|
29a993 |
raise e
|
|
|
29a993 |
|
|
|
29a993 |
@@ -373,8 +373,8 @@ def isolate_cpus(cpus, nr_cpus):
|
|
|
29a993 |
continue
|
|
|
29a993 |
try:
|
|
|
29a993 |
affinity = schedutils.get_affinity(tid)
|
|
|
29a993 |
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
- if e[0] == 3:
|
|
|
29a993 |
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
+ if e[0] == errno.ESRCH:
|
|
|
29a993 |
continue
|
|
|
29a993 |
raise e
|
|
|
29a993 |
if set(affinity).intersection(set(cpus)):
|
|
|
29a993 |
@@ -382,8 +382,8 @@ def isolate_cpus(cpus, nr_cpus):
|
|
|
29a993 |
affinity = affinity_remove_cpus(affinity, cpus, nr_cpus)
|
|
|
29a993 |
try:
|
|
|
29a993 |
schedutils.set_affinity(tid, affinity)
|
|
|
29a993 |
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
- if e[0] == 3:
|
|
|
29a993 |
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
+ if e[0] == errno.ESRCH:
|
|
|
29a993 |
continue
|
|
|
29a993 |
raise e
|
|
|
29a993 |
|
|
|
29a993 |
@@ -419,8 +419,8 @@ def include_cpus(cpus, nr_cpus):
|
|
|
29a993 |
continue
|
|
|
29a993 |
try:
|
|
|
29a993 |
affinity = schedutils.get_affinity(pid)
|
|
|
29a993 |
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
- if e[0] == 3:
|
|
|
29a993 |
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
+ if e[0] == errno.ESRCH:
|
|
|
29a993 |
continue
|
|
|
29a993 |
raise e
|
|
|
29a993 |
if set(affinity).intersection(set(cpus)) != set(cpus):
|
|
|
29a993 |
@@ -428,8 +428,8 @@ def include_cpus(cpus, nr_cpus):
|
|
|
29a993 |
affinity = list(set(affinity + cpus))
|
|
|
29a993 |
try:
|
|
|
29a993 |
schedutils.set_affinity(pid, affinity)
|
|
|
29a993 |
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
- if e[0] == 3:
|
|
|
29a993 |
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
+ if e[0] == errno.ESRCH:
|
|
|
29a993 |
continue
|
|
|
29a993 |
raise e
|
|
|
29a993 |
|
|
|
29a993 |
@@ -441,8 +441,8 @@ def include_cpus(cpus, nr_cpus):
|
|
|
29a993 |
continue
|
|
|
29a993 |
try:
|
|
|
29a993 |
affinity = schedutils.get_affinity(tid)
|
|
|
29a993 |
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
- if e[0] == 3:
|
|
|
29a993 |
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
+ if e[0] == errno.ESRCH:
|
|
|
29a993 |
continue
|
|
|
29a993 |
raise e
|
|
|
29a993 |
if set(affinity).intersection(set(cpus)) != set(cpus):
|
|
|
29a993 |
@@ -450,8 +450,8 @@ def include_cpus(cpus, nr_cpus):
|
|
|
29a993 |
affinity = list(set(affinity + cpus))
|
|
|
29a993 |
try:
|
|
|
29a993 |
schedutils.set_affinity(tid, affinity)
|
|
|
29a993 |
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
- if e[0] == 3:
|
|
|
29a993 |
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
+ if e[0] == errno.ESRCH:
|
|
|
29a993 |
continue
|
|
|
29a993 |
raise e
|
|
|
29a993 |
|
|
|
29a993 |
@@ -518,8 +518,8 @@ def thread_filtered(tid, cpus_filtered, show_kthreads, show_uthreads):
|
|
|
29a993 |
if cpus_filtered:
|
|
|
29a993 |
try:
|
|
|
29a993 |
affinity = schedutils.get_affinity(tid)
|
|
|
29a993 |
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
- if e[0] == 3:
|
|
|
29a993 |
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
+ if e[0] == errno.ESRCH:
|
|
|
29a993 |
return False
|
|
|
29a993 |
raise e
|
|
|
29a993 |
|
|
|
29a993 |
@@ -557,8 +557,8 @@ def threads_set_priority(tids, parm, affect_children = False):
|
|
|
29a993 |
for tid in tids:
|
|
|
29a993 |
try:
|
|
|
29a993 |
thread_set_priority(tid, policy, rtprio)
|
|
|
29a993 |
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
- if e[0] == 3:
|
|
|
29a993 |
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
+ if e[0] == errno.ESRCH:
|
|
|
29a993 |
continue
|
|
|
29a993 |
raise e
|
|
|
29a993 |
if affect_children:
|
|
|
29a993 |
@@ -566,8 +566,8 @@ def threads_set_priority(tids, parm, affect_children = False):
|
|
|
29a993 |
if child != tid:
|
|
|
29a993 |
try:
|
|
|
29a993 |
thread_set_priority(child, policy, rtprio)
|
|
|
29a993 |
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
- if e[0] == 3:
|
|
|
29a993 |
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
+ if e[0] == errno.ESRCH:
|
|
|
29a993 |
continue
|
|
|
29a993 |
raise e
|
|
|
29a993 |
|
|
|
29a993 |
@@ -597,8 +597,8 @@ def get_kthread_sched_tunings(proc = None):
|
|
|
29a993 |
try:
|
|
|
29a993 |
policy = schedutils.get_scheduler(pid)
|
|
|
29a993 |
affinity = schedutils.get_affinity(pid)
|
|
|
29a993 |
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
- if e[0] == 3:
|
|
|
29a993 |
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
|
|
|
29a993 |
+ if e[0] == errno.ESRCH:
|
|
|
29a993 |
continue
|
|
|
29a993 |
raise e
|
|
|
29a993 |
percpu = iskthread(pid) and \
|
|
|
29a993 |
--
|
|
|
29a993 |
2.9.5
|
|
|
29a993 |
|