mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 1/2] cpufreq: CPPC: keep target core awake when reading its cpufreq rate
@ 2023-05-16 13:32 Zeng Heng
  2023-05-16 13:32 ` [PATCH v2 2/2] acpi: CPPC: read delivered_reg and reference_reg in critical section Zeng Heng
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Zeng Heng @ 2023-05-16 13:32 UTC (permalink / raw)
  To: lenb, viresh.kumar, rafael
  Cc: linux-kernel, linux-pm, wangxiongfeng2, xiexiuqi, liwei391,
	linux-acpi, weiyongjun1

As ARM AMU's document says, all counters are subject to any changes
in clock frequency, including clock stopping caused by the WFI and WFE
instructions.

Therefore, using smp_call_on_cpu() to trigger target CPU to
read self's AMU counters, which ensures the counters are working
properly during calculation.

Signed-off-by: Zeng Heng <zengheng4@huawei.com>
---
 drivers/cpufreq/cppc_cpufreq.c | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c
index 022e3555407c..910167f58bb3 100644
--- a/drivers/cpufreq/cppc_cpufreq.c
+++ b/drivers/cpufreq/cppc_cpufreq.c
@@ -837,9 +837,24 @@ static int cppc_perf_from_fbctrs(struct cppc_cpudata *cpu_data,
 	return (reference_perf * delta_delivered) / delta_reference;
 }
 
+static int cppc_get_perf_ctrs_smp(void *val)
+{
+	int cpu = smp_processor_id();
+	struct cppc_perf_fb_ctrs *fb_ctrs = val;
+	int ret;
+
+	ret = cppc_get_perf_ctrs(cpu, fb_ctrs);
+	if (ret)
+		return ret;
+
+	udelay(2); /* 2usec delay between sampling */
+
+	return cppc_get_perf_ctrs(cpu, fb_ctrs + 1);
+}
+
 static unsigned int cppc_cpufreq_get_rate(unsigned int cpu)
 {
-	struct cppc_perf_fb_ctrs fb_ctrs_t0 = {0}, fb_ctrs_t1 = {0};
+	struct cppc_perf_fb_ctrs fb_ctrs[2] = {0};
 	struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
 	struct cppc_cpudata *cpu_data = policy->driver_data;
 	u64 delivered_perf;
@@ -847,19 +862,12 @@ static unsigned int cppc_cpufreq_get_rate(unsigned int cpu)
 
 	cpufreq_cpu_put(policy);
 
-	ret = cppc_get_perf_ctrs(cpu, &fb_ctrs_t0);
-	if (ret)
-		return ret;
-
-	udelay(2); /* 2usec delay between sampling */
-
-	ret = cppc_get_perf_ctrs(cpu, &fb_ctrs_t1);
+	ret = smp_call_on_cpu(cpu, cppc_get_perf_ctrs_smp, fb_ctrs, 1);
 	if (ret)
 		return ret;
 
-	delivered_perf = cppc_perf_from_fbctrs(cpu_data, &fb_ctrs_t0,
-					       &fb_ctrs_t1);
-
+	delivered_perf = cppc_perf_from_fbctrs(cpu_data, fb_ctrs,
+					       fb_ctrs + 1);
 	return cppc_cpufreq_perf_to_khz(cpu_data, delivered_perf);
 }
 
-- 
2.25.1


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

end of thread, other threads:[~2023-05-26  8:59 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-16 13:32 [PATCH v2 1/2] cpufreq: CPPC: keep target core awake when reading its cpufreq rate Zeng Heng
2023-05-16 13:32 ` [PATCH v2 2/2] acpi: CPPC: read delivered_reg and reference_reg in critical section Zeng Heng
2023-05-16 13:32 ` [PATCH 0/2] drivers/cpufreq: gain accurate CPU frequency from cpufreq/scaling_cur_freq Zeng Heng
2023-05-17  8:17 ` [PATCH v2 1/2] cpufreq: CPPC: keep target core awake when reading its cpufreq rate Pierre Gondois
2023-05-17 15:03   ` Sumit Gupta
2023-05-17 18:46     ` Yang Shi
2023-05-18 14:40       ` Sumit Gupta
2023-05-19 16:39         ` Beata Michalska
2023-05-24 18:08         ` Yang Shi
2023-05-18  1:44     ` Zeng Heng
2023-05-26  8:58   ` Zeng Heng

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

all inboxes | Powered by JetHome®