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

Commit 38bfa262 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "cpufreq: persistent_stats: Synchronize access to time_in_state"

parents 933fe75d 87fb7c50
Loading
Loading
Loading
Loading
+43 −25
Original line number Diff line number Diff line
@@ -132,9 +132,13 @@ static int freq_table_get_index(
		unsigned int freq)
{
	int index;

	if (stats->freq_table) {
		for (index = 0; index < stats->max_state; index++)
			if (stats->freq_table[index] == freq)
				return index;
	}

	return -ENOENT;
}

@@ -161,6 +165,8 @@ static int cpufreq_stats_create_table(unsigned int cpu,
	unsigned long irq_flags;
	struct cpufreq_frequency_table *table =
		cpufreq_frequency_get_table(policy->cpu);
	void *temp_time_in_state;
	int next_freq_index;

	if (unlikely(!table))
		return -EINVAL;
@@ -176,12 +182,16 @@ static int cpufreq_stats_create_table(unsigned int cpu,
	}

	alloc_size = count * sizeof(int) + count * sizeof(cputime64_t);
	cpu_stats->max_state = count;
	cpu_stats->time_in_state = kzalloc(alloc_size, GFP_KERNEL);
	temp_time_in_state = kzalloc(alloc_size, GFP_KERNEL);

	if (!cpu_stats->time_in_state)
	if (!temp_time_in_state)
		return -ENOMEM;

	spin_lock_irqsave(&cpufreq_stats_lock, irq_flags);

	if (!cpu_stats->time_in_state) {
		cpu_stats->time_in_state = temp_time_in_state;
		cpu_stats->max_state = count;
		cpu_stats->freq_table =
			(unsigned int *)(cpu_stats->time_in_state + count);

@@ -192,12 +202,16 @@ static int cpufreq_stats_create_table(unsigned int cpu,
				continue;
			cpu_stats->freq_table[k++] = freq;
		}
	} else
		kfree(temp_time_in_state);

	spin_lock_irqsave(&cpufreq_stats_lock, irq_flags);
	next_freq_index = freq_table_get_index(
			cpu_stats, policy->cur);

	if (next_freq_index != -ENOENT) {
		cpu_stats->last_time = get_jiffies_64();
	cpu_stats->last_index = freq_table_get_index(
			cpu_stats, policy->cur);
		cpu_stats->last_index = next_freq_index;
	}

	spin_unlock_irqrestore(&cpufreq_stats_lock, irq_flags);

@@ -214,6 +228,7 @@ static int cpufreq_stat_notifier_trans(struct notifier_block *nb,
		freq->cpu);
	unsigned long irq_flags;
	unsigned int cpu;
	int next_freq_index;

	if (val != CPUFREQ_POSTCHANGE)
		return 0;
@@ -234,14 +249,17 @@ static int cpufreq_stat_notifier_trans(struct notifier_block *nb,

	for_each_cpu(cpu, policy->cpus) {
		cpu_stats = &per_cpu(pcpu_stats, cpu);
		next_freq_index = freq_table_get_index(cpu_stats,
				freq->new);

		if (next_freq_index != -ENOENT) {
			if (cpu_online(cpu)) {
				cpufreq_stats_update(cpu);
				cpu_stats->last_time = get_jiffies_64();
			}

		cpu_stats->last_index = freq_table_get_index(cpu_stats,
				freq->new);
			cpu_stats->last_index = next_freq_index;
		}
	}

	spin_unlock_irqrestore(&cpufreq_stats_lock, irq_flags);