cpufreq: governor: Make governor private data per-policy
[deliverable/linux.git] / drivers / cpufreq / cpufreq_conservative.c
index 6243502ce24db8c3d31ee144db1af43ea6d92579..ffffda2dcbfcda2d98758160d765485489cd7f64 100644 (file)
 #include <linux/slab.h>
 #include "cpufreq_governor.h"
 
+struct cs_policy_dbs_info {
+       struct policy_dbs_info policy_dbs;
+       unsigned int down_skip;
+       unsigned int requested_freq;
+};
+
+static inline struct cs_policy_dbs_info *to_dbs_info(struct policy_dbs_info *policy_dbs)
+{
+       return container_of(policy_dbs, struct cs_policy_dbs_info, policy_dbs);
+}
+
 /* Conservative governor macros */
 #define DEF_FREQUENCY_UP_THRESHOLD             (80)
 #define DEF_FREQUENCY_DOWN_THRESHOLD           (20)
@@ -23,6 +34,8 @@
 
 static DEFINE_PER_CPU(struct cs_cpu_dbs_info_s, cs_cpu_dbs_info);
 
+static struct dbs_governor cs_dbs_gov;
+
 static inline unsigned int get_freq_target(struct cs_dbs_tuners *cs_tuners,
                                           struct cpufreq_policy *policy)
 {
@@ -44,20 +57,20 @@ static inline unsigned int get_freq_target(struct cs_dbs_tuners *cs_tuners,
  * Any frequency increase takes it to the maximum frequency. Frequency reduction
  * happens at minimum steps of 5% (default) of maximum frequency
  */
-static void cs_check_cpu(int cpu, unsigned int load)
+static unsigned int cs_dbs_timer(struct cpufreq_policy *policy)
 {
-       struct cs_cpu_dbs_info_s *dbs_info = &per_cpu(cs_cpu_dbs_info, cpu);
-       struct cpufreq_policy *policy = dbs_info->cdbs.policy_dbs->policy;
        struct policy_dbs_info *policy_dbs = policy->governor_data;
+       struct cs_policy_dbs_info *dbs_info = to_dbs_info(policy_dbs);
        struct dbs_data *dbs_data = policy_dbs->dbs_data;
        struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
+       unsigned int load = dbs_update(policy);
 
        /*
         * break out if we 'cannot' reduce the speed as the user might
         * want freq_step to be zero
         */
        if (cs_tuners->freq_step == 0)
-               return;
+               goto out;
 
        /* Check for frequency increase */
        if (load > dbs_data->up_threshold) {
@@ -65,7 +78,7 @@ static void cs_check_cpu(int cpu, unsigned int load)
 
                /* if we are already at full speed then break out early */
                if (dbs_info->requested_freq == policy->max)
-                       return;
+                       goto out;
 
                dbs_info->requested_freq += get_freq_target(cs_tuners, policy);
 
@@ -74,12 +87,12 @@ static void cs_check_cpu(int cpu, unsigned int load)
 
                __cpufreq_driver_target(policy, dbs_info->requested_freq,
                        CPUFREQ_RELATION_H);
-               return;
+               goto out;
        }
 
        /* if sampling_down_factor is active break out early */
        if (++dbs_info->down_skip < dbs_data->sampling_down_factor)
-               return;
+               goto out;
        dbs_info->down_skip = 0;
 
        /* Check for frequency decrease */
@@ -89,7 +102,7 @@ static void cs_check_cpu(int cpu, unsigned int load)
                 * if we cannot reduce the frequency anymore, break out early
                 */
                if (policy->cur == policy->min)
-                       return;
+                       goto out;
 
                freq_target = get_freq_target(cs_tuners, policy);
                if (dbs_info->requested_freq > freq_target)
@@ -99,17 +112,10 @@ static void cs_check_cpu(int cpu, unsigned int load)
 
                __cpufreq_driver_target(policy, dbs_info->requested_freq,
                                CPUFREQ_RELATION_L);
-               return;
        }
-}
 
-static unsigned int cs_dbs_timer(struct cpufreq_policy *policy)
-{
-       struct policy_dbs_info *policy_dbs = policy->governor_data;
-       struct dbs_data *dbs_data = policy_dbs->dbs_data;
-
-       dbs_check_cpu(policy);
-       return delay_for_sampling_rate(dbs_data->sampling_rate);
+ out:
+       return dbs_data->sampling_rate;
 }
 
 static int dbs_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
@@ -171,7 +177,7 @@ static ssize_t store_down_threshold(struct dbs_data *dbs_data, const char *buf,
 static ssize_t store_ignore_nice_load(struct dbs_data *dbs_data,
                const char *buf, size_t count)
 {
-       unsigned int input, j;
+       unsigned int input;
        int ret;
 
        ret = sscanf(buf, "%u", &input);
@@ -187,15 +193,8 @@ static ssize_t store_ignore_nice_load(struct dbs_data *dbs_data,
        dbs_data->ignore_nice_load = input;
 
        /* we need to re-evaluate prev_cpu_idle */
-       for_each_online_cpu(j) {
-               struct cs_cpu_dbs_info_s *dbs_info;
-               dbs_info = &per_cpu(cs_cpu_dbs_info, j);
-               dbs_info->cdbs.prev_cpu_idle = get_cpu_idle_time(j,
-                                       &dbs_info->cdbs.prev_cpu_wall, 0);
-               if (dbs_data->ignore_nice_load)
-                       dbs_info->cdbs.prev_cpu_nice =
-                               kcpustat_cpu(j).cpustat[CPUTIME_NICE];
-       }
+       gov_update_cpu_data(&cs_dbs_gov, dbs_data);
+
        return count;
 }
 
@@ -250,6 +249,19 @@ static struct attribute *cs_attributes[] = {
 
 /************************** sysfs end ************************/
 
+static struct policy_dbs_info *cs_alloc(void)
+{
+       struct cs_policy_dbs_info *dbs_info;
+
+       dbs_info = kzalloc(sizeof(*dbs_info), GFP_KERNEL);
+       return dbs_info ? &dbs_info->policy_dbs : NULL;
+}
+
+static void cs_free(struct policy_dbs_info *policy_dbs)
+{
+       kfree(to_dbs_info(policy_dbs));
+}
+
 static int cs_init(struct dbs_data *dbs_data, bool notify)
 {
        struct cs_dbs_tuners *tuners;
@@ -286,6 +298,14 @@ static void cs_exit(struct dbs_data *dbs_data, bool notify)
        kfree(dbs_data->tuners);
 }
 
+static void cs_start(struct cpufreq_policy *policy)
+{
+       struct cs_policy_dbs_info *dbs_info = to_dbs_info(policy->governor_data);
+
+       dbs_info->down_skip = 0;
+       dbs_info->requested_freq = policy->cur;
+}
+
 define_get_cpu_dbs_routines(cs_cpu_dbs_info);
 
 static struct dbs_governor cs_dbs_gov = {
@@ -295,14 +315,14 @@ static struct dbs_governor cs_dbs_gov = {
                .max_transition_latency = TRANSITION_LATENCY_LIMIT,
                .owner = THIS_MODULE,
        },
-       .governor = GOV_CONSERVATIVE,
        .kobj_type = { .default_attrs = cs_attributes },
        .get_cpu_cdbs = get_cpu_cdbs,
-       .get_cpu_dbs_info_s = get_cpu_dbs_info_s,
        .gov_dbs_timer = cs_dbs_timer,
-       .gov_check_cpu = cs_check_cpu,
+       .alloc = cs_alloc,
+       .free = cs_free,
        .init = cs_init,
        .exit = cs_exit,
+       .start = cs_start,
 };
 
 #define CPU_FREQ_GOV_CONSERVATIVE      (&cs_dbs_gov.gov)
@@ -311,9 +331,8 @@ static int dbs_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
                                void *data)
 {
        struct cpufreq_freqs *freq = data;
-       struct cs_cpu_dbs_info_s *dbs_info =
-                                       &per_cpu(cs_cpu_dbs_info, freq->cpu);
        struct cpufreq_policy *policy = cpufreq_cpu_get_raw(freq->cpu);
+       struct cs_policy_dbs_info *dbs_info;
 
        if (!policy)
                return 0;
@@ -322,6 +341,7 @@ static int dbs_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
        if (policy->governor != CPU_FREQ_GOV_CONSERVATIVE)
                return 0;
 
+       dbs_info = to_dbs_info(policy->governor_data);
        /*
         * we only care if our internally tracked freq moves outside the 'valid'
         * ranges of frequency available to us otherwise we do not change it
This page took 0.027808 seconds and 5 git commands to generate.