Make candidate processes sequentially 95/141195/4
authorJunghoon Park <jh9216.park@samsung.com>
Fri, 28 Jul 2017 11:58:48 +0000 (20:58 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Mon, 31 Jul 2017 03:03:31 +0000 (12:03 +0900)
- Once candidate processes are launched at the same time, it will cause bad
  performance.
- This path allow launchpad to make candidate processes sequentially.

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

index 6d9b0b5..b9dad40 100755 (executable)
@@ -62,6 +62,7 @@
 #define PAD_ERR_INVALID_PATH           -4
 #define CPU_CHECKER_TIMEOUT            1000
 #define PI                             3.14159265
+#define EVENT_BOOTING                  -1
 
 typedef struct {
        int type;
@@ -83,6 +84,7 @@ typedef struct {
        int threshold;
        int threshold_max;
        int threshold_min;
+       int cur_event;
 } candidate_process_context_t;
 
 typedef struct {
@@ -117,6 +119,7 @@ static candidate_process_context_t *__add_slot(int type, int loader_id,
 static int __remove_slot(int type, int loader_id);
 static int __add_default_slots(void);
 static gboolean __handle_idle_checker(gpointer data);
+static int __add_idle_checker(int detection_method, GList *cur);
 
 static int __make_loader_id(void)
 {
@@ -458,7 +461,8 @@ static gboolean __handle_timeout_event(gpointer user_data)
        cpc->cpu_total_time = total;
        _D("Add idle checker");
        cpc->idle_checker = g_timeout_add(CPU_CHECKER_TIMEOUT,
-                               __handle_idle_checker, cpc);
+                               __handle_idle_checker,
+                               g_list_find(candidate_slot_list, cpc));
 
        return G_SOURCE_REMOVE;
 }
@@ -1136,8 +1140,13 @@ static gboolean __handle_idle_checker(gpointer data)
        unsigned long long total = 0;
        unsigned long long idle = 0;
        int per;
-       candidate_process_context_t *cpc = data;
+       GList *list = data;
+       candidate_process_context_t *cpc;
+
+       if (!data)
+               return G_SOURCE_REMOVE;
 
+       cpc = list->data;
        _get_cpu_idle(&total, &idle);
        if (total == cpc->cpu_total_time)
                total++;
@@ -1149,6 +1158,7 @@ static gboolean __handle_idle_checker(gpointer data)
                __update_threshold(cpc, -0.02f * (per - cpc->threshold));
                __prepare_candidate_process(cpc->type, cpc->loader_id);
                cpc->idle_checker = 0;
+               __add_idle_checker(cpc->cur_event, g_list_next(list));
                return G_SOURCE_REMOVE;
        }
 
@@ -1159,18 +1169,24 @@ static gboolean __handle_idle_checker(gpointer data)
        return G_SOURCE_CONTINUE;
 }
 
-static int __dispatch_cmd_hint(bundle *kb, int detection_method)
+static int __add_idle_checker(int detection_method, GList *cur)
 {
        candidate_process_context_t *cpc;
-       GList *iter = candidate_slot_list;
+       GList *iter = cur;
        unsigned long long total = 0;
        unsigned long long idle = 0;
 
-       _W("cmd hint %d", detection_method);
        while (iter) {
                cpc = (candidate_process_context_t *)iter->data;
+
+               if (strcmp("null", cpc->loader_path) == 0) {
+                       iter = g_list_next(iter);
+                       continue;
+               }
+
                if (cpc->pid == CANDIDATE_NONE &&
-                               (cpc->detection_method & detection_method)) {
+                               (detection_method == EVENT_BOOTING ||
+                                (cpc->detection_method & detection_method))) {
                        if (cpc->timer > 0) {
                                g_source_remove(cpc->timer);
                                cpc->timer = 0;
@@ -1180,14 +1196,25 @@ static int __dispatch_cmd_hint(bundle *kb, int detection_method)
                                _get_cpu_idle(&total, &idle);
                                cpc->cpu_idle_time = idle;
                                cpc->cpu_total_time = total;
+                               cpc->cur_event = detection_method;
                                cpc->idle_checker = g_timeout_add(CPU_CHECKER_TIMEOUT,
-                                               __handle_idle_checker, cpc);
+                                               __handle_idle_checker, iter);
+                               _D("Add Idler checker");
+                               return 0;
                        }
                }
 
                iter = g_list_next(iter);
        }
 
+       return -1;
+}
+
+static int __dispatch_cmd_hint(bundle *kb, int detection_method)
+{
+       _W("cmd hint %d", detection_method);
+       __add_idle_checker(detection_method, candidate_slot_list);
+
        return 0;
 }
 
@@ -1687,8 +1714,6 @@ static void __add_slot_from_info(gpointer data, gpointer user_data)
        candidate_process_context_t *cpc;
        bundle_raw *extra = NULL;
        int len;
-       unsigned long long total = 0;
-       unsigned long long idle = 0;
 
        if (!strcmp(info->exe, "null")) {
                cpc = __add_slot(LAUNCHPAD_TYPE_USER + user_slot_offset,
@@ -1718,12 +1743,6 @@ static void __add_slot_from_info(gpointer data, gpointer user_data)
                if (cpc == NULL)
                        return;
 
-               _get_cpu_idle(&total, &idle);
-               cpc->cpu_idle_time = idle;
-               cpc->cpu_total_time = total;
-               cpc->idle_checker = g_timeout_add(CPU_CHECKER_TIMEOUT,
-                               __handle_idle_checker, cpc);
-
                info->type = LAUNCHPAD_TYPE_USER + user_slot_offset;
                user_slot_offset++;
        }
@@ -1740,6 +1759,7 @@ static int __add_default_slots(void)
 
        user_slot_offset = 0;
        g_list_foreach(loader_info_list, __add_slot_from_info, NULL);
+       __add_idle_checker(EVENT_BOOTING, candidate_slot_list);
 
        return 0;
 }