Commit 80a26a5c22b90a82b8696cb72c1d09d525ada53e

Authored by Zhang Rui
1 parent 5fc024ab47

Thermal: build thermal governors into thermal_sys module

The thermal governors are part of the thermal framework,
rather than a seperate feature/module.
Because the generic thermal layer can not work without
thermal governors, and it must load the thermal governors
during its initialization.

Build them into one module in this patch.

This also fix a problem that the generic thermal layer does not
work when CONFIG_THERMAL=m and CONFIG_THERMAL_GOV_XXX=y.

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Acked-by: Eduardo Valentin <eduardo.valentin@ti.com>
Acked-by: Durgadoss R <durgadoss.r@intel.com>

Showing 8 changed files with 84 additions and 66 deletions Side-by-side Diff

Documentation/thermal/sysfs-api.txt
... ... @@ -379,12 +379,4 @@
379 379 This function serves as an arbitrator to set the state of a cooling
380 380 device. It sets the cooling device to the deepest cooling state if
381 381 possible.
382   -
383   -5.5:thermal_register_governor:
384   -This function lets the various thermal governors to register themselves
385   -with the Thermal framework. At run time, depending on a zone's platform
386   -data, a particular governor is used for throttling.
387   -
388   -5.6:thermal_unregister_governor:
389   -This function unregisters a governor from the thermal framework.
drivers/thermal/Makefile
... ... @@ -6,9 +6,9 @@
6 6 thermal_sys-y += thermal_core.o
7 7  
8 8 # governors
9   -obj-$(CONFIG_THERMAL_GOV_FAIR_SHARE) += fair_share.o
10   -obj-$(CONFIG_THERMAL_GOV_STEP_WISE) += step_wise.o
11   -obj-$(CONFIG_THERMAL_GOV_USER_SPACE) += user_space.o
  9 +thermal_sys-$(CONFIG_THERMAL_GOV_FAIR_SHARE) += fair_share.o
  10 +thermal_sys-$(CONFIG_THERMAL_GOV_STEP_WISE) += step_wise.o
  11 +thermal_sys-$(CONFIG_THERMAL_GOV_USER_SPACE) += user_space.o
12 12  
13 13 # cpufreq cooling
14 14 obj-$(CONFIG_CPU_THERMAL) += cpu_cooling.o
drivers/thermal/fair_share.c
... ... @@ -22,9 +22,6 @@
22 22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 23 */
24 24  
25   -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26   -
27   -#include <linux/module.h>
28 25 #include <linux/thermal.h>
29 26  
30 27 #include "thermal_core.h"
31 28  
32 29  
33 30  
... ... @@ -111,24 +108,15 @@
111 108 static struct thermal_governor thermal_gov_fair_share = {
112 109 .name = "fair_share",
113 110 .throttle = fair_share_throttle,
114   - .owner = THIS_MODULE,
115 111 };
116 112  
117   -static int __init thermal_gov_fair_share_init(void)
  113 +int thermal_gov_fair_share_register(void)
118 114 {
119 115 return thermal_register_governor(&thermal_gov_fair_share);
120 116 }
121 117  
122   -static void __exit thermal_gov_fair_share_exit(void)
  118 +void thermal_gov_fair_share_unregister(void)
123 119 {
124 120 thermal_unregister_governor(&thermal_gov_fair_share);
125 121 }
126   -
127   -/* This should load after thermal framework */
128   -fs_initcall(thermal_gov_fair_share_init);
129   -module_exit(thermal_gov_fair_share_exit);
130   -
131   -MODULE_AUTHOR("Durgadoss R");
132   -MODULE_DESCRIPTION("A simple weight based thermal throttling governor");
133   -MODULE_LICENSE("GPL");
drivers/thermal/step_wise.c
... ... @@ -22,9 +22,6 @@
22 22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 23 */
24 24  
25   -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26   -
27   -#include <linux/module.h>
28 25 #include <linux/thermal.h>
29 26  
30 27 #include "thermal_core.h"
31 28  
32 29  
33 30  
... ... @@ -186,24 +183,15 @@
186 183 static struct thermal_governor thermal_gov_step_wise = {
187 184 .name = "step_wise",
188 185 .throttle = step_wise_throttle,
189   - .owner = THIS_MODULE,
190 186 };
191 187  
192   -static int __init thermal_gov_step_wise_init(void)
  188 +int thermal_gov_step_wise_register(void)
