From 5809f5b67091ac2a37cff410d56951df994ddead Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Mon, 17 Jul 2017 14:24:33 +0900 Subject: [PATCH] Check CPU idle time for TIMEOUT method - Although timeout event happen, launchpad will check CPU idle time again to figure out proper time for making candidate process Change-Id: I8480fe1bb575182a794f47a9d192370968d9a245 Signed-off-by: Junghoon Park --- src/launchpad.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/launchpad.c b/src/launchpad.c index 3b06c24..1c7c4f5 100755 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -115,6 +115,7 @@ static candidate_process_context_t *__add_slot(int type, int loader_id, int detection_method, int timeout_val); static int __remove_slot(int type, int loader_id); static int __add_default_slots(void); +static gboolean __handle_idle_checker(gpointer data); static int __make_loader_id(void) { @@ -414,7 +415,7 @@ static int __prepare_candidate_process(int type, int loader_id) if (cpt == NULL) return -1; - _D("prepare candidate process"); + _D("prepare candidate process / type:%d", type); memset(argbuf, ' ', LOADER_ARG_LEN); argbuf[LOADER_ARG_LEN - 1] = '\0'; argv[LOADER_ARG_DUMMY] = argbuf; @@ -439,14 +440,25 @@ static int __prepare_candidate_process(int type, int loader_id) return 0; } -static gboolean __handle_preparing_candidate_process(gpointer user_data) +static gboolean __handle_timeout_event(gpointer user_data) { candidate_process_context_t *cpc; + unsigned long long total = 0; + unsigned long long idle = 0; cpc = (candidate_process_context_t *)user_data; - __prepare_candidate_process(cpc->type, cpc->loader_id); - _D("Prepare another candidate process"); cpc->timer = 0; + + if (cpc->idle_checker > 0) + return G_SOURCE_REMOVE; + + _get_cpu_idle(&total, &idle); + cpc->cpu_idle_time = idle; + cpc->cpu_total_time = total; + _D("Add idle checker"); + cpc->idle_checker = g_timeout_add(CPU_CHECKER_TIMEOUT, + __handle_idle_checker, cpc); + return G_SOURCE_REMOVE; } @@ -457,7 +469,7 @@ static void __set_timer(candidate_process_context_t *cpc) if (cpc->detection_method & METHOD_TIMEOUT) { cpc->timer = g_timeout_add(cpc->timeout_val, - __handle_preparing_candidate_process, cpc); + __handle_timeout_event, cpc); } } @@ -964,7 +976,6 @@ static gboolean __handle_loader_client_event(gpointer data) 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; @@ -1163,16 +1174,13 @@ static int __dispatch_cmd_hint(bundle *kb, int detection_method) cpc->timer = 0; } - if (cpc->idle_checker > 0) { - g_source_remove(cpc->idle_checker); - cpc->idle_checker = 0; + if (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); } - - _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); -- 2.7.4