From: Sumit Gupta <sumitg@nvidia.com>
To: <rafael@kernel.org>, <viresh.kumar@linaro.org>, <lenb@kernel.org>,
<robert.moore@intel.com>, <corbet@lwn.net>,
<pierre.gondois@arm.com>, <zhenglifeng1@huawei.com>,
<ray.huang@amd.com>, <gautham.shenoy@amd.com>,
<mario.limonciello@amd.com>, <perry.yuan@amd.com>,
<linux-pm@vger.kernel.org>, <linux-acpi@vger.kernel.org>,
<linux-doc@vger.kernel.org>, <acpica-devel@lists.linux.dev>,
<linux-kernel@vger.kernel.org>
Cc: <linux-tegra@vger.kernel.org>, <treding@nvidia.com>,
<jonathanh@nvidia.com>, <vsethi@nvidia.com>,
<ksitaraman@nvidia.com>, <sanjayc@nvidia.com>, <bbasu@nvidia.com>,
<sumitg@nvidia.com>
Subject: [PATCH v2 5/7] cpufreq: CPPC: update policy min/max when toggling auto_select
Date: Sun, 24 Aug 2025 01:31:18 +0530 [thread overview]
Message-ID: <20250823200121.1320197-6-sumitg@nvidia.com> (raw)
In-Reply-To: <20250823200121.1320197-1-sumitg@nvidia.com>
When CPPC autonomous selection (auto_select) is enabled or disabled,
the policy min/max frequency limits should be updated appropriately to
reflect the new operating mode.
Currently, toggling auto_select only changes the hardware register but
doesn't update the cpufreq policy constraints, which can lead to
inconsistent behavior between the hardware state and the policy limits
visible to userspace and other kernel components.
When auto_select is enabled, preserve the current min/max performance
values to maintain user-configured limits. When disabled, the hardware
operates in a default mode where the OS directly controls performance,
so update the policy limits accordingly.
Signed-off-by: Sumit Gupta <sumitg@nvidia.com>
---
drivers/cpufreq/cppc_cpufreq.c | 47 ++++++++++++++++++++++++++++++++--
1 file changed, 45 insertions(+), 2 deletions(-)
diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c
index d9aae1ec26e1..5e1bbb5f67b8 100644
--- a/drivers/cpufreq/cppc_cpufreq.c
+++ b/drivers/cpufreq/cppc_cpufreq.c
@@ -880,6 +880,10 @@ static ssize_t show_auto_select(struct cpufreq_policy *policy, char *buf)
static ssize_t store_auto_select(struct cpufreq_policy *policy,
const char *buf, size_t count)
{
+ struct cppc_cpudata *cpu_data = policy->driver_data;
+ unsigned int cpu = policy->cpu;
+ bool update_reg = false;
+ u32 min_perf, max_perf;
bool val;
int ret;
@@ -887,9 +891,48 @@ static ssize_t store_auto_select(struct cpufreq_policy *policy,
if (ret)
return ret;
- ret = cppc_set_auto_sel(policy->cpu, val);
- if (ret)
+ mutex_lock(&cppc_cpufreq_update_autosel_config_lock);
+ if (val) {
+ /* Enabling auto_select: set current user-configured limits */
+ min_perf = cpu_data->perf_ctrls.min_perf;
+ max_perf = cpu_data->perf_ctrls.max_perf;
+ update_reg = true;
+ } else {
+ /*
+ * Disabling auto_select: set defaults for OS control.
+ * Use lowest_nonlinear_perf as minimum to avoid very low frequencies
+ * and nominal_perf as maximum for balanced operation.
+ */
+ min_perf = cpu_data->perf_caps.lowest_nonlinear_perf;
+ max_perf = cpu_data->perf_caps.nominal_perf;
+ }
+
+ ret = cppc_set_auto_sel(cpu, val);
+ if (ret) {
+ pr_warn("failed to set auto_sel for cpu:%d (%d)\n", cpu, ret);
+ mutex_unlock(&cppc_cpufreq_update_autosel_config_lock);
+ return ret;
+ }
+ cpu_data->perf_caps.auto_sel = val;
+ mutex_unlock(&cppc_cpufreq_update_autosel_config_lock);
+
+ /*
+ * On enabling auto_select: set min/max_perf register and update policy.
+ * On disabling auto_select: update only policy.
+ */
+ ret = cppc_cpufreq_set_min_perf(policy, min_perf, update_reg, true);
+ if (ret) {
+ pr_warn("failed to %s update min policy for cpu:%d (%d)\n",
+ val > 0 ? "set min_perf and" : "", cpu, ret);
return ret;
+ }
+
+ ret = cppc_cpufreq_set_max_perf(policy, max_perf, update_reg, true);
+ if (ret) {
+ pr_warn("failed to %s update max policy for cpu:%d (%d)\n",
+ val > 0 ? "set max_perf and" : "", cpu, ret);
+ return ret;
+ }
return count;
}
--
2.34.1
next prev parent reply other threads:[~2025-08-23 20:02 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-23 20:01 [PATCH v2 0/7] Enhanced autonomous selection and API Sumit Gupta
2025-08-23 20:01 ` [PATCH v2 1/7] ACPI: CPPC: add perf control read API and clarify naming Sumit Gupta
2025-08-25 18:33 ` Rafael J. Wysocki
2025-09-01 13:46 ` Sumit Gupta
2025-09-01 19:00 ` Rafael J. Wysocki
2025-08-25 23:41 ` kernel test robot
2025-08-23 20:01 ` [PATCH v2 2/7] ACPI: CPPC: extend APIs to support auto_sel and epp Sumit Gupta
2025-08-23 20:01 ` [PATCH v2 3/7] ACPI: CPPC: add APIs and sysfs interface for min/max_perf Sumit Gupta
2025-08-23 20:01 ` [PATCH v2 4/7] ACPI: CPPC: add APIs and sysfs interface for perf_limited register Sumit Gupta
2025-08-23 20:01 ` Sumit Gupta [this message]
2025-08-23 20:01 ` [PATCH v2 6/7] cpufreq: CPPC: Add sysfs for min/max_perf and perf_limited Sumit Gupta
2025-08-24 0:08 ` Randy Dunlap
2025-09-01 13:12 ` Sumit Gupta
2025-08-23 20:01 ` [PATCH v2 7/7] cpufreq: CPPC: add autonomous mode boot parameter support Sumit Gupta
2025-08-24 0:08 ` Randy Dunlap
2025-09-01 13:18 ` Sumit Gupta
2025-08-25 18:40 ` Mario Limonciello
2025-09-01 13:37 ` Sumit Gupta
2025-09-02 19:48 ` Mario Limonciello
2025-09-04 12:01 ` Sumit Gupta
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250823200121.1320197-6-sumitg@nvidia.com \
--to=sumitg@nvidia.com \
--cc=acpica-devel@lists.linux.dev \
--cc=bbasu@nvidia.com \
--cc=corbet@lwn.net \
--cc=gautham.shenoy@amd.com \
--cc=jonathanh@nvidia.com \
--cc=ksitaraman@nvidia.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=mario.limonciello@amd.com \
--cc=perry.yuan@amd.com \
--cc=pierre.gondois@arm.com \
--cc=rafael@kernel.org \
--cc=ray.huang@amd.com \
--cc=robert.moore@intel.com \
--cc=sanjayc@nvidia.com \
--cc=treding@nvidia.com \
--cc=viresh.kumar@linaro.org \
--cc=vsethi@nvidia.com \
--cc=zhenglifeng1@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®