From 3104141ff670ca2ff1d4cefb5705ce034137f098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Lyson=C4=9Bk?= Date: Sun, 13 May 2018 21:03:36 +0200 Subject: [PATCH 1/3] cpu: Fix verification of EPB on Linux 4.13+ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix verification of Energy Performance Bias on Linux 4.13+. In Linux 4.13, the value strings accepted by the x86_energy_perf_policy program changed. Resolves: rhbz#1508468 Signed-off-by: Ondřej Lysoněk --- tuned/plugins/plugin_cpu.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tuned/plugins/plugin_cpu.py b/tuned/plugins/plugin_cpu.py index 6a5ea36..30c5d63 100644 --- a/tuned/plugins/plugin_cpu.py +++ b/tuned/plugins/plugin_cpu.py @@ -282,9 +282,19 @@ class CPULatencyPlugin(base.Plugin): v = s return v + # Before Linux 4.13 def _energy_perf_policy_to_human(self, s): return {0:"performance", 6:"normal", 15:"powersave"}.get(self._try_parse_num(s), s) + # Since Linux 4.13 + def _energy_perf_policy_to_human_v2(self, s): + return {0:"performance", + 4:"balance-performance", + 6:"normal", + 8:"balance-power", + 15:"power", + }.get(self._try_parse_num(s), s) + @command_get("energy_perf_bias") def _get_energy_perf_bias(self, device, ignore_missing=False): energy_perf_bias = None @@ -300,5 +310,8 @@ class CPULatencyPlugin(base.Plugin): if len(l) == 2: energy_perf_bias = self._energy_perf_policy_to_human(l[1]) break + elif len(l) == 3: + energy_perf_bias = self._energy_perf_policy_to_human_v2(l[2]) + break return energy_perf_bias From 07159dfb0a73fb7cf9c6bc57649d636390b319a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Lyson=C4=9Bk?= Date: Sun, 13 May 2018 21:09:04 +0200 Subject: [PATCH 2/3] cpu: Support specifying alternative EPB values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Support specifying alternative Energy Performance Bias values. The values are separated using the '|' character. For example, if you have the following in your profile: [cpu] energy_perf_bias=powersave|power then tuned will try to set EPB to 'powersave', and if that fails, it will try to set it to 'power'. Resolves: rhbz#1508468 Signed-off-by: Ondřej Lysoněk --- tuned/plugins/base.py | 7 +++++++ tuned/plugins/plugin_cpu.py | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/tuned/plugins/base.py b/tuned/plugins/base.py index b9cf04c..a3c9814 100644 --- a/tuned/plugins/base.py +++ b/tuned/plugins/base.py @@ -515,6 +515,13 @@ class Plugin(object): ret = int(new_value, 16) == int(current_value, 16) except ValueError: ret = str(new_value) == str(current_value) + if not ret: + vals = str(new_value).split('|') + for val in vals: + val = val.strip() + ret = val == current_value + if ret: + break if ret: if device is None: log.info(consts.STR_VERIFY_PROFILE_VALUE_OK % (name, str(current_value).strip())) diff --git a/tuned/plugins/plugin_cpu.py b/tuned/plugins/plugin_cpu.py index 30c5d63..8f0babd 100644 --- a/tuned/plugins/plugin_cpu.py +++ b/tuned/plugins/plugin_cpu.py @@ -258,6 +258,15 @@ class CPULatencyPlugin(base.Plugin): return None return self._cmd.read_file(path).strip() + def _try_set_energy_perf_bias(self, cpu_id, value): + (retcode, out, err_msg) = self._cmd.execute( + ["x86_energy_perf_policy", + "-c", cpu_id, + str(value) + ], + return_err = True) + return (retcode, err_msg) + @command_set("energy_perf_bias", per_device=True) def _set_energy_perf_bias(self, energy_perf_bias, device, sim): if not self._is_cpu_online(device): @@ -266,8 +275,27 @@ class CPULatencyPlugin(base.Plugin): if self._has_energy_perf_bias: if not sim: cpu_id = device.lstrip("cpu") - log.info("setting energy_perf_bias '%s' on cpu '%s'" % (energy_perf_bias, device)) - self._cmd.execute(["x86_energy_perf_policy", "-c", cpu_id, str(energy_perf_bias)]) + vals = energy_perf_bias.split('|') + for val in vals: + val = val.strip() + log.debug("Trying to set energy_perf_bias to '%s' on cpu '%s'" + % (val, device)) + (retcode, err_msg) = self._try_set_energy_perf_bias( + cpu_id, val) + if retcode == 0: + log.info("energy_perf_bias successfully set to '%s' on cpu '%s'" + % (val, device)) + break + elif retcode < 0: + log.error("Failed to set energy_perf_bias: %s" + % err_msg) + break + else: + log.debug("Could not set energy_perf_bias to '%s' on cpu '%s', trying another value" + % (val, device)) + else: + log.error("Failed to set energy_perf_bias on cpu '%s'. Is the value in the profile correct?" + % device) return str(energy_perf_bias) else: return None From 726ea77b7020cb5bfb42d16652c0191fc3d8eca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Lyson=C4=9Bk?= Date: Sun, 13 May 2018 21:29:24 +0200 Subject: [PATCH 3/3] Use value powersave|power for EPB in powersave profile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since Linux 4.13 the value "powersave" in the x86_energy_perf_policy program has been renamed to "power". Let's try both values when applying the powersave profile. Resolves: rhbz#1508468 Signed-off-by: Ondřej Lysoněk --- profiles/powersave/tuned.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/profiles/powersave/tuned.conf b/profiles/powersave/tuned.conf index cd2c8ca..660362f 100644 --- a/profiles/powersave/tuned.conf +++ b/profiles/powersave/tuned.conf @@ -7,7 +7,7 @@ summary=Optimize for low power consumption [cpu] governor=ondemand -energy_perf_bias=power +energy_perf_bias=powersave|power [eeepc_she]