Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Viresh Kumar and committed by
Rafael J. Wysocki
490285c6 e7347694

+1 -5
+1 -5
drivers/cpufreq/cpufreq_stats.c
··· 207 207 cpufreq_for_each_valid_entry(pos, table) 208 208 if (freq_table_get_index(stats, pos->frequency) == -1) 209 209 stats->freq_table[i++] = pos->frequency; 210 - stats->state_num = i; 211 210 212 - spin_lock(&cpufreq_stats_lock); 211 + stats->state_num = i; 213 212 stats->last_time = get_jiffies_64(); 214 213 stats->last_index = freq_table_get_index(stats, policy->cur); 215 - spin_unlock(&cpufreq_stats_lock); 216 214 217 215 policy->stats = stats; 218 216 ret = sysfs_create_group(&policy->kobj, &stats_attr_group); ··· 292 294 293 295 cpufreq_stats_update(stats); 294 296 295 - spin_lock(&cpufreq_stats_lock); 296 297 stats->last_index = new_index; 297 298 #ifdef CONFIG_CPU_FREQ_STAT_DETAILS 298 299 stats->trans_table[old_index * stats->max_state + new_index]++; 299 300 #endif 300 301 stats->total_trans++; 301 - spin_unlock(&cpufreq_stats_lock); 302 302 303 303 put_policy: 304 304 cpufreq_cpu_put(policy);