def run(self): changed = False if self.dialog.run() == gtk.RESPONSE_OK: new_policy = self.sched_policy.get_active() new_prio = int(self.sched_pri.get_value()) new_affinity = self.affinity.get_text() irq_re = tuna.threaded_irq_re(self.irq) pids = self.ps.find_by_regex(irq_re) if pids: if gui.thread_set_attributes(self.ps[pids[0]], new_policy, new_prio, new_affinity, self.irqs.nr_cpus): changed = True try: new_affinity = [int(a) for a in new_affinity.split(",")] except: try: new_affinity = tuna.cpustring_to_list(new_affinity) except: new_affinity = procfs.bitmasklist(new_affinity, self.irqs.nr_cpus) new_affinity.sort() curr_affinity = self.irqs[self.irq]["affinity"] if curr_affinity != new_affinity: tuna.set_irq_affinity( self.irq, procfs.hexbitmask(new_affinity, self.irqs.nr_cpus)) changed = True self.dialog.destroy() return changed
def bitmasklist_test(self): print "\n##################\n" cpu = bitmasklist(self.line, self.nr_entries) print "Converted : ", self.line, "\nto ", cpu if cpu == self.expected_result: self.result = 0 print "PASS" else: self.result = 1 print "expected : ", self.expected_result print "FAIL" self.set_unit_test_result()
def run(self): changed = False if self.dialog.run() == gtk.RESPONSE_OK: new_policy = self.sched_policy.get_active() new_prio = int(self.sched_pri.get_value()) new_affinity = self.affinity.get_text() irq_re = tuna.threaded_irq_re(self.irq) pids = self.ps.find_by_regex(irq_re) if pids: if gui.thread_set_attributes(self.ps[pids[0]], new_policy, new_prio, new_affinity, self.irqs.nr_cpus): changed = True try: new_affinity = [ int(a) for a in new_affinity.split(",") ] except: try: new_affinity = tuna.cpustring_to_list(new_affinity) except: new_affinity = procfs.bitmasklist(new_affinity, self.irqs.nr_cpus) new_affinity.sort() curr_affinity = self.irqs[self.irq]["affinity"] if curr_affinity != new_affinity: tuna.set_irq_affinity(self.irq, procfs.hexbitmask(new_affinity, self.irqs.nr_cpus)) changed = True self.dialog.destroy() return changed
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_prio = int(pid_info["stat"]["rt_priority"]) if new_policy == schedutils.SCHED_OTHER: new_prio = 0 if curr_policy != new_policy or curr_prio != new_prio: try: schedutils.set_scheduler(pid, new_policy, new_prio) except: dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, _("Invalid parameters!")) dialog.run() dialog.destroy() return False curr_policy = schedutils.get_scheduler(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), 'cpri': curr_prio, 'npol': schedutils.schedstr(new_policy), 'npri': new_prio} else: changed = True 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: return False raise e try: new_affinity = [int(a) for a in new_affinity.split(",")] except: try: new_affinity = tuna.cpustring_to_list(new_affinity) except: new_affinity = procfs.bitmasklist(new_affinity, nr_cpus) new_affinity.sort() if curr_affinity != new_affinity: try: schedutils.set_affinity(pid, new_affinity) except: return invalid_affinity() 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: 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 } else: changed = True return changed
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_prio = int(pid_info["stat"]["rt_priority"]) if new_policy == schedutils.SCHED_OTHER: new_prio = 0 if curr_policy != new_policy or curr_prio != new_prio: try: schedutils.set_scheduler(pid, new_policy, new_prio) except: dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, _("Invalid parameters!")) dialog.run() dialog.destroy() return False curr_policy = schedutils.get_scheduler(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), 'cpri': curr_prio, 'npol': schedutils.schedstr(new_policy), 'npri': new_prio} else: changed = True 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: return False raise e try: new_affinity = [ int(a) for a in new_affinity.split(",") ] except: try: new_affinity = tuna.cpustring_to_list(new_affinity) except: new_affinity = procfs.bitmasklist(new_affinity, nr_cpus) new_affinity.sort() if curr_affinity != new_affinity: try: schedutils.set_affinity(pid, new_affinity) except: return invalid_affinity() 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: 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 } else: changed = True return changed