193 189 {
194 190 return thermal_register_governor(&thermal_gov_step_wise);
195 191 }
196 192  
197   -static void __exit thermal_gov_step_wise_exit(void)
  193 +void thermal_gov_step_wise_unregister(void)
198 194 {
199 195 thermal_unregister_governor(&thermal_gov_step_wise);
200 196 }
201   -
202   -/* This should load after thermal framework */
203   -fs_initcall(thermal_gov_step_wise_init);
204   -module_exit(thermal_gov_step_wise_exit);
205   -
206   -MODULE_AUTHOR("Durgadoss R");
207   -MODULE_DESCRIPTION("A step-by-step thermal throttling governor");
208   -MODULE_LICENSE("GPL");
drivers/thermal/thermal_core.c
... ... @@ -99,7 +99,6 @@
99 99  
100 100 return err;
101 101 }
102   -EXPORT_SYMBOL_GPL(thermal_register_governor);
103 102  
104 103 void thermal_unregister_governor(struct thermal_governor *governor)
105 104 {
... ... @@ -127,7 +126,6 @@
127 126 mutex_unlock(&thermal_governor_lock);
128 127 return;
129 128 }
130   -EXPORT_SYMBOL_GPL(thermal_unregister_governor);
131 129  
132 130 static int get_idr(struct idr *idr, struct mutex *lock, int *id)
133 131 {
134 132  
135 133  
136 134  
137 135  
138 136  
139 137  
140 138  
... ... @@ -1858,30 +1856,69 @@
1858 1856 static inline void genetlink_exit(void) {}
1859 1857 #endif /* !CONFIG_NET */
1860 1858  
  1859 +static int __init thermal_register_governors(void)
  1860 +{
  1861 + int result;
  1862 +
  1863 + result = thermal_gov_step_wise_register();
  1864 + if (result)
  1865 + return result;
  1866 +
  1867 + result = thermal_gov_fair_share_register();
  1868 + if (result)
  1869 + return result;
  1870 +
  1871 + return thermal_gov_user_space_register();
  1872 +}
  1873 +
  1874 +static void thermal_unregister_governors(void)
  1875 +{
  1876 + thermal_gov_step_wise_unregister();
  1877 + thermal_gov_fair_share_unregister();
  1878 + thermal_gov_user_space_unregister();
  1879 +}
  1880 +
1861 1881 static int __init thermal_init(void)
1862 1882 {
1863   - int result = 0;
  1883 + int result;
1864 1884  
  1885 + result = thermal_register_governors();
  1886 + if (result)
  1887 + goto error;
  1888 +
1865 1889 result = class_register(&thermal_class);
1866   - if (result) {
1867   - idr_destroy(&thermal_tz_idr);
1868   - idr_destroy(&thermal_cdev_idr);
1869   - mutex_destroy(&thermal_idr_lock);
1870   - mutex_destroy(&thermal_list_lock);
1871   - return result;
1872   - }
  1890 + if (result)
  1891 + goto unregister_governors;
  1892 +
1873 1893 result = genetlink_init();
  1894 + if (result)
  1895 + goto unregister_class;
  1896 +
  1897 + return 0;
  1898 +
  1899 +unregister_governors:
  1900 + thermal_unregister_governors();
  1901 +unregister_class:
  1902 + class_unregister(&thermal_class);
  1903 +error:
  1904 + idr_destroy(&thermal_tz_idr);
  1905 + idr_destroy(&thermal_cdev_idr);
  1906 + mutex_destroy(&thermal_idr_lock);
  1907 + mutex_destroy(&thermal_list_lock);
  1908 + mutex_destroy(&thermal_governor_lock);
1874 1909 return result;
1875 1910 }
1876 1911  
1877 1912 static void __exit thermal_exit(void)
1878 1913 {
  1914 + genetlink_exit();
1879 1915 class_unregister(&thermal_class);
  1916 + thermal_unregister_governors();
1880 1917 idr_destroy(&thermal_tz_idr);
1881 1918 idr_destroy(&thermal_cdev_idr);
1882 1919 mutex_destroy(&thermal_idr_lock);
1883 1920 mutex_destroy(&thermal_list_lock);
1884   - genetlink_exit();
  1921 + mutex_destroy(&thermal_governor_lock);
1885 1922 }
1886 1923  
1887 1924 fs_initcall(thermal_init);
drivers/thermal/thermal_core.h
... ... @@ -50,5 +50,32 @@
50 50 struct list_head cdev_node; /* node in cdev->thermal_instances */
51 51 };
52 52  
  53 +int thermal_register_governor(struct thermal_governor *);
  54 +void thermal_unregister_governor(struct thermal_governor *);
  55 +
  56 +#ifdef CONFIG_THERMAL_GOV_STEP_WISE
  57 +int thermal_gov_step_wise_register(void);
  58 +void thermal_gov_step_wise_unregister(void);
  59 +#else
  60 +static inline int thermal_gov_step_wise_register(void) { return 0; }
  61 +static inline void thermal_gov_step_wise_unregister(void) {}
  62 +#endif /* CONFIG_THERMAL_GOV_STEP_WISE */
  63 +
  64 +#ifdef CONFIG_THERMAL_GOV_FAIR_SHARE
  65 +int thermal_gov_fair_share_register(void);
  66 +void thermal_gov_fair_share_unregister(void);
  67 +#else
  68 +static inline int thermal_gov_fair_share_register(void) { return 0; }
  69 +static inline void thermal_gov_fair_share_unregister(void) {}
  70 +#endif /* CONFIG_THERMAL_GOV_FAIR_SHARE */
  71 +
  72 +#ifdef CONFIG_THERMAL_GOV_USER_SPACE
  73 +int thermal_gov_user_space_register(void);
  74 +void thermal_gov_user_space_unregister(void);
  75 +#else
  76 +static inline int thermal_gov_user_space_register(void) { return 0; }
  77 +static inline void thermal_gov_user_space_unregister(void) {}
  78 +#endif /* CONFIG_THERMAL_GOV_USER_SPACE */
  79 +
