Check cpu idle time to prepare candidate process 61/77461/16 accepted/tizen/common/20160803.193309 accepted/tizen/ivi/20160804.080819 accepted/tizen/mobile/20160804.080910 accepted/tizen/tv/20160804.080736 accepted/tizen/wearable/20160804.080650 submit/tizen/20160803.012753
authorJunghoon Park <jh9216.park@samsung.com>
Mon, 25 Jul 2016 01:20:39 +0000 (10:20 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Tue, 2 Aug 2016 07:56:07 +0000 (00:56 -0700)
Change-Id: Ie2c0551a417a2a06ab2891e6a467701e215178c3
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
inc/launchpad_common.h
packaging/default.loader.in
src/launchpad.c
src/launchpad_common.c

index 8263dec..8b70af4 100644 (file)
@@ -102,6 +102,7 @@ void _appinfo_free(appinfo_t *menu_info);
 char *_appinfo_get_app_path(appinfo_t *menu_info);
 int _proc_get_attr_by_pid(int pid, char *buf, int size);
 int _close_all_fds(int except);
+void _get_cpu_idle(long long *total, long long *idle);
 
 int _mount_legacy_app_path(const char *app_root_path,
                        const char *pkgid);
index 0ea64e5..d0d151c 100644 (file)
@@ -3,8 +3,8 @@ NAME    hw-loader1
 EXE    /usr/bin/launchpad-loader
 APP_TYPE       capp|c++app
 HW_ACC         ON
-DETECTION_METHOD       TIMEOUT
-TIMEOUT                2000
+DETECTION_METHOD       TIMEOUT|VISIBILITY
+TIMEOUT                5000
 EXTRA          loader_type      hw-loader
 EXTRA_ARRAY            preload
 EXTRA_ARRAY_VAL                @LIB_INSTALL_DIR@/libappcore-efl.so.1
@@ -22,8 +22,8 @@ ALTERNATIVE_LOADER    common-loader1
 NAME   common-loader1
 EXE    /usr/bin/launchpad-loader
 APP_TYPE       capp|c++app
-DETECTION_METHOD       TIMEOUT
-TIMEOUT                2000
+DETECTION_METHOD       TIMEOUT|VISIBILITY
+TIMEOUT                5000
 EXTRA          loader_type     common-loader
 EXTRA_ARRAY            preload
 EXTRA_ARRAY_VAL                @LIB_INSTALL_DIR@/libappcore-efl.so.1
index 202ccbb..4fb2490 100755 (executable)
@@ -55,7 +55,7 @@
 #define PAD_ERR_REJECTED               -2
 #define PAD_ERR_INVALID_ARGUMENT       -3
 #define PAD_ERR_INVALID_PATH           -4
-
+#define CPU_CHECKER_TIMEOUT            1000
 
 typedef struct {
        int type;
@@ -71,6 +71,9 @@ typedef struct {
        char *loader_extra;
        int detection_method;
        int timeout_val;
+       long long cpu_total_time;
+       long long cpu_idle_time;
+       guint idle_checker;
 } candidate_process_context_t;
 
 typedef struct {
@@ -421,6 +424,7 @@ static int __prepare_candidate_process(int type, int loader_id)
        if (cpt == NULL)
                return -1;
 
+       _D("prepare candidate process");
        memset(argbuf, ' ', LOADER_ARG_LEN);
        argbuf[LOADER_ARG_LEN - 1] = '\0';
        argv[LOADER_ARG_DUMMY] = argbuf;
@@ -497,6 +501,11 @@ static int __send_launchpad_loader(candidate_process_context_t *cpc,
                cpc->timer = 0;
        }
 
+       if (cpc->idle_checker > 0) {
+               g_source_remove(cpc->idle_checker);
+               cpc->idle_checker = 0;
+       }
+
        __set_timer(cpc);
        return pid;
 }
@@ -816,6 +825,10 @@ static gboolean __handle_loader_client_event(gpointer data)
                if (cpc->timer > 0)
                        g_source_remove(cpc->timer);
                cpc->timer = 0;
+               if (cpc->idle_checker > 0)
+                       g_source_remove(cpc->idle_checker);
+               cpc->idle_checker = 0;
+
                __prepare_candidate_process(cpc->type, cpc->loader_id);
 
                return G_SOURCE_REMOVE;
@@ -915,6 +928,11 @@ static gboolean __handle_label_monitor(gpointer data)
                                cpc->timer = 0;
                        }
 
+                       if (cpc->idle_checker > 0) {
+                               g_source_remove(cpc->idle_checker);
+                               cpc->idle_checker = 0;
+                       }
+
                        _D("Dispose candidate process %d", cpc->pid);
                        __kill_process(cpc->pid);
                        close(cpc->send_fd);
@@ -930,10 +948,37 @@ static gboolean __handle_label_monitor(gpointer data)
        return G_SOURCE_CONTINUE;
 }
 
