WorkStruct: make allyesconfig
[deliverable/linux.git] / drivers / cpufreq / cpufreq_conservative.c
index 7498f2506adeaa2cffe379509786a24fd8049714..5ef5ede5b8848e96c3d7d4ba00d9e7e8a11bc60f 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/types.h>
 #include <linux/fs.h>
 #include <linux/sysfs.h>
+#include <linux/cpu.h>
 #include <linux/sched.h>
 #include <linux/kmod.h>
 #include <linux/workqueue.h>
@@ -58,20 +59,30 @@ static unsigned int                                 def_sampling_rate;
 #define MAX_SAMPLING_DOWN_FACTOR               (10)
 #define TRANSITION_LATENCY_LIMIT               (10 * 1000)
 
-static void do_dbs_timer(void *data);
+static void do_dbs_timer(struct work_struct *work);
 
 struct cpu_dbs_info_s {
        struct cpufreq_policy   *cur_policy;
        unsigned int            prev_cpu_idle_up;
        unsigned int            prev_cpu_idle_down;
        unsigned int            enable;
+       unsigned int            down_skip;
+       unsigned int            requested_freq;
 };
 static DEFINE_PER_CPU(struct cpu_dbs_info_s, cpu_dbs_info);
 
 static unsigned int dbs_enable;        /* number of CPUs using this policy */
 
+/*
+ * DEADLOCK ALERT! There is a ordering requirement between cpu_hotplug
+ * lock and dbs_mutex. cpu_hotplug lock should always be held before
+ * dbs_mutex. If any function that can potentially take cpu_hotplug lock
+ * (like __cpufreq_driver_target()) is being called with dbs_mutex taken, then
+ * cpu_hotplug lock should be taken before that. Note that cpu_hotplug lock
+ * is recursive for the same process. -Venki
+ */
 static DEFINE_MUTEX    (dbs_mutex);
