Skip to content

Commit 10dd857

Browse files
Quentin Perretrafaeljw
authored andcommitted
cpufreq: Register governors at core_initcall
Currently, most CPUFreq governors are registered at the core_initcall time when the given governor is the default one, and the module_init time otherwise. In preparation for letting users specify the default governor on the kernel command line, change all of them to be registered at the core_initcall unconditionally, as it is already the case for the schedutil and performance governors. This will allow us to assume that builtin governors have been registered before the built-in CPUFreq drivers probe. And since all governors have similar init/exit patterns now, introduce two new macros, cpufreq_governor_{init,exit}(), to factorize the code. Acked-by: Viresh Kumar <[email protected]> Signed-off-by: Quentin Perret <[email protected]> Signed-off-by: Viresh Kumar <[email protected]> [ rjw: Changelog ] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 8cc46ae commit 10dd857

File tree

8 files changed

+36
-106
lines changed

8 files changed

+36
-106
lines changed

arch/powerpc/platforms/cell/cpufreq_spudemand.c

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -126,30 +126,8 @@ static struct cpufreq_governor spu_governor = {
126126
.stop = spu_gov_stop,
127127
.owner = THIS_MODULE,
128128
};
129-
130-
/*
131-
* module init and destoy
132-
*/
133-
134-
static int __init spu_gov_init(void)
135-
{
136-
int ret;
137-
138-
ret = cpufreq_register_governor(&spu_governor);
139-
if (ret)
140-
printk(KERN_ERR "registration of governor failed\n");
141-
return ret;
142-
}
143-
144-
static void __exit spu_gov_exit(void)
145-
{
146-
cpufreq_unregister_governor(&spu_governor);
147-
}
148-
149-
150-
module_init(spu_gov_init);
151-
module_exit(spu_gov_exit);
129+
cpufreq_governor_init(spu_governor);
130+
cpufreq_governor_exit(spu_governor);
152131

153132
MODULE_LICENSE("GPL");
154133
MODULE_AUTHOR("Christian Krafft <[email protected]>");
155-

drivers/cpufreq/cpufreq_conservative.c

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -322,17 +322,7 @@ static struct dbs_governor cs_governor = {
322322
.start = cs_start,
323323
};
324324

325-
#define CPU_FREQ_GOV_CONSERVATIVE (&cs_governor.gov)
326-
327-
static int __init cpufreq_gov_dbs_init(void)
328-
{
329-
return cpufreq_register_governor(CPU_FREQ_GOV_CONSERVATIVE);
330-
}
331-
332-
static void __exit cpufreq_gov_dbs_exit(void)
333-
{
334-
cpufreq_unregister_governor(CPU_FREQ_GOV_CONSERVATIVE);
335-
}
325+
#define CPU_FREQ_GOV_CONSERVATIVE (cs_governor.gov)
336326

