diff mbox series

cpufreq: intel_pstate: Directly use stored ratios for max frequencies

Message ID 20240118120513.1018808-1-srinivas.pandruvada@linux.intel.com
State New
Headers show
Series cpufreq: intel_pstate: Directly use stored ratios for max frequencies | expand

Commit Message

Srinivas Pandruvada Jan. 18, 2024, 12:05 p.m. UTC
Avoid unnecessary calculation for converting frequency to performance
ratio by using a scaling factor for the maximum non turbo and turbo
frequency. Here the driver already stored performance ratios for max
non turbo and turbo frequency by reading from MSR_HWP_CAPABILITIES.
Directly use those ratios without any calculations.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/cpufreq/intel_pstate.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Rafael J. Wysocki Jan. 22, 2024, 11:46 a.m. UTC | #1
On Mon, Jan 22, 2024 at 12:35 PM srinivas pandruvada
<srinivas.pandruvada@linux.intel.com> wrote:
>
> On Mon, 2024-01-22 at 11:53 +0100, Rafael J. Wysocki wrote:
> > On Thursday, January 18, 2024 1:05:13 PM CET Srinivas Pandruvada
> > wrote:
> > > Avoid unnecessary calculation for converting frequency to
> > > performance
> > > ratio by using a scaling factor for the maximum non turbo and turbo
> >
>
> [...]
>
> > ---
> > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> > Subject: [PATCH v1] cpufreq: intel_pstate: Refine computation of P-
> > state for given frequency
> >
> > On systems using HWP, if a given frequency is equal to the maximum
> > turbo
> > frequency or the maximum non-turbo frequency, the HWP performance
> > level
> > corresponding to it is already known and can be used directly without
> > any computation.
> >
> > Accordingly, adjust the code to use the known HWP performance levels
> > in
> > the cases mentioned above.
> >
> > This also helps to avoid limiting CPU capacity artificially in some
> > cases when the BIOS produces the HWP_CAP numbers using a different
> > E-core-to-P-core performance scaling factor than expected by the
> > kernel.
> >
> > Fixes: f5c8cf2a4992 ("cpufreq: intel_pstate: hybrid: Use known
> > scaling factor for P-cores")
> > Cc: 6.1+ <stable@vger.kernel.org> # 6.1+
> > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> > ---
>
> Tested on the system which showed the issue, this patch work fine.

So I'm going to add a Tested-by from you to it or please let me know
if you don't want me to do so.
Srinivas Pandruvada Jan. 22, 2024, 12:45 p.m. UTC | #2
On 1/22/24 03:46, Rafael J. Wysocki wrote:
> On Mon, Jan 22, 2024 at 12:35 PM srinivas pandruvada
> <srinivas.pandruvada@linux.intel.com> wrote:
>> On Mon, 2024-01-22 at 11:53 +0100, Rafael J. Wysocki wrote:
>>> On Thursday, January 18, 2024 1:05:13 PM CET Srinivas Pandruvada
>>> wrote:
>>>> Avoid unnecessary calculation for converting frequency to
>>>> performance
>>>> ratio by using a scaling factor for the maximum non turbo and turbo
>> [...]
>>
>>> ---
>>> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>>> Subject: [PATCH v1] cpufreq: intel_pstate: Refine computation of P-
>>> state for given frequency
>>>
>>> On systems using HWP, if a given frequency is equal to the maximum
>>> turbo
>>> frequency or the maximum non-turbo frequency, the HWP performance
>>> level
>>> corresponding to it is already known and can be used directly without
>>> any computation.
>>>
>>> Accordingly, adjust the code to use the known HWP performance levels
>>> in
>>> the cases mentioned above.
>>>
>>> This also helps to avoid limiting CPU capacity artificially in some
>>> cases when the BIOS produces the HWP_CAP numbers using a different
>>> E-core-to-P-core performance scaling factor than expected by the
>>> kernel.
>>>
>>> Fixes: f5c8cf2a4992 ("cpufreq: intel_pstate: hybrid: Use known
>>> scaling factor for P-cores")
>>> Cc: 6.1+ <stable@vger.kernel.org> # 6.1+
>>> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>>> ---
>> Tested on the system which showed the issue, this patch work fine.
> So I'm going to add a Tested-by from you to it or please let me know
> if you don't want me to do so.

You can add.

Thanks,

Srinivas
diff mbox series

Patch

diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 2ca70b0b5fdc..6bbc21ca96e0 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -2532,7 +2532,14 @@  static void intel_pstate_update_perf_limits(struct cpudata *cpu,
 		int freq;
 
 		freq = max_policy_perf * perf_ctl_scaling;
-		max_policy_perf = DIV_ROUND_UP(freq, scaling);
+
+		if (freq == cpu->pstate.turbo_freq)
+			max_policy_perf = cpu->pstate.turbo_pstate;
+		else if (freq == cpu->pstate.max_freq)
+			max_policy_perf = cpu->pstate.max_pstate;
+		else
+			max_policy_perf = DIV_ROUND_UP(freq, scaling);
+
 		freq = min_policy_perf * perf_ctl_scaling;
 		min_policy_perf = DIV_ROUND_UP(freq, scaling);
 	}