pass: Rename governor module to pass-gov and add governor helper functions
authorChanwoo Choi <cw00.choi@samsung.com>
Thu, 2 Feb 2017 01:33:56 +0000 (10:33 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Thu, 2 Feb 2017 23:43:19 +0000 (08:43 +0900)
This patch renames the governor module's filename from pass-core.c
to pass-gov.c beceause pass-core.c includes the governor functions.

And it adds new following governor functions. On previous, other module
,such as pass.c, access the field of struct pass_governor direclty without
any wrapper function.
- int pass_governor_init(struct pass_policy *);
- int pass_governor_exit(struct pass_policy *);
- int pass_governor_update(struct pass_policy *, enum pass_gov_state);

Change-Id: I772edc602325409faf0b747cc741be5d83151c23
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
CMakeLists.txt
src/pass/pass-core.h [deleted file]
src/pass/pass-gov.c [moved from src/pass/pass-core.c with 89% similarity]
src/pass/pass-gov.h
src/pass/pass-pmqos.c
src/pass/pass.c

index 1cb331b..9f1ac38 100644 (file)
@@ -62,7 +62,7 @@ SET(VERSION 0.1.0)
 
 SET(SRCS
        src/pass/pass.c
-       src/pass/pass-core.c
+       src/pass/pass-gov.c
        src/pass/pass-gov-radiation.c
        src/pass/pass-gov-step.c
        src/pass/pass-parser.c
diff --git a/src/pass/pass-core.h b/src/pass/pass-core.h
deleted file mode 100644 (file)
index bbec558..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * PASS (Power Aware System Service)
- *
- * Copyright (c) 2012 - 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __PASS_CORE__
-#define __PASS_CORE__
-
-/*
- * pass_get_governor - Return specific governor instance according to type
- *
- * @policy: the instance of struct pass_policy
- * @type: the type of PASS governor
- */
-struct pass_governor* pass_get_governor(struct pass_policy *policy,
-                                               enum pass_gov_type type);
-
-/*
- * pass_get_hotplug - Return specific hotplug instance according to type
- *
- * @policy: the instance of struct pass_policy
- * @type: the type of PASS governor
- */
-struct pass_hotplug* pass_get_hotplug(struct pass_policy *policy,
-                                               enum pass_gov_type type);
-
-/*
- * pass_governor_change_level_scope - Change the scope of cpufreq scaling
- *
- * @policy: the instance of struct pass_policy
- * @min_level: the minimum level of cpufreq scaling
- * @max_level: the maximum level of cpufreq scaling
- */
-int pass_governor_change_level_scope(struct pass_policy *policy,
-                                           int min_level, int max_level);
-
-#endif /* __PASS_CORE__ */
similarity index 89%
rename from src/pass/pass-core.c
rename to src/pass/pass-gov.c
index f420b3b..904ac72 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * PASS (Power Aware System Service)
+ * PASS (Power Aware System Service) Governor
  *
  * Copyright (c) 2012 - 2017 Samsung Electronics Co., Ltd.
  *
@@ -370,42 +370,6 @@ static void pass_calculate_busy_cpu(struct pass_policy *policy)
 }
 
 /*
- * pass_governor_stop - Stop PASS governor through D-Bus
- *
- * @policy: the instance of struct pass_policy
- */
-static void pass_governor_stop(struct pass_policy *policy)
-{
-       struct pass_resource *res = to_pass_resource(policy);
-       struct pass_conf_data *cdata = &res->cdata;
-
-       if (!policy->governor) {
-               _E("cannot stop PASS governor");
-               return;
-       }
-
-       if (policy->gov_state == PASS_GOV_STOP) {
-               _E("PASS governor is already inactive state");
-               return;
-       }
-
-       /* Restore maximum cpu freq/the number of online cpu */
-       pass_governor_change_level(policy, policy->num_levels - 1);
-
-       pass_hotplug_stop(policy);
-
-       if (policy->governor->gov_timer_id) {
-               ecore_timer_del(policy->governor->gov_timer_id);
-               policy->governor->gov_timer_id = NULL;
-       }
-
-       /* Set PASS state as PASS_GOV_STOP */
-       policy->gov_state = PASS_GOV_STOP;
-
-       _I("Stop governor for '%s' resource", cdata->res_name);
-}
-
-/*
  * pass_governor_core_timer - Callback function of core timer for PASS governor
  *
  * @data: the instance of struct pass_policy
@@ -436,7 +400,7 @@ static Eina_Bool pass_governor_core_timer(void *data)
                count = 0;
 
                _E("cannot read 'pass_cpu_stats' sysfs entry");
-               pass_governor_stop(policy);
+               pass_governor_update(policy, PASS_GOV_STOP);
 
                return ECORE_CALLBACK_CANCEL;
        }
@@ -451,7 +415,7 @@ static Eina_Bool pass_governor_core_timer(void *data)
                pass_governor_change_level(policy, level);
        } else {
                _E("cannot execute governor function");
-               pass_governor_stop(policy);
+               pass_governor_update(policy, PASS_GOV_STOP);
                return ECORE_CALLBACK_CANCEL;
        }
 
@@ -477,11 +441,11 @@ static Eina_Bool pass_governor_core_timer(void *data)
 }
 
 /*
- * pass_governor_start - Start PASS governor through D-Bus
+ * __pass_governor_start - Start PASS governor through D-Bus
  *
  * @policy: the instance of struct pass_policy
  */
-static void pass_governor_start(struct pass_policy *policy)
+static void __pass_governor_start(struct pass_policy *policy)
 {
        struct pass_resource *res = to_pass_resource(policy);
        struct pass_conf_data *cdata = &res->cdata;
@@ -503,7 +467,7 @@ static void pass_governor_start(struct pass_policy *policy)
                                (void *)policy);
        if (!policy->governor->gov_timer_id) {
                _E("cannot add core timer for governor");
-               pass_governor_stop(policy);
+               pass_governor_update(policy, PASS_GOV_STOP);
                return;
        }
 
@@ -523,11 +487,42 @@ static void pass_governor_start(struct pass_policy *policy)
 }
 
 /*
- * pass_governor_init - Initialize PASS governor
+ * __pass_governor_stop - Stop PASS governor through D-Bus
  *
  * @policy: the instance of struct pass_policy
  */
