thermal/drivers/core: Use governor table to initialize
authorDaniel Lezcano <daniel.lezcano@linaro.org>
Wed, 12 Jun 2019 20:13:25 +0000 (22:13 +0200)
committerZhang Rui <rui.zhang@intel.com>
Thu, 27 Jun 2019 13:22:14 +0000 (21:22 +0800)
Now that the governor table is in place and the macro allows to browse the
table, declare the governor so the entry is added in the governor table
in the init section.

The [un]register_thermal_governors function does no longer need to use the
exported [un]register thermal governor's specific function which in turn
call the [un]register_thermal_governor. The governors are fully
self-encapsulated.

The cyclic dependency is no longer needed, remove it.

Reviewed-by: Amit Kucheria <amit.kucheria@linaro.org>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
drivers/thermal/fair_share.c
drivers/thermal/gov_bang_bang.c
drivers/thermal/power_allocator.c
drivers/thermal/step_wise.c
drivers/thermal/thermal_core.c
drivers/thermal/thermal_core.h
drivers/thermal/user_space.c

index 8ff109fb77e1d092ac14b8b36336aa57a3c4be5b..afd99f668c65d51190547682a30c80b83c38119e 100644 (file)
@@ -117,14 +117,4 @@ static struct thermal_governor thermal_gov_fair_share = {
        .name           = "fair_share",
        .throttle       = fair_share_throttle,
 };
-
-int thermal_gov_fair_share_register(void)
-{
-       return thermal_register_governor(&thermal_gov_fair_share);
-}
-
-void thermal_gov_fair_share_unregister(void)
-{
-       thermal_unregister_governor(&thermal_gov_fair_share);
-}
-
+THERMAL_GOVERNOR_DECLARE(thermal_gov_fair_share);
index 632fb925e9754569cf707b2bc90a61c052ad2361..e0575d29023aab18ea1be6e2f4664d13a6da62ef 100644 (file)
@@ -116,13 +116,4 @@ static struct thermal_governor thermal_gov_bang_bang = {
        .name           = "bang_bang",
        .throttle       = bang_bang_control,
 };
-
-int thermal_gov_bang_bang_register(void)
-{
-       return thermal_register_governor(&thermal_gov_bang_bang);
-}
-
-void thermal_gov_bang_bang_unregister(void)
-{
-       thermal_unregister_governor(&thermal_gov_bang_bang);
-}
+THERMAL_GOVERNOR_DECLARE(thermal_gov_bang_bang);
index 3055f9a12a17087cfee105400b2cca3e68cbb166..44636475b2a348e115a9027a29d77a45f35fc91b 100644 (file)
@@ -651,13 +651,4 @@ static struct thermal_governor thermal_gov_power_allocator = {
        .unbind_from_tz = power_allocator_unbind,
        .throttle       = power_allocator_throttle,
 };
-
-int thermal_gov_power_allocator_register(void)
-{
-       return thermal_register_governor(&thermal_gov_power_allocator);
-}
-
-void thermal_gov_power_allocator_unregister(void)
-{
-       thermal_unregister_governor(&thermal_gov_power_allocator);
-}
+THERMAL_GOVERNOR_DECLARE(thermal_gov_power_allocator);
index 81a183befd48a32d92cb6e03521b239a0d6f50f2..6e051cbd824ffe3e4fa056ae34c48deff3f5f97a 100644 (file)
@@ -206,13 +206,4 @@ static struct thermal_governor thermal_gov_step_wise = {
        .name           = "step_wise",
        .throttle       = step_wise_throttle,
 };
-
-int thermal_gov_step_wise_register(void)
-{
-       return thermal_register_governor(&thermal_gov_step_wise);
-}
-
-void thermal_gov_step_wise_unregister(void)
-{
-       thermal_unregister_governor(&thermal_gov_step_wise);
-}
+THERMAL_GOVERNOR_DECLARE(thermal_gov_step_wise);
index 46cfb7de4eb289d7b81db525178a5dd5ef6656d4..6bab66e84eb58c6fc86d1528bf5ffdfa4a1dfc4b 100644 (file)
@@ -243,36 +243,42 @@ int thermal_build_list_of_policies(char *buf)
        return count;
 }
 
