[PATCH] ACPI: CPPC: Add helper to get effective guaranteed performance

Xueqin Luo posted 1 patch 1 week, 3 days ago
drivers/acpi/cppc_acpi.c       | 26 ++++++++++++++++++++++++++
drivers/cpufreq/intel_pstate.c | 10 ++++------
include/acpi/cppc_acpi.h       |  5 +++++
3 files changed, 35 insertions(+), 6 deletions(-)
[PATCH] ACPI: CPPC: Add helper to get effective guaranteed performance
Posted by Xueqin Luo 1 week, 3 days ago
According to the ACPI CPPC specification, if the Guaranteed
Performance register is not implemented, OSPM assumes the
guaranteed performance is equal to nominal performance.

Add cppc_get_effective_guaranteed_perf() helper to provide a
spec-compliant effective guaranteed performance value while
preserving the raw values returned by cppc_get_perf_caps().

Signed-off-by: Xueqin Luo <luoxueqin@kylinos.cn>
---
 drivers/acpi/cppc_acpi.c       | 26 ++++++++++++++++++++++++++
 drivers/cpufreq/intel_pstate.c | 10 ++++------
 include/acpi/cppc_acpi.h       |  5 +++++
 3 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
index f370be8715ae..6dc11030707a 100644
--- a/drivers/acpi/cppc_acpi.c
+++ b/drivers/acpi/cppc_acpi.c
@@ -1328,6 +1328,32 @@ int cppc_get_highest_perf(int cpunum, u64 *highest_perf)
 }
 EXPORT_SYMBOL_GPL(cppc_get_highest_perf);
 
