cpufreq: governor: Add a ->start callback for governors
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Thu, 18 Feb 2016 01:21:21 +0000 (02:21 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 9 Mar 2016 13:41:07 +0000 (14:41 +0100)
To avoid having to check the governor type explicitly in the common
code in order to initialize data structures specific to the governor
type properly, add a ->start callback to struct dbs_governor and
use it to initialize those data structures for the ondemand and
conservative governors.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
drivers/cpufreq/cpufreq_conservative.c
drivers/cpufreq/cpufreq_governor.c
drivers/cpufreq/cpufreq_governor.h
drivers/cpufreq/cpufreq_ondemand.c

index 4a6f8e1ed72e276d2abda2337f68d513be8b9c4b..c11fe95152dea7ccc5864b0672a72336154fa4a3 100644 (file)
@@ -279,6 +279,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_cpu_dbs_info_s *dbs_info = &per_cpu(cs_cpu_dbs_info, policy->cpu);
+
+       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,6 +303,7 @@ static struct dbs_governor cs_dbs_gov = {
        .gov_dbs_timer = cs_dbs_timer,
        .init = cs_init,
        .exit = cs_exit,
+       .start = cs_start,
 };
 
 #define CPU_FREQ_GOV_CONSERVATIVE      (&cs_dbs_gov.gov)
index 60268160e0adaf61ebc6770bf00eed650f21a812..badbd467e5e261e793e6c275a34463940ff692e5 100644 (file)
@@ -517,7 +517,7 @@ static int cpufreq_governor_start(struct cpufreq_policy *policy)
        struct dbs_governor *gov = dbs_governor_of(policy);
        struct policy_dbs_info *policy_dbs = policy->governor_data;
        struct dbs_data *dbs_data = policy_dbs->dbs_data;
-       unsigned int sampling_rate, ignore_nice, j, cpu = policy->cpu;
+       unsigned int sampling_rate, ignore_nice, j;
        unsigned int io_busy;
 
        if (!policy->cur)
@@ -543,19 +543,7 @@ static int cpufreq_governor_start(struct cpufreq_policy *policy)
                        j_cdbs->prev_cpu_nice = kcpustat_cpu(j).cpustat[CPUTIME_NICE];
        }
 
-       if (gov->governor == GOV_CONSERVATIVE) {
-               struct cs_cpu_dbs_info_s *cs_dbs_info =
-                       gov->get_cpu_dbs_info_s(cpu);
-
-               cs_dbs_info->down_skip = 0;
-               cs_dbs_info->requested_freq = policy->cur;
-       } else {
-               struct od_ops *od_ops = gov->gov_ops;
-               struct od_cpu_dbs_info_s *od_dbs_info = gov->get_cpu_dbs_info_s(cpu);
-
-               od_dbs_info->sample_type = OD_NORMAL_SAMPLE;
-               od_ops->powersave_bias_init_cpu(cpu);
-       }
+       gov->start(policy);
 
        gov_set_update_util(policy_dbs, sampling_rate);
        return 0;
index 7b363932806614f09f6150980e1621981dc3772f..2ae0ad50ca3d3c58f3cfc37c867cf503a13687ff 100644 (file)
@@ -205,6 +205,7 @@ struct dbs_governor {
        unsigned int (*gov_dbs_timer)(struct cpufreq_policy *policy);
        int (*init)(struct dbs_data *dbs_data, bool notify);
        void (*exit)(struct dbs_data *dbs_data, bool notify);
+       void (*start)(struct cpufreq_policy *policy);
 
        /* Governor specific ops, see below */
        void *gov_ops;
index 330b5884b99b44245a1e605682030c606bcfa041..de069f80b619740d280b38c82efcec5a3fdf3035 100644 (file)
@@ -410,6 +410,15 @@ static void od_exit(struct dbs_data *dbs_data, bool notify)
        kfree(dbs_data->tuners);
 }
 
+static void od_start(struct cpufreq_policy *policy)
+{
+       unsigned int cpu = policy->cpu;
+       struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info, cpu);
+
+       dbs_info->sample_type = OD_NORMAL_SAMPLE;
+       od_ops.powersave_bias_init_cpu(cpu);
+}
+
 define_get_cpu_dbs_routines(od_cpu_dbs_info);
 
 static struct od_ops od_ops = {
@@ -432,6 +441,7 @@ static struct dbs_governor od_dbs_gov = {
        .gov_ops = &od_ops,
        .init = od_init,
        .exit = od_exit,
+       .start = od_start,
 };
 
 #define CPU_FREQ_GOV_ONDEMAND  (&od_dbs_gov.gov)