Exemple #1
0
def show_irqs(irq_list, cpu_list):
	global irqs
	if not irqs:
		irqs = procfs.interrupts()

	print "%4s %-16s %8s" % ("#", _("users"), _("affinity"),)
	sorted_irqs = []
	for k in irqs.keys():
		try:
			irqn = int(k)
			affinity = irqs[irqn]["affinity"]
		except:
			continue
		if irq_list and irqn not in irq_list:
			continue

		if cpu_list and not set(cpu_list).intersection(set(affinity)):
			continue
		sorted_irqs.append(irqn)

	sorted_irqs.sort()
	for irq in sorted_irqs:
		affinity = format_affinity(irqs[irq]["affinity"])
		users = irqs[irq]["users"]
		print "%4d %-16s %8s" % (irq, ",".join(users), affinity),
		drivers = find_drivers_by_users(users)
		if drivers:
			print " %s" % ",".join(drivers)
		else:
			print
Exemple #2
0
    def _set_all_irq_affinity(self, affinity):
        irq_original = IRQAffinities()
        irqs = procfs.interrupts()
        for irq in irqs.keys():
            try:
                prev_affinity = irqs[irq]["affinity"]
                log.debug("Read affinity of IRQ '%s': '%s'" %
                          (irq, prev_affinity))
            except KeyError:
                continue
            _affinity = self._get_intersect_affinity(prev_affinity, affinity,
                                                     affinity)
            if set(_affinity) == set(prev_affinity):
                continue
            if self._set_irq_affinity(irq, _affinity, False):
                irq_original.irqs[irq] = prev_affinity

        # default affinity
        prev_affinity_hex = self._cmd.read_file(
            "/proc/irq/default_smp_affinity")
        prev_affinity = self._cmd.hex2cpulist(prev_affinity_hex)
        _affinity = self._get_intersect_affinity(prev_affinity, affinity,
                                                 affinity)
        self._set_default_irq_affinity(_affinity)
        irq_original.default = prev_affinity
        self._storage.set(self._irq_storage_key, irq_original)
Exemple #3
0
def show_irqs(irq_list, cpu_list):
    global irqs
    if not irqs:
        irqs = procfs.interrupts()

    print "%4s %-16s %8s" % ("#", _("users"), _("affinity"))
    sorted_irqs = []
    for k in irqs.keys():
        try:
            irqn = int(k)
            affinity = irqs[irqn]["affinity"]
        except:
            continue
        if irq_list and irqn not in irq_list:
            continue

        if cpu_list and not set(cpu_list).intersection(set(affinity)):
            continue
        sorted_irqs.append(irqn)

    sorted_irqs.sort()
    for irq in sorted_irqs:
        affinity = format_affinity(irqs[irq]["affinity"])
        users = irqs[irq]["users"]
        print "%4d %-16s %8s" % (irq, ",".join(users), affinity),
        drivers = find_drivers_by_users(users)
        if drivers:
            print " %s" % ",".join(drivers)
        else:
            print
	def _set_ps_affinity(self, affinity, intersect = False):
		_affinity = affinity
		affinity_hex = self._cmd.cpulist2hex(_affinity)
		ps = procfs.pidstats()
		ps.reload_threads()
		psl = [v for v in list(ps.values()) if re.search(self._ps_whitelist, self._get_stat_comm(v)) is not None]
		if self._ps_blacklist != "":
			psl = [v for v in psl if re.search(self._ps_blacklist, self._get_stat_comm(v)) is None]
		psd = dict([(v.pid, v) for v in psl])
		self._set_all_obj_affinity(psd, affinity, False, intersect)

		# process IRQs
		irqs = procfs.interrupts()
		for irq in list(irqs.keys()):
			try:
				prev_affinity = irqs[irq]["affinity"]
			except KeyError:
				continue
			if intersect:
				_affinity = self._get_intersect_affinity(prev_affinity, affinity, affinity)
				affinity_hex = self._cmd.cpulist2hex(_affinity)
			self._cmd.write_to_file("/proc/irq/%s/smp_affinity" % irq, affinity_hex, no_error = True)

		# default affinity
		prev_affinity_hex = self._cmd.read_file("/proc/irq/default_smp_affinity")
		prev_affinity = self._cmd.hex2cpulist(prev_affinity_hex)
		if intersect:
			_affinity = self._get_intersect_affinity(prev_affinity, affinity, affinity)
			affinity_hex = self._cmd.cpulist2hex(_affinity)
		self._cmd.write_to_file("/proc/irq/default_smp_affinity", affinity_hex)
