pass: cpuhp: Move initialization code to guarantee the independnecy 29/169029/2
authorChanwoo Choi <cw00.choi@samsung.com>
Thu, 1 Feb 2018 07:16:52 +0000 (16:16 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Fri, 2 Feb 2018 04:12:31 +0000 (13:12 +0900)
Each module have to initialize/control their own variables
included in module structure. Move initialization code of CPUHP
from pass.c to pass-gov.c in orer to guarantee the independnecy
among modules.

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

index c10b43dc50ff4aa3bda8397cce765ebfbee5dc38..f9c7b715c796c9e93e6d085ee0c049556d47ed4d 100644 (file)
@@ -30,6 +30,9 @@
 #include "pass-hal.h"
 #include "pass-rescon.h"
 
+#define PASS_DEFAULT_CPU_THRESHOLD             20
+#define PASS_DEFAULT_LEVEL_UP_THRESHOLD                30
+#define PASS_DEFAULT_LEVEL_DOWN_THRESHOLD      80
 #define PASS_CPU_STATS_MAX_COUNT       20
 
 struct pass_governor {
@@ -57,10 +60,6 @@ static bool is_enabled(struct pass_cpuhp *cpuhp)
        return true;
 }
 
-/*****************************************************************************
- *                            PASS CPU Hotplug                               *
- ****************************************************************************/
-
 /*
  * pass_hotplug_stop - Stop PASS hotplug
  * @res: the instance of struct pass_resource
@@ -83,12 +82,7 @@ static int pass_hotplug_dummy_governor(struct pass_resource *res)
        return res->config_data.levels[level].limit_min_cpu;
 }
 
-/*
- * pass_get_governor - Return specific hotplug instance according to type
- * @res: the instance of struct pass_resource
- * @type: the type of PASS hotplug
- */
-struct pass_hotplug* pass_get_hotplug(struct pass_resource *res,
+static struct pass_hotplug* get_hotplug(struct pass_resource *res,
                                        enum pass_gov_type type)
 {
        struct pass_hotplug *hotplug;
@@ -117,10 +111,6 @@ struct pass_hotplug* pass_get_hotplug(struct pass_resource *res,
        return NULL;
 }
 
-/*****************************************************************************
- *                              PASS governor                                *
- ****************************************************************************/
-
 /*
  * pass_calculate_busy_cpu - Count a number of busy cpu among NR_CPUS by using
  *                          runnable_avg_sum/runnable_avg_period
@@ -455,7 +445,7 @@ static struct pass_governor pass_gov_radiation = {
  * pass_get_governor - Return specific governor instance according to type
  * @type: the type of PASS governor
  */
-struct pass_governor* pass_get_governor(struct pass_resource *res,
+static struct pass_governor* get_governor(struct pass_resource *res,
                                                enum pass_gov_type type)
 {
        switch (type) {
@@ -486,12 +476,66 @@ struct pass_governor* pass_get_governor(struct pass_resource *res,
 int pass_governor_init(struct pass_resource *res)
 {
        struct pass_cpuhp *cpuhp;
+       int max_freq = 0;
+       int i;
 
        if (!res)
                return -EINVAL;
 
        cpuhp = &res->cpuhp;
 
+       if (!cpuhp->pass_cpu_threshold)
+               cpuhp->pass_cpu_threshold = PASS_DEFAULT_CPU_THRESHOLD;
+
+       if (!cpuhp->up_threshold)
+               cpuhp->up_threshold = PASS_DEFAULT_LEVEL_UP_THRESHOLD;
+
+       if (!cpuhp->down_threshold)
+               cpuhp->down_threshold = PASS_DEFAULT_LEVEL_DOWN_THRESHOLD;
+
+       if (!cpuhp->level_up_threshold)
+               cpuhp->level_up_threshold = 0;
+
+       if (!cpuhp->num_pass_cpu_stats)
+               cpuhp->num_pass_cpu_stats = PASS_CPU_STATS_MAX_COUNT;
+
+       for (i = 0; i < res->config_data.num_levels; i++)
+               if (max_freq < res->config_data.levels[i].limit_max_freq)
+                       max_freq = res->config_data.levels[i].limit_max_freq;
+       cpuhp->freq.max_freq = max_freq;
+
+
+       /* Allocate memory according to the number of data and cpu */
+       cpuhp->pass_cpu_stats = calloc(cpuhp->num_pass_cpu_stats,
+                                       sizeof(struct pass_cpu_stats));
+
+       for (i = 0; i < cpuhp->num_pass_cpu_stats; i++) {
+               cpuhp->pass_cpu_stats[i].load =
+                       calloc(res->config_data.num_cpus, sizeof(unsigned int));
+               cpuhp->pass_cpu_stats[i].nr_running =
+                       calloc(res->config_data.num_cpus, sizeof(unsigned int));
+               cpuhp->pass_cpu_stats[i].runnable_load =
+                       calloc(res->config_data.num_cpus, sizeof(unsigned int));
+       }
+
+       /* Get the instance of CPU Hotplug's policy */
+       cpuhp->hotplug = get_hotplug(res, res->config_data.gov_type);
+       if (cpuhp->hotplug) {
+               cpuhp->hotplug->sequence = calloc(res->config_data.num_cpus,
+                                               sizeof(int));
+               for (i = 0; i < res->config_data.num_cpus; i++)
+                       cpuhp->hotplug->sequence[i] = i + res->config_data.cpu;
+
+               cpuhp->hotplug->num_cpus = res->config_data.num_cpus;
+       }
+
+       /* Get the instance of CPUHP governor */
+       cpuhp->governor = get_governor(res, res->config_data.gov_type);
+       if (!cpuhp->governor) {
+               _E("cannot get the instance of PASS governor");
+               return -1;
+       }
+
        if (!cpuhp->governor || !cpuhp->governor->init)
                return -EINVAL;
 
index 9d4e234494d10aaeaa7df704e9b2bd2c9d05f00b..5e4b4f00f93e1dd894150a52ada5926f05f5fc12 100644 (file)
@@ -24,12 +24,6 @@ int pass_governor_init(struct pass_resource *res);
 int pass_governor_exit(struct pass_resource *res);
 int pass_governor_update(struct pass_resource *res, enum pass_state state);
 
-/* Get the governor/hotplug instance according to enum pass_gov_type */
-struct pass_governor* pass_get_governor(struct pass_resource *res,
-                               enum pass_gov_type type);
-struct pass_hotplug* pass_get_hotplug(struct pass_resource *res,
-                               enum pass_gov_type type);
-
 /* Function for radiation and step governor */
 int pass_step_governor(struct pass_resource *res);
 int pass_radiation_governor(struct pass_resource *res);
index 08fd96e3c12de7b04c69a4ee24f4e2e02fcccc34..692fad450701049c8413d600d4bc31dcb10d9ff0 100644 (file)
 #define DBUS_CORE_PATH                         "/Org/Tizen/System/Pass/Core"
 #define PASS_CONF_PATH                         "/etc/pass/pass.conf"
 #define PASS_DEFAULT_MIN_LEVEL                 0
-#define PASS_DEFAULT_CPU_THRESHOLD             20
-#define PASS_DEFAULT_LEVEL_UP_THRESHOLD                30
-#define PASS_DEFAULT_LEVEL_DOWN_THRESHOLD      80
-#define PASS_CPU_STATS_DEFAULT                 20
 
 static struct pass g_pass;
 static SystemPassCore *g_gdbus_instance = NULL;
@@ -120,8 +116,6 @@ static struct pass_gdbus_signal_info g_gdbus_signal_infos[] = {
  ******************************************************/
 static int pass_init_resource(struct pass_resource *res)
 {
-       struct pass_cpuhp *cpuhp = &res->cpuhp;
-       int max_freq = 0;
        int ret;
        int i;
 
@@ -153,60 +147,10 @@ static int pass_init_resource(struct pass_resource *res)
        if (!res->rescon.init_level)
                res->rescon.init_level = PASS_DEFAULT_MIN_LEVEL;
 
-       if (!cpuhp->pass_cpu_threshold)
-               cpuhp->pass_cpu_threshold = PASS_DEFAULT_CPU_THRESHOLD;
-
-       if (!cpuhp->up_threshold)
-               cpuhp->up_threshold = PASS_DEFAULT_LEVEL_UP_THRESHOLD;
-
-       if (!cpuhp->down_threshold)
-               cpuhp->down_threshold = PASS_DEFAULT_LEVEL_DOWN_THRESHOLD;
-
-       if (!cpuhp->level_up_threshold)
-               cpuhp->level_up_threshold = 0;
-
-       if (!cpuhp->num_pass_cpu_stats)
-               cpuhp->num_pass_cpu_stats = PASS_CPU_STATS_DEFAULT;
-
-       for (i = 0; i < res->config_data.num_levels; i++) {
-               if (max_freq < res->config_data.levels[i].limit_max_freq)
-                       max_freq = res->config_data.levels[i].limit_max_freq;
+       for (i = 0; i < res->config_data.num_levels; i++)
                if (res->config_data.levels[i].gov_timeout == 0)
                        res->config_data.levels[i].gov_timeout =
                                                res->config_data.gov_timeout;
-       }
-       cpuhp->freq.max_freq = max_freq;
-
-       /* Allocate memory according to the number of data and cpu */
-       cpuhp->pass_cpu_stats = calloc(cpuhp->num_pass_cpu_stats,
-                                       sizeof(struct pass_cpu_stats));
-
-       for (i = 0; i < cpuhp->num_pass_cpu_stats; i++) {
-               cpuhp->pass_cpu_stats[i].load =
-                       calloc(res->config_data.num_cpus, sizeof(unsigned int));
-               cpuhp->pass_cpu_stats[i].nr_running =
-                       calloc(res->config_data.num_cpus, sizeof(unsigned int));
-               cpuhp->pass_cpu_stats[i].runnable_load =
-                       calloc(res->config_data.num_cpus, sizeof(unsigned int));
-       }
-
-       /* Get the instance of PASS governor */
-       cpuhp->governor = pass_get_governor(res, res->config_data.gov_type);
-       if (!cpuhp->governor) {
-               _E("cannot get the instance of PASS governor");
-               return -1;
-       }
-
-       /* Get the instance of PASS hotplug */
-       cpuhp->hotplug = pass_get_hotplug(res, res->config_data.gov_type);
-       if (cpuhp->hotplug) {
-               cpuhp->hotplug->sequence = calloc(res->config_data.num_cpus,
-                                               sizeof(int));
-               for (i = 0; i < res->config_data.num_cpus; i++)
-                       cpuhp->hotplug->sequence[i] = i + res->config_data.cpu;
-
-               cpuhp->hotplug->num_cpus = res->config_data.num_cpus;
-       }
 
        ret = pass_governor_init(res);
        if (ret < 0) {