diff options
author | Hwankyu Jhun <h.jhun@samsung.com> | 2020-05-19 09:45:43 +0900 |
---|---|---|
committer | Hwankyu Jhun <h.jhun@samsung.com> | 2020-05-19 09:45:43 +0900 |
commit | cb7a1b22ecbdaeb2dad96f0ad6b234956e526142 (patch) | |
tree | 52565036b6c00431d5f7a998746d7f400a0151bf | |
parent | 499f8710606badf7dc620dc1a76d480b93859bc4 (diff) | |
parent | d1488f6d5ec4f7e86d6512323be1702dc3db7e66 (diff) | |
download | launchpad-cb7a1b22ecbdaeb2dad96f0ad6b234956e526142.tar.gz launchpad-cb7a1b22ecbdaeb2dad96f0ad6b234956e526142.tar.bz2 launchpad-cb7a1b22ecbdaeb2dad96f0ad6b234956e526142.zip |
Merge branch 'tizen' into tizen_5.5submit/tizen_5.5/20200519.004557accepted/tizen/5.5/unified/20200519.155031
Change-Id: I7cfd4200c60a9e7e25178907a94434ae27be1ea9
-rw-r--r-- | packaging/launchpad.spec | 2 | ||||
-rw-r--r-- | src/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/common/inc/launchpad_plugin.h | 24 | ||||
-rw-r--r-- | src/common/src/launchpad_plugin.c | 62 | ||||
-rw-r--r-- | src/launchpad/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/launchpad/conf/launchpad.conf.in | 3 | ||||
-rw-r--r-- | src/launchpad/inc/launchpad_config.h | 1 | ||||
-rw-r--r-- | src/launchpad/src/launchpad.c | 37 | ||||
-rw-r--r-- | src/launchpad/src/launchpad_config.c | 36 | ||||
-rw-r--r-- | src/lib/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/lib/src/launchpad_lib.c | 7 |
11 files changed, 172 insertions, 10 deletions
diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index e39fa09..9218b71 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.14.5 +Version: 0.15.0 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 352038e..de3c1c6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,5 +7,5 @@ ADD_SUBDIRECTORY(app-defined-loader) ADD_SUBDIRECTORY(hydra) ADD_SUBDIRECTORY(parser) -ADD_DEPENDENCIES(launchpad-loader launchpad-lib) -ADD_DEPENDENCIES(app-defined-loader launchpad-lib) +ADD_DEPENDENCIES(launchpad-loader liblaunchpad) +ADD_DEPENDENCIES(app-defined-loader liblaunchpad) diff --git a/src/common/inc/launchpad_plugin.h b/src/common/inc/launchpad_plugin.h new file mode 100644 index 0000000..f2cf987 --- /dev/null +++ b/src/common/inc/launchpad_plugin.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __LAUNCHPAD_PLUGIN_H__ +#define __LAUNCHPAD_PLUGIN_H__ + +#include <bundle.h> + +int _launchpad_plugin_prepare_app(const char *app_id, bundle *kb); + +#endif /* __LAUNCHPAD_PLUGIN_H__ */ diff --git a/src/common/src/launchpad_plugin.c b/src/common/src/launchpad_plugin.c new file mode 100644 index 0000000..912c19d --- /dev/null +++ b/src/common/src/launchpad_plugin.c @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define _GNU_SOURCE +#include <dlfcn.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "launchpad_plugin.h" +#include "log_private.h" + +#define PATH_LAUNCHPAD_PLUGIN "/usr/share/aul/plugin/liblaunchpad-plugin.so" +#define TAG_LAUNCHPAD_PLUGIN_PREPARE_APP "LAUNCHPAD_PLUGIN_PREPARE_APP" + +int _launchpad_plugin_prepare_app(const char *app_id, bundle *kb) +{ + void *handle; + int (*prepare_app)(const char *, bundle *); + int ret; + + ret = access(PATH_LAUNCHPAD_PLUGIN, F_OK); + if (ret != 0) { + _D("plugin module does not exist. errno(%d)", errno); + return 0; + } + + handle = dlopen(PATH_LAUNCHPAD_PLUGIN, RTLD_LAZY | RTLD_LOCAL); + if (!handle) { + _W("Failed to open plugin so. error(%s)", dlerror()); + return 0; + } + + prepare_app = dlsym(handle, TAG_LAUNCHPAD_PLUGIN_PREPARE_APP); + if (!prepare_app) { + _W("Failed to load %s", TAG_LAUNCHPAD_PLUGIN_PREPARE_APP); + dlclose(handle); + return 0; + } + + _W("LAUNCHPAD_PLUGIN_PREPARE_APP ++"); + ret = prepare_app(app_id, kb); + _W("LAUNCHPAD_PLUGIN_PREPARE_APP --"); + if (ret != 0) + return -1; + + return 0; +} diff --git a/src/launchpad/CMakeLists.txt b/src/launchpad/CMakeLists.txt index a51f395..39ce5c8 100644 --- a/src/launchpad/CMakeLists.txt +++ b/src/launchpad/CMakeLists.txt @@ -53,9 +53,9 @@ SET(LAUNCHPAD_PROCESS_POOL_SOURCE_FILES ADD_EXECUTABLE(${LAUNCHPAD_PROCESS_POOL} ${LAUNCHPAD_PROCESS_POOL_SOURCE_FILES}) IF(_TIZEN_FEATURE_PRELINK) -TARGET_LINK_LIBRARIES(${LAUNCHPAD_PROCESS_POOL} ${LAUNCHPAD_PROCESS_POOL_PKGS_LDFLAGS} "-lm") +TARGET_LINK_LIBRARIES(${LAUNCHPAD_PROCESS_POOL} ${LAUNCHPAD_PROCESS_POOL_PKGS_LDFLAGS} "-lm -ldl") ELSE(_TIZEN_FEATURE_PRELINK) -TARGET_LINK_LIBRARIES(${LAUNCHPAD_PROCESS_POOL} ${LAUNCHPAD_PROCESS_POOL_PKGS_LDFLAGS} "-pie -lm") +TARGET_LINK_LIBRARIES(${LAUNCHPAD_PROCESS_POOL} ${LAUNCHPAD_PROCESS_POOL_PKGS_LDFLAGS} "-pie -lm -ldl") ENDIF(_TIZEN_FEATURE_PRELINK) SET_TARGET_PROPERTIES(${LAUNCHPAD_PROCESS_POOL} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_pool}) diff --git a/src/launchpad/conf/launchpad.conf.in b/src/launchpad/conf/launchpad.conf.in index 3615188..6e7e6b2 100644 --- a/src/launchpad/conf/launchpad.conf.in +++ b/src/launchpad/conf/launchpad.conf.in @@ -7,3 +7,6 @@ NormalValue=1 [MemoryMonitor] Threshold=80 Interval=5000 + +[CpuChecker] +MaxCount=10 diff --git a/src/launchpad/inc/launchpad_config.h b/src/launchpad/inc/launchpad_config.h index 1d2ee1e..328f839 100644 --- a/src/launchpad/inc/launchpad_config.h +++ b/src/launchpad/inc/launchpad_config.h @@ -24,6 +24,7 @@ typedef enum { CONFIG_TYPE_MEMORY_STATUS_NORMAL_VALUE, CONFIG_TYPE_MEMORY_MONITOR_THRESHOLD, CONFIG_TYPE_MEMORY_MONITOR_INTERVAL, + CONFIG_TYPE_CPU_CHECKER_MAX_COUNT, } config_type_e; const char *_config_get_string_value(config_type_e type); diff --git a/src/launchpad/src/launchpad.c b/src/launchpad/src/launchpad.c index da7042b..9c7239d 100644 --- a/src/launchpad/src/launchpad.c +++ b/src/launchpad/src/launchpad.c @@ -47,6 +47,7 @@ #include "launchpad_inotify.h" #include "launchpad_io_channel.h" #include "launchpad_memory_monitor.h" +#include "launchpad_plugin.h" #include "launchpad_proc.h" #include "launchpad_signal.h" #include "launchpad_types.h" @@ -122,6 +123,7 @@ typedef struct { io_channel_h hydra_channel; unsigned int score; unsigned int pss; + int cpu_check_count; } candidate_process_context_t; typedef struct { @@ -167,6 +169,7 @@ static int __memory_status_normal; static sequencer __sequencer; static int MEMORY_STATUS_LOW; static int MEMORY_STATUS_NORMAL; +static int MAX_CPU_CHECK_COUNT; static io_channel_h __logger_channel; static io_channel_h __label_monitor_channel; @@ -231,6 +234,7 @@ static gboolean __handle_queuing_slots(gpointer data) _get_cpu_idle(&total, &idle); cpc->cpu_idle_time = idle; cpc->cpu_total_time = total; + cpc->cpu_check_count = 0; __sequencer.idle_checker = g_timeout_add(CPU_CHECKER_TIMEOUT, __handle_idle_checker, cpc); @@ -1208,6 +1212,12 @@ static int __prepare_exec(const char *appid, const char *app_path, /* TODO : should be add to check permission in the kernel*/ setsid(); + ret = _launchpad_plugin_prepare_app(appid, kb); + if (ret < 0) { + _E("_launchpad_plugin_prepare_app() is failed. error(%d)", ret); + return PAD_ERR_FAILED; + } + ret = _enable_external_pkg(kb, menu_info->pkgid, menu_info->global ? GLOBAL_USER : getuid()); if (ret < 0) @@ -1603,14 +1613,16 @@ static gboolean __handle_idle_checker(gpointer data) cpc = (candidate_process_context_t *)data; if (cpc->app_check && !cpc->app_exists) { - _W("The application is not installed. Type(%d)", cpc->type); + _W("The application is not installed. loader(%s:%d)", + cpc->loader_name, cpc->type); __sequencer.idle_checker = 0; __sequencer.running_cpc = NULL; return G_SOURCE_REMOVE; } if (cpc->state != CANDIDATE_PROCESS_STATE_RUNNING) { - _W("Slot state is not running. Type(%d)", cpc->type); + _W("Slot state is not running. loader(%s:%d)", + cpc->loader_name, cpc->type); __sequencer.idle_checker = 0; __sequencer.running_cpc = NULL; return G_SOURCE_REMOVE; @@ -1621,7 +1633,7 @@ static gboolean __handle_idle_checker(gpointer data) total++; per = (idle - cpc->cpu_idle_time) * 100 / (total - cpc->cpu_total_time); - _D("[CPU] Idle : %d / type : %d", per, cpc->type); + _D("[CPU] Idle : %d / loader(%s:%d)", per, cpc->loader_name, cpc->type); if (per >= cpc->threshold) { __update_threshold(cpc, -0.02f * (per - cpc->threshold)); @@ -1636,6 +1648,18 @@ static gboolean __handle_idle_checker(gpointer data) cpc->cpu_total_time = total; __update_threshold(cpc, 0.05f); + cpc->cpu_check_count++; + if (cpc->cpu_check_count == MAX_CPU_CHECK_COUNT) { + _W("CPU check count has exceeded %d times. loader(%s:%d)", + cpc->cpu_check_count, + cpc->loader_name, + cpc->type); + __sequencer.idle_checker = 0; + __sequencer.running_cpc = NULL; + __sequencer_add_slot(cpc); + return G_SOURCE_REMOVE; + } + return G_SOURCE_CONTINUE; } @@ -2298,6 +2322,7 @@ static candidate_process_context_t *__create_slot(int type, int loader_id, cpc->app_check = app_check; cpc->score = WIN_SCORE; cpc->pss = 0; + cpc->cpu_check_count = 0; if ((cpc->deactivation_method & METHOD_OUT_OF_MEMORY) && __is_low_memory()) @@ -2305,6 +2330,8 @@ static candidate_process_context_t *__create_slot(int type, int loader_id, else cpc->state = CANDIDATE_PROCESS_STATE_RUNNING; + _W("loader(%s), type(%d), state(%d)", + cpc->loader_name, cpc->type, cpc->state); return cpc; } @@ -2873,12 +2900,12 @@ static int __memory_monitor_cb(bool low_memory, void *user_data) { candidate_process_context_t *cpc; - _W("low memory(%s)", low_memory ? "true" : "false"); cpc = __get_running_slot(false); if (!cpc && low_memory) return -1; if (low_memory) { + _W("Low memory"); __update_slots_pss(); candidate_slot_list = g_list_sort(candidate_slot_list, @@ -2936,6 +2963,8 @@ static int __before_loop(int argc, char **argv) _inotify_init(); + MAX_CPU_CHECK_COUNT = _config_get_int_value( + CONFIG_TYPE_CPU_CHECKER_MAX_COUNT); __add_default_slots(); launcher_info_list = _launcher_info_load(LAUNCHER_INFO_PATH); diff --git a/src/launchpad/src/launchpad_config.c b/src/launchpad/src/launchpad_config.c index 5b517b0..0838dd7 100644 --- a/src/launchpad/src/launchpad_config.c +++ b/src/launchpad/src/launchpad_config.c @@ -40,6 +40,9 @@ #define KEY_MEMORY_MONITOR_THRESHOLD "Threshold" #define KEY_MEMORY_MONITOR_INTERVAL "Interval" +#define TAG_CPU_CHECKER "CpuChecker" +#define KEY_CPU_CHECKER_MAX_COUNT "MaxCount" + struct memory_status_s { char *low_key; int low_value; @@ -52,8 +55,13 @@ struct memory_monitor_s { int interval; }; +struct cpu_checker_s { + int max_count; +}; + static struct memory_status_s __memory_status; static struct memory_monitor_s __memory_monitor; +static struct cpu_checker_s __cpu_checker; const char *_config_get_string_value(config_type_e type) { @@ -92,6 +100,9 @@ int _config_get_int_value(config_type_e type) case CONFIG_TYPE_MEMORY_MONITOR_INTERVAL: value = __memory_monitor.interval; break; + case CONFIG_TYPE_CPU_CHECKER_MAX_COUNT: + value = __cpu_checker.max_count; + break; default: _E("Unknown type"); value = INT_MIN; @@ -208,6 +219,28 @@ static void __memory_monitor_set(dictionary *d) __memory_monitor.interval); } +static void __cpu_checker_init(void) +{ + __cpu_checker.max_count = 10; +} + +static void __cpu_checker_fini(void) +{ + __cpu_checker.max_count = 0; +} + +static void __cpu_checker_set(dictionary *d) +{ + int ret; + + ret = __get_int_value(d, TAG_CPU_CHECKER, + KEY_CPU_CHECKER_MAX_COUNT); + if (ret != INT_MAX) + __cpu_checker.max_count = ret; + + _W("CPU Checker MaxCount(%d)", __cpu_checker.max_count); +} + int _config_init(void) { dictionary *d; @@ -217,6 +250,7 @@ int _config_init(void) __memory_status_init(); __memory_monitor_init(); + __cpu_checker_init(); ret = access(PATH_LAUNCHPAD_CONF, F_OK); if (ret != 0) { @@ -232,6 +266,7 @@ int _config_init(void) __memory_status_set(d); __memory_monitor_set(d); + __cpu_checker_set(d); iniparser_freedict(d); @@ -242,6 +277,7 @@ void _config_fini(void) { _D("config fini"); + __cpu_checker_fini(); __memory_monitor_fini(); __memory_status_fini(); } diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index d5a2ecd..1d42ce0 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -1,5 +1,5 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8) -PROJECT(launchpad-lib C) +PROJECT(liblaunchpad C) SET(LAUNCHPAD_LIB "launchpad") INCLUDE(FindPkgConfig) diff --git a/src/lib/src/launchpad_lib.c b/src/lib/src/launchpad_lib.c index 45a59f9..d9d4434 100644 --- a/src/lib/src/launchpad_lib.c +++ b/src/lib/src/launchpad_lib.c @@ -35,6 +35,7 @@ #include "launchpad.h" #include "launchpad_common.h" +#include "launchpad_plugin.h" #include "launchpad_types.h" #include "preexec.h" @@ -71,6 +72,12 @@ static int __prepare_exec(const char *appid, const char *app_path, __preexec_run(pkg_type, appid, app_path); + ret = _launchpad_plugin_prepare_app(appid, kb); + if (ret != 0) { + _E("_launchpad_plugin_prepare_app() is failed. error(%d)", ret); + return -1; + } + ret = _enable_external_pkg(kb, pkgid, global ? GLOBAL_USER : getuid()); if (ret < 0) return -1; |