Modify loader priority feature 42/287542/2
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 31 Jan 2023 06:35:46 +0000 (06:35 +0000)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 31 Jan 2023 06:46:07 +0000 (06:46 +0000)
After this patch is applied, the loader priority feature is basically activated.
The platform developer can adjust a scheduling priority using
the loader configuration file.
The 'SCEHD_PRIORITY' tag is added for the loader process.
The loader developer can set the scheduling priority as below:
+------------------------------------------------------------------------------+
| [LOADER]                                                                     |
| NAME hw-loader                                                               |
| ...                                                                          |
| SCEHD_PRIORITY         -20                                                   |
+------------------------------------------------------------------------------+

The range of the priority is -20 to 19. (-20 being the highest priority
and 19 being the lowest priority.)
If the loader has the sched priority tag, the child process sets
the scheduling priority using the configure information after the process
is created. And then, the loader process sets the priority to the normal
priority before running the main loop.

Change-Id: I531cc8381936ef4f6c9b8bad1640a0a8714f2777
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
CMakeLists.txt
packaging/launchpad.spec
src/app-defined-loader/src/app-defined-loader.cc
src/launchpad-loader/src/launchpad_loader.c
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
src/lib/common/src/launchpad_common.c
src/lib/launchpad/src/launchpad_lib.c

index fc8276c..1708bfa 100644 (file)
@@ -4,9 +4,6 @@ PROJECT(launchpad)
 IF(_TIZEN_FEATURE_PRIORITY_CHANGE)
        ADD_DEFINITIONS("-DTIZEN_FEATURE_PRIORITY_CHANGE")
 ENDIF(_TIZEN_FEATURE_PRIORITY_CHANGE)
-IF(_TIZEN_FEATURE_LOADER_PRIORITY)
-       ADD_DEFINITIONS("-DTIZEN_FEATURE_LOADER_PRIORITY")
-ENDIF(_TIZEN_FEATURE_LOADER_PRIORITY)
 IF(_TIZEN_FEATURE_SET_PERSONALITY_32)
        ADD_DEFINITIONS("-DTIZEN_FEATURE_SET_PERSONALITY_32")
 ENDIF(_TIZEN_FEATURE_SET_PERSONALITY_32)
index a91fa3c..a48227f 100644 (file)
@@ -44,7 +44,6 @@ Provides: app-launchpad
 Obsoletes: amd-mod-launchpad
 
 %define tizen_feature_priority_change 0
-%define tizen_feature_loader_priority 0
 %ifarch armv7l i686 i586
 %define tizen_arch32 1
 %else
@@ -119,9 +118,6 @@ export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE"
 %if 0%{?tizen_feature_priority_change}
 _TIZEN_FEATURE_PRIORITY_CHANGE=ON
 %endif
-%if 0%{?tizen_feature_loader_priority}
-_TIZEN_FEATURE_LOADER_PRIORITY=ON
-%endif
 %if 0%{?tizen_arch32}
 _TIZEN_FEATURE_SET_PERSONALITY_32=ON
 %else
@@ -142,7 +138,6 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
        -DMAJORVER=${MAJORVER} \
        -DHW_LOADER_THREADS=${HW_LOADER_THREADS} \
        -D_TIZEN_FEATURE_PRIORITY_CHANGE:BOOL=${_TIZEN_FEATURE_PRIORITY_CHANGE} \
-       -D_TIZEN_FEATURE_LOADER_PRIORITY:BOOL=${_TIZEN_FEATURE_LOADER_PRIORITY} \
        -D_TIZEN_FEATURE_SET_PERSONALITY_32:BOOL=${_TIZEN_FEATURE_SET_PERSONALITY_32} \
        -D_TIZEN_FEATURE_PRELINK:BOOL=${_TIZEN_FEATURE_PRELINK} \
        -D_TIZEN_FEATURE_LOADER_ARCH64:BOOL=${_TIZEN_FEATURE_LOADER_ARCH64} \
index b96e72e..3e9f368 100644 (file)
@@ -85,14 +85,6 @@ class AppDefinedLoader {
     return adapter_;
   }
 
-  void SetLoaderPriority(bool enable) {
-    loader_priority_enabled_ = enable;
-  }
-
-  bool IsLoaderPriorityEnabled() {
-    return loader_priority_enabled_;
-  }
-
   void SetFdHandler(Ecore_Fd_Handler* fd_handler) {
     fd_handler_ = fd_handler;
   }
@@ -142,9 +134,6 @@ class AppDefinedLoader {
       return;
     }
 
-    if (loader->IsLoaderPriorityEnabled())
-      launchpad_loader_set_priority(19);
-
     loader->PreloadLib(ex);
     ecore_init();
     setenv("AUL_LOADER_INIT", "1", 1);