+static gboolean __handle_idle_checker(gpointer data)
+{
+       long long total = 0;
+       long long idle = 0;
+       int per;
+       candidate_process_context_t *cpc = data;
+
+       _get_cpu_idle(&total, &idle);
+       if (total == cpc->cpu_total_time)
+               total++;
+
+       per = (idle - cpc->cpu_idle_time) * 100 / (total - cpc->cpu_total_time);
+       _D("CPU Idle : %d %d", per, cpc->type);
+
+       if (per >= 90) {
+               __prepare_candidate_process(cpc->type, cpc->loader_id);
+               cpc->idle_checker = 0;
+               return G_SOURCE_REMOVE;
+       }
+
+       cpc->cpu_idle_time = idle;
+       cpc->cpu_total_time = total;
+       return G_SOURCE_CONTINUE;
+}
+
 static int __dispatch_cmd_hint(bundle *kb, int detection_method)
 {
        candidate_process_context_t *cpc;
        GList *iter = candidate_slot_list;
+       long long total = 0;
+       long long idle = 0;
 
        _W("cmd hint %d", detection_method);
        while (iter) {
@@ -944,7 +989,16 @@ static int __dispatch_cmd_hint(bundle *kb, int detection_method)
                                g_source_remove(cpc->timer);
                                cpc->timer = 0;
                        }
-                       __prepare_candidate_process(cpc->type, cpc->loader_id);
+
+                       if (cpc->idle_checker > 0) {
+                               g_source_remove(cpc->idle_checker);
+                               cpc->idle_checker = 0;
+                       }
+
+                       _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);
                }
 
                iter = g_list_next(iter);
@@ -1240,6 +1294,9 @@ static candidate_process_context_t *__add_slot(int type, int loader_id,
        cpc->loader_extra = loader_extra ? strdup(loader_extra) : strdup("");
        cpc->detection_method = detection_method;
        cpc->timeout_val = timeout_val;
+       cpc->cpu_total_time = 0;
+       cpc->cpu_idle_time = 0;
+       cpc->idle_checker = 0;
 
        fd = __listen_candidate_process(cpc->type, cpc->loader_id);
        if (fd == -1) {
@@ -1278,6 +1335,8 @@ static int __remove_slot(int type, int loader_id)
                                g_source_remove(cpc->timer);
                        if (cpc->source > 0)
                                g_source_remove(cpc->source);
+                       if (cpc->idle_checker > 0)
+                               g_source_remove(cpc->idle_checker);
 
                        candidate_slot_list = g_list_delete_link(
                                        candidate_slot_list, iter);
index 0e9d63b..c4ffa98 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/limits.h>
 #include <unistd.h>
 #include <tzplatform_config.h>
+#include <stdio.h>
 
 #include "launchpad_common.h"
 #include "key.h"
@@ -79,6 +80,42 @@ static int __read_proc(const char *path, char *buf, int size)
        return ret;
 }
 
+void _get_cpu_idle(long long *total, long long *idle)
+{
+       FILE *fp;
+       int i;
+       long long sum = 0;
+       long long val;
+       long long iv = 0;
+
+       char buf[4]= { 0, };
+
+       fp = fopen("/proc/stat", "rt");
+
+       if (fp == NULL)
+               return;
+
+       if (fscanf(fp, "%3s", buf) == -1) {
+               fclose(fp);
+               return;
+       }
+
+       for (i = 0; i < 10; i++){
+               if (fscanf(fp, "%lld", &val) == -1) {
+                       fclose(fp);
+                       return;
+               }
+               sum += val;
+               if (i == 3) /* idle */
+                       iv = val;
+       }
+
+       fclose(fp);
+
+       *total = sum;
+       *idle = iv;
+}
+
 void _set_sock_option(int fd, int cli)
 {
        int size;