From 068928e47b506267d8fc8a728299208c498509e1 Mon Sep 17 00:00:00 2001 From: Mario Limonciello Date: Fri, 21 Jun 2024 15:12:39 -0500 Subject: [PATCH] Add support for controlling amd-pstate core performance boost Core performance boost control is added to kernel 6.11. This sets up the policy to turn it off while in the power saver profile. Link: https://lore.kernel.org/linux-pm/1a78eeaa-fadd-4734-aaeb-2fe11e96e198@amd.com/T/#m4a0c8917ea8fb033504055bd61512c80c85410c8 --- profiles/balanced-battery/tuned.conf | 1 + profiles/balanced/tuned.conf | 1 + profiles/powersave/tuned.conf | 1 + tuned/plugins/plugin_cpu.py | 39 ++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+) diff --git a/profiles/balanced-battery/tuned.conf b/profiles/balanced-battery/tuned.conf index 192957e..3921103 100644 --- a/profiles/balanced-battery/tuned.conf +++ b/profiles/balanced-battery/tuned.conf @@ -8,6 +8,7 @@ include=balanced [cpu] energy_performance_preference=balance_power +boost=1 [video] panel_power_savings=1 diff --git a/profiles/balanced/tuned.conf b/profiles/balanced/tuned.conf index 78f28d4..feb7e5b 100644 --- a/profiles/balanced/tuned.conf +++ b/profiles/balanced/tuned.conf @@ -13,6 +13,7 @@ priority=10 governor=conservative|powersave energy_perf_bias=normal energy_performance_preference=balance_performance +boost=1 [acpi] platform_profile=balanced diff --git a/profiles/powersave/tuned.conf b/profiles/powersave/tuned.conf index 17dff1f..3c35280 100644 --- a/profiles/powersave/tuned.conf +++ b/profiles/powersave/tuned.conf @@ -9,6 +9,7 @@ summary=Optimize for low power consumption governor=ondemand|powersave energy_perf_bias=powersave|power energy_performance_preference=power +boost=0 [acpi] platform_profile=low-power|quiet diff --git a/tuned/plugins/plugin_cpu.py b/tuned/plugins/plugin_cpu.py index 767e68c..50ccef4 100644 --- a/tuned/plugins/plugin_cpu.py +++ b/tuned/plugins/plugin_cpu.py @@ -186,6 +186,10 @@ class CPULatencyPlugin(hotplug.Plugin): pm_qos_resume_latency_us=100 ---- Allows any C-state with a resume latency less than value. + [cpu] + boost=1 + ---- + CPU is allowed to boost above nominal frequencies for short periods of time. """ def __init__(self, *args, **kwargs): @@ -237,6 +241,7 @@ class CPULatencyPlugin(hotplug.Plugin): "no_turbo" : None, "pm_qos_resume_latency_us": None, "energy_performance_preference" : None, + "boost": None, } def _check_arch(self): @@ -603,6 +608,9 @@ class CPULatencyPlugin(hotplug.Plugin): return_err = True) return (retcode, err_msg) + def _pstate_boost_path(self, cpu_id): + return "/sys/devices/system/cpu/cpufreq/policy%s/boost" % cpu_id + def _pstate_preference_path(self, cpu_id, available = False): return "/sys/devices/system/cpu/cpufreq/policy%s/energy_performance_%s" % (cpu_id, "available_preferences" if available else "preference") @@ -748,6 +756,37 @@ class CPULatencyPlugin(hotplug.Plugin): return None return self._cmd.read_file(self._pm_qos_resume_latency_us_path(device), no_error=ignore_missing).strip() + @command_set("boost", per_device=True) + def _set_boost(self, boost, device, sim, remove): + if not self._is_cpu_online(device): + log.debug("%s is not online, skipping" % device) + return None + cpu_id = device.lstrip("cpu") + if os.path.exists(self._pstate_boost_path(cpu_id)): + if not sim: + if boost == "0" or boost == "1": + self._cmd.write_to_file(self._pstate_boost_path(cpu_id), boost, \ + no_error = [errno.ENOENT] if remove else False, ignore_same=True) + log.info("Setting boost value '%s' for cpu '%s'" % (boost, device)) + else: + log.error("Failed to set boost on cpu '%s'. Is the value in the profile correct?" % device) + return str(boost) + else: + log.debug("boost file missing, which can happen on pre 6.11 kernels.") + return None + + @command_get("boost") + def _get_boost(self, device, ignore_missing=False): + if not self._is_cpu_online(device): + log.debug("%s is not online, skipping" % device) + return None + cpu_id = device.lstrip("cpu") + if os.path.exists(self._pstate_boost_path(cpu_id)): + return self._cmd.read_file(self._pstate_boost_path(cpu_id)).strip() + else: + log.debug("boost file missing, which can happen on pre 6.11 kernels.") + return None + @command_set("energy_performance_preference", per_device=True) def _set_energy_performance_preference(self, energy_performance_preference, device, sim, remove): if not self._is_cpu_online(device):