Skip to content

Commit de1df26

Browse files
committed
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: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Acked-by: Saravana Kannan <skannan@codeaurora.org> Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
1 parent 36f90b0 commit de1df26

File tree

7 files changed

+73
-73
lines changed

7 files changed

+73
-73
lines changed

drivers/cpufreq/cpufreq.c

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,11 @@ static int cpufreq_add_dev_interface(struct cpufreq_policy *policy)
959959
return cpufreq_add_dev_symlink(policy);
960960
}
961961

962+
__weak struct cpufreq_governor *cpufreq_default_governor(void)
963+
{
964+
return NULL;
965+
}
966+
962967
static int cpufreq_init_policy(struct cpufreq_policy *policy)
963968
{
964969
struct cpufreq_governor *gov = NULL;
@@ -968,11 +973,14 @@ static int cpufreq_init_policy(struct cpufreq_policy *policy)
968973

969974
/* Update governor of new_policy to the governor used before hotplug */
970975
gov = find_governor(policy->last_governor);
971-
if (gov)
976+
if (gov) {
972977
pr_debug("Restoring governor %s for cpu %d\n",
973978
policy->governor->name, policy->cpu);
974-
else
975-
gov = CPUFREQ_DEFAULT_GOVERNOR;
979+
} else {
980+
gov = cpufreq_default_governor();
981+
if (!gov)
982+
return -ENODATA;
983+
}
976984

977985
new_policy.governor = gov;
978986

@@ -1920,21 +1928,16 @@ int cpufreq_driver_target(struct cpufreq_policy *policy,
19201928
}
19211929
EXPORT_SYMBOL_GPL(cpufreq_driver_target);
19221930

1931+
__weak struct cpufreq_governor *cpufreq_fallback_governor(void)
1932+
{
1933+
return NULL;
1934+
}
1935+
19231936
static int __cpufreq_governor(struct cpufreq_policy *policy,
19241937
unsigned int event)
19251938
{
19261939
int ret;
19271940

1928-
/* Only must be defined when default governor is known to have latency
1929-
restrictions, like e.g. conservative or ondemand.
1930-
That this is the case is already ensured in Kconfig
1931-
*/
1932-
#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE
1933-
struct cpufreq_governor *gov = &cpufreq_gov_performance;
1934-
#else
1935-
struct cpufreq_governor *gov = NULL;
1936-
#endif
1937-
19381941
/* Don't start any governor operations if we are entering suspend */
19391942
if (cpufreq_suspended)
19401943
return 0;
@@ -1948,12 +1951,14 @@ static int __cpufreq_governor(struct cpufreq_policy *policy,
19481951
if (policy->governor->max_transition_latency &&
19491952
policy->cpuinfo.transition_latency >
19501953
policy->governor->max_transition_latency) {
1951-
if (!gov)
1952-
return -EINVAL;
1953-
else {
1954+
struct cpufreq_governor *gov = cpufreq_fallback_governor();
1955+
1956+
if (gov) {
19541957
pr_warn("%s governor failed, too long transition latency of HW, fallback to %s governor\n",
19551958
policy->governor->name, gov->name);
19561959
policy->governor = gov;
1960+
} else {
1961+
return -EINVAL;
19571962
}
19581963
}
19591964

drivers/cpufreq/cpufreq_conservative.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ static DEFINE_PER_CPU(struct cs_cpu_dbs_info_s, cs_cpu_dbs_info);
2626
static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy,
2727
unsigned int event);
2828

29-
#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE
30-
static
31-
#endif
32-
struct cpufreq_governor cpufreq_gov_conservative = {
29+
static struct cpufreq_governor cpufreq_gov_conservative = {
3330
.name = "conservative",
3431
.governor = cs_cpufreq_governor_dbs,
3532
.max_transition_latency = TRANSITION_LATENCY_LIMIT,
@@ -399,6 +396,11 @@ MODULE_DESCRIPTION("'cpufreq_conservative' - A dynamic cpufreq governor for "
399396
MODULE_LICENSE("GPL");
400397

401398
#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE
399+
struct cpufreq_governor *cpufreq_default_governor(void)
400+
{
401+
return &cpufreq_gov_conservative;
402+
}
403+
402404
fs_initcall(cpufreq_gov_dbs_init);
403405
#else
404406
module_init(cpufreq_gov_dbs_init);

drivers/cpufreq/cpufreq_ondemand.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ static DEFINE_PER_CPU(struct od_cpu_dbs_info_s, od_cpu_dbs_info);
3131

3232
static struct od_ops od_ops;
3333

34-
#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND
3534
static struct cpufreq_governor cpufreq_gov_ondemand;
36-
#endif
3735

3836
static unsigned int default_powersave_bias;
3937

@@ -554,6 +552,19 @@ static struct common_dbs_data od_dbs_cdata = {
554552
.mutex = __MUTEX_INITIALIZER(od_dbs_cdata.mutex),
555553
};
556554

555+
static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
556+
unsigned int event)
557+
{
558+
return cpufreq_governor_dbs(policy, &od_dbs_cdata, event);
559+
}
560+
561+
static struct cpufreq_governor cpufreq_gov_ondemand = {
562+
.name = "ondemand",
563+
.governor = od_cpufreq_governor_dbs,
564+
.max_transition_latency = TRANSITION_LATENCY_LIMIT,
565+
.owner = THIS_MODULE,
566+
};
567+
557568
static void od_set_powersave_bias(unsigned int powersave_bias)
558569
{
559570
struct cpufreq_policy *policy;
@@ -605,22 +616,6 @@ void od_unregister_powersave_bias_handler(void)
605616
}
606617
EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
607618

608-
static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
609-
unsigned int event)
610-
{
611-
return cpufreq_governor_dbs(policy, &od_dbs_cdata, event);
612-
}
613-
614-
#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND
615-
static
616-
#endif
617-
struct cpufreq_governor cpufreq_gov_ondemand = {
618-
.name = "ondemand",
619-
.governor = od_cpufreq_governor_dbs,
620-
.max_transition_latency = TRANSITION_LATENCY_LIMIT,
621-
.owner = THIS_MODULE,
622-
};
623-
624619
static int __init cpufreq_gov_dbs_init(void)
625620
{
626621
return cpufreq_register_governor(&cpufreq_gov_ondemand);
@@ -638,6 +633,11 @@ MODULE_DESCRIPTION("'cpufreq_ondemand' - A dynamic cpufreq governor for "
638633
MODULE_LICENSE("GPL");
639634

640635
#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND
636+
struct cpufreq_governor *cpufreq_default_governor(void)
637+
{
638+
return &cpufreq_gov_ondemand;
639+
}
640+
641641
fs_initcall(cpufreq_gov_dbs_init);
642642
#else
643643
module_init(cpufreq_gov_dbs_init);

drivers/cpufreq/cpufreq_performance.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ static int cpufreq_governor_performance(struct cpufreq_policy *policy,
3333
return 0;
3434
}
3535

36-
#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE_MODULE
37-
static
38-
#endif
39-
struct cpufreq_governor cpufreq_gov_performance = {
36+
static struct cpufreq_governor cpufreq_gov_performance = {
4037
.name = "performance",
4138
.governor = cpufreq_governor_performance,
4239
.owner = THIS_MODULE,
@@ -52,6 +49,19 @@ static void __exit cpufreq_gov_performance_exit(void)
5249
cpufreq_unregister_governor(&cpufreq_gov_performance);
5350
}
5451

52+
#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
53+
struct cpufreq_governor *cpufreq_default_governor(void)
54+
{
55+
return &cpufreq_gov_performance;
56+
}
57+
#endif
58+
#ifndef CONFIG_CPU_FREQ_GOV_PERFORMANCE_MODULE
59+
struct cpufreq_governor *cpufreq_fallback_governor(void)
60+
{
61+
return &cpufreq_gov_performance;
62+
}
63+
#endif
64+
5565
MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>");
5666
MODULE_DESCRIPTION("CPUfreq policy governor 'performance'");
5767
MODULE_LICENSE("GPL");

drivers/cpufreq/cpufreq_powersave.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ static int cpufreq_governor_powersave(struct cpufreq_policy *policy,
3333
return 0;
3434
}
3535

36-
#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE
37-
static
38-
#endif
39-
struct cpufreq_governor cpufreq_gov_powersave = {
36+
static struct cpufreq_governor cpufreq_gov_powersave = {
4037
.name = "powersave",
4138
.governor = cpufreq_governor_powersave,
4239
.owner = THIS_MODULE,
@@ -57,6 +54,11 @@ MODULE_DESCRIPTION("CPUfreq policy governor 'powersave'");
5754
MODULE_LICENSE("GPL");
5855

5956
#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE
57+
struct cpufreq_governor *cpufreq_default_governor(void)
58+
{
59+
return &cpufreq_gov_powersave;
60+
}
61+
6062
fs_initcall(cpufreq_gov_powersave_init);
6163
#else
6264
module_init(cpufreq_gov_powersave_init);

drivers/cpufreq/cpufreq_userspace.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,7 @@ static int cpufreq_governor_userspace(struct cpufreq_policy *policy,
8989
return rc;
9090
}
9191

92-
#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE
93-
static
94-
#endif
95-
struct cpufreq_governor cpufreq_gov_userspace = {
92+
static struct cpufreq_governor cpufreq_gov_userspace = {
9693
.name = "userspace",
9794
.governor = cpufreq_governor_userspace,
9895
.store_setspeed = cpufreq_set,
@@ -116,6 +113,11 @@ MODULE_DESCRIPTION("CPUfreq policy governor 'userspace'");
116113
MODULE_LICENSE("GPL");
117114

118115
#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE
116+
struct cpufreq_governor *cpufreq_default_governor(void)
117+
{
118+
return &cpufreq_gov_userspace;
119+
}
120+
119121
fs_initcall(cpufreq_gov_userspace_init);
120122
#else
121123
module_init(cpufreq_gov_userspace_init);

include/linux/cpufreq.h

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -464,29 +464,8 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
464464
int cpufreq_register_governor(struct cpufreq_governor *governor);
465465
void cpufreq_unregister_governor(struct cpufreq_governor *governor);
466466

467-
/* CPUFREQ DEFAULT GOVERNOR */
468-
/*
469-
* Performance governor is fallback governor if any other gov failed to auto
470-
* load due latency restrictions
471-
*/
472-
#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE
473-
extern struct cpufreq_governor cpufreq_gov_performance;
474-
#endif
475-
#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
476-
#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_performance)
477-
#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE)
478-
extern struct cpufreq_governor cpufreq_gov_powersave;
479-
#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_powersave)
480-
#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE)
481-
extern struct cpufreq_governor cpufreq_gov_userspace;
482-
#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_userspace)
483-
#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND)
484-
extern struct cpufreq_governor cpufreq_gov_ondemand;
485-
#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_ondemand)
486-
#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE)
487-
extern struct cpufreq_governor cpufreq_gov_conservative;
488-
#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_conservative)
489-
#endif
467+
struct cpufreq_governor *cpufreq_default_governor(void);
468+
struct cpufreq_governor *cpufreq_fallback_governor(void);
490469

491470
/*********************************************************************
492471
* FREQUENCY TABLE HELPERS *

0 commit comments

Comments
 (0)