diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2008-10-15 19:39:05 -0200 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2008-10-15 19:39:05 -0200 |
commit | 078f9549076c5d5fb0ca5f8ee573c6e7d49eb22d (patch) | |
tree | 16446cf1f0b9ab64f6d554a94d9e774110ef2418 | |
parent | c8654b13c9c750329b2a01ec92c6d6f7cc3d87ce (diff) | |
download | tuna-078f9549076c5d5fb0ca5f8ee573c6e7d49eb22d.tar.gz |
tuna: handle schedutils SystemError exceptions
Sometimes the refresh stopped due to threads disappearing and the schedutils
routines (get_affinity, set_affinity, etc) trowing SystemError exceptions,
handle them.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rwxr-xr-x | tuna-cmd.py | 15 | ||||
-rwxr-xr-x | tuna/tuna.py | 77 | ||||
-rw-r--r-- | tuna/tuna_gui.py | 13 |
3 files changed, 81 insertions, 24 deletions
diff --git a/tuna-cmd.py b/tuna-cmd.py index 2c4b566..8683867 100755 --- a/tuna-cmd.py +++ b/tuna-cmd.py @@ -86,7 +86,11 @@ def ps_show_header(has_ctxt_switch_info): "cmd") def ps_show_thread(pid, affect_children, ps, cpuinfo, irqs, nics, has_ctxt_switch_info): - affinity = schedutils.get_affinity(pid) + try: + affinity = schedutils.get_affinity(pid) + except SystemError: # (3, 'No such process') + return + if len(affinity) <= 4: affinity = ",".join(str(a) for a in affinity) else: @@ -137,7 +141,10 @@ def ps_show(ps, affect_children, cpuinfo, irqs, threads, cpus, continue if not show_kthreads and iskth: continue - affinity = schedutils.get_affinity(pid) + try: + affinity = schedutils.get_affinity(pid) + except SystemError: # (3, 'No such process') + continue if cpus and not set(cpus).intersection(set(affinity)): continue ps_list.append(pid) @@ -149,7 +156,7 @@ def ps_show(ps, affect_children, cpuinfo, irqs, threads, cpus, for pid in ps_list: ps_show_thread(pid, affect_children, ps, cpuinfo, irqs, nics, has_ctxt_switch_info) -def ps(threads, cpus, show_uthreads, show_kthreads, affect_children): +def do_ps(threads, cpus, show_uthreads, show_kthreads, affect_children): ps = procfs.pidstats() if affect_children: ps.reload_threads() @@ -215,7 +222,7 @@ def main(): elif o in ("-p", "--priority"): tuna.threads_set_priority(threads, a, affect_children) elif o in ("-P", "--show_threads"): - ps(threads, cpus, uthreads, kthreads, affect_children) + do_ps(threads, cpus, uthreads, kthreads, affect_children) elif o in ("-m", "--move"): if not cpus: print "tuna: --move requires a cpu list!" diff --git a/tuna/tuna.py b/tuna/tuna.py index 6de6ec8..5cad29e 100755 --- a/tuna/tuna.py +++ b/tuna/tuna.py @@ -148,10 +148,16 @@ def move_threads_to_cpu(new_affinity, pid_list, set_affinity_warning = None): ps = procfs.pidstats() for pid in pid_list: try: - curr_affinity = schedutils.get_affinity(pid) - if set(curr_affinity) != set(new_affinity): - schedutils.set_affinity(pid, new_affinity) + try: curr_affinity = schedutils.get_affinity(pid) + except SystemError: # (3, 'No such process') + continue + if set(curr_affinity) != set(new_affinity): + try: + schedutils.set_affinity(pid, new_affinity) + curr_affinity = schedutils.get_affinity(pid) + except SystemError: # (3, 'No such process') + continue if set(curr_affinity) == set(new_affinity): changed = True elif set_affinity_warning: @@ -165,10 +171,16 @@ def move_threads_to_cpu(new_affinity, pid_list, set_affinity_warning = None): threads = procfs.pidstats("/proc/%d/task" % pid) for tid in threads.keys(): - curr_affinity = schedutils.get_affinity(tid) - if set(curr_affinity) != set(new_affinity): - schedutils.set_affinity(tid, new_affinity) + try: curr_affinity = schedutils.get_affinity(tid) + except SystemError: # (3, 'No such process') + continue + if set(curr_affinity) != set(new_affinity): + try: + schedutils.set_affinity(tid, new_affinity) + curr_affinity = schedutils.get_affinity(tid) + except SystemError: # (3, 'No such process') + continue if set(curr_affinity) == set(new_affinity): changed = True elif set_affinity_warning: @@ -195,11 +207,17 @@ def isolate_cpus(cpus, nr_cpus): for pid in ps.keys(): if iskthread(pid): continue - affinity = schedutils.get_affinity(pid) + try: + affinity = schedutils.get_affinity(pid) + except SystemError: # (3, 'No such process') + continue if set(affinity).intersection(set(cpus)): previous_pid_affinities[pid] = copy.copy(affinity) affinity = affinity_remove_cpus(affinity, cpus, nr_cpus) - schedutils.set_affinity(pid, affinity) + try: + schedutils.set_affinity(pid, affinity) + except SystemError: # (3, 'No such process') + continue if not ps[pid].has_key("threads"): continue @@ -207,11 +225,17 @@ def isolate_cpus(cpus, nr_cpus): for tid in threads.keys(): if iskthread(tid): continue - affinity = schedutils.get_affinity(tid) + try: + affinity = schedutils.get_affinity(tid) + except SystemError: # (3, 'No such process') + continue if set(affinity).intersection(set(cpus)): previous_pid_affinities[tid] = copy.copy(affinity) affinity = affinity_remove_cpus(affinity, cpus, nr_cpus) - schedutils.set_affinity(tid, affinity) + try: + schedutils.set_affinity(tid, affinity) + except SystemError: # (3, 'No such process') + continue del ps @@ -239,11 +263,17 @@ def include_cpus(cpus, nr_cpus): for pid in ps.keys(): if iskthread(pid): continue - affinity = schedutils.get_affinity(pid) + try: + affinity = schedutils.get_affinity(pid) + except SystemError: # (3, 'No such process') + continue if set(affinity).intersection(set(cpus)) != set(cpus): previous_pid_affinities[pid] = copy.copy(affinity) affinity = list(set(affinity + cpus)) - schedutils.set_affinity(pid, affinity) + try: + schedutils.set_affinity(pid, affinity) + except SystemError: # (3, 'No such process') + continue if not ps[pid].has_key("threads"): continue @@ -251,11 +281,17 @@ def include_cpus(cpus, nr_cpus): for tid in threads.keys(): if iskthread(tid): continue - affinity = schedutils.get_affinity(tid) + try: + affinity = schedutils.get_affinity(tid) + except SystemError: # (3, 'No such process') + continue if set(affinity).intersection(set(cpus)) != set(cpus): previous_pid_affinities[tid] = copy.copy(affinity) affinity = list(set(affinity + cpus)) - schedutils.set_affinity(tid, affinity) + try: + schedutils.set_affinity(tid, affinity) + except SystemError: # (3, 'No such process') + continue del ps @@ -298,7 +334,11 @@ def get_irq_affinity_text(irqs, irq): def thread_filtered(tid, cpus_filtered, show_kthreads, show_uthreads): if cpus_filtered: - affinity = schedutils.get_affinity(tid) + try: + affinity = schedutils.get_affinity(tid) + except SystemError: # (3, 'No such process') + return False + if set(cpus_filtered + affinity) == set(cpus_filtered): return True @@ -357,8 +397,11 @@ def get_kthread_sched_tunings(proc = None): if iskthread(pid): name = proc[pid]["stat"]["comm"] rtprio = int(proc[pid]["stat"]["rt_priority"]) - policy = schedutils.get_scheduler(pid) - affinity = schedutils.get_affinity(pid) + try: + policy = schedutils.get_scheduler(pid) + affinity = schedutils.get_affinity(pid) + except SystemError: # (3, 'No such process') + continue percpu = iskthread(pid) and \ proc.is_bound_to_cpu(pid) kthreads[name] = sched_tunings(name, pid, policy, diff --git a/tuna/tuna_gui.py b/tuna/tuna_gui.py index 48d7f6a..f012752 100644 --- a/tuna/tuna_gui.py +++ b/tuna/tuna_gui.py @@ -453,7 +453,11 @@ def thread_set_attributes(pid, threads, new_policy, new_prio, new_affinity, nr_c else: changed = True - curr_affinity = schedutils.get_affinity(pid) + try: + curr_affinity = schedutils.get_affinity(pid) + except SystemError: # (3, 'No such process') + return False + try: new_affinity = [ int(a) for a in new_affinity.split(",") ] except: @@ -470,7 +474,10 @@ def thread_set_attributes(pid, threads, new_policy, new_prio, new_affinity, nr_c except: return invalid_affinity() - curr_affinity = schedutils.get_affinity(pid) + try: + curr_affinity = schedutils.get_affinity(pid) + except SystemError: # (3, 'No such process') + return False if curr_affinity != new_affinity: print "couldn't change pid %d from %s to %s!" % \ ( pid, curr_affinity, new_affinity ) @@ -1077,11 +1084,11 @@ class procview: try: new_value[self.COL_POL] = schedutils.schedstr(schedutils.get_scheduler(tid))[6:] + thread_affinity_list = schedutils.get_affinity(tid) except SystemError: return True new_value[self.COL_PID] = tid - thread_affinity_list = schedutils.get_affinity(tid) new_value[self.COL_AFF] = tuna.list_to_cpustring(thread_affinity_list) try: new_value[self.COL_VOLCTXT] = int(thread_info["status"]["voluntary_ctxt_switches"]) |