provide disable_cpufreq() function to disable the API.
authorKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Tue, 13 Mar 2012 23:18:39 +0000 (19:18 -0400)
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Tue, 20 Mar 2012 19:31:28 +0000 (15:31 -0400)
useful for disabling cpufreq altogether. The cpu frequency
scaling drivers and cpu frequency governors will fail to register.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: Dave Jones <davej@redhat.com>
drivers/cpufreq/cpufreq.c
include/linux/cpufreq.h

index 8c2df3499da7b11beedf6535e125d1286cf3f17d..a9a1d81cadc47aae3c306df6942e6c95e2d61761 100644 (file)
@@ -126,6 +126,15 @@ static int __init init_cpufreq_transition_notifier_list(void)
 }
 pure_initcall(init_cpufreq_transition_notifier_list);
 
+static int off __read_mostly;
+int cpufreq_disabled(void)
+{
+       return off;
+}
+void disable_cpufreq(void)
+{
+       off = 1;
+}
 static LIST_HEAD(cpufreq_governor_list);
 static DEFINE_MUTEX(cpufreq_governor_mutex);
 
@@ -1442,6 +1451,9 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
 {
        int retval = -EINVAL;
 
+       if (cpufreq_disabled())
+               return -ENODEV;
+
        pr_debug("target for CPU %u: %u kHz, relation %u\n", policy->cpu,
                target_freq, relation);
        if (cpu_online(policy->cpu) && cpufreq_driver->target)
@@ -1550,6 +1562,9 @@ int cpufreq_register_governor(struct cpufreq_governor *governor)
        if (!governor)
                return -EINVAL;
 
+       if (cpufreq_disabled())
+               return -ENODEV;
+
        mutex_lock(&cpufreq_governor_mutex);
 
        err = -EBUSY;
@@ -1573,6 +1588,9 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
        if (!governor)
                return;
 
+       if (cpufreq_disabled())
+               return;
+
 #ifdef CONFIG_HOTPLUG_CPU
        for_each_present_cpu(cpu) {
                if (cpu_online(cpu))
@@ -1815,6 +1833,9 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
        unsigned long flags;
        int ret;
 
+       if (cpufreq_disabled())
+               return -ENODEV;
+
        if (!driver_data || !driver_data->verify || !driver_data->init ||
            ((!driver_data->setpolicy) && (!driver_data->target)))
                return -EINVAL;
@@ -1902,6 +1923,9 @@ static int __init cpufreq_core_init(void)
 {
        int cpu;
 
+       if (cpufreq_disabled())
+               return -ENODEV;
+
        for_each_possible_cpu(cpu) {
                per_cpu(cpufreq_policy_cpu, cpu) = -1;
                init_rwsem(&per_cpu(cpu_policy_rwsem, cpu));
index 6216115c7789aa6198aea1c5d904e6dedec2840a..8ff442753c758cf6e0e82d2c86aa0941e2952813 100644 (file)
@@ -35,6 +35,7 @@
 #ifdef CONFIG_CPU_FREQ
 int cpufreq_register_notifier(struct notifier_block *nb, unsigned int list);
 int cpufreq_unregister_notifier(struct notifier_block *nb, unsigned int list);
+extern void disable_cpufreq(void);
 #else          /* CONFIG_CPU_FREQ */
 static inline int cpufreq_register_notifier(struct notifier_block *nb,
                                                unsigned int list)
@@ -46,6 +47,7 @@ static inline int cpufreq_unregister_notifier(struct notifier_block *nb,
 {
        return 0;
 }
+static inline void disable_cpufreq(void) { }
 #endif         /* CONFIG_CPU_FREQ */
 
 /* if (cpufreq_driver->target) exists, the ->governor decides what frequency