From: Hwankyu Jhun Date: Thu, 30 Jun 2022 06:58:41 +0000 (+0900) Subject: Inherit CPU scheduling policy to Daemon Process X-Git-Tag: accepted/tizen/unified/20220703.214155~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=961767c193bf8ea3d75f71ef68995a0211a3e113;p=platform%2Fcore%2Fappfw%2Faul-1.git Inherit CPU scheduling policy to Daemon Process To solve the priority inversion issue, AUL calls resource_set_cpu_inheritance() to inherit the CPU scheduling policy to AMD when IPC with AMD. If the stcheduling priority of AMD is higher than the caller, the inheritance request will be ignored. Change-Id: I5a12f208c31f113f7c12a975526f3a03f155787a Signed-off-by: Hwankyu Jhun --- diff --git a/CMakeLists.txt b/CMakeLists.txt index f2a12f3..6835e06 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,11 +40,13 @@ INCLUDE(ApplyPkgConfig) PKG_CHECK_MODULES(BUNDLE_DEPS REQUIRED bundle) PKG_CHECK_MODULES(CAPI_SYSTEM_INFO_DEPS REQUIRED capi-system-info) +PKG_CHECK_MODULES(CAPI_SYSTEM_RESOURCE_DEPS REQUIRED capi-system-resource) PKG_CHECK_MODULES(DLOG_DEPS REQUIRED dlog) PKG_CHECK_MODULES(GIO_DEPS REQUIRED gio-2.0) PKG_CHECK_MODULES(GLIB_DEPS REQUIRED glib-2.0) PKG_CHECK_MODULES(GMOCK_DEPS REQUIRED gmock) PKG_CHECK_MODULES(INIPARSER_DEPS REQUIRED iniparser) +PKG_CHECK_MODULES(LIBSESSIOND_DEPS REQUIRED libsessiond) PKG_CHECK_MODULES(LIBSMACK_DEPS REQUIRED libsmack) PKG_CHECK_MODULES(LIBTZPLATFORM_CONFIG_DEPS REQUIRED libtzplatform-config) PKG_CHECK_MODULES(LIBXML_DEPS REQUIRED libxml-2.0) @@ -57,7 +59,6 @@ PKG_CHECK_MODULES(TTRACE_DEPS REQUIRED ttrace) PKG_CHECK_MODULES(UUID_DEPS REQUIRED uuid) PKG_CHECK_MODULES(VCONF_DEPS REQUIRED vconf) PKG_CHECK_MODULES(XDGMIME_DEPS REQUIRED xdgmime) -PKG_CHECK_MODULES(LIBSESSIOND_DEPS REQUIRED libsessiond) ## Target sources AUX_SOURCE_DIRECTORY(src SRCS) @@ -102,10 +103,12 @@ SET_TARGET_PROPERTIES(${TARGET_AUL} PROPERTIES VERSION ${FULLVER}) APPLY_PKG_CONFIG(${TARGET_AUL} PUBLIC BUNDLE_DEPS CAPI_SYSTEM_INFO_DEPS + CAPI_SYSTEM_RESOURCE_DEPS DLOG_DEPS GIO_DEPS GLIB_DEPS INIPARSER_DEPS + LIBSESSIOND_DEPS LIBSMACK_DEPS LIBTZPLATFORM_CONFIG_DEPS LIBXML_DEPS @@ -116,7 +119,6 @@ APPLY_PKG_CONFIG(${TARGET_AUL} PUBLIC UUID_DEPS VCONF_DEPS XDGMIME_DEPS - LIBSESSIOND_DEPS ) INSTALL(TARGETS ${TARGET_AUL} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) diff --git a/packaging/aul.spec b/packaging/aul.spec index 7272fc6..b0eff00 100644 --- a/packaging/aul.spec +++ b/packaging/aul.spec @@ -17,27 +17,28 @@ Requires(preun): /usr/bin/systemctl Requires: tizen-platform-config BuildRequires: cmake -BuildRequires: pkgconfig(gio-2.0) -BuildRequires: pkgconfig(glib-2.0) -BuildRequires: pkgconfig(bundle) -BuildRequires: pkgconfig(dlog) -BuildRequires: xdgmime-devel, pkgconfig(xdgmime) -BuildRequires: pkgconfig(vconf) -BuildRequires: pkgconfig(pkgmgr-info) BuildRequires: libattr-devel -BuildRequires: pkgconfig(libtzplatform-config) +BuildRequires: pkgconfig(bundle) BuildRequires: pkgconfig(capi-system-info) +BuildRequires: pkgconfig(capi-system-resource) +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(gio-2.0) +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(gmock) BuildRequires: pkgconfig(iniparser) +BuildRequires: pkgconfig(libsessiond) +BuildRequires: pkgconfig(libsmack) +BuildRequires: pkgconfig(libtzplatform-config) +BuildRequires: pkgconfig(libxml-2.0) +BuildRequires: pkgconfig(parcel) +BuildRequires: pkgconfig(pkgmgr-info) +BuildRequires: pkgconfig(pkgmgr-installer) BuildRequires: pkgconfig(sqlite3) BuildRequires: pkgconfig(storage) BuildRequires: pkgconfig(ttrace) -BuildRequires: pkgconfig(pkgmgr-installer) -BuildRequires: pkgconfig(libxml-2.0) BuildRequires: pkgconfig(uuid) -BuildRequires: pkgconfig(libsmack) -BuildRequires: pkgconfig(gmock) -BuildRequires: pkgconfig(parcel) -BuildRequires: pkgconfig(libsessiond) +BuildRequires: pkgconfig(vconf) +BuildRequires: xdgmime-devel, pkgconfig(xdgmime) %if 0%{?gcov:1} BuildRequires: lcov diff --git a/src/aul_sock.cc b/src/aul_sock.cc index 78b88dc..ad96c6f 100644 --- a/src/aul_sock.cc +++ b/src/aul_sock.cc @@ -16,6 +16,7 @@ #include "include/aul_sock.h" +#include #include #include #include @@ -47,6 +48,7 @@ constexpr const int MAX_PAYLOAD_SIZE = 1024 * 1024 * 1; constexpr const char PATH_AUL_SOCKET_TIMEOUT[] = "/run/aul/.socket_timeout"; constexpr const char PATH_AMD_SOCK[] = "/run/aul/daemons/.amd-sock"; int MAX_FDS = sysconf(_SC_OPEN_MAX); +constexpr const char DEST_PROCESS[] = "amd"; // POD type struct PacketHeader { @@ -55,6 +57,28 @@ struct PacketHeader { int opt; }; +class CPUInheritance { + public: + CPUInheritance() { + int ret = resource_set_cpu_inheritance(gettid(), DEST_PROCESS, -1); + if (ret != 0) + _E("resource_set_cpu_inheritance() is failed. error(%d)", ret); + else + inherited_ = true; + } + + ~CPUInheritance() { + if (inherited_) { + int ret = resource_clear_cpu_inheritance(gettid(), DEST_PROCESS); + if (ret != 0) + _E("resource_clear_cpu_inheritance() is failed. error(%d)", ret); + } + } + + private: + bool inherited_ = false; +}; + class SocketTimeout { public: SocketTimeout() = default; @@ -181,6 +205,7 @@ int SendAndReceive(ClientSocket* client, int cmd, unsigned char* data, parcel.WriteParcelable(packet); auto raw = parcel.GetRaw(); + const auto& inherit = CPUInheritance(); int ret = client->Send(reinterpret_cast(&raw[0]), raw.size()); if (ret != 0 || opt & AUL_SOCK_NOREPLY) { if (opt & AUL_SOCK_ASYNC) @@ -231,6 +256,7 @@ int ReceiveAppPacket(ClientSocket* client, app_pkt_t** out_pkt) { static_assert(std::is_trivial(), "Header should be POD type"); + const auto& inherit = CPUInheritance(); *out_pkt = nullptr; int ret = client->Receive(&header, sizeof(header)); if (ret < 0) @@ -300,6 +326,7 @@ int ReceiveMessage(int fd, struct iovec* vec, int vec_max_size, int* vec_size, else is_blocking = true; + const auto& inherit = CPUInheritance(); retry: int ret = recvmsg(fd, &msg, 0); if (ret == 0) {