-static DECLARE_WORK    (dbs_work, do_dbs_timer, NULL);
+static DECLARE_DELAYED_WORK(dbs_work, do_dbs_timer);
 
 struct dbs_tuners {
        unsigned int            sampling_rate;
@@ -86,6 +97,8 @@ static struct dbs_tuners dbs_tuners_ins = {
        .up_threshold           = DEF_FREQUENCY_UP_THRESHOLD,
        .down_threshold         = DEF_FREQUENCY_DOWN_THRESHOLD,
        .sampling_down_factor   = DEF_SAMPLING_DOWN_FACTOR,
+       .ignore_nice            = 0,
+       .freq_step              = 5,
 };
 
 static inline unsigned int get_cpu_idle_time(unsigned int cpu)
@@ -172,8 +185,7 @@ static ssize_t store_up_threshold(struct cpufreq_policy *unused,
        ret = sscanf (buf, "%u", &input);
 
        mutex_lock(&dbs_mutex);
-       if (ret != 1 || input > 100 || input < 0 ||
-                       input <= dbs_tuners_ins.down_threshold) {
+       if (ret != 1 || input > 100 || input <= dbs_tuners_ins.down_threshold) {
                mutex_unlock(&dbs_mutex);
                return -EINVAL;
        }
@@ -192,8 +204,7 @@ static ssize_t store_down_threshold(struct cpufreq_policy *unused,
        ret = sscanf (buf, "%u", &input);
 
        mutex_lock(&dbs_mutex);
-       if (ret != 1 || input > 100 || input < 0 ||
-                       input >= dbs_tuners_ins.up_threshold) {
+       if (ret != 1 || input > 100 || input >= dbs_tuners_ins.up_threshold) {
                mutex_unlock(&dbs_mutex);
                return -EINVAL;
        }
@@ -297,35 +308,12 @@ static void dbs_check_cpu(int cpu)
        unsigned int tmp_idle_ticks, total_idle_ticks;
        unsigned int freq_step;
        unsigned int freq_down_sampling_rate;
-       static unsigned short down_skip[NR_CPUS];
-       static unsigned int requested_freq[NR_CPUS];
-       static unsigned int init_flag = NR_CPUS;
        struct cpu_dbs_info_s *this_dbs_info = &per_cpu(cpu_dbs_info, cpu);
        struct cpufreq_policy *policy;
 
        if (!this_dbs_info->enable)
                return;
 
-       if ( init_flag != 0 ) {
-               for_each_cpu(init_flag) {
-                       down_skip[init_flag] = 0;
-                       /* I doubt a CPU exists with a freq of 0hz :) */
-                       requested_freq[init_flag] = 0;
-               }
-               init_flag = 0;
-       }
-       
-       /*
-        * If its a freshly initialised cpu we setup requested_freq.  This
-        * check could be avoided if we did not care about a first time
-        * stunted increase in CPU speed when there is a load.  I feel we
-        * should be initialising this to something.  The removal of a CPU
-        * is not a problem, after a short time the CPU should settle down
-        * to a 'natural' frequency.
-        */
-       if (requested_freq[cpu] == 0)
-               requested_freq[cpu] = this_dbs_info->cur_policy->cur;
-
        policy = this_dbs_info->cur_policy;
 
        /* 
@@ -360,12 +348,12 @@ static void dbs_check_cpu(int cpu)
                        usecs_to_jiffies(dbs_tuners_ins.sampling_rate);
 
        if (idle_ticks < up_idle_ticks) {
-               down_skip[cpu] = 0;
+               this_dbs_info->down_skip = 0;
                this_dbs_info->prev_cpu_idle_down =
                        this_dbs_info->prev_cpu_idle_up;
 
                /* if we are already at full speed then break out early */
-               if (requested_freq[cpu] == policy->max)
+               if (this_dbs_info->requested_freq == policy->max)
                        return;
                
                freq_step = (dbs_tuners_ins.freq_step * policy->max) / 100;
@@ -374,18 +362,18 @@ static void dbs_check_cpu(int cpu)
                if (unlikely(freq_step == 0))
                        freq_step = 5;
                
-               requested_freq[cpu] += freq_step;
-               if (requested_freq[cpu] > policy->max)
-                       requested_freq[cpu] = policy->max;
+               this_dbs_info->requested_freq += freq_step;
+               if (this_dbs_info->requested_freq > policy->max)
+                       this_dbs_info->requested_freq = policy->max;
 
-               __cpufreq_driver_target(policy, requested_freq[cpu], 
+               __cpufreq_driver_target(policy, this_dbs_info->requested_freq,
                        CPUFREQ_RELATION_H);
                return;
        }
 
        /* Check for frequency decrease */
-       down_skip[cpu]++;
-       if (down_skip[cpu] < dbs_tuners_ins.sampling_down_factor)
+       this_dbs_info->down_skip++;
+       if (this_dbs_info->down_skip < dbs_tuners_ins.sampling_down_factor)
                return;
 
        /* Check for frequency decrease */
@@ -399,7 +387,7 @@ static void dbs_check_cpu(int cpu)
 
        /* Scale idle ticks by 100 and compare with up and down ticks */
        idle_ticks *= 100;
-       down_skip[cpu] = 0;
+       this_dbs_info->down_skip = 0;
 
        freq_down_sampling_rate = dbs_tuners_ins.sampling_rate *
                dbs_tuners_ins.sampling_down_factor;
@@ -412,7 +400,7 @@ static void dbs_check_cpu(int cpu)
                 * or if we 'cannot' reduce the speed as the user might want
                 * freq_step to be zero
                 */
-               if (requested_freq[cpu] == policy->min
+               if (this_dbs_info->requested_freq == policy->min
                                || dbs_tuners_ins.freq_step == 0)
                        return;
 
@@ -422,30 +410,31 @@ static void dbs_check_cpu(int cpu)
                if (unlikely(freq_step == 0))
                        freq_step = 5;
 
-               requested_freq[cpu] -= freq_step;
-               if (requested_freq[cpu] < policy->min)
-                       requested_freq[cpu] = policy->min;
+               this_dbs_info->requested_freq -= freq_step;
+               if (this_dbs_info->requested_freq < policy->min)
+                       this_dbs_info->requested_freq = policy->min;
 
-               __cpufreq_driver_target(policy, requested_freq[cpu],
+               __cpufreq_driver_target(policy, this_dbs_info->requested_freq,
                                CPUFREQ_RELATION_H);
                return;
        }
 }
 
-static void do_dbs_timer(void *data)
+static void do_dbs_timer(struct work_struct *work)
 { 
        int i;
+       lock_cpu_hotplug();
        mutex_lock(&dbs_mutex);
        for_each_online_cpu(i)
                dbs_check_cpu(i);
        schedule_delayed_work(&dbs_work, 
                        usecs_to_jiffies(dbs_tuners_ins.sampling_rate));
        mutex_unlock(&dbs_mutex);
+       unlock_cpu_hotplug();
 } 
 
 static inline void dbs_timer_init(void)
 {
-       INIT_WORK(&dbs_work, do_dbs_timer, NULL);
        schedule_delayed_work(&dbs_work,
                        usecs_to_jiffies(dbs_tuners_ins.sampling_rate));
        return;
@@ -489,6 +478,8 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
                                = j_dbs_info->prev_cpu_idle_up;
                }
                this_dbs_info->enable = 1;
+               this_dbs_info->down_skip = 0;
+               this_dbs_info->requested_freq = policy->cur;
                sysfs_create_group(&policy->kobj, &dbs_attr_group);
                dbs_enable++;
                /*
@@ -509,8 +500,6 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
                                def_sampling_rate = MIN_STAT_SAMPLING_RATE;
 
                        dbs_tuners_ins.sampling_rate = def_sampling_rate;
-                       dbs_tuners_ins.ignore_nice = 0;
-                       dbs_tuners_ins.freq_step = 5;
 
                        dbs_timer_init();
                }
This page took 0.026338 seconds and 5 git commands to generate.