From f5904e98b9fd58381960f143b0f99a0917f36e89 Mon Sep 17 00:00:00 2001 From: SangYoun Kwak Date: Fri, 10 Feb 2023 16:52:29 +0900 Subject: [PATCH] Modify module name, add dlog and add governor Module name changed. * low_memory_killer -> resourced-memory-lmk * According to this, the name of library, source directory, source file name, and symbols are modified. Governor source code added. Dlog feature is added. Signed-off-by: SangYoun Kwak --- CMakeLists.txt | 2 +- packaging/plugin-backend-resourced-rpi.spec | 4 +- src/low_memory_killer/low_memory_killer.c | 40 ------------ .../CMakeLists.txt | 16 +++-- src/resourced-memory-lmk/common.h | 36 +++++++++++ .../resourced-memory-lmk-governor.c | 29 +++++++++ .../resourced-memory-lmk-governor.h | 24 +++++++ .../resourced-memory-lmk.c | 64 +++++++++++++++++++ 8 files changed, 168 insertions(+), 47 deletions(-) delete mode 100644 src/low_memory_killer/low_memory_killer.c rename src/{low_memory_killer => resourced-memory-lmk}/CMakeLists.txt (61%) create mode 100644 src/resourced-memory-lmk/common.h create mode 100644 src/resourced-memory-lmk/resourced-memory-lmk-governor.c create mode 100644 src/resourced-memory-lmk/resourced-memory-lmk-governor.h create mode 100644 src/resourced-memory-lmk/resourced-memory-lmk.c diff --git a/CMakeLists.txt b/CMakeLists.txt index a319c08..ef29410 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,4 +12,4 @@ ENDIF() INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.Apache-2.0 DESTINATION ${PLUGIN_LICENSE_DIR}) -ADD_SUBDIRECTORY(src/low_memory_killer) +ADD_SUBDIRECTORY(src/resourced-memory-lmk) diff --git a/packaging/plugin-backend-resourced-rpi.spec b/packaging/plugin-backend-resourced-rpi.spec index c8486a0..b7cca95 100644 --- a/packaging/plugin-backend-resourced-rpi.spec +++ b/packaging/plugin-backend-resourced-rpi.spec @@ -1,4 +1,4 @@ -%define PLUGIN_LIBDIR %{_libdir}/plugin/%{name} +%define PLUGIN_LIBDIR %{_libdir}/plugin %define PLUGIN_LICENSEDIR /usr/share/plugin/%{name} Name: plugin-backend-resourced-rpi @@ -42,6 +42,6 @@ make %{?jobs:-j%jobs} /sbin/ldconfig %files -%{PLUGIN_LIBDIR}/libplugin-backend-resourced-low_memory_killer.so +%{PLUGIN_LIBDIR}/libplugin-backend-resourced-memory-lmk.so %manifest %{name}.manifest %{PLUGIN_LICENSEDIR}/LICENSE.Apache-2.0 diff --git a/src/low_memory_killer/low_memory_killer.c b/src/low_memory_killer/low_memory_killer.c deleted file mode 100644 index a5461c9..0000000 --- a/src/low_memory_killer/low_memory_killer.c +++ /dev/null @@ -1,40 +0,0 @@ -#include - -#include -#include - -#define EXPORT __attribute__ ((visibility("default"))) - -GArray *get_kill_candidates(GSList *proc_app_list, int start_oom, int end_oom, int killer_flags) -{ - return (GArray *)100; -} - -int low_memory_killer_init(void **data) -{ - plugin_backend_low_memory_killer_funcs *funcs = NULL; - - funcs = calloc(1, sizeof(*funcs)); - if (!funcs) - return -ENOMEM; - - funcs->get_kill_candidates = get_kill_candidates; - - *data = (void *)funcs; - - return 0; -} - -int low_memory_killer_exit(void *data) -{ - free(data); - return 0; -} - -plugin_backend EXPORT plugin_backend_resourced_low_memory_killer_data = { - .name = "low_memory_killer", - .vendor = "Samsung", - .abi_version = PLUGIN_ABI_VERSION_TIZEN_7_5, - .init = low_memory_killer_init, - .exit = low_memory_killer_exit, -}; diff --git a/src/low_memory_killer/CMakeLists.txt b/src/resourced-memory-lmk/CMakeLists.txt similarity index 61% rename from src/low_memory_killer/CMakeLists.txt rename to src/resourced-memory-lmk/CMakeLists.txt index 7aa1534..dfec877 100644 --- a/src/low_memory_killer/CMakeLists.txt +++ b/src/resourced-memory-lmk/CMakeLists.txt @@ -1,10 +1,18 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(plugin-backend-resourced-low_memory_killer C) +PROJECT(plugin-backend-resourced-memory-lmk C) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) -SET(PKG_MODULES - libsyscommon) +if (${PLUGIN_BACKEND_RESOURCED_MEMORY_LMK_ENABLE_DLOG}) + SET(PKG_MODULES + libsyscommon + glib-2.0) + ADD_DEFINITIONS("-DENABLE_DLOG") + ADD_DEFINITIONS("-DLOG_TAG=\"PLUGIN_BACKEND_RESOURCED_MEMORY_LMK\"") +else() + SET(PKG_MODULES + libsyscommon) +endif() INCLUDE(FindPkgConfig) pkg_check_modules(pkgs REQUIRED ${PKG_MODULES}) @@ -15,7 +23,7 @@ ENDFOREACH(flag) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") -ADD_LIBRARY(${PROJECT_NAME} SHARED low_memory_killer.c) +ADD_LIBRARY(${PROJECT_NAME} SHARED resourced-memory-lmk.c) MESSAGE("pkgs_LDFLAGS: ${pkgs_LDFLAGS}") TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS}) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${PLUGIN_LIB_DIR} COMPONENT RuntimeLibraries) diff --git a/src/resourced-memory-lmk/common.h b/src/resourced-memory-lmk/common.h new file mode 100644 index 0000000..1591089 --- /dev/null +++ b/src/resourced-memory-lmk/common.h @@ -0,0 +1,36 @@ +/** + * plugin-backend-resourced-rpi + * + * Copyright (c) 2023 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 __COMMON_H__ +#define __COMMON_H__ + +#ifdef ENABLE_DLOG +#include + +#define _D(fmt, args...) SLOGD(fmt, ##args) +#define _I(fmt, args...) SLOGI(fmt, ##args) +#define _W(fmt, args...) SLOGW(fmt, ##args) +#define _E(fmt, args...) SLOGE(fmt, ##args) +#else +#define _D(fmt, args...) do { } while(0) +#define _I(fmt, args...) do { } while(0) +#define _W(fmt, args...) do { } while(0) +#define _E(fmt, args...) do { } while(0) +#endif + +#endif /* __COMMON_H__ */ diff --git a/src/resourced-memory-lmk/resourced-memory-lmk-governor.c b/src/resourced-memory-lmk/resourced-memory-lmk-governor.c new file mode 100644 index 0000000..2251e58 --- /dev/null +++ b/src/resourced-memory-lmk/resourced-memory-lmk-governor.c @@ -0,0 +1,29 @@ +/** + * plugin-backend-resourced-rpi + * + * Copyright (c) 2023 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. + */ + +#include + +#include "common.h" +#include "resourced-memory-lmk-governor.h" + +GArray *lowmem_governor_get_kill_candidates(GSList *proc_app_list, int start_oom, int end_oom, int killer_flags) +{ + _D("lowmem_governor_get_kill_candidates called"); + + return NULL; +} diff --git a/src/resourced-memory-lmk/resourced-memory-lmk-governor.h b/src/resourced-memory-lmk/resourced-memory-lmk-governor.h new file mode 100644 index 0000000..9328607 --- /dev/null +++ b/src/resourced-memory-lmk/resourced-memory-lmk-governor.h @@ -0,0 +1,24 @@ +/** + * plugin-backend-resourced-rpi + * + * Copyright (c) 2023 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 __RESOURCED_MEMORY_LMK_GOVERNOR_H__ +#define __RESOURCED_MEMORY_LMK_GOVERNOR_H__ + +GArray *lowmem_governor_get_kill_candidates(GSList *proc_app_list, int start_oom, int end_oom, int killer_flags); + +#endif /* __RESOURCED_MEMORY_LMK_GOVERNOR_H__ */ diff --git a/src/resourced-memory-lmk/resourced-memory-lmk.c b/src/resourced-memory-lmk/resourced-memory-lmk.c new file mode 100644 index 0000000..39b0b4a --- /dev/null +++ b/src/resourced-memory-lmk/resourced-memory-lmk.c @@ -0,0 +1,64 @@ +/** + * plugin-backend-resourced-rpi + * + * Copyright (c) 2023 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. + */ + +#include + +#include +#include + +#include "common.h" +#include "resourced-memory-lmk-governor.h" /* TODO: Remove this line */ + +#define EXPORT __attribute__ ((visibility("default"))) + +/* +GArray *get_kill_candidates(GSList *proc_app_list, int start_oom, int end_oom, int killer_flags) +{ + return NULL; +} +*/ + +int resourced_memory_lmk_init(void **data) +{ + plugin_backend_resourced_memory_lmk_funcs *funcs = NULL; + + funcs = calloc(1, sizeof(*funcs)); + if (!funcs) + return -ENOMEM; + + /* funcs->get_kill_candidates = get_kill_candidates; */ /* TODO: Use this line instead of a line below */ + funcs->get_kill_candidates = lowmem_governor_get_kill_candidates; /* TODO: Remove this line */ + + *data = (void *)funcs; + + return 0; +} + +int resourced_memory_lmk_exit(void *data) +{ + free(data); + return 0; +} + +plugin_backend EXPORT plugin_backend_resourced_memory_lmk_data = { + .name = "resourced-memory-lmk", + .vendor = "Samsung", + .abi_version = PLUGIN_ABI_VERSION_TIZEN_7_5, + .init = resourced_memory_lmk_init, + .exit = resourced_memory_lmk_exit, +}; -- 2.34.1