From: Unsung Lee Date: Wed, 9 Aug 2023 08:17:47 +0000 (+0900) Subject: plugin-api: resourced: Add cpu boosting module X-Git-Tag: accepted/tizen/unified/20230906.014630~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fd6bd3f76fe427c90ffa8af087de26713fdc90fb;p=platform%2Fcore%2Fsystem%2Flibsyscommon.git plugin-api: resourced: Add cpu boosting module Add cpu boosting governor function to be called when CPU PSI is triggered in resourced. The goal of cpu boosting governor is finding out cpu contention reason and making actions to do in cpu boosting controller. A new function called cpu boosting governor is added: - int syscommon_plugin_resourced_cpu_boosting_governor_govern_request (GHashTable *cpu_boosting_info_table, cpu_boosting_level_e cpu_boosting_level, GSList **cpu_boosting_controller_action); * This function receives cpu_boosting_info_table and cpu_boosting_level as inputs and gives cpu_boosting_controller_action as an output. If return value of this function is not 0, then cpu_boosting_controller_action is meaningless. Change-Id: Id6f7854278560fd8816a2e15021cccd7261b7027 Signed-off-by: Unsung Lee --- diff --git a/packaging/libsyscommon.spec b/packaging/libsyscommon.spec index bb2d003..4d2d613 100644 --- a/packaging/libsyscommon.spec +++ b/packaging/libsyscommon.spec @@ -20,6 +20,7 @@ BuildRequires: pkgconfig(gio-unix-2.0) BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(json-c) BuildRequires: pkgconfig(capi-system-info) +BuildRequires: pkgconfig(capi-system-resource) Requires: /bin/cp Requires(post): /sbin/ldconfig diff --git a/src/plugin-api/common/include/system/syscommon-plugin-common.h b/src/plugin-api/common/include/system/syscommon-plugin-common.h index 13b35d7..528c339 100644 --- a/src/plugin-api/common/include/system/syscommon-plugin-common.h +++ b/src/plugin-api/common/include/system/syscommon-plugin-common.h @@ -37,6 +37,7 @@ enum syscommon_plugin_module { SYSCOMMON_PLUGIN_MODULE_DEVICED_BATTERY, SYSCOMMON_PLUGIN_MODULE_DEVICED_INPUT, SYSCOMMON_PLUGIN_MODULE_DEVICED_DISPLAY, + SYSCOMMON_PLUGIN_MODULE_RESOURCED_CPU_BOOSTING, SYSCOMMON_PLUGIN_MODULE_END, }; diff --git a/src/plugin-api/common/src/syscommon-plugin-api-list.h b/src/plugin-api/common/src/syscommon-plugin-api-list.h index 9271370..248d699 100644 --- a/src/plugin-api/common/src/syscommon-plugin-api-list.h +++ b/src/plugin-api/common/src/syscommon-plugin-api-list.h @@ -60,6 +60,12 @@ static struct plugin_abi_version_match abi_version_match_data[SYSCOMMON_PLUGIN_M .backend_min_abi_version = SYSCOMMON_PLUGIN_ABI_VERSION_TIZEN_8_0, }, }, + [SYSCOMMON_PLUGIN_MODULE_RESOURCED_CPU_BOOSTING] = { + [0] = { + .platform_abi_version = SYSCOMMON_PLUGIN_ABI_VERSION_TIZEN_8_0, + .backend_min_abi_version = SYSCOMMON_PLUGIN_ABI_VERSION_TIZEN_8_0, + }, + }, }; static struct __plugin_module_info g_plugin_module_info[] = { @@ -111,6 +117,18 @@ static struct __plugin_module_info g_plugin_module_info[] = { .num_abi_versions = ARRAY_SIZE(abi_version_match_data[SYSCOMMON_PLUGIN_MODULE_DEVICED_DISPLAY]), .abi_versions = abi_version_match_data[SYSCOMMON_PLUGIN_MODULE_DEVICED_DISPLAY], }, + [SYSCOMMON_PLUGIN_MODULE_RESOURCED_CPU_BOOSTING] = { + .group = PLUGIN_GROUP_RESOURCED, + .module = SYSCOMMON_PLUGIN_MODULE_RESOURCED_CPU_BOOSTING, + .license = PLUGIN_LICENSE_APACHE_2_0, + .module_name = "SYSCOMMON_PLUGIN_MODULE_RESOURCED_CPU_BOOSTING", + .backend_module_name = "resourced-cpu-boosting", + .library_name = "/usr/lib/system/plugin/libplugin-backend-resourced-cpu-boosting.so", + .library_name_64bit = "/usr/lib64/system/plugin/libplugin-backend-resourced-cpu-boosting.so", + .symbol_name = "system_plugin_backend_resourced_cpu_boosting_data", + .num_abi_versions = ARRAY_SIZE(abi_version_match_data[SYSCOMMON_PLUGIN_MODULE_RESOURCED_CPU_BOOSTING]), + .abi_versions = abi_version_match_data[SYSCOMMON_PLUGIN_MODULE_RESOURCED_CPU_BOOSTING], + }, }; #endif /* __PLUGIN_API_LIST_H__ */ diff --git a/src/plugin-api/resourced/CMakeLists.txt b/src/plugin-api/resourced/CMakeLists.txt index d595753..7b9dbe4 100644 --- a/src/plugin-api/resourced/CMakeLists.txt +++ b/src/plugin-api/resourced/CMakeLists.txt @@ -16,12 +16,14 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../common/include) if (${PLUGIN_API_RESOURCED_ENABLE_DLOG}) SET(PKG_MODULES glib-2.0 - dlog) + dlog + capi-system-resource) ADD_DEFINITIONS("-DENABLE_DLOG") ADD_DEFINITIONS("-DLOG_TAG=\"SYSTEM_PLUGIN_API_RESOURCED\"") else() SET(PKG_MODULES - glib-2.0) + glib-2.0 + capi-system-resource) endif() INCLUDE(FindPkgConfig) @@ -41,6 +43,7 @@ SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") # Please remove them from SRCS and add 'syscommon-plugin-api-common' # to PKG_MODULES. SET(SRCS src/syscommon-plugin-resourced-memory-lmk.c + src/syscommon-plugin-resourced-cpu-boosting.c ../common/src/syscommon-plugin-api-common.c ../common/src/syscommon-plugin-api-conf.c) diff --git a/src/plugin-api/resourced/include/system/syscommon-plugin-resourced-cpu-boosting-interface.h b/src/plugin-api/resourced/include/system/syscommon-plugin-resourced-cpu-boosting-interface.h new file mode 100644 index 0000000..5e43274 --- /dev/null +++ b/src/plugin-api/resourced/include/system/syscommon-plugin-resourced-cpu-boosting-interface.h @@ -0,0 +1,62 @@ +/** + * MIT License + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef __SYSCOMMON_PLUGIN_RESOURCED_CPU_BOOSTING_INTERFACE_H__ +#define __SYSCOMMON_PLUGIN_RESOURCED_CPU_BOOSTING_INTERFACE_H__ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct syscommon_resourced_cpu_boosting_input { + cpu_boosting_input_t client_input; + int sock; + guint *gsource_id; + bool remove_input; +}; + +struct syscommon_resourced_cpu_boosting_info { + pid_t tid; + cpu_boosting_level_e level; /* current boosting level */ + guint gsource_id; /* timer id */ + int ref_cnt; /* reference count */ + cpu_boosting_flag_e cpu_boosting_flags; +}; + +typedef struct _syscommon_plugin_backend_resourced_cpu_boosting_funcs { + int (*cpu_boosting_governor_govern_request) ( + GHashTable *cpu_boosting_info_table, + cpu_boosting_level_e cpu_boosting_level, + GSList **cpu_boosting_controller_action) +} syscommon_plugin_backend_resourced_cpu_boosting_funcs; + +#ifdef __cplusplus +} +#endif + +#endif /* __SYSCOMMON_PLUGIN_RESOURCED_CPU_BOOSTING_INTERFACE_H__ */ diff --git a/src/plugin-api/resourced/include/system/syscommon-plugin-resourced-cpu-boosting.h b/src/plugin-api/resourced/include/system/syscommon-plugin-resourced-cpu-boosting.h new file mode 100644 index 0000000..1242b73 --- /dev/null +++ b/src/plugin-api/resourced/include/system/syscommon-plugin-resourced-cpu-boosting.h @@ -0,0 +1,67 @@ +/** + * MIT License + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef __SYSCOMMON_PLUGIN_RESOURCED_CPU_BOOSTING_H__ +#define __SYSCOMMON_PLUGIN_RESOURCED_CPU_BOOSTING_H__ + +#include "syscommon-plugin-resourced-cpu-boosting-interface.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Get the backend data of resourced-cpu-boosting module + * @return @c 0 on success, otherwise a negative error value + */ +int syscommon_plugin_resourced_cpu_boosting_get_backend(void); + +/** + * @brief Put the backend data of resourced-cpu-boosting module + * @return @c 0 on success, otherwise a negative error value + */ +int syscommon_plugin_resourced_cpu_boosting_put_backend(void); + +/** + * @brief Analyze cpu contention reason and + * make a list to do for cpu boosting controller + * @param[in] cpu_boosting_info_table is a GHashTable containing cpu boosting info + * of the currently boosted thread + * @param[in] cpu_boosting_level is cpu boosting level among CPU_BOOSTING_LEVEL_STRONG, + * CPU_BOOSTING_LEVEL_MEDIUM, and CPU_BOOSTING_LEVEL_WEAK + * @param[out] cpu_boosting_controller_action is a GSList containing actions + * to be taken by cpu boosting controller + * @return @c zero on success, + * otherwise a negative error value + */ +int syscommon_plugin_resourced_cpu_boosting_governor_govern_request( + GHashTable *cpu_boosting_info_table, + cpu_boosting_level_e cpu_boosting_level, + GSList **cpu_boosting_controller_action); + +#ifdef __cplusplus +} +#endif + +#endif /* __SYSCOMMON_PLUGIN_RESOURCED_CPU_BOOSTING_H__ */ diff --git a/src/plugin-api/resourced/src/syscommon-plugin-resourced-cpu-boosting.c b/src/plugin-api/resourced/src/syscommon-plugin-resourced-cpu-boosting.c new file mode 100644 index 0000000..1bd8eea --- /dev/null +++ b/src/plugin-api/resourced/src/syscommon-plugin-resourced-cpu-boosting.c @@ -0,0 +1,104 @@ +/** + * MIT License + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include + +#include +#include + +#ifndef EXPORT +#define EXPORT __attribute__((visibility("default"))) +#endif + +static syscommon_plugin_backend_resourced_cpu_boosting_funcs *funcs = NULL; + +EXPORT +int syscommon_plugin_resourced_cpu_boosting_get_backend(void) +{ + int ret = 0; + + if (funcs) + return 0; + + ret = syscommon_plugin_common_get_backend( + SYSCOMMON_PLUGIN_MODULE_RESOURCED_CPU_BOOSTING, + (void **)&funcs); + if (ret < 0) { + _E("Failed to get resourced_cpu_boosting backend: %d", ret); + return ret; + } + + _I("Success to get resourced_cpu_boosting backend: %d", ret); + + return 0; +} + +EXPORT +int syscommon_plugin_resourced_cpu_boosting_put_backend(void) +{ + int ret = 0; + + if (!funcs) + return 0; + + ret = syscommon_plugin_common_put_backend( + SYSCOMMON_PLUGIN_MODULE_RESOURCED_CPU_BOOSTING, + (void *)funcs); + if (ret < 0) { + _E("Failed to put resourced_cpu_boosting backend: %d", ret); + return ret; + } + funcs = NULL; + + _I("Success to put resourced_cpu_boosting backend: %d", ret); + + return 0; +} + +EXPORT +int syscommon_plugin_resourced_cpu_boosting_governor_govern_request( + GHashTable *cpu_boosting_info_table, + cpu_boosting_level_e cpu_boosting_level, + GSList **cpu_boosting_controller_action) + +{ + int ret = 0; + + if (!funcs) { + ret = syscommon_plugin_resourced_cpu_boosting_get_backend(); + if (ret < 0) + return ret; + } + + assert(funcs); + if (!funcs->cpu_boosting_governor_govern_request) { + _E("No \"cpu_boosting_governor_govern_request\" function"); + return -ENOTSUP; + } + + return funcs->cpu_boosting_governor_govern_request(cpu_boosting_info_table, + cpu_boosting_level, cpu_boosting_controller_action); +}