@@ -153,16 +142,12 @@ class AppDefinedLoader {
       setenv("AUL_HWACC", "none", 1);
     else if (loader_type == LOADER_TYPE_HW)
       setenv("AUL_HWACC", "hw", 1);
-
-    if (loader->IsLoaderPriorityEnabled())
-      launchpad_loader_set_priority(0);
   }
 
   static int OnLaunch(int argc, char** argv, const char* app_path,
       const char* appid, const char* pkgid, const char* pkg_type,
       void* user_data) {
     _I("on launch");
-    AppDefinedLoader* loader = static_cast<AppDefinedLoader*>(user_data);
     bundle* kb = launchpad_loader_get_bundle();
     if (kb == nullptr)
       return 0;
@@ -318,7 +303,6 @@ class AppDefinedLoader {
  private:
   std::shared_ptr<loader_lifecycle_callback_s> lifecycle_cb_ = nullptr;
   std::shared_ptr<loader_adapter_s> adapter_ = nullptr;
-  bool loader_priority_enabled_ = false;
   loader_receiver_cb receiver_cb_ = nullptr;
   Ecore_Fd_Handler* fd_handler_ = nullptr;
   std::unique_ptr<Proc> proc_;
@@ -331,11 +315,6 @@ class AppDefinedLoader {
 
 int main(int argc, char** argv) {
   launchpad::AppDefinedLoader loader(argc, argv);
-
-#ifdef TIZEN_FEATURE_LOADER_PRIORITY
-  loader.SetLoaderPriority(true);
-#endif
-
   return launchpad_loader_main(argc, argv,
       loader.GetLifeCycle().get(), loader.GetAdapter().get(), &loader);
 }
index f87150b..b815e48 100644 (file)
@@ -203,10 +203,6 @@ static void __loader_create_cb(bundle *extra, int type, void *user_data)
                return;
        }
 
-#ifdef TIZEN_FEATURE_LOADER_PRIORITY
-       launchpad_loader_set_priority(19);
-#endif
-
        if (!strcmp(LOADER_TYPE_COMMON, ltype))
                __type = TYPE_COMMON;
        else if (!strcmp(LOADER_TYPE_SW, ltype))
@@ -252,9 +248,6 @@ static void __loader_create_cb(bundle *extra, int type, void *user_data)
                _E("Failed to register callback for %s",
                                VCONFKEY_SETAPPL_APP_HW_ACCELERATION);
        }
-#ifdef TIZEN_FEATURE_LOADER_PRIORITY
-       launchpad_loader_set_priority(0);
-#endif
 }
 
 static loader_convertible __converter_table[MAX_LOADER_TYPE][MAX_ACC_TYPE] = {
index 79ec242..6d44b1d 100644 (file)
@@ -55,6 +55,7 @@ typedef struct _loader_info {
        bool is_hydra;
        bool app_check;
        int on_boot_timeout;
+       int sched_priority;
 } loader_info_t;
 
 typedef void (*loader_info_foreach_cb)(loader_info_t *info, void *data);
index 31cbc16..58de327 100644 (file)
@@ -38,6 +38,7 @@ typedef struct slot_info_s {
        bool is_hydra;
        bool app_check;
        int on_boot_timeout;
+       int sched_priority;
 } slot_info_t;
 
 #endif /* __SLOT_INFO_H__ */
index be6ab2a..e5ca890 100644 (file)
@@ -131,6 +131,7 @@ typedef struct {
        int cpu_check_count;
        int on_boot_timeout;
        guint on_boot_timer;
+       int sched_priority;
 } candidate_process_context_t;
 
 typedef struct {
@@ -779,7 +780,8 @@ static int __real_send(int clifd, int ret)
        return 0;
 }
 
-static int __fork_app_process(int (*child_fn)(void *), void *arg)
+static int __fork_app_process(int (*child_fn)(void *), void *arg,
+               int sched_priority)
 {
        int pid;
        int ret;
@@ -791,6 +793,9 @@ static int __fork_app_process(int (*child_fn)(void *), void *arg)
        }
 
        if (pid == 0) {
+               if (sched_priority != 0)
+                       _set_priority(sched_priority);
+
                _W("security_manager_prepare_app_candidate ++");
                ret = security_manager_prepare_app_candidate();
                _W("security_manager_prepare_app_candidate --");
@@ -957,7 +962,8 @@ static int __prepare_candidate_process(int type, int loader_id)
        if (ret < 0)
                return ret;
 
-       info->pid = __fork_app_process(__exec_loader_process, info->argv);
+       info->pid = __fork_app_process(__exec_loader_process, info->argv,
+                       cpt->sched_priority);
        if (info->pid == -1) {
                _E("Failed to create a child process. type: %d", type);
                __candidate_info_free(info);
@@ -1430,7 +1436,7 @@ static int __launch_directly(const char *appid, const char *app_path, int clifd,
        arg.kb = kb;
 
        _print_hwc_log("before calling fork(). %s", appid);
-       pid = __fork_app_process(__exec_app_process, &arg);
+       pid = __fork_app_process(__exec_app_process, &arg, 0);
        if (pid <= 0)
                _E("failed to fork app process");
 
@@ -1988,6 +1994,7 @@ static int __dispatch_cmd_add_loader(bundle *kb)
        slot_info.is_hydra = false;
        slot_info.app_check = true;
        slot_info.on_boot_timeout = 0;
+       slot_info.sched_priority = 0;
 
        cpc = __add_slot(&slot_info);
        free(loader_name);
@@ -2047,6 +2054,7 @@ static int __dispatch_cmd_add_app_defined_loader(bundle *kb)
                slot_info.is_hydra = false;
                slot_info.app_check = true;
                slot_info.on_boot_timeout = 0;
+               slot_info.sched_priority = 0;
 
                cpc = __add_slot(&slot_info);
                bundle_free_encoded_rawdata(&extra);
@@ -2735,6 +2743,7 @@ static candidate_process_context_t *__create_slot(slot_info_t *info)
        cpc->pss = 0;
        cpc->cpu_check_count = 0;
        cpc->on_boot_timeout = info->on_boot_timeout;
+       cpc->sched_priority = info->sched_priority;
 
        if ((cpc->deactivation_method & METHOD_OUT_OF_MEMORY) &&
                        __is_low_memory())
@@ -3061,6 +3070,7 @@ static void __add_slot_from_info(gpointer data, gpointer user_data)
                .is_hydra = info->is_hydra,
                .app_check = info->app_check,
                .on_boot_timeout = info->on_boot_timeout,
+               .sched_priority = info->sched_priority,
        };
 
        if (!strcmp(info->exe, "null")) {
index 3788b90..c43986f 100644 (file)
@@ -44,6 +44,7 @@
 #define TAG_HYDRA                      "HYDRA"
 #define TAG_APP_CHECK                   "APP_CHECK"
 #define TAG_ON_BOOT_TIMEOUT             "ON_BOOT_TIMEOUT"
+#define TAG_SCHED_PRIORITY             "SCHED_PRIORITY"
 
 #define VAL_ON                         "ON"
 #define VAL_OFF                                "OFF"
@@ -62,7 +63,7 @@ static loader_info_t *__create_loader_info()
 {
        loader_info_t *info;
 
-       info = malloc(sizeof(loader_info_t));
+       info = calloc(1, sizeof(loader_info_t));
        if (info == NULL) {
                _E("Out of memory");
                return NULL;
@@ -312,6 +313,12 @@ static GList *__parse_file(GList *list, const char *path)
                                cur_info->app_check = false;
                } else if (strcasecmp(TAG_ON_BOOT_TIMEOUT, tok1) == 0) {
                        cur_info->on_boot_timeout = atoi(tok2);
+               } else if (strcasecmp(TAG_SCHED_PRIORITY, tok1) == 0) {
+                       cur_info->sched_priority = atoi(tok2);
+                       if (cur_info->sched_priority < -20)
+                               cur_info->sched_priority = -20;
+                       else if (cur_info->sched_priority > 19)
+                               cur_info->sched_priority = 19;
                }
        }
 
index d474ebc..f062423 100644 (file)
@@ -1049,15 +1049,17 @@ int _setup_stdio(const char *ident)
 
 int _set_priority(int prio)
 {
-       int r;
+       int ret;
 
-       r = setpriority(PRIO_PGRP, 0, prio);
-       if (r < 0) {
+       ret = setpriority(PRIO_PROCESS, 0, prio);
+       if (ret != 0) {
                SECURE_LOGE("Failed to set process(%d) priority(%d) - err(%d)",
                                getpid(), prio, errno);
+       } else {
+               SECURE_LOGD("priority(%d)", prio);
        }
 
-       return r;
+       return ret;
 }
 
 static int __dbus_send_message(DBusMessage *callback(void *), void *user_data,
index 7c4512f..a96f468 100644 (file)
@@ -577,6 +577,7 @@ API int launchpad_loader_main(int argc, char **argv,
                return -1;
        }
 
+       _set_priority(0);
        _D("[candidate] ecore main loop begin");
        __loader_adapter->loop_begin(__loader_user_data);