summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunghoon Park <jh9216.park@samsung.com>2016-07-25 10:20:39 +0900
committerJunghoon Park <jh9216.park@samsung.com>2016-08-02 00:56:07 -0700
commit11d2bf8c325bcb220b037df04ae9e12c98f3ac61 (patch)
tree28f45b1bfaca78e977c6c3fd7248946cf8cd7a9b
parent69ac0df9d2e377dd7d387262e8278fd66ce03a42 (diff)
downloadlaunchpad-11d2bf8c325bcb220b037df04ae9e12c98f3ac61.tar.gz
launchpad-11d2bf8c325bcb220b037df04ae9e12c98f3ac61.tar.bz2
launchpad-11d2bf8c325bcb220b037df04ae9e12c98f3ac61.zip
Change-Id: Ie2c0551a417a2a06ab2891e6a467701e215178c3 Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
-rw-r--r--inc/launchpad_common.h1
-rw-r--r--packaging/default.loader.in8
-rwxr-xr-xsrc/launchpad.c63
-rw-r--r--src/launchpad_common.c37
4 files changed, 103 insertions, 6 deletions
diff --git a/inc/launchpad_common.h b/inc/launchpad_common.h
index 8263dec..8b70af4 100644
--- a/inc/launchpad_common.h
+++ b/inc/launchpad_common.h
@@ -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);
diff --git a/packaging/default.loader.in b/packaging/default.loader.in
index 0ea64e5..d0d151c 100644
--- a/packaging/default.loader.in
+++ b/packaging/default.loader.in
@@ -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
diff --git a/src/launchpad.c b/src/launchpad.c
index 202ccbb..4fb2490 100755
--- a/src/launchpad.c
+++ b/src/launchpad.c
@@ -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);
diff --git a/src/launchpad_common.c b/src/launchpad_common.c
index 0e9d63b..c4ffa98 100644
--- a/src/launchpad_common.c
+++ b/src/launchpad_common.c
@@ -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;