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>
## 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")
%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
ADD_SUBDIRECTORY(aul)
+ADD_SUBDIRECTORY(blink)
ADD_SUBDIRECTORY(parser)
ADD_SUBDIRECTORY(rsc-mgr)
ADD_SUBDIRECTORY(server)
XDGMIME_DEPS
)
+TARGET_LINK_LIBRARIES(${TARGET_AUL} PRIVATE ${TARGET_AUL_BLINK})
+
INSTALL(TARGETS ${TARGET_AUL}
DESTINATION ${LIB_INSTALL_DIR}
COMPONENT RuntimeLibraries)
--- /dev/null
+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)
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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_