Exemple #5
0
    def _set_all_irq_affinity(self, affinity):
        irq_original = IRQAffinities()
        irqs = procfs.interrupts()
        for irq in irqs.keys():
            try:
                prev_affinity = irqs[irq]["affinity"]
                log.debug("Read affinity of IRQ '%s': '%s'" %
                          (irq, prev_affinity))
            except KeyError:
                continue
            _affinity = self._get_intersect_affinity(prev_affinity, affinity,
                                                     affinity)
            if set(_affinity) == set(prev_affinity):
                continue
            res = self._set_irq_affinity(irq, _affinity, False)
            if res == 0:
                irq_original.irqs[irq] = prev_affinity
            elif res == -2:
                irq_original.unchangeable.append(irq)

        # default affinity
        prev_affinity_hex = self._cmd.read_file(
            "/proc/irq/default_smp_affinity")
        prev_affinity = self._cmd.hex2cpulist(prev_affinity_hex)
        if self._default_irq_smp_affinity_value == "calc":
            _affinity = self._get_intersect_affinity(prev_affinity, affinity,
                                                     affinity)
        elif self._default_irq_smp_affinity_value != "ignore":
            _affinity = self._default_irq_smp_affinity_value
        if self._default_irq_smp_affinity_value != "ignore":
            self._set_default_irq_affinity(_affinity)
            irq_original.default = prev_affinity
        self._storage.set(self._irq_storage_key, irq_original)
Exemple #6
0
    def ps_show_thread(self, pid, affect_children, ps, has_ctxt_switch_info,
                       sock_inodes, sock_inode_re, cgroups):
        try:
            affinity = self.format_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
            raise e

        sched = schedutils.schedstr(schedutils.get_scheduler(pid))[6:]
        rtprio = int(ps[pid]["stat"]["rt_priority"])
        cgout = ps[pid]["cgroups"]
        cmd = ps[pid]["stat"]["comm"]
        users = ""
        if tuna.is_irq_thread(cmd):
            try:
                if not self.irqs:
                    self.irqs = procfs.interrupts()
                if cmd[:4] == "IRQ-":
                    users = self.irqs[tuna.irq_thread_number(cmd)]["users"]
                    for u in users:
                        if u in self.get_nics():
                            users[users.index(
                                u)] = "%s(%s)" % (u, ethtool.get_module(u))
                    users = ",".join(users)
                else:
                    u = cmd[cmd.find('-') + 1:]
                    if u in self.get_nics():
                        users = ethtool.get_module(u)
            except:
                users = "Not found in /proc/interrupts!"

        ctxt_switch_info = ""
        if has_ctxt_switch_info:
            voluntary_ctxt_switches = int(
                ps[pid]["status"]["voluntary_ctxt_switches"])
            nonvoluntary_ctxt_switches = int(
                ps[pid]["status"]["nonvoluntary_ctxt_switches"])
            ctxt_switch_info = " %9d %12s" % (voluntary_ctxt_switches,
                                              nonvoluntary_ctxt_switches)

        if affect_children:
            print " %-5d " % pid,
        else:
            print "  %-5d" % pid,
        print "%6s %5d %8s%s %15s %s" % (sched, rtprio, affinity,
                                         ctxt_switch_info, cmd, users),
        if cgroups:
            print " %9s" % cgout,
        print ""
        if sock_inodes:
            self.ps_show_sockets(pid, ps, sock_inodes, sock_inode_re,
                                 affect_children and 3 or 4)
        if affect_children and ps[pid].has_key("threads"):
            for tid in ps[pid]["threads"].keys():
                self.ps_show_thread(tid, False, ps[pid]["threads"],
                                    has_ctxt_switch_info, sock_inodes,
                                    sock_inode_re)
