Add grammar for setting cpu threadhold 61/139061/3
authorJunghoon Park <jh9216.park@samsung.com>
Mon, 17 Jul 2017 06:09:20 +0000 (15:09 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Mon, 17 Jul 2017 06:45:31 +0000 (15:45 +0900)
 - 'CPU_THRESHOLD_MAX' and 'CPU_THRESHOLD_MIN' are added
 - By default, CPU_THRESHOLD_MAX is 90
 - By default, CPU_THRESHOLD_MIN is 40
 - These values may be changed later for some devices by changing '.loader' file

Change-Id: I9054cc79d1399ba860421354772733f7b8bd1ac4
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
inc/loader_info.h
src/launchpad.c
src/loader_info.c

index 4bc89ec..2e5a21d 100644 (file)
@@ -24,6 +24,9 @@
 #define METHOD_VISIBILITY      0x2
 #define METHOD_DEMAND          0x4
 
+#define DEFAULT_CPU_THRESHOLD_MAX              90
+#define DEFAULT_CPU_THRESHOLD_MIN              40
+
 typedef struct _loader_info {
        int type;
        char *name;
@@ -34,6 +37,8 @@ typedef struct _loader_info {
        char *hw_acc;
        GList *alternative_loaders;
        bundle *extra;
+       int cpu_threshold_max;
+       int cpu_threshold_min;
 } loader_info_t;
 
 GList *_loader_info_load(const char *path);
index 1c7c4f5..6d9b0b5 100755 (executable)
@@ -61,8 +61,6 @@
 #define PAD_ERR_INVALID_ARGUMENT       -3
 #define PAD_ERR_INVALID_PATH           -4
 #define CPU_CHECKER_TIMEOUT            1000
-#define DEFAULT_THRESHOLD              90
-#define MIN_THRESHOLD                  40
 #define PI                             3.14159265
 
 typedef struct {
@@ -83,6 +81,8 @@ typedef struct {
        unsigned long long cpu_idle_time;
        guint idle_checker;
        int threshold;
+       int threshold_max;
+       int threshold_min;
 } candidate_process_context_t;
 
 typedef struct {
@@ -112,7 +112,8 @@ static GList *launcher_info_list;
 
 static candidate_process_context_t *__add_slot(int type, int loader_id,
                int caller_pid, const char *loader_path, const char *extra,
-               int detection_method, int timeout_val);
+               int detection_method, int timeout_val,
+               int threshold_max, int threshold_min);
 static int __remove_slot(int type, int loader_id);
 static int __add_default_slots(void);
 static gboolean __handle_idle_checker(gpointer data);
@@ -1095,11 +1096,11 @@ static gboolean __handle_label_monitor(gpointer data)
        return G_SOURCE_CONTINUE;
 }
 
-static float __interpolator(float input)
+static float __interpolator(float input, int cpu_max, int cpu_min)
 {
        float ret;
-       float min = MIN_THRESHOLD / 100.0f;
-       float max = DEFAULT_THRESHOLD / 100.0f;
+       float min = cpu_min / 100.0f;
+       float max = cpu_max / 100.0f;
 
        if (input > 1.0f)
                input = 1.0f;
@@ -1124,7 +1125,8 @@ static void __update_threshold(candidate_process_context_t *cpc, float delta)
        if (pos > 1.0f)
                pos = 1.0f;
 
-       cpc->threshold = (int)(__interpolator(pos) * 100);
+       cpc->threshold = (int)(__interpolator(pos,
+                               cpc->threshold_max, cpc->threshold_min) * 100);
        _D("[CPU] type:%d / delta:%f / input cursor : %f / threshold : %d",
                        cpc->type, delta, pos, cpc->threshold);
 }
@@ -1206,7 +1208,8 @@ static int __dispatch_cmd_add_loader(bundle *kb)
                lid = __make_loader_id();
                cpc = __add_slot(LAUNCHPAD_TYPE_DYNAMIC, lid, atoi(caller_pid),
                                add_slot_str, extra,
-                               METHOD_TIMEOUT | METHOD_VISIBILITY, 2000);
+                               METHOD_TIMEOUT | METHOD_VISIBILITY, 2000,
+                               DEFAULT_CPU_THRESHOLD_MAX, DEFAULT_CPU_THRESHOLD_MIN);
                __set_timer(cpc);
                return lid;
        }
