@@ -39,12 +39,10 @@ static int cpufreq_stats_update(struct cpufreq_stats *stat)
{
unsigned long long cur_time = get_jiffies_64();
- spin_lock(&cpufreq_stats_lock);
if (stat->time_in_state)
stat->time_in_state[stat->last_index] +=
cur_time - stat->last_time;
stat->last_time = cur_time;
- spin_unlock(&cpufreq_stats_lock);
return 0;
}
@@ -61,7 +59,10 @@ static ssize_t show_time_in_state(struct cpufreq_policy *policy, char *buf)
ssize_t len = 0;
int i;
+ spin_lock(&cpufreq_stats_lock);
cpufreq_stats_update(stat);
+ spin_unlock(&cpufreq_stats_lock);
+
for (i = 0; i < stat->state_num; i++) {
len += sprintf(buf + len, "%u %llu\n", stat->freq_table[i],
(unsigned long long)
@@ -302,9 +303,9 @@ static int cpufreq_stat_notifier_trans(struct notifier_block *nb,
if (old_index == new_index)
return 0;
+ spin_lock(&cpufreq_stats_lock);
cpufreq_stats_update(stat);
- spin_lock(&cpufreq_stats_lock);
stat->last_index = new_index;
#ifdef CONFIG_CPU_FREQ_STAT_DETAILS
stat->trans_table[old_index * stat->max_state + new_index]++;
cpufreq_stats_update() has only two callers, one of them is already taking locks and other one don't. To make locking efficient for cpufreq_stat_notifier_trans(), lets call cpufreq_stats_update() from within locks. Also update show_time_in_state() to call cpufreq_stats_update() after taking locks. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> --- drivers/cpufreq/cpufreq_stats.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)