From 1183333c5229d89e47bbc8a513a60537ccbe02bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavol=20=C5=BD=C3=A1=C4=8Dik?= Date: Thu, 11 Jan 2024 11:02:08 +0100 Subject: [PATCH] plugin_cpu: Support cstate settings of `pm_qos_resume_latency_us` The `force_latency` option already supports using C-state IDs/names. This commit extends the support to the `pm_qos_resume_latency_us` option, together with the ability to set fallback values (including the special "n/a" value which disables all C-states). Resolves: RHEL-21129 --- tuned/plugins/plugin_cpu.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/tuned/plugins/plugin_cpu.py b/tuned/plugins/plugin_cpu.py index 4b90f408..a36aded3 100644 --- a/tuned/plugins/plugin_cpu.py +++ b/tuned/plugins/plugin_cpu.py @@ -458,7 +458,7 @@ def _get_latency_by_cstate_id(self, lid, no_zero=False): return latency # returns (latency, skip), skip means we want to skip latency settings - def _parse_latency(self, latency): + def _parse_latency(self, latency, allow_na=False): self.cstates_latency = None latencies = str(latency).split("|") log.debug("parsing latency") @@ -478,6 +478,8 @@ def _parse_latency(self, latency): elif latency in ["none", "None"]: log.debug("latency 'none' specified") return None, True + elif allow_na and latency == "n/a": + pass else: latency = None log.debug("invalid latency specified: '%s'" % str(latency)) @@ -717,18 +719,11 @@ def _set_pm_qos_resume_latency_us(self, pm_qos_resume_latency_us, device, sim, r if not self._is_cpu_online(device): log.debug("%s is not online, skipping" % device) return None - try: - latency = int(pm_qos_resume_latency_us) - log.debug("parsed directly specified latency value: %d" % latency) - if latency < 0: - raise ValueError - except ValueError: - if pm_qos_resume_latency_us == "n/a": - latency = pm_qos_resume_latency_us - else: - log.warning("Invalid latency specified: '%s'" % str(pm_qos_resume_latency_us)) - return None - if not self._check_pm_qos_resume_latency_us(device): + latency, skip = self._parse_latency(pm_qos_resume_latency_us, allow_na=True) + if skip or not self._check_pm_qos_resume_latency_us(device): + return None + if latency is None or (latency != "n/a" and latency < 0): + log.warning("Failed to set pm_qos_resume_latency_us on cpu '%s'. Is the value in the profile correct?" % device) return None if not sim: self._cmd.write_to_file(self._pm_qos_resume_latency_us_path(device), latency, \