Commit de1df26b authored by Rafael J. Wysocki's avatar Rafael J. Wysocki

cpufreq: Clean up default and fallback governor setup

The preprocessor magic used for setting the default cpufreq governor
(and for using the performance governor as a fallback one for that
matter) is really nasty, so replace it with __weak functions and
overrides.
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: default avatarSaravana Kannan <skannan@codeaurora.org>
Acked-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
parent 36f90b0a
...@@ -959,6 +959,11 @@ static int cpufreq_add_dev_interface(struct cpufreq_policy *policy) ...@@ -959,6 +959,11 @@ static int cpufreq_add_dev_interface(struct cpufreq_policy *policy)
return cpufreq_add_dev_symlink(policy); return cpufreq_add_dev_symlink(policy);
} }
__weak struct cpufreq_governor *cpufreq_default_governor(void)
{
return NULL;
}
static int cpufreq_init_policy(struct cpufreq_policy *policy) static int cpufreq_init_policy(struct cpufreq_policy *policy)
{ {
struct cpufreq_governor *gov = NULL; struct cpufreq_governor *gov = NULL;
...@@ -968,11 +973,14 @@ static int cpufreq_init_policy(struct cpufreq_policy *policy) ...@@ -968,11 +973,14 @@ static int cpufreq_init_policy(struct cpufreq_policy *policy)
/* Update governor of new_policy to the governor used before hotplug */ /* Update governor of new_policy to the governor used before hotplug */
gov = find_governor(policy->last_governor); gov = find_governor(policy->last_governor);
if (gov) if (gov) {
pr_debug("Restoring governor %s for cpu %d\n", pr_debug("Restoring governor %s for cpu %d\n",
policy->governor->name, policy->cpu); policy->governor->name, policy->cpu);
else } else {
gov = CPUFREQ_DEFAULT_GOVERNOR; gov = cpufreq_default_governor();
if (!gov)
return -ENODATA;
}
new_policy.governor = gov; new_policy.governor = gov;
...@@ -1920,21 +1928,16 @@ int cpufreq_driver_target(struct cpufreq_policy *policy, ...@@ -1920,21 +1928,16 @@ int cpufreq_driver_target(struct cpufreq_policy *policy,
} }
EXPORT_SYMBOL_GPL(cpufreq_driver_target); EXPORT_SYMBOL_GPL(cpufreq_driver_target);
__weak struct cpufreq_governor *cpufreq_fallback_governor(void)
{
return NULL;
}
static int __cpufreq_governor(struct cpufreq_policy *policy, static int __cpufreq_governor(struct cpufreq_policy *policy,
unsigned int event) unsigned int event)
{ {
int ret; int ret;
/* Only must be defined when default governor is known to have latency
restrictions, like e.g. conservative or ondemand.
That this is the case is already ensured in Kconfig
*/
#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE
struct cpufreq_governor *gov = &cpufreq_gov_performance;
#else
struct cpufreq_governor *gov = NULL;
#endif
/* Don't start any governor operations if we are entering suspend */ /* Don't start any governor operations if we are entering suspend */
if (cpufreq_suspended) if (cpufreq_suspended)
return 0; return 0;
...@@ -1948,12 +1951,14 @@ static int __cpufreq_governor(struct cpufreq_policy *policy, ...@@ -1948,12 +1951,14 @@ static int __cpufreq_governor(struct cpufreq_policy *policy,
if (policy->governor->max_transition_latency && if (policy->governor->max_transition_latency &&
policy->cpuinfo.transition_latency > policy->cpuinfo.transition_latency >
policy->governor->max_transition_latency) { policy->governor->max_transition_latency) {
if (!gov) struct cpufreq_governor *gov = cpufreq_fallback_governor();
return -EINVAL;
else { if (gov) {
pr_warn("%s governor failed, too long transition latency of HW, fallback to %s governor\n", pr_warn("%s governor failed, too long transition latency of HW, fallback to %s governor\n",
policy->governor->name, gov->name); policy->governor->name, gov->name);
policy->governor = gov; policy->governor = gov;
} else {
return -EINVAL;
} }
} }
......
...@@ -26,10 +26,7 @@ static DEFINE_PER_CPU(struct cs_cpu_dbs_info_s, cs_cpu_dbs_info); ...@@ -26,10 +26,7 @@ static DEFINE_PER_CPU(struct cs_cpu_dbs_info_s, cs_cpu_dbs_info);
static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy, static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy,
unsigned int event); unsigned int event);
#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE static struct cpufreq_governor cpufreq_gov_conservative = {
static
#endif
struct cpufreq_governor cpufreq_gov_conservative = {
.name = "conservative", .name = "conservative",
.governor = cs_cpufreq_governor_dbs, .governor = cs_cpufreq_governor_dbs,
.max_transition_latency = TRANSITION_LATENCY_LIMIT, .max_transition_latency = TRANSITION_LATENCY_LIMIT,
...@@ -399,6 +396,11 @@ MODULE_DESCRIPTION("'cpufreq_conservative' - A dynamic cpufreq governor for " ...@@ -399,6 +396,11 @@ MODULE_DESCRIPTION("'cpufreq_conservative' - A dynamic cpufreq governor for "
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE
struct cpufreq_governor *cpufreq_default_governor(void)
{
return &cpufreq_gov_conservative;
}
fs_initcall(cpufreq_gov_dbs_init); fs_initcall(cpufreq_gov_dbs_init);
#else #else
module_init(cpufreq_gov_dbs_init); module_init(cpufreq_gov_dbs_init);
......
...@@ -31,9 +31,7 @@ static DEFINE_PER_CPU(struct od_cpu_dbs_info_s, od_cpu_dbs_info); ...@@ -31,9 +31,7 @@ static DEFINE_PER_CPU(struct od_cpu_dbs_info_s, od_cpu_dbs_info);
static struct od_ops od_ops; static struct od_ops od_ops;
#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND
static struct cpufreq_governor cpufreq_gov_ondemand; static struct cpufreq_governor cpufreq_gov_ondemand;
#endif
static unsigned int default_powersave_bias; static unsigned int default_powersave_bias;
...@@ -554,6 +552,19 @@ static struct common_dbs_data od_dbs_cdata = { ...@@ -554,6 +552,19 @@ static struct common_dbs_data od_dbs_cdata = {
.mutex = __MUTEX_INITIALIZER(od_dbs_cdata.mutex), .mutex = __MUTEX_INITIALIZER(od_dbs_cdata.mutex),
}; };
static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
unsigned int event)
{
return cpufreq_governor_dbs(policy, &od_dbs_cdata, event);
}
static struct cpufreq_governor cpufreq_gov_ondemand = {
.name = "ondemand",
.governor = od_cpufreq_governor_dbs,
.max_transition_latency = TRANSITION_LATENCY_LIMIT,
.owner = THIS_MODULE,
};
static void od_set_powersave_bias(unsigned int powersave_bias) static void od_set_powersave_bias(unsigned int powersave_bias)
{ {
struct cpufreq_policy *policy; struct cpufreq_policy *policy;
...@@ -605,22 +616,6 @@ void od_unregister_powersave_bias_handler(void) ...@@ -605,22 +616,6 @@ void od_unregister_powersave_bias_handler(void)
} }
EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler); EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
unsigned int event)
{
return cpufreq_governor_dbs(policy, &od_dbs_cdata, event);
}
#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND
static
#endif
struct cpufreq_governor cpufreq_gov_ondemand = {
.name = "ondemand",
.governor = od_cpufreq_governor_dbs,
.max_transition_latency = TRANSITION_LATENCY_LIMIT,
.owner = THIS_MODULE,
};
static int __init cpufreq_gov_dbs_init(void) static int __init cpufreq_gov_dbs_init(void)
{ {
return cpufreq_register_governor(&cpufreq_gov_ondemand); return cpufreq_register_governor(&cpufreq_gov_ondemand);
...@@ -638,6 +633,11 @@ MODULE_DESCRIPTION("'cpufreq_ondemand' - A dynamic cpufreq governor for " ...@@ -638,6 +633,11 @@ MODULE_DESCRIPTION("'cpufreq_ondemand' - A dynamic cpufreq governor for "
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND
struct cpufreq_governor *cpufreq_default_governor(void)
{
return &cpufreq_gov_ondemand;
}
fs_initcall(cpufreq_gov_dbs_init); fs_initcall(cpufreq_gov_dbs_init);
#else #else
module_init(cpufreq_gov_dbs_init); module_init(cpufreq_gov_dbs_init);
......
...@@ -33,10 +33,7 @@ static int cpufreq_governor_performance(struct cpufreq_policy *policy, ...@@ -33,10 +33,7 @@ static int cpufreq_governor_performance(struct cpufreq_policy *policy,
return 0; return 0;
} }
#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE_MODULE static struct cpufreq_governor cpufreq_gov_performance = {
static
#endif
struct cpufreq_governor cpufreq_gov_performance = {
.name = "performance", .name = "performance",
.governor = cpufreq_governor_performance, .governor = cpufreq_governor_performance,
.owner = THIS_MODULE, .owner = THIS_MODULE,
...@@ -52,6 +49,19 @@ static void __exit cpufreq_gov_performance_exit(void) ...@@ -52,6 +49,19 @@ static void __exit cpufreq_gov_performance_exit(void)
cpufreq_unregister_governor(&cpufreq_gov_performance); cpufreq_unregister_governor(&cpufreq_gov_performance);
} }
#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
struct cpufreq_governor *cpufreq_default_governor(void)
{
return &cpufreq_gov_performance;
}
#endif
#ifndef CONFIG_CPU_FREQ_GOV_PERFORMANCE_MODULE
struct cpufreq_governor *cpufreq_fallback_governor(void)
{
return &cpufreq_gov_performance;
}
#endif
MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>"); MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>");
MODULE_DESCRIPTION("CPUfreq policy governor 'performance'"); MODULE_DESCRIPTION("CPUfreq policy governor 'performance'");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
......
...@@ -33,10 +33,7 @@ static int cpufreq_governor_powersave(struct cpufreq_policy *policy, ...@@ -33,10 +33,7 @@ static int cpufreq_governor_powersave(struct cpufreq_policy *policy,
return 0; return 0;
} }
#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE static struct cpufreq_governor cpufreq_gov_powersave = {
static
#endif
struct cpufreq_governor cpufreq_gov_powersave = {
.name = "powersave", .name = "powersave",
.governor = cpufreq_governor_powersave, .governor = cpufreq_governor_powersave,
.owner = THIS_MODULE, .owner = THIS_MODULE,
...@@ -57,6 +54,11 @@ MODULE_DESCRIPTION("CPUfreq policy governor 'powersave'"); ...@@ -57,6 +54,11 @@ MODULE_DESCRIPTION("CPUfreq policy governor 'powersave'");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE
struct cpufreq_governor *cpufreq_default_governor(void)
{
return &cpufreq_gov_powersave;
}
fs_initcall(cpufreq_gov_powersave_init); fs_initcall(cpufreq_gov_powersave_init);
#else #else
module_init(cpufreq_gov_powersave_init); module_init(cpufreq_gov_powersave_init);
......
...@@ -89,10 +89,7 @@ static int cpufreq_governor_userspace(struct cpufreq_policy *policy, ...@@ -89,10 +89,7 @@ static int cpufreq_governor_userspace(struct cpufreq_policy *policy,
return rc; return rc;
} }
#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE static struct cpufreq_governor cpufreq_gov_userspace = {
static
#endif
struct cpufreq_governor cpufreq_gov_userspace = {
.name = "userspace", .name = "userspace",
.governor = cpufreq_governor_userspace, .governor = cpufreq_governor_userspace,
.store_setspeed = cpufreq_set, .store_setspeed = cpufreq_set,
...@@ -116,6 +113,11 @@ MODULE_DESCRIPTION("CPUfreq policy governor 'userspace'"); ...@@ -116,6 +113,11 @@ MODULE_DESCRIPTION("CPUfreq policy governor 'userspace'");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE
struct cpufreq_governor *cpufreq_default_governor(void)
{
return &cpufreq_gov_userspace;
}
fs_initcall(cpufreq_gov_userspace_init); fs_initcall(cpufreq_gov_userspace_init);
#else #else
module_init(cpufreq_gov_userspace_init); module_init(cpufreq_gov_userspace_init);
......
...@@ -464,29 +464,8 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy, ...@@ -464,29 +464,8 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
int cpufreq_register_governor(struct cpufreq_governor *governor); int cpufreq_register_governor(struct cpufreq_governor *governor);
void cpufreq_unregister_governor(struct cpufreq_governor *governor); void cpufreq_unregister_governor(struct cpufreq_governor *governor);
/* CPUFREQ DEFAULT GOVERNOR */ struct cpufreq_governor *cpufreq_default_governor(void);
/* struct cpufreq_governor *cpufreq_fallback_governor(void);
* Performance governor is fallback governor if any other gov failed to auto
* load due latency restrictions
*/
#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE
extern struct cpufreq_governor cpufreq_gov_performance;
#endif
#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_performance)
#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE)
extern struct cpufreq_governor cpufreq_gov_powersave;
#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_powersave)
#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE)
extern struct cpufreq_governor cpufreq_gov_userspace;
#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_userspace)
#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND)
extern struct cpufreq_governor cpufreq_gov_ondemand;
#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_ondemand)
#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE)
extern struct cpufreq_governor cpufreq_gov_conservative;
#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_conservative)
#endif
/********************************************************************* /*********************************************************************
* FREQUENCY TABLE HELPERS * * FREQUENCY TABLE HELPERS *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment