cpufreq: Add CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING cpufreq driver flag
authorViresh Kumar <viresh.kumar@linaro.org>
Wed, 19 Jul 2017 10:12:48 +0000 (15:42 +0530)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 25 Jul 2017 22:15:46 +0000 (00:15 +0200)
The policy->transition_latency field is used for multiple purposes
today and its not straight forward at all. This is how it is used:

A. Set the correct transition_latency value.

B. Set it to CPUFREQ_ETERNAL because:
   1. We don't want automatic dynamic switching (with
      ondemand/conservative) to happen at all.
   2. We don't know the transition latency.

This patch handles the B.1. case in a more readable way. A new flag for
the cpufreq drivers is added to disallow use of cpufreq governors which
have dynamic_switching flag set.

All the current cpufreq drivers which are setting transition_latency
unconditionally to CPUFREQ_ETERNAL are updated to use it. They don't
need to set transition_latency anymore.

There shouldn't be any functional change after this patch.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Dominik Brodowski <linux@dominikbrodowski.net>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/cpufreq/cpufreq-nforce2.c
drivers/cpufreq/cpufreq.c
drivers/cpufreq/elanfreq.c
drivers/cpufreq/gx-suspmod.c
drivers/cpufreq/pmac32-cpufreq.c
drivers/cpufreq/sa1100-cpufreq.c
drivers/cpufreq/sa1110-cpufreq.c
drivers/cpufreq/sh-cpufreq.c
drivers/cpufreq/speedstep-smi.c
drivers/cpufreq/unicore2-cpufreq.c
include/linux/cpufreq.h

index 5503d491b0160f39be799469aef3fd0d5bc60e72..dbf82f36d270dfd8fd5bd51b4db5f261c37930c4 100644 (file)
@@ -357,7 +357,6 @@ static int nforce2_cpu_init(struct cpufreq_policy *policy)
        /* cpuinfo and default policy values */
        policy->min = policy->cpuinfo.min_freq = min_fsb * fid * 100;
        policy->max = policy->cpuinfo.max_freq = max_fsb * fid * 100;
-       policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;
 
        return 0;
 }
