cpufreq: stats: Refactor common code into __cpufreq_stats_create_table()
cpufreq_frequency_get_table() is called from all callers of __cpufreq_stats_create_table(). So, move it inside. Suggested-by: Viresh Kumar <viresh.kumar@linaro.org> Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Saravana Kannan <skannan@codeaurora.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
		
					parent
					
						
							
								0b7528d963
							
						
					
				
			
			
				commit
				
					
						ad4c2302c2
					
				
			
		
					 1 changed files with 9 additions and 13 deletions
				
			
		| 
						 | 
					@ -180,13 +180,18 @@ static void cpufreq_stats_free_table(unsigned int cpu)
 | 
				
			||||||
	cpufreq_cpu_put(policy);
 | 
						cpufreq_cpu_put(policy);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int __cpufreq_stats_create_table(struct cpufreq_policy *policy,
 | 
					static int __cpufreq_stats_create_table(struct cpufreq_policy *policy)
 | 
				
			||||||
		struct cpufreq_frequency_table *table)
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	unsigned int i, j, count = 0, ret = 0;
 | 
						unsigned int i, j, count = 0, ret = 0;
 | 
				
			||||||
	struct cpufreq_stats *stat;
 | 
						struct cpufreq_stats *stat;
 | 
				
			||||||
	unsigned int alloc_size;
 | 
						unsigned int alloc_size;
 | 
				
			||||||
	unsigned int cpu = policy->cpu;
 | 
						unsigned int cpu = policy->cpu;
 | 
				
			||||||
 | 
						struct cpufreq_frequency_table *table;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						table = cpufreq_frequency_get_table(cpu);
 | 
				
			||||||
 | 
						if (unlikely(!table))
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (per_cpu(cpufreq_stats_table, cpu))
 | 
						if (per_cpu(cpufreq_stats_table, cpu))
 | 
				
			||||||
		return -EBUSY;
 | 
							return -EBUSY;
 | 
				
			||||||
	stat = kzalloc(sizeof(*stat), GFP_KERNEL);
 | 
						stat = kzalloc(sizeof(*stat), GFP_KERNEL);
 | 
				
			||||||
| 
						 | 
					@ -248,7 +253,6 @@ error_out:
 | 
				
			||||||
static void cpufreq_stats_create_table(unsigned int cpu)
 | 
					static void cpufreq_stats_create_table(unsigned int cpu)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct cpufreq_policy *policy;
 | 
						struct cpufreq_policy *policy;
 | 
				
			||||||
	struct cpufreq_frequency_table *table;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * "likely(!policy)" because normally cpufreq_stats will be registered
 | 
						 * "likely(!policy)" because normally cpufreq_stats will be registered
 | 
				
			||||||
| 
						 | 
					@ -258,9 +262,7 @@ static void cpufreq_stats_create_table(unsigned int cpu)
 | 
				
			||||||
	if (likely(!policy))
 | 
						if (likely(!policy))
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	table = cpufreq_frequency_get_table(policy->cpu);
 | 
						__cpufreq_stats_create_table(policy);
 | 
				
			||||||
	if (likely(table))
 | 
					 | 
				
			||||||
		__cpufreq_stats_create_table(policy, table);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cpufreq_cpu_put(policy);
 | 
						cpufreq_cpu_put(policy);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -283,20 +285,14 @@ static int cpufreq_stat_notifier_policy(struct notifier_block *nb,
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int ret = 0;
 | 
						int ret = 0;
 | 
				
			||||||
	struct cpufreq_policy *policy = data;
 | 
						struct cpufreq_policy *policy = data;
 | 
				
			||||||
	struct cpufreq_frequency_table *table;
 | 
					 | 
				
			||||||
	unsigned int cpu = policy->cpu;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (val == CPUFREQ_UPDATE_POLICY_CPU) {
 | 
						if (val == CPUFREQ_UPDATE_POLICY_CPU) {
 | 
				
			||||||
		cpufreq_stats_update_policy_cpu(policy);
 | 
							cpufreq_stats_update_policy_cpu(policy);
 | 
				
			||||||
		return 0;
 | 
							return 0;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	table = cpufreq_frequency_get_table(cpu);
 | 
					 | 
				
			||||||
	if (!table)
 | 
					 | 
				
			||||||
		return 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (val == CPUFREQ_CREATE_POLICY)
 | 
						if (val == CPUFREQ_CREATE_POLICY)
 | 
				
			||||||
		ret = __cpufreq_stats_create_table(policy, table);
 | 
							ret = __cpufreq_stats_create_table(policy);
 | 
				
			||||||
	else if (val == CPUFREQ_REMOVE_POLICY)
 | 
						else if (val == CPUFREQ_REMOVE_POLICY)
 | 
				
			||||||
		__cpufreq_stats_free_table(policy);
 | 
							__cpufreq_stats_free_table(policy);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue