#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;
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 {
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;
cpc->timer = 0;
}
+ if (cpc->idle_checker > 0) {
+ g_source_remove(cpc->idle_checker);
+ cpc->idle_checker = 0;
+ }
+
__set_timer(cpc);
return pid;
}
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;
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);
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) {
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);
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) {
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);