Merge master.kernel.org:/pub/scm/linux/kernel/git/davej/cpufreq
[sfrench/cifs-2.6.git] / drivers / cpufreq / cpufreq_stats.c
index 7ddf714c4d437477156eb1da5173d347a78bed5f..0bddb8e694d9bbde6acd604c540383e65524e2f9 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/percpu.h>
 #include <linux/kobject.h>
 #include <linux/spinlock.h>
+#include <linux/notifier.h>
 #include <asm/cputime.h>
 
 static spinlock_t cpufreq_stats_lock;
@@ -302,6 +303,27 @@ cpufreq_stat_notifier_trans (struct notifier_block *nb, unsigned long val,
        return 0;
 }
 
+static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
+                                       unsigned long action, void *hcpu)
+{
+       unsigned int cpu = (unsigned long)hcpu;
+
+       switch (action) {
+       case CPU_ONLINE:
+               cpufreq_update_policy(cpu);
+               break;
+       case CPU_DEAD:
+               cpufreq_stats_free_table(cpu);
+               break;
+       }
+       return NOTIFY_OK;
+}
+
+static struct notifier_block cpufreq_stat_cpu_notifier =
+{
+       .notifier_call = cpufreq_stat_cpu_callback,
+};
+
 static struct notifier_block notifier_policy_block = {
        .notifier_call = cpufreq_stat_notifier_policy
 };
@@ -315,6 +337,7 @@ __init cpufreq_stats_init(void)
 {
        int ret;
        unsigned int cpu;
+
        spin_lock_init(&cpufreq_stats_lock);
        if ((ret = cpufreq_register_notifier(&notifier_policy_block,
                                CPUFREQ_POLICY_NOTIFIER)))
@@ -327,20 +350,31 @@ __init cpufreq_stats_init(void)
                return ret;
        }
 
-       for_each_cpu(cpu)
-               cpufreq_update_policy(cpu);
+       register_cpu_notifier(&cpufreq_stat_cpu_notifier);
+       lock_cpu_hotplug();
+       for_each_online_cpu(cpu) {
+               cpufreq_stat_cpu_callback(&cpufreq_stat_cpu_notifier, CPU_ONLINE,
+                       (void *)(long)cpu);
+       }
+       unlock_cpu_hotplug();
        return 0;
 }
 static void
 __exit cpufreq_stats_exit(void)
 {
        unsigned int cpu;
+
        cpufreq_unregister_notifier(&notifier_policy_block,
                        CPUFREQ_POLICY_NOTIFIER);
        cpufreq_unregister_notifier(&notifier_trans_block,
                        CPUFREQ_TRANSITION_NOTIFIER);
-       for_each_cpu(cpu)
-               cpufreq_stats_free_table(cpu);
+       unregister_cpu_notifier(&cpufreq_stat_cpu_notifier);
+       lock_cpu_hotplug();
+       for_each_online_cpu(cpu) {
+               cpufreq_stat_cpu_callback(&cpufreq_stat_cpu_notifier, CPU_DEAD,
+                       (void *)(long)cpu);
+       }
+       unlock_cpu_hotplug();
 }
 
 MODULE_AUTHOR ("Zou Nan hai <nanhai.zou@intel.com>");