@@ -369,6 +368,7 @@ static int nforce2_cpu_exit(struct cpufreq_policy *policy)
 
 static struct cpufreq_driver nforce2_driver = {
        .name = "nforce2",
+       .flags = CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING,
        .verify = nforce2_verify,
        .target = nforce2_target,
        .get = nforce2_get,
index 88139e5e87da31eda192fbdb817f08720f5b31b8..6ec589c048b2ab35849b54883a03528ce20a8e2e 100644 (file)
@@ -2005,11 +2005,12 @@ static int cpufreq_init_governor(struct cpufreq_policy *policy)
 
        /* Platform doesn't want dynamic frequency switching ? */
        if (policy->governor->dynamic_switching &&
-           policy->cpuinfo.transition_latency == CPUFREQ_ETERNAL) {
+           (cpufreq_driver->flags & CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING ||
+           policy->cpuinfo.transition_latency == CPUFREQ_ETERNAL)) {
                struct cpufreq_governor *gov = cpufreq_fallback_governor();
 
                if (gov) {
-                       pr_warn("Transition latency set to CPUFREQ_ETERNAL, can't use %s governor. Fallback to %s governor\n",
+                       pr_warn("Can't use %s governor as dynamic switching is disallowed. Fallback to %s governor\n",
                                policy->governor->name, gov->name);
                        policy->governor = gov;
                } else {
index bfce11cba1df8d92068b4095e1772ce38b7db12e..45e2ca62515e5647bdd60034575b35e964185005 100644 (file)
@@ -165,9 +165,6 @@ static int elanfreq_cpu_init(struct cpufreq_policy *policy)
                if (pos->frequency > max_freq)
                        pos->frequency = CPUFREQ_ENTRY_INVALID;
 
-       /* cpuinfo and default policy values */
-       policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;
-
        return cpufreq_table_validate_and_show(policy, elanfreq_table);
 }
 
@@ -196,6 +193,7 @@ __setup("elanfreq=", elanfreq_setup);
 
 static struct cpufreq_driver elanfreq_driver = {
        .get            = elanfreq_get_cpu_frequency,
+       .flags          = CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING,
        .verify         = cpufreq_generic_frequency_table_verify,
        .target_index   = elanfreq_target,
        .init           = elanfreq_cpu_init,
index 3488c9c175eb2ed90164d1b2d20fcf2c089262b7..8f52a06664e32d058c3192406f233cdafa7d1a98 100644 (file)
@@ -428,7 +428,6 @@ static int cpufreq_gx_cpu_init(struct cpufreq_policy *policy)
        policy->max = maxfreq;
        policy->cpuinfo.min_freq = maxfreq / max_duration;
        policy->cpuinfo.max_freq = maxfreq;
-       policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;
 
        return 0;
 }
@@ -438,6 +437,7 @@ static int cpufreq_gx_cpu_init(struct cpufreq_policy *policy)
  *   MediaGX/Geode GX initialize cpufreq driver
  */
 static struct cpufreq_driver gx_suspmod_driver = {
+       .flags          = CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING,
        .get            = gx_get_cpuspeed,
        .verify         = cpufreq_gx_verify,
        .target         = cpufreq_gx_target,
index ff44016ea0312e4b6c50ff1d9f0126f2d63dcddc..61ae06ca008e746ac7d166f502ac212ab86148fc 100644 (file)
@@ -442,7 +442,8 @@ static struct cpufreq_driver pmac_cpufreq_driver = {
        .init           = pmac_cpufreq_cpu_init,
        .suspend        = pmac_cpufreq_suspend,
        .resume         = pmac_cpufreq_resume,
-       .flags          = CPUFREQ_PM_NO_WARN,
+       .flags          = CPUFREQ_PM_NO_WARN |
+                         CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING,
        .attr           = cpufreq_generic_attr,
        .name           = "powermac",
 };
@@ -626,14 +627,16 @@ static int __init pmac_cpufreq_setup(void)
        if (!value)
                goto out;
        cur_freq = (*value) / 1000;
-       transition_latency = CPUFREQ_ETERNAL;
 
        /*  Check for 7447A based MacRISC3 */
        if (of_machine_is_compatible("MacRISC3") &&
            of_get_property(cpunode, "dynamic-power-step", NULL) &&
            PVR_VER(mfspr(SPRN_PVR)) == 0x8003) {
                pmac_cpufreq_init_7447A(cpunode);
+
+               /* Allow dynamic switching */
                transition_latency = 8000000;
+               pmac_cpufreq_driver.flags &= ~CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING;
        /* Check for other MacRISC3 machines */
        } else if (of_machine_is_compatible("PowerBook3,4") ||
                   of_machine_is_compatible("PowerBook3,5") ||
index 728eab77e8e080457bca09f1ad8d7e69d936e6d1..e2d8a77c36d5824dda438e2800c46e2afc58b0c7 100644 (file)
@@ -197,11 +197,12 @@ static int sa1100_target(struct cpufreq_policy *policy, unsigned int ppcr)
 
 static int __init sa1100_cpu_init(struct cpufreq_policy *policy)
 {
-       return cpufreq_generic_init(policy, sa11x0_freq_table, CPUFREQ_ETERNAL);
+       return cpufreq_generic_init(policy, sa11x0_freq_table, 0);
 }
 
 static struct cpufreq_driver sa1100_driver __refdata = {
-       .flags          = CPUFREQ_STICKY | CPUFREQ_NEED_INITIAL_FREQ_CHECK,
+       .flags          = CPUFREQ_STICKY | CPUFREQ_NEED_INITIAL_FREQ_CHECK |
+                         CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING,
        .verify         = cpufreq_generic_frequency_table_verify,
        .target_index   = sa1100_target,
        .get            = sa11x0_getspeed,
index 2bac9b6cfeea3b905ca99e171f5f60012f9a9363..66e5fb088ecca76c6d62065ea11a15ce01d488db 100644 (file)
@@ -306,13 +306,14 @@ static int sa1110_target(struct cpufreq_policy *policy, unsigned int ppcr)
 
 static int __init sa1110_cpu_init(struct cpufreq_policy *policy)
 {
-       return cpufreq_generic_init(policy, sa11x0_freq_table, CPUFREQ_ETERNAL);
+       return cpufreq_generic_init(policy, sa11x0_freq_table, 0);
 }
 
 /* sa1110_driver needs __refdata because it must remain after init registers
  * it with cpufreq_register_driver() */
 static struct cpufreq_driver sa1110_driver __refdata = {
-       .flags          = CPUFREQ_STICKY | CPUFREQ_NEED_INITIAL_FREQ_CHECK,
+       .flags          = CPUFREQ_STICKY | CPUFREQ_NEED_INITIAL_FREQ_CHECK |
+                         CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING,
        .verify         = cpufreq_generic_frequency_table_verify,
        .target_index   = sa1110_target,
        .get            = sa11x0_getspeed,
index 719c3d9f07fb1adbb0e4e528d00c3f49bb39be33..28893d435cf56b940143bb169193b3bb3f1506a4 100644 (file)
@@ -137,8 +137,6 @@ static int sh_cpufreq_cpu_init(struct cpufreq_policy *policy)
                        (clk_round_rate(cpuclk, ~0UL) + 500) / 1000;
        }
 
-       policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;
-
        dev_info(dev, "CPU Frequencies - Minimum %u.%03u MHz, "
               "Maximum %u.%03u MHz.\n",
               policy->min / 1000, policy->min % 1000,
@@ -159,6 +157,7 @@ static int sh_cpufreq_cpu_exit(struct cpufreq_policy *policy)
 
 static struct cpufreq_driver sh_cpufreq_driver = {
        .name           = "sh",
+       .flags          = CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING,
        .get            = sh_cpufreq_get,
        .target         = sh_cpufreq_target,
        .verify         = sh_cpufreq_verify,
index 37b30071c220e456c72985bf50147c12f2edcc67..d23f24ccff38ef59dbb23880bf2492be4acb300c 100644 (file)
@@ -266,7 +266,6 @@ static int speedstep_cpu_init(struct cpufreq_policy *policy)
                        pr_debug("workaround worked.\n");
        }
 
-       policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;
        return cpufreq_table_validate_and_show(policy, speedstep_freqs);
 }
 
@@ -290,6 +289,7 @@ static int speedstep_resume(struct cpufreq_policy *policy)
 
 static struct cpufreq_driver speedstep_driver = {
        .name           = "speedstep-smi",
+       .flags          = CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING,
        .verify         = cpufreq_generic_frequency_table_verify,
        .target_index   = speedstep_target,
        .init           = speedstep_cpu_init,
index 6f9dfa80563a344249ef153aa4f92b17b35ce158..db62d984475132f0f9abb24a0dfd1db2e405e7e6 100644 (file)
@@ -58,13 +58,12 @@ static int __init ucv2_cpu_init(struct cpufreq_policy *policy)
 
        policy->min = policy->cpuinfo.min_freq = 250000;
        policy->max = policy->cpuinfo.max_freq = 1000000;
-       policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;
        policy->clk = clk_get(NULL, "MAIN_CLK");
        return PTR_ERR_OR_ZERO(policy->clk);
 }
 
 static struct cpufreq_driver ucv2_driver = {
-       .flags          = CPUFREQ_STICKY,
+       .flags          = CPUFREQ_STICKY | CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING,
        .verify         = ucv2_verify_speed,
        .target         = ucv2_target,
        .get            = cpufreq_generic_get,
index e141dbbb9d1c03529271922b7db301c8c6c57cb9..5f40522ec98cbe12a2eca27d08812e6487342df2 100644 (file)
@@ -370,6 +370,12 @@ struct cpufreq_driver {
  */
 #define CPUFREQ_NEED_INITIAL_FREQ_CHECK        (1 << 5)
 
+/*
+ * Set by drivers to disallow use of governors with "dynamic_switching" flag
+ * set.
+ */
+#define CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING (1 << 6)
+
 int cpufreq_register_driver(struct cpufreq_driver *driver_data);
 int cpufreq_unregister_driver(struct cpufreq_driver *driver_data);