File tuned_do_check_if_cpu_is_online.patch of Package tuned.7874

From: Jaroslav Škarvada <jskarvad@redhat.com>
Subject: plugin_cpu: skip offline CPUs
References: bsc#1093694
Patch-Mainline: v2.5.0
Git-commit: 516dc1c168847a58d4ed7d19f1875932860e3814
Git-repo: git://github.com/redhat-performance/tuned

Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>

Signed-off-by: Thomas Renninger <trenn@suse.com>

Index: tuned-2.4.1/tuned/plugins/plugin_cpu.py
===================================================================
--- tuned-2.4.1.orig/tuned/plugins/plugin_cpu.py	2018-06-27 15:34:46.198895619 +0200
+++ tuned-2.4.1/tuned/plugins/plugin_cpu.py	2018-06-27 15:38:04.245917430 +0200
@@ -72,6 +72,11 @@ class CPULatencyPlugin(base.Plugin):
 		if self._has_intel_pstate:
 			log.info("intel_pstate detected")
 
+	def _is_cpu_online(self, device):
+		sd = str(device)
+		# CPU0 is always online
+		return sd == "cpu0" or self._cmd.read_file("/sys/devices/system/cpu/%s/online" % sd).strip() == "1"
+
 	def _instance_init(self, instance):
 		instance._has_static_tuning = True
 		instance._has_dynamic_tuning = False
@@ -171,6 +176,9 @@ class CPULatencyPlugin(base.Plugin):
 
 	@command_set("governor", per_device=True)
 	def _set_governor(self, governor, device):
+		if not self._is_cpu_online(device):
+			log.debug("%s is not online, skipping" % device)
+			return None
 		if governor not in self._get_available_governors(device):
 			log.info("ignoring governor '%s' on cpu '%s', it is not supported" % (governor, device))
 			return
@@ -184,6 +192,9 @@ class CPULatencyPlugin(base.Plugin):
 	@command_get("governor")
 	def _get_governor(self, device):
 		governor = None
+		if not self._is_cpu_online(device):
+			log.debug("%s is not online, skipping" % device)
+			return None
 		if self._has_cpupower:
 			cpu_id = device.lstrip("cpu")
 			retcode, lines = self._cmd.execute(["cpupower", "-c", cpu_id, "frequency-info", "-p"])
@@ -208,6 +219,9 @@ class CPULatencyPlugin(base.Plugin):
 
 	@command_set("energy_perf_bias", per_device=True)
 	def _set_energy_perf_bias(self, energy_perf_bias, device):
+		if not self._is_cpu_online(device):
+			log.debug("%s is not online, skipping" % device)
+			return None
 		if self._has_cpupower is True:
 			bias_str = str(energy_perf_bias)
 			if bias_str == "performance":
@@ -226,6 +240,9 @@ class CPULatencyPlugin(base.Plugin):
 	@command_get("energy_perf_bias")
 	def _get_energy_perf_bias(self, device):
 		energy_perf_bias = None
+		if not self._is_cpu_online(device):
+			log.debug("%s is not online, skipping" % device)
+			return None
 		if self._has_cpupower is True:
 			cpu_id = device.lstrip("cpu")
 			retcode, lines = self._cmd.execute(["cpupower", "-c", cpu_id, "info", "-b"])
openSUSE Build Service is sponsored by