aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/cpufreq
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2013-08-14 16:21:16 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2013-08-14 16:21:16 -0400
commitc49a089c3eedbc4b3fa9c3d469599a6c14dea4c5 (patch)
tree9f21ef73bb2d3b8fad642158c6ffa6e33ccabee3 /drivers/cpufreq
parentd4e4ab86bcba5a72779c43dc1459f71fea3d89c8 (diff)
parent3de9bdeb28638e164d1f0eb38dd68e3f5d2ac95c (diff)
Merge back earlier 'pm-cpufreq' material
Diffstat (limited to 'drivers/cpufreq')
-rw-r--r--drivers/cpufreq/Makefile2
-rw-r--r--drivers/cpufreq/acpi-cpufreq.c10
-rw-r--r--drivers/cpufreq/at32ap-cpufreq.c1
-rw-r--r--drivers/cpufreq/blackfin-cpufreq.c1
-rw-r--r--drivers/cpufreq/cpufreq-nforce2.c1
-rw-r--r--drivers/cpufreq/cpufreq.c722
-rw-r--r--drivers/cpufreq/cpufreq_conservative.c14
-rw-r--r--drivers/cpufreq/cpufreq_governor.c16
-rw-r--r--drivers/cpufreq/cpufreq_governor.h8
-rw-r--r--drivers/cpufreq/cpufreq_ondemand.c63
-rw-r--r--drivers/cpufreq/cpufreq_performance.c3
-rw-r--r--drivers/cpufreq/cpufreq_powersave.c3
-rw-r--r--drivers/cpufreq/cpufreq_stats.c31
-rw-r--r--drivers/cpufreq/cris-artpec3-cpufreq.c1
-rw-r--r--drivers/cpufreq/cris-etraxfs-cpufreq.c1
-rw-r--r--drivers/cpufreq/e_powersaver.c5
-rw-r--r--drivers/cpufreq/elanfreq.c1
-rw-r--r--drivers/cpufreq/exynos-cpufreq.c2
-rw-r--r--drivers/cpufreq/freq_table.c4
-rw-r--r--drivers/cpufreq/gx-suspmod.c3
-rw-r--r--drivers/cpufreq/ia64-acpi-cpufreq.c5
-rw-r--r--drivers/cpufreq/intel_pstate.c1
-rw-r--r--drivers/cpufreq/kirkwood-cpufreq.c1
-rw-r--r--drivers/cpufreq/longhaul.c1
-rw-r--r--drivers/cpufreq/longrun.c1
-rw-r--r--drivers/cpufreq/loongson2_cpufreq.c1
-rw-r--r--drivers/cpufreq/maple-cpufreq.c1
-rw-r--r--drivers/cpufreq/mperf.c51
-rw-r--r--drivers/cpufreq/mperf.h9
-rw-r--r--drivers/cpufreq/p4-clockmod.c1
-rw-r--r--drivers/cpufreq/pasemi-cpufreq.c1
-rw-r--r--drivers/cpufreq/pcc-cpufreq.c1
-rw-r--r--drivers/cpufreq/pmac32-cpufreq.c1
-rw-r--r--drivers/cpufreq/pmac64-cpufreq.c6
-rw-r--r--drivers/cpufreq/powernow-k6.c1
-rw-r--r--drivers/cpufreq/powernow-k7.c14
-rw-r--r--drivers/cpufreq/powernow-k8.c7
-rw-r--r--drivers/cpufreq/ppc-corenet-cpufreq.c1
-rw-r--r--drivers/cpufreq/ppc_cbe_cpufreq.c1
-rw-r--r--drivers/cpufreq/s3c2416-cpufreq.c1
-rw-r--r--drivers/cpufreq/s3c24xx-cpufreq.c6
-rw-r--r--drivers/cpufreq/s3c64xx-cpufreq.c1
-rw-r--r--drivers/cpufreq/sc520_freq.c1
-rw-r--r--drivers/cpufreq/sh-cpufreq.c1
-rw-r--r--drivers/cpufreq/sparc-us2e-cpufreq.c6
-rw-r--r--drivers/cpufreq/sparc-us3-cpufreq.c6
-rw-r--r--drivers/cpufreq/speedstep-centrino.c1
-rw-r--r--drivers/cpufreq/speedstep-ich.c1
-rw-r--r--drivers/cpufreq/speedstep-smi.c1
49 files changed, 456 insertions, 566 deletions
diff --git a/drivers/cpufreq/Makefile b/drivers/cpufreq/Makefile
index d345b5a7aa71..ad5866c2ada0 100644
--- a/drivers/cpufreq/Makefile
+++ b/drivers/cpufreq/Makefile
@@ -23,7 +23,7 @@ obj-$(CONFIG_GENERIC_CPUFREQ_CPU0) += cpufreq-cpu0.o
23# powernow-k8 can load then. ACPI is preferred to all other hardware-specific drivers. 23# powernow-k8 can load then. ACPI is preferred to all other hardware-specific drivers.
24# speedstep-* is preferred over p4-clockmod. 24# speedstep-* is preferred over p4-clockmod.
25 25
26obj-$(CONFIG_X86_ACPI_CPUFREQ) += acpi-cpufreq.o mperf.o 26obj-$(CONFIG_X86_ACPI_CPUFREQ) += acpi-cpufreq.o
27obj-$(CONFIG_X86_POWERNOW_K8) += powernow-k8.o 27obj-$(CONFIG_X86_POWERNOW_K8) += powernow-k8.o
28obj-$(CONFIG_X86_PCC_CPUFREQ) += pcc-cpufreq.o 28obj-$(CONFIG_X86_PCC_CPUFREQ) += pcc-cpufreq.o
29obj-$(CONFIG_X86_POWERNOW_K6) += powernow-k6.o 29obj-$(CONFIG_X86_POWERNOW_K6) += powernow-k6.o
diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
index 39264020b88a..9b5d1b1a9c03 100644
--- a/drivers/cpufreq/acpi-cpufreq.c
+++ b/drivers/cpufreq/acpi-cpufreq.c
@@ -45,7 +45,6 @@
45#include <asm/msr.h> 45#include <asm/msr.h>
46#include <asm/processor.h> 46#include <asm/processor.h>
47#include <asm/cpufeature.h> 47#include <asm/cpufeature.h>
48#include "mperf.h"
49 48
50MODULE_AUTHOR("Paul Diefenbaugh, Dominik Brodowski"); 49MODULE_AUTHOR("Paul Diefenbaugh, Dominik Brodowski");
51MODULE_DESCRIPTION("ACPI Processor P-States Driver"); 50MODULE_DESCRIPTION("ACPI Processor P-States Driver");
@@ -710,7 +709,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
710 return blacklisted; 709 return blacklisted;
711#endif 710#endif
712 711
713 data = kzalloc(sizeof(struct acpi_cpufreq_data), GFP_KERNEL); 712 data = kzalloc(sizeof(*data), GFP_KERNEL);
714 if (!data) 713 if (!data)
715 return -ENOMEM; 714 return -ENOMEM;
716 715
@@ -800,7 +799,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
800 goto err_unreg; 799 goto err_unreg;
801 } 800 }
802 801
803 data->freq_table = kmalloc(sizeof(struct cpufreq_frequency_table) * 802 data->freq_table = kmalloc(sizeof(*data->freq_table) *
804 (perf->state_count+1), GFP_KERNEL); 803 (perf->state_count+1), GFP_KERNEL);
805 if (!data->freq_table) { 804 if (!data->freq_table) {
806 result = -ENOMEM; 805 result = -ENOMEM;
@@ -861,10 +860,6 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
861 /* notify BIOS that we exist */ 860 /* notify BIOS that we exist */
862 acpi_processor_notify_smm(THIS_MODULE); 861 acpi_processor_notify_smm(THIS_MODULE);
863 862
864 /* Check for APERF/MPERF support in hardware */
865 if (boot_cpu_has(X86_FEATURE_APERFMPERF))
866 acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
867
868 pr_debug("CPU%u - ACPI performance management activated.\n", cpu); 863 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
869 for (i = 0; i < perf->state_count; i++) 864 for (i = 0; i < perf->state_count; i++)
870 pr_debug(" %cP%d: %d MHz, %d mW, %d uS\n", 865 pr_debug(" %cP%d: %d MHz, %d mW, %d uS\n",
@@ -941,7 +936,6 @@ static struct cpufreq_driver acpi_cpufreq_driver = {
941 .exit = acpi_cpufreq_cpu_exit, 936 .exit = acpi_cpufreq_cpu_exit,
942 .resume = acpi_cpufreq_resume, 937 .resume = acpi_cpufreq_resume,
943 .name = "acpi-cpufreq", 938 .name = "acpi-cpufreq",
944 .owner = THIS_MODULE,
945 .attr = acpi_cpufreq_attr, 939 .attr = acpi_cpufreq_attr,
946}; 940};
947 941
diff --git a/drivers/cpufreq/at32ap-cpufreq.c b/drivers/cpufreq/at32ap-cpufreq.c
index 654488723cb5..e0c38d938997 100644
--- a/drivers/cpufreq/at32ap-cpufreq.c
+++ b/drivers/cpufreq/at32ap-cpufreq.c
@@ -108,7 +108,6 @@ static int __init at32_cpufreq_driver_init(struct cpufreq_policy *policy)
108 108
109static struct cpufreq_driver at32_driver = { 109static struct cpufreq_driver at32_driver = {
110 .name = "at32ap", 110 .name = "at32ap",
111 .owner = THIS_MODULE,
112 .init = at32_cpufreq_driver_init, 111 .init = at32_cpufreq_driver_init,
113 .verify = at32_verify_speed, 112 .verify = at32_verify_speed,
114 .target = at32_set_target, 113 .target = at32_set_target,
diff --git a/drivers/cpufreq/blackfin-cpufreq.c b/drivers/cpufreq/blackfin-cpufreq.c
index 9cdbbd278a80..ef05978a7237 100644
--- a/drivers/cpufreq/blackfin-cpufreq.c
+++ b/drivers/cpufreq/blackfin-cpufreq.c
@@ -225,7 +225,6 @@ static struct cpufreq_driver bfin_driver = {
225 .get = bfin_getfreq_khz, 225 .get = bfin_getfreq_khz,
226 .init = __bfin_cpu_init, 226 .init = __bfin_cpu_init,
227 .name = "bfin cpufreq", 227 .name = "bfin cpufreq",
228 .owner = THIS_MODULE,
229 .attr = bfin_freq_attr, 228 .attr = bfin_freq_attr,
230}; 229};
231 230
diff --git a/drivers/cpufreq/cpufreq-nforce2.c b/drivers/cpufreq/cpufreq-nforce2.c
index af1542d41440..b83d45f68574 100644
--- a/drivers/cpufreq/cpufreq-nforce2.c
+++ b/drivers/cpufreq/cpufreq-nforce2.c
@@ -379,7 +379,6 @@ static struct cpufreq_driver nforce2_driver = {
379 .get = nforce2_get, 379 .get = nforce2_get,
380 .init = nforce2_cpu_init, 380 .init = nforce2_cpu_init,
381 .exit = nforce2_cpu_exit, 381 .exit = nforce2_cpu_exit,
382 .owner = THIS_MODULE,
383}; 382};
384 383
385#ifdef MODULE 384#ifdef MODULE
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index f0a5e2b0eb8a..37a687467329 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -17,24 +17,17 @@
17 17
18#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 18#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19 19
20#include <asm/cputime.h> 20#include <linux/cpu.h>
21#include <linux/kernel.h>
22#include <linux/kernel_stat.h>
23#include <linux/module.h>
24#include <linux/init.h>
25#include <linux/notifier.h>
26#include <linux/cpufreq.h> 21#include <linux/cpufreq.h>
27#include <linux/delay.h> 22#include <linux/delay.h>
28#include <linux/interrupt.h>
29#include <linux/spinlock.h>
30#include <linux/tick.h>
31#include <linux/device.h> 23#include <linux/device.h>
32#include <linux/slab.h> 24#include <linux/init.h>
33#include <linux/cpu.h> 25#include <linux/kernel_stat.h>
34#include <linux/completion.h> 26#include <linux/module.h>
35#include <linux/mutex.h> 27#include <linux/mutex.h>
28#include <linux/slab.h>
36#include <linux/syscore_ops.h> 29#include <linux/syscore_ops.h>
37 30#include <linux/tick.h>
38#include <trace/events/power.h> 31#include <trace/events/power.h>
39 32
40/** 33/**
@@ -44,8 +37,10 @@
44 */ 37 */
45static struct cpufreq_driver *cpufreq_driver; 38static struct cpufreq_driver *cpufreq_driver;
46static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data); 39static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data);
40static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data_fallback);
47static DEFINE_RWLOCK(cpufreq_driver_lock); 41static DEFINE_RWLOCK(cpufreq_driver_lock);
48static DEFINE_MUTEX(cpufreq_governor_lock); 42static DEFINE_MUTEX(cpufreq_governor_lock);
43static LIST_HEAD(cpufreq_policy_list);
49 44
50#ifdef CONFIG_HOTPLUG_CPU 45#ifdef CONFIG_HOTPLUG_CPU
51/* This one keeps track of the previously set governor of a removed CPU */ 46/* This one keeps track of the previously set governor of a removed CPU */
@@ -96,6 +91,12 @@ static void unlock_policy_rwsem_##mode(int cpu) \
96unlock_policy_rwsem(read, cpu); 91unlock_policy_rwsem(read, cpu);
97unlock_policy_rwsem(write, cpu); 92unlock_policy_rwsem(write, cpu);
98 93
94/*
95 * rwsem to guarantee that cpufreq driver module doesn't unload during critical
96 * sections
97 */
98static DECLARE_RWSEM(cpufreq_rwsem);
99
99/* internal prototypes */ 100/* internal prototypes */
100static int __cpufreq_governor(struct cpufreq_policy *policy, 101static int __cpufreq_governor(struct cpufreq_policy *policy,
101 unsigned int event); 102 unsigned int event);
@@ -183,78 +184,46 @@ u64 get_cpu_idle_time(unsigned int cpu, u64 *wall, int io_busy)
183} 184}
184EXPORT_SYMBOL_GPL(get_cpu_idle_time); 185EXPORT_SYMBOL_GPL(get_cpu_idle_time);
185 186
186static struct cpufreq_policy *__cpufreq_cpu_get(unsigned int cpu, bool sysfs) 187struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu)
187{ 188{
188 struct cpufreq_policy *data; 189 struct cpufreq_policy *policy = NULL;
189 unsigned long flags; 190 unsigned long flags;
190 191
191 if (cpu >= nr_cpu_ids) 192 if (cpufreq_disabled() || (cpu >= nr_cpu_ids))
192 goto err_out; 193 return NULL;
194
195 if (!down_read_trylock(&cpufreq_rwsem))
196 return NULL;
193 197
194 /* get the cpufreq driver */ 198 /* get the cpufreq driver */
195 read_lock_irqsave(&cpufreq_driver_lock, flags); 199 read_lock_irqsave(&cpufreq_driver_lock, flags);
196 200
197 if (!cpufreq_driver) 201 if (cpufreq_driver) {
198 goto err_out_unlock; 202 /* get the CPU */
199 203 policy = per_cpu(cpufreq_cpu_data, cpu);
200 if (!try_module_get(cpufreq_driver->owner)) 204 if (policy)
201 goto err_out_unlock; 205 kobject_get(&policy->kobj);
202 206 }
203 /* get the CPU */
204 data = per_cpu(cpufreq_cpu_data, cpu);
205
206 if (!data)
207 goto err_out_put_module;
208
209 if (!sysfs && !kobject_get(&data->kobj))
210 goto err_out_put_module;
211 207
212 read_unlock_irqrestore(&cpufreq_driver_lock, flags); 208 read_unlock_irqrestore(&cpufreq_driver_lock, flags);
213 return data;
214 209
215err_out_put_module: 210 if (!policy)
216 module_put(cpufreq_driver->owner); 211 up_read(&cpufreq_rwsem);
217err_out_unlock:
218 read_unlock_irqrestore(&cpufreq_driver_lock, flags);
219err_out:
220 return NULL;
221}
222
223struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu)
224{
225 if (cpufreq_disabled())
226 return NULL;
227 212
228 return __cpufreq_cpu_get(cpu, false); 213 return policy;
229} 214}
230EXPORT_SYMBOL_GPL(cpufreq_cpu_get); 215EXPORT_SYMBOL_GPL(cpufreq_cpu_get);
231 216
232static struct cpufreq_policy *cpufreq_cpu_get_sysfs(unsigned int cpu) 217void cpufreq_cpu_put(struct cpufreq_policy *policy)
233{
234 return __cpufreq_cpu_get(cpu, true);
235}
236
237static void __cpufreq_cpu_put(struct cpufreq_policy *data, bool sysfs)
238{
239 if (!sysfs)
240 kobject_put(&data->kobj);
241 module_put(cpufreq_driver->owner);
242}
243
244void cpufreq_cpu_put(struct cpufreq_policy *data)
245{ 218{
246 if (cpufreq_disabled()) 219 if (cpufreq_disabled())
247 return; 220 return;
248 221
249 __cpufreq_cpu_put(data, false); 222 kobject_put(&policy->kobj);
223 up_read(&cpufreq_rwsem);
250} 224}
251EXPORT_SYMBOL_GPL(cpufreq_cpu_put); 225EXPORT_SYMBOL_GPL(cpufreq_cpu_put);
252 226
253static void cpufreq_cpu_put_sysfs(struct cpufreq_policy *data)
254{
255 __cpufreq_cpu_put(data, true);
256}
257
258/********************************************************************* 227/*********************************************************************
259 * EXTERNALLY AFFECTING FREQUENCY CHANGES * 228 * EXTERNALLY AFFECTING FREQUENCY CHANGES *
260 *********************************************************************/ 229 *********************************************************************/
@@ -459,8 +428,8 @@ show_one(scaling_min_freq, min);
459show_one(scaling_max_freq, max); 428show_one(scaling_max_freq, max);
460show_one(scaling_cur_freq, cur); 429show_one(scaling_cur_freq, cur);
461 430
462static int __cpufreq_set_policy(struct cpufreq_policy *data, 431static int __cpufreq_set_policy(struct cpufreq_policy *policy,
463 struct cpufreq_policy *policy); 432 struct cpufreq_policy *new_policy);
464 433
465/** 434/**
466 * cpufreq_per_cpu_attr_write() / store_##file_name() - sysfs write access 435 * cpufreq_per_cpu_attr_write() / store_##file_name() - sysfs write access
@@ -699,12 +668,12 @@ static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)
699 struct cpufreq_policy *policy = to_policy(kobj); 668 struct cpufreq_policy *policy = to_policy(kobj);
700 struct freq_attr *fattr = to_attr(attr); 669 struct freq_attr *fattr = to_attr(attr);
701 ssize_t ret = -EINVAL; 670 ssize_t ret = -EINVAL;
702 policy = cpufreq_cpu_get_sysfs(policy->cpu); 671
703 if (!policy) 672 if (!down_read_trylock(&cpufreq_rwsem))
704 goto no_policy; 673 goto exit;
705 674
706 if (lock_policy_rwsem_read(policy->cpu) < 0) 675 if (lock_policy_rwsem_read(policy->cpu) < 0)
707 goto fail; 676 goto up_read;
708 677
709 if (fattr->show) 678 if (fattr->show)
710 ret = fattr->show(policy, buf); 679 ret = fattr->show(policy, buf);
@@ -712,9 +681,10 @@ static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)
712 ret = -EIO; 681 ret = -EIO;
713 682
714 unlock_policy_rwsem_read(policy->cpu); 683 unlock_policy_rwsem_read(policy->cpu);
715fail: 684
716 cpufreq_cpu_put_sysfs(policy); 685up_read:
717no_policy: 686 up_read(&cpufreq_rwsem);
687exit:
718 return ret; 688 return ret;
719} 689}
720 690
@@ -724,12 +694,12 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,
724 struct cpufreq_policy *policy = to_policy(kobj); 694 struct cpufreq_policy *policy = to_policy(kobj);
725 struct freq_attr *fattr = to_attr(attr); 695 struct freq_attr *fattr = to_attr(attr);
726 ssize_t ret = -EINVAL; 696 ssize_t ret = -EINVAL;
727 policy = cpufreq_cpu_get_sysfs(policy->cpu); 697
728 if (!policy) 698 if (!down_read_trylock(&cpufreq_rwsem))
729 goto no_policy; 699 goto exit;
730 700
731 if (lock_policy_rwsem_write(policy->cpu) < 0) 701 if (lock_policy_rwsem_write(policy->cpu) < 0)
732 goto fail; 702 goto up_read;
733 703
734 if (fattr->store) 704 if (fattr->store)
735 ret = fattr->store(policy, buf, count); 705 ret = fattr->store(policy, buf, count);
@@ -737,9 +707,10 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,
737 ret = -EIO; 707 ret = -EIO;
738 708
739 unlock_policy_rwsem_write(policy->cpu); 709 unlock_policy_rwsem_write(policy->cpu);
740fail: 710
741 cpufreq_cpu_put_sysfs(policy); 711up_read:
742no_policy: 712 up_read(&cpufreq_rwsem);
713exit:
743 return ret; 714 return ret;
744} 715}
745 716
@@ -805,41 +776,32 @@ void cpufreq_sysfs_remove_file(const struct attribute *attr)
805EXPORT_SYMBOL(cpufreq_sysfs_remove_file); 776EXPORT_SYMBOL(cpufreq_sysfs_remove_file);
806 777
807/* symlink affected CPUs */ 778/* symlink affected CPUs */
808static int cpufreq_add_dev_symlink(unsigned int cpu, 779static int cpufreq_add_dev_symlink(struct cpufreq_policy *policy)
809 struct cpufreq_policy *policy)
810{ 780{
811 unsigned int j; 781 unsigned int j;
812 int ret = 0; 782 int ret = 0;
813 783
814 for_each_cpu(j, policy->cpus) { 784 for_each_cpu(j, policy->cpus) {
815 struct cpufreq_policy *managed_policy;
816 struct device *cpu_dev; 785 struct device *cpu_dev;
817 786
818 if (j == cpu) 787 if (j == policy->cpu)
819 continue; 788 continue;
820 789
821 pr_debug("CPU %u already managed, adding link\n", j); 790 pr_debug("Adding link for CPU: %u\n", j);
822 managed_policy = cpufreq_cpu_get(cpu);
823 cpu_dev = get_cpu_device(j); 791 cpu_dev = get_cpu_device(j);
824 ret = sysfs_create_link(&cpu_dev->kobj, &policy->kobj, 792 ret = sysfs_create_link(&cpu_dev->kobj, &policy->kobj,
825 "cpufreq"); 793 "cpufreq");
826 if (ret) { 794 if (ret)
827 cpufreq_cpu_put(managed_policy); 795 break;
828 return ret;
829 }
830 } 796 }
831 return ret; 797 return ret;
832} 798}
833 799
834static int cpufreq_add_dev_interface(unsigned int cpu, 800static int cpufreq_add_dev_interface(struct cpufreq_policy *policy,
835 struct cpufreq_policy *policy,
836 struct device *dev) 801 struct device *dev)
837{ 802{
838 struct cpufreq_policy new_policy;
839 struct freq_attr **drv_attr; 803 struct freq_attr **drv_attr;
840 unsigned long flags;
841 int ret = 0; 804 int ret = 0;
842 unsigned int j;
843 805
844 /* prepare interface data */ 806 /* prepare interface data */
845 ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq, 807 ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq,
@@ -871,18 +833,24 @@ static int cpufreq_add_dev_interface(unsigned int cpu,
871 goto err_out_kobj_put; 833 goto err_out_kobj_put;
872 } 834 }
873 835
874 write_lock_irqsave(&cpufreq_driver_lock, flags); 836 ret = cpufreq_add_dev_symlink(policy);
875 for_each_cpu(j, policy->cpus) {
876 per_cpu(cpufreq_cpu_data, j) = policy;
877 per_cpu(cpufreq_policy_cpu, j) = policy->cpu;
878 }
879 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
880
881 ret = cpufreq_add_dev_symlink(cpu, policy);
882 if (ret) 837 if (ret)
883 goto err_out_kobj_put; 838 goto err_out_kobj_put;
884 839
885 memcpy(&new_policy, policy, sizeof(struct cpufreq_policy)); 840 return ret;
841
842err_out_kobj_put:
843 kobject_put(&policy->kobj);
844 wait_for_completion(&policy->kobj_unregister);
845 return ret;
846}
847
848static void cpufreq_init_policy(struct cpufreq_policy *policy)
849{
850 struct cpufreq_policy new_policy;
851 int ret = 0;
852
853 memcpy(&new_policy, policy, sizeof(*policy));
886 /* assure that the starting sequence is run in __cpufreq_set_policy */ 854 /* assure that the starting sequence is run in __cpufreq_set_policy */
887 policy->governor = NULL; 855 policy->governor = NULL;
888 856
@@ -896,29 +864,25 @@ static int cpufreq_add_dev_interface(unsigned int cpu,
896 if (cpufreq_driver->exit) 864 if (cpufreq_driver->exit)
897 cpufreq_driver->exit(policy); 865 cpufreq_driver->exit(policy);
898 } 866 }
899 return ret;
900
901err_out_kobj_put:
902 kobject_put(&policy->kobj);
903 wait_for_completion(&policy->kobj_unregister);
904 return ret;
905} 867}
906 868
907#ifdef CONFIG_HOTPLUG_CPU 869#ifdef CONFIG_HOTPLUG_CPU
908static int cpufreq_add_policy_cpu(unsigned int cpu, unsigned int sibling, 870static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy,
909 struct device *dev) 871 unsigned int cpu, struct device *dev,
872 bool frozen)
910{ 873{
911 struct cpufreq_policy *policy;
912 int ret = 0, has_target = !!cpufreq_driver->target; 874 int ret = 0, has_target = !!cpufreq_driver->target;
913 unsigned long flags; 875 unsigned long flags;
914 876
915 policy = cpufreq_cpu_get(sibling); 877 if (has_target) {
916 WARN_ON(!policy); 878 ret = __cpufreq_governor(policy, CPUFREQ_GOV_STOP);
917 879 if (ret) {
918 if (has_target) 880 pr_err("%s: Failed to stop governor\n", __func__);
919 __cpufreq_governor(policy, CPUFREQ_GOV_STOP); 881 return ret;
882 }
883 }
920 884
921 lock_policy_rwsem_write(sibling); 885 lock_policy_rwsem_write(policy->cpu);
922 886
923 write_lock_irqsave(&cpufreq_driver_lock, flags); 887 write_lock_irqsave(&cpufreq_driver_lock, flags);
924 888
@@ -927,41 +891,86 @@ static int cpufreq_add_policy_cpu(unsigned int cpu, unsigned int sibling,
927 per_cpu(cpufreq_cpu_data, cpu) = policy; 891 per_cpu(cpufreq_cpu_data, cpu) = policy;
928 write_unlock_irqrestore(&cpufreq_driver_lock, flags); 892 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
929 893
930 unlock_policy_rwsem_write(sibling); 894 unlock_policy_rwsem_write(policy->cpu);
931 895
932 if (has_target) { 896 if (has_target) {
933 __cpufreq_governor(policy, CPUFREQ_GOV_START); 897 if ((ret = __cpufreq_governor(policy, CPUFREQ_GOV_START)) ||
934 __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS); 898 (ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS))) {
899 pr_err("%s: Failed to start governor\n", __func__);
900 return ret;
901 }
935 } 902 }
936 903
937 ret = sysfs_create_link(&dev->kobj, &policy->kobj, "cpufreq"); 904 /* Don't touch sysfs links during light-weight init */
938 if (ret) { 905 if (!frozen)
939 cpufreq_cpu_put(policy); 906 ret = sysfs_create_link(&dev->kobj, &policy->kobj, "cpufreq");
940 return ret;
941 }
942 907
943 return 0; 908 return ret;
944} 909}
945#endif 910#endif
946 911
947/** 912static struct cpufreq_policy *cpufreq_policy_restore(unsigned int cpu)
948 * cpufreq_add_dev - add a CPU device 913{
949 * 914 struct cpufreq_policy *policy;
950 * Adds the cpufreq interface for a CPU device. 915 unsigned long flags;
951 * 916
952 * The Oracle says: try running cpufreq registration/unregistration concurrently 917 write_lock_irqsave(&cpufreq_driver_lock, flags);
953 * with with cpu hotplugging and all hell will break loose. Tried to clean this 918
954 * mess up, but more thorough testing is needed. - Mathieu 919 policy = per_cpu(cpufreq_cpu_data_fallback, cpu);
955 */ 920
956static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) 921 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
922
923 return policy;
924}
925
926static struct cpufreq_policy *cpufreq_policy_alloc(void)
927{
928 struct cpufreq_policy *policy;
929
930 policy = kzalloc(sizeof(*policy), GFP_KERNEL);
931 if (!policy)
932 return NULL;
933
934 if (!alloc_cpumask_var(&policy->cpus, GFP_KERNEL))
935 goto err_free_policy;
936
937 if (!zalloc_cpumask_var(&policy->related_cpus, GFP_KERNEL))
938 goto err_free_cpumask;
939
940 INIT_LIST_HEAD(&policy->policy_list);
941 return policy;
942
943err_free_cpumask:
944 free_cpumask_var(policy->cpus);
945err_free_policy:
946 kfree(policy);
947
948 return NULL;
949}
950
951static void cpufreq_policy_free(struct cpufreq_policy *policy)
952{
953 unsigned long flags;
954
955 write_lock_irqsave(&cpufreq_driver_lock, flags);
956 list_del(&policy->policy_list);
957 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
958
959 free_cpumask_var(policy->related_cpus);
960 free_cpumask_var(policy->cpus);
961 kfree(policy);
962}
963
964static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
965 bool frozen)
957{ 966{
958 unsigned int j, cpu = dev->id; 967 unsigned int j, cpu = dev->id;
959 int ret = -ENOMEM; 968 int ret = -ENOMEM;
960 struct cpufreq_policy *policy; 969 struct cpufreq_policy *policy;
961 unsigned long flags; 970 unsigned long flags;
962#ifdef CONFIG_HOTPLUG_CPU 971#ifdef CONFIG_HOTPLUG_CPU
972 struct cpufreq_policy *tpolicy;
963 struct cpufreq_governor *gov; 973 struct cpufreq_governor *gov;
964 int sibling;
965#endif 974#endif
966 975
967 if (cpu_is_offline(cpu)) 976 if (cpu_is_offline(cpu))
@@ -978,35 +987,33 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
978 return 0; 987 return 0;
979 } 988 }
980 989
990 if (!down_read_trylock(&cpufreq_rwsem))
991 return 0;
992
981#ifdef CONFIG_HOTPLUG_CPU 993#ifdef CONFIG_HOTPLUG_CPU
982 /* Check if this cpu was hot-unplugged earlier and has siblings */ 994 /* Check if this cpu was hot-unplugged earlier and has siblings */
983 read_lock_irqsave(&cpufreq_driver_lock, flags); 995 read_lock_irqsave(&cpufreq_driver_lock, flags);
984 for_each_online_cpu(sibling) { 996 list_for_each_entry(tpolicy, &cpufreq_policy_list, policy_list) {
985 struct cpufreq_policy *cp = per_cpu(cpufreq_cpu_data, sibling); 997 if (cpumask_test_cpu(cpu, tpolicy->related_cpus)) {
986 if (cp && cpumask_test_cpu(cpu, cp->related_cpus)) {
987 read_unlock_irqrestore(&cpufreq_driver_lock, flags); 998 read_unlock_irqrestore(&cpufreq_driver_lock, flags);
988 return cpufreq_add_policy_cpu(cpu, sibling, dev); 999 ret = cpufreq_add_policy_cpu(tpolicy, cpu, dev, frozen);
1000 up_read(&cpufreq_rwsem);
1001 return ret;
989 } 1002 }
990 } 1003 }
991 read_unlock_irqrestore(&cpufreq_driver_lock, flags); 1004 read_unlock_irqrestore(&cpufreq_driver_lock, flags);
992#endif 1005#endif
993#endif 1006#endif
994 1007
995 if (!try_module_get(cpufreq_driver->owner)) { 1008 if (frozen)
996 ret = -EINVAL; 1009 /* Restore the saved policy when doing light-weight init */
997 goto module_out; 1010 policy = cpufreq_policy_restore(cpu);
998 } 1011 else
1012 policy = cpufreq_policy_alloc();
999 1013
1000 policy = kzalloc(sizeof(struct cpufreq_policy), GFP_KERNEL);
1001 if (!policy) 1014 if (!policy)
1002 goto nomem_out; 1015 goto nomem_out;
1003 1016
1004 if (!alloc_cpumask_var(&policy->cpus, GFP_KERNEL))
1005 goto err_free_policy;
1006
1007 if (!zalloc_cpumask_var(&policy->related_cpus, GFP_KERNEL))
1008 goto err_free_cpumask;
1009
1010 policy->cpu = cpu; 1017 policy->cpu = cpu;
1011 policy->governor = CPUFREQ_DEFAULT_GOVERNOR; 1018 policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
1012 cpumask_copy(policy->cpus, cpumask_of(cpu)); 1019 cpumask_copy(policy->cpus, cpumask_of(cpu));
@@ -1050,38 +1057,64 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
1050 } 1057 }
1051#endif 1058#endif
1052 1059
1053 ret = cpufreq_add_dev_interface(cpu, policy, dev); 1060 write_lock_irqsave(&cpufreq_driver_lock, flags);
1054 if (ret) 1061 for_each_cpu(j, policy->cpus) {
1055 goto err_out_unregister; 1062 per_cpu(cpufreq_cpu_data, j) = policy;
1063 per_cpu(cpufreq_policy_cpu, j) = policy->cpu;
1064 }
1065 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
1066
1067 if (!frozen) {
1068 ret = cpufreq_add_dev_interface(policy, dev);
1069 if (ret)
1070 goto err_out_unregister;
1071
1072 write_lock_irqsave(&cpufreq_driver_lock, flags);
1073 list_add(&policy->policy_list, &cpufreq_policy_list);
1074 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
1075 }
1076
1077 cpufreq_init_policy(policy);
1056 1078
1057 kobject_uevent(&policy->kobj, KOBJ_ADD); 1079 kobject_uevent(&policy->kobj, KOBJ_ADD);
1058 module_put(cpufreq_driver->owner); 1080 up_read(&cpufreq_rwsem);
1081
1059 pr_debug("initialization complete\n"); 1082 pr_debug("initialization complete\n");
1060 1083
1061 return 0; 1084 return 0;
1062 1085
1063err_out_unregister: 1086err_out_unregister:
1064 write_lock_irqsave(&cpufreq_driver_lock, flags); 1087 write_lock_irqsave(&cpufreq_driver_lock, flags);
1065 for_each_cpu(j, policy->cpus) 1088 for_each_cpu(j, policy->cpus) {
1066 per_cpu(cpufreq_cpu_data, j) = NULL; 1089 per_cpu(cpufreq_cpu_data, j) = NULL;
1090 if (j != cpu)
1091 per_cpu(cpufreq_policy_cpu, j) = -1;
1092 }
1067 write_unlock_irqrestore(&cpufreq_driver_lock, flags); 1093 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
1068 1094
1069 kobject_put(&policy->kobj);
1070 wait_for_completion(&policy->kobj_unregister);
1071
1072err_set_policy_cpu: 1095err_set_policy_cpu:
1073 per_cpu(cpufreq_policy_cpu, cpu) = -1; 1096 per_cpu(cpufreq_policy_cpu, cpu) = -1;
1074 free_cpumask_var(policy->related_cpus); 1097 cpufreq_policy_free(policy);
1075err_free_cpumask:
1076 free_cpumask_var(policy->cpus);
1077err_free_policy:
1078 kfree(policy);
1079nomem_out: 1098nomem_out:
1080 module_put(cpufreq_driver->owner); 1099 up_read(&cpufreq_rwsem);
1081module_out: 1100
1082 return ret; 1101 return ret;
1083} 1102}
1084 1103
1104/**
1105 * cpufreq_add_dev - add a CPU device
1106 *
1107 * Adds the cpufreq interface for a CPU device.
1108 *
1109 * The Oracle says: try running cpufreq registration/unregistration concurrently
1110 * with with cpu hotplugging and all hell will break loose. Tried to clean this
1111 * mess up, but more thorough testing is needed. - Mathieu
1112 */
1113static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
1114{
1115 return __cpufreq_add_dev(dev, sif, false);
1116}
1117
1085static void update_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu) 1118static void update_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu)
1086{ 1119{
1087 int j; 1120 int j;
@@ -1099,6 +1132,43 @@ static void update_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu)
1099 CPUFREQ_UPDATE_POLICY_CPU, policy); 1132 CPUFREQ_UPDATE_POLICY_CPU, policy);
1100} 1133}
1101 1134
1135static int cpufreq_nominate_new_policy_cpu(struct cpufreq_policy *policy,
1136 unsigned int old_cpu, bool frozen)
1137{
1138 struct device *cpu_dev;
1139 unsigned long flags;
1140 int ret;
1141
1142 /* first sibling now owns the new sysfs dir */
1143 cpu_dev = get_cpu_device(cpumask_first(policy->cpus));
1144
1145 /* Don't touch sysfs files during light-weight tear-down */
1146 if (frozen)
1147 return cpu_dev->id;
1148
1149 sysfs_remove_link(&cpu_dev->kobj, "cpufreq");
1150 ret = kobject_move(&policy->kobj, &cpu_dev->kobj);
1151 if (ret) {
1152 pr_err("%s: Failed to move kobj: %d", __func__, ret);
1153
1154 WARN_ON(lock_policy_rwsem_write(old_cpu));
1155 cpumask_set_cpu(old_cpu, policy->cpus);
1156
1157 write_lock_irqsave(&cpufreq_driver_lock, flags);
1158 per_cpu(cpufreq_cpu_data, old_cpu) = policy;
1159 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
1160
1161 unlock_policy_rwsem_write(old_cpu);
1162
1163 ret = sysfs_create_link(&cpu_dev->kobj, &policy->kobj,
1164 "cpufreq");
1165
1166 return -EINVAL;
1167 }
1168
1169 return cpu_dev->id;
1170}
1171
1102/** 1172/**
1103 * __cpufreq_remove_dev - remove a CPU device 1173 * __cpufreq_remove_dev - remove a CPU device
1104 * 1174 *
@@ -1107,107 +1177,118 @@ static void update_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu)
1107 * This routine frees the rwsem before returning. 1177 * This routine frees the rwsem before returning.
1108 */ 1178 */
1109static int __cpufreq_remove_dev(struct device *dev, 1179static int __cpufreq_remove_dev(struct device *dev,
1110 struct subsys_interface *sif) 1180 struct subsys_interface *sif, bool frozen)
1111{ 1181{
1112 unsigned int cpu = dev->id, ret, cpus; 1182 unsigned int cpu = dev->id, cpus;
1183 int new_cpu, ret;
1113 unsigned long flags; 1184 unsigned long flags;
1114 struct cpufreq_policy *data; 1185 struct cpufreq_policy *policy;
1115 struct kobject *kobj; 1186 struct kobject *kobj;
1116 struct completion *cmp; 1187 struct completion *cmp;
1117 struct device *cpu_dev;
1118 1188
1119 pr_debug("%s: unregistering CPU %u\n", __func__, cpu); 1189 pr_debug("%s: unregistering CPU %u\n", __func__, cpu);
1120 1190
1121 write_lock_irqsave(&cpufreq_driver_lock, flags); 1191 write_lock_irqsave(&cpufreq_driver_lock, flags);
1122 1192
1123 data = per_cpu(cpufreq_cpu_data, cpu); 1193 policy = per_cpu(cpufreq_cpu_data, cpu);
1124 per_cpu(cpufreq_cpu_data, cpu) = NULL; 1194 per_cpu(cpufreq_cpu_data, cpu) = NULL;
1125 1195
1196 /* Save the policy somewhere when doing a light-weight tear-down */
1197 if (frozen)
1198 per_cpu(cpufreq_cpu_data_fallback, cpu) = policy;
1199
1126 write_unlock_irqrestore(&cpufreq_driver_lock, flags); 1200 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
1127 1201
1128 if (!data) { 1202 if (!policy) {
1129 pr_debug("%s: No cpu_data found\n", __func__); 1203 pr_debug("%s: No cpu_data found\n", __func__);
1130 return -EINVAL; 1204 return -EINVAL;
1131 } 1205 }
1132 1206
1133 if (cpufreq_driver->target) 1207 if (cpufreq_driver->target) {
1134 __cpufreq_governor(data, CPUFREQ_GOV_STOP); 1208 ret = __cpufreq_governor(policy, CPUFREQ_GOV_STOP);
1209 if (ret) {
1210 pr_err("%s: Failed to stop governor\n", __func__);
1211 return ret;
1212 }
1213 }
1135 1214
1136#ifdef CONFIG_HOTPLUG_CPU 1215#ifdef CONFIG_HOTPLUG_CPU
1137 if (!cpufreq_driver->setpolicy) 1216 if (!cpufreq_driver->setpolicy)
1138 strncpy(per_cpu(cpufreq_cpu_governor, cpu), 1217 strncpy(per_cpu(cpufreq_cpu_governor, cpu),
1139 data->governor->name, CPUFREQ_NAME_LEN); 1218 policy->governor->name, CPUFREQ_NAME_LEN);
1140#endif 1219#endif
1141 1220
1142 WARN_ON(lock_policy_rwsem_write(cpu)); 1221 WARN_ON(lock_policy_rwsem_write(cpu));
1143 cpus = cpumask_weight(data->cpus); 1222 cpus = cpumask_weight(policy->cpus);
1144 1223
1145 if (cpus > 1) 1224 if (cpus > 1)
1146 cpumask_clear_cpu(cpu, data->cpus); 1225 cpumask_clear_cpu(cpu, policy->cpus);
1147 unlock_policy_rwsem_write(cpu); 1226 unlock_policy_rwsem_write(cpu);
1148 1227
1149 if (cpu != data->cpu) { 1228 if (cpu != policy->cpu && !frozen) {
1150 sysfs_remove_link(&dev->kobj, "cpufreq"); 1229 sysfs_remove_link(&dev->kobj, "cpufreq");
1151 } else if (cpus > 1) { 1230 } else if (cpus > 1) {
1152 /* first sibling now owns the new sysfs dir */
1153 cpu_dev = get_cpu_device(cpumask_first(data->cpus));
1154 sysfs_remove_link(&cpu_dev->kobj, "cpufreq");
1155 ret = kobject_move(&data->kobj, &cpu_dev->kobj);
1156 if (ret) {
1157 pr_err("%s: Failed to move kobj: %d", __func__, ret);
1158 1231
1232 new_cpu = cpufreq_nominate_new_policy_cpu(policy, cpu, frozen);
1233 if (new_cpu >= 0) {
1159 WARN_ON(lock_policy_rwsem_write(cpu)); 1234 WARN_ON(lock_policy_rwsem_write(cpu));
1160 cpumask_set_cpu(cpu, data->cpus); 1235 update_policy_cpu(policy, new_cpu);
1161
1162 write_lock_irqsave(&cpufreq_driver_lock, flags);
1163 per_cpu(cpufreq_cpu_data, cpu) = data;
1164 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
1165
1166 unlock_policy_rwsem_write(cpu); 1236 unlock_policy_rwsem_write(cpu);
1167 1237
1168 ret = sysfs_create_link(&cpu_dev->kobj, &data->kobj, 1238 if (!frozen) {
1169 "cpufreq"); 1239 pr_debug("%s: policy Kobject moved to cpu: %d "
1170 return -EINVAL; 1240 "from: %d\n",__func__, new_cpu, cpu);
1241 }
1171 } 1242 }
1172
1173 WARN_ON(lock_policy_rwsem_write(cpu));
1174 update_policy_cpu(data, cpu_dev->id);
1175 unlock_policy_rwsem_write(cpu);
1176 pr_debug("%s: policy Kobject moved to cpu: %d from: %d\n",
1177 __func__, cpu_dev->id, cpu);
1178 } 1243 }
1179 1244
1180 /* If cpu is last user of policy, free policy */ 1245 /* If cpu is last user of policy, free policy */
1181 if (cpus == 1) { 1246 if (cpus == 1) {
1182 if (cpufreq_driver->target) 1247 if (cpufreq_driver->target) {
1183 __cpufreq_governor(data, CPUFREQ_GOV_POLICY_EXIT); 1248 ret = __cpufreq_governor(policy,
1184 1249 CPUFREQ_GOV_POLICY_EXIT);
1185 lock_policy_rwsem_read(cpu); 1250 if (ret) {
1186 kobj = &data->kobj; 1251 pr_err("%s: Failed to exit governor\n",
1187 cmp = &data->kobj_unregister; 1252 __func__);
1188 unlock_policy_rwsem_read(cpu); 1253 return ret;
1189 kobject_put(kobj); 1254 }
1190 1255 }
1191 /* we need to make sure that the underlying kobj is actually
1192 * not referenced anymore by anybody before we proceed with
1193 * unloading.
1194 */
1195 pr_debug("waiting for dropping of refcount\n");
1196 wait_for_completion(cmp);
1197 pr_debug("wait complete\n");
1198 1256
1257 if (!frozen) {
1258 lock_policy_rwsem_read(cpu);
1259 kobj = &policy->kobj;
1260 cmp = &policy->kobj_unregister;
1261 unlock_policy_rwsem_read(cpu);
1262 kobject_put(kobj);
1263
1264 /*
1265 * We need to make sure that the underlying kobj is
1266 * actually not referenced anymore by anybody before we
1267 * proceed with unloading.
1268 */
1269 pr_debug("waiting for dropping of refcount\n");
1270 wait_for_completion(cmp);
1271 pr_debug("wait complete\n");
1272 }
1273
1274 /*
1275 * Perform the ->exit() even during light-weight tear-down,
1276 * since this is a core component, and is essential for the
1277 * subsequent light-weight ->init() to succeed.
1278 */
1199 if (cpufreq_driver->exit) 1279 if (cpufreq_driver->exit)
1200 cpufreq_driver->exit(data); 1280 cpufreq_driver->exit(policy);
1201 1281
1202 free_cpumask_var(data->related_cpus); 1282 if (!frozen)
1203 free_cpumask_var(data->cpus); 1283 cpufreq_policy_free(policy);
1204 kfree(data);
1205 } else { 1284 } else {
1206 pr_debug("%s: removing link, cpu: %d\n", __func__, cpu);
1207 cpufreq_cpu_put(data);
1208 if (cpufreq_driver->target) { 1285 if (cpufreq_driver->target) {
1209 __cpufreq_governor(data, CPUFREQ_GOV_START); 1286 if ((ret = __cpufreq_governor(policy, CPUFREQ_GOV_START)) ||
1210 __cpufreq_governor(data, CPUFREQ_GOV_LIMITS); 1287 (ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS))) {
1288 pr_err("%s: Failed to start governor\n",
1289 __func__);
1290 return ret;
1291 }
1211 } 1292 }
1212 } 1293 }
1213 1294
@@ -1223,7 +1304,7 @@ static int cpufreq_remove_dev(struct device *dev, struct subsys_interface *sif)
1223 if (cpu_is_offline(cpu)) 1304 if (cpu_is_offline(cpu))
1224 return 0; 1305 return 0;
1225 1306
1226 retval = __cpufreq_remove_dev(dev, sif); 1307 retval = __cpufreq_remove_dev(dev, sif, false);
1227 return retval; 1308 return retval;
1228} 1309}
1229 1310
@@ -1344,10 +1425,9 @@ static unsigned int __cpufreq_get(unsigned int cpu)
1344unsigned int cpufreq_get(unsigned int cpu) 1425unsigned int cpufreq_get(unsigned int cpu)
1345{ 1426{
1346 unsigned int ret_freq = 0; 1427 unsigned int ret_freq = 0;
1347 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
1348 1428
1349 if (!policy) 1429 if (!down_read_trylock(&cpufreq_rwsem))
1350 goto out; 1430 return 0;
1351 1431
1352 if (unlikely(lock_policy_rwsem_read(cpu))) 1432 if (unlikely(lock_policy_rwsem_read(cpu)))
1353 goto out_policy; 1433 goto out_policy;
@@ -1357,8 +1437,8 @@ unsigned int cpufreq_get(unsigned int cpu)
1357 unlock_policy_rwsem_read(cpu); 1437 unlock_policy_rwsem_read(cpu);
1358 1438
1359out_policy: 1439out_policy:
1360 cpufreq_cpu_put(policy); 1440 up_read(&cpufreq_rwsem);
1361out: 1441
1362 return ret_freq; 1442 return ret_freq;
1363} 1443}
1364EXPORT_SYMBOL(cpufreq_get); 1444EXPORT_SYMBOL(cpufreq_get);
@@ -1381,23 +1461,23 @@ static int cpufreq_bp_suspend(void)
1381 int ret = 0; 1461 int ret = 0;
1382 1462
1383 int cpu = smp_processor_id(); 1463 int cpu = smp_processor_id();
1384 struct cpufreq_policy *cpu_policy; 1464 struct cpufreq_policy *policy;
1385 1465
1386 pr_debug("suspending cpu %u\n", cpu); 1466 pr_debug("suspending cpu %u\n", cpu);
1387 1467
1388 /* If there's no policy for the boot CPU, we have nothing to do. */ 1468 /* If there's no policy for the boot CPU, we have nothing to do. */
1389 cpu_policy = cpufreq_cpu_get(cpu); 1469 policy = cpufreq_cpu_get(cpu);
1390 if (!cpu_policy) 1470 if (!policy)
1391 return 0; 1471 return 0;
1392 1472
1393 if (cpufreq_driver->suspend) { 1473 if (cpufreq_driver->suspend) {
1394 ret = cpufreq_driver->suspend(cpu_policy); 1474 ret = cpufreq_driver->suspend(policy);
1395 if (ret) 1475 if (ret)
1396 printk(KERN_ERR "cpufreq: suspend failed in ->suspend " 1476 printk(KERN_ERR "cpufreq: suspend failed in ->suspend "
1397 "step on CPU %u\n", cpu_policy->cpu); 1477 "step on CPU %u\n", policy->cpu);
1398 } 1478 }
1399 1479
1400 cpufreq_cpu_put(cpu_policy); 1480 cpufreq_cpu_put(policy);
1401 return ret; 1481 return ret;
1402} 1482}
1403 1483
@@ -1419,28 +1499,28 @@ static void cpufreq_bp_resume(void)
1419 int ret = 0; 1499 int ret = 0;
1420 1500
1421 int cpu = smp_processor_id(); 1501 int cpu = smp_processor_id();
1422 struct cpufreq_policy *cpu_policy; 1502 struct cpufreq_policy *policy;
1423 1503
1424 pr_debug("resuming cpu %u\n", cpu); 1504 pr_debug("resuming cpu %u\n", cpu);
1425 1505
1426 /* If there's no policy for the boot CPU, we have nothing to do. */ 1506 /* If there's no policy for the boot CPU, we have nothing to do. */
1427 cpu_policy = cpufreq_cpu_get(cpu); 1507 policy = cpufreq_cpu_get(cpu);
1428 if (!cpu_policy) 1508 if (!policy)
1429 return; 1509 return;
1430 1510
1431 if (cpufreq_driver->resume) { 1511 if (cpufreq_driver->resume) {
1432 ret = cpufreq_driver->resume(cpu_policy); 1512 ret = cpufreq_driver->resume(policy);
1433 if (ret) { 1513 if (ret) {
1434 printk(KERN_ERR "cpufreq: resume failed in ->resume " 1514 printk(KERN_ERR "cpufreq: resume failed in ->resume "
1435 "step on CPU %u\n", cpu_policy->cpu); 1515 "step on CPU %u\n", policy->cpu);
1436 goto fail; 1516 goto fail;
1437 } 1517 }
1438 } 1518 }
1439 1519
1440 schedule_work(&cpu_policy->update); 1520 schedule_work(&policy->update);
1441 1521
1442fail: 1522fail:
1443 cpufreq_cpu_put(cpu_policy); 1523 cpufreq_cpu_put(policy);
1444} 1524}
1445 1525
1446static struct syscore_ops cpufreq_syscore_ops = { 1526static struct syscore_ops cpufreq_syscore_ops = {
@@ -1594,18 +1674,6 @@ fail:
1594} 1674}
1595EXPORT_SYMBOL_GPL(cpufreq_driver_target); 1675EXPORT_SYMBOL_GPL(cpufreq_driver_target);
1596 1676
1597int __cpufreq_driver_getavg(struct cpufreq_policy *policy, unsigned int cpu)
1598{
1599 if (cpufreq_disabled())
1600 return 0;
1601
1602 if (!cpufreq_driver->getavg)
1603 return 0;
1604
1605 return cpufreq_driver->getavg(policy, cpu);
1606}
1607EXPORT_SYMBOL_GPL(__cpufreq_driver_getavg);
1608
1609/* 1677/*
1610 * when "event" is CPUFREQ_GOV_LIMITS 1678 * when "event" is CPUFREQ_GOV_LIMITS
1611 */ 1679 */
@@ -1640,8 +1708,9 @@ static int __cpufreq_governor(struct cpufreq_policy *policy,
1640 } 1708 }
1641 } 1709 }
1642 1710
1643 if (!try_module_get(policy->governor->owner)) 1711 if (event == CPUFREQ_GOV_POLICY_INIT)
1644 return -EINVAL; 1712 if (!try_module_get(policy->governor->owner))
1713 return -EINVAL;
1645 1714
1646 pr_debug("__cpufreq_governor for CPU %u, event %u\n", 1715 pr_debug("__cpufreq_governor for CPU %u, event %u\n",
1647 policy->cpu, event); 1716 policy->cpu, event);
@@ -1650,6 +1719,8 @@ static int __cpufreq_governor(struct cpufreq_policy *policy,
1650 if ((!policy->governor_enabled && (event == CPUFREQ_GOV_STOP)) || 1719 if ((!policy->governor_enabled && (event == CPUFREQ_GOV_STOP)) ||
1651 (policy->governor_enabled && (event == CPUFREQ_GOV_START))) { 1720 (policy->governor_enabled && (event == CPUFREQ_GOV_START))) {
1652 mutex_unlock(&cpufreq_governor_lock); 1721 mutex_unlock(&cpufreq_governor_lock);
1722 if (event == CPUFREQ_GOV_POLICY_INIT)
1723 module_put(policy->governor->owner);
1653 return -EBUSY; 1724 return -EBUSY;
1654 } 1725 }
1655 1726
@@ -1677,11 +1748,8 @@ static int __cpufreq_governor(struct cpufreq_policy *policy,
1677 mutex_unlock(&cpufreq_governor_lock); 1748 mutex_unlock(&cpufreq_governor_lock);
1678 } 1749 }
1679 1750
1680 /* we keep one module reference alive for 1751 if (((event == CPUFREQ_GOV_POLICY_INIT) && ret) ||
1681 each CPU governed by this CPU */ 1752 ((event == CPUFREQ_GOV_POLICY_EXIT) && !ret))
1682 if ((event != CPUFREQ_GOV_START) || ret)
1683 module_put(policy->governor->owner);
1684 if ((event == CPUFREQ_GOV_STOP) && !ret)
1685 module_put(policy->governor->owner); 1753 module_put(policy->governor->owner);
1686 1754
1687 return ret; 1755 return ret;
@@ -1761,7 +1829,7 @@ int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu)
1761 if (!cpu_policy) 1829 if (!cpu_policy)
1762 return -EINVAL; 1830 return -EINVAL;
1763 1831
1764 memcpy(policy, cpu_policy, sizeof(struct cpufreq_policy)); 1832 memcpy(policy, cpu_policy, sizeof(*policy));
1765 1833
1766 cpufreq_cpu_put(cpu_policy); 1834 cpufreq_cpu_put(cpu_policy);
1767 return 0; 1835 return 0;
@@ -1772,95 +1840,94 @@ EXPORT_SYMBOL(cpufreq_get_policy);
1772 * data : current policy. 1840 * data : current policy.
1773 * policy : policy to be set. 1841 * policy : policy to be set.
1774 */ 1842 */
1775static int __cpufreq_set_policy(struct cpufreq_policy *data, 1843static int __cpufreq_set_policy(struct cpufreq_policy *policy,
1776 struct cpufreq_policy *policy) 1844 struct cpufreq_policy *new_policy)
1777{ 1845{
1778 int ret = 0, failed = 1; 1846 int ret = 0, failed = 1;
1779 1847
1780 pr_debug("setting new policy for CPU %u: %u - %u kHz\n", policy->cpu, 1848 pr_debug("setting new policy for CPU %u: %u - %u kHz\n", new_policy->cpu,
1781 policy->min, policy->max); 1849 new_policy->min, new_policy->max);
1782 1850
1783 memcpy(&policy->cpuinfo, &data->cpuinfo, 1851 memcpy(&new_policy->cpuinfo, &policy->cpuinfo, sizeof(policy->cpuinfo));
1784 sizeof(struct cpufreq_cpuinfo));
1785 1852
1786 if (policy->min > data->max || policy->max < data->min) { 1853 if (new_policy->min > policy->max || new_policy->max < policy->min) {
1787 ret = -EINVAL; 1854 ret = -EINVAL;
1788 goto error_out; 1855 goto error_out;
1789 } 1856 }
1790 1857
1791 /* verify the cpu speed can be set within this limit */ 1858 /* verify the cpu speed can be set within this limit */
1792 ret = cpufreq_driver->verify(policy); 1859 ret = cpufreq_driver->verify(new_policy);
1793 if (ret) 1860 if (ret)
1794 goto error_out; 1861 goto error_out;
1795 1862
1796 /* adjust if necessary - all reasons */ 1863 /* adjust if necessary - all reasons */
1797 blocking_notifier_call_chain(&cpufreq_policy_notifier_list, 1864 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1798 CPUFREQ_ADJUST, policy); 1865 CPUFREQ_ADJUST, new_policy);
1799 1866
1800 /* adjust if necessary - hardware incompatibility*/ 1867 /* adjust if necessary - hardware incompatibility*/
1801 blocking_notifier_call_chain(&cpufreq_policy_notifier_list, 1868 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1802 CPUFREQ_INCOMPATIBLE, policy); 1869 CPUFREQ_INCOMPATIBLE, new_policy);
1803 1870
1804 /* 1871 /*
1805 * verify the cpu speed can be set within this limit, which might be 1872 * verify the cpu speed can be set within this limit, which might be
1806 * different to the first one 1873 * different to the first one
1807 */ 1874 */
1808 ret = cpufreq_driver->verify(policy); 1875 ret = cpufreq_driver->verify(new_policy);
1809 if (ret) 1876 if (ret)
1810 goto error_out; 1877 goto error_out;
1811 1878
1812 /* notification of the new policy */ 1879 /* notification of the new policy */
1813 blocking_notifier_call_chain(&cpufreq_policy_notifier_list, 1880 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1814 CPUFREQ_NOTIFY, policy); 1881 CPUFREQ_NOTIFY, new_policy);
1815 1882
1816 data->min = policy->min; 1883 policy->min = new_policy->min;
1817 data->max = policy->max; 1884 policy->max = new_policy->max;
1818 1885
1819 pr_debug("new min and max freqs are %u - %u kHz\n", 1886 pr_debug("new min and max freqs are %u - %u kHz\n",
1820 data->min, data->max); 1887 policy->min, policy->max);
1821 1888
1822 if (cpufreq_driver->setpolicy) { 1889 if (cpufreq_driver->setpolicy) {
1823 data->policy = policy->policy; 1890 policy->policy = new_policy->policy;
1824 pr_debug("setting range\n"); 1891 pr_debug("setting range\n");
1825 ret = cpufreq_driver->setpolicy(policy); 1892 ret = cpufreq_driver->setpolicy(new_policy);
1826 } else { 1893 } else {
1827 if (policy->governor != data->governor) { 1894 if (new_policy->governor != policy->governor) {
1828 /* save old, working values */ 1895 /* save old, working values */
1829 struct cpufreq_governor *old_gov = data->governor; 1896 struct cpufreq_governor *old_gov = policy->governor;
1830 1897
1831 pr_debug("governor switch\n"); 1898 pr_debug("governor switch\n");
1832 1899
1833 /* end old governor */ 1900 /* end old governor */
1834 if (data->governor) { 1901 if (policy->governor) {
1835 __cpufreq_governor(data, CPUFREQ_GOV_STOP); 1902 __cpufreq_governor(policy, CPUFREQ_GOV_STOP);
1836 unlock_policy_rwsem_write(policy->cpu); 1903 unlock_policy_rwsem_write(new_policy->cpu);
1837 __cpufreq_governor(data, 1904 __cpufreq_governor(policy,
1838 CPUFREQ_GOV_POLICY_EXIT); 1905 CPUFREQ_GOV_POLICY_EXIT);
1839 lock_policy_rwsem_write(policy->cpu); 1906 lock_policy_rwsem_write(new_policy->cpu);
1840 } 1907 }
1841 1908
1842 /* start new governor */ 1909 /* start new governor */
1843 data->governor = policy->governor; 1910 policy->governor = new_policy->governor;
1844 if (!__cpufreq_governor(data, CPUFREQ_GOV_POLICY_INIT)) { 1911 if (!__cpufreq_governor(policy, CPUFREQ_GOV_POLICY_INIT)) {
1845 if (!__cpufreq_governor(data, CPUFREQ_GOV_START)) { 1912 if (!__cpufreq_governor(policy, CPUFREQ_GOV_START)) {
1846 failed = 0; 1913 failed = 0;
1847 } else { 1914 } else {
1848 unlock_policy_rwsem_write(policy->cpu); 1915 unlock_policy_rwsem_write(new_policy->cpu);
1849 __cpufreq_governor(data, 1916 __cpufreq_governor(policy,
1850 CPUFREQ_GOV_POLICY_EXIT); 1917 CPUFREQ_GOV_POLICY_EXIT);
1851 lock_policy_rwsem_write(policy->cpu); 1918 lock_policy_rwsem_write(new_policy->cpu);
1852 } 1919 }
1853 } 1920 }
1854 1921
1855 if (failed) { 1922 if (failed) {
1856 /* new governor failed, so re-start old one */ 1923 /* new governor failed, so re-start old one */
1857 pr_debug("starting governor %s failed\n", 1924 pr_debug("starting governor %s failed\n",
1858 data->governor->name); 1925 policy->governor->name);
1859 if (old_gov) { 1926 if (old_gov) {
1860 data->governor = old_gov; 1927 policy->governor = old_gov;
1861 __cpufreq_governor(data, 1928 __cpufreq_governor(policy,
1862 CPUFREQ_GOV_POLICY_INIT); 1929 CPUFREQ_GOV_POLICY_INIT);
1863 __cpufreq_governor(data, 1930 __cpufreq_governor(policy,
1864 CPUFREQ_GOV_START); 1931 CPUFREQ_GOV_START);
1865 } 1932 }
1866 ret = -EINVAL; 1933 ret = -EINVAL;
@@ -1869,7 +1936,7 @@ static int __cpufreq_set_policy(struct cpufreq_policy *data,
1869 /* might be a policy change, too, so fall through */ 1936 /* might be a policy change, too, so fall through */
1870 } 1937 }
1871 pr_debug("governor: change or update limits\n"); 1938 pr_debug("governor: change or update limits\n");
1872 __cpufreq_governor(data, CPUFREQ_GOV_LIMITS); 1939 ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
1873 } 1940 }
1874 1941
1875error_out: 1942error_out:
@@ -1885,11 +1952,11 @@ error_out:
1885 */ 1952 */
1886int cpufreq_update_policy(unsigned int cpu) 1953int cpufreq_update_policy(unsigned int cpu)
1887{ 1954{
1888 struct cpufreq_policy *data = cpufreq_cpu_get(cpu); 1955 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
1889 struct cpufreq_policy policy; 1956 struct cpufreq_policy new_policy;
1890 int ret; 1957 int ret;
1891 1958
1892 if (!data) { 1959 if (!policy) {
1893 ret = -ENODEV; 1960 ret = -ENODEV;
1894 goto no_policy; 1961 goto no_policy;
1895 } 1962 }
@@ -1900,34 +1967,34 @@ int cpufreq_update_policy(unsigned int cpu)
1900 } 1967 }
1901 1968
1902 pr_debug("updating policy for CPU %u\n", cpu); 1969 pr_debug("updating policy for CPU %u\n", cpu);
1903 memcpy(&policy, data, sizeof(struct cpufreq_policy)); 1970 memcpy(&new_policy, policy, sizeof(*policy));
1904 policy.min = data->user_policy.min; 1971 new_policy.min = policy->user_policy.min;
1905 policy.max = data->user_policy.max; 1972 new_policy.max = policy->user_policy.max;
1906 policy.policy = data->user_policy.policy; 1973 new_policy.policy = policy->user_policy.policy;
1907 policy.governor = data->user_policy.governor; 1974 new_policy.governor = policy->user_policy.governor;
1908 1975
1909 /* 1976 /*
1910 * BIOS might change freq behind our back 1977 * BIOS might change freq behind our back
1911 * -> ask driver for current freq and notify governors about a change 1978 * -> ask driver for current freq and notify governors about a change
1912 */ 1979 */
1913 if (cpufreq_driver->get) { 1980 if (cpufreq_driver->get) {
1914 policy.cur = cpufreq_driver->get(cpu); 1981 new_policy.cur = cpufreq_driver->get(cpu);
1915 if (!data->cur) { 1982 if (!policy->cur) {
1916 pr_debug("Driver did not initialize current freq"); 1983 pr_debug("Driver did not initialize current freq");
1917 data->cur = policy.cur; 1984 policy->cur = new_policy.cur;
1918 } else { 1985 } else {
1919 if (data->cur != policy.cur && cpufreq_driver->target) 1986 if (policy->cur != new_policy.cur && cpufreq_driver->target)
1920 cpufreq_out_of_sync(cpu, data->cur, 1987 cpufreq_out_of_sync(cpu, policy->cur,
1921 policy.cur); 1988 new_policy.cur);
1922 } 1989 }
1923 } 1990 }
1924 1991
1925 ret = __cpufreq_set_policy(data, &policy); 1992 ret = __cpufreq_set_policy(policy, &new_policy);
1926 1993
1927 unlock_policy_rwsem_write(cpu); 1994 unlock_policy_rwsem_write(cpu);
1928 1995
1929fail: 1996fail:
1930 cpufreq_cpu_put(data); 1997 cpufreq_cpu_put(policy);
1931no_policy: 1998no_policy:
1932 return ret; 1999 return ret;
1933} 2000}
@@ -1938,21 +2005,26 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
1938{ 2005{
1939 unsigned int cpu = (unsigned long)hcpu; 2006 unsigned int cpu = (unsigned long)hcpu;
1940 struct device *dev; 2007 struct device *dev;
2008 bool frozen = false;
1941 2009
1942 dev = get_cpu_device(cpu); 2010 dev = get_cpu_device(cpu);
1943 if (dev) { 2011 if (dev) {
1944 switch (action) { 2012
2013 if (action & CPU_TASKS_FROZEN)
2014 frozen = true;
2015
2016 switch (action & ~CPU_TASKS_FROZEN) {
1945 case CPU_ONLINE: 2017 case CPU_ONLINE:
1946 case CPU_ONLINE_FROZEN: 2018 __cpufreq_add_dev(dev, NULL, frozen);
1947 cpufreq_add_dev(dev, NULL); 2019 cpufreq_update_policy(cpu);
1948 break; 2020 break;
2021
1949 case CPU_DOWN_PREPARE: 2022 case CPU_DOWN_PREPARE:
1950 case CPU_DOWN_PREPARE_FROZEN: 2023 __cpufreq_remove_dev(dev, NULL, frozen);
1951 __cpufreq_remove_dev(dev, NULL);
1952 break; 2024 break;
2025
1953 case CPU_DOWN_FAILED: 2026 case CPU_DOWN_FAILED:
1954 case CPU_DOWN_FAILED_FROZEN: 2027 __cpufreq_add_dev(dev, NULL, frozen);
1955 cpufreq_add_dev(dev, NULL);
1956 break; 2028 break;
1957 } 2029 }
1958 } 2030 }
@@ -2059,9 +2131,13 @@ int cpufreq_unregister_driver(struct cpufreq_driver *driver)
2059 subsys_interface_unregister(&cpufreq_interface); 2131 subsys_interface_unregister(&cpufreq_interface);
2060 unregister_hotcpu_notifier(&cpufreq_cpu_notifier); 2132 unregister_hotcpu_notifier(&cpufreq_cpu_notifier);
2061 2133
2134 down_write(&cpufreq_rwsem);
2062 write_lock_irqsave(&cpufreq_driver_lock, flags); 2135 write_lock_irqsave(&cpufreq_driver_lock, flags);
2136
2063 cpufreq_driver = NULL; 2137 cpufreq_driver = NULL;
2138
2064 write_unlock_irqrestore(&cpufreq_driver_lock, flags); 2139 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
2140 up_write(&cpufreq_rwsem);
2065 2141
2066 return 0; 2142 return 0;
2067} 2143}
diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c
index f97cb3d8c5a2..7f67a75b3c3c 100644
--- a/drivers/cpufreq/cpufreq_conservative.c
+++ b/drivers/cpufreq/cpufreq_conservative.c
@@ -11,19 +11,7 @@
11 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
12 */ 12 */
13 13
14#include <linux/cpufreq.h>
15#include <linux/init.h>
16#include <linux/kernel.h>
17#include <linux/kernel_stat.h>
18#include <linux/kobject.h>
19#include <linux/module.h>
20#include <linux/mutex.h>
21#include <linux/notifier.h>
22#include <linux/percpu-defs.h>
23#include <linux/slab.h> 14#include <linux/slab.h>
24#include <linux/sysfs.h>
25#include <linux/types.h>
26
27#include "cpufreq_governor.h" 15#include "cpufreq_governor.h"
28 16
29/* Conservative governor macros */ 17/* Conservative governor macros */
@@ -329,7 +317,7 @@ static int cs_init(struct dbs_data *dbs_data)
329{ 317{
330 struct cs_dbs_tuners *tuners; 318 struct cs_dbs_tuners *tuners;
331 319
332 tuners = kzalloc(sizeof(struct cs_dbs_tuners), GFP_KERNEL); 320 tuners = kzalloc(sizeof(*tuners), GFP_KERNEL);
333 if (!tuners) { 321 if (!tuners) {
334 pr_err("%s: kzalloc failed\n", __func__); 322 pr_err("%s: kzalloc failed\n", __func__);
335 return -ENOMEM; 323 return -ENOMEM;
diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
index e59afaa9da23..87427360c77f 100644
--- a/drivers/cpufreq/cpufreq_governor.c
+++ b/drivers/cpufreq/cpufreq_governor.c
@@ -16,15 +16,9 @@
16 16
17#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 17#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18 18
19#include <asm/cputime.h>
20#include <linux/cpufreq.h>
21#include <linux/cpumask.h>
22#include <linux/export.h> 19#include <linux/export.h>
23#include <linux/kernel_stat.h> 20#include <linux/kernel_stat.h>
24#include <linux/mutex.h>
25#include <linux/slab.h> 21#include <linux/slab.h>
26#include <linux/types.h>
27#include <linux/workqueue.h>
28 22
29#include "cpufreq_governor.h" 23#include "cpufreq_governor.h"
30 24
@@ -53,7 +47,7 @@ void dbs_check_cpu(struct dbs_data *dbs_data, int cpu)
53 47
54 policy = cdbs->cur_policy; 48 policy = cdbs->cur_policy;
55 49
56 /* Get Absolute Load (in terms of freq for ondemand gov) */ 50 /* Get Absolute Load */
57 for_each_cpu(j, policy->cpus) { 51 for_each_cpu(j, policy->cpus) {
58 struct cpu_dbs_common_info *j_cdbs; 52 struct cpu_dbs_common_info *j_cdbs;
59 u64 cur_wall_time, cur_idle_time; 53 u64 cur_wall_time, cur_idle_time;
@@ -104,14 +98,6 @@ void dbs_check_cpu(struct dbs_data *dbs_data, int cpu)
104 98
105 load = 100 * (wall_time - idle_time) / wall_time; 99 load = 100 * (wall_time - idle_time) / wall_time;
106 100
107 if (dbs_data->cdata->governor == GOV_ONDEMAND) {
108 int freq_avg = __cpufreq_driver_getavg(policy, j);
109 if (freq_avg <= 0)
110 freq_avg = policy->cur;
111
112 load *= freq_avg;
113 }
114
115 if (load > max_load) 101 if (load > max_load)
116 max_load = load; 102 max_load = load;
117 } 103 }
diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
index d5f12b4b11b8..a02d78b25898 100644
--- a/drivers/cpufreq/cpufreq_governor.h
+++ b/drivers/cpufreq/cpufreq_governor.h
@@ -18,10 +18,9 @@
18#define _CPUFREQ_GOVERNOR_H 18#define _CPUFREQ_GOVERNOR_H
19 19
20#include <linux/cpufreq.h> 20#include <linux/cpufreq.h>
21#include <linux/kobject.h> 21#include <linux/kernel_stat.h>
22#include <linux/module.h>
22#include <linux/mutex.h> 23#include <linux/mutex.h>
23#include <linux/workqueue.h>
24#include <linux/sysfs.h>
25 24
26/* 25/*
27 * The polling frequency depends on the capability of the processor. Default 26 * The polling frequency depends on the capability of the processor. Default
@@ -169,7 +168,6 @@ struct od_dbs_tuners {
169 unsigned int sampling_rate; 168 unsigned int sampling_rate;
170 unsigned int sampling_down_factor; 169 unsigned int sampling_down_factor;
171 unsigned int up_threshold; 170 unsigned int up_threshold;
172 unsigned int adj_up_threshold;
173 unsigned int powersave_bias; 171 unsigned int powersave_bias;
174 unsigned int io_is_busy; 172 unsigned int io_is_busy;
175}; 173};
@@ -223,7 +221,7 @@ struct od_ops {
223 void (*powersave_bias_init_cpu)(int cpu); 221 void (*powersave_bias_init_cpu)(int cpu);
224 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy, 222 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
225 unsigned int freq_next, unsigned int relation); 223 unsigned int freq_next, unsigned int relation);
226 void (*freq_increase)(struct cpufreq_policy *p, unsigned int freq); 224 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
227}; 225};
228 226
229struct cs_ops { 227struct cs_ops {
diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
index c087347d6688..87f3305e80a6 100644
--- a/drivers/cpufreq/cpufreq_ondemand.c
+++ b/drivers/cpufreq/cpufreq_ondemand.c
@@ -12,28 +12,16 @@
12 12
13#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 13#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14 14
15#include <linux/cpufreq.h> 15#include <linux/cpu.h>
16#include <linux/init.h>
17#include <linux/kernel.h>
18#include <linux/kernel_stat.h>
19#include <linux/kobject.h>
20#include <linux/module.h>
21#include <linux/mutex.h>
22#include <linux/percpu-defs.h> 16#include <linux/percpu-defs.h>
23#include <linux/slab.h> 17#include <linux/slab.h>
24#include <linux/sysfs.h>
25#include <linux/tick.h> 18#include <linux/tick.h>
26#include <linux/types.h>
27#include <linux/cpu.h>
28
29#include "cpufreq_governor.h" 19#include "cpufreq_governor.h"
30 20
31/* On-demand governor macros */ 21/* On-demand governor macros */
32#define DEF_FREQUENCY_DOWN_DIFFERENTIAL (10)
33#define DEF_FREQUENCY_UP_THRESHOLD (80) 22#define DEF_FREQUENCY_UP_THRESHOLD (80)
34#define DEF_SAMPLING_DOWN_FACTOR (1) 23#define DEF_SAMPLING_DOWN_FACTOR (1)
35#define MAX_SAMPLING_DOWN_FACTOR (100000) 24#define MAX_SAMPLING_DOWN_FACTOR (100000)
36#define MICRO_FREQUENCY_DOWN_DIFFERENTIAL (3)
37#define MICRO_FREQUENCY_UP_THRESHOLD (95) 25#define MICRO_FREQUENCY_UP_THRESHOLD (95)
38#define MICRO_FREQUENCY_MIN_SAMPLE_RATE (10000) 26#define MICRO_FREQUENCY_MIN_SAMPLE_RATE (10000)
39#define MIN_FREQUENCY_UP_THRESHOLD (11) 27#define MIN_FREQUENCY_UP_THRESHOLD (11)
@@ -144,31 +132,27 @@ static void ondemand_powersave_bias_init(void)
144 } 132 }
145} 133}
146 134
147static void dbs_freq_increase(struct cpufreq_policy *p, unsigned int freq) 135static void dbs_freq_increase(struct cpufreq_policy *policy, unsigned int freq)
148{ 136{
149 struct dbs_data *dbs_data = p->governor_data; 137 struct dbs_data *dbs_data = policy->governor_data;
150 struct od_dbs_tuners *od_tuners = dbs_data->tuners; 138 struct od_dbs_tuners *od_tuners = dbs_data->tuners;
151 139
152 if (od_tuners->powersave_bias) 140 if (od_tuners->powersave_bias)
153 freq = od_ops.powersave_bias_target(p, freq, 141 freq = od_ops.powersave_bias_target(policy, freq,
154 CPUFREQ_RELATION_H); 142 CPUFREQ_RELATION_H);
155 else if (p->cur == p->max) 143 else if (policy->cur == policy->max)
156 return; 144 return;
157 145
158 __cpufreq_driver_target(p, freq, od_tuners->powersave_bias ? 146 __cpufreq_driver_target(policy, freq, od_tuners->powersave_bias ?
159 CPUFREQ_RELATION_L : CPUFREQ_RELATION_H); 147 CPUFREQ_RELATION_L : CPUFREQ_RELATION_H);
160} 148}
161 149
162/* 150/*
163 * Every sampling_rate, we check, if current idle time is less than 20% 151 * Every sampling_rate, we check, if current idle time is less than 20%
164 * (default), then we try to increase frequency. Every sampling_rate, we look 152 * (default), then we try to increase frequency. Else, we adjust the frequency
165 * for the lowest frequency which can sustain the load while keeping idle time 153 * proportional to load.
166 * over 30%. If such a frequency exist, we try to decrease to this frequency.
167 *
168 * Any frequency increase takes it to the maximum frequency. Frequency reduction
169 * happens at minimum steps of 5% (default) of current frequency
170 */ 154 */
171static void od_check_cpu(int cpu, unsigned int load_freq) 155static void od_check_cpu(int cpu, unsigned int load)
172{ 156{
173 struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info, cpu); 157 struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info, cpu);
174 struct cpufreq_policy *policy = dbs_info->cdbs.cur_policy; 158 struct cpufreq_policy *policy = dbs_info->cdbs.cur_policy;
@@ -178,29 +162,17 @@ static void od_check_cpu(int cpu, unsigned int load_freq)
178 dbs_info->freq_lo = 0; 162 dbs_info->freq_lo = 0;
179 163
180 /* Check for frequency increase */ 164 /* Check for frequency increase */
181 if (load_freq > od_tuners->up_threshold * policy->cur) { 165 if (load > od_tuners->up_threshold) {
182 /* If switching to max speed, apply sampling_down_factor */ 166 /* If switching to max speed, apply sampling_down_factor */
183 if (policy->cur < policy->max) 167 if (policy->cur < policy->max)
184 dbs_info->rate_mult = 168 dbs_info->rate_mult =
185 od_tuners->sampling_down_factor; 169 od_tuners->sampling_down_factor;
186 dbs_freq_increase(policy, policy->max); 170 dbs_freq_increase(policy, policy->max);
187 return; 171 return;
188 } 172 } else {
189 173 /* Calculate the next frequency proportional to load */
190 /* Check for frequency decrease */
191 /* if we cannot reduce the frequency anymore, break out early */
192 if (policy->cur == policy->min)
193 return;
194
195 /*
196 * The optimal frequency is the frequency that is the lowest that can
197 * support the current CPU usage without triggering the up policy. To be
198 * safe, we focus 10 points under the threshold.
199 */
200 if (load_freq < od_tuners->adj_up_threshold
201 * policy->cur) {
202 unsigned int freq_next; 174 unsigned int freq_next;
203 freq_next = load_freq / od_tuners->adj_up_threshold; 175 freq_next = load * policy->cpuinfo.max_freq / 100;
204 176
205 /* No longer fully busy, reset rate_mult */ 177 /* No longer fully busy, reset rate_mult */
206 dbs_info->rate_mult = 1; 178 dbs_info->rate_mult = 1;
@@ -374,9 +346,6 @@ static ssize_t store_up_threshold(struct dbs_data *dbs_data, const char *buf,
374 input < MIN_FREQUENCY_UP_THRESHOLD) { 346 input < MIN_FREQUENCY_UP_THRESHOLD) {
375 return -EINVAL; 347 return -EINVAL;
376 } 348 }
377 /* Calculate the new adj_up_threshold */
378 od_tuners->adj_up_threshold += input;
379 od_tuners->adj_up_threshold -= od_tuners->up_threshold;
380 349
381 od_tuners->up_threshold = input; 350 od_tuners->up_threshold = input;
382 return count; 351 return count;
@@ -513,7 +482,7 @@ static int od_init(struct dbs_data *dbs_data)
513 u64 idle_time; 482 u64 idle_time;
514 int cpu; 483 int cpu;
515 484
516 tuners = kzalloc(sizeof(struct od_dbs_tuners), GFP_KERNEL); 485 tuners = kzalloc(sizeof(*tuners), GFP_KERNEL);
517 if (!tuners) { 486 if (!tuners) {
518 pr_err("%s: kzalloc failed\n", __func__); 487 pr_err("%s: kzalloc failed\n", __func__);
519 return -ENOMEM; 488 return -ENOMEM;
@@ -525,8 +494,6 @@ static int od_init(struct dbs_data *dbs_data)
525 if (idle_time != -1ULL) { 494 if (idle_time != -1ULL) {
526 /* Idle micro accounting is supported. Use finer thresholds */ 495 /* Idle micro accounting is supported. Use finer thresholds */
527 tuners->up_threshold = MICRO_FREQUENCY_UP_THRESHOLD; 496 tuners->up_threshold = MICRO_FREQUENCY_UP_THRESHOLD;
528 tuners->adj_up_threshold = MICRO_FREQUENCY_UP_THRESHOLD -
529 MICRO_FREQUENCY_DOWN_DIFFERENTIAL;
530 /* 497 /*
531 * In nohz/micro accounting case we set the minimum frequency 498 * In nohz/micro accounting case we set the minimum frequency
532 * not depending on HZ, but fixed (very low). The deferred 499 * not depending on HZ, but fixed (very low). The deferred
@@ -535,8 +502,6 @@ static int od_init(struct dbs_data *dbs_data)
535 dbs_data->min_sampling_rate = MICRO_FREQUENCY_MIN_SAMPLE_RATE; 502 dbs_data->min_sampling_rate = MICRO_FREQUENCY_MIN_SAMPLE_RATE;
536 } else { 503 } else {
537 tuners->up_threshold = DEF_FREQUENCY_UP_THRESHOLD; 504 tuners->up_threshold = DEF_FREQUENCY_UP_THRESHOLD;
538 tuners->adj_up_threshold = DEF_FREQUENCY_UP_THRESHOLD -
539 DEF_FREQUENCY_DOWN_DIFFERENTIAL;
540 505
541 /* For correct statistics, we need 10 ticks for each measure */ 506 /* For correct statistics, we need 10 ticks for each measure */
542 dbs_data->min_sampling_rate = MIN_SAMPLING_RATE_RATIO * 507 dbs_data->min_sampling_rate = MIN_SAMPLING_RATE_RATIO *
diff --git a/drivers/cpufreq/cpufreq_performance.c b/drivers/cpufreq/cpufreq_performance.c
index 9fef7d6e4e6a..cf117deb39b1 100644
--- a/drivers/cpufreq/cpufreq_performance.c
+++ b/drivers/cpufreq/cpufreq_performance.c
@@ -12,10 +12,9 @@
12 12
13#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 13#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14 14
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/cpufreq.h> 15#include <linux/cpufreq.h>
18#include <linux/init.h> 16#include <linux/init.h>
17#include <linux/module.h>
19 18
20static int cpufreq_governor_performance(struct cpufreq_policy *policy, 19static int cpufreq_governor_performance(struct cpufreq_policy *policy,
21 unsigned int event) 20 unsigned int event)
diff --git a/drivers/cpufreq/cpufreq_powersave.c b/drivers/cpufreq/cpufreq_powersave.c
index 32109a14f5dc..e3b874c235ea 100644
--- a/drivers/cpufreq/cpufreq_powersave.c
+++ b/drivers/cpufreq/cpufreq_powersave.c
@@ -12,10 +12,9 @@
12 12
13#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 13#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14 14
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/cpufreq.h> 15#include <linux/cpufreq.h>
18#include <linux/init.h> 16#include <linux/init.h>
17#include <linux/module.h>
19 18
20static int cpufreq_governor_powersave(struct cpufreq_policy *policy, 19static int cpufreq_governor_powersave(struct cpufreq_policy *policy,
21 unsigned int event) 20 unsigned int event)
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
index d37568c5ca9c..04452f026ed0 100644
--- a/drivers/cpufreq/cpufreq_stats.c
+++ b/drivers/cpufreq/cpufreq_stats.c
@@ -9,17 +9,10 @@
9 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
10 */ 10 */
11 11
12#include <linux/kernel.h>
13#include <linux/slab.h>
14#include <linux/cpu.h> 12#include <linux/cpu.h>
15#include <linux/sysfs.h>
16#include <linux/cpufreq.h> 13#include <linux/cpufreq.h>
17#include <linux/module.h> 14#include <linux/module.h>
18#include <linux/jiffies.h> 15#include <linux/slab.h>
19#include <linux/percpu.h>
20#include <linux/kobject.h>
21#include <linux/spinlock.h>
22#include <linux/notifier.h>
23#include <asm/cputime.h> 16#include <asm/cputime.h>
24 17
25static spinlock_t cpufreq_stats_lock; 18static spinlock_t cpufreq_stats_lock;
@@ -200,22 +193,22 @@ static int cpufreq_stats_create_table(struct cpufreq_policy *policy,
200{ 193{
201 unsigned int i, j, count = 0, ret = 0; 194 unsigned int i, j, count = 0, ret = 0;
202 struct cpufreq_stats *stat; 195 struct cpufreq_stats *stat;
203 struct cpufreq_policy *data; 196 struct cpufreq_policy *current_policy;
204 unsigned int alloc_size; 197 unsigned int alloc_size;
205 unsigned int cpu = policy->cpu; 198 unsigned int cpu = policy->cpu;
206 if (per_cpu(cpufreq_stats_table, cpu)) 199 if (per_cpu(cpufreq_stats_table, cpu))
207 return -EBUSY; 200 return -EBUSY;
208 stat = kzalloc(sizeof(struct cpufreq_stats), GFP_KERNEL); 201 stat = kzalloc(sizeof(*stat), GFP_KERNEL);
209 if ((stat) == NULL) 202 if ((stat) == NULL)
210 return -ENOMEM; 203 return -ENOMEM;
211 204
212 data = cpufreq_cpu_get(cpu); 205 current_policy = cpufreq_cpu_get(cpu);
213 if (data == NULL) { 206 if (current_policy == NULL) {
214 ret = -EINVAL; 207 ret = -EINVAL;
215 goto error_get_fail; 208 goto error_get_fail;
216 } 209 }
217 210
218 ret = sysfs_create_group(&data->kobj, &stats_attr_group); 211 ret = sysfs_create_group(&current_policy->kobj, &stats_attr_group);
219 if (ret) 212 if (ret)
220 goto error_out; 213 goto error_out;
221 214
@@ -258,10 +251,10 @@ static int cpufreq_stats_create_table(struct cpufreq_policy *policy,
258 stat->last_time = get_jiffies_64(); 251 stat->last_time = get_jiffies_64();
259 stat->last_index = freq_table_get_index(stat, policy->cur); 252 stat->last_index = freq_table_get_index(stat, policy->cur);
260 spin_unlock(&cpufreq_stats_lock); 253 spin_unlock(&cpufreq_stats_lock);
261 cpufreq_cpu_put(data); 254 cpufreq_cpu_put(current_policy);
262 return 0; 255 return 0;
263error_out: 256error_out:
264 cpufreq_cpu_put(data); 257 cpufreq_cpu_put(current_policy);
265error_get_fail: 258error_get_fail:
266 kfree(stat); 259 kfree(stat);
267 per_cpu(cpufreq_stats_table, cpu) = NULL; 260 per_cpu(cpufreq_stats_table, cpu) = NULL;
@@ -348,16 +341,10 @@ static int cpufreq_stat_cpu_callback(struct notifier_block *nfb,
348 unsigned int cpu = (unsigned long)hcpu; 341 unsigned int cpu = (unsigned long)hcpu;
349 342
350 switch (action) { 343 switch (action) {
351 case CPU_ONLINE:
352 case CPU_ONLINE_FROZEN:
353 cpufreq_update_policy(cpu);
354 break;
355 case CPU_DOWN_PREPARE: 344 case CPU_DOWN_PREPARE:
356 case CPU_DOWN_PREPARE_FROZEN:
357 cpufreq_stats_free_sysfs(cpu); 345 cpufreq_stats_free_sysfs(cpu);
358 break; 346 break;
359 case CPU_DEAD: 347 case CPU_DEAD:
360 case CPU_DEAD_FROZEN:
361 cpufreq_stats_free_table(cpu); 348 cpufreq_stats_free_table(cpu);
362 break; 349 break;
363 } 350 }
@@ -390,8 +377,6 @@ static int __init cpufreq_stats_init(void)
390 return ret; 377 return ret;
391 378
392 register_hotcpu_notifier(&cpufreq_stat_cpu_notifier); 379 register_hotcpu_notifier(&cpufreq_stat_cpu_notifier);
393 for_each_online_cpu(cpu)
394 cpufreq_update_policy(cpu);
395 380
396 ret = cpufreq_register_notifier(&notifier_trans_block, 381 ret = cpufreq_register_notifier(&notifier_trans_block,
397 CPUFREQ_TRANSITION_NOTIFIER); 382 CPUFREQ_TRANSITION_NOTIFIER);
diff --git a/drivers/cpufreq/cris-artpec3-cpufreq.c b/drivers/cpufreq/cris-artpec3-cpufreq.c
index ee142c490575..cb8276dd19ca 100644
--- a/drivers/cpufreq/cris-artpec3-cpufreq.c
+++ b/drivers/cpufreq/cris-artpec3-cpufreq.c
@@ -111,7 +111,6 @@ static struct cpufreq_driver cris_freq_driver = {
111 .init = cris_freq_cpu_init, 111 .init = cris_freq_cpu_init,
112 .exit = cris_freq_cpu_exit, 112 .exit = cris_freq_cpu_exit,
113 .name = "cris_freq", 113 .name = "cris_freq",
114 .owner = THIS_MODULE,
115 .attr = cris_freq_attr, 114 .attr = cris_freq_attr,
116}; 115};
117 116
diff --git a/drivers/cpufreq/cris-etraxfs-cpufreq.c b/drivers/cpufreq/cris-etraxfs-cpufreq.c
index 12952235d5db..72328f77dc53 100644
--- a/drivers/cpufreq/cris-etraxfs-cpufreq.c
+++ b/drivers/cpufreq/cris-etraxfs-cpufreq.c
@@ -108,7 +108,6 @@ static struct cpufreq_driver cris_freq_driver = {
108 .init = cris_freq_cpu_init, 108 .init = cris_freq_cpu_init,
109 .exit = cris_freq_cpu_exit, 109 .exit = cris_freq_cpu_exit,
110 .name = "cris_freq", 110 .name = "cris_freq",
111 .owner = THIS_MODULE,
112 .attr = cris_freq_attr, 111 .attr = cris_freq_attr,
113}; 112};
114 113
diff --git a/drivers/cpufreq/e_powersaver.c b/drivers/cpufreq/e_powersaver.c
index a60efaeb4cf8..09f64cc83019 100644
--- a/drivers/cpufreq/e_powersaver.c
+++ b/drivers/cpufreq/e_powersaver.c
@@ -54,7 +54,7 @@ static struct acpi_processor_performance *eps_acpi_cpu_perf;
54/* Minimum necessary to get acpi_processor_get_bios_limit() working */ 54/* Minimum necessary to get acpi_processor_get_bios_limit() working */
55static int eps_acpi_init(void) 55static int eps_acpi_init(void)
56{ 56{
57 eps_acpi_cpu_perf = kzalloc(sizeof(struct acpi_processor_performance), 57 eps_acpi_cpu_perf = kzalloc(sizeof(*eps_acpi_cpu_perf),
58 GFP_KERNEL); 58 GFP_KERNEL);
59 if (!eps_acpi_cpu_perf) 59 if (!eps_acpi_cpu_perf)
60 return -ENOMEM; 60 return -ENOMEM;
@@ -366,7 +366,7 @@ static int eps_cpu_init(struct cpufreq_policy *policy)
366 states = 2; 366 states = 2;
367 367
368 /* Allocate private data and frequency table for current cpu */ 368 /* Allocate private data and frequency table for current cpu */
369 centaur = kzalloc(sizeof(struct eps_cpu_data) 369 centaur = kzalloc(sizeof(*centaur)
370 + (states + 1) * sizeof(struct cpufreq_frequency_table), 370 + (states + 1) * sizeof(struct cpufreq_frequency_table),
371 GFP_KERNEL); 371 GFP_KERNEL);
372 if (!centaur) 372 if (!centaur)
@@ -436,7 +436,6 @@ static struct cpufreq_driver eps_driver = {
436 .exit = eps_cpu_exit, 436 .exit = eps_cpu_exit,
437 .get = eps_get, 437 .get = eps_get,
438 .name = "e_powersaver", 438 .name = "e_powersaver",
439 .owner = THIS_MODULE,
440 .attr = eps_attr, 439 .attr = eps_attr,
441}; 440};
442 441
diff --git a/drivers/cpufreq/elanfreq.c b/drivers/cpufreq/elanfreq.c
index 658d860344b0..823a400d98fd 100644
--- a/drivers/cpufreq/elanfreq.c
+++ b/drivers/cpufreq/elanfreq.c
@@ -274,7 +274,6 @@ static struct cpufreq_driver elanfreq_driver = {
274 .init = elanfreq_cpu_init, 274 .init = elanfreq_cpu_init,
275 .exit = elanfreq_cpu_exit, 275 .exit = elanfreq_cpu_exit,
276 .name = "elanfreq", 276 .name = "elanfreq",
277 .owner = THIS_MODULE,
278 .attr = elanfreq_attr, 277 .attr = elanfreq_attr,
279}; 278};
280 279
diff --git a/drivers/cpufreq/exynos-cpufreq.c b/drivers/cpufreq/exynos-cpufreq.c
index 0d32f02ef4d6..366475161c76 100644
--- a/drivers/cpufreq/exynos-cpufreq.c
+++ b/drivers/cpufreq/exynos-cpufreq.c
@@ -289,7 +289,7 @@ static int __init exynos_cpufreq_init(void)
289{ 289{
290 int ret = -EINVAL; 290 int ret = -EINVAL;
291 291
292 exynos_info = kzalloc(sizeof(struct exynos_dvfs_info), GFP_KERNEL); 292 exynos_info = kzalloc(sizeof(*exynos_info), GFP_KERNEL);
293 if (!exynos_info) 293 if (!exynos_info)
294 return -ENOMEM; 294 return -ENOMEM;
295 295
diff --git a/drivers/cpufreq/freq_table.c b/drivers/cpufreq/freq_table.c
index f0d87412cc91..f111454a7aea 100644
--- a/drivers/cpufreq/freq_table.c
+++ b/drivers/cpufreq/freq_table.c
@@ -11,10 +11,8 @@
11 11
12#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 12#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13 13
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/init.h>
17#include <linux/cpufreq.h> 14#include <linux/cpufreq.h>
15#include <linux/module.h>
18 16
19/********************************************************************* 17/*********************************************************************
20 * FREQUENCY TABLE HELPERS * 18 * FREQUENCY TABLE HELPERS *
diff --git a/drivers/cpufreq/gx-suspmod.c b/drivers/cpufreq/gx-suspmod.c
index 3dfc99b9ca86..ef5fee7dc0b3 100644
--- a/drivers/cpufreq/gx-suspmod.c
+++ b/drivers/cpufreq/gx-suspmod.c
@@ -446,7 +446,6 @@ static struct cpufreq_driver gx_suspmod_driver = {
446 .target = cpufreq_gx_target, 446 .target = cpufreq_gx_target,
447 .init = cpufreq_gx_cpu_init, 447 .init = cpufreq_gx_cpu_init,
448 .name = "gx-suspmod", 448 .name = "gx-suspmod",
449 .owner = THIS_MODULE,
450}; 449};
451 450
452static int __init cpufreq_gx_init(void) 451static int __init cpufreq_gx_init(void)
@@ -466,7 +465,7 @@ static int __init cpufreq_gx_init(void)
466 465
467 pr_debug("geode suspend modulation available.\n"); 466 pr_debug("geode suspend modulation available.\n");
468 467
469 params = kzalloc(sizeof(struct gxfreq_params), GFP_KERNEL); 468 params = kzalloc(sizeof(*params), GFP_KERNEL);
470 if (params == NULL) 469 if (params == NULL)
471 return -ENOMEM; 470 return -ENOMEM;
472 471
diff --git a/drivers/cpufreq/ia64-acpi-cpufreq.c b/drivers/cpufreq/ia64-acpi-cpufreq.c
index 573c14ea802d..3e14f0317175 100644
--- a/drivers/cpufreq/ia64-acpi-cpufreq.c
+++ b/drivers/cpufreq/ia64-acpi-cpufreq.c
@@ -274,7 +274,7 @@ acpi_cpufreq_cpu_init (
274 274
275 pr_debug("acpi_cpufreq_cpu_init\n"); 275 pr_debug("acpi_cpufreq_cpu_init\n");
276 276
277 data = kzalloc(sizeof(struct cpufreq_acpi_io), GFP_KERNEL); 277 data = kzalloc(sizeof(*data), GFP_KERNEL);
278 if (!data) 278 if (!data)
279 return (-ENOMEM); 279 return (-ENOMEM);
280 280
@@ -304,7 +304,7 @@ acpi_cpufreq_cpu_init (
304 } 304 }
305 305
306 /* alloc freq_table */ 306 /* alloc freq_table */
307 data->freq_table = kmalloc(sizeof(struct cpufreq_frequency_table) * 307 data->freq_table = kmalloc(sizeof(*data->freq_table) *
308 (data->acpi_data.state_count + 1), 308 (data->acpi_data.state_count + 1),
309 GFP_KERNEL); 309 GFP_KERNEL);
310 if (!data->freq_table) { 310 if (!data->freq_table) {
@@ -409,7 +409,6 @@ static struct cpufreq_driver acpi_cpufreq_driver = {
409 .init = acpi_cpufreq_cpu_init, 409 .init = acpi_cpufreq_cpu_init,
410 .exit = acpi_cpufreq_cpu_exit, 410 .exit = acpi_cpufreq_cpu_exit,
411 .name = "acpi-cpufreq", 411 .name = "acpi-cpufreq",
412 .owner = THIS_MODULE,
413 .attr = acpi_cpufreq_attr, 412 .attr = acpi_cpufreq_attr,
414}; 413};
415 414
diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 7cde885011ed..6efd96c196b2 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -665,7 +665,6 @@ static struct cpufreq_driver intel_pstate_driver = {
665 .init = intel_pstate_cpu_init, 665 .init = intel_pstate_cpu_init,
666 .exit = intel_pstate_cpu_exit, 666 .exit = intel_pstate_cpu_exit,
667 .name = "intel_pstate", 667 .name = "intel_pstate",
668 .owner = THIS_MODULE,
669}; 668};
670 669
671static int __initdata no_load; 670static int __initdata no_load;
diff --git a/drivers/cpufreq/kirkwood-cpufreq.c b/drivers/cpufreq/kirkwood-cpufreq.c
index c233ea617366..45e4d7fc261d 100644
--- a/drivers/cpufreq/kirkwood-cpufreq.c
+++ b/drivers/cpufreq/kirkwood-cpufreq.c
@@ -158,7 +158,6 @@ static struct cpufreq_driver kirkwood_cpufreq_driver = {
158 .init = kirkwood_cpufreq_cpu_init, 158 .init = kirkwood_cpufreq_cpu_init,
159 .exit = kirkwood_cpufreq_cpu_exit, 159 .exit = kirkwood_cpufreq_cpu_exit,
160 .name = "kirkwood-cpufreq", 160 .name = "kirkwood-cpufreq",
161 .owner = THIS_MODULE,
162 .attr = kirkwood_cpufreq_attr, 161 .attr = kirkwood_cpufreq_attr,
163}; 162};
164 163
diff --git a/drivers/cpufreq/longhaul.c b/drivers/cpufreq/longhaul.c
index 8c49261df57d..4ada1cccb052 100644
--- a/drivers/cpufreq/longhaul.c
+++ b/drivers/cpufreq/longhaul.c
@@ -948,7 +948,6 @@ static struct cpufreq_driver longhaul_driver = {
948 .init = longhaul_cpu_init, 948 .init = longhaul_cpu_init,
949 .exit = longhaul_cpu_exit, 949 .exit = longhaul_cpu_exit,
950 .name = "longhaul", 950 .name = "longhaul",
951 .owner = THIS_MODULE,
952 .attr = longhaul_attr, 951 .attr = longhaul_attr,
953}; 952};
954 953
diff --git a/drivers/cpufreq/longrun.c b/drivers/cpufreq/longrun.c
index 0fe041d1f77f..5aa031612d53 100644
--- a/drivers/cpufreq/longrun.c
+++ b/drivers/cpufreq/longrun.c
@@ -286,7 +286,6 @@ static struct cpufreq_driver longrun_driver = {
286 .get = longrun_get, 286 .get = longrun_get,
287 .init = longrun_cpu_init, 287 .init = longrun_cpu_init,
288 .name = "longrun", 288 .name = "longrun",
289 .owner = THIS_MODULE,
290}; 289};
291 290
292static const struct x86_cpu_id longrun_ids[] = { 291static const struct x86_cpu_id longrun_ids[] = {
diff --git a/drivers/cpufreq/loongson2_cpufreq.c b/drivers/cpufreq/loongson2_cpufreq.c
index 9536852c504a..7bc3c44d34e2 100644
--- a/drivers/cpufreq/loongson2_cpufreq.c
+++ b/drivers/cpufreq/loongson2_cpufreq.c
@@ -158,7 +158,6 @@ static struct freq_attr *loongson2_table_attr[] = {
158}; 158};
159 159
160static struct cpufreq_driver loongson2_cpufreq_driver = { 160static struct cpufreq_driver loongson2_cpufreq_driver = {
161 .owner = THIS_MODULE,
162 .name = "loongson2", 161 .name = "loongson2",
163 .init = loongson2_cpufreq_cpu_init, 162 .init = loongson2_cpufreq_cpu_init,
164 .verify = loongson2_cpufreq_verify, 163 .verify = loongson2_cpufreq_verify,
diff --git a/drivers/cpufreq/maple-cpufreq.c b/drivers/cpufreq/maple-cpufreq.c
index cdd62915efaf..41c601f4631e 100644
--- a/drivers/cpufreq/maple-cpufreq.c
+++ b/drivers/cpufreq/maple-cpufreq.c
@@ -190,7 +190,6 @@ static int maple_cpufreq_cpu_init(struct cpufreq_policy *policy)
190 190
191static struct cpufreq_driver maple_cpufreq_driver = { 191static struct cpufreq_driver maple_cpufreq_driver = {
192 .name = "maple", 192 .name = "maple",
193 .owner = THIS_MODULE,
194 .flags = CPUFREQ_CONST_LOOPS, 193 .flags = CPUFREQ_CONST_LOOPS,
195 .init = maple_cpufreq_cpu_init, 194 .init = maple_cpufreq_cpu_init,
196 .verify = maple_cpufreq_verify, 195 .verify = maple_cpufreq_verify,
diff --git a/drivers/cpufreq/mperf.c b/drivers/cpufreq/mperf.c
deleted file mode 100644
index 911e193018ae..000000000000
--- a/drivers/cpufreq/mperf.c
+++ /dev/null
@@ -1,51 +0,0 @@
1#include <linux/kernel.h>
2#include <linux/smp.h>
3#include <linux/module.h>
4#include <linux/init.h>
5#include <linux/cpufreq.h>
6#include <linux/slab.h>
7
8#include "mperf.h"
9
10static DEFINE_PER_CPU(struct aperfmperf, acfreq_old_perf);
11
12/* Called via smp_call_function_single(), on the target CPU */
13static void read_measured_perf_ctrs(void *_cur)
14{
15 struct aperfmperf *am = _cur;
16
17 get_aperfmperf(am);
18}
19
20/*
21 * Return the measured active (C0) frequency on this CPU since last call
22 * to this function.
23 * Input: cpu number
24 * Return: Average CPU frequency in terms of max frequency (zero on error)
25 *
26 * We use IA32_MPERF and IA32_APERF MSRs to get the measured performance
27 * over a period of time, while CPU is in C0 state.
28 * IA32_MPERF counts at the rate of max advertised frequency
29 * IA32_APERF counts at the rate of actual CPU frequency
30 * Only IA32_APERF/IA32_MPERF ratio is architecturally defined and
31 * no meaning should be associated with absolute values of these MSRs.
32 */
33unsigned int cpufreq_get_measured_perf(struct cpufreq_policy *policy,
34 unsigned int cpu)
35{
36 struct aperfmperf perf;
37 unsigned long ratio;
38 unsigned int retval;
39
40 if (smp_call_function_single(cpu, read_measured_perf_ctrs, &perf, 1))
41 return 0;
42
43 ratio = calc_aperfmperf_ratio(&per_cpu(acfreq_old_perf, cpu), &perf);
44 per_cpu(acfreq_old_perf, cpu) = perf;
45
46 retval = (policy->cpuinfo.max_freq * ratio) >> APERFMPERF_SHIFT;
47
48 return retval;
49}
50EXPORT_SYMBOL_GPL(cpufreq_get_measured_perf);
51MODULE_LICENSE("GPL");
diff --git a/drivers/cpufreq/mperf.h b/drivers/cpufreq/mperf.h
deleted file mode 100644
index 5dbf2950dc22..000000000000
--- a/drivers/cpufreq/mperf.h
+++ /dev/null
@@ -1,9 +0,0 @@
1/*
2 * (c) 2010 Advanced Micro Devices, Inc.
3 * Your use of this code is subject to the terms and conditions of the
4 * GNU general public license version 2. See "COPYING" or
5 * http://www.gnu.org/licenses/gpl.html
6 */
7
8unsigned int cpufreq_get_measured_perf(struct cpufreq_policy *policy,
9 unsigned int cpu);
diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
index 9ee78170ff86..2f0a2a65c37f 100644
--- a/drivers/cpufreq/p4-clockmod.c
+++ b/drivers/cpufreq/p4-clockmod.c
@@ -279,7 +279,6 @@ static struct cpufreq_driver p4clockmod_driver = {
279 .exit = cpufreq_p4_cpu_exit, 279 .exit = cpufreq_p4_cpu_exit,
280 .get = cpufreq_p4_get, 280 .get = cpufreq_p4_get,
281 .name = "p4-clockmod", 281 .name = "p4-clockmod",
282 .owner = THIS_MODULE,
283 .attr = p4clockmod_attr, 282 .attr = p4clockmod_attr,
284}; 283};
285 284
diff --git a/drivers/cpufreq/pasemi-cpufreq.c b/drivers/cpufreq/pasemi-cpufreq.c
index b704da404067..534e43a60d1f 100644
--- a/drivers/cpufreq/pasemi-cpufreq.c
+++ b/drivers/cpufreq/pasemi-cpufreq.c
@@ -297,7 +297,6 @@ static int pas_cpufreq_target(struct cpufreq_policy *policy,
297 297
298static struct cpufreq_driver pas_cpufreq_driver = { 298static struct cpufreq_driver pas_cpufreq_driver = {
299 .name = "pas-cpufreq", 299 .name = "pas-cpufreq",
300 .owner = THIS_MODULE,
301 .flags = CPUFREQ_CONST_LOOPS, 300 .flags = CPUFREQ_CONST_LOOPS,
302 .init = pas_cpufreq_cpu_init, 301 .init = pas_cpufreq_cpu_init,
303 .exit = pas_cpufreq_cpu_exit, 302 .exit = pas_cpufreq_cpu_exit,
diff --git a/drivers/cpufreq/pcc-cpufreq.c b/drivers/cpufreq/pcc-cpufreq.c
index 1581fcc4cf4a..d81c4e5ea0ad 100644
--- a/drivers/cpufreq/pcc-cpufreq.c
+++ b/drivers/cpufreq/pcc-cpufreq.c
@@ -587,7 +587,6 @@ static struct cpufreq_driver pcc_cpufreq_driver = {
587 .init = pcc_cpufreq_cpu_init, 587 .init = pcc_cpufreq_cpu_init,
588 .exit = pcc_cpufreq_cpu_exit, 588 .exit = pcc_cpufreq_cpu_exit,
589 .name = "pcc-cpufreq", 589 .name = "pcc-cpufreq",
590 .owner = THIS_MODULE,
591}; 590};
592 591
593static int __init pcc_cpufreq_init(void) 592static int __init pcc_cpufreq_init(void)
diff --git a/drivers/cpufreq/pmac32-cpufreq.c b/drivers/cpufreq/pmac32-cpufreq.c
index 3104fad82480..38cdc63c38da 100644
--- a/drivers/cpufreq/pmac32-cpufreq.c
+++ b/drivers/cpufreq/pmac32-cpufreq.c
@@ -477,7 +477,6 @@ static struct cpufreq_driver pmac_cpufreq_driver = {
477 .flags = CPUFREQ_PM_NO_WARN, 477 .flags = CPUFREQ_PM_NO_WARN,
478 .attr = pmac_cpu_freqs_attr, 478 .attr = pmac_cpu_freqs_attr,
479 .name = "powermac", 479 .name = "powermac",
480 .owner = THIS_MODULE,
481}; 480};
482 481
483 482
diff --git a/drivers/cpufreq/pmac64-cpufreq.c b/drivers/cpufreq/pmac64-cpufreq.c
index 7ba423431cfe..b6850d97f0d5 100644
--- a/drivers/cpufreq/pmac64-cpufreq.c
+++ b/drivers/cpufreq/pmac64-cpufreq.c
@@ -371,7 +371,6 @@ static int g5_cpufreq_cpu_init(struct cpufreq_policy *policy)
371 371
372static struct cpufreq_driver g5_cpufreq_driver = { 372static struct cpufreq_driver g5_cpufreq_driver = {
373 .name = "powermac", 373 .name = "powermac",
374 .owner = THIS_MODULE,
375 .flags = CPUFREQ_CONST_LOOPS, 374 .flags = CPUFREQ_CONST_LOOPS,
376 .init = g5_cpufreq_cpu_init, 375 .init = g5_cpufreq_cpu_init,
377 .verify = g5_cpufreq_verify, 376 .verify = g5_cpufreq_verify,
@@ -447,9 +446,8 @@ static int __init g5_neo2_cpufreq_init(struct device_node *cpus)
447 if (!shdr) 446 if (!shdr)
448 goto bail_noprops; 447 goto bail_noprops;
449 g5_fvt_table = (struct smu_sdbp_fvt *)&shdr[1]; 448 g5_fvt_table = (struct smu_sdbp_fvt *)&shdr[1];
450 ssize = (shdr->len * sizeof(u32)) - 449 ssize = (shdr->len * sizeof(u32)) - sizeof(*shdr);
451 sizeof(struct smu_sdbp_header); 450 g5_fvt_count = ssize / sizeof(*g5_fvt_table);
452 g5_fvt_count = ssize / sizeof(struct smu_sdbp_fvt);
453 g5_fvt_cur = 0; 451 g5_fvt_cur = 0;
454 452
455 /* Sanity checking */ 453 /* Sanity checking */
diff --git a/drivers/cpufreq/powernow-k6.c b/drivers/cpufreq/powernow-k6.c
index ea8e10382ec5..85f1c8c25ddc 100644
--- a/drivers/cpufreq/powernow-k6.c
+++ b/drivers/cpufreq/powernow-k6.c
@@ -207,7 +207,6 @@ static struct cpufreq_driver powernow_k6_driver = {
207 .exit = powernow_k6_cpu_exit, 207 .exit = powernow_k6_cpu_exit,
208 .get = powernow_k6_get, 208 .get = powernow_k6_get,
209 .name = "powernow-k6", 209 .name = "powernow-k6",
210 .owner = THIS_MODULE,
211 .attr = powernow_k6_attr, 210 .attr = powernow_k6_attr,
212}; 211};
213 212
diff --git a/drivers/cpufreq/powernow-k7.c b/drivers/cpufreq/powernow-k7.c
index 955870877935..14ce480be8ab 100644
--- a/drivers/cpufreq/powernow-k7.c
+++ b/drivers/cpufreq/powernow-k7.c
@@ -177,7 +177,7 @@ static int get_ranges(unsigned char *pst)
177 unsigned int speed; 177 unsigned int speed;
178 u8 fid, vid; 178 u8 fid, vid;
179 179
180 powernow_table = kzalloc((sizeof(struct cpufreq_frequency_table) * 180 powernow_table = kzalloc((sizeof(*powernow_table) *
181 (number_scales + 1)), GFP_KERNEL); 181 (number_scales + 1)), GFP_KERNEL);
182 if (!powernow_table) 182 if (!powernow_table)
183 return -ENOMEM; 183 return -ENOMEM;
@@ -309,8 +309,7 @@ static int powernow_acpi_init(void)
309 goto err0; 309 goto err0;
310 } 310 }
311 311
312 acpi_processor_perf = kzalloc(sizeof(struct acpi_processor_performance), 312 acpi_processor_perf = kzalloc(sizeof(*acpi_processor_perf), GFP_KERNEL);
313 GFP_KERNEL);
314 if (!acpi_processor_perf) { 313 if (!acpi_processor_perf) {
315 retval = -ENOMEM; 314 retval = -ENOMEM;
316 goto err0; 315 goto err0;
@@ -346,7 +345,7 @@ static int powernow_acpi_init(void)
346 goto err2; 345 goto err2;
347 } 346 }
348 347
349 powernow_table = kzalloc((sizeof(struct cpufreq_frequency_table) * 348 powernow_table = kzalloc((sizeof(*powernow_table) *
350 (number_scales + 1)), GFP_KERNEL); 349 (number_scales + 1)), GFP_KERNEL);
351 if (!powernow_table) { 350 if (!powernow_table) {
352 retval = -ENOMEM; 351 retval = -ENOMEM;
@@ -497,7 +496,7 @@ static int powernow_decode_bios(int maxfid, int startvid)
497 "relevant to this CPU).\n", 496 "relevant to this CPU).\n",
498 psb->numpst); 497 psb->numpst);
499 498
500 p += sizeof(struct psb_s); 499 p += sizeof(*psb);
501 500
502 pst = (struct pst_s *) p; 501 pst = (struct pst_s *) p;
503 502
@@ -510,12 +509,12 @@ static int powernow_decode_bios(int maxfid, int startvid)
510 (maxfid == pst->maxfid) && 509 (maxfid == pst->maxfid) &&
511 (startvid == pst->startvid)) { 510 (startvid == pst->startvid)) {
512 print_pst_entry(pst, j); 511 print_pst_entry(pst, j);
513 p = (char *)pst + sizeof(struct pst_s); 512 p = (char *)pst + sizeof(*pst);
514 ret = get_ranges(p); 513 ret = get_ranges(p);
515 return ret; 514 return ret;
516 } else { 515 } else {
517 unsigned int k; 516 unsigned int k;
518 p = (char *)pst + sizeof(struct pst_s); 517 p = (char *)pst + sizeof(*pst);
519 for (k = 0; k < number_scales; k++) 518 for (k = 0; k < number_scales; k++)
520 p += 2; 519 p += 2;
521 } 520 }
@@ -717,7 +716,6 @@ static struct cpufreq_driver powernow_driver = {
717 .init = powernow_cpu_init, 716 .init = powernow_cpu_init,
718 .exit = powernow_cpu_exit, 717 .exit = powernow_cpu_exit,
719 .name = "powernow-k7", 718 .name = "powernow-k7",
720 .owner = THIS_MODULE,
721 .attr = powernow_table_attr, 719 .attr = powernow_table_attr,
722}; 720};
723 721
diff --git a/drivers/cpufreq/powernow-k8.c b/drivers/cpufreq/powernow-k8.c
index c39d189217cb..2344a9ed17f3 100644
--- a/drivers/cpufreq/powernow-k8.c
+++ b/drivers/cpufreq/powernow-k8.c
@@ -623,7 +623,7 @@ static int fill_powernow_table(struct powernow_k8_data *data,
623 if (check_pst_table(data, pst, maxvid)) 623 if (check_pst_table(data, pst, maxvid))
624 return -EINVAL; 624 return -EINVAL;
625 625
626 powernow_table = kmalloc((sizeof(struct cpufreq_frequency_table) 626 powernow_table = kmalloc((sizeof(*powernow_table)
627 * (data->numps + 1)), GFP_KERNEL); 627 * (data->numps + 1)), GFP_KERNEL);
628 if (!powernow_table) { 628 if (!powernow_table) {
629 printk(KERN_ERR PFX "powernow_table memory alloc failure\n"); 629 printk(KERN_ERR PFX "powernow_table memory alloc failure\n");
@@ -793,7 +793,7 @@ static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data)
793 } 793 }
794 794
795 /* fill in data->powernow_table */ 795 /* fill in data->powernow_table */
796 powernow_table = kmalloc((sizeof(struct cpufreq_frequency_table) 796 powernow_table = kmalloc((sizeof(*powernow_table)
797 * (data->acpi_data.state_count + 1)), GFP_KERNEL); 797 * (data->acpi_data.state_count + 1)), GFP_KERNEL);
798 if (!powernow_table) { 798 if (!powernow_table) {
799 pr_debug("powernow_table memory alloc failure\n"); 799 pr_debug("powernow_table memory alloc failure\n");
@@ -1106,7 +1106,7 @@ static int powernowk8_cpu_init(struct cpufreq_policy *pol)
1106 if (rc) 1106 if (rc)
1107 return -ENODEV; 1107 return -ENODEV;
1108 1108
1109 data = kzalloc(sizeof(struct powernow_k8_data), GFP_KERNEL); 1109 data = kzalloc(sizeof(*data), GFP_KERNEL);
1110 if (!data) { 1110 if (!data) {
1111 printk(KERN_ERR PFX "unable to alloc powernow_k8_data"); 1111 printk(KERN_ERR PFX "unable to alloc powernow_k8_data");
1112 return -ENOMEM; 1112 return -ENOMEM;
@@ -1240,7 +1240,6 @@ static struct cpufreq_driver cpufreq_amd64_driver = {
1240 .exit = powernowk8_cpu_exit, 1240 .exit = powernowk8_cpu_exit,
1241 .get = powernowk8_get, 1241 .get = powernowk8_get,
1242 .name = "powernow-k8", 1242 .name = "powernow-k8",
1243 .owner = THIS_MODULE,
1244 .attr = powernow_k8_attr, 1243 .attr = powernow_k8_attr,
1245}; 1244};
1246 1245
diff --git a/drivers/cpufreq/ppc-corenet-cpufreq.c b/drivers/cpufreq/ppc-corenet-cpufreq.c
index 3cae4529f959..60e81d524ea8 100644
--- a/drivers/cpufreq/ppc-corenet-cpufreq.c
+++ b/drivers/cpufreq/ppc-corenet-cpufreq.c
@@ -300,7 +300,6 @@ static struct freq_attr *corenet_cpufreq_attr[] = {
300 300
301static struct cpufreq_driver ppc_corenet_cpufreq_driver = { 301static struct cpufreq_driver ppc_corenet_cpufreq_driver = {
302 .name = "ppc_cpufreq", 302 .name = "ppc_cpufreq",
303 .owner = THIS_MODULE,
304 .flags = CPUFREQ_CONST_LOOPS, 303 .flags = CPUFREQ_CONST_LOOPS,
305 .init = corenet_cpufreq_cpu_init, 304 .init = corenet_cpufreq_cpu_init,
306 .exit = __exit_p(corenet_cpufreq_cpu_exit), 305 .exit = __exit_p(corenet_cpufreq_cpu_exit),
diff --git a/drivers/cpufreq/ppc_cbe_cpufreq.c b/drivers/cpufreq/ppc_cbe_cpufreq.c
index 5936f8d6f2cc..2e448f0bbdc5 100644
--- a/drivers/cpufreq/ppc_cbe_cpufreq.c
+++ b/drivers/cpufreq/ppc_cbe_cpufreq.c
@@ -181,7 +181,6 @@ static struct cpufreq_driver cbe_cpufreq_driver = {
181 .init = cbe_cpufreq_cpu_init, 181 .init = cbe_cpufreq_cpu_init,
182 .exit = cbe_cpufreq_cpu_exit, 182 .exit = cbe_cpufreq_cpu_exit,
183 .name = "cbe-cpufreq", 183 .name = "cbe-cpufreq",
184 .owner = THIS_MODULE,
185 .flags = CPUFREQ_CONST_LOOPS, 184 .flags = CPUFREQ_CONST_LOOPS,
186}; 185};
187 186
diff --git a/drivers/cpufreq/s3c2416-cpufreq.c b/drivers/cpufreq/s3c2416-cpufreq.c
index ce5b9fca9c18..22dcb81ef9d0 100644
--- a/drivers/cpufreq/s3c2416-cpufreq.c
+++ b/drivers/cpufreq/s3c2416-cpufreq.c
@@ -524,7 +524,6 @@ static struct freq_attr *s3c2416_cpufreq_attr[] = {
524}; 524};
525 525
526static struct cpufreq_driver s3c2416_cpufreq_driver = { 526static struct cpufreq_driver s3c2416_cpufreq_driver = {
527 .owner = THIS_MODULE,
528 .flags = 0, 527 .flags = 0,
529 .verify = s3c2416_cpufreq_verify_speed, 528 .verify = s3c2416_cpufreq_verify_speed,
530 .target = s3c2416_cpufreq_set_target, 529 .target = s3c2416_cpufreq_set_target,
diff --git a/drivers/cpufreq/s3c24xx-cpufreq.c b/drivers/cpufreq/s3c24xx-cpufreq.c
index 87781eb20d6d..f169ee52e6eb 100644
--- a/drivers/cpufreq/s3c24xx-cpufreq.c
+++ b/drivers/cpufreq/s3c24xx-cpufreq.c
@@ -522,7 +522,7 @@ int __init s3c_cpufreq_setboard(struct s3c_cpufreq_board *board)
522 /* Copy the board information so that each board can make this 522 /* Copy the board information so that each board can make this
523 * initdata. */ 523 * initdata. */
524 524
525 ours = kzalloc(sizeof(struct s3c_cpufreq_board), GFP_KERNEL); 525 ours = kzalloc(sizeof(*ours), GFP_KERNEL);
526 if (ours == NULL) { 526 if (ours == NULL) {
527 printk(KERN_ERR "%s: no memory\n", __func__); 527 printk(KERN_ERR "%s: no memory\n", __func__);
528 return -ENOMEM; 528 return -ENOMEM;
@@ -615,7 +615,7 @@ static int s3c_cpufreq_build_freq(void)
615 size = cpu_cur.info->calc_freqtable(&cpu_cur, NULL, 0); 615 size = cpu_cur.info->calc_freqtable(&cpu_cur, NULL, 0);
616 size++; 616 size++;
617 617
618 ftab = kmalloc(sizeof(struct cpufreq_frequency_table) * size, GFP_KERNEL); 618 ftab = kmalloc(sizeof(*ftab) * size, GFP_KERNEL);
619 if (!ftab) { 619 if (!ftab) {
620 printk(KERN_ERR "%s: no memory for tables\n", __func__); 620 printk(KERN_ERR "%s: no memory for tables\n", __func__);
621 return -ENOMEM; 621 return -ENOMEM;
@@ -691,7 +691,7 @@ int __init s3c_plltab_register(struct cpufreq_frequency_table *plls,
691 struct cpufreq_frequency_table *vals; 691 struct cpufreq_frequency_table *vals;
692 unsigned int size; 692 unsigned int size;
693 693
694 size = sizeof(struct cpufreq_frequency_table) * (plls_no + 1); 694 size = sizeof(*vals) * (plls_no + 1);
695 695
696 vals = kmalloc(size, GFP_KERNEL); 696 vals = kmalloc(size, GFP_KERNEL);
697 if (vals) { 697 if (vals) {
diff --git a/drivers/cpufreq/s3c64xx-cpufreq.c b/drivers/cpufreq/s3c64xx-cpufreq.c
index 13bb4bae64ee..8a72b0c555f8 100644
--- a/drivers/cpufreq/s3c64xx-cpufreq.c
+++ b/drivers/cpufreq/s3c64xx-cpufreq.c
@@ -263,7 +263,6 @@ static int s3c64xx_cpufreq_driver_init(struct cpufreq_policy *policy)
263} 263}
264 264
265static struct cpufreq_driver s3c64xx_cpufreq_driver = { 265static struct cpufreq_driver s3c64xx_cpufreq_driver = {
266 .owner = THIS_MODULE,
267 .flags = 0, 266 .flags = 0,
268 .verify = s3c64xx_cpufreq_verify_speed, 267 .verify = s3c64xx_cpufreq_verify_speed,
269 .target = s3c64xx_cpufreq_set_target, 268 .target = s3c64xx_cpufreq_set_target,
diff --git a/drivers/cpufreq/sc520_freq.c b/drivers/cpufreq/sc520_freq.c
index 77a210975fc4..d6f6c6f4efa7 100644
--- a/drivers/cpufreq/sc520_freq.c
+++ b/drivers/cpufreq/sc520_freq.c
@@ -147,7 +147,6 @@ static struct cpufreq_driver sc520_freq_driver = {
147 .init = sc520_freq_cpu_init, 147 .init = sc520_freq_cpu_init,
148 .exit = sc520_freq_cpu_exit, 148 .exit = sc520_freq_cpu_exit,
149 .name = "sc520_freq", 149 .name = "sc520_freq",
150 .owner = THIS_MODULE,
151 .attr = sc520_freq_attr, 150 .attr = sc520_freq_attr,
152}; 151};
153 152
diff --git a/drivers/cpufreq/sh-cpufreq.c b/drivers/cpufreq/sh-cpufreq.c
index 73adb64651e8..ffc6d24b0cfb 100644
--- a/drivers/cpufreq/sh-cpufreq.c
+++ b/drivers/cpufreq/sh-cpufreq.c
@@ -160,7 +160,6 @@ static struct freq_attr *sh_freq_attr[] = {
160}; 160};
161 161
162static struct cpufreq_driver sh_cpufreq_driver = { 162static struct cpufreq_driver sh_cpufreq_driver = {
163 .owner = THIS_MODULE,
164 .name = "sh", 163 .name = "sh",
165 .get = sh_cpufreq_get, 164 .get = sh_cpufreq_get,
166 .target = sh_cpufreq_target, 165 .target = sh_cpufreq_target,
diff --git a/drivers/cpufreq/sparc-us2e-cpufreq.c b/drivers/cpufreq/sparc-us2e-cpufreq.c
index 93061a408773..cf5bc2ca16fa 100644
--- a/drivers/cpufreq/sparc-us2e-cpufreq.c
+++ b/drivers/cpufreq/sparc-us2e-cpufreq.c
@@ -351,12 +351,11 @@ static int __init us2e_freq_init(void)
351 struct cpufreq_driver *driver; 351 struct cpufreq_driver *driver;
352 352
353 ret = -ENOMEM; 353 ret = -ENOMEM;
354 driver = kzalloc(sizeof(struct cpufreq_driver), GFP_KERNEL); 354 driver = kzalloc(sizeof(*driver), GFP_KERNEL);
355 if (!driver) 355 if (!driver)
356 goto err_out; 356 goto err_out;
357 357
358 us2e_freq_table = kzalloc( 358 us2e_freq_table = kzalloc((NR_CPUS * sizeof(*us2e_freq_table)),
359 (NR_CPUS * sizeof(struct us2e_freq_percpu_info)),
360 GFP_KERNEL); 359 GFP_KERNEL);
361 if (!us2e_freq_table) 360 if (!us2e_freq_table)
362 goto err_out; 361 goto err_out;
@@ -366,7 +365,6 @@ static int __init us2e_freq_init(void)
366 driver->target = us2e_freq_target; 365 driver->target = us2e_freq_target;
367 driver->get = us2e_freq_get; 366 driver->get = us2e_freq_get;
368 driver->exit = us2e_freq_cpu_exit; 367 driver->exit = us2e_freq_cpu_exit;
369 driver->owner = THIS_MODULE,
370 strcpy(driver->name, "UltraSPARC-IIe"); 368 strcpy(driver->name, "UltraSPARC-IIe");
371 369
372 cpufreq_us2e_driver = driver; 370 cpufreq_us2e_driver = driver;
diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
index 880ee293d61e..ac76b489979d 100644
--- a/drivers/cpufreq/sparc-us3-cpufreq.c
+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
@@ -212,12 +212,11 @@ static int __init us3_freq_init(void)
212 struct cpufreq_driver *driver; 212 struct cpufreq_driver *driver;
213 213
214 ret = -ENOMEM; 214 ret = -ENOMEM;
215 driver = kzalloc(sizeof(struct cpufreq_driver), GFP_KERNEL); 215 driver = kzalloc(sizeof(*driver), GFP_KERNEL);
216 if (!driver) 216 if (!driver)
217 goto err_out; 217 goto err_out;
218 218
219 us3_freq_table = kzalloc( 219 us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
220 (NR_CPUS * sizeof(struct us3_freq_percpu_info)),
221 GFP_KERNEL); 220 GFP_KERNEL);
222 if (!us3_freq_table) 221 if (!us3_freq_table)
223 goto err_out; 222 goto err_out;
@@ -227,7 +226,6 @@ static int __init us3_freq_init(void)
227 driver->target = us3_freq_target; 226 driver->target = us3_freq_target;
228 driver->get = us3_freq_get; 227 driver->get = us3_freq_get;
229 driver->exit = us3_freq_cpu_exit; 228 driver->exit = us3_freq_cpu_exit;
230 driver->owner = THIS_MODULE,
231 strcpy(driver->name, "UltraSPARC-III"); 229 strcpy(driver->name, "UltraSPARC-III");
232 230
233 cpufreq_us3_driver = driver; 231 cpufreq_us3_driver = driver;
diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
index 0915e712fbdc..f897d5105842 100644
--- a/drivers/cpufreq/speedstep-centrino.c
+++ b/drivers/cpufreq/speedstep-centrino.c
@@ -575,7 +575,6 @@ static struct cpufreq_driver centrino_driver = {
575 .target = centrino_target, 575 .target = centrino_target,
576 .get = get_cur_freq, 576 .get = get_cur_freq,
577 .attr = centrino_attr, 577 .attr = centrino_attr,
578 .owner = THIS_MODULE,
579}; 578};
580 579
581/* 580/*
diff --git a/drivers/cpufreq/speedstep-ich.c b/drivers/cpufreq/speedstep-ich.c
index e2e5aa971452..5355abb69afc 100644
--- a/drivers/cpufreq/speedstep-ich.c
+++ b/drivers/cpufreq/speedstep-ich.c
@@ -378,7 +378,6 @@ static struct cpufreq_driver speedstep_driver = {
378 .init = speedstep_cpu_init, 378 .init = speedstep_cpu_init,
379 .exit = speedstep_cpu_exit, 379 .exit = speedstep_cpu_exit,
380 .get = speedstep_get, 380 .get = speedstep_get,
381 .owner = THIS_MODULE,
382 .attr = speedstep_attr, 381 .attr = speedstep_attr,
383}; 382};
384 383
diff --git a/drivers/cpufreq/speedstep-smi.c b/drivers/cpufreq/speedstep-smi.c
index f5a6b70ee6c0..abfba4f731eb 100644
--- a/drivers/cpufreq/speedstep-smi.c
+++ b/drivers/cpufreq/speedstep-smi.c
@@ -375,7 +375,6 @@ static struct cpufreq_driver speedstep_driver = {
375 .exit = speedstep_cpu_exit, 375 .exit = speedstep_cpu_exit,
376 .get = speedstep_get, 376 .get = speedstep_get,
377 .resume = speedstep_resume, 377 .resume = speedstep_resume,
378 .owner = THIS_MODULE,
379 .attr = speedstep_attr, 378 .attr = speedstep_attr,
380}; 379};
381 380