diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-01-17 15:57:49 -0300 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-01-17 16:01:54 -0300 |
commit | 5d4ee705eebdefa4f0f1d22f19e874e7b43e007b (patch) | |
tree | 625ec7ca1fcf555a4a718ba17697489852744d2e | |
parent | cca561d2b28f3204cb2c2d17741370b613f83e49 (diff) | |
download | tuna-5d4ee705eebdefa4f0f1d22f19e874e7b43e007b.tar.gz |
tuna: Tighten "No such process" schedutils exception handling
I.e. don't consider all OSError as if the process went away, as this
trows away other errors we want to know about.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rwxr-xr-x | tuna-cmd.py | 12 | ||||
-rwxr-xr-x | tuna/gui/util.py | 13 | ||||
-rwxr-xr-x | tuna/tuna.py | 104 |
3 files changed, 86 insertions, 43 deletions
diff --git a/tuna-cmd.py b/tuna-cmd.py index 8fb986c..17bd392 100755 --- a/tuna-cmd.py +++ b/tuna-cmd.py @@ -170,8 +170,10 @@ def ps_show_thread(pid, affect_children, ps, global irqs try: affinity = format_affinity(schedutils.get_affinity(pid)) - except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError - return + except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError + if e[0] == 3: + return + raise e sched = schedutils.schedstr(schedutils.get_scheduler(pid))[6:] rtprio = int(ps[pid]["stat"]["rt_priority"]) @@ -246,8 +248,10 @@ def ps_show(ps, affect_children, thread_list, cpu_list, continue try: affinity = schedutils.get_affinity(pid) - except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError - continue + except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError + if e[0] == 3: + continue + raise e if cpu_list and not set(cpu_list).intersection(set(affinity)): continue ps_list.append(pid) diff --git a/tuna/gui/util.py b/tuna/gui/util.py index ed46784..33c8567 100755 --- a/tuna/gui/util.py +++ b/tuna/gui/util.py @@ -84,8 +84,10 @@ def thread_set_attributes(pid, threads, new_policy, new_prio, new_affinity, nr_c try: curr_affinity = schedutils.get_affinity(pid) - except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError - return False + except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError + if e[0] == 3: + return False + raise e try: new_affinity = [ int(a) for a in new_affinity.split(",") ] @@ -105,8 +107,11 @@ def thread_set_attributes(pid, threads, new_policy, new_prio, new_affinity, nr_c try: curr_affinity = schedutils.get_affinity(pid) - except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError - return False + except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError + if e[0] == 3: + return False + raise e + if curr_affinity != new_affinity: print _("couldn't change pid %(pid)d from %(caff)s to %(naff)s!") % \ { 'pid':pid, 'caff':curr_affinity, 'naff':new_affinity } diff --git a/tuna/tuna.py b/tuna/tuna.py index 810d86c..a9dab14 100755 --- a/tuna/tuna.py +++ b/tuna/tuna.py @@ -170,6 +170,7 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None, if e[0] == 3: # 'No such process' continue curr_affinity = None + raise e if set(curr_affinity) != set(new_affinity): try: schedutils.set_affinity(pid, new_affinity) @@ -178,6 +179,7 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None, if e[0] == 3: # 'No such process' continue curr_affinity == None + raise e if set(curr_affinity) == set(new_affinity): changed = True if is_hardirq_handler(ps, pid): @@ -202,14 +204,18 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None, for tid in threads.keys(): try: curr_affinity = schedutils.get_affinity(tid) - except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError - continue + except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError + if e[0] == 3: + continue + raise e if set(curr_affinity) != set(new_affinity): try: schedutils.set_affinity(tid, new_affinity) curr_affinity = schedutils.get_affinity(tid) - except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError - continue + except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError + if e[0] == 3: + continue + raise e if set(curr_affinity) == set(new_affinity): changed = True elif set_affinity_warning: @@ -218,9 +224,11 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None, print "move_threads_to_cpu: %s " % \ (_("could not change %(pid)d affinity to %(new_affinity)s") % \ {'pid':pid, 'new_affinity':new_affinity}) - except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError - # process died - continue + except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError + if e[0] == 3: + # process died + continue + raise e return changed def move_irqs_to_cpu(cpus, irq_list, spread = False): @@ -263,10 +271,12 @@ def move_irqs_to_cpu(cpus, irq_list, spread = False): pid = int(pid[0]) try: schedutils.set_affinity(pid, new_affinity) - except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError - unprocessed.append(i) - changed -= 1 - continue + except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError + if e[0] == 3: + unprocessed.append(i) + changed -= 1 + continue + raise e return (changed, unprocessed) @@ -287,15 +297,19 @@ def isolate_cpus(cpus, nr_cpus): continue try: affinity = schedutils.get_affinity(pid) - except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError - continue + except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError + if e[0] == 3: + continue + raise e if set(affinity).intersection(set(cpus)): previous_pid_affinities[pid] = copy.copy(affinity) affinity = affinity_remove_cpus(affinity, cpus, nr_cpus) try: schedutils.set_affinity(pid, affinity) - except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError - continue + except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError + if e[0] == 3: + continue + raise e if not ps[pid].has_key("threads"): continue @@ -305,15 +319,19 @@ def isolate_cpus(cpus, nr_cpus): continue try: affinity = schedutils.get_affinity(tid) - except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError - continue + except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError + if e[0] == 3: + continue + raise e if set(affinity).intersection(set(cpus)): previous_pid_affinities[tid] = copy.copy(affinity) affinity = affinity_remove_cpus(affinity, cpus, nr_cpus) try: schedutils.set_affinity(tid, affinity) - except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError - continue + except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError + if e[0] == 3: + continue + raise e del ps @@ -343,15 +361,19 @@ def include_cpus(cpus, nr_cpus): continue try: affinity = schedutils.get_affinity(pid) - except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError - continue + except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError + if e[0] == 3: + continue + raise e if set(affinity).intersection(set(cpus)) != set(cpus): previous_pid_affinities[pid] = copy.copy(affinity) affinity = list(set(affinity + cpus)) try: schedutils.set_affinity(pid, affinity) - except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError - continue + except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError + if e[0] == 3: + continue + raise e if not ps[pid].has_key("threads"): continue @@ -361,15 +383,19 @@ def include_cpus(cpus, nr_cpus): continue try: affinity = schedutils.get_affinity(tid) - except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError - continue + except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError + if e[0] == 3: + continue + raise e if set(affinity).intersection(set(cpus)) != set(cpus): previous_pid_affinities[tid] = copy.copy(affinity) affinity = list(set(affinity + cpus)) try: schedutils.set_affinity(tid, affinity) - except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError - continue + except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError + if e[0] == 3: + continue + raise e del ps @@ -414,8 +440,10 @@ def thread_filtered(tid, cpus_filtered, show_kthreads, show_uthreads): if cpus_filtered: try: affinity = schedutils.get_affinity(tid) - except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError - return False + except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError + if e[0] == 3: + return False + raise e if set(cpus_filtered + affinity) == set(cpus_filtered): return True @@ -453,15 +481,19 @@ def threads_set_priority(tids, parm, affect_children = False): for tid in tids: try: thread_set_priority(tid, policy, rtprio) - except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError - continue + except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError + if e[0] == 3: + continue + raise e if affect_children: for child in [int (a) for a in os.listdir("/proc/%d/task" % tid)]: if child != tid: try: thread_set_priority(child, policy, rtprio) - except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError - continue + except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError + if e[0] == 3: + continue + raise e class sched_tunings: def __init__(self, name, pid, policy, rtprio, affinity, percpu): @@ -489,8 +521,10 @@ def get_kthread_sched_tunings(proc = None): try: policy = schedutils.get_scheduler(pid) affinity = schedutils.get_affinity(pid) - except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError - continue + except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError + if e[0] == 3: + continue + raise e percpu = iskthread(pid) and \ proc.is_bound_to_cpu(pid) kthreads[name] = sched_tunings(name, pid, policy, |