SILENT KILLERPanel

Current Path: > > usr > lib > python3.6 > site-packages > tuned > plugins


Operation   : Linux host59.registrar-servers.com 4.18.0-513.18.1.lve.2.el8.x86_64 #1 SMP Sat Mar 30 15:36:11 UTC 2024 x86_64
Software     : Apache
Server IP    : 198.54.126.42 | Your IP: 216.73.216.8
Domains      : 1034 Domain(s)
Permission   : [ 0755 ]

Files and Folders in: //usr/lib/python3.6/site-packages/tuned/plugins

NameTypeSizeLast ModifiedActions
__pycache__ Directory - -
instance Directory - -
__init__.py File 49 bytes February 22 2024 12:23:28.
base.py File 22417 bytes February 22 2024 12:23:28.
decorators.py File 983 bytes February 22 2024 12:23:28.
exceptions.py File 99 bytes February 22 2024 12:23:28.
hotplug.py File 3928 bytes February 22 2024 12:23:28.
plugin_acpi.py File 2446 bytes February 22 2024 12:23:28.
plugin_audio.py File 3209 bytes February 22 2024 12:23:28.
plugin_bootloader.py File 25914 bytes February 22 2024 12:23:28.
plugin_cpu.py File 28218 bytes February 22 2024 12:23:28.
plugin_disk.py File 17049 bytes March 11 2025 07:42:24.
plugin_eeepc_she.py File 2947 bytes February 22 2024 12:23:28.
plugin_irqbalance.py File 3554 bytes February 22 2024 12:23:28.
plugin_modules.py File 4925 bytes February 22 2024 12:23:28.
plugin_mounts.py File 5580 bytes February 22 2024 12:23:28.
plugin_net.py File 23252 bytes February 22 2024 12:23:28.
plugin_rtentsk.py File 1109 bytes February 22 2024 12:23:28.
plugin_scheduler.py File 56255 bytes February 22 2024 12:23:28.
plugin_script.py File 3852 bytes February 22 2024 12:23:28.
plugin_scsi_host.py File 3153 bytes February 22 2024 12:23:28.
plugin_selinux.py File 2320 bytes February 22 2024 12:23:28.
plugin_service.py File 10721 bytes February 22 2024 12:23:28.
plugin_sysctl.py File 6906 bytes February 22 2024 12:23:28.
plugin_sysfs.py File 2694 bytes February 22 2024 12:23:28.
plugin_systemd.py File 5428 bytes February 22 2024 12:23:28.
plugin_uncore.py File 4723 bytes February 22 2024 12:23:28.
plugin_usb.py File 2015 bytes February 22 2024 12:23:28.
plugin_video.py File 3807 bytes February 22 2024 12:23:28.
plugin_vm.py File 3561 bytes February 22 2024 12:23:28.
repository.py File 1530 bytes February 22 2024 12:23:28.

Reading File: //usr/lib/python3.6/site-packages/tuned/plugins/plugin_irqbalance.py

from . import base
from .decorators import command_custom
from tuned import consts
import tuned.logs
import errno
import perf
import re

log = tuned.logs.get()

class IrqbalancePlugin(base.Plugin):
	"""
	`irqbalance`::
	
	Plug-in for irqbalance settings management. The plug-in
	configures CPUs which should be skipped when rebalancing IRQs in
	`/etc/sysconfig/irqbalance`. It then restarts irqbalance if and
	only if it was previously running.
	+
	The banned/skipped CPUs are specified as a CPU list via the
	[option]`banned_cpus` option.
	+
	.Skip CPUs 2,4 and 9-13 when rebalancing IRQs
	====
	----
	[irqbalance]
	banned_cpus=2,4,9-13
	----
	====
	"""

	def __init__(self, *args, **kwargs):
		super(IrqbalancePlugin, self).__init__(*args, **kwargs)
		self._cpus = perf.cpu_map()

	def _instance_init(self, instance):
		instance._has_dynamic_tuning = False
		instance._has_static_tuning = True

	def _instance_cleanup(self, instance):
		pass

	@classmethod
	def _get_config_options(cls):
		return {
			"banned_cpus": None,
		}

	def _read_irqbalance_sysconfig(self):
		try:
			with open(consts.IRQBALANCE_SYSCONFIG_FILE, "r") as f:
				return f.read()
		except IOError as e:
			if e.errno == errno.ENOENT:
				log.warn("irqbalance sysconfig file is missing. Is irqbalance installed?")
			else:
				log.error("Failed to read irqbalance sysconfig file: %s" % e)
			return None

	def _write_irqbalance_sysconfig(self, content):
		try:
			with open(consts.IRQBALANCE_SYSCONFIG_FILE, "w") as f:
				f.write(content)
			return True
		except IOError as e:
			log.error("Failed to write irqbalance sysconfig file: %s" % e)
			return False

	def _write_banned_cpus(self, sysconfig, banned_cpumask):
		return sysconfig + "IRQBALANCE_BANNED_CPUS=%s\n" % banned_cpumask

	def _clear_banned_cpus(self, sysconfig):
		lines = []
		for line in sysconfig.split("\n"):
			if not re.match(r"\s*IRQBALANCE_BANNED_CPUS=", line):
				lines.append(line)
		return "\n".join(lines)

	def _restart_irqbalance(self):
		# Exit code 5 means unit not found (see 'EXIT_NOTINSTALLED' in
		# systemd.exec(5))
		retcode, out = self._cmd.execute(
			["systemctl", "try-restart", "irqbalance"],
			no_errors=[5])
		if retcode != 0:
			log.warn("Failed to restart irqbalance. Is it installed?")

	def _set_banned_cpus(self, banned_cpumask):
		content = self._read_irqbalance_sysconfig()
		if content is None:
			return
		content = self._clear_banned_cpus(content)
		content = self._write_banned_cpus(content, banned_cpumask)
		if self._write_irqbalance_sysconfig(content):
			self._restart_irqbalance()

	def _restore_banned_cpus(self):
		content = self._read_irqbalance_sysconfig()
		if content is None:
			return
		content = self._clear_banned_cpus(content)
		if self._write_irqbalance_sysconfig(content):
			self._restart_irqbalance()

	@command_custom("banned_cpus", per_device=False)
	def _banned_cpus(self, enabling, value, verify, ignore_missing):
		banned_cpumask = None
		if value is not None:
			banned = set(self._cmd.cpulist_unpack(value))
			present = set(self._cpus)
			if banned.issubset(present):
				banned_cpumask = self._cmd.cpulist2hex(list(banned))
			else:
				str_cpus = ",".join([str(x) for x in self._cpus])
				log.error("Invalid banned_cpus specified, '%s' does not match available cores '%s'"
					  % (value, str_cpus))

		if (enabling or verify) and banned_cpumask is None:
			return None
		if verify:
			# Verification is currently not supported
			return None
		elif enabling:
			self._set_banned_cpus(banned_cpumask)
		else:
			self._restore_banned_cpus()

SILENT KILLER Tool