+/**
+ * cppc_get_effective_guaranteed_perf - get effective guaranteed performance
+ * @cpunum: CPU number
+ * @guaranteed_perf: Effective guaranteed performance value
+ *
+ * The ACPI CPPC specification states that if the Guaranteed
+ * Performance register is not implemented, OSPM assumes the
+ * guaranteed performance is equal to nominal performance.
+ *
+ * Return: 0 on success, negative errno on failure.
+ */
+int cppc_get_effective_guaranteed_perf(int cpunum, u64 *guaranteed_perf)
+{
+	struct cppc_perf_caps perf_caps;
+	int ret;
+
+	ret = cppc_get_perf_caps(cpunum, &perf_caps);
+	if (ret)
+		return ret;
+	*guaranteed_perf = perf_caps.guaranteed_perf ?:
+			   perf_caps.nominal_perf;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(cppc_get_effective_guaranteed_perf);
+
 /**
  * cppc_get_epp_perf - Get the epp register value.
  * @cpunum: CPU from which to get epp preference value.
diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 8dc22a65e025..8934e48f71a2 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -404,17 +404,15 @@ static void intel_pstate_set_itmt_prio(int cpu)
 
 static int intel_pstate_get_cppc_guaranteed(int cpu)
 {
-	struct cppc_perf_caps cppc_perf;
+	u64 guaranteed_perf;
 	int ret;
 
-	ret = cppc_get_perf_caps(cpu, &cppc_perf);
+	ret = cppc_get_effective_guaranteed_perf(cpu, &guaranteed_perf);
+
 	if (ret)
 		return ret;
 
-	if (cppc_perf.guaranteed_perf)
-		return cppc_perf.guaranteed_perf;
-
-	return cppc_perf.nominal_perf;
+	return guaranteed_perf;
 }
 
 static int intel_pstate_cppc_get_scaling(int cpu)
diff --git a/include/acpi/cppc_acpi.h b/include/acpi/cppc_acpi.h
index d1f02ceec4f9..c02f3bc1fc1a 100644
--- a/include/acpi/cppc_acpi.h
+++ b/include/acpi/cppc_acpi.h
@@ -155,6 +155,7 @@ struct cppc_cpudata {
 extern int cppc_get_desired_perf(int cpunum, u64 *desired_perf);
 extern int cppc_get_nominal_perf(int cpunum, u64 *nominal_perf);
 extern int cppc_get_highest_perf(int cpunum, u64 *highest_perf);
+extern int cppc_get_effective_guaranteed_perf(int cpunum, u64 *guaranteed_perf);
 extern int cppc_get_perf_ctrs(int cpu, struct cppc_perf_fb_ctrs *perf_fb_ctrs);
 extern int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls);
 extern int cppc_set_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls);
@@ -198,6 +199,10 @@ static inline int cppc_get_highest_perf(int cpunum, u64 *highest_perf)
 {
 	return -EOPNOTSUPP;
 }
+static inline int cppc_get_effective_guaranteed_perf(int cpunum, u64 *guaranteed_perf)
+{
+	return -EOPNOTSUPP;
+}
 static inline int cppc_get_perf_ctrs(int cpu, struct cppc_perf_fb_ctrs *perf_fb_ctrs)
 {
 	return -EOPNOTSUPP;
-- 
2.43.0
Re: [PATCH] ACPI: CPPC: Add helper to get effective guaranteed performance
Posted by srinivas pandruvada 1 week, 2 days ago
On Fri, 2026-05-29 at 16:18 +0800, Xueqin Luo wrote:
> According to the ACPI CPPC specification, if the Guaranteed
> Performance register is not implemented, OSPM assumes the
> guaranteed performance is equal to nominal performance.
> 
> Add cppc_get_effective_guaranteed_perf() helper to provide a
> spec-compliant effective guaranteed performance value while
> preserving the raw values returned by cppc_get_perf_caps().
> 
Hi Luo,

Are you trying to fix any issue where you have issue with
"base_frequency" display? intel_pstate will revert to native MSR, which
is always present when we are using CPPC.

I worry about some bad nominal perf in some platforms as we will be
dependent on OEM BIOS.

Thanks,
Srinivas


> Signed-off-by: Xueqin Luo <luoxueqin@kylinos.cn>
> ---
>  drivers/acpi/cppc_acpi.c       | 26 ++++++++++++++++++++++++++
>  drivers/cpufreq/intel_pstate.c | 10 ++++------
>  include/acpi/cppc_acpi.h       |  5 +++++
>  3 files changed, 35 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
> index f370be8715ae..6dc11030707a 100644
> --- a/drivers/acpi/cppc_acpi.c
> +++ b/drivers/acpi/cppc_acpi.c
> @@ -1328,6 +1328,32 @@ int cppc_get_highest_perf(int cpunum, u64
> *highest_perf)
>  }
>  EXPORT_SYMBOL_GPL(cppc_get_highest_perf);
>  
> +/**
> + * cppc_get_effective_guaranteed_perf - get effective guaranteed
> performance
> + * @cpunum: CPU number
> + * @guaranteed_perf: Effective guaranteed performance value
> + *
> + * The ACPI CPPC specification states that if the Guaranteed
> + * Performance register is not implemented, OSPM assumes the
> + * guaranteed performance is equal to nominal performance.
> + *
> + * Return: 0 on success, negative errno on failure.
> + */
> +int cppc_get_effective_guaranteed_perf(int cpunum, u64
> *guaranteed_perf)
> +{
> +	struct cppc_perf_caps perf_caps;
> +	int ret;
> +
> +	ret = cppc_get_perf_caps(cpunum, &perf_caps);
> +	if (ret)
> +		return ret;
> +	*guaranteed_perf = perf_caps.guaranteed_perf ?:
> +			   perf_caps.nominal_perf;
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(cppc_get_effective_guaranteed_perf);
> +
>  /**
>   * cppc_get_epp_perf - Get the epp register value.
>   * @cpunum: CPU from which to get epp preference value.
> diff --git a/drivers/cpufreq/intel_pstate.c
> b/drivers/cpufreq/intel_pstate.c
> index 8dc22a65e025..8934e48f71a2 100644
> --- a/drivers/cpufreq/intel_pstate.c
> +++ b/drivers/cpufreq/intel_pstate.c
> @@ -404,17 +404,15 @@ static void intel_pstate_set_itmt_prio(int cpu)
>  
>  static int intel_pstate_get_cppc_guaranteed(int cpu)
>  {
> -	struct cppc_perf_caps cppc_perf;
> +	u64 guaranteed_perf;
>  	int ret;
>  
> -	ret = cppc_get_perf_caps(cpu, &cppc_perf);
> +	ret = cppc_get_effective_guaranteed_perf(cpu,
> &guaranteed_perf);
> +
>  	if (ret)
>  		return ret;
>  
> -	if (cppc_perf.guaranteed_perf)
> -		return cppc_perf.guaranteed_perf;
> -
> -	return cppc_perf.nominal_perf;
> +	return guaranteed_perf;
>  }
>  
>  static int intel_pstate_cppc_get_scaling(int cpu)
> diff --git a/include/acpi/cppc_acpi.h b/include/acpi/cppc_acpi.h
> index d1f02ceec4f9..c02f3bc1fc1a 100644
> --- a/include/acpi/cppc_acpi.h
> +++ b/include/acpi/cppc_acpi.h
> @@ -155,6 +155,7 @@ struct cppc_cpudata {
>  extern int cppc_get_desired_perf(int cpunum, u64 *desired_perf);
>  extern int cppc_get_nominal_perf(int cpunum, u64 *nominal_perf);
>  extern int cppc_get_highest_perf(int cpunum, u64 *highest_perf);
> +extern int cppc_get_effective_guaranteed_perf(int cpunum, u64
> *guaranteed_perf);
>  extern int cppc_get_perf_ctrs(int cpu, struct cppc_perf_fb_ctrs
> *perf_fb_ctrs);
>  extern int cppc_get_perf(int cpu, struct cppc_perf_ctrls
> *perf_ctrls);
>  extern int cppc_set_perf(int cpu, struct cppc_perf_ctrls
> *perf_ctrls);
> @@ -198,6 +199,10 @@ static inline int cppc_get_highest_perf(int
> cpunum, u64 *highest_perf)
>  {
>  	return -EOPNOTSUPP;
>  }
> +static inline int cppc_get_effective_guaranteed_perf(int cpunum, u64
> *guaranteed_perf)
> +{
> +	return -EOPNOTSUPP;
> +}
>  static inline int cppc_get_perf_ctrs(int cpu, struct
> cppc_perf_fb_ctrs *perf_fb_ctrs)
>  {
>  	return -EOPNOTSUPP;
Re: [PATCH] ACPI: CPPC: Add helper to get effective guaranteed performance
Posted by luoxueqin 1 week ago
在 2026/5/29 23:33, srinivas pandruvada 写道:
> On Fri, 2026-05-29 at 16:18 +0800, Xueqin Luo wrote:
>> According to the ACPI CPPC specification, if the Guaranteed
>> Performance register is not implemented, OSPM assumes the
>> guaranteed performance is equal to nominal performance.
>>
>> Add cppc_get_effective_guaranteed_perf() helper to provide a
>> spec-compliant effective guaranteed performance value while
>> preserving the raw values returned by cppc_get_perf_caps().
>>
> Hi Luo,
>
> Are you trying to fix any issue where you have issue with
> "base_frequency" display? intel_pstate will revert to native MSR, which
> is always present when we are using CPPC.
>
> I worry about some bad nominal perf in some platforms as we will be
> dependent on OEM BIOS.
>
> Thanks,
> Srinivas
>
Thanks Srinivas.

The intent is not to fix any issue in intel_pstate. It already
implements the fallback correctly today.

My goal was to provide a common helper encapsulating the ACPI
CPPC semantics, with intel_pstate serving as the first user.
That said, I agree the benefit may not justify a new exported
helper at this point.
>> Signed-off-by: Xueqin Luo <luoxueqin@kylinos.cn>
>> ---
>>   drivers/acpi/cppc_acpi.c       | 26 ++++++++++++++++++++++++++
>>   drivers/cpufreq/intel_pstate.c | 10 ++++------
>>   include/acpi/cppc_acpi.h       |  5 +++++
>>   3 files changed, 35 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
>> index f370be8715ae..6dc11030707a 100644
>> --- a/drivers/acpi/cppc_acpi.c
>> +++ b/drivers/acpi/cppc_acpi.c
>> @@ -1328,6 +1328,32 @@ int cppc_get_highest_perf(int cpunum, u64
>> *highest_perf)
>>   }
>>   EXPORT_SYMBOL_GPL(cppc_get_highest_perf);
>>   
>> +/**
>> + * cppc_get_effective_guaranteed_perf - get effective guaranteed
>> performance
>> + * @cpunum: CPU number
>> + * @guaranteed_perf: Effective guaranteed performance value
>> + *
>> + * The ACPI CPPC specification states that if the Guaranteed
>> + * Performance register is not implemented, OSPM assumes the
>> + * guaranteed performance is equal to nominal performance.
>> + *
>> + * Return: 0 on success, negative errno on failure.
>> + */
>> +int cppc_get_effective_guaranteed_perf(int cpunum, u64
>> *guaranteed_perf)
>> +{
>> +	struct cppc_perf_caps perf_caps;
>> +	int ret;
>> +
>> +	ret = cppc_get_perf_caps(cpunum, &perf_caps);
>> +	if (ret)
>> +		return ret;
>> +	*guaranteed_perf = perf_caps.guaranteed_perf ?:
>> +			   perf_caps.nominal_perf;
>> +
>> +	return 0;
>> +}
>> +EXPORT_SYMBOL_GPL(cppc_get_effective_guaranteed_perf);
>> +
>>   /**
>>    * cppc_get_epp_perf - Get the epp register value.
>>    * @cpunum: CPU from which to get epp preference value.
>> diff --git a/drivers/cpufreq/intel_pstate.c
>> b/drivers/cpufreq/intel_pstate.c
>> index 8dc22a65e025..8934e48f71a2 100644
>> --- a/drivers/cpufreq/intel_pstate.c
>> +++ b/drivers/cpufreq/intel_pstate.c
>> @@ -404,17 +404,15 @@ static void intel_pstate_set_itmt_prio(int cpu)
>>   
>>   static int intel_pstate_get_cppc_guaranteed(int cpu)
>>   {
>> -	struct cppc_perf_caps cppc_perf;
>> +	u64 guaranteed_perf;
>>   	int ret;
>>   
>> -	ret = cppc_get_perf_caps(cpu, &cppc_perf);
>> +	ret = cppc_get_effective_guaranteed_perf(cpu,
>> &guaranteed_perf);
>> +
>>   	if (ret)
>>   		return ret;
>>   
>> -	if (cppc_perf.guaranteed_perf)
>> -		return cppc_perf.guaranteed_perf;
>> -
>> -	return cppc_perf.nominal_perf;
>> +	return guaranteed_perf;
>>   }
>>   
>>   static int intel_pstate_cppc_get_scaling(int cpu)
>> diff --git a/include/acpi/cppc_acpi.h b/include/acpi/cppc_acpi.h
>> index d1f02ceec4f9..c02f3bc1fc1a 100644
>> --- a/include/acpi/cppc_acpi.h
>> +++ b/include/acpi/cppc_acpi.h
>> @@ -155,6 +155,7 @@ struct cppc_cpudata {
>>   extern int cppc_get_desired_perf(int cpunum, u64 *desired_perf);
>>   extern int cppc_get_nominal_perf(int cpunum, u64 *nominal_perf);
>>   extern int cppc_get_highest_perf(int cpunum, u64 *highest_perf);
>> +extern int cppc_get_effective_guaranteed_perf(int cpunum, u64
>> *guaranteed_perf);
>>   extern int cppc_get_perf_ctrs(int cpu, struct cppc_perf_fb_ctrs
>> *perf_fb_ctrs);
>>   extern int cppc_get_perf(int cpu, struct cppc_perf_ctrls
>> *perf_ctrls);
>>   extern int cppc_set_perf(int cpu, struct cppc_perf_ctrls
>> *perf_ctrls);
>> @@ -198,6 +199,10 @@ static inline int cppc_get_highest_perf(int
>> cpunum, u64 *highest_perf)
>>   {
>>   	return -EOPNOTSUPP;
>>   }
>> +static inline int cppc_get_effective_guaranteed_perf(int cpunum, u64
>> *guaranteed_perf)
>> +{
>> +	return -EOPNOTSUPP;
>> +}
>>   static inline int cppc_get_perf_ctrs(int cpu, struct
>> cppc_perf_fb_ctrs *perf_fb_ctrs)
>>   {
>>   	return -EOPNOTSUPP;