diff options
author | Krzysztof Jackiewicz <k.jackiewicz@samsung.com> | 2023-11-16 22:42:25 +0100 |
---|---|---|
committer | Krzysztof Jackiewicz <k.jackiewicz@samsung.com> | 2023-11-20 14:50:15 +0100 |
commit | 793105d64b9518e7b8702374865aaf63ba88632a (patch) | |
tree | 9044dce70a2601498a3c056f57e2d37043ec5d76 | |
parent | 6e9510574315e15785e134a4713715f1a3835038 (diff) | |
download | key-manager-793105d64b9518e7b8702374865aaf63ba88632a.tar.gz key-manager-793105d64b9518e7b8702374865aaf63ba88632a.tar.bz2 key-manager-793105d64b9518e7b8702374865aaf63ba88632a.zip |
Implement cpu inheritance
Apply CPU boosting to server for high priority clients.
Change-Id: I6493362020eee6b43534166bc8442d5931cc450d
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | packaging/key-manager.spec | 1 | ||||
-rw-r--r-- | src/manager/client/client-common.cpp | 28 | ||||
-rw-r--r-- | src/manager/common/protocols.cpp | 1 | ||||
-rw-r--r-- | src/manager/common/protocols.h | 1 | ||||
-rw-r--r-- | src/manager/main/key-manager-main.cpp | 28 |
6 files changed, 59 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 24779e76..ecfc13d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -140,6 +140,7 @@ PKG_CHECK_MODULES(KEY_MANAGER_DEP pkgmgr vconf sqlcipher + capi-system-resource ${EXTRA_KM_DEPS} ) diff --git a/packaging/key-manager.spec b/packaging/key-manager.spec index 6afa8019..138d6107 100644 --- a/packaging/key-manager.spec +++ b/packaging/key-manager.spec @@ -55,6 +55,7 @@ Requires: libkey-manager-common = %{version}-%{release} %if "%{build_type}" == "COVERAGE" BuildRequires: lcov %endif +BuildRequires: pkgconfig(capi-system-resource) %{?systemd_requires} diff --git a/src/manager/client/client-common.cpp b/src/manager/client/client-common.cpp index 238b2ff8..334a5ee4 100644 --- a/src/manager/client/client-common.cpp +++ b/src/manager/client/client-common.cpp @@ -41,11 +41,30 @@ #include <ckmc/ckmc-type.h> #include <client-common.h> #include <ckmc-type-converter.h> +#include <cpu-boosting.h> +#include <tizen.h> namespace { const int POLL_TIMEOUT = 600000; +struct ClearInheritance +{ + explicit ClearInheritance(pid_t _tid) : tid(_tid){ + } + + ~ClearInheritance() { + try { + int ret = resource_clear_cpu_inheritance(tid, CKM::KEY_MANAGER_BOOST_TARGET); + if (ret != TIZEN_ERROR_NONE) + LogDebug("resource_clear_cpu_inheritance failed with " << ret); + } catch (...) { + } + } + + const pid_t tid; +}; + } // namespace anonymous namespace CKM { @@ -287,8 +306,15 @@ int try_catch(const std::function<int()> &func) { int retval = CKM_API_ERROR_UNKNOWN; + const auto tid = gettid(); try { - return func(); + std::unique_ptr<ClearInheritance> ci; + int cpuRet = resource_set_cpu_inheritance(tid, CKM::KEY_MANAGER_BOOST_TARGET, -1); + if (cpuRet == TIZEN_ERROR_NONE) + ci.reset(new ClearInheritance(tid)); + else + LogDebug("resource_set_cpu_inheritance failed with " << cpuRet); + retval = func(); } catch (const MessageBuffer::Exception::Base &e) { LogError("CKM::MessageBuffer::Exception " << e.DumpToString()); } catch (const std::exception &e) { diff --git a/src/manager/common/protocols.cpp b/src/manager/common/protocols.cpp index 417a65c9..dc0a5bd4 100644 --- a/src/manager/common/protocols.cpp +++ b/src/manager/common/protocols.cpp @@ -41,6 +41,7 @@ char const *const SERVICE_SOCKET_ENCRYPTION = char const *const ALIAS_SEPARATOR = " "; char const *const CLIENT_ID_SYSTEM = "/System"; char const *const CLIENT_ID_ADMIN_USER = "/User"; +char const *const KEY_MANAGER_BOOST_TARGET = "key-manager"; PolicySerializable::PolicySerializable(IStream &stream) { diff --git a/src/manager/common/protocols.h b/src/manager/common/protocols.h index 75c12cf9..30118874 100644 --- a/src/manager/common/protocols.h +++ b/src/manager/common/protocols.h @@ -40,6 +40,7 @@ COMMON_API extern char const *const SERVICE_SOCKET_CKM_CONTROL; COMMON_API extern char const *const SERVICE_SOCKET_CKM_STORAGE; COMMON_API extern char const *const SERVICE_SOCKET_OCSP; COMMON_API extern char const *const SERVICE_SOCKET_ENCRYPTION; +COMMON_API extern char const *const KEY_MANAGER_BOOST_TARGET; enum class ControlCommand : int { UNLOCK_USER_KEY, diff --git a/src/manager/main/key-manager-main.cpp b/src/manager/main/key-manager-main.cpp index d1840c59..dcb2347d 100644 --- a/src/manager/main/key-manager-main.cpp +++ b/src/manager/main/key-manager-main.cpp @@ -21,6 +21,9 @@ */ #include <stdlib.h> #include <signal.h> +#include <sys/types.h> +#include <unistd.h> + #include <fstream> @@ -39,12 +42,35 @@ #include <key-provider.h> #include <file-system.h> +#include <cpu-boosting.h> +#include <tizen.h> + namespace { const char *DEV_HW_RANDOM_FILE = "/dev/hwrng"; const char *DEV_URANDOM_FILE = "/dev/urandom"; const size_t RANDOM_BUFFER_LEN = 32; +struct PriorityInheritor +{ + PriorityInheritor() { + resource_pid_t pid; + pid.pid = getpid(); + int ret = resource_register_cpu_inheritance_destination(CKM::KEY_MANAGER_BOOST_TARGET, pid); + if (ret != TIZEN_ERROR_NONE) + LogError("resource_register_cpu_inheritance_destination failed with " << ret); + } + + ~PriorityInheritor() { + try { + int ret = resource_unregister_cpu_inheritance_destination( + CKM::KEY_MANAGER_BOOST_TARGET); + if (ret != TIZEN_ERROR_NONE) + LogError("resource_unregister_cpu_inheritance_destination failed with " << ret); + } catch (...) {} + } +}; + void initializeEntropy() // entropy sources - /dev/random,/dev/urandom(Default) { int ret = 0; @@ -122,6 +148,8 @@ int main(void) initializeEntropy(); + PriorityInheritor pi; + { LogInfo("Start!"); CKM::SocketManager manager; |