Exemple #7
0
    def _verify_all_irq_affinity(self, correct_affinity, ignore_missing):
        irq_original = self._storage.get(self._irq_storage_key, None)
        irqs = procfs.interrupts()
        res = True
        for irq in irqs.keys():
            if irq in irq_original.unchangeable and ignore_missing:
                description = "IRQ %s does not support changing SMP affinity" % irq
                log.info(consts.STR_VERIFY_PROFILE_VALUE_MISSING % description)
                continue
            try:
                current_affinity = irqs[irq]["affinity"]
                log.debug("Read SMP affinity of IRQ '%s': '%s'" %
                          (irq, current_affinity))
                irq_description = "SMP affinity of IRQ %s" % irq
                if not self._verify_irq_affinity(
                        irq_description, correct_affinity, current_affinity):
                    res = False
            except KeyError:
                continue

        current_affinity_hex = self._cmd.read_file(
            "/proc/irq/default_smp_affinity")
        current_affinity = self._cmd.hex2cpulist(current_affinity_hex)
        if self._default_irq_smp_affinity_value != "ignore" and not self._verify_irq_affinity(
                "default IRQ SMP affinity", current_affinity,
                correct_affinity if self._default_irq_smp_affinity_value
                == "calc" else self._default_irq_smp_affinity_value):
            res = False
        return res
Exemple #8
0
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: # (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"])
	cgout = ps[pid]["cgroups"]
	cmd = ps[pid]["stat"]["comm"]
	users = ""
	if tuna.is_irq_thread(cmd):
		try:
			if not irqs:
				irqs = procfs.interrupts()
			if cmd[:4] == "IRQ-":
				users = irqs[tuna.irq_thread_number(cmd)]["users"]
				for u in users:
					if u in get_nics():
						users[users.index(u)] = "%s(%s)" % (u, ethtool.get_module(u))
				users = ",".join(users)
			else:
				u = cmd[cmd.find('-') + 1:]
				if u in get_nics():
					users = ethtool.get_module(u)
		except:
			users = "Not found in /proc/interrupts!"

	ctxt_switch_info = ""
	if has_ctxt_switch_info:
		voluntary_ctxt_switches = int(ps[pid]["status"]["voluntary_ctxt_switches"])
		nonvoluntary_ctxt_switches = int(ps[pid]["status"]["nonvoluntary_ctxt_switches"])
		ctxt_switch_info = " %9d %12s" % (voluntary_ctxt_switches,
						  nonvoluntary_ctxt_switches)
	
	if affect_children:
		print " %-5d " % pid,
	else:
		print "  %-5d" % pid,
	print "%6s %5d %8s%s %15s %s" % (sched, rtprio, affinity,
					 ctxt_switch_info, cmd, users),
	if cgroups:
		print " %9s" % cgout,
	print ""
	if sock_inodes:
		ps_show_sockets(pid, ps, sock_inodes, sock_inode_re,
				affect_children and 3 or 4)
	if affect_children and ps[pid].has_key("threads"):
		for tid in ps[pid]["threads"].keys():
			ps_show_thread(tid, False, ps[pid]["threads"],
				       has_ctxt_switch_info,
				       sock_inodes, sock_inode_re, cgroups)
