From: Zeng Heng <zengheng4@huawei.com>
To: <lenb@kernel.org>, <viresh.kumar@linaro.org>, <rafael@kernel.org>
Cc: <linux-kernel@vger.kernel.org>, <linux-pm@vger.kernel.org>,
<wangxiongfeng2@huawei.com>, <xiexiuqi@huawei.com>,
<liwei391@huawei.com>, <linux-acpi@vger.kernel.org>,
<weiyongjun1@huawei.com>
Subject: [PATCH v2 1/2] cpufreq: CPPC: keep target core awake when reading its cpufreq rate
Date: Tue, 16 May 2023 21:32:46 +0800 [thread overview]
Message-ID: <20230516133248.712242-1-zengheng4@huawei.com> (raw)
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
next reply other threads:[~2023-05-16 13:33 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-16 13:32 Zeng Heng [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230516133248.712242-1-zengheng4@huawei.com \
--to=zengheng4@huawei.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=liwei391@huawei.com \
--cc=rafael@kernel.org \
--cc=viresh.kumar@linaro.org \
--cc=wangxiongfeng2@huawei.com \
--cc=weiyongjun1@huawei.com \
--cc=xiexiuqi@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®