Linux Power Management development
 help / color / mirror / Atom feed
* [PATCH v4] cpufreq: cppc: mask Desired_Excursion when autonomous selection is enabled
@ 2026-05-13  4:42 Xueqin Luo
  2026-05-14 20:11 ` Sumit Gupta
  0 siblings, 1 reply; 2+ messages in thread
From: Xueqin Luo @ 2026-05-13  4:42 UTC (permalink / raw)
  To: rafael, viresh.kumar, zhanjie9, zhenglifeng1, pierre.gondois,
	sumitg, linux-pm, linux-kernel
  Cc: Xueqin Luo

According to the ACPI 6.6 specification, the Desired_Excursion field is not
utilized when autonomous selection is enabled. In this mode, the bit is
architecturally ignored and does not carry meaningful information.

Currently, the kernel exposes the raw Performance Limited register
value to userspace through the cpufreq sysfs interface. This may lead to
misinterpretation, as userspace may assume Desired_Excursion is valid
even when autonomous selection is active.

To provide a stable and semantically correct ABI, mask out the
Desired_Excursion bit when autonomous selection is enabled, so that
userspace does not observe undefined or misleading values.

Writes are left unchanged, as the field is architecturally ignored in
this mode and write attempts are harmless.

Signed-off-by: Xueqin Luo <luoxueqin@kylinos.cn>
Reviewed-by: Pierre Gondois <pierre.gondois@arm.com>
---
v3 -> v4:
 - Address Sumit Gupta's review comments by reordering the
   error check and simplifying auto_sel handling in the
   perf_limited getter
---
 drivers/cpufreq/cppc_cpufreq.c | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c
index 7e7f9dfb7a24..d2f86df06129 100644
--- a/drivers/cpufreq/cppc_cpufreq.c
+++ b/drivers/cpufreq/cppc_cpufreq.c
@@ -982,7 +982,34 @@ store_energy_performance_preference_val(struct cpufreq_policy *policy,
 	return count;
 }
 
-CPPC_CPUFREQ_ATTR_RW_U64(perf_limited, cppc_get_perf_limited,
+static int cppc_get_perf_limited_filtered(int cpu, u64 *perf_limited)
+{
+	struct cpufreq_policy *policy;
+	struct cppc_cpudata *cpu_data;
+	int ret;
+
+	ret = cppc_get_perf_limited(cpu, perf_limited);
+	if (ret)
+		return ret;
+
+	policy = cpufreq_cpu_get_raw(cpu);
+	if (!policy)
+		return 0;
+
+	cpu_data = policy->driver_data;
+
+	/*
+	 * Desired Excursion is ignored when autonomous selection is
+	 * enabled. Clear the bit to avoid exposing meaningless state
+	 * to userspace.
+	 */
+	if (cpu_data && cpu_data->perf_ctrls.auto_sel)
+		*perf_limited &= ~CPPC_PERF_LIMITED_DESIRED_EXCURSION;
+
+	return 0;
+}
+
+CPPC_CPUFREQ_ATTR_RW_U64(perf_limited, cppc_get_perf_limited_filtered,
 			 cppc_set_perf_limited)
 
 cpufreq_freq_attr_ro(freqdomain_cpus);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v4] cpufreq: cppc: mask Desired_Excursion when autonomous selection is enabled
  2026-05-13  4:42 [PATCH v4] cpufreq: cppc: mask Desired_Excursion when autonomous selection is enabled Xueqin Luo
@ 2026-05-14 20:11 ` Sumit Gupta
  0 siblings, 0 replies; 2+ messages in thread
From: Sumit Gupta @ 2026-05-14 20:11 UTC (permalink / raw)
  To: Xueqin Luo, rafael, viresh.kumar, zhanjie9, zhenglifeng1,
	pierre.gondois, linux-pm, linux-kernel


On 13/05/26 10:12, Xueqin Luo wrote:
> External email: Use caution opening links or attachments
>
>
> According to the ACPI 6.6 specification, the Desired_Excursion field is not
> utilized when autonomous selection is enabled. In this mode, the bit is
> architecturally ignored and does not carry meaningful information.
>
> Currently, the kernel exposes the raw Performance Limited register
> value to userspace through the cpufreq sysfs interface. This may lead to
> misinterpretation, as userspace may assume Desired_Excursion is valid
> even when autonomous selection is active.
>
> To provide a stable and semantically correct ABI, mask out the
> Desired_Excursion bit when autonomous selection is enabled, so that
> userspace does not observe undefined or misleading values.
>
> Writes are left unchanged, as the field is architecturally ignored in
> this mode and write attempts are harmless.
>
> Signed-off-by: Xueqin Luo <luoxueqin@kylinos.cn>
> Reviewed-by: Pierre Gondois <pierre.gondois@arm.com>

Reviewed-by: Sumit Gupta <sumitg@nvidia.com>>, with a nit


> ---
> v3 -> v4:
>   - Address Sumit Gupta's review comments by reordering the
>     error check and simplifying auto_sel handling in the
>     perf_limited getter
> ---
>   drivers/cpufreq/cppc_cpufreq.c | 29 ++++++++++++++++++++++++++++-
>   1 file changed, 28 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c
> index 7e7f9dfb7a24..d2f86df06129 100644
> --- a/drivers/cpufreq/cppc_cpufreq.c
> +++ b/drivers/cpufreq/cppc_cpufreq.c
> @@ -982,7 +982,34 @@ store_energy_performance_preference_val(struct cpufreq_policy *policy,
>          return count;
>   }
>
> -CPPC_CPUFREQ_ATTR_RW_U64(perf_limited, cppc_get_perf_limited,
> +static int cppc_get_perf_limited_filtered(int cpu, u64 *perf_limited)
> +{
> +       struct cpufreq_policy *policy;
> +       struct cppc_cpudata *cpu_data;
> +       int ret;
> +
> +       ret = cppc_get_perf_limited(cpu, perf_limited);
> +       if (ret)
> +               return ret;
> +
> +       policy = cpufreq_cpu_get_raw(cpu);
> +       if (!policy)
> +               return 0;

return -EINVAL ?

Thank you,
Sumit Gupta


> +
> +       cpu_data = policy->driver_data;
> +
> +       /*
> +        * Desired Excursion is ignored when autonomous selection is
> +        * enabled. Clear the bit to avoid exposing meaningless state
> +        * to userspace.
> +        */
> +       if (cpu_data && cpu_data->perf_ctrls.auto_sel)
> +               *perf_limited &= ~CPPC_PERF_LIMITED_DESIRED_EXCURSION;
> +
> +       return 0;
> +}
> +
> +CPPC_CPUFREQ_ATTR_RW_U64(perf_limited, cppc_get_perf_limited_filtered,
>                           cppc_set_perf_limited)
>
>   cpufreq_freq_attr_ro(freqdomain_cpus);
> --
> 2.43.0
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-05-14 20:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-13  4:42 [PATCH v4] cpufreq: cppc: mask Desired_Excursion when autonomous selection is enabled Xueqin Luo
2026-05-14 20:11 ` Sumit Gupta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox