summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Kacur <jkacur@redhat.com>2021-01-15 15:56:36 -0500
committerJohn Kacur <jkacur@redhat.com>2021-01-18 22:39:29 -0500
commitcc2af6e1c990bdc690d4bc6c30d588fd3bb5a5a5 (patch)
tree7fbb8a610c4342a091e1f2a94f7441293f07494f
parente2bfea6172d48a4ec7d40eaa7dd3ad7ab5e42de1 (diff)
downloadtuna-cc2af6e1c990bdc690d4bc6c30d588fd3bb5a5a5.tar.gz
tuna: Remove python-schedutils dependency
python-schedutils isn't necessary anymore as python-3.3 and up has built in support for scheduling functions - Also remove check for SystemError that old python-schedutils incorrectly raised, this was fixed long ago. - A functions to go from a str to a policy number and from a policy number to a str. These were in python-schedutils but not in python3 - Fix a few remaining spots where the code tested for 3 instead of errno.ERSCH Signed-off-by: John Kacur <jkacur@redhat.com>
-rwxr-xr-xtuna-cmd.py15
-rwxr-xr-xtuna/gui/cpuview.py4
-rwxr-xr-xtuna/gui/irqview.py10
-rwxr-xr-xtuna/gui/procview.py14
-rw-r--r--tuna/gui/util.py35
-rwxr-xr-xtuna/tuna.py103
-rw-r--r--tuna/tuna_sched.py29
7 files changed, 109 insertions, 101 deletions
diff --git a/tuna-cmd.py b/tuna-cmd.py
index 0388ecb..d3446d7 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -26,7 +26,7 @@ import gettext
import locale
from functools import reduce
import ethtool
-import schedutils
+import tuna.tuna_sched as tuna_sched
import procfs
from tuna import tuna, sysfs
@@ -203,13 +203,13 @@ def ps_show_thread(pid, affect_children, ps, has_ctxt_switch_info, sock_inodes,
sock_inode_re, cgroups):
global irqs
try:
- affinity = format_affinity(schedutils.get_affinity(pid))
- except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
+ affinity = format_affinity(os.sched_getaffinity(pid))
+ except OSError as e:
if e.args[0] == errno.ESRCH:
return
raise e
- sched = schedutils.schedstr(schedutils.get_scheduler(pid))[6:]
+ sched = tuna_sched.sched_str(os.sched_getscheduler(pid))[6:]
rtprio = int(ps[pid]["stat"]["rt_priority"])
cgout = ps[pid]["cgroups"]
cmd = ps[pid]["stat"]["comm"]
@@ -288,8 +288,8 @@ def ps_show(ps, affect_children, thread_list, cpu_list,
if not in_irq_list and thread_list and pid not in thread_list:
continue
try:
- affinity = schedutils.get_affinity(pid)
- except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
+ affinity = os.sched_getaffinity(pid)
+ except OSError as e:
if e.args[0] == errno.ESRCH:
continue
raise e
@@ -597,8 +597,7 @@ def main():
else:
try:
tuna.threads_set_priority(thread_list, a, affect_children)
- # old python-schedutils incorrectly raised SystemError
- except (SystemError, OSError) as err:
+ except OSError as err:
print("tuna: %s" % err)
sys.exit(2)
elif o in ("-P", "--show_threads"):
diff --git a/tuna/gui/cpuview.py b/tuna/gui/cpuview.py
index 4915ce4..ec19149 100755
--- a/tuna/gui/cpuview.py
+++ b/tuna/gui/cpuview.py
@@ -9,7 +9,7 @@ gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GObject
-import schedutils
+import tuna.tuna_sched as tuna_sched
import procfs
from tuna import sysfs, tuna, gui
@@ -337,7 +337,7 @@ class cpuview:
affinities = self.previous_pid_affinities
for pid in list(affinities.keys()):
try:
- schedutils.set_affinity(pid, affinities[pid])
+ os.sched_setaffinity(pid, affinities[pid])
except:
pass
diff --git a/tuna/gui/irqview.py b/tuna/gui/irqview.py
index 012bd9f..ea5c2f5 100755
--- a/tuna/gui/irqview.py
+++ b/tuna/gui/irqview.py
@@ -8,7 +8,7 @@ from gi.repository import GObject
import os
from functools import reduce
import ethtool
-import schedutils
+import tuna.tuna_sched as tuna_sched
import gi
gi.require_version("Gtk", "3.0")
@@ -46,7 +46,7 @@ class irq_druid:
pid = pids[0]
prio = int(ps[pid]["stat"]["rt_priority"])
self.create_policy_model(self.sched_policy)
- self.sched_policy.set_active(schedutils.get_scheduler(pid))
+ self.sched_policy.set_active(os.sched_getscheduler(pid))
self.sched_pri.set_value(prio)
text.set_markup(
"IRQ <b>%u</b> (PID <b>%u</b>), pri <b>%u</b>, aff <b>%s</b>, <tt><b>%s</b></tt>" %
@@ -68,13 +68,13 @@ class irq_druid:
policy.add_attribute(renderer, "text", COL_TEXT)
for pol in range(4):
row = list_store.append()
- list_store.set(row, COL_TEXT, schedutils.schedstr(pol),
+ list_store.set(row, COL_TEXT, tuna_sched.sched_str(pol),
COL_SCHED, pol)
policy.set_model(list_store)
def on_sched_policy_combo_changed(self, button):
new_policy = self.sched_policy.get_active()
- if new_policy in (schedutils.SCHED_FIFO, schedutils.SCHED_RR):
+ if new_policy in (os.SCHED_FIFO, os.SCHED_RR):
can_change_pri = True
else:
can_change_pri = False
@@ -201,7 +201,7 @@ class irqview:
if pids:
pid = pids[0]
prio = int(self.ps[pid]["stat"]["rt_priority"])
- sched = schedutils.schedstr(schedutils.get_scheduler(pid))[6:]
+ sched = tuna_sched.sched_str(os.sched_getscheduler(pid))[6:]
else:
sched = ""
pid = -1
diff --git a/tuna/gui/procview.py b/tuna/gui/procview.py
index 435ce11..f897fdd 100755
--- a/tuna/gui/procview.py
+++ b/tuna/gui/procview.py
@@ -1,5 +1,5 @@
import re
-import schedutils
+import tuna.tuna_sched as tuna_sched
import gi
gi.require_version("Gtk", "3.0")
@@ -54,11 +54,11 @@ class process_druid:
self.sched_pri.set_value(int(pid_info["stat"]["rt_priority"]))
cmdline_regex = procfs.process_cmdline(pid_info)
- self.affinity_text = tuna.list_to_cpustring(schedutils.get_affinity(pid))
+ self.affinity_text = tuna.list_to_cpustring(os.sched_getaffinity(pid))
self.affinity.set_text(self.affinity_text)
self.create_matching_process_model(processes)
self.create_policy_model(self.sched_policy)
- self.sched_policy.set_active(schedutils.get_scheduler(pid))
+ self.sched_policy.set_active(os.sched_getscheduler(pid))
self.regex_edit.set_text(cmdline_regex)
self.just_this_thread.set_active(True)
self.regex_edit.set_sensitive(False)
@@ -98,7 +98,7 @@ class process_druid:
policy.add_attribute(renderer, "text", COL_TEXT)
for pol in range(4):
row = list_store.append()
- list_store.set(row, COL_TEXT, schedutils.schedstr(pol),
+ list_store.set(row, COL_TEXT, tuna_sched.sched_str(pol),
COL_SCHED, pol)
policy.set_model(list_store)
@@ -141,7 +141,7 @@ class process_druid:
def on_sched_policy_combo_changed(self, button):
new_policy = self.sched_policy.get_active()
- if new_policy in (schedutils.SCHED_FIFO, schedutils.SCHED_RR):
+ if new_policy in (os.SCHED_FIFO, os.SCHED_RR):
can_change_pri = True
else:
can_change_pri = False
@@ -396,8 +396,8 @@ class procview:
new_value = [None] * self.nr_columns
new_value[self.COL_PRI] = int(thread_info["stat"]["rt_priority"])
- new_value[self.COL_POL] = schedutils.schedstr(schedutils.get_scheduler(tid))[6:]
- thread_affinity_list = schedutils.get_affinity(tid)
+ new_value[self.COL_POL] = tuna_sched.sched_str(os.sched_getscheduler(tid))[6:]
+ thread_affinity_list = os.sched_getaffinity(tid)
new_value[self.COL_PID] = tid
new_value[self.COL_AFF] = tuna.list_to_cpustring(thread_affinity_list)
diff --git a/tuna/gui/util.py b/tuna/gui/util.py
index 3b5ff42..3c3ff4a 100644
--- a/tuna/gui/util.py
+++ b/tuna/gui/util.py
@@ -1,10 +1,10 @@
+import errno
import gi
gi.require_version("Gtk", "3.0")
-
from gi.repository import GObject
from gi.repository import Gtk
from gi.repository import Pango
-import schedutils
+import tuna.tuna_sched as tuna_sched
import procfs
from tuna import tuna
@@ -62,13 +62,14 @@ def invalid_affinity():
def thread_set_attributes(pid_info, new_policy, new_prio, new_affinity, nr_cpus):
pid = pid_info.pid
changed = False
- curr_policy = schedutils.get_scheduler(pid)
+ curr_policy = os.sched_getscheduler(pid)
curr_prio = int(pid_info["stat"]["rt_priority"])
- if new_policy == schedutils.SCHED_OTHER:
+ if new_policy == os.SCHED_OTHER:
new_prio = 0
if curr_policy != new_policy or curr_prio != new_prio:
+ param = os.sched_param(new_prio)
try:
- schedutils.set_scheduler(pid, new_policy, new_prio)
+ os.sched_setscheduler(pid, new_policy, param)
except:
dialog = Gtk.MessageDialog(None, \
Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, \
@@ -79,22 +80,20 @@ def thread_set_attributes(pid_info, new_policy, new_prio, new_affinity, nr_cpus)
dialog.destroy()
return False
- curr_policy = schedutils.get_scheduler(pid)
+ curr_policy = os.sched_getscheduler(pid)
if curr_policy != new_policy:
print(_("couldn't change pid %(pid)d from %(cpol)s(%(cpri)d) to %(npol)s(%(npri)d)!") % \
- {'pid': pid, 'cpol': schedutils.schedstr(curr_policy),
+ {'pid': pid, 'cpol': tuna_sched.sched_str(curr_policy),
'cpri': curr_prio,
- 'npol': schedutils.schedstr(new_policy),
+ 'npol': tuna_sched.sched_str(new_policy),
'npri': new_prio})
else:
changed = True
try:
- curr_affinity = schedutils.get_affinity(pid)
- # (3, 'No such process') old python-schedutils
- # incorrectly raised SystemError
- except (SystemError, OSError) as err:
- if err.args[0] == 3:
+ curr_affinity = os.sched_getaffinity(pid)
+ except OSError as err:
+ if err.args[0] == errno.ESRCH:
return False
raise err
@@ -110,16 +109,14 @@ def thread_set_attributes(pid_info, new_policy, new_prio, new_affinity, nr_cpus)
if curr_affinity != new_affinity:
try:
- schedutils.set_affinity(pid, new_affinity)
+ os.sched_setaffinity(pid, new_affinity)
except:
return invalid_affinity()
try:
- curr_affinity = schedutils.get_affinity(pid)
- # (3, 'No such process') old python-schedutils
- # incorrectly raised SystemError
- except (SystemError, OSError) as err:
- if err.args[0] == 3:
+ curr_affinity = os.sched_getaffinity(pid)
+ except OSError as err:
+ if err.args[0] == errno.ESRCH:
return False
raise err
diff --git a/tuna/tuna.py b/tuna/tuna.py
index 30e8752..e5122da 100755
--- a/tuna/tuna.py
+++ b/tuna/tuna.py
@@ -9,11 +9,11 @@ import sys
import shlex
import fnmatch
import platform
-import schedutils
import ethtool
import procfs
from procfs import utilist
from . import help
+import tuna.tuna_sched as tuna_sched
try:
fntable
@@ -191,19 +191,17 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning=None, spread=False)
try:
try:
- curr_affinity = schedutils.get_affinity(pid)
- # old python-schedutils incorrectly raised SystemError
- except(SystemError, OSError) as err:
+ curr_affinity = os.sched_getaffinity(pid)
+ except OSError as err:
if err.args[0] == errno.ESRCH:
continue
curr_affinity = None
raise err
if set(curr_affinity) != set(new_affinity):
try:
- schedutils.set_affinity(pid, new_affinity)
- curr_affinity = schedutils.get_affinity(pid)
- # old python-schedutils incorrectly raised SystemError
- except(SystemError, OSError) as err:
+ os.sched_setaffinity(pid, new_affinity)
+ curr_affinity = os.sched_getaffinity(pid)
+ except OSError as err:
if err.args[0] == errno.ESRCH:
continue
curr_affinity = None
@@ -231,18 +229,16 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning=None, spread=False)
threads = procfs.pidstats("/proc/%d/task" % pid)
for tid in list(threads.keys()):
try:
- curr_affinity = schedutils.get_affinity(tid)
- # old python-schedutils incorrectly raised SystemError
- except(SystemError, OSError) as err:
+ curr_affinity = os.sched_getaffinity(tid)
+ except OSError as err:
if err.args[0] == errno.ESRCH:
continue
raise err
if set(curr_affinity) != set(new_affinity):
try:
- schedutils.set_affinity(tid, new_affinity)
- curr_affinity = schedutils.get_affinity(tid)
- # old python-schedutils incorrectly raised SystemError
- except(SystemError, OSError) as err:
+ os.sched_setaffinity(tid, new_affinity)
+ curr_affinity = os.sched_getaffinity(tid)
+ except OSError as err:
if err.args[0] == errno.ESRCH:
continue
raise err
@@ -254,8 +250,7 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning=None, spread=False)
print("move_threads_to_cpu: %s " % \
(_("could not change %(pid)d affinity to %(new_affinity)s") % \
{'pid':pid, 'new_affinity':new_affinity}))
- # old python-schedutils incorrectly raised SystemError
- except (SystemError, OSError) as err:
+ except OSError as err:
if err.args[0] == errno.ESRCH:
# process died
continue
@@ -304,9 +299,8 @@ def move_irqs_to_cpu(cpus, irq_list, spread=False):
if pid:
pid = int(pid[0])
try:
- schedutils.set_affinity(pid, new_affinity)
- # old python-schedutils incorrectly raised SystemError
- except(SystemError, OSError) as err:
+ os.sched_setaffinity(pid, new_affinity)
+ except OSError as err:
if err.args[0] == errno.ESRCH:
unprocessed.append(i)
changed -= 1
@@ -354,9 +348,8 @@ def isolate_cpus(cpus, nr_cpus):
if procfs.cannot_set_affinity(ps, pid):
continue
try:
- affinity = schedutils.get_affinity(pid)
- # old python-schedutils incorrectly raised SystemError
- except (SystemError, OSError) as err:
+ affinity = os.sched_getaffinity(pid)
+ except OSError as err:
if err.args[0] == errno.ESRCH:
continue
if err.args[0] == errno.EINVAL:
@@ -367,9 +360,8 @@ def isolate_cpus(cpus, nr_cpus):
previous_pid_affinities[pid] = copy.copy(affinity)
affinity = affinity_remove_cpus(affinity, cpus, nr_cpus)
try:
- schedutils.set_affinity(pid, affinity)
- # old python-schedutils incorrectly raised SystemError
- except (SystemError, OSError) as err:
+ os.sched_setaffinity(pid, affinity)
+ except OSError as err:
if err.args[0] == errno.ESRCH:
continue
if err.args[0] == errno.EINVAL:
@@ -384,9 +376,8 @@ def isolate_cpus(cpus, nr_cpus):
if procfs.cannot_set_thread_affinity(ps, pid, tid):
continue
try:
- affinity = schedutils.get_affinity(tid)
- # old python-schedutils incorrectly raised SystemError
- except (SystemError, OSError) as err:
+ affinity = os.sched_getaffinity(tid)
+ except OSError as err:
if err.args[0] == errno.ESRCH:
continue
if err.args[0] == errno.EINVAL:
@@ -397,9 +388,8 @@ def isolate_cpus(cpus, nr_cpus):
previous_pid_affinities[tid] = copy.copy(affinity)
affinity = affinity_remove_cpus(affinity, cpus, nr_cpus)
try:
- schedutils.set_affinity(tid, affinity)
- # old python-schedutils incorrectly raised SystemError
- except (SystemError, OSError) as err:
+ os.sched_setaffinity(tid, affinity)
+ except OSError as err:
if err.args[0] == errno.ESRCH:
continue
if err.args[0] == errno.EINVAL:
@@ -436,9 +426,8 @@ def include_cpus(cpus, nr_cpus):
if procfs.cannot_set_affinity(ps, pid):
continue
try:
- affinity = schedutils.get_affinity(pid)
- # old python-schedutils incorrectly raised SystemError
- except (SystemError, OSError) as err:
+ affinity = os.sched_getaffinity(pid)
+ except OSError as err:
if err.args[0] == errno.ESRCH:
continue
raise err
@@ -446,9 +435,8 @@ def include_cpus(cpus, nr_cpus):
previous_pid_affinities[pid] = copy.copy(affinity)
affinity = list(set(affinity + cpus))
try:
- schedutils.set_affinity(pid, affinity)
- # old python-schedutils incorrectly raised SystemError
- except (SystemError, OSError) as err:
+ os.sched_setaffinity(pid, affinity)
+ except OSError as err:
if err.args[0] == errno.ESRCH:
continue
raise err
@@ -460,9 +448,8 @@ def include_cpus(cpus, nr_cpus):
if procfs.cannot_set_thread_affinity(ps, pid, tid):
continue
try:
- affinity = schedutils.get_affinity(tid)
- # old python-schedutils incorrectly raised SystemError
- except (SystemError, OSError) as err:
+ affinity = os.sched_getaffinity(tid)
+ except OSError as err:
if err.args[0] == errno.ESRCH:
continue
raise err
@@ -470,9 +457,8 @@ def include_cpus(cpus, nr_cpus):
previous_pid_affinities[tid] = copy.copy(affinity)
affinity = list(set(affinity + cpus))
try:
- schedutils.set_affinity(tid, affinity)
- # old python-schedutils incorrectly raised SystemError
- except (SystemError, OSError) as err:
+ os.sched_setaffinity(tid, affinity)
+ except OSError as err:
if err.args[0] == errno.ESRCH:
continue
raise err
@@ -524,7 +510,7 @@ def get_policy_and_rtprio(parm):
rtprio = 0
policy = None
if parms[0].upper() in ["OTHER", "BATCH", "IDLE", "FIFO", "RR"]:
- policy = schedutils.schedfromstr("SCHED_%s" % parms[0].upper())
+ policy = tuna_sched.sched_fromstr("SCHED_%s" % parms[0].upper())
if len(parms) > 1:
rtprio = int(parms[1])
elif parms[0].upper() in ["FIFO", "RR"]:
@@ -538,9 +524,8 @@ def get_policy_and_rtprio(parm):
def thread_filtered(tid, cpus_filtered, show_kthreads, show_uthreads):
if cpus_filtered:
try:
- affinity = schedutils.get_affinity(tid)
- # old python-schedutils incorrectly raised SystemError
- except (SystemError, OSError) as err:
+ affinity = os.sched_getaffinity(tid)
+ except OSError as err:
if err.args[0] == errno.ESRCH:
return False
raise err
@@ -565,9 +550,10 @@ def irq_filtered(irq, irqs, cpus_filtered, is_root):
return False
def thread_set_priority(tid, policy, rtprio):
+ param = os.sched_param(rtprio)
if not policy and policy != 0:
- policy = schedutils.get_scheduler(tid)
- schedutils.set_scheduler(tid, policy, rtprio)
+ policy = os.sched_getscheduler(tid)
+ os.sched_setscheduler(tid, policy, param)
def threads_set_priority(tids, parm, affect_children=False):
try:
@@ -579,8 +565,7 @@ def threads_set_priority(tids, parm, affect_children=False):
for tid in tids:
try:
thread_set_priority(tid, policy, rtprio)
- # old python-schedutils incorrectly raised SystemError
- except (SystemError, OSError) as err:
+ except OSError as err:
if err.args[0] == errno.ESRCH:
continue
raise err
@@ -589,8 +574,7 @@ def threads_set_priority(tids, parm, affect_children=False):
if child != tid:
try:
thread_set_priority(child, policy, rtprio)
- # old python-schedutils incorrectly raised SystemError
- except(SystemError, OSError) as err:
+ except OSError as err:
if err.args[0] == errno.ESRCH:
continue
raise err
@@ -619,10 +603,9 @@ def get_kthread_sched_tunings(proc=None):
if iskthread(pid) and not name.startswith("migration/"):
rtprio = int(proc[pid]["stat"]["rt_priority"])
try:
- policy = schedutils.get_scheduler(pid)
- affinity = schedutils.get_affinity(pid)
- # old python-schedutils incorrectly raised SystemError
- except(SystemError, OSError) as err:
+ policy = os.sched_getscheduler(pid)
+ affinity = os.sched_getaffinity(pid)
+ except OSError as err:
if err.args[0] == errno.ESRCH:
continue
raise err
@@ -646,7 +629,7 @@ def run_command(cmd, policy, rtprio, cpu_list):
sys.exit(2)
if cpu_list:
try:
- schedutils.set_affinity(pid, cpu_list)
+ os.sched_setaffinity(pid, cpu_list)
except (SystemError, OSError) as err:
print("tuna: %s" % err)
sys.exit(2)
@@ -718,7 +701,7 @@ def generate_rtgroups(filename, kthreads, nr_cpus):
mask = ",".join([hex(a) for a in \
procfs.hexbitmask(kt.affinity, nr_cpus)])
f.write("%s:%c:%d:%s:\[%s\]$\n" % (name, \
- schedutils.schedstr(kt.policy)[6].lower(), \
+ tuna_sched.sched_str(kt.policy)[6].lower(), \
kt.rtprio, mask, regex))
f.close()
diff --git a/tuna/tuna_sched.py b/tuna/tuna_sched.py
new file mode 100644
index 0000000..fee5f16
--- /dev/null
+++ b/tuna/tuna_sched.py
@@ -0,0 +1,29 @@
+"""
+Functions to translate a scheduling policy into either a string name or an
+equivalent integer
+"""
+import os
+
+SCHED_POLICIES = {
+ "SCHED_OTHER": os.SCHED_OTHER,
+ "SCHED_FIFO": os.SCHED_FIFO,
+ "SCHED_RR": os.SCHED_RR,
+ "SCHED_BATCH": os.SCHED_BATCH,
+ "SCHED_IDLE": os.SCHED_IDLE,
+ "SCHED_DEADLINE": 6
+}
+
+def sched_fromstr(policy):
+ """ Given a policy as a string, return the equivalent integer """
+ try:
+ return SCHED_POLICIES[policy]
+ except:
+ raise OSError()
+
+
+def sched_str(policy):
+ """ Given a policy as an integer, return the equivalent string name """
+ for pstr, pnum in SCHED_POLICIES.items():
+ if pnum == policy:
+ return pstr
+ return "UNKNOWN"