pass: pmqos: Separate PMQoS's code from pass-gov.c (cpu hotplug) 01/168801/1
authorChanwoo Choi <cw00.choi@samsung.com>
Mon, 29 Jan 2018 08:16:06 +0000 (17:16 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Wed, 31 Jan 2018 01:16:56 +0000 (10:16 +0900)
PASS supports CPUHP (CPU hotplug manager) and PMQoS features until now.
The pass-gov.c contains the CPU hotplug manager feature and a little
of PMQoS's code. In order to remove the tightly coupled code,
move PMQoS's code from pass-gov.c to pass-pmqos.c.

Change-Id: I2811414fbe99cea04d9f111dc61ec0a2e05cb21c
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
src/pass/pass-gov.c
src/pass/pass-pmqos.c
src/pass/pass-pmqos.h
src/pass/pass.c

index 6601220..adb1966 100644 (file)
@@ -57,45 +57,6 @@ static bool is_enabled(struct pass_policy *policy)
        return true;
 }
 
-/*
- * pass_notifier_pmqos - Callback func of DEVICE_NOTIFIER_PMQOS
- * @data: the scenario name
- * @user_data: the instance of struct pass_resource
- */
-static int pass_notifier_pmqos(void *data, void *user_data)
-{
-       struct pass_resource *res = user_data;
-
-       if (res->policy.state == PASS_ON)
-               pass_notifier_pmqos_func(res, data);
-
-       return 0;
-}
-
-/*
- * pass_notifier_init - Register notifiers and init
- * @res: the instance of struct pass_resource
- */
-static int pass_notifier_init(struct pass_resource *res)
-{
-       /* Register DEVICE_NOTIFIER_PMQOS */
-       return register_notifier(DEVICE_NOTIFIER_PMQOS, pass_notifier_pmqos,
-                       res);
-}
-
-/*
- * pass_notifier_exit - Un-register notifiers and exit
- * @res: the instance of struct pass_resource
- */
-static int pass_notifier_exit(struct pass_resource *res)
-{
-       /* Un-register DEVICE_NOTIFIER_PMQOS */
-       unregister_notifier(DEVICE_NOTIFIER_PMQOS, pass_notifier_pmqos,
-                       res);
-
-       return 0;
-}
-
 /*****************************************************************************
  *                            PASS CPU Hotplug                               *
  ****************************************************************************/
