public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cpufreq: CPPC: Return desired perf in ->get() if feedback counters are 0
@ 2024-08-19  3:51 Jie Zhan
  2024-08-21  8:27 ` Jie Zhan
  2024-08-28  6:50 ` Viresh Kumar
  0 siblings, 2 replies; 7+ messages in thread
From: Jie Zhan @ 2024-08-19  3:51 UTC (permalink / raw)
  To: rafael, viresh.kumar
  Cc: linux-pm, linux-acpi, linuxarm, liaochang1, zhanjie9,
	wanghuiqiang, prime.zeng, fanghao11, jonathan.cameron

The CPPC performance feedback counters could return 0 when the target cpu
is in a deep idle state (e.g. powered off) and those counters are not
powered.  cppc_cpufreq_get_rate() returns 0 in this case, triggering two
problems:

1. cpufreq_online() gets a false error and doesn't generate a cpufreq
policy, which happens in cpufreq_add_dev() when a new cpu device is added.
2. 'cpuinfo_cur_freq' shows '<unknown>'

Don't take it as an error and return the frequency corresponding to the
desired perf when the feedback counters are 0.

Fixes: 6a4fec4f6d30 ("cpufreq: cppc: cppc_cpufreq_get_rate() returns zero in all error cases.")
Signed-off-by: Jie Zhan <zhanjie9@hisilicon.com>
---
 drivers/cpufreq/cppc_cpufreq.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c
index bafa32dd375d..1c5eb12c1a5a 100644
--- a/drivers/cpufreq/cppc_cpufreq.c
+++ b/drivers/cpufreq/cppc_cpufreq.c
@@ -748,18 +748,25 @@ static unsigned int cppc_cpufreq_get_rate(unsigned int cpu)
 
 	ret = cppc_get_perf_ctrs(cpu, &fb_ctrs_t0);
 	if (ret)
-		return 0;
+		goto out_err;
 
 	udelay(2); /* 2usec delay between sampling */
 
 	ret = cppc_get_perf_ctrs(cpu, &fb_ctrs_t1);
 	if (ret)
-		return 0;
+		goto out_err;
 
 	delivered_perf = cppc_perf_from_fbctrs(cpu_data, &fb_ctrs_t0,
 					       &fb_ctrs_t1);
 
 	return cppc_perf_to_khz(&cpu_data->perf_caps, delivered_perf);
+
+out_err:
+	if (ret == -EFAULT)
+		return cppc_perf_to_khz(&cpu_data->perf_caps,
+					cpu_data->perf_ctrls.desired_perf);
+
+	return 0;
 }
 
 static int cppc_cpufreq_set_boost(struct cpufreq_policy *policy, int state)
-- 
2.33.0


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

end of thread, other threads:[~2024-08-28 10:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-19  3:51 [PATCH] cpufreq: CPPC: Return desired perf in ->get() if feedback counters are 0 Jie Zhan
2024-08-21  8:27 ` Jie Zhan
2024-08-28  2:19   ` Jie Zhan
2024-08-28  6:50 ` Viresh Kumar
2024-08-28  8:17   ` Ionela Voinescu
2024-08-28  9:45     ` Jie Zhan
2024-08-28 10:12       ` Ionela Voinescu

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