Skip to content

Commit f99c735

Browse files
committed
cppc_cpufreq: Use desired perf if feedback ctrs are 0 or unchanged
jira LE-2742 Rebuild_History Non-Buildable kernel-5.14.0-503.35.1.el9_5 commit-author Jie Zhan <[email protected]> commit c471956 The CPPC performance feedback counters could be 0 or unchanged when the target cpu is in a low-power idle state, e.g. power-gated or clock-gated. When the counters are 0, cppc_cpufreq_get_rate() returns 0 KHz, which makes cpufreq_online() get a false error and fail to generate a cpufreq policy. When the counters are unchanged, the existing cppc_perf_from_fbctrs() returns a cached desired perf, but some platforms may update the real frequency back to the desired perf reg. For the above cases in cppc_cpufreq_get_rate(), get the latest desired perf from the CPPC reg to reflect the frequency because some platforms may update the actual frequency back there; if failed, use the cached desired perf. Fixes: 6a4fec4 ("cpufreq: cppc: cppc_cpufreq_get_rate() returns zero in all error cases.") Signed-off-by: Jie Zhan <[email protected]> Reviewed-by: Zeng Heng <[email protected]> Reviewed-by: Ionela Voinescu <[email protected]> Reviewed-by: Huisong Li <[email protected]> Signed-off-by: Viresh Kumar <[email protected]> (cherry picked from commit c471956) Signed-off-by: Jonathan Maple <[email protected]>
1 parent 0f39f6f commit f99c735

File tree

1 file changed

+46
-11
lines changed

1 file changed

+46
-11
lines changed

drivers/cpufreq/cppc_cpufreq.c

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ static void cppc_scale_freq_workfn(struct kthread_work *work)
118118

119119
perf = cppc_perf_from_fbctrs(cpu_data, &cppc_fi->prev_perf_fb_ctrs,
120120
&fb_ctrs);
121+
if (!perf)
122+
return;
123+
121124
cppc_fi->prev_perf_fb_ctrs = fb_ctrs;
122125

123126
perf <<= SCHED_CAPACITY_SHIFT;
@@ -730,13 +733,31 @@ static int cppc_perf_from_fbctrs(struct cppc_cpudata *cpu_data,
730733
delta_delivered = get_delta(fb_ctrs_t1->delivered,
731734
fb_ctrs_t0->delivered);
732735

733-
/* Check to avoid divide-by zero and invalid delivered_perf */
736+
/*
737+
* Avoid divide-by zero and unchanged feedback counters.
738+
* Leave it for callers to handle.
739+
*/
734740
if (!delta_reference || !delta_delivered)
735-
return cpu_data->perf_ctrls.desired_perf;
741+
return 0;
736742

737743
return (reference_perf * delta_delivered) / delta_reference;
738744
}
739745

746+
static int cppc_get_perf_ctrs_sample(int cpu,
747+
struct cppc_perf_fb_ctrs *fb_ctrs_t0,
748+
struct cppc_perf_fb_ctrs *fb_ctrs_t1)
749+
{
750+
int ret;
751+
752+
ret = cppc_get_perf_ctrs(cpu, fb_ctrs_t0);
753+
if (ret)
754+
return ret;
755+
756+
udelay(2); /* 2usec delay between sampling */
757+
758+
return cppc_get_perf_ctrs(cpu, fb_ctrs_t1);
759+
}
760+
740761
static unsigned int cppc_cpufreq_get_rate(unsigned int cpu)
741762
{
742763
struct cppc_perf_fb_ctrs fb_ctrs_t0 = {0}, fb_ctrs_t1 = {0};
@@ -752,18 +773,32 @@ static unsigned int cppc_cpufreq_get_rate(unsigned int cpu)
752773

753774
cpufreq_cpu_put(policy);
754775

755-
ret = cppc_get_perf_ctrs(cpu, &fb_ctrs_t0);
756-
if (ret)
757-
return 0;
758-
759-
udelay(2); /* 2usec delay between sampling */
760-
761-
ret = cppc_get_perf_ctrs(cpu, &fb_ctrs_t1);
762-
if (ret)
763-
return 0;
776+
ret = cppc_get_perf_ctrs_sample(cpu, &fb_ctrs_t0, &fb_ctrs_t1);
777+
if (ret) {
778+
if (ret == -EFAULT)
779+
/* Any of the associated CPPC regs is 0. */
780+
goto out_invalid_counters;
781+
else
782+
return 0;
783+
}
764784

765785
delivered_perf = cppc_perf_from_fbctrs(cpu_data, &fb_ctrs_t0,
766786
&fb_ctrs_t1);
787+
if (!delivered_perf)
788+
goto out_invalid_counters;
789+
790+
return cppc_perf_to_khz(&cpu_data->perf_caps, delivered_perf);
791+
792+
out_invalid_counters:
793+
/*
794+
* Feedback counters could be unchanged or 0 when a cpu enters a
795+
* low-power idle state, e.g. clock-gated or power-gated.
796+
* Use desired perf for reflecting frequency. Get the latest register
797+
* value first as some platforms may update the actual delivered perf
798+
* there; if failed, resort to the cached desired perf.
799+
*/
800+
if (cppc_get_desired_perf(cpu, &delivered_perf))
801+
delivered_perf = cpu_data->perf_ctrls.desired_perf;
767802

768803
return cppc_perf_to_khz(&cpu_data->perf_caps, delivered_perf);
769804
}

0 commit comments

Comments
 (0)