53 80 #endif /* __THERMAL_CORE_H__ */
drivers/thermal/user_space.c
... ... @@ -22,9 +22,6 @@
22 22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 23 */
24 24  
25   -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26   -
27   -#include <linux/module.h>
28 25 #include <linux/thermal.h>
29 26  
30 27 #include "thermal_core.h"
31 28  
32 29  
33 30  
... ... @@ -46,24 +43,15 @@
46 43 static struct thermal_governor thermal_gov_user_space = {
47 44 .name = "user_space",
48 45 .throttle = notify_user_space,
49   - .owner = THIS_MODULE,
50 46 };
51 47  
52   -static int __init thermal_gov_user_space_init(void)
  48 +int thermal_gov_user_space_register(void)
53 49 {
54 50 return thermal_register_governor(&thermal_gov_user_space);
55 51 }
56 52  
57   -static void __exit thermal_gov_user_space_exit(void)
  53 +void thermal_gov_user_space_unregister(void)
58 54 {
59 55 thermal_unregister_governor(&thermal_gov_user_space);
60 56 }
61   -
62   -/* This should load after thermal framework */
63   -fs_initcall(thermal_gov_user_space_init);
64   -module_exit(thermal_gov_user_space_exit);
65   -
66   -MODULE_AUTHOR("Durgadoss R");
67   -MODULE_DESCRIPTION("A user space Thermal notifier");
68   -MODULE_LICENSE("GPL");
include/linux/thermal.h
... ... @@ -187,7 +187,6 @@
187 187 char name[THERMAL_NAME_LENGTH];
188 188 int (*throttle)(struct thermal_zone_device *tz, int trip);
189 189 struct list_head governor_list;
190   - struct module *owner;
191 190 };
192 191  
193 192 /* Structure that holds binding parameters for a zone */
... ... @@ -246,9 +245,6 @@
246 245 struct thermal_cooling_device *, int);
247 246 void thermal_cdev_update(struct thermal_cooling_device *);
248 247 void notify_thermal_framework(struct thermal_zone_device *, int);
249   -
250   -int thermal_register_governor(struct thermal_governor *);
251   -void thermal_unregister_governor(struct thermal_governor *);
252 248  
253 249 #ifdef CONFIG_NET
254 250 extern int thermal_generate_netlink_event(struct thermal_zone_device *tz,