Re: [PATCH] cpufreq: intel_pstate: Clean up frequency computations

2021-03-22 Thread Chen Yu
On Tue, Mar 16, 2021 at 04:52:43PM +0100, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki 
> 
> Notice that some computations related to frequency in intel_pstate
> can be simplified if (a) intel_pstate_get_hwp_max() updates the
> relevant members of struct cpudata by itself and (b) the "turbo
> disabled" check is moved from it to its callers, so modify the code
> accordingly and while at it rename intel_pstate_get_hwp_max() to
> intel_pstate_get_hwp_cap() which better reflects its purpose and
> provide a simplified variat of it, __intel_pstate_get_hwp_cap(),
> suitable for the initialization path.
> 
> No intentional functional impact.
> 
> Signed-off-by: Rafael J. Wysocki 
Tested-by: Chen Yu 

thanks,
Chenyu


[PATCH] cpufreq: intel_pstate: Clean up frequency computations

2021-03-16 Thread Rafael J. Wysocki
From: Rafael J. Wysocki 

Notice that some computations related to frequency in intel_pstate
can be simplified if (a) intel_pstate_get_hwp_max() updates the
relevant members of struct cpudata by itself and (b) the "turbo
disabled" check is moved from it to its callers, so modify the code
accordingly and while at it rename intel_pstate_get_hwp_max() to
intel_pstate_get_hwp_cap() which better reflects its purpose and
provide a simplified variat of it, __intel_pstate_get_hwp_cap(),
suitable for the initialization path.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki 
---
 drivers/cpufreq/intel_pstate.c |  101 ++---
 1 file changed, 45 insertions(+), 56 deletions(-)

Index: linux-pm/drivers/cpufreq/intel_pstate.c
===
--- linux-pm.orig/drivers/cpufreq/intel_pstate.c
+++ linux-pm/drivers/cpufreq/intel_pstate.c
@@ -819,19 +819,21 @@ static struct freq_attr *hwp_cpufreq_att
NULL,
 };
 
-static void intel_pstate_get_hwp_max(struct cpudata *cpu, int *phy_max,
-int *current_max)
+static void __intel_pstate_get_hwp_cap(struct cpudata *cpu)
 {
u64 cap;
 
rdmsrl_on_cpu(cpu->cpu, MSR_HWP_CAPABILITIES, );
WRITE_ONCE(cpu->hwp_cap_cached, cap);
-   if (global.no_turbo || global.turbo_disabled)
-   *current_max = HWP_GUARANTEED_PERF(cap);
-   else
-   *current_max = HWP_HIGHEST_PERF(cap);
+   cpu->pstate.max_pstate = HWP_GUARANTEED_PERF(cap);
+   cpu->pstate.turbo_pstate = HWP_HIGHEST_PERF(cap);
+}
 
-   *phy_max = HWP_HIGHEST_PERF(cap);
+static void intel_pstate_get_hwp_cap(struct cpudata *cpu)
+{
+   __intel_pstate_get_hwp_cap(cpu);
+   cpu->pstate.max_freq = cpu->pstate.max_pstate * cpu->pstate.scaling;
+   cpu->pstate.turbo_freq = cpu->pstate.turbo_pstate * cpu->pstate.scaling;
 }
 
 static void intel_pstate_hwp_set(unsigned int cpu)
@@ -1195,12 +1197,13 @@ static ssize_t store_no_turbo(struct kob
 
 static void update_qos_request(enum freq_qos_req_type type)
 {
-   int max_state, turbo_max, freq, i, perf_pct;
struct freq_qos_request *req;
struct cpufreq_policy *policy;
+   int i;
 
for_each_possible_cpu(i) {
struct cpudata *cpu = all_cpu_data[i];
+   unsigned int freq, perf_pct;
 
policy = cpufreq_cpu_get(i);
if (!policy)
@@ -1213,9 +1216,7 @@ static void update_qos_request(enum freq
continue;
 
if (hwp_active)
-   intel_pstate_get_hwp_max(cpu, _max, _state);
-   else
-   turbo_max = cpu->pstate.turbo_pstate;
+   intel_pstate_get_hwp_cap(cpu);
 
if (type == FREQ_QOS_MIN) {
perf_pct = global.min_perf_pct;
@@ -1224,8 +1225,7 @@ static void update_qos_request(enum freq
perf_pct = global.max_perf_pct;
}
 
-   freq = DIV_ROUND_UP(turbo_max * perf_pct, 100);
-   freq *= cpu->pstate.scaling;
+   freq = DIV_ROUND_UP(cpu->pstate.turbo_freq * perf_pct, 100);
 
if (freq_qos_update_request(req, freq) < 0)
pr_warn("Failed to update freq constraint: CPU%d\n", i);
@@ -1715,21 +1715,17 @@ static void intel_pstate_get_cpu_pstates
 {
cpu->pstate.min_pstate = pstate_funcs.get_min();
cpu->pstate.max_pstate_physical = pstate_funcs.get_max_physical();
-   cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
cpu->pstate.scaling = pstate_funcs.get_scaling();
 
if (hwp_active && !hwp_mode_bdw) {
-   unsigned int phy_max, current_max;
-
-   intel_pstate_get_hwp_max(cpu, _max, _max);
-   cpu->pstate.turbo_freq = phy_max * cpu->pstate.scaling;
-   cpu->pstate.turbo_pstate = phy_max;
-   cpu->pstate.max_pstate = 
HWP_GUARANTEED_PERF(READ_ONCE(cpu->hwp_cap_cached));
+   __intel_pstate_get_hwp_cap(cpu);
} else {
-   cpu->pstate.turbo_freq = cpu->pstate.turbo_pstate * 
cpu->pstate.scaling;
cpu->pstate.max_pstate = pstate_funcs.get_max();
+   cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
}
+
cpu->pstate.max_freq = cpu->pstate.max_pstate * cpu->pstate.scaling;
+   cpu->pstate.turbo_freq = cpu->pstate.turbo_pstate * cpu->pstate.scaling;
 
if (pstate_funcs.get_aperf_mperf_shift)
cpu->aperf_mperf_shift = pstate_funcs.get_aperf_mperf_shift();
@@ -2204,18 +2200,21 @@ static void intel_pstate_update_perf_lim
int max_freq;
 
/*
-* HWP needs some special consideration, because on BDX the
-* HWP_REQUEST uses abstract value to represent performance
-* rather than pure ratios.
+* HWP needs some special consideration,