-static int pass_governor_init(struct pass_policy *policy)
+static void __pass_governor_stop(struct pass_policy *policy)
+{
+       struct pass_resource *res = to_pass_resource(policy);
+       struct pass_conf_data *cdata = &res->cdata;
+
+       if (!policy->governor) {
+               _E("cannot stop PASS governor");
+               return;
+       }
+
+       if (policy->gov_state == PASS_GOV_STOP) {
+               _E("PASS governor is already inactive state");
+               return;
+       }
+
+       /* Restore maximum cpu freq/the number of online cpu */
+       pass_governor_change_level(policy, policy->num_levels - 1);
+
+       pass_hotplug_stop(policy);
+
+       if (policy->governor->gov_timer_id) {
+               ecore_timer_del(policy->governor->gov_timer_id);
+               policy->governor->gov_timer_id = NULL;
+       }
+
+       /* Set PASS state as PASS_GOV_STOP */
+       policy->gov_state = PASS_GOV_STOP;
+
+       _I("Stop governor for '%s' resource", cdata->res_name);
+}
+
+static int __pass_governor_init(struct pass_policy *policy)
 {
        struct pass_resource *res = to_pass_resource(policy);
        struct pass_conf_data *cdata = &res->cdata;
@@ -535,7 +530,7 @@ static int pass_governor_init(struct pass_policy *policy)
        if(policy->governor->gov_timeout < 0) {
                _E("invalid timeout value [%d]!",
                        policy->governor->gov_timeout);
-               pass_governor_stop(policy);
+               pass_governor_update(policy, PASS_GOV_STOP);
                return -EINVAL;
        }
 
@@ -550,10 +545,7 @@ static int pass_governor_init(struct pass_policy *policy)
        return 0;
 }
 
