From 63ece0343a2e56b7718e250114b638c6010e645f Mon Sep 17 00:00:00 2001 From: Zhang Rui Date: Mon, 18 Feb 2013 10:33:21 +0800 Subject: [PATCH 2/2] Thermal: build thermal governors into thermal_sys module The generic thermal layer must run with thermal governors loaded, thus we build thermal governors into thermal_sys module instead of seperate modules. Signed-off-by: Zhang Rui --- drivers/thermal/Makefile | 7 ++++--- drivers/thermal/fair_share.c | 14 +++----------- drivers/thermal/step_wise.c | 13 ++----------- drivers/thermal/thermal_core.c | 42 +++++++++++++++++++++++++++++++++------- drivers/thermal/thermal_core.h | 27 ++++++++++++++++++++++++++ drivers/thermal/user_space.c | 13 ++----------- include/linux/thermal.h | 1 - 7 files changed, 73 insertions(+), 44 deletions(-) diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile index d8da683..37a6860 100644 --- a/drivers/thermal/Makefile +++ b/drivers/thermal/Makefile @@ -4,10 +4,11 @@ obj-$(CONFIG_THERMAL) += thermal_sys.o +thermal_sys-y := thermal_core.o # governors -obj-$(CONFIG_FAIR_SHARE) += fair_share.o -obj-$(CONFIG_STEP_WISE) += step_wise.o -obj-$(CONFIG_USER_SPACE) += user_space.o +thermal_sys-$(CONFIG_STEP_WISE) += step_wise.o +thermal_sys-$(CONFIG_FAIR_SHARE) += fair_share.o +thermal_sys-$(CONFIG_USER_SPACE) += user_space.o # cpufreq cooling obj-$(CONFIG_CPU_THERMAL) += cpu_cooling.o diff --git a/drivers/thermal/fair_share.c b/drivers/thermal/fair_share.c index 792479f..32018b7 100644 --- a/drivers/thermal/fair_share.c +++ b/drivers/thermal/fair_share.c @@ -111,23 +111,15 @@ static int fair_share_throttle(struct thermal_zone_device *tz, int trip) static struct thermal_governor thermal_gov_fair_share = { .name = "fair_share", .throttle = fair_share_throttle, - .owner = THIS_MODULE, }; -static int __init thermal_gov_fair_share_init(void) +int __init thermal_gov_fair_share_register(void) { + printk("thermal_gov_fair_share_init\n"); return thermal_register_governor(&thermal_gov_fair_share); } -static void __exit thermal_gov_fair_share_exit(void) +void __exit thermal_gov_fair_share_unregister(void) { thermal_unregister_governor(&thermal_gov_fair_share); } - -/* This should load after thermal framework */ -fs_initcall(thermal_gov_fair_share_init); -module_exit(thermal_gov_fair_share_exit); - -MODULE_AUTHOR("Durgadoss R"); -MODULE_DESCRIPTION("A simple weight based thermal throttling governor"); -MODULE_LICENSE("GPL"); diff --git a/drivers/thermal/step_wise.c b/drivers/thermal/step_wise.c index 0cd5e9f..0e18fa3 100644 --- a/drivers/thermal/step_wise.c +++ b/drivers/thermal/step_wise.c @@ -172,23 +172,14 @@ static int step_wise_throttle(struct thermal_zone_device *tz, int trip) static struct thermal_governor thermal_gov_step_wise = { .name = "step_wise", .throttle = step_wise_throttle, - .owner = THIS_MODULE, }; -static int __init thermal_gov_step_wise_init(void) +int __init thermal_gov_step_wise_register(void) { return thermal_register_governor(&thermal_gov_step_wise); } -static void __exit thermal_gov_step_wise_exit(void) +void __exit thermal_gov_step_wise_unregister(void) { thermal_unregister_governor(&thermal_gov_step_wise); } - -/* This should load after thermal framework */ -fs_initcall(thermal_gov_step_wise_init); -module_exit(thermal_gov_step_wise_exit); - -MODULE_AUTHOR("Durgadoss R"); -MODULE_DESCRIPTION("A step-by-step thermal throttling governor"); -MODULE_LICENSE("GPL"); diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 8c8ce80..90eb4f4 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -61,7 +61,6 @@ static struct thermal_governor *__find_governor(const char *name) list_for_each_entry(pos, &thermal_governor_list, governor_list) if (!strnicmp(name, pos->name, THERMAL_NAME_LENGTH)) return pos; - return NULL; } @@ -1797,23 +1796,52 @@ static inline int genetlink_init(void) { return 0; } static inline void genetlink_exit(void) {} #endif /* !CONFIG_NET */ +static int thermal_register_governors(void) +{ + return (thermal_gov_step_wise_register() & + thermal_gov_fair_share_register() & + thermal_gov_user_space_register()); +} + +static void thermal_unregister_governors(void) +{ + thermal_gov_step_wise_unregister(); + thermal_gov_fair_share_unregister(); + thermal_gov_user_space_unregister(); +} static int __init thermal_init(void) { int result = 0; result = class_register(&thermal_class); - if (result) { - idr_destroy(&thermal_tz_idr); - idr_destroy(&thermal_cdev_idr); - mutex_destroy(&thermal_idr_lock); - mutex_destroy(&thermal_list_lock); - } + if (result) + goto idr_destroy; + + result = thermal_register_governors(); + if (result) + goto class_unregister; + result = genetlink_init(); + if (result) + goto unregister_governors; + + return result; + +unregister_governors: + thermal_unregister_governors(); +class_unregister: + class_unregister(&thermal_class); +idr_destroy: + idr_destroy(&thermal_tz_idr); + idr_destroy(&thermal_cdev_idr); + mutex_destroy(&thermal_idr_lock); + mutex_destroy(&thermal_list_lock); return result; } static void __exit thermal_exit(void) { + thermal_unregister_governors(); class_unregister(&thermal_class); idr_destroy(&thermal_tz_idr); idr_destroy(&thermal_cdev_idr); diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h index 0d3205a..42093db 100644 --- a/drivers/thermal/thermal_core.h +++ b/drivers/thermal/thermal_core.h @@ -50,4 +50,31 @@ struct thermal_instance { struct list_head cdev_node; /* node in cdev->thermal_instances */ }; +#ifdef CONFIG_STEP_WISE +extern int thermal_gov_step_wise_register(void); +extern void thermal_gov_step_wise_unregister(void); +#else +static inline int thermal_gov_step_wise_register(void) +{ return 0; } +static inline void thermal_gov_step_wise_unregister(void) {} +#endif + +#ifdef CONFIG_FAIR_SHARE +extern int thermal_gov_fair_share_register(void); +extern void thermal_gov_fair_share_unregister(void); +#else +static inline int thermal_gov_fair_share_register(void) +{ return 0; } +static inline void thermal_gov_fair_share_unregister(void) {} +#endif + +#ifdef CONFIG_USER_SPACE +extern int thermal_gov_user_space_register(void); +extern void thermal_gov_user_space_unregister(void); +#else +static inline int thermal_gov_user_space_register(void) +{ return 0; } +static inline void thermal_gov_user_space_unregister(void) {} +#endif + #endif /* __THERMAL_CORE_H__ */ diff --git a/drivers/thermal/user_space.c b/drivers/thermal/user_space.c index 6bbb380..6bf755f 100644 --- a/drivers/thermal/user_space.c +++ b/drivers/thermal/user_space.c @@ -46,23 +46,14 @@ static int notify_user_space(struct thermal_zone_device *tz, int trip) static struct thermal_governor thermal_gov_user_space = { .name = "user_space", .throttle = notify_user_space, - .owner = THIS_MODULE, }; -static int __init thermal_gov_user_space_init(void) +int __init thermal_gov_user_space_register(void) { return thermal_register_governor(&thermal_gov_user_space); } -static void __exit thermal_gov_user_space_exit(void) +void __exit thermal_gov_user_space_unregister(void) { thermal_unregister_governor(&thermal_gov_user_space); } - -/* This should load after thermal framework */ -fs_initcall(thermal_gov_user_space_init); -module_exit(thermal_gov_user_space_exit); - -MODULE_AUTHOR("Durgadoss R"); -MODULE_DESCRIPTION("A user space Thermal notifier"); -MODULE_LICENSE("GPL"); diff --git a/include/linux/thermal.h b/include/linux/thermal.h index fe82022..1438b7e 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -180,7 +180,6 @@ struct thermal_governor { char name[THERMAL_NAME_LENGTH]; int (*throttle)(struct thermal_zone_device *tz, int trip); struct list_head governor_list; - struct module *owner; }; /* Structure that holds binding parameters for a zone */ -- 1.7.10.4