@@ -388,7 +349,6 @@ static void __pass_governor_stop(struct pass_resource *res)
 static int __pass_governor_init(struct pass_resource *res)
 {
        struct pass_policy *policy = &res->policy;
-       int ret;
 
        if (policy->gov_timeout < 0) {
                _E("invalid timeout value [%d]!", policy->gov_timeout);
@@ -398,11 +358,6 @@ static int __pass_governor_init(struct pass_resource *res)
 
        /* Set default PASS state */
        policy->gov_state = PASS_GOV_STOP;
-       ret = pass_notifier_init(res);
-       if (ret < 0) {
-               _E("cannot initialize notifier for the pmqos (%d)\n", ret);
-               return ret;
-       }
 
        if (policy->state == PASS_ON)
                pass_governor_update(res, PASS_GOV_START);
@@ -415,9 +370,6 @@ static int __pass_governor_exit(struct pass_resource *res)
        struct pass_policy *policy = &res->policy;
        int i;
 
-       /* Exit notifier */
-       pass_notifier_exit(res);
-
        /*
         * Stop timer and
         * Restore the frequency and the number of online resources
index 64606f0..f7b7380 100644 (file)
@@ -25,7 +25,6 @@
 #include <pass/config-parser.h>
 
 #include "pass.h"
-#include "pass-gov.h"
 #include "pass-rescon.h"
 
 /****************************************************************************
@@ -45,27 +44,6 @@ static int64_t get_time_ms(void)
        return ((int64_t) now.tv_sec * 1000 + (int64_t) now.tv_usec / 1000);
 }
 
-/*
- * is_pmqos_enabled - Check state of whether to support PM_QOS for scenario
- * @policy: instance of pass_policy structure
- *
- * Return true if the state of PM_QOS is supported
- * Return false if the state of PM_QOS isn't supported
- */
-static bool is_pmqos_enabled(struct pass_policy *policy)
-{
-       if (!policy)
-               return false;
-
-       if (!policy->pmqos.scenarios)
-               return false;
-
-       if (policy->pmqos.state != PASS_ON)
-               return false;
-
-       return true;
-}
-
 static enum pass_state is_pmqos_locked(char *data, char *name)
 {
        char *unlock = NULL;
@@ -96,12 +74,9 @@ static int find_scenario_index(struct pass_pmqos *pmqos, char *name)
        return -EINVAL;
 }
 
-/*
- * pass_notifier_pmqos - Callback function of DEVICE_NOTIFIER_PMQOS notifier
- * @data: the scenario name
- */
-int pass_notifier_pmqos_func(struct pass_resource *res, void *data)
+static int pmqos_notifier_cb(void *data, void *user_data)
 {
+       struct pass_resource *res = user_data;
        struct pass_policy *policy;
        struct pass_conf_data *cdata;
        struct pass_pmqos *pmqos;
@@ -118,7 +93,7 @@ int pass_notifier_pmqos_func(struct pass_resource *res, void *data)
 
        policy = &res->policy;
 
-       if (!is_pmqos_enabled(policy))
+       if (!policy->pmqos.scenarios || policy->pmqos.state != PASS_ON)
                return 0;
 
        cdata = &res->cdata;
@@ -209,3 +184,25 @@ int pass_notifier_pmqos_func(struct pass_resource *res, void *data)
 
        return 0;
 }
+
+int pass_pmqos_init(struct pass_resource *res)
+{
+       int ret;
+
+       /* Register DEVICE_NOTIFIER_PMQOS */
+       ret = register_notifier(DEVICE_NOTIFIER_PMQOS, pmqos_notifier_cb, res);
+       if (ret < 0) {
+               _E("cannot initialize notifier for the pmqos (%d)\n", ret);
+               return ret;
+       }
+
+       return 0;
+}
+
+int pass_pmqos_exit(struct pass_resource *res)
+{
+       /* Un-register DEVICE_NOTIFIER_PMQOS */
+       unregister_notifier(DEVICE_NOTIFIER_PMQOS, pmqos_notifier_cb, res);
+
+       return 0;
+}
index 4505479..5960cbf 100644 (file)
 #ifndef __PASS_PMQOS__
 #define __PASS_PMQOS__
 
-/*
- * pass_notifier_pmqos - Callback function of DEVICE_NOTIFIER_PMQOS notifier
- * @res : the instance of pass_resource
- * @data: the scenario name
- */
-int pass_notifier_pmqos_func(struct pass_resource *res, void *data);
+/* Initialize and exit the Scenario-based PMQoS */
+int pass_pmqos_init(struct pass_resource *res);
+int pass_pmqos_exit(struct pass_resource *res);
 
 #endif /* __PASS_PMQOS__ */
index b5bd8a6..361ff01 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "pass.h"
 #include "pass-parser.h"
+#include "pass-pmqos.h"
 #include "pass-hal.h"
 #include "pass-gov.h"
 
@@ -212,7 +213,18 @@ static int pass_init_resource(struct pass_resource *res)
                return -1;
        }
 
+       ret = pass_pmqos_init(res);
+       if (ret < 0) {
+               _E("cannot initialize PASS PMQoS");
+               goto err;
+       }
+
        return 0;
+err:
+       if (pass_governor_exit(res) < 0)
+               _E("cannot exit PASS governor");
+
+       return ret;
 }
 
 static int pass_exit_resource(struct pass_resource *res)
@@ -229,6 +241,12 @@ static int pass_exit_resource(struct pass_resource *res)
                return -1;
        }
 
+       ret = pass_pmqos_exit(res);
+       if (ret < 0) {
+               _E("cannot exit PASS PMQoS");
+               return ret;
+       }
+
        policy->governor = NULL;
 
        return 0;