Exemple #9
0
def move_irqs_to_cpu(cpus, irq_list, spread = False):
	changed = 0
	unprocessed = []

	cpu_idx = 0
	nr_cpus = len(cpus)
	new_affinity = cpus
	last_cpu = max(cpus) + 1
	irqs = None
	ps = procfs.pidstats()
	for i in irq_list:
		try:
			irq = int(i)
		except:
			if not irqs:
				irqs = procfs.interrupts()
			irq = irqs.find_by_user(i)
			if not irq:
				unprocessed.append(i)
				continue
			try:
				irq = int(irq)
			except:
				unprocessed.append(i)
				continue

		if spread:
			new_affinity = [cpus[cpu_idx]]
			cpu_idx += 1
			if cpu_idx == nr_cpus:
				cpu_idx = 0

		bitmasklist = procfs.hexbitmask(new_affinity, last_cpu)
		set_irq_affinity(irq, bitmasklist)
		changed += 1
		pid = ps.find_by_name("IRQ-%d" % irq)
		if pid:
			pid = int(pid[0])
			try:
				schedutils.set_affinity(pid, new_affinity)
			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)
Exemple #10
0
def irq_mapper(s):
	global irqs
	try:
		return [ int(s), ]
	except:
		pass
	if not irqs:
		irqs = procfs.interrupts()

	irq_list_str = irqs.find_by_user_regex(re.compile(fnmatch.translate(s)))
	irq_list = []
	for i in irq_list_str:
		try:
			irq_list.append(int(i))
		except:
			pass

	return irq_list
Exemple #11
0
def irq_mapper(s):
    global irqs
    try:
        return [int(s)]
    except:
        pass
    if not irqs:
        irqs = procfs.interrupts()

    irq_list_str = irqs.find_by_user_regex(re.compile(fnmatch.translate(s)))
    irq_list = []
    for i in irq_list_str:
        try:
            irq_list.append(int(i))
        except:
            pass

    return irq_list
Exemple #12
0
    def _verify_all_irq_affinity(self, correct_affinity):
        irqs = procfs.interrupts()
        res = True
        for irq in irqs.keys():
            try:
                current_affinity = irqs[irq]["affinity"]
                log.debug("Read SMP affinity of IRQ '%s': '%s'" %
                          (irq, current_affinity))
                irq_description = "SMP affinity of IRQ %s" % irq
                if not self._verify_irq_affinity(
                        irq_description, correct_affinity, current_affinity):
                    res = False
            except KeyError:
                continue

        current_affinity_hex = self._cmd.read_file(
            "/proc/irq/default_smp_affinity")
        current_affinity = self._cmd.hex2cpulist(current_affinity_hex)
        if not self._verify_irq_affinity("default IRQ SMP affinity",
                                         current_affinity, correct_affinity):
            res = False
        return res
Exemple #13
0
def print_irqs_used_by_network_interface_cards(irq_list, cpu_list):
    irqs = procfs.interrupts()

    if sys.stdout.isatty():
        print("%4s %8s %-25s  %-10s" %
              ("IRQ", "CPU-lcore", "NIC-TxRx-Queue", "NIC-driver"))
    sorted_irqs = []
    for k in list(irqs.keys()):
        try:
            irqn = int(k)
            affinity = irqs[irqn]["affinity"]
        except:
            continue
        if irq_list and irqn not in irq_list:
            continue

        if cpu_list and not set(cpu_list).intersection(set(affinity)):
            continue
        sorted_irqs.append(irqn)

    sorted_irqs.sort()
    for irq in sorted_irqs:
        affinity = format_affinity(irqs[irq]["affinity"])
        users = irqs[irq]["users"]
        is_nic = False
        for i in users:
            # 网卡IRQ名称必定以en开头或eth开头
            is_nic = i.startswith("en") or i.startswith("eth") or i.startswith(
                "i40e-")
            if is_nic:
                break
        if not is_nic:
            continue
        print("%4d %8s  %-25s" % (irq, affinity, ",".join(users)), end=' ')
        drivers = find_drivers_by_users(users)
        if drivers:
            print(" %-10s" % ",".join(drivers))
        else:
            print()