@@ -1462,7 +1465,7 @@ end:
 static candidate_process_context_t *__add_slot(int type, int loader_id,
                int caller_pid, const char *loader_path,
                const char *loader_extra, int detection_method,
-               int timeout_val)
+               int timeout_val, int threshold_max, int threshold_min)
 {
        candidate_process_context_t *cpc;
        int fd = -1;
@@ -1492,7 +1495,9 @@ static candidate_process_context_t *__add_slot(int type, int loader_id,
        cpc->cpu_total_time = 0;
        cpc->cpu_idle_time = 0;
        cpc->idle_checker = 0;
-       cpc->threshold = DEFAULT_THRESHOLD;
+       cpc->threshold = threshold_max;
+       cpc->threshold_max = threshold_max;
+       cpc->threshold_min = threshold_min;
 
        fd = __listen_candidate_process(cpc->type, cpc->loader_id);
        if (fd == -1) {
@@ -1688,7 +1693,8 @@ static void __add_slot_from_info(gpointer data, gpointer user_data)
        if (!strcmp(info->exe, "null")) {
                cpc = __add_slot(LAUNCHPAD_TYPE_USER + user_slot_offset,
                                PAD_LOADER_ID_DIRECT,
-                               0, info->exe, NULL, 0, 0);
+                               0, info->exe, NULL, 0, 0,
+                               info->cpu_threshold_max, info->cpu_threshold_min);
                if (cpc == NULL)
                        return;
 
@@ -1707,7 +1713,8 @@ static void __add_slot_from_info(gpointer data, gpointer user_data)
                cpc = __add_slot(LAUNCHPAD_TYPE_USER + user_slot_offset,
                                PAD_LOADER_ID_STATIC,
                                0, info->exe, (char *)extra,
-                               info->detection_method, info->timeout_val);
+                               info->detection_method, info->timeout_val,
+                               info->cpu_threshold_max, info->cpu_threshold_min);
                if (cpc == NULL)
                        return;
 
index 889ab1d..8cce136 100644 (file)
@@ -35,6 +35,8 @@
 #define TAG_EXTRA_ARRAY_VAL    "EXTRA_ARRAY_VAL"
 #define TAG_ALTERNATIVE_LOADER "ALTERNATIVE_LOADER"
 #define TAG_HW_ACC             "HW_ACC"
+#define TAG_CPU_THRESHOLD_MAX  "CPU_THRESHOLD_MAX"
+#define TAG_CPU_THRESHOLD_MIN  "CPU_THRESHOLD_MIN"
 #define VAL_ON                 "ON"
 #define VAL_OFF                        "OFF"
 #define VAL_METHOD_TIMEOUT     "TIMEOUT"
@@ -46,6 +48,9 @@ static loader_info_t *__create_loader_info()
 {
        loader_info_t *info = malloc(sizeof(loader_info_t));
 
+       if (!info)
+               return NULL;
+
        info->type = 0;
        info->name = NULL;
        info->exe = NULL;
@@ -55,6 +60,8 @@ static loader_info_t *__create_loader_info()
        info->detection_method = METHOD_TIMEOUT | METHOD_VISIBILITY;
        info->timeout_val = 5000;
        info->extra = bundle_create();
+       info->cpu_threshold_max = DEFAULT_CPU_THRESHOLD_MAX;
+       info->cpu_threshold_min = DEFAULT_CPU_THRESHOLD_MIN;
 
        return info;
 }
@@ -183,7 +190,7 @@ static GList *__parse_file(GList *list, const char *path)
                        continue;
                }
 
-               if (!tok1 || !tok2)
+               if (!tok1 || !tok2 || !cur_info)
                        continue;
                if (tok1[0] == '\0' || tok2[0] == '\0' || tok1[0] == '#')
                        continue;
@@ -212,6 +219,10 @@ static GList *__parse_file(GList *list, const char *path)
                        cur_info->alternative_loaders =
                                g_list_append(cur_info->alternative_loaders,
                                                strdup(tok2));
+               } else if (strcasecmp(TAG_CPU_THRESHOLD_MAX, tok1) == 0) {
+                       cur_info->cpu_threshold_max = atoi(tok2);
+               } else if (strcasecmp(TAG_CPU_THRESHOLD_MIN, tok1) == 0) {
+                       cur_info->cpu_threshold_min = atoi(tok2);
                }
        }