diff options
Diffstat (limited to 'drivers/cpufreq/cpufreq_stats.c')
-rw-r--r-- | drivers/cpufreq/cpufreq_stats.c | 38 |
1 files changed, 13 insertions, 25 deletions
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c index 5793e1447fb1..eb214d83ad6b 100644 --- a/drivers/cpufreq/cpufreq_stats.c +++ b/drivers/cpufreq/cpufreq_stats.c | |||
@@ -180,27 +180,25 @@ static void cpufreq_stats_free_table(unsigned int cpu) | |||
180 | cpufreq_cpu_put(policy); | 180 | cpufreq_cpu_put(policy); |
181 | } | 181 | } |
182 | 182 | ||
183 | static int __cpufreq_stats_create_table(struct cpufreq_policy *policy, | 183 | static int __cpufreq_stats_create_table(struct cpufreq_policy *policy) |
184 | struct cpufreq_frequency_table *table) | ||
185 | { | 184 | { |
186 | unsigned int i, j, count = 0, ret = 0; | 185 | unsigned int i, j, count = 0, ret = 0; |
187 | struct cpufreq_stats *stat; | 186 | struct cpufreq_stats *stat; |
188 | struct cpufreq_policy *current_policy; | ||
189 | unsigned int alloc_size; | 187 | unsigned int alloc_size; |
190 | unsigned int cpu = policy->cpu; | 188 | unsigned int cpu = policy->cpu; |
189 | struct cpufreq_frequency_table *table; | ||
190 | |||
191 | table = cpufreq_frequency_get_table(cpu); | ||
192 | if (unlikely(!table)) | ||
193 | return 0; | ||
194 | |||
191 | if (per_cpu(cpufreq_stats_table, cpu)) | 195 | if (per_cpu(cpufreq_stats_table, cpu)) |
192 | return -EBUSY; | 196 | return -EBUSY; |
193 | stat = kzalloc(sizeof(*stat), GFP_KERNEL); | 197 | stat = kzalloc(sizeof(*stat), GFP_KERNEL); |
194 | if ((stat) == NULL) | 198 | if ((stat) == NULL) |
195 | return -ENOMEM; | 199 | return -ENOMEM; |
196 | 200 | ||
197 | current_policy = cpufreq_cpu_get(cpu); | 201 | ret = sysfs_create_group(&policy->kobj, &stats_attr_group); |
198 | if (current_policy == NULL) { | ||
199 | ret = -EINVAL; | ||
200 | goto error_get_fail; | ||
201 | } | ||
202 | |||
203 | ret = sysfs_create_group(¤t_policy->kobj, &stats_attr_group); | ||
204 | if (ret) | 202 | if (ret) |
205 | goto error_out; | 203 | goto error_out; |
206 | 204 | ||
@@ -223,7 +221,7 @@ static int __cpufreq_stats_create_table(struct cpufreq_policy *policy, | |||
223 | stat->time_in_state = kzalloc(alloc_size, GFP_KERNEL); | 221 | stat->time_in_state = kzalloc(alloc_size, GFP_KERNEL); |
224 | if (!stat->time_in_state) { | 222 | if (!stat->time_in_state) { |
225 | ret = -ENOMEM; | 223 | ret = -ENOMEM; |
226 | goto error_out; | 224 | goto error_alloc; |
227 | } | 225 | } |
228 | stat->freq_table = (unsigned int *)(stat->time_in_state + count); | 226 | stat->freq_table = (unsigned int *)(stat->time_in_state + count); |
229 | 227 | ||
@@ -243,11 +241,10 @@ static int __cpufreq_stats_create_table(struct cpufreq_policy *policy, | |||
243 | stat->last_time = get_jiffies_64(); | 241 | stat->last_time = get_jiffies_64(); |
244 | stat->last_index = freq_table_get_index(stat, policy->cur); | 242 | stat->last_index = freq_table_get_index(stat, policy->cur); |
245 | spin_unlock(&cpufreq_stats_lock); | 243 | spin_unlock(&cpufreq_stats_lock); |
246 | cpufreq_cpu_put(current_policy); | ||
247 | return 0; | 244 | return 0; |
245 | error_alloc: | ||
246 | sysfs_remove_group(&policy->kobj, &stats_attr_group); | ||
248 | error_out: | 247 | error_out: |
249 | cpufreq_cpu_put(current_policy); | ||
250 | error_get_fail: | ||
251 | kfree(stat); | 248 | kfree(stat); |
252 | per_cpu(cpufreq_stats_table, cpu) = NULL; | 249 | per_cpu(cpufreq_stats_table, cpu) = NULL; |
253 | return ret; | 250 | return ret; |
@@ -256,7 +253,6 @@ error_get_fail: | |||
256 | static void cpufreq_stats_create_table(unsigned int cpu) | 253 | static void cpufreq_stats_create_table(unsigned int cpu) |
257 | { | 254 | { |
258 | struct cpufreq_policy *policy; | 255 | struct cpufreq_policy *policy; |
259 | struct cpufreq_frequency_table *table; | ||
260 | 256 | ||
261 | /* | 257 | /* |
262 | * "likely(!policy)" because normally cpufreq_stats will be registered | 258 | * "likely(!policy)" because normally cpufreq_stats will be registered |
@@ -266,9 +262,7 @@ static void cpufreq_stats_create_table(unsigned int cpu) | |||
266 | if (likely(!policy)) | 262 | if (likely(!policy)) |
267 | return; | 263 | return; |
268 | 264 | ||
269 | table = cpufreq_frequency_get_table(policy->cpu); | 265 | __cpufreq_stats_create_table(policy); |
270 | if (likely(table)) | ||
271 | __cpufreq_stats_create_table(policy, table); | ||
272 | 266 | ||
273 | cpufreq_cpu_put(policy); | 267 | cpufreq_cpu_put(policy); |
274 | } | 268 | } |
@@ -291,20 +285,14 @@ static int cpufreq_stat_notifier_policy(struct notifier_block *nb, | |||
291 | { | 285 | { |
292 | int ret = 0; | 286 | int ret = 0; |
293 | struct cpufreq_policy *policy = data; | 287 | struct cpufreq_policy *policy = data; |
294 | struct cpufreq_frequency_table *table; | ||
295 | unsigned int cpu = policy->cpu; | ||
296 | 288 | ||
297 | if (val == CPUFREQ_UPDATE_POLICY_CPU) { | 289 | if (val == CPUFREQ_UPDATE_POLICY_CPU) { |
298 | cpufreq_stats_update_policy_cpu(policy); | 290 | cpufreq_stats_update_policy_cpu(policy); |
299 | return 0; | 291 | return 0; |
300 | } | 292 | } |
301 | 293 | ||
302 | table = cpufreq_frequency_get_table(cpu); | ||
303 | if (!table) | ||
304 | return 0; | ||
305 | |||
306 | if (val == CPUFREQ_CREATE_POLICY) | 294 | if (val == CPUFREQ_CREATE_POLICY) |
307 | ret = __cpufreq_stats_create_table(policy, table); | 295 | ret = __cpufreq_stats_create_table(policy); |
308 | else if (val == CPUFREQ_REMOVE_POLICY) | 296 | else if (val == CPUFREQ_REMOVE_POLICY) |
309 | __cpufreq_stats_free_table(policy); | 297 | __cpufreq_stats_free_table(policy); |
310 | 298 | ||