Exemple #14
0
    def __init__(self,
                 show_kthreads=True,
                 show_uthreads=True,
                 cpus_filtered=[]):
        global tuna_glade

        (app, localedir) = ('tuna', '/usr/share/locale')
        gtk.glade.bindtextdomain(app, localedir)
        gtk.glade.textdomain(app)

        if self.check_root():
            sys.exit(1)
        for dir in tuna_glade_dirs:
            tuna_glade = "%s/tuna_gui.glade" % dir
            if os.access(tuna_glade, os.F_OK):
                break
        self.wtree = gtk.glade.XML(tuna_glade, "mainbig_window", "tuna")
        self.ps = procfs.pidstats()
        self.irqs = procfs.interrupts()
        self.window = self.wtree.get_widget("mainbig_window")

        self.procview = procview(self.wtree.get_widget("processlist"), self.ps,
                                 show_kthreads, show_uthreads, cpus_filtered,
                                 tuna_glade)
        self.irqview = irqview(self.wtree.get_widget("irqlist"), self.irqs,
                               self.ps, cpus_filtered, tuna_glade)
        self.cpuview = cpuview(self.wtree.get_widget("vpaned1"),
                               self.wtree.get_widget("hpaned2"),
                               self.wtree.get_widget("cpuview"), self.procview,
                               self.irqview, cpus_filtered)

        self.config = Config()
        self.check_env()
        self.commonview = commonview()
        self.commonview.contentTable = self.wtree.get_widget("commonTbl")
        self.commonview.configFileCombo = self.wtree.get_widget(
            "profileSelector")

        self.profileview = profileview()
        self.profileview.config = self.config
        self.commonview.config = self.config
        self.profileview.commonview = self.commonview
        self.commonview.profileview = self.profileview

        self.profileview.setWtree(self.wtree)
        self.profileview.init_default_file()

        event_handlers = {
            "on_mainbig_window_delete_event":
            self.on_mainbig_window_delete_event,
            "on_processlist_button_press_event":
            self.procview.on_processlist_button_press_event,
            "on_irqlist_button_press_event":
            self.irqview.on_irqlist_button_press_event,
            "on_loadProfileButton_clicked":
            self.profileview.on_loadProfileButton_clicked,
            "on_SaveButton_clicked":
            self.profileview.on_SaveButton_clicked,
            "on_UpdateButton_clicked":
            self.profileview.on_UpdateButton_clicked,
            "on_applyChanges_clicked":
            self.commonview.on_applyChanges_clicked,
            "on_undoChanges_clicked":
            self.commonview.on_undoChanges_clicked,
            "on_saveSnapshot_clicked":
            self.commonview.on_saveSnapshot_clicked,
            "on_saveTunedChanges_clicked":
            self.commonview.on_saveTunedChanges_clicked,
            "on_profileSelector_changed":
            self.commonview.on_profileSelector_changed,
            "on_profileTree_button_press_event":
            self.profileview.on_profileTree_button_press_event
        }

        self.wtree.signal_autoconnect(event_handlers)

        self.ps.reload_threads()
        self.show()
        self.timer = gobject.timeout_add(2500, self.refresh)
        try:
            self.icon = gtk.status_icon_new_from_stock(gtk.STOCK_PREFERENCES)
            self.icon.connect("activate", self.on_status_icon_activate)
            self.icon.connect("popup-menu", self.on_status_icon_popup_menu)
        except AttributeError:
            # Old pygtk2
            pass
        pixbuf = self.window.render_icon(gtk.STOCK_PREFERENCES,
                                         gtk.ICON_SIZE_SMALL_TOOLBAR)
        self.window.set_icon(pixbuf)
Exemple #15
0
                ps[pid]["status"]["voluntary_ctxt_switches"])
            nonvoluntary_ctxt_switches = int(
                ps[pid]["status"]["nonvoluntary_ctxt_switches"])
        except:
            voluntary_ctxt_switches = -1
            nonvoluntary_ctxt_switches = -1
        print "%5d %6s %5d %8s %9d %12s %15s %s" % (
            pid, sched, rtprio, thread_affinity, voluntary_ctxt_switches,
            nonvoluntary_ctxt_switches, cmd, users)


if __name__ == '__main__':

    ps = procfs.pidstats()
    cpuinfo = procfs.cpuinfo()
    irqs = procfs.interrupts()

    show_header()
    show(ps, cpuinfo, irqs)

    try:
        interval = int(sys.argv[1])
        while True:
            time.sleep(interval)
            ps.reload()

            show_header()
            show(ps, cpuinfo, irqs)
    except:
        pass
Exemple #16
0
				irq_affinity = ",".join("0x%x" % a for a in procfs.hexbitmask(irq_affinity_list, irqs.nr_cpus))
		except:
			irq_affinity = ""
		events = reduce(lambda a, b: a + b, info["cpu"])
		users = info["users"]
		for u in users:
			if u in nics:
				users[users.index(u)] = "%s(%s)" % (u, ethtool.get_module(u))
		print "%5d: %5d %5d %11d %8s %8s %s" % (irq, pid, rtprio,
							events, thread_affinity,
						        irq_affinity,
						        ",".join(users))

if __name__ == '__main__':

	irqs = procfs.interrupts()
	ps = procfs.pidstats()

	show_header()
	show(irqs, ps)

	try:
		interval = int(sys.argv[1])
		while True:
			time.sleep(interval)
			irqs.reload()
			ps.reload()

			show_header()
			show(irqs, ps)
	except:
Exemple #17
0
def include_cpus(cpus, nr_cpus):
	ps = procfs.pidstats()
	ps.reload_threads()
	previous_pid_affinities = {}
	for pid in ps.keys():
		if iskthread(pid):
			continue
		try:
			affinity = schedutils.get_affinity(pid)
		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) 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
		threads = ps[pid]["threads"]
		for tid in threads.keys():
			if iskthread(tid):
				continue
			try:
				affinity = schedutils.get_affinity(tid)
			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) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
					if e[0] == 3:
						continue
					raise e

	del ps

	# Now include it in IRQs too
	irqs = procfs.interrupts()
	previous_irq_affinities = {}
	for irq in irqs.keys():
		# LOC, NMI, TLB, etc
		if not irqs[irq].has_key("affinity"):
			continue
		affinity = irqs[irq]["affinity"]
		if set(affinity).intersection(set(cpus)) != set(cpus):
			previous_irq_affinities[irq] = copy.copy(affinity)
			affinity = list(set(affinity + cpus))
			set_irq_affinity(int(irq),
					 procfs.hexbitmask(affinity, nr_cpus))

	return (previous_pid_affinities, previous_irq_affinities)
Exemple #18
0
def isolate_cpus(cpus, nr_cpus):
	ps = procfs.pidstats()
	ps.reload_threads()
	previous_pid_affinities = {}
	for pid in ps.keys():
		if cannot_set_affinity(ps, pid):
			continue
		try:
			affinity = schedutils.get_affinity(pid)
		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) 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
		threads = ps[pid]["threads"]
		for tid in threads.keys():
			if cannot_set_thread_affinity(ps, pid, tid):
				continue
			try:
				affinity = schedutils.get_affinity(tid)
			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) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
					if e[0] == 3:
						continue
					raise e

	del ps

	# Now isolate it from IRQs too
	irqs = procfs.interrupts()
	previous_irq_affinities = {}
	for irq in irqs.keys():
		# LOC, NMI, TLB, etc
		if not irqs[irq].has_key("affinity"):
			continue
		affinity = irqs[irq]["affinity"]
		if set(affinity).intersection(set(cpus)):
			previous_irq_affinities[irq] = copy.copy(affinity)
			affinity = affinity_remove_cpus(affinity, cpus, nr_cpus)
			set_irq_affinity(int(irq),
					 procfs.hexbitmask(affinity,
							   nr_cpus))

	affinity = parse_irq_affinity_filename("default_smp_affinity", nr_cpus)
	affinity = affinity_remove_cpus(affinity, cpus, nr_cpus)
	set_irq_affinity_filename("default_smp_affinity", procfs.hexbitmask(affinity, nr_cpus))

	return (previous_pid_affinities, previous_irq_affinities)