-static int __init thermal_register_governors(void)
+static void __init thermal_unregister_governors(void)
 {
-       int result;
+       struct thermal_governor **governor;
 
-       result = thermal_gov_step_wise_register();
-       if (result)
-               return result;
+       for_each_governor_table(governor)
+               thermal_unregister_governor(*governor);
+}
 
-       result = thermal_gov_fair_share_register();
-       if (result)
-               return result;
+static int __init thermal_register_governors(void)
+{
+       int ret = 0;
+       struct thermal_governor **governor;
 
-       result = thermal_gov_bang_bang_register();
-       if (result)
-               return result;
+       for_each_governor_table(governor) {
+               ret = thermal_register_governor(*governor);
+               if (ret) {
+                       pr_err("Failed to register governor: '%s'",
+                              (*governor)->name);
+                       break;
+               }
 
-       result = thermal_gov_user_space_register();
-       if (result)
-               return result;
+               pr_info("Registered thermal governor '%s'",
+                       (*governor)->name);
+       }
 
-       return thermal_gov_power_allocator_register();
-}
+       if (ret) {
+               struct thermal_governor **gov;
 
-static void __init thermal_unregister_governors(void)
-{
-       thermal_gov_step_wise_unregister();
-       thermal_gov_fair_share_unregister();
-       thermal_gov_bang_bang_unregister();
-       thermal_gov_user_space_unregister();
-       thermal_gov_power_allocator_unregister();
+               for_each_governor_table(gov) {
+                       if (gov == governor)
+                               break;
+                       thermal_unregister_governor(*gov);
+               }
+       }
+
+       return ret;
 }
 
 /*
index 06778cec8416d3c0b3613e2c7ef182b3b179dec7..207b0cda70da75483f374b368a3bc1edb244e93c 100644 (file)
@@ -89,46 +89,6 @@ thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,
                                    unsigned long new_state) {}
 #endif /* CONFIG_THERMAL_STATISTICS */
 
-#ifdef CONFIG_THERMAL_GOV_STEP_WISE
-int thermal_gov_step_wise_register(void);
-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 /* CONFIG_THERMAL_GOV_STEP_WISE */
-
-#ifdef CONFIG_THERMAL_GOV_FAIR_SHARE
-int thermal_gov_fair_share_register(void);
-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 /* CONFIG_THERMAL_GOV_FAIR_SHARE */
-
-#ifdef CONFIG_THERMAL_GOV_BANG_BANG
-int thermal_gov_bang_bang_register(void);
-void thermal_gov_bang_bang_unregister(void);
-#else
-static inline int thermal_gov_bang_bang_register(void) { return 0; }
-static inline void thermal_gov_bang_bang_unregister(void) {}
-#endif /* CONFIG_THERMAL_GOV_BANG_BANG */
-
-#ifdef CONFIG_THERMAL_GOV_USER_SPACE
-int thermal_gov_user_space_register(void);
-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 /* CONFIG_THERMAL_GOV_USER_SPACE */
-
-#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR
-int thermal_gov_power_allocator_register(void);
-void thermal_gov_power_allocator_unregister(void);
-#else
-static inline int thermal_gov_power_allocator_register(void) { return 0; }
-static inline void thermal_gov_power_allocator_unregister(void) {}
-#endif /* CONFIG_THERMAL_GOV_POWER_ALLOCATOR */
-
 /* device tree support */
 #ifdef CONFIG_THERMAL_OF
 int of_parse_thermal_zones(void);
index d62a99fc60a6f6132231af3893ed86e32f35f536..962873fd92425e8daf7287b57b3b93c31a4aa1ca 100644 (file)
@@ -44,14 +44,4 @@ static struct thermal_governor thermal_gov_user_space = {
        .name           = "user_space",
        .throttle       = notify_user_space,
 };
-
-int thermal_gov_user_space_register(void)
-{
-       return thermal_register_governor(&thermal_gov_user_space);
-}
-
-void thermal_gov_user_space_unregister(void)
-{
-       thermal_unregister_governor(&thermal_gov_user_space);
-}
-
+THERMAL_GOVERNOR_DECLARE(thermal_gov_user_space);