From: "zhenglifeng (A)" <zhenglifeng1@huawei.com>
To: Sumit Gupta <sumitg@nvidia.com>
Cc: <rafael@kernel.org>, <viresh.kumar@linaro.org>, <lenb@kernel.org>,
<robert.moore@intel.com>, <corbet@lwn.net>,
<pierre.gondois@arm.com>, <rdunlap@infradead.org>,
<ray.huang@amd.com>, <gautham.shenoy@amd.com>,
<mario.limonciello@amd.com>, <perry.yuan@amd.com>,
<ionela.voinescu@arm.com>, <zhanjie9@hisilicon.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>, <linux-tegra@vger.kernel.org>,
<treding@nvidia.com>, <jonathanh@nvidia.com>, <vsethi@nvidia.com>,
<ksitaraman@nvidia.com>, <sanjayc@nvidia.com>,
<nhartman@nvidia.com>, <bbasu@nvidia.com>
Subject: Re: [PATCH v5 09/11] cpufreq: CPPC: sync policy limits when toggling auto_select
Date: Thu, 15 Jan 2026 16:57:58 +0800 [thread overview]
Message-ID: <7e5bfa69-96e2-4f54-9446-cc64845b52cd@huawei.com> (raw)
In-Reply-To: <fb876f94-f92e-4c8a-9b64-fe9118a15595@nvidia.com>
On 2026/1/8 22:21, Sumit Gupta wrote:
>
> On 26/12/25 08:25, zhenglifeng (A) wrote:
>> External email: Use caution opening links or attachments
>>
>>
>> On 2025/12/23 20:13, Sumit Gupta wrote:
>>> 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.
>>>
>>> Add cppc_cpufreq_update_autosel_config() function to handle the
>>> auto_select toggle by syncing min/max_perf values with policy
>>> constraints. When enabling auto_sel, restore preserved min/max_perf
>>> values to policy limits. When disabling, reset policy to defaults
>>> while preserving hardware register values for later use.
>>>
>>> Signed-off-by: Sumit Gupta <sumitg@nvidia.com>
>>> ---
>>> drivers/cpufreq/cppc_cpufreq.c | 112 +++++++++++++++++++++++++++------
>>> 1 file changed, 92 insertions(+), 20 deletions(-)
>>>
>>> diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c
>>> index 0202c7b823e6..b1f570d6de34 100644
>>> --- a/drivers/cpufreq/cppc_cpufreq.c
>>> +++ b/drivers/cpufreq/cppc_cpufreq.c
>>> @@ -544,14 +544,20 @@ static void populate_efficiency_class(void)
>>> * cppc_cpufreq_set_mperf_limit - Set min/max performance limit
>>> * @policy: cpufreq policy
>>> * @val: performance value to set
>>> + * @update_reg: whether to update hardware register
>>> * @update_policy: whether to update policy constraints
>>> * @is_min: true for min_perf, false for max_perf
>>> *
>>> + * When @update_reg is true, writes to HW registers and preserves values.
>>> * When @update_policy is true, updates cpufreq policy frequency limits.
>>> + *
>>> + * @update_reg is false when disabling auto_sel to preserve HW values.
>>> + * The preserved value is used on next enabling of the autonomous mode.
>>> * @update_policy is false during cpu_init when policy isn't fully set up.
>>> */
>>> static int cppc_cpufreq_set_mperf_limit(struct cpufreq_policy *policy, u64 val,
>>> - bool update_policy, bool is_min)
>>> + bool update_reg, bool update_policy,
>>> + bool is_min)
>>> {
>>> struct cppc_cpudata *cpu_data = policy->driver_data;
>>> struct cppc_perf_caps *caps = &cpu_data->perf_caps;
>>> @@ -563,19 +569,22 @@ static int cppc_cpufreq_set_mperf_limit(struct cpufreq_policy *policy, u64 val,
>>>
>>> perf = clamp(val, caps->lowest_perf, caps->highest_perf);
>>>
>>> - ret = is_min ? cppc_set_min_perf(cpu, perf) :
>>> - cppc_set_max_perf(cpu, perf);
>>> - if (ret) {
>>> - if (ret != -EOPNOTSUPP)
>>> - pr_warn("Failed to set %s_perf (%llu) on CPU%d (%d)\n",
>>> - is_min ? "min" : "max", (u64)perf, cpu, ret);
>>> - return ret;
>>> - }
>>> + if (update_reg) {
>>> + ret = is_min ? cppc_set_min_perf(cpu, perf) :
>>> + cppc_set_max_perf(cpu, perf);
>>> + if (ret) {
>>> + if (ret != -EOPNOTSUPP)
>>> + pr_warn("CPU%d: set %s_perf=%llu failed (%d)\n",
>>> + cpu, is_min ? "min" : "max",
>>> + (u64)perf, ret);
>>> + return ret;
>>> + }
>>>
>>> - if (is_min)
>>> - cpu_data->perf_ctrls.min_perf = perf;
>>> - else
>>> - cpu_data->perf_ctrls.max_perf = perf;
>>> + if (is_min)
>>> + cpu_data->perf_ctrls.min_perf = perf;
>>> + else
>>> + cpu_data->perf_ctrls.max_perf = perf;
>>> + }
>>>
>>> if (update_policy) {
>>> freq = cppc_perf_to_khz(caps, perf);
>>> @@ -592,11 +601,74 @@ static int cppc_cpufreq_set_mperf_limit(struct cpufreq_policy *policy, u64 val,
>>> return 0;
>>> }
>>>
>>> -#define cppc_cpufreq_set_min_perf(policy, val, update_policy) \
>>> - cppc_cpufreq_set_mperf_limit(policy, val, update_policy, true)
>>> +#define cppc_cpufreq_set_min_perf(policy, val, update_reg, update_policy) \
>>> + cppc_cpufreq_set_mperf_limit(policy, val, update_reg, update_policy, \
>>> + true)
>>> +
>>> +#define cppc_cpufreq_set_max_perf(policy, val, update_reg, update_policy) \
>>> + cppc_cpufreq_set_mperf_limit(policy, val, update_reg, update_policy, \
>>> + false)
>>> +
>>> +/**
>>> + * cppc_cpufreq_update_autosel_config - Update autonomous selection config
>>> + * @policy: cpufreq policy
>>> + * @is_auto_sel: enable/disable autonomous selection
>>> + *
>>> + * Return: 0 on success, negative error code on failure
>>> + */
>>> +static int cppc_cpufreq_update_autosel_config(struct cpufreq_policy *policy,
>>> + bool is_auto_sel)
>>> +{
>>> + struct cppc_cpudata *cpu_data = policy->driver_data;
>>> + struct cppc_perf_caps *caps = &cpu_data->perf_caps;
>>> + u64 min_perf = caps->lowest_nonlinear_perf;
>>> + u64 max_perf = caps->nominal_perf;
>>> + unsigned int cpu = policy->cpu;
>>> + bool update_reg = is_auto_sel;
>>> + bool update_policy = true;
>>> + int ret;
>>> +
>>> + guard(mutex)(&cppc_cpufreq_update_autosel_config_lock);
>>> +
>>> + if (is_auto_sel) {
>>> + /* Use preserved values if available, else use defaults */
>>> + if (cpu_data->perf_ctrls.min_perf)
>>> + min_perf = cpu_data->perf_ctrls.min_perf;
>>> + if (cpu_data->perf_ctrls.max_perf)
>>> + max_perf = cpu_data->perf_ctrls.max_perf;
>>> + }
>> So if !is_auto_sel, min_perf and max_perf reg will be set to
>> lowest_nonlinear_perf and nominal_perf, but perf_ctrls.min_perf and
>> perf_ctrls.max_perf remain the old value. A little bit strange I think. And
>> when this happen, min_freq_req and max_freq_req will retain the value last
>> set by the users through min_perf and max_perf. It's that alright?
>
> When disabling: Reset policy to defaults for normal governor control,
> but preserve HW min/max_perf values and cached values for when
> auto_sel is re-enabled.
> When enabling: Restore policy to preserved min/max_perf values.
It's easy to assume that the values store in reg and in
cpu_data->perf_ctrls should be consistent. Perhaps adding some comments
would be better.
>
>>> +
>>> + /*
>>> + * Set min/max performance and update policy constraints.
>>> + * When enabling: update both HW registers and policy.
>>> + * When disabling: update policy only, preserve HW registers.
>>> + * Continue even if min/max are not supported, as EPP and autosel
>>> + * might still be supported.
>>> + */
>>> + ret = cppc_cpufreq_set_min_perf(policy, min_perf, update_reg,
>>> + update_policy);
>>> + if (ret && ret != -EOPNOTSUPP)
>>> + return ret;
>>> +
>>> + ret = cppc_cpufreq_set_max_perf(policy, max_perf, update_reg,
>>> + update_policy);
>>> + if (ret && ret != -EOPNOTSUPP)
>>> + return ret;
>>> +
>>> + /* Update auto_sel register */
>>> + ret = cppc_set_auto_sel(cpu, is_auto_sel);
>>> + if (ret && ret != -EOPNOTSUPP) {
>>> + pr_warn("Failed to set auto_sel=%d for CPU%d (%d)\n",
>>> + is_auto_sel, cpu, ret);
>>> + return ret;
>>> + }
>>> + if (!ret)
>>> + cpu_data->perf_ctrls.auto_sel = is_auto_sel;
>>> +
>>> + return 0;
>> Better to return ret.
>
> Here, return 0 is intentional.
> If cppc_set_auto_sel() returns -EOPNOTSUPP, we still consider the
> function successful since auto_sel is an optional register.
Why consider it successful?
>
>>> +}
>>> +
>>>
>>> -#define cppc_cpufreq_set_max_perf(policy, val, update_policy) \
>>> - cppc_cpufreq_set_mperf_limit(policy, val, update_policy, false)
>>> static struct cppc_cpudata *cppc_cpufreq_get_cpu_data(unsigned int cpu)
>>> {
>>> struct cppc_cpudata *cpu_data;
>>> @@ -889,7 +961,7 @@ static ssize_t store_auto_select(struct cpufreq_policy *policy,
>>> if (ret)
>>> return ret;
>> Since you already store auto_sel value in perf_ctrls, We can compare the
>> new value with perf_ctrls.auto_sel here, and just return if they are the
>> same.
>
> Will add in v6.
>
> Thank you,
> Sumit Gupta
>
> ....
>
>
>
next prev parent reply other threads:[~2026-01-15 8:58 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-23 12:12 [PATCH v5 00/11] Enhanced autonomous selection and improvements Sumit Gupta
2025-12-23 12:12 ` [PATCH v5 01/11] cpufreq: CPPC: Add generic helpers for sysfs show/store Sumit Gupta
2025-12-25 3:41 ` zhenglifeng (A)
2026-01-08 13:31 ` Sumit Gupta
2025-12-23 12:12 ` [PATCH v5 02/11] ACPI: CPPC: Clean up cppc_perf_caps and cppc_perf_ctrls structs Sumit Gupta
2026-01-08 13:43 ` Pierre Gondois
2025-12-23 12:12 ` [PATCH v5 03/11] ACPI: CPPC: Add cppc_get_perf() API to read performance controls Sumit Gupta
2025-12-25 8:21 ` zhenglifeng (A)
2026-01-08 13:36 ` Sumit Gupta
2025-12-23 12:13 ` [PATCH v5 04/11] ACPI: CPPC: Extend cppc_set_epp_perf() to support auto_sel and epp Sumit Gupta
2025-12-25 3:56 ` zhenglifeng (A)
2026-01-08 13:39 ` Sumit Gupta
2026-01-16 15:59 ` Pierre Gondois
2025-12-23 12:13 ` [PATCH v5 05/11] ACPI: CPPC: add APIs and sysfs interface for min/max_perf Sumit Gupta
2025-12-25 9:03 ` zhenglifeng (A)
2025-12-23 12:13 ` [PATCH v5 06/11] ACPI: CPPC: add APIs and sysfs interface for perf_limited Sumit Gupta
2025-12-25 12:06 ` zhenglifeng (A)
2026-01-08 14:38 ` Sumit Gupta
2026-01-15 8:01 ` zhenglifeng (A)
2025-12-23 12:13 ` [PATCH v5 07/11] cpufreq: CPPC: Add sysfs for min/max_perf and perf_limited Sumit Gupta
2025-12-24 18:32 ` kernel test robot
2025-12-26 0:20 ` Bagas Sanjaya
2026-01-08 14:30 ` Sumit Gupta
2025-12-23 12:13 ` [PATCH v5 08/11] cpufreq: CPPC: sync policy limits when updating min/max_perf Sumit Gupta
2025-12-25 13:56 ` zhenglifeng (A)
2026-01-08 13:53 ` Sumit Gupta
2026-01-15 8:20 ` zhenglifeng (A)
2025-12-23 12:13 ` [PATCH v5 09/11] cpufreq: CPPC: sync policy limits when toggling auto_select Sumit Gupta
2025-12-26 2:55 ` zhenglifeng (A)
2026-01-08 14:21 ` Sumit Gupta
2026-01-15 8:57 ` zhenglifeng (A) [this message]
2025-12-23 12:13 ` [PATCH v5 10/11] cpufreq: CPPC: make scaling_min/max_freq read-only when auto_sel enabled Sumit Gupta
2025-12-26 3:26 ` zhenglifeng (A)
2026-01-08 14:01 ` Sumit Gupta
2026-01-08 16:46 ` Pierre Gondois
2026-01-09 14:37 ` Sumit Gupta
2026-01-12 11:44 ` Pierre Gondois
2026-01-15 12:32 ` zhenglifeng (A)
2026-01-15 15:22 ` Sumit Gupta
2026-01-16 17:05 ` Pierre Gondois
2026-01-15 15:15 ` Sumit Gupta
2025-12-23 12:13 ` [PATCH v5 11/11] cpufreq: CPPC: add autonomous mode boot parameter support Sumit Gupta
2025-12-26 8:03 ` zhenglifeng (A)
2026-01-08 14:04 ` 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=7e5bfa69-96e2-4f54-9446-cc64845b52cd@huawei.com \
--to=zhenglifeng1@huawei.com \
--cc=acpica-devel@lists.linux.dev \
--cc=bbasu@nvidia.com \
--cc=corbet@lwn.net \
--cc=gautham.shenoy@amd.com \
--cc=ionela.voinescu@arm.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=nhartman@nvidia.com \
--cc=perry.yuan@amd.com \
--cc=pierre.gondois@arm.com \
--cc=rafael@kernel.org \
--cc=ray.huang@amd.com \
--cc=rdunlap@infradead.org \
--cc=robert.moore@intel.com \
--cc=sanjayc@nvidia.com \
--cc=sumitg@nvidia.com \
--cc=treding@nvidia.com \
--cc=viresh.kumar@linaro.org \
--cc=vsethi@nvidia.com \
--cc=zhanjie9@hisilicon.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