Exemple #19
0
	def __init__(self, show_kthreads = True, show_uthreads = True, cpus_filtered = []):
		global tuna_glade

		(app, localedir) = ('tuna', '/usr/share/locale')
		gtk.glade.bindtextdomain(app, localedir)
		gtk.glade.textdomain(app)

		if self.check_root():
			sys.exit(1)
		for dir in tuna_glade_dirs:
			tuna_glade = "%s/tuna_gui.glade" % dir
			if os.access(tuna_glade, os.F_OK):
				break
		self.wtree = gtk.glade.XML(tuna_glade, "mainbig_window", "tuna")
		self.ps = procfs.pidstats()
		self.irqs = procfs.interrupts()
		self.window = self.wtree.get_widget("mainbig_window")

		self.procview = procview(self.wtree.get_widget("processlist"),
					 self.ps, show_kthreads, show_uthreads,
					 cpus_filtered, tuna_glade)
		self.irqview = irqview(self.wtree.get_widget("irqlist"),
				       self.irqs, self.ps, cpus_filtered,
				       tuna_glade)
		self.cpuview = cpuview(self.wtree.get_widget("vpaned1"),
				       self.wtree.get_widget("hpaned2"),
				       self.wtree.get_widget("cpuview"),
				       self.procview, self.irqview, cpus_filtered)

		self.config = Config()
		self.check_env()
		self.commonview = commonview()
		self.commonview.contentTable = self.wtree.get_widget("commonTbl")
		self.commonview.configFileCombo = self.wtree.get_widget("profileSelector")

		self.profileview = profileview()
		self.profileview.config = self.config
		self.commonview.config = self.config
		self.profileview.commonview = self.commonview
		self.commonview.profileview = self.profileview

		self.profileview.setWtree(self.wtree)
		self.profileview.init_default_file()

		event_handlers = { "on_mainbig_window_delete_event"		: self.on_mainbig_window_delete_event,
					"on_processlist_button_press_event"			: self.procview.on_processlist_button_press_event,
					"on_irqlist_button_press_event"				: self.irqview.on_irqlist_button_press_event,
					"on_loadProfileButton_clicked"				: self.profileview.on_loadProfileButton_clicked,
					"on_SaveButton_clicked"						: self.profileview.on_SaveButton_clicked,
					"on_UpdateButton_clicked"					: self.profileview.on_UpdateButton_clicked,
					"on_applyChanges_clicked"					: self.commonview.on_applyChanges_clicked,
					"on_undoChanges_clicked"					: self.commonview.on_undoChanges_clicked,
					"on_saveSnapshot_clicked"					: self.commonview.on_saveSnapshot_clicked,
					"on_saveTunedChanges_clicked"				: self.commonview.on_saveTunedChanges_clicked,
					"on_profileSelector_changed"				: self.commonview.on_profileSelector_changed,
					"on_profileTree_button_press_event"			: self.profileview.on_profileTree_button_press_event
		}
	
		self.wtree.signal_autoconnect(event_handlers)

		self.ps.reload_threads()
		self.show()
		self.timer = gobject.timeout_add(2500, self.refresh)
		try:
			self.icon = gtk.status_icon_new_from_stock(gtk.STOCK_PREFERENCES)
			self.icon.connect("activate", self.on_status_icon_activate)
			self.icon.connect("popup-menu", self.on_status_icon_popup_menu)
		except AttributeError:
			# Old pygtk2
			pass
		pixbuf = self.window.render_icon(gtk.STOCK_PREFERENCES,
						 gtk.ICON_SIZE_SMALL_TOOLBAR)
		self.window.set_icon(pixbuf)