diff options
-rw-r--r-- | drivers/cpufreq/cpufreq_stats.c | 74 |
1 files changed, 35 insertions, 39 deletions
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c index c0ff97d375d7..5a62d678dd19 100644 --- a/drivers/cpufreq/cpufreq_stats.c +++ b/drivers/cpufreq/cpufreq_stats.c | |||
@@ -2,7 +2,7 @@ | |||
2 | * drivers/cpufreq/cpufreq_stats.c | 2 | * drivers/cpufreq/cpufreq_stats.c |
3 | * | 3 | * |
4 | * Copyright (C) 2003-2004 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>. | 4 | * Copyright (C) 2003-2004 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>. |
5 | * (C) 2004 Zou Nan hai <nanhai.zou@intel.com>. | 5 | * (C) 2004 Zou Nan hai <nanhai.zou@intel.com>. |
6 | * | 6 | * |
7 | * This program is free software; you can redistribute it and/or modify | 7 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License version 2 as | 8 | * it under the terms of the GNU General Public License version 2 as |
@@ -23,7 +23,7 @@ | |||
23 | 23 | ||
24 | static spinlock_t cpufreq_stats_lock; | 24 | static spinlock_t cpufreq_stats_lock; |
25 | 25 | ||
26 | #define CPUFREQ_STATDEVICE_ATTR(_name,_mode,_show) \ | 26 | #define CPUFREQ_STATDEVICE_ATTR(_name, _mode, _show) \ |
27 | static struct freq_attr _attr_##_name = {\ | 27 | static struct freq_attr _attr_##_name = {\ |
28 | .attr = {.name = __stringify(_name), .mode = _mode, }, \ | 28 | .attr = {.name = __stringify(_name), .mode = _mode, }, \ |
29 | .show = _show,\ | 29 | .show = _show,\ |
@@ -50,8 +50,7 @@ struct cpufreq_stats_attribute { | |||
50 | ssize_t(*show) (struct cpufreq_stats *, char *); | 50 | ssize_t(*show) (struct cpufreq_stats *, char *); |
51 | }; | 51 | }; |
52 | 52 | ||
53 | static int | 53 | static int cpufreq_stats_update(unsigned int cpu) |
54 | cpufreq_stats_update (unsigned int cpu) | ||
55 | { | 54 | { |
56 | struct cpufreq_stats *stat; | 55 | struct cpufreq_stats *stat; |
57 | unsigned long long cur_time; | 56 | unsigned long long cur_time; |
@@ -68,8 +67,7 @@ cpufreq_stats_update (unsigned int cpu) | |||
68 | return 0; | 67 | return 0; |
69 | } | 68 | } |
70 | 69 | ||
71 | static ssize_t | 70 | static ssize_t show_total_trans(struct cpufreq_policy *policy, char *buf) |
72 | show_total_trans(struct cpufreq_policy *policy, char *buf) | ||
73 | { | 71 | { |
74 | struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, policy->cpu); | 72 | struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, policy->cpu); |
75 | if (!stat) | 73 | if (!stat) |
@@ -78,8 +76,7 @@ show_total_trans(struct cpufreq_policy *policy, char *buf) | |||
78 | per_cpu(cpufreq_stats_table, stat->cpu)->total_trans); | 76 | per_cpu(cpufreq_stats_table, stat->cpu)->total_trans); |
79 | } | 77 | } |
80 | 78 | ||
81 | static ssize_t | 79 | static ssize_t show_time_in_state(struct cpufreq_policy *policy, char *buf) |
82 | show_time_in_state(struct cpufreq_policy *policy, char *buf) | ||
83 | { | 80 | { |
84 | ssize_t len = 0; | 81 | ssize_t len = 0; |
85 | int i; | 82 | int i; |
@@ -89,14 +86,14 @@ show_time_in_state(struct cpufreq_policy *policy, char *buf) | |||
89 | cpufreq_stats_update(stat->cpu); | 86 | cpufreq_stats_update(stat->cpu); |
90 | for (i = 0; i < stat->state_num; i++) { | 87 | for (i = 0; i < stat->state_num; i++) { |
91 | len += sprintf(buf + len, "%u %llu\n", stat->freq_table[i], | 88 | len += sprintf(buf + len, "%u %llu\n", stat->freq_table[i], |
92 | (unsigned long long)cputime64_to_clock_t(stat->time_in_state[i])); | 89 | (unsigned long long) |
90 | cputime64_to_clock_t(stat->time_in_state[i])); | ||
93 | } | 91 | } |
94 | return len; | 92 | return len; |
95 | } | 93 | } |
96 | 94 | ||
97 | #ifdef CONFIG_CPU_FREQ_STAT_DETAILS | 95 | #ifdef CONFIG_CPU_FREQ_STAT_DETAILS |
98 | static ssize_t | 96 | static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf) |
99 | show_trans_table(struct cpufreq_policy *policy, char *buf) | ||
100 | { | 97 | { |
101 | ssize_t len = 0; | 98 | ssize_t len = 0; |
102 | int i, j; | 99 | int i, j; |
@@ -139,11 +136,11 @@ show_trans_table(struct cpufreq_policy *policy, char *buf) | |||
139 | return PAGE_SIZE; | 136 | return PAGE_SIZE; |
140 | return len; | 137 | return len; |
141 | } | 138 | } |
142 | CPUFREQ_STATDEVICE_ATTR(trans_table,0444,show_trans_table); | 139 | CPUFREQ_STATDEVICE_ATTR(trans_table, 0444, show_trans_table); |
143 | #endif | 140 | #endif |
144 | 141 | ||
145 | CPUFREQ_STATDEVICE_ATTR(total_trans,0444,show_total_trans); | 142 | CPUFREQ_STATDEVICE_ATTR(total_trans, 0444, show_total_trans); |
146 | CPUFREQ_STATDEVICE_ATTR(time_in_state,0444,show_time_in_state); | 143 | CPUFREQ_STATDEVICE_ATTR(time_in_state, 0444, show_time_in_state); |
147 | 144 | ||
148 | static struct attribute *default_attrs[] = { | 145 | static struct attribute *default_attrs[] = { |
149 | &_attr_total_trans.attr, | 146 | &_attr_total_trans.attr, |
@@ -158,8 +155,7 @@ static struct attribute_group stats_attr_group = { | |||
158 | .name = "stats" | 155 | .name = "stats" |
159 | }; | 156 | }; |
160 | 157 | ||
161 | static int | 158 | static int freq_table_get_index(struct cpufreq_stats *stat, unsigned int freq) |
162 | freq_table_get_index(struct cpufreq_stats *stat, unsigned int freq) | ||
163 | { | 159 | { |
164 | int index; | 160 | int index; |
165 | for (index = 0; index < stat->max_state; index++) | 161 | for (index = 0; index < stat->max_state; index++) |
@@ -183,8 +179,7 @@ static void cpufreq_stats_free_table(unsigned int cpu) | |||
183 | cpufreq_cpu_put(policy); | 179 | cpufreq_cpu_put(policy); |
184 | } | 180 | } |
185 | 181 | ||
186 | static int | 182 | static int cpufreq_stats_create_table(struct cpufreq_policy *policy, |
187 | cpufreq_stats_create_table (struct cpufreq_policy *policy, | ||
188 | struct cpufreq_frequency_table *table) | 183 | struct cpufreq_frequency_table *table) |
189 | { | 184 | { |
190 | unsigned int i, j, count = 0, ret = 0; | 185 | unsigned int i, j, count = 0, ret = 0; |
@@ -194,7 +189,8 @@ cpufreq_stats_create_table (struct cpufreq_policy *policy, | |||
194 | unsigned int cpu = policy->cpu; | 189 | unsigned int cpu = policy->cpu; |
195 | if (per_cpu(cpufreq_stats_table, cpu)) | 190 | if (per_cpu(cpufreq_stats_table, cpu)) |
196 | return -EBUSY; | 191 | return -EBUSY; |
197 | if ((stat = kzalloc(sizeof(struct cpufreq_stats), GFP_KERNEL)) == NULL) | 192 | stat = kzalloc(sizeof(struct cpufreq_stats), GFP_KERNEL); |
193 | if ((stat) == NULL) | ||
198 | return -ENOMEM; | 194 | return -ENOMEM; |
199 | 195 | ||
200 | data = cpufreq_cpu_get(cpu); | 196 | data = cpufreq_cpu_get(cpu); |
@@ -203,13 +199,14 @@ cpufreq_stats_create_table (struct cpufreq_policy *policy, | |||
203 | goto error_get_fail; | 199 | goto error_get_fail; |
204 | } | 200 | } |
205 | 201 | ||
206 | if ((ret = sysfs_create_group(&data->kobj, &stats_attr_group))) | 202 | ret = sysfs_create_group(&data->kobj, &stats_attr_group); |
203 | if (ret) | ||
207 | goto error_out; | 204 | goto error_out; |
208 | 205 | ||
209 | stat->cpu = cpu; | 206 | stat->cpu = cpu; |
210 | per_cpu(cpufreq_stats_table, cpu) = stat; | 207 | per_cpu(cpufreq_stats_table, cpu) = stat; |
211 | 208 | ||
212 | for (i=0; table[i].frequency != CPUFREQ_TABLE_END; i++) { | 209 | for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) { |
213 | unsigned int freq = table[i].frequency; | 210 | unsigned int freq = table[i].frequency; |
214 | if (freq == CPUFREQ_ENTRY_INVALID) | 211 | if (freq == CPUFREQ_ENTRY_INVALID) |
215 | continue; | 212 | continue; |
@@ -255,9 +252,8 @@ error_get_fail: | |||
255 | return ret; | 252 | return ret; |
256 | } | 253 | } |
257 | 254 | ||
258 | static int | 255 | static int cpufreq_stat_notifier_policy(struct notifier_block *nb, |
259 | cpufreq_stat_notifier_policy (struct notifier_block *nb, unsigned long val, | 256 | unsigned long val, void *data) |
260 | void *data) | ||
261 | { | 257 | { |
262 | int ret; | 258 | int ret; |
263 | struct cpufreq_policy *policy = data; | 259 | struct cpufreq_policy *policy = data; |
@@ -268,14 +264,14 @@ cpufreq_stat_notifier_policy (struct notifier_block *nb, unsigned long val, | |||
268 | table = cpufreq_frequency_get_table(cpu); | 264 | table = cpufreq_frequency_get_table(cpu); |
269 | if (!table) | 265 | if (!table) |
270 | return 0; | 266 | return 0; |
271 | if ((ret = cpufreq_stats_create_table(policy, table))) | 267 | ret = cpufreq_stats_create_table(policy, table); |
268 | if (ret) | ||
272 | return ret; | 269 | return ret; |
273 | return 0; | 270 | return 0; |
274 | } | 271 | } |
275 | 272 | ||
276 | static int | 273 | static int cpufreq_stat_notifier_trans(struct notifier_block *nb, |
277 | cpufreq_stat_notifier_trans (struct notifier_block *nb, unsigned long val, | 274 | unsigned long val, void *data) |
278 | void *data) | ||
279 | { | 275 | { |
280 | struct cpufreq_freqs *freq = data; | 276 | struct cpufreq_freqs *freq = data; |
281 | struct cpufreq_stats *stat; | 277 | struct cpufreq_stats *stat; |
@@ -340,19 +336,20 @@ static struct notifier_block notifier_trans_block = { | |||
340 | .notifier_call = cpufreq_stat_notifier_trans | 336 | .notifier_call = cpufreq_stat_notifier_trans |
341 | }; | 337 | }; |
342 | 338 | ||
343 | static int | 339 | static int __init cpufreq_stats_init(void) |
344 | __init cpufreq_stats_init(void) | ||
345 | { | 340 | { |
346 | int ret; | 341 | int ret; |
347 | unsigned int cpu; | 342 | unsigned int cpu; |
348 | 343 | ||
349 | spin_lock_init(&cpufreq_stats_lock); | 344 | spin_lock_init(&cpufreq_stats_lock); |
350 | if ((ret = cpufreq_register_notifier(¬ifier_policy_block, | 345 | ret = cpufreq_register_notifier(¬ifier_policy_block, |
351 | CPUFREQ_POLICY_NOTIFIER))) | 346 | CPUFREQ_POLICY_NOTIFIER); |
347 | if (ret) | ||
352 | return ret; | 348 | return ret; |
353 | 349 | ||
354 | if ((ret = cpufreq_register_notifier(¬ifier_trans_block, | 350 | ret = cpufreq_register_notifier(¬ifier_trans_block, |
355 | CPUFREQ_TRANSITION_NOTIFIER))) { | 351 | CPUFREQ_TRANSITION_NOTIFIER); |
352 | if (ret) { | ||
356 | cpufreq_unregister_notifier(¬ifier_policy_block, | 353 | cpufreq_unregister_notifier(¬ifier_policy_block, |
357 | CPUFREQ_POLICY_NOTIFIER); | 354 | CPUFREQ_POLICY_NOTIFIER); |
358 | return ret; | 355 | return ret; |
@@ -364,8 +361,7 @@ __init cpufreq_stats_init(void) | |||
364 | } | 361 | } |
365 | return 0; | 362 | return 0; |
366 | } | 363 | } |
367 | static void | 364 | static void __exit cpufreq_stats_exit(void) |
368 | __exit cpufreq_stats_exit(void) | ||
369 | { | 365 | { |
370 | unsigned int cpu; | 366 | unsigned int cpu; |
371 | 367 | ||
@@ -379,10 +375,10 @@ __exit cpufreq_stats_exit(void) | |||
379 | } | 375 | } |
380 | } | 376 | } |
381 | 377 | ||
382 | MODULE_AUTHOR ("Zou Nan hai <nanhai.zou@intel.com>"); | 378 | MODULE_AUTHOR("Zou Nan hai <nanhai.zou@intel.com>"); |
383 | MODULE_DESCRIPTION ("'cpufreq_stats' - A driver to export cpufreq stats " | 379 | MODULE_DESCRIPTION("'cpufreq_stats' - A driver to export cpufreq stats " |
384 | "through sysfs filesystem"); | 380 | "through sysfs filesystem"); |
385 | MODULE_LICENSE ("GPL"); | 381 | MODULE_LICENSE("GPL"); |
386 | 382 | ||
387 | module_init(cpufreq_stats_init); | 383 | module_init(cpufreq_stats_init); |
388 | module_exit(cpufreq_stats_exit); | 384 | module_exit(cpufreq_stats_exit); |