If a process with a high cpu priority attempts IPC with a non cpu boosting process
the high cpu priority of the process becomes useless
To improve the priority inversion problem
apply cpu priority inheritance to pkginfo-server
Change-Id: I05414234f147d360ce63820b53edbbabda872aad
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
cynara-client-async
cynara-session
cynara-creds-socket
+ capi-system-resource
)
FOREACH(flag ${libpkgs_CFLAGS})
cynara-client-async
cynara-session
cynara-creds-socket
+ capi-system-resource
)
FOREACH(flag ${libpkgs_server_CFLAGS})
BuildRequires: pkgconfig(cynara-client-async)
BuildRequires: pkgconfig(cynara-session)
BuildRequires: pkgconfig(cynara-creds-socket)
+BuildRequires: pkgconfig(capi-system-resource)
%if 0%{?gcov:1}
BuildRequires: lcov
#include "pkginfo_client.hh"
+#include <cpu-boosting.h>
#include <dlfcn.h>
#include <parcel.hh>
constexpr const char SOCK_PATH[] = "/run/pkgmgr-info-server";
constexpr const char SERVER_READY[] = "/run/.pkginfo_server_ready";
+constexpr const char DEST_PROCESS_NAME[] = "pkgmgr-info";
+
+PkgInfoClient::CPUInheritanceInvoker::CPUInheritanceInvoker()
+ : set_complete_(false) {}
+
+PkgInfoClient::CPUInheritanceInvoker::~CPUInheritanceInvoker() {
+ ClearCPUInheritance();
+}
+
+void PkgInfoClient::CPUInheritanceInvoker::SetCPUInheritance() {
+ int ret = resource_set_cpu_inheritance(gettid(), DEST_PROCESS_NAME, -1);
+ if (ret != 0) {
+ LOG(ERROR) << "set cpu inheritance fail ret : " << ret;
+ return;
+ }
+
+ set_complete_ = true;
+}
+
+void PkgInfoClient::CPUInheritanceInvoker::ClearCPUInheritance() {
+ if (!set_complete_)
+ return;
+
+ int ret = resource_clear_cpu_inheritance(gettid(), DEST_PROCESS_NAME);
+ if (ret != 0) {
+ LOG(ERROR) << "clear cpu inheritance fail ret : " << ret;
+ return;
+ }
+
+ set_complete_ = false;
+}
PkgInfoClient::PkgInfoClient(
std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcel,
LOG(WARNING) << "Try to send request, Request type: "
<< pkgmgr_common::ReqTypeToString(req_type_);
+ cpu_inheritance_invoker_.SetCPUInheritance();
if (!socket_->Connect(req_type_)) {
LOG(ERROR) << "Failed to connect client socket, try to direct access";
is_offline_ = true;
return nullptr;
}
+ cpu_inheritance_invoker_.ClearCPUInheritance();
+
auto res = pkgmgr_common::parcel::ParcelableFactory::GetInst().CreateParcel(
raw, len);
delete[] raw;
class PkgInfoClient {
public:
+ class CPUInheritanceInvoker {
+ public:
+ CPUInheritanceInvoker();
+ ~CPUInheritanceInvoker();
+ void SetCPUInheritance();
+ void ClearCPUInheritance();
+
+ private:
+ bool set_complete_;
+ };
+
PkgInfoClient(
std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcel,
uid_t uid, pkgmgr_common::ReqType req_type);
uid_t uid_;
pkgmgr_common::ReqType req_type_;
bool is_offline_;
+ CPUInheritanceInvoker cpu_inheritance_invoker_;
};
} // namespace pkgmgr_client
* limitations under the License.
*/
+#include <cpu-boosting.h>
#include <fcntl.h>
#include <glib-unix.h>
#include <stdlib.h>
namespace {
static const std::string SOCK_PATH = "/run/pkgmgr-info-server";
-const char PRIVILEGE_PACKAGE_MANAGER_ADMIN[] =
+constexpr const char PRIVILEGE_PACKAGE_MANAGER_ADMIN[] =
"http://tizen.org/privilege/packagemanager.admin";
+constexpr const char DEST_PROCESS_NAME[] = "pkgmgr-info";
} // namespace
CynaraChecker::GetInst().Init();
server_ = std::make_unique<pkgmgr_common::socket::ServerSocket>(SOCK_PATH);
thread_pool_ = std::make_unique<WorkerThread>(thread_num_);
+ SetCPUInheritance();
auto condition = static_cast<GIOCondition>(G_IO_IN);
sid_ = g_unix_fd_add(server_->GetFd(), condition, OnReceiveRequest, this);
pkgmgr_common::SystemLocale::GetInst().RegisterEvent(this);
return true;
}
+void Runner::SetCPUInheritance() {
+ int ret;
+ resource_pid_t resource_st = { 0, };
+ resource_st.pid = getpid();
+
+ ret = resource_register_cpu_inheritance_destination(
+ DEST_PROCESS_NAME, resource_st);
+ if (ret != 0)
+ LOG(ERROR) << "Fail to register cpu inheritance destination ret : " << ret;
+}
+
} // namespace pkgmgr_server
private:
static int OnReceiveRequest(int fd, GIOCondition cond, void* user_data);
bool QueueRequest(int client_fd);
+ void SetCPUInheritance();
private:
int sid_;