Support timeout feature related on boot 89/284489/4
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 18 Nov 2022 00:26:46 +0000 (00:26 +0000)
committerHwankyu Jhun <h.jhun@samsung.com>
Fri, 18 Nov 2022 01:40:02 +0000 (01:40 +0000)
To exeucte the loader process forcedly, the feature is supported.
"ON_BOOT_TIMEOUT" tag is added for parsing on boot timeout value.
Even if the CPU threshold is not exceeded, the loader process will be
executed by the timer.

Change-Id: I6a588d28ed1c81685f5718b9c03a680d6d0631d3
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/launchpad-process-pool/inc/loader_info.h
src/launchpad-process-pool/inc/slot_info.h
src/launchpad-process-pool/src/launchpad.c
src/launchpad-process-pool/src/loader_info.c

index e3ae865328cdf5f4b1a5e9d2d6aaf3cc11b30799..79ec242c3181beb28e1e866a7d33eb2e02ef5ed7 100644 (file)
@@ -54,6 +54,7 @@ typedef struct _loader_info {
        unsigned int ttl;
        bool is_hydra;
        bool app_check;
+       int on_boot_timeout;
 } loader_info_t;
 
 typedef void (*loader_info_foreach_cb)(loader_info_t *info, void *data);
index fdb08b7dfa41748e0ee0933d0a7fdd6a597c0871..31cbc16de955266ba1b09061f4f2ef9e05a99d31 100644 (file)
@@ -37,6 +37,7 @@ typedef struct slot_info_s {
        bool app_exists;
        bool is_hydra;
        bool app_check;
+       int on_boot_timeout;
 } slot_info_t;
 
 #endif /* __SLOT_INFO_H__ */
index 22edbea954a05e794e33b8b6ea58c8fa2f3adad3..1e88226855ff4dd9a35423cc809046572026d958 100644 (file)
@@ -129,6 +129,8 @@ typedef struct {
        unsigned int score;
        unsigned int pss;
        int cpu_check_count;
+       int on_boot_timeout;
+       guint on_boot_timer;
 } candidate_process_context_t;
 
 typedef struct {
@@ -1021,6 +1023,7 @@ static void __reset_slot(candidate_process_context_t *cpc)
        cpc->client_channel = NULL;
        cpc->timer = 0;
        cpc->live_timer = 0;
+       cpc->on_boot_timer = 0;
 }
 
 static void __dispose_candidate_process(candidate_process_context_t *cpc)
@@ -1041,6 +1044,8 @@ static void __dispose_candidate_process(candidate_process_context_t *cpc)
                g_source_remove(cpc->timer);
        if (cpc->send_fd > 0)
                close(cpc->send_fd);
+       if (cpc->on_boot_timer > 0)
+               g_source_remove(cpc->on_boot_timer);
        __reset_slot(cpc);
 }
 
@@ -1805,6 +1810,14 @@ static gboolean __handle_idle_checker(gpointer data)
                return G_SOURCE_REMOVE;
        }
 
+       if (cpc->pid != CANDIDATE_NONE) {
+               _W("Slot is already running. %d:%s:%d",
+                               cpc->type, cpc->loader_name, cpc->pid);
+               __sequencer.idle_checker = 0;
+               __sequencer.running_cpc = NULL;
+               return G_SOURCE_REMOVE;
+       }
+
        _get_cpu_idle(&total, &idle);
        if (total == cpc->cpu_total_time)
                total++;
@@ -1840,6 +1853,33 @@ static gboolean __handle_idle_checker(gpointer data)
        return G_SOURCE_CONTINUE;
 }
 
+static gboolean __on_boot_timeout_cb(gpointer user_data)
+{
+       candidate_process_context_t *context = user_data;
+
+       _W("type(%d), loader_name(%s)", context->type, context->loader_name);
+       context->on_boot_timer = 0;
+       if (context->pid != CANDIDATE_NONE) {
+               _E("Candidate process is already running. %d:%s:%d",
+                               context->type, context->loader_name,
+                               context->pid);
+       } else {
+               __prepare_candidate_process(context->type, context->loader_id);
+               context->touched = true;
+       }
+
+       return G_SOURCE_REMOVE;
+}
+
+static void __add_on_boot_timer(candidate_process_context_t *context)
+{
+       if (context->on_boot_timer != 0)
+               return;
+
+       context->on_boot_timer = g_timeout_add(context->on_boot_timeout,
+                       __on_boot_timeout_cb, context);
+}
+
 static int __add_idle_checker(int detection_method, GList *cur)
 {
        candidate_process_context_t *cpc;
@@ -1862,6 +1902,9 @@ static int __add_idle_checker(int detection_method, GList *cur)
                        continue;
                }
 
+               if (!cpc->touched && cpc->on_boot && cpc->on_boot_timeout > 0)
+                       __add_on_boot_timer(cpc);
+
                if (cpc->app_check && !cpc->app_exists) {
                        iter = g_list_next(iter);
                        continue;
@@ -2707,6 +2750,7 @@ static candidate_process_context_t *__create_slot(slot_info_t *info)
        cpc->score = WIN_SCORE;
        cpc->pss = 0;
        cpc->cpu_check_count = 0;
+       cpc->on_boot_timeout = info->on_boot_timeout;
 
        if ((cpc->deactivation_method & METHOD_OUT_OF_MEMORY) &&
                        __is_low_memory())
@@ -3032,6 +3076,7 @@ static void __add_slot_from_info(gpointer data, gpointer user_data)
                .app_exists = info->app_exists,
                .is_hydra = info->is_hydra,
                .app_check = info->app_check,
+               .on_boot_timeout = info->on_boot_timeout,
        };
 
        if (!strcmp(info->exe, "null")) {
index 349336606075d277dcb198d75e36754bb0f4393d..3788b90f85cf19796d7b997571911914e287f22c 100644 (file)
@@ -43,6 +43,7 @@
 #define TAG_ON_BOOT                    "ON_BOOT"
 #define TAG_HYDRA                      "HYDRA"
 #define TAG_APP_CHECK                   "APP_CHECK"
+#define TAG_ON_BOOT_TIMEOUT             "ON_BOOT_TIMEOUT"
 
 #define VAL_ON                         "ON"
 #define VAL_OFF                                "OFF"
@@ -302,14 +303,15 @@ static GList *__parse_file(GList *list, const char *path)
                        if (tok2 && strcasecmp(VAL_OFF, tok2) == 0)
                                cur_info->on_boot = false;
                } else if (strcasecmp(TAG_HYDRA, tok1) == 0) {
-                       if (strcasecmp(VAL_ON, tok2) == 0) {
+                       if (strcasecmp(VAL_ON, tok2) == 0)
                                cur_info->is_hydra = 1;
-                       } else {
+                       else
                                cur_info->is_hydra = 0;
-                       }
                } else if (strcasecmp(TAG_APP_CHECK, tok1) == 0) {
                        if (tok2 && strcasecmp(VAL_OFF, tok2) == 0)
                                cur_info->app_check = false;
+               } else if (strcasecmp(TAG_ON_BOOT_TIMEOUT, tok1) == 0) {
+                       cur_info->on_boot_timeout = atoi(tok2);
                }
        }