-/*
- * pass_governor_exit - Exit PASS governor
- */
-static int pass_governor_exit(struct pass_policy *policy)
+static int __pass_governor_exit(struct pass_policy *policy)
 {
        struct pass_resource *res = to_pass_resource(policy);
        struct pass_conf_data *cdata = &res->cdata;
@@ -566,7 +558,7 @@ static int pass_governor_exit(struct pass_policy *policy)
         * Stop core timer and
         * Restore maximum online cpu/cpu frequency
         */
-       pass_governor_stop(policy);
+       pass_governor_update(policy, PASS_GOV_STOP);
 
        /* Free allocated memory */
        for (i = 0; i < policy->num_pass_cpu_stats; i++) {
@@ -608,12 +600,7 @@ static int pass_governor_exit(struct pass_policy *policy)
        return 0;
 }
 
-/*
- * pass_governor_update - Restart/Pause PASS governor
- *
- * @cond: the instance of struct pass_policy
- */
-static int pass_governor_update(struct pass_policy *policy,
+static int __pass_governor_update(struct pass_policy *policy,
                        enum pass_gov_state state)
 {
        if (!policy) {
@@ -623,10 +610,10 @@ static int pass_governor_update(struct pass_policy *policy,
 
        switch (state) {
        case PASS_GOV_START:
-               pass_governor_start(policy);
+               __pass_governor_start(policy);
                break;
        case PASS_GOV_STOP:
-               pass_governor_stop(policy);
+               __pass_governor_stop(policy);
                break;
        default:
                _E("Unknown governor state");
@@ -676,18 +663,18 @@ int pass_governor_change_level_scope(struct pass_policy *policy,
  */
 static struct pass_governor pass_gov_step = {
        .name           = "pass_step",
-       .init           = pass_governor_init,
-       .exit           = pass_governor_exit,
-       .update         = pass_governor_update,
+       .init           = __pass_governor_init,
+       .exit           = __pass_governor_exit,
+       .update         = __pass_governor_update,
 
        .governor       = pass_step_governor,
 };
 
 static struct pass_governor pass_gov_radiation = {
        .name           = "pass_radiation",
-       .init           = pass_governor_init,
-       .exit           = pass_governor_exit,
-       .update         = pass_governor_update,
+       .init           = __pass_governor_init,
+       .exit           = __pass_governor_exit,
+       .update         = __pass_governor_update,
 
        .governor       = pass_radiation_governor,
 };
@@ -712,3 +699,44 @@ struct pass_governor* pass_get_governor(struct pass_policy *policy,
 
        return NULL;
 }
+
+/*
+ * __pass_governor_init - Initialize PASS governor
+ *
+ * @policy: the instance of struct pass_policy
+ */
+int pass_governor_init(struct pass_policy *policy)
+{
+       if (!policy || !policy->governor || !policy->governor->init)
+               return -EINVAL;
+
+       return policy->governor->init(policy);
+}
+
+/*
+ * __pass_governor_exit - Exit PASS governor
+ */
+int pass_governor_exit(struct pass_policy *policy)
+{
+       if (!policy || !policy->governor || !policy->governor->exit)
+               return -EINVAL;
+
+       return policy->governor->exit(policy);
+}
+
+/*
+ * __pass_governor_update - Restart/Pause PASS governor
+ *
+ * @policy: the instance of struct pass_policy
+ * @state: the state of governor
+ *     PASS_GOV_START : start governor
+ *     PASS_GOV_STOP: stop governor
+ */
+int pass_governor_update(struct pass_policy *policy,
+                                       enum pass_gov_state state)
+{
+       if (!policy || !policy->governor || !policy->governor->update)
+               return -EINVAL;
+
+       return policy->governor->update(policy, state);
+}
index 1caa07b..e80498f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * PASS (Power Aware System Service)
+ * PASS (Power Aware System Service) Governor
  *
  * Copyright (c) 2012 - 2017 Samsung Electronics Co., Ltd.
  *
 #ifndef __PASS_GOV__
 #define __PASS_GOV__
 
-/* PASS Step governor function */
-int pass_step_governor(struct pass_policy *policy);
+/* Init, exit and update the governor */
+int pass_governor_init(struct pass_policy *policy);
+int pass_governor_exit(struct pass_policy *policy);
+int pass_governor_update(struct pass_policy *policy, enum pass_gov_state state);
+int pass_governor_change_level_scope(struct pass_policy *policy,
+                                       int min_level, int max_level);
+
+/* Get the governor/hotplug instance according to enum pass_gov_type */
+struct pass_governor* pass_get_governor(struct pass_policy *policy,
+                                       enum pass_gov_type type);
+struct pass_hotplug* pass_get_hotplug(struct pass_policy *policy,
+                                       enum pass_gov_type type);
 
-/* PASS Radiation governor function */
+/* Function for radiation and step governor */
+int pass_step_governor(struct pass_policy *policy);
 int pass_radiation_governor(struct pass_policy *policy);
 
 #endif /* __PASS_GOV__ */
index 9ab0dbb..31627c5 100644 (file)
@@ -22,7 +22,7 @@
 #include <sys/time.h>
 
 #include "pass.h"
-#include "pass-core.h"
+#include "pass-gov.h"
 #include "pass-hal.h"
 
 #include "core/device-notifier.h"
index ed84d9f..0fbabd3 100644 (file)
@@ -23,9 +23,9 @@
 #include <stdlib.h>
 
 #include "pass.h"
-#include "pass-core.h"
 #include "pass-parser.h"
 #include "pass-hal.h"
+#include "pass-gov.h"
 
 #include "core/devices.h"
 #include "core/common.h"
@@ -43,40 +43,47 @@ static struct pass g_pass;
  ******************************************************/
 static DBusMessage* e_dbus_start_cb(E_DBus_Object *obj, DBusMessage* msg)
 {
-       DBusMessage *ret = NULL;
-       int i;
+       DBusMessage *ret_dbus = NULL;
+       int i, ret;
 
        for (i = 0; i < g_pass.num_resources; i++) {
                struct pass_resource *pass_res = &g_pass.res[i];
                struct pass_policy *policy = &pass_res->policy;
 
-               if (policy->governor)
-                       policy->governor->update(policy, PASS_GOV_START);
-               ret = dbus_message_new_method_return(msg);
-               if (!ret)
-                       return ret;
+               ret = pass_governor_update(policy, PASS_GOV_START);
+               if (ret < 0) {
+                       _E("cannot start the governor with dbus");
+                       return ret_dbus;
+               }
+               ret_dbus = dbus_message_new_method_return(msg);
+               if (!ret_dbus)
+                       return ret_dbus;
        }
 
-       return ret;
+       return ret_dbus;
 }
 
 static DBusMessage* e_dbus_stop_cb(E_DBus_Object *obj, DBusMessage* msg)
 {
-       DBusMessage *ret = NULL;
-       int i;
+       DBusMessage *ret_dbus = NULL;
+       int i, ret;
 
        for (i = 0; i < g_pass.num_resources; i++) {
                struct pass_resource *pass_res = &g_pass.res[i];
                struct pass_policy *policy = &pass_res->policy;
 
-               if (policy->governor)
-                       policy->governor->update(policy, PASS_GOV_STOP);
-               ret = dbus_message_new_method_return(msg);
-               if (!ret)
-                       return ret;
+               ret = pass_governor_update(policy, PASS_GOV_STOP);
+               if (ret < 0) {
+                       _E("cannot stop the governor");
+                       return ret_dbus;
+               }
+
+               ret_dbus = dbus_message_new_method_return(msg);
+               if (!ret_dbus)
+                       return ret_dbus;
        }
 
-       return ret;
+       return ret_dbus;
 }
 
 static const struct edbus_method edbus_methods[] = {
@@ -187,14 +194,9 @@ static int pass_resource_init(struct pass_policy *policy)
                        policy->hotplug->sequence[i] = i + pass_res->cdata.cpu;
        }
 
-       if (policy->governor->init) {
-               ret = policy->governor->init(policy);
-               if (ret < 0) {
-                       _E("cannot initialize PASS governor");
-                       return -1;
-               }
-       } else {
-               _E("cannot execute init() of PASS governor");
+       ret = pass_governor_init(policy);
+       if (ret < 0) {
+               _E("cannot initialize PASS governor");
                return -1;
        }
 
@@ -205,21 +207,11 @@ static int pass_resource_exit(struct pass_policy *policy)
 {
        int ret;
 
-       if (!policy->governor) {
-               _E("cannot exit PASS");
-               return -1;
-       }
-
        pass_put_table(policy);
 
-       if (policy->governor->exit) {
-               ret = policy->governor->exit(policy);
-               if (ret < 0) {
-                       _E("cannot exit PASS governor");
-                       return -1;
-               }
-       } else {
-               _E("cannot execute exit() of PASS governor");
+       ret = pass_governor_exit(policy);
+       if (ret < 0) {
+               _E("cannot exit PASS governor");
                return -1;
        }