From: Lukasz Luba <lukasz.luba@arm.com>
To: linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org
Cc: sudeep.holla@arm.com, cristian.marussi@arm.com,
viresh.kumar@linaro.org, lukasz.luba@arm.com, rjw@rjwysocki.net
Subject: [PATCH 4/4] cpufreq: scmi: Read statistics from FW shared memory
Date: Wed, 29 Jul 2020 16:12:08 +0100 [thread overview]
Message-ID: <20200729151208.27737-5-lukasz.luba@arm.com> (raw)
In-Reply-To: <20200729151208.27737-1-lukasz.luba@arm.com>
Add support for reading CPUFreq statistics from the firmware. The setup
code initializes needed structures per domain basis. The driver callback
scmi_cpufreq_stats_get is called by the CPUFreq framework and invokes
SCMI performance protocol in order to retrieve latest statistics.
Signed-off-by: Lukasz Luba <lukasz.luba@arm.com>
---
drivers/cpufreq/scmi-cpufreq.c | 80 ++++++++++++++++++++++++++++++++++
1 file changed, 80 insertions(+)
diff --git a/drivers/cpufreq/scmi-cpufreq.c b/drivers/cpufreq/scmi-cpufreq.c
index fe95350eb844..67ae63171dd0 100644
--- a/drivers/cpufreq/scmi-cpufreq.c
+++ b/drivers/cpufreq/scmi-cpufreq.c
@@ -22,6 +22,7 @@
struct scmi_data {
int domain_id;
struct device *cpu_dev;
+ struct scmi_perf_domain_stats *stats;
};
static unsigned int scmi_cpufreq_get_rate(unsigned int cpu);
@@ -48,6 +49,34 @@ static struct cpufreq_driver scmi_cpufreq_driver = {
static const struct scmi_handle *handle;
+static int scmi_cpufreq_stats_get(struct cpufreq_policy *policy)
+{
+ struct scmi_data *priv = policy->driver_data;
+ struct cpufreq_stats *stats = policy->stats;
+ int i, ret;
+
+ /*
+ * Since the driver callback is global and can be set for all
+ * policy objects, there is a need to check if that policy has
+ * statistics in the shared memory.
+ */
+ if (!policy->has_driver_stats)
+ return -EINVAL;
+
+ ret = handle->perf_ops->statistics_get(handle, priv->domain_id, priv->stats);
+ if (ret)
+ return ret;
+
+ for (i = 0; i < priv->stats->state_num; i++)
+ stats->time_in_state[i] = priv->stats->time_in_state[i];
+
+ stats->total_trans = priv->stats->total_trans;
+ stats->last_index = priv->stats->last_index;
+ stats->last_time = priv->stats->last_time;
+
+ return ret;
+}
+
static unsigned int scmi_cpufreq_get_rate(unsigned int cpu)
{
struct cpufreq_policy *policy = cpufreq_cpu_get_raw(cpu);
@@ -147,6 +176,45 @@ scmi_get_cpu_power(unsigned long *power, unsigned long *KHz,
return 0;
}
+static int scmi_cpufreq_stats_init(struct cpufreq_policy *policy,
+ struct scmi_data *priv, int nr_opp)
+{
+ struct scmi_perf_domain_stats *stats;
+ int ret;
+
+ stats = kzalloc(sizeof(struct scmi_perf_domain_stats), GFP_KERNEL);
+ if (!stats)
+ return -ENOMEM;
+
+ stats->time_in_state = kcalloc(nr_opp, sizeof(u64), GFP_KERNEL);
+ if (!stats->time_in_state) {
+ kfree(stats);
+ return -ENOMEM;
+ }
+
+ stats->freq_table = kcalloc(nr_opp, sizeof(unsigned int), GFP_KERNEL);
+ if (!stats->freq_table) {
+ kfree(stats->time_in_state);
+ kfree(stats);
+ return -ENOMEM;
+ }
+
+ priv->stats = stats;
+ priv->stats->state_num = nr_opp;
+ policy->has_driver_stats = true;
+ scmi_cpufreq_driver.get_statistics = scmi_cpufreq_stats_get;
+
+ ret = handle->perf_ops->statistics_get(handle, priv->domain_id, stats);
+ if (ret) {
+ kfree(stats->freq_table);
+ kfree(stats->time_in_state);
+ kfree(stats);
+ policy->has_driver_stats = false;
+ }
+
+ return ret;
+}
+
static int scmi_cpufreq_init(struct cpufreq_policy *policy)
{
int ret, nr_opp;
@@ -209,6 +277,10 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy)
/* SCMI allows DVFS request for any domain from any CPU */
policy->dvfs_possible_from_any_cpu = true;
+ ret = scmi_cpufreq_stats_init(policy, priv, nr_opp);
+ if (ret)
+ dev_warn(cpu_dev, "failed to init statistics: %d\n", ret);
+
latency = handle->perf_ops->transition_latency_get(handle, cpu_dev);
if (!latency)
latency = CPUFREQ_ETERNAL;
@@ -236,6 +308,14 @@ static int scmi_cpufreq_exit(struct cpufreq_policy *policy)
dev_pm_opp_free_cpufreq_table(priv->cpu_dev, &policy->freq_table);
dev_pm_opp_remove_all_dynamic(priv->cpu_dev);
+
+ if (priv->stats) {
+ policy->has_driver_stats = false;
+ kfree(priv->stats->time_in_state);
+ kfree(priv->stats->freq_table);
+ kfree(priv->stats);
+ }
+
kfree(priv);
return 0;
--
2.17.1
next prev parent reply other threads:[~2020-07-29 15:12 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-29 15:12 [PATCH 0/4] CPUFreq statistics retrieved by drivers Lukasz Luba
2020-07-29 15:12 ` [PATCH 1/4] cpufreq: Add support for statistics read from drivers Lukasz Luba
2020-07-29 15:12 ` [PATCH 2/4] scmi: perf: Extend protocol to support performance statistics Lukasz Luba
2020-07-31 1:50 ` kernel test robot
2020-07-31 15:15 ` Cristian Marussi
2020-08-04 11:10 ` Lukasz Luba
2020-07-29 15:12 ` [PATCH 3/4] cpufreq: scmi: Move scmi_cpufreq_driver structure to the top Lukasz Luba
2020-07-29 15:12 ` Lukasz Luba [this message]
2020-07-30 8:53 ` [PATCH 0/4] CPUFreq statistics retrieved by drivers Viresh Kumar
2020-07-30 9:10 ` Sudeep Holla
2020-07-30 9:36 ` Lukasz Luba
2020-07-31 15:56 ` Sudeep Holla
2020-08-04 17:19 ` Florian Fainelli
2020-08-05 12:36 ` Sudeep Holla
2020-08-04 5:35 ` Viresh Kumar
2020-08-04 10:29 ` Lukasz Luba
2020-08-04 10:38 ` Viresh Kumar
2020-08-04 10:44 ` Lukasz Luba
2020-09-02 7:26 ` Viresh Kumar
2020-08-04 17:27 ` Florian Fainelli
2020-08-05 11:04 ` Lukasz Luba
2020-08-05 13:04 ` Viresh Kumar
2020-08-05 16:03 ` Sudeep Holla
2020-08-05 17:33 ` Florian Fainelli
2020-08-06 13:37 ` Sudeep Holla
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=20200729151208.27737-5-lukasz.luba@arm.com \
--to=lukasz.luba@arm.com \
--cc=cristian.marussi@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rjw@rjwysocki.net \
--cc=sudeep.holla@arm.com \
--cc=viresh.kumar@linaro.org \
/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;
as well as URLs for NNTP newsgroup(s).