linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Viresh Kumar <viresh.kumar@linaro.org>
To: Rafael Wysocki <rjw@rjwysocki.net>
Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org,
	prarit@redhat.com, skannan@codeaurora.org,
	Viresh Kumar <viresh.kumar@linaro.org>
Subject: [PATCH V3 06/16] cpufreq: stats: pass 'stat' to cpufreq_stats_update()
Date: Tue,  6 Jan 2015 21:09:05 +0530	[thread overview]
Message-ID: <181e3a27d02ce74569478191e6fa84aea73caf6c.1420558386.git.viresh.kumar@linaro.org> (raw)
In-Reply-To: <cover.1420558386.git.viresh.kumar@linaro.org>
In-Reply-To: <cover.1420558386.git.viresh.kumar@linaro.org>

It is better to pass a struct cpufreq_stats pointer to cpufreq_stats_update()
instead of a CPU number, because that's all it needs.

Even if we pass a cpu number to cpufreq_stats_update(), it reads the per-cpu
variable to get 'stats' out of it. So we are doing these operations
unnecessarily:
- First getting the cpu number to pass to cpufreq_stats_update(), stat->cpu.
- And then getting stats from the cpu, per_cpu(cpufreq_stats_table, cpu).

Reviewed-by: Prarit Bhargava <prarit@redhat.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/cpufreq/cpufreq_stats.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
index e9d68420b876..6c234f548601 100644
--- a/drivers/cpufreq/cpufreq_stats.c
+++ b/drivers/cpufreq/cpufreq_stats.c
@@ -33,13 +33,11 @@ struct cpufreq_stats {
 
 static DEFINE_PER_CPU(struct cpufreq_stats *, cpufreq_stats_table);
 
-static int cpufreq_stats_update(unsigned int cpu)
+static int cpufreq_stats_update(struct cpufreq_stats *stat)
 {
-	struct cpufreq_stats *stat;
 	unsigned long long cur_time = get_jiffies_64();
 
 	spin_lock(&cpufreq_stats_lock);
-	stat = per_cpu(cpufreq_stats_table, cpu);
 	if (stat->time_in_state)
 		stat->time_in_state[stat->last_index] +=
 			cur_time - stat->last_time;
@@ -64,7 +62,7 @@ static ssize_t show_time_in_state(struct cpufreq_policy *policy, char *buf)
 	struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, policy->cpu);
 	if (!stat)
 		return 0;
-	cpufreq_stats_update(stat->cpu);
+	cpufreq_stats_update(stat);
 	for (i = 0; i < stat->state_num; i++) {
 		len += sprintf(buf + len, "%u %llu\n", stat->freq_table[i],
 			(unsigned long long)
@@ -82,7 +80,7 @@ static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf)
 	struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, policy->cpu);
 	if (!stat)
 		return 0;
-	cpufreq_stats_update(stat->cpu);
+	cpufreq_stats_update(stat);
 	len += snprintf(buf + len, PAGE_SIZE - len, "   From  :    To\n");
 	len += snprintf(buf + len, PAGE_SIZE - len, "         : ");
 	for (i = 0; i < stat->state_num; i++) {
@@ -307,7 +305,7 @@ static int cpufreq_stat_notifier_trans(struct notifier_block *nb,
 	if (old_index == -1 || new_index == -1)
 		return 0;
 
-	cpufreq_stats_update(freq->cpu);
+	cpufreq_stats_update(stat);
 
 	if (old_index == new_index)
 		return 0;
-- 
2.2.0


  parent reply	other threads:[~2015-01-06 15:39 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-06 15:38 [PATCH V3 00/16] cpufreq: stats: cleanups Viresh Kumar
2015-01-06 15:39 ` [PATCH V3 01/16] cpufreq: stats: Improve module description string Viresh Kumar
2015-01-06 15:39 ` [PATCH V3 02/16] cpufreq: stats: return -EEXIST when stats are already allocated Viresh Kumar
2015-01-06 15:39 ` [PATCH V3 03/16] cpufreq: stats: remove unused cpufreq_stats_attribute Viresh Kumar
2015-01-06 15:39 ` [PATCH V3 04/16] cpufreq: stats: initialize 'cur_time' on its definition Viresh Kumar
2015-01-06 15:39 ` [PATCH V3 05/16] cpufreq: stats: don't check for freq table while freeing stats Viresh Kumar
2015-01-06 15:39 ` Viresh Kumar [this message]
2015-01-06 15:39 ` [PATCH V3 07/16] cpufreq: stats: get rid of per-cpu cpufreq_stats_table Viresh Kumar
2015-01-13  6:04   ` [PATCH V3 Resend " Viresh Kumar
2015-01-06 15:39 ` [PATCH V3 08/16] cpufreq: stats: rename 'struct cpufreq_stats' objects as 'stats' Viresh Kumar
2015-01-06 15:39 ` [PATCH V3 09/16] cpufreq: Remove (now) unused 'last_cpu' from struct cpufreq_policy Viresh Kumar
2015-01-06 15:39 ` [PATCH V3 10/16] cpufreq: stats: drop 'cpu' field of struct cpufreq_stats Viresh Kumar
2015-01-06 15:39 ` [PATCH V3 11/16] cpufreq: remove CPUFREQ_UPDATE_POLICY_CPU notifications Viresh Kumar
2015-01-06 15:39 ` [PATCH V3 12/16] cpufreq: stats: create sysfs group once we are ready Viresh Kumar
2015-01-06 15:39 ` [PATCH V3 13/16] cpufreq: stats: time_in_state can't be NULL in cpufreq_stats_update() Viresh Kumar
2015-01-06 15:39 ` [PATCH V3 14/16] cpufreq: stats: don't update stats from show_trans_table() Viresh Kumar
2015-01-06 15:39 ` [PATCH V3 15/16] cpufreq: stats: don't update stats on false notifiers Viresh Kumar
2015-01-06 15:39 ` [PATCH V3 16/16] cpufreq: stats: drop unnecessary locking Viresh Kumar
2015-01-12  6:12 ` [PATCH V3 00/16] cpufreq: stats: cleanups Viresh Kumar

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=181e3a27d02ce74569478191e6fa84aea73caf6c.1420558386.git.viresh.kumar@linaro.org \
    --to=viresh.kumar@linaro.org \
    --cc=linaro-kernel@lists.linaro.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=prarit@redhat.com \
    --cc=rjw@rjwysocki.net \
    --cc=skannan@codeaurora.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).