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] 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 6a5ea36..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 @@ -282,9 +310,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 +338,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