Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 490285c6 authored by Viresh Kumar's avatar Viresh Kumar Committed by Rafael J. Wysocki
Browse files

cpufreq: stats: drop unnecessary locking



There is no possibility of any race on updating last_index, trans_table or
total_trans as these are updated only by cpufreq_stat_notifier_trans() which
will be called sequentially.

The only place where locking is still relevant is: cpufreq_stats_update(), which
updates time_in_state and last_time. This can be called by two thread in
parallel, that may result in races.

The two threads being:
- sysfs read of time_in_state
- and frequency transition that calls cpufreq_stat_notifier_trans().

Remove locking from the first case mentioned above.

Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent e7347694
Loading
Loading
Loading
Loading
+1 −5
Original line number Original line Diff line number Diff line
@@ -207,12 +207,10 @@ static int __cpufreq_stats_create_table(struct cpufreq_policy *policy)
	cpufreq_for_each_valid_entry(pos, table)
	cpufreq_for_each_valid_entry(pos, table)
		if (freq_table_get_index(stats, pos->frequency) == -1)
		if (freq_table_get_index(stats, pos->frequency) == -1)
			stats->freq_table[i++] = pos->frequency;
			stats->freq_table[i++] = pos->frequency;
	stats->state_num = i;


	spin_lock(&cpufreq_stats_lock);
	stats->state_num = i;
	stats->last_time = get_jiffies_64();
	stats->last_time = get_jiffies_64();
	stats->last_index = freq_table_get_index(stats, policy->cur);
	stats->last_index = freq_table_get_index(stats, policy->cur);
	spin_unlock(&cpufreq_stats_lock);


	policy->stats = stats;
	policy->stats = stats;
	ret = sysfs_create_group(&policy->kobj, &stats_attr_group);
	ret = sysfs_create_group(&policy->kobj, &stats_attr_group);
@@ -294,13 +292,11 @@ static int cpufreq_stat_notifier_trans(struct notifier_block *nb,


	cpufreq_stats_update(stats);
	cpufreq_stats_update(stats);


	spin_lock(&cpufreq_stats_lock);
	stats->last_index = new_index;
	stats->last_index = new_index;
#ifdef CONFIG_CPU_FREQ_STAT_DETAILS
#ifdef CONFIG_CPU_FREQ_STAT_DETAILS
	stats->trans_table[old_index * stats->max_state + new_index]++;
	stats->trans_table[old_index * stats->max_state + new_index]++;
#endif
#endif
	stats->total_trans++;
	stats->total_trans++;
	spin_unlock(&cpufreq_stats_lock);


put_policy:
put_policy:
	cpufreq_cpu_put(policy);
	cpufreq_cpu_put(policy);