Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cpufreq: Add CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING cpufreq driver flag

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>

authored by

Viresh Kumar and committed by
Rafael J. Wysocki
fe829ed8 560c6e45

+26 -18
+1 -1
drivers/cpufreq/cpufreq-nforce2.c
··· 357 357 /* cpuinfo and default policy values */ 358 358 policy->min = policy->cpuinfo.min_freq = min_fsb * fid * 100; 359 359 policy->max = policy->cpuinfo.max_freq = max_fsb * fid * 100; 360 - policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; 361 360 362 361 return 0; 363 362 } ··· 368 369 369 370 static struct cpufreq_driver nforce2_driver = { 370 371 .name = "nforce2", 372 + .flags = CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING, 371 373 .verify = nforce2_verify, 372 374 .target = nforce2_target, 373 375 .get = nforce2_get,
+3 -2
drivers/cpufreq/cpufreq.c
··· 2005 2005 2006 2006 /* Platform doesn't want dynamic frequency switching ? */ 2007 2007 if (policy->governor->dynamic_switching && 2008 - policy->cpuinfo.transition_latency == CPUFREQ_ETERNAL) { 2008 + (cpufreq_driver->flags & CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING || 2009 + policy->cpuinfo.transition_latency == CPUFREQ_ETERNAL)) { 2009 2010 struct cpufreq_governor *gov = cpufreq_fallback_governor(); 2010 2011 2011 2012 if (gov) { 2012 - pr_warn("Transition latency set to CPUFREQ_ETERNAL, can't use %s governor. Fallback to %s governor\n", 2013 + pr_warn("Can't use %s governor as dynamic switching is disallowed. Fallback to %s governor\n", 2013 2014 policy->governor->name, gov->name); 2014 2015 policy->governor = gov; 2015 2016 } else {
+1 -3
drivers/cpufreq/elanfreq.c
··· 165 165 if (pos->frequency > max_freq) 166 166 pos->frequency = CPUFREQ_ENTRY_INVALID; 167 167 168 - /* cpuinfo and default policy values */ 169 - policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; 170 - 171 168 return cpufreq_table_validate_and_show(policy, elanfreq_table); 172 169 } 173 170 ··· 193 196 194 197 static struct cpufreq_driver elanfreq_driver = { 195 198 .get = elanfreq_get_cpu_frequency, 199 + .flags = CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING, 196 200 .verify = cpufreq_generic_frequency_table_verify, 197 201 .target_index = elanfreq_target, 198 202 .init = elanfreq_cpu_init,
+1 -1
drivers/cpufreq/gx-suspmod.c
··· 428 428 policy->max = maxfreq; 429 429 policy->cpuinfo.min_freq = maxfreq / max_duration; 430 430 policy->cpuinfo.max_freq = maxfreq; 431 - policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; 432 431 433 432 return 0; 434 433 } ··· 437 438 * MediaGX/Geode GX initialize cpufreq driver 438 439 */ 439 440 static struct cpufreq_driver gx_suspmod_driver = { 441 + .flags = CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING, 440 442 .get = gx_get_cpuspeed, 441 443 .verify = cpufreq_gx_verify, 442 444 .target = cpufreq_gx_target,
+5 -2
drivers/cpufreq/pmac32-cpufreq.c
··· 442 442 .init = pmac_cpufreq_cpu_init, 443 443 .suspend = pmac_cpufreq_suspend, 444 444 .resume = pmac_cpufreq_resume, 445 - .flags = CPUFREQ_PM_NO_WARN, 445 + .flags = CPUFREQ_PM_NO_WARN | 446 + CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING, 446 447 .attr = cpufreq_generic_attr, 447 448 .name = "powermac", 448 449 }; ··· 627 626 if (!value) 628 627 goto out; 629 628 cur_freq = (*value) / 1000; 630 - transition_latency = CPUFREQ_ETERNAL; 631 629 632 630 /* Check for 7447A based MacRISC3 */ 633 631 if (of_machine_is_compatible("MacRISC3") && 634 632 of_get_property(cpunode, "dynamic-power-step", NULL) && 635 633 PVR_VER(mfspr(SPRN_PVR)) == 0x8003) { 636 634 pmac_cpufreq_init_7447A(cpunode); 635 + 636 + /* Allow dynamic switching */ 637 637 transition_latency = 8000000; 638 + pmac_cpufreq_driver.flags &= ~CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING; 638 639 /* Check for other MacRISC3 machines */ 639 640 } else if (of_machine_is_compatible("PowerBook3,4") || 640 641 of_machine_is_compatible("PowerBook3,5") ||
+3 -2
drivers/cpufreq/sa1100-cpufreq.c
··· 197 197 198 198 static int __init sa1100_cpu_init(struct cpufreq_policy *policy) 199 199 { 200 - return cpufreq_generic_init(policy, sa11x0_freq_table, CPUFREQ_ETERNAL); 200 + return cpufreq_generic_init(policy, sa11x0_freq_table, 0); 201 201 } 202 202 203 203 static struct cpufreq_driver sa1100_driver __refdata = { 204 - .flags = CPUFREQ_STICKY | CPUFREQ_NEED_INITIAL_FREQ_CHECK, 204 + .flags = CPUFREQ_STICKY | CPUFREQ_NEED_INITIAL_FREQ_CHECK | 205 + CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING, 205 206 .verify = cpufreq_generic_frequency_table_verify, 206 207 .target_index = sa1100_target, 207 208 .get = sa11x0_getspeed,
+3 -2
drivers/cpufreq/sa1110-cpufreq.c
··· 306 306 307 307 static int __init sa1110_cpu_init(struct cpufreq_policy *policy) 308 308 { 309 - return cpufreq_generic_init(policy, sa11x0_freq_table, CPUFREQ_ETERNAL); 309 + return cpufreq_generic_init(policy, sa11x0_freq_table, 0); 310 310 } 311 311 312 312 /* sa1110_driver needs __refdata because it must remain after init registers 313 313 * it with cpufreq_register_driver() */ 314 314 static struct cpufreq_driver sa1110_driver __refdata = { 315 - .flags = CPUFREQ_STICKY | CPUFREQ_NEED_INITIAL_FREQ_CHECK, 315 + .flags = CPUFREQ_STICKY | CPUFREQ_NEED_INITIAL_FREQ_CHECK | 316 + CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING, 316 317 .verify = cpufreq_generic_frequency_table_verify, 317 318 .target_index = sa1110_target, 318 319 .get = sa11x0_getspeed,
+1 -2
drivers/cpufreq/sh-cpufreq.c
··· 137 137 (clk_round_rate(cpuclk, ~0UL) + 500) / 1000; 138 138 } 139 139 140 - policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; 141 - 142 140 dev_info(dev, "CPU Frequencies - Minimum %u.%03u MHz, " 143 141 "Maximum %u.%03u MHz.\n", 144 142 policy->min / 1000, policy->min % 1000, ··· 157 159 158 160 static struct cpufreq_driver sh_cpufreq_driver = { 159 161 .name = "sh", 162 + .flags = CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING, 160 163 .get = sh_cpufreq_get, 161 164 .target = sh_cpufreq_target, 162 165 .verify = sh_cpufreq_verify,
+1 -1
drivers/cpufreq/speedstep-smi.c
··· 266 266 pr_debug("workaround worked.\n"); 267 267 } 268 268 269 - policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; 270 269 return cpufreq_table_validate_and_show(policy, speedstep_freqs); 271 270 } 272 271 ··· 289 290 290 291 static struct cpufreq_driver speedstep_driver = { 291 292 .name = "speedstep-smi", 293 + .flags = CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING, 292 294 .verify = cpufreq_generic_frequency_table_verify, 293 295 .target_index = speedstep_target, 294 296 .init = speedstep_cpu_init,
+1 -2
drivers/cpufreq/unicore2-cpufreq.c
··· 58 58 59 59 policy->min = policy->cpuinfo.min_freq = 250000; 60 60 policy->max = policy->cpuinfo.max_freq = 1000000; 61 - policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; 62 61 policy->clk = clk_get(NULL, "MAIN_CLK"); 63 62 return PTR_ERR_OR_ZERO(policy->clk); 64 63 } 65 64 66 65 static struct cpufreq_driver ucv2_driver = { 67 - .flags = CPUFREQ_STICKY, 66 + .flags = CPUFREQ_STICKY | CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING, 68 67 .verify = ucv2_verify_speed, 69 68 .target = ucv2_target, 70 69 .get = cpufreq_generic_get,
+6
include/linux/cpufreq.h
··· 370 370 */ 371 371 #define CPUFREQ_NEED_INITIAL_FREQ_CHECK (1 << 5) 372 372 373 + /* 374 + * Set by drivers to disallow use of governors with "dynamic_switching" flag 375 + * set. 376 + */ 377 + #define CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING (1 << 6) 378 + 373 379 int cpufreq_register_driver(struct cpufreq_driver *driver_data); 374 380 int cpufreq_unregister_driver(struct cpufreq_driver *driver_data); 375 381