blob: a2dee4cedf417a8408a97139ab810d54856c5045 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * drivers/cpufreq/cpufreq_stats.c
3 *
4 * Copyright (C) 2003-2004 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>.
Dave Jones0a829c52009-01-18 01:49:04 -05005 * (C) 2004 Zou Nan hai <nanhai.zou@intel.com>.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
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
9 * published by the Free Software Foundation.
10 */
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/kernel.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090013#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/cpu.h>
15#include <linux/sysfs.h>
16#include <linux/cpufreq.h>
Paul Gortmaker5c720d32011-05-27 13:23:32 -040017#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/jiffies.h>
19#include <linux/percpu.h>
20#include <linux/kobject.h>
21#include <linux/spinlock.h>
Ashok Rajc32b6b82005-10-30 14:59:54 -080022#include <linux/notifier.h>
Venkatesh Pallipadi58f1df22005-05-25 14:46:50 -070023#include <asm/cputime.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25static spinlock_t cpufreq_stats_lock;
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027struct cpufreq_stats {
28 unsigned int cpu;
29 unsigned int total_trans;
Venkatesh Pallipadi58f1df22005-05-25 14:46:50 -070030 unsigned long long last_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 unsigned int max_state;
32 unsigned int state_num;
33 unsigned int last_index;
Viresh Kumar1e7586a2012-10-26 00:51:21 +020034 u64 *time_in_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 unsigned int *freq_table;
36#ifdef CONFIG_CPU_FREQ_STAT_DETAILS
37 unsigned int *trans_table;
38#endif
39};
40
Mike Travis7a6aedf2008-03-25 15:06:53 -070041static DEFINE_PER_CPU(struct cpufreq_stats *, cpufreq_stats_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43struct cpufreq_stats_attribute {
44 struct attribute attr;
45 ssize_t(*show) (struct cpufreq_stats *, char *);
46};
47
Dave Jones0a829c52009-01-18 01:49:04 -050048static int cpufreq_stats_update(unsigned int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049{
50 struct cpufreq_stats *stat;
Venkatesh Pallipadi58f1df22005-05-25 14:46:50 -070051 unsigned long long cur_time;
52
53 cur_time = get_jiffies_64();
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 spin_lock(&cpufreq_stats_lock);
Mike Travis7a6aedf2008-03-25 15:06:53 -070055 stat = per_cpu(cpufreq_stats_table, cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 if (stat->time_in_state)
Martin Schwidefsky64861632011-12-15 14:56:09 +010057 stat->time_in_state[stat->last_index] +=
58 cur_time - stat->last_time;
Venkatesh Pallipadi58f1df22005-05-25 14:46:50 -070059 stat->last_time = cur_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 spin_unlock(&cpufreq_stats_lock);
61 return 0;
62}
63
Dave Jones0a829c52009-01-18 01:49:04 -050064static ssize_t show_total_trans(struct cpufreq_policy *policy, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
Mike Travis7a6aedf2008-03-25 15:06:53 -070066 struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, policy->cpu);
Dave Jones511e9ee2006-05-30 17:57:14 -040067 if (!stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 return 0;
69 return sprintf(buf, "%d\n",
Mike Travis7a6aedf2008-03-25 15:06:53 -070070 per_cpu(cpufreq_stats_table, stat->cpu)->total_trans);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071}
72
Dave Jones0a829c52009-01-18 01:49:04 -050073static ssize_t show_time_in_state(struct cpufreq_policy *policy, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
75 ssize_t len = 0;
76 int i;
Mike Travis7a6aedf2008-03-25 15:06:53 -070077 struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, policy->cpu);
Dave Jones511e9ee2006-05-30 17:57:14 -040078 if (!stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 return 0;
80 cpufreq_stats_update(stat->cpu);
81 for (i = 0; i < stat->state_num; i++) {
Dave Jones32ee8c32006-02-28 00:43:23 -050082 len += sprintf(buf + len, "%u %llu\n", stat->freq_table[i],
Dave Jones0a829c52009-01-18 01:49:04 -050083 (unsigned long long)
84 cputime64_to_clock_t(stat->time_in_state[i]));
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 }
86 return len;
87}
88
89#ifdef CONFIG_CPU_FREQ_STAT_DETAILS
Dave Jones0a829c52009-01-18 01:49:04 -050090static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091{
92 ssize_t len = 0;
93 int i, j;
94
Mike Travis7a6aedf2008-03-25 15:06:53 -070095 struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, policy->cpu);
Dave Jones511e9ee2006-05-30 17:57:14 -040096 if (!stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 return 0;
98 cpufreq_stats_update(stat->cpu);
Venkatesh Pallipadi58f1df22005-05-25 14:46:50 -070099 len += snprintf(buf + len, PAGE_SIZE - len, " From : To\n");
100 len += snprintf(buf + len, PAGE_SIZE - len, " : ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 for (i = 0; i < stat->state_num; i++) {
102 if (len >= PAGE_SIZE)
103 break;
Venkatesh Pallipadi58f1df22005-05-25 14:46:50 -0700104 len += snprintf(buf + len, PAGE_SIZE - len, "%9u ",
105 stat->freq_table[i]);
106 }
107 if (len >= PAGE_SIZE)
Cesar Eduardo Barros25aca342008-02-16 08:41:25 -0200108 return PAGE_SIZE;
Venkatesh Pallipadi58f1df22005-05-25 14:46:50 -0700109
110 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
111
112 for (i = 0; i < stat->state_num; i++) {
113 if (len >= PAGE_SIZE)
114 break;
115
116 len += snprintf(buf + len, PAGE_SIZE - len, "%9u: ",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 stat->freq_table[i]);
118
119 for (j = 0; j < stat->state_num; j++) {
120 if (len >= PAGE_SIZE)
121 break;
Venkatesh Pallipadi58f1df22005-05-25 14:46:50 -0700122 len += snprintf(buf + len, PAGE_SIZE - len, "%9u ",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 stat->trans_table[i*stat->max_state+j]);
124 }
Cesar Eduardo Barros25aca342008-02-16 08:41:25 -0200125 if (len >= PAGE_SIZE)
126 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
128 }
Cesar Eduardo Barros25aca342008-02-16 08:41:25 -0200129 if (len >= PAGE_SIZE)
130 return PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 return len;
132}
Viresh Kumardf18e502013-02-04 11:38:52 +0000133cpufreq_freq_attr_ro(trans_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134#endif
135
Viresh Kumardf18e502013-02-04 11:38:52 +0000136cpufreq_freq_attr_ro(total_trans);
137cpufreq_freq_attr_ro(time_in_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139static struct attribute *default_attrs[] = {
Viresh Kumardf18e502013-02-04 11:38:52 +0000140 &total_trans.attr,
141 &time_in_state.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142#ifdef CONFIG_CPU_FREQ_STAT_DETAILS
Viresh Kumardf18e502013-02-04 11:38:52 +0000143 &trans_table.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144#endif
145 NULL
146};
147static struct attribute_group stats_attr_group = {
148 .attrs = default_attrs,
149 .name = "stats"
150};
151
Dave Jones0a829c52009-01-18 01:49:04 -0500152static int freq_table_get_index(struct cpufreq_stats *stat, unsigned int freq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153{
154 int index;
155 for (index = 0; index < stat->max_state; index++)
156 if (stat->freq_table[index] == freq)
157 return index;
158 return -1;
159}
160
steven finney98586ed2011-05-02 11:29:17 -0700161/* should be called late in the CPU removal sequence so that the stats
162 * memory is still available in case someone tries to use it.
163 */
Adrian Bunka3323472007-12-17 16:20:03 -0800164static void cpufreq_stats_free_table(unsigned int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165{
Mike Travis7a6aedf2008-03-25 15:06:53 -0700166 struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, cpu);
Viresh Kumarb8eed8a2013-01-14 13:23:03 +0000167
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 if (stat) {
Viresh Kumarb8eed8a2013-01-14 13:23:03 +0000169 pr_debug("%s: Free stat table\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 kfree(stat->time_in_state);
171 kfree(stat);
Viresh Kumarb8eed8a2013-01-14 13:23:03 +0000172 per_cpu(cpufreq_stats_table, cpu) = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 }
steven finney98586ed2011-05-02 11:29:17 -0700174}
175
176/* must be called early in the CPU removal sequence (before
177 * cpufreq_remove_dev) so that policy is still valid.
178 */
179static void cpufreq_stats_free_sysfs(unsigned int cpu)
180{
181 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
Fabio Baltieri2624f902013-01-31 09:44:40 +0000182 if (policy && !policy_is_shared(policy)) {
Viresh Kumarb8eed8a2013-01-14 13:23:03 +0000183 pr_debug("%s: Free sysfs stat\n", __func__);
steven finney98586ed2011-05-02 11:29:17 -0700184 sysfs_remove_group(&policy->kobj, &stats_attr_group);
Viresh Kumarb8eed8a2013-01-14 13:23:03 +0000185 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 if (policy)
187 cpufreq_cpu_put(policy);
188}
189
Dave Jones0a829c52009-01-18 01:49:04 -0500190static int cpufreq_stats_create_table(struct cpufreq_policy *policy,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 struct cpufreq_frequency_table *table)
192{
193 unsigned int i, j, count = 0, ret = 0;
194 struct cpufreq_stats *stat;
195 struct cpufreq_policy *data;
196 unsigned int alloc_size;
197 unsigned int cpu = policy->cpu;
Mike Travis7a6aedf2008-03-25 15:06:53 -0700198 if (per_cpu(cpufreq_stats_table, cpu))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 return -EBUSY;
Dave Jones0a829c52009-01-18 01:49:04 -0500200 stat = kzalloc(sizeof(struct cpufreq_stats), GFP_KERNEL);
201 if ((stat) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
204 data = cpufreq_cpu_get(cpu);
Dave Jonesbc7b26f2005-10-27 16:02:06 -0700205 if (data == NULL) {
206 ret = -EINVAL;
207 goto error_get_fail;
208 }
209
Dave Jones0a829c52009-01-18 01:49:04 -0500210 ret = sysfs_create_group(&data->kobj, &stats_attr_group);
211 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 goto error_out;
213
214 stat->cpu = cpu;
Mike Travis7a6aedf2008-03-25 15:06:53 -0700215 per_cpu(cpufreq_stats_table, cpu) = stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
Dave Jones0a829c52009-01-18 01:49:04 -0500217 for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 unsigned int freq = table[i].frequency;
219 if (freq == CPUFREQ_ENTRY_INVALID)
220 continue;
221 count++;
222 }
223
Viresh Kumar1e7586a2012-10-26 00:51:21 +0200224 alloc_size = count * sizeof(int) + count * sizeof(u64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
226#ifdef CONFIG_CPU_FREQ_STAT_DETAILS
227 alloc_size += count * count * sizeof(int);
228#endif
229 stat->max_state = count;
Dave Jonese98df502005-10-20 15:17:43 -0700230 stat->time_in_state = kzalloc(alloc_size, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 if (!stat->time_in_state) {
232 ret = -ENOMEM;
233 goto error_out;
234 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 stat->freq_table = (unsigned int *)(stat->time_in_state + count);
236
237#ifdef CONFIG_CPU_FREQ_STAT_DETAILS
238 stat->trans_table = stat->freq_table + count;
239#endif
240 j = 0;
241 for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) {
242 unsigned int freq = table[i].frequency;
243 if (freq == CPUFREQ_ENTRY_INVALID)
244 continue;
245 if (freq_table_get_index(stat, freq) == -1)
246 stat->freq_table[j++] = freq;
247 }
248 stat->state_num = j;
249 spin_lock(&cpufreq_stats_lock);
Venkatesh Pallipadi58f1df22005-05-25 14:46:50 -0700250 stat->last_time = get_jiffies_64();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 stat->last_index = freq_table_get_index(stat, policy->cur);
252 spin_unlock(&cpufreq_stats_lock);
253 cpufreq_cpu_put(data);
254 return 0;
255error_out:
256 cpufreq_cpu_put(data);
Dave Jonesb7fb3582005-11-01 23:13:45 -0800257error_get_fail:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 kfree(stat);
Mike Travis7a6aedf2008-03-25 15:06:53 -0700259 per_cpu(cpufreq_stats_table, cpu) = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 return ret;
261}
262
Viresh Kumarb8eed8a2013-01-14 13:23:03 +0000263static void cpufreq_stats_update_policy_cpu(struct cpufreq_policy *policy)
264{
265 struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table,
266 policy->last_cpu);
267
268 pr_debug("Updating stats_table for new_cpu %u from last_cpu %u\n",
269 policy->cpu, policy->last_cpu);
270 per_cpu(cpufreq_stats_table, policy->cpu) = per_cpu(cpufreq_stats_table,
271 policy->last_cpu);
272 per_cpu(cpufreq_stats_table, policy->last_cpu) = NULL;
273 stat->cpu = policy->cpu;
274}
275
Dave Jones0a829c52009-01-18 01:49:04 -0500276static int cpufreq_stat_notifier_policy(struct notifier_block *nb,
277 unsigned long val, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278{
279 int ret;
280 struct cpufreq_policy *policy = data;
281 struct cpufreq_frequency_table *table;
282 unsigned int cpu = policy->cpu;
Viresh Kumarb8eed8a2013-01-14 13:23:03 +0000283
284 if (val == CPUFREQ_UPDATE_POLICY_CPU) {
285 cpufreq_stats_update_policy_cpu(policy);
286 return 0;
287 }
288
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 if (val != CPUFREQ_NOTIFY)
290 return 0;
291 table = cpufreq_frequency_get_table(cpu);
292 if (!table)
293 return 0;
Dave Jones0a829c52009-01-18 01:49:04 -0500294 ret = cpufreq_stats_create_table(policy, table);
295 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 return ret;
297 return 0;
298}
299
Dave Jones0a829c52009-01-18 01:49:04 -0500300static int cpufreq_stat_notifier_trans(struct notifier_block *nb,
301 unsigned long val, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302{
303 struct cpufreq_freqs *freq = data;
304 struct cpufreq_stats *stat;
305 int old_index, new_index;
306
307 if (val != CPUFREQ_POSTCHANGE)
308 return 0;
309
Mike Travis7a6aedf2008-03-25 15:06:53 -0700310 stat = per_cpu(cpufreq_stats_table, freq->cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 if (!stat)
312 return 0;
Venkatesh Pallipadi8edc59d92006-12-19 12:58:55 -0800313
Shaohua Li6501faf2008-04-27 13:46:56 -0700314 old_index = stat->last_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 new_index = freq_table_get_index(stat, freq->new);
316
Konrad Rzeszutek Wilk46a310b2011-06-16 15:36:38 -0400317 /* We can't do stat->time_in_state[-1]= .. */
318 if (old_index == -1 || new_index == -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 return 0;
320
Konrad Rzeszutek Wilk46a310b2011-06-16 15:36:38 -0400321 cpufreq_stats_update(freq->cpu);
322
323 if (old_index == new_index)
Venkatesh Pallipadi8edc59d92006-12-19 12:58:55 -0800324 return 0;
325
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 spin_lock(&cpufreq_stats_lock);
327 stat->last_index = new_index;
328#ifdef CONFIG_CPU_FREQ_STAT_DETAILS
329 stat->trans_table[old_index * stat->max_state + new_index]++;
330#endif
331 stat->total_trans++;
332 spin_unlock(&cpufreq_stats_lock);
333 return 0;
334}
335
Satyam Sharma55395ae2007-10-02 13:28:15 -0700336static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
337 unsigned long action,
338 void *hcpu)
Ashok Rajc32b6b82005-10-30 14:59:54 -0800339{
340 unsigned int cpu = (unsigned long)hcpu;
341
342 switch (action) {
343 case CPU_ONLINE:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700344 case CPU_ONLINE_FROZEN:
Ashok Rajc32b6b82005-10-30 14:59:54 -0800345 cpufreq_update_policy(cpu);
346 break;
steven finney98586ed2011-05-02 11:29:17 -0700347 case CPU_DOWN_PREPARE:
Tu, Xiaobinge3773672012-10-23 01:03:00 +0200348 case CPU_DOWN_PREPARE_FROZEN:
steven finney98586ed2011-05-02 11:29:17 -0700349 cpufreq_stats_free_sysfs(cpu);
350 break;
Ashok Rajc32b6b82005-10-30 14:59:54 -0800351 case CPU_DEAD:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700352 case CPU_DEAD_FROZEN:
Ashok Rajc32b6b82005-10-30 14:59:54 -0800353 cpufreq_stats_free_table(cpu);
354 break;
355 }
356 return NOTIFY_OK;
357}
358
steven finney98586ed2011-05-02 11:29:17 -0700359/* priority=1 so this will get called before cpufreq_remove_dev */
Karthigan Srinivasan469057d2011-04-01 17:34:47 -0500360static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
Ashok Rajc32b6b82005-10-30 14:59:54 -0800361 .notifier_call = cpufreq_stat_cpu_callback,
steven finney98586ed2011-05-02 11:29:17 -0700362 .priority = 1,
Ashok Rajc32b6b82005-10-30 14:59:54 -0800363};
364
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365static struct notifier_block notifier_policy_block = {
366 .notifier_call = cpufreq_stat_notifier_policy
367};
368
369static struct notifier_block notifier_trans_block = {
370 .notifier_call = cpufreq_stat_notifier_trans
371};
372
Dave Jones0a829c52009-01-18 01:49:04 -0500373static int __init cpufreq_stats_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374{
375 int ret;
376 unsigned int cpu;
Ashok Rajc32b6b82005-10-30 14:59:54 -0800377
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 spin_lock_init(&cpufreq_stats_lock);
Dave Jones0a829c52009-01-18 01:49:04 -0500379 ret = cpufreq_register_notifier(&notifier_policy_block,
380 CPUFREQ_POLICY_NOTIFIER);
381 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 return ret;
383
Konstantin Khlebnikov56836fb2012-12-15 00:22:02 +0100384 register_hotcpu_notifier(&cpufreq_stat_cpu_notifier);
385 for_each_online_cpu(cpu)
386 cpufreq_update_policy(cpu);
387
Dave Jones0a829c52009-01-18 01:49:04 -0500388 ret = cpufreq_register_notifier(&notifier_trans_block,
389 CPUFREQ_TRANSITION_NOTIFIER);
390 if (ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 cpufreq_unregister_notifier(&notifier_policy_block,
392 CPUFREQ_POLICY_NOTIFIER);
Konstantin Khlebnikov56836fb2012-12-15 00:22:02 +0100393 unregister_hotcpu_notifier(&cpufreq_stat_cpu_notifier);
394 for_each_online_cpu(cpu)
395 cpufreq_stats_free_table(cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 return ret;
397 }
398
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 return 0;
400}
Dave Jones0a829c52009-01-18 01:49:04 -0500401static void __exit cpufreq_stats_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402{
403 unsigned int cpu;
Ashok Rajc32b6b82005-10-30 14:59:54 -0800404
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 cpufreq_unregister_notifier(&notifier_policy_block,
406 CPUFREQ_POLICY_NOTIFIER);
407 cpufreq_unregister_notifier(&notifier_trans_block,
408 CPUFREQ_TRANSITION_NOTIFIER);
Chandra Seetharaman65edc682006-06-27 02:54:08 -0700409 unregister_hotcpu_notifier(&cpufreq_stat_cpu_notifier);
Ashok Rajc32b6b82005-10-30 14:59:54 -0800410 for_each_online_cpu(cpu) {
Satyam Sharma55395ae2007-10-02 13:28:15 -0700411 cpufreq_stats_free_table(cpu);
Dave Jones13f06752011-06-12 16:35:28 -0400412 cpufreq_stats_free_sysfs(cpu);
Ashok Rajc32b6b82005-10-30 14:59:54 -0800413 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414}
415
Dave Jones0a829c52009-01-18 01:49:04 -0500416MODULE_AUTHOR("Zou Nan hai <nanhai.zou@intel.com>");
417MODULE_DESCRIPTION("'cpufreq_stats' - A driver to export cpufreq stats "
Gautham R Shenoye08f5f52006-10-26 16:20:58 +0530418 "through sysfs filesystem");
Dave Jones0a829c52009-01-18 01:49:04 -0500419MODULE_LICENSE("GPL");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
421module_init(cpufreq_stats_init);
422module_exit(cpufreq_stats_exit);