diff options
author | Hwankyu Jhun <h.jhun@samsung.com> | 2024-04-08 17:42:48 +0900 |
---|---|---|
committer | Hwankyu Jhun <h.jhun@samsung.com> | 2024-04-08 19:46:16 +0900 |
commit | c4c77d457291869b63954caf89ae9bc43b623c8e (patch) | |
tree | 9c7a646b8477e42a69f22f78ee2c044b1ddf2829 | |
parent | c7ea394a9d05ce382430027eb431de48da143d26 (diff) | |
download | aul-1-c4c77d457291869b63954caf89ae9bc43b623c8e.tar.gz aul-1-c4c77d457291869b63954caf89ae9bc43b623c8e.tar.bz2 aul-1-c4c77d457291869b63954caf89ae9bc43b623c8e.zip |
Add blink feature for daemon processes
The term "blink" is utilized to denote momentary movement.
If the environmental variable "AUL_BLINK=1" is present, the AUL library will
initiate boosting for the process as soon as it is loaded.
The "AUL_BLINK_TIMEOUT" is a variable that enables the setting of
a time-out duration. The unit of measurement is milliseconds, with
a default value of 5000 milliseconds.
Change-Id: I93dd570b7d442d0033e409b2f9a6a352f864ccbd
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | packaging/aul.spec | 1 | ||||
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/aul/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/blink/CMakeLists.txt | 18 | ||||
-rw-r--r-- | src/blink/aul_blink.cc | 102 | ||||
-rw-r--r-- | src/blink/log_private.hh | 37 |
7 files changed, 162 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index f432afe9..14e86ac7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,7 @@ SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ## Target SET(TARGET_AUL "aul") SET(TARGET_AUL_SERVER "aul-server") +SET(TARGET_AUL_BLINK "aul-blink") ENABLE_TESTING() SET(TARGET_AUL_UNIT_TESTS "aul-unit-tests") diff --git a/packaging/aul.spec b/packaging/aul.spec index 99f23076..4e8cfc93 100644 --- a/packaging/aul.spec +++ b/packaging/aul.spec @@ -272,6 +272,7 @@ chsmack -a 'User::Home' %{TZ_SYS_DB}/.component.db-journal %license LICENSE %manifest %{name}.manifest %attr(0644,root,root) %{_libdir}/libaul.so.* +%attr(0644,root,root) %{_libdir}/libaul-blink.so %config %{_sysconfdir}/dbus-1/system.d/aul.conf %{_bindir}/aulctl %{_bindir}/aul_test diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 341502bb..b0db2600 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,5 @@ ADD_SUBDIRECTORY(aul) +ADD_SUBDIRECTORY(blink) ADD_SUBDIRECTORY(parser) ADD_SUBDIRECTORY(rsc-mgr) ADD_SUBDIRECTORY(server) diff --git a/src/aul/CMakeLists.txt b/src/aul/CMakeLists.txt index 2d9de984..f09929dc 100644 --- a/src/aul/CMakeLists.txt +++ b/src/aul/CMakeLists.txt @@ -53,6 +53,8 @@ APPLY_PKG_CONFIG(${TARGET_AUL} PUBLIC XDGMIME_DEPS ) +TARGET_LINK_LIBRARIES(${TARGET_AUL} PRIVATE ${TARGET_AUL_BLINK}) + INSTALL(TARGETS ${TARGET_AUL} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) diff --git a/src/blink/CMakeLists.txt b/src/blink/CMakeLists.txt new file mode 100644 index 00000000..4fe5d303 --- /dev/null +++ b/src/blink/CMakeLists.txt @@ -0,0 +1,18 @@ +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SRCS) + +ADD_LIBRARY(${TARGET_AUL_BLINK} SHARED ${SRCS}) + +TARGET_INCLUDE_DIRECTORIES(${TARGET_AUL_BLINK} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/../ +) + +APPLY_PKG_CONFIG(${TARGET_AUL_BLINK} PUBLIC + CAPI_SYSTEM_RESOURCE_DEPS + DLOG_DEPS + GLIB_DEPS +) + +INSTALL(TARGETS ${TARGET_AUL_BLINK} + DESTINATION ${LIB_INSTALL_DIR} + COMPONENT RuntimeLibraries) diff --git a/src/blink/aul_blink.cc b/src/blink/aul_blink.cc new file mode 100644 index 00000000..13d8e76f --- /dev/null +++ b/src/blink/aul_blink.cc @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2024 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 <cpu-boosting.h> +#include <glib.h> +#include <sys/types.h> +#include <unistd.h> + +#include <cctype> + +#include "blink/log_private.hh" + +namespace aul { + +constexpr const char kAulBlink[] = "AUL_BLINK"; +constexpr const char kAulBlinkTimeout[] = "AUL_BLINK_TIMEOUT"; + +class Blink { + public: + Blink() { + const char* blink_str = getenv(kAulBlink); + if (blink_str && !strcmp(blink_str, "1")) { + const char* timeout = getenv(kAulBlinkTimeout); + if (timeout && isdigit(timeout[0])) + timeout_ = atoi(timeout); + + Set(); + } + } + + ~Blink() { Clear(); } + + private: + void Set() { + pid_t pid = getpid(); + resource_pid_t res_pid = { + .pid = 0, + .tid = &pid, + .tid_count = 1, + }; + + int ret = + resource_set_cpu_boosting(res_pid, CPU_BOOSTING_LEVEL_STRONG, + CPU_BOOSTING_RESET_ON_FORK, -1); + if (ret != 0) { + _E("resource_set_cpu_boosting() is failed. error=%d", ret); + return; + } + + source_ = g_timeout_add(timeout_, OnTimeout, this); + enabled_ = true; + _W("Set"); + } + + void Clear() { + if (source_ != 0) { + g_source_remove(source_); + source_ = 0; + } + + if (enabled_) { + pid_t pid = getpid(); + resource_pid_t res_pid = { + .pid = 0, + .tid = &pid, + .tid_count = 1, + }; + resource_clear_cpu_boosting(res_pid); + enabled_ = false; + _W("Clear"); + } + } + + static gboolean OnTimeout(gpointer user_data) { + auto* blink = static_cast<Blink*>(user_data); + blink->source_ = 0; + blink->Clear(); + return G_SOURCE_REMOVE; + } + + private: + bool enabled_ = false; + int timeout_ = 5000; + guint source_ = 0; +}; + +Blink blink; + +} // namespace aul diff --git a/src/blink/log_private.hh b/src/blink/log_private.hh new file mode 100644 index 00000000..56a55112 --- /dev/null +++ b/src/blink/log_private.hh @@ -0,0 +1,37 @@ +/* + * 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 BLINK_LOG_PRIVATE_HH_ +#define BLINK_LOG_PRIVATE_HH_ + +#include <dlog.h> + +#undef LOG_TAG +#define LOG_TAG "AUL_BLINK" + +#undef _E +#define _E LOGE + +#undef _W +#define _W LOGW + +#undef _I +#define _I LOGI + +#undef _D +#define _D LOGD + +#endif // BLINK_LOG_PRIVATE_HH_ |