337327
MODULE_AUTHOR("Alexander Clouter <[email protected]>");
338328
MODULE_DESCRIPTION("'cpufreq_conservative' - A dynamic cpufreq governor for "
@@ -343,11 +333,9 @@ MODULE_LICENSE("GPL");
343333
#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE
344334
struct cpufreq_governor *cpufreq_default_governor(void)
345335
{
346-
return CPU_FREQ_GOV_CONSERVATIVE;
336+
return &CPU_FREQ_GOV_CONSERVATIVE;
347337
}
348-
349-
core_initcall(cpufreq_gov_dbs_init);
350-
#else
351-
module_init(cpufreq_gov_dbs_init);
352338
#endif
353-
module_exit(cpufreq_gov_dbs_exit);
339+
340+
cpufreq_governor_init(CPU_FREQ_GOV_CONSERVATIVE);
341+
cpufreq_governor_exit(CPU_FREQ_GOV_CONSERVATIVE);

drivers/cpufreq/cpufreq_ondemand.c

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ static struct dbs_governor od_dbs_gov = {
408408
.start = od_start,
409409
};
410410

411-
#define CPU_FREQ_GOV_ONDEMAND (&od_dbs_gov.gov)
411+
#define CPU_FREQ_GOV_ONDEMAND (od_dbs_gov.gov)
412412

413413
static void od_set_powersave_bias(unsigned int powersave_bias)
414414
{
@@ -429,7 +429,7 @@ static void od_set_powersave_bias(unsigned int powersave_bias)
429429
continue;
430430

431431
policy = cpufreq_cpu_get_raw(cpu);
432-
if (!policy || policy->governor != CPU_FREQ_GOV_ONDEMAND)
432+
if (!policy || policy->governor != &CPU_FREQ_GOV_ONDEMAND)
433433
continue;
434434

435435
policy_dbs = policy->governor_data;
@@ -461,16 +461,6 @@ void od_unregister_powersave_bias_handler(void)
461461
}
462462
EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
463463

464-
static int __init cpufreq_gov_dbs_init(void)
465-
{
466-
return cpufreq_register_governor(CPU_FREQ_GOV_ONDEMAND);
467-
}
468-
469-
static void __exit cpufreq_gov_dbs_exit(void)
470-
{
471-
cpufreq_unregister_governor(CPU_FREQ_GOV_ONDEMAND);
472-
}
473-
474464
MODULE_AUTHOR("Venkatesh Pallipadi <[email protected]>");
475465
MODULE_AUTHOR("Alexey Starikovskiy <[email protected]>");
476466
MODULE_DESCRIPTION("'cpufreq_ondemand' - A dynamic cpufreq governor for "
@@ -480,11 +470,9 @@ MODULE_LICENSE("GPL");
480470
#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND
481471
struct cpufreq_governor *cpufreq_default_governor(void)
482472
{
483-
return CPU_FREQ_GOV_ONDEMAND;
473+
return &CPU_FREQ_GOV_ONDEMAND;
484474
}
485-
486-
core_initcall(cpufreq_gov_dbs_init);
487-
#else
488-
module_init(cpufreq_gov_dbs_init);
489475
#endif
490-
module_exit(cpufreq_gov_dbs_exit);
476+
477+
cpufreq_governor_init(CPU_FREQ_GOV_ONDEMAND);
478+
cpufreq_governor_exit(CPU_FREQ_GOV_ONDEMAND);

drivers/cpufreq/cpufreq_performance.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@ static struct cpufreq_governor cpufreq_gov_performance = {
2323
.limits = cpufreq_gov_performance_limits,
2424
};
2525

26-
static int __init cpufreq_gov_performance_init(void)
27-
{
28-
return cpufreq_register_governor(&cpufreq_gov_performance);
29-
}
30-
31-
static void __exit cpufreq_gov_performance_exit(void)
32-
{
33-
cpufreq_unregister_governor(&cpufreq_gov_performance);
34-
}
35-
3626
#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
3727
struct cpufreq_governor *cpufreq_default_governor(void)
3828
{
@@ -50,5 +40,5 @@ MODULE_AUTHOR("Dominik Brodowski <[email protected]>");
5040
MODULE_DESCRIPTION("CPUfreq policy governor 'performance'");
5141
MODULE_LICENSE("GPL");
5242

53-
core_initcall(cpufreq_gov_performance_init);
54-
module_exit(cpufreq_gov_performance_exit);
43+
cpufreq_governor_init(cpufreq_gov_performance);
44+
cpufreq_governor_exit(cpufreq_gov_performance);

drivers/cpufreq/cpufreq_powersave.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@ static struct cpufreq_governor cpufreq_gov_powersave = {
2323
.owner = THIS_MODULE,
2424
};
2525

26-
static int __init cpufreq_gov_powersave_init(void)
27-
{
28-
return cpufreq_register_governor(&cpufreq_gov_powersave);
29-
}
30-
31-
static void __exit cpufreq_gov_powersave_exit(void)
32-
{
33-
cpufreq_unregister_governor(&cpufreq_gov_powersave);
34-
}
35-
3626
MODULE_AUTHOR("Dominik Brodowski <[email protected]>");
3727
MODULE_DESCRIPTION("CPUfreq policy governor 'powersave'");
3828
MODULE_LICENSE("GPL");
@@ -42,9 +32,7 @@ struct cpufreq_governor *cpufreq_default_governor(void)
4232
{
4333
return &cpufreq_gov_powersave;
4434
}
45-
46-
core_initcall(cpufreq_gov_powersave_init);
47-
#else
48-
module_init(cpufreq_gov_powersave_init);
4935
#endif
50-
module_exit(cpufreq_gov_powersave_exit);
36+
37+
cpufreq_governor_init(cpufreq_gov_powersave);
38+
cpufreq_governor_exit(cpufreq_gov_powersave);

drivers/cpufreq/cpufreq_userspace.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,6 @@ static struct cpufreq_governor cpufreq_gov_userspace = {
126126
.owner = THIS_MODULE,
127127
};
128128

129-
static int __init cpufreq_gov_userspace_init(void)
130-
{
131-
return cpufreq_register_governor(&cpufreq_gov_userspace);
132-
}
133-
134-
static void __exit cpufreq_gov_userspace_exit(void)
135-
{
136-
cpufreq_unregister_governor(&cpufreq_gov_userspace);
137-
}
138-
139129
MODULE_AUTHOR("Dominik Brodowski <[email protected]>, "
140130
"Russell King <[email protected]>");
141131
MODULE_DESCRIPTION("CPUfreq policy governor 'userspace'");
@@ -146,9 +136,7 @@ struct cpufreq_governor *cpufreq_default_governor(void)
146136
{
147137
return &cpufreq_gov_userspace;
148138
}
149-
150-
core_initcall(cpufreq_gov_userspace_init);
151-
#else
152-
module_init(cpufreq_gov_userspace_init);
153139
#endif
154-
module_exit(cpufreq_gov_userspace_exit);
140+
141+
cpufreq_governor_init(cpufreq_gov_userspace);
142+
cpufreq_governor_exit(cpufreq_gov_userspace);

include/linux/cpufreq.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,20 @@ unsigned int cpufreq_policy_transition_delay_us(struct cpufreq_policy *policy);
577577
int cpufreq_register_governor(struct cpufreq_governor *governor);
578578
void cpufreq_unregister_governor(struct cpufreq_governor *governor);
579579

580+
#define cpufreq_governor_init(__governor) \
581+
static int __init __governor##_init(void) \
582+
{ \
583+
return cpufreq_register_governor(&__governor); \
584+
} \
585+
core_initcall(__governor##_init)
586+
587+
#define cpufreq_governor_exit(__governor) \
588+
static void __exit __governor##_exit(void) \
589+
{ \
590+
return cpufreq_unregister_governor(&__governor); \
591+
} \
592+
module_exit(__governor##_exit)
593+
580594
struct cpufreq_governor *cpufreq_default_governor(void);
581595
struct cpufreq_governor *cpufreq_fallback_governor(void);
582596

kernel/sched/cpufreq_schedutil.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -909,11 +909,7 @@ struct cpufreq_governor *cpufreq_default_governor(void)
909909
}
910910
#endif
911911

912-
static int __init sugov_register(void)
913-
{
914-
return cpufreq_register_governor(&schedutil_gov);
915-
}
916-
core_initcall(sugov_register);
912+
cpufreq_governor_init(schedutil_gov);
917913

918914
#ifdef CONFIG_ENERGY_MODEL
919915
extern bool sched_energy_update;

0 commit comments

Comments
 (0)