From 3c2ee45d72323c82d93cea08fe5127c91f3cbe48 Mon Sep 17 00:00:00 2001 From: Ilho Kim Date: Tue, 12 Jul 2022 16:21:34 +0900 Subject: [PATCH] Set nice value -10 when making cache When creating cache the scheduling policy is changed to RR which is the real time scheduling policy as a result, the pkginfo-server can occupy the cpu for a long time with some real time scheduling policy process this patch modified to increase the priority by changing only the nice value instead of changing the scheduling policy Change-Id: If5c6509cddaa1bf3fa2cd2c47f94057aa8c35168 Signed-off-by: Ilho Kim --- .../create_cache_request_handler.cc | 66 ++++++++++------------ .../create_cache_request_handler.hh | 13 ++--- 2 files changed, 35 insertions(+), 44 deletions(-) diff --git a/src/server/request_handler/create_cache_request_handler.cc b/src/server/request_handler/create_cache_request_handler.cc index e83adaa..012d746 100644 --- a/src/server/request_handler/create_cache_request_handler.cc +++ b/src/server/request_handler/create_cache_request_handler.cc @@ -4,6 +4,8 @@ #include "create_cache_request_handler.hh" +#include + #include #include "cache_db_handler.hh" @@ -14,56 +16,48 @@ namespace psd = pkgmgr_server::database; namespace pkgmgr_server { namespace request_handler { -CreateCacheRequestHandler::Scheduler::Scheduler(pid_t tid) : tid_(tid) { - Get(&policy_, ¶m_); +CreateCacheRequestHandler::Scheduler::Scheduler(pid_t tid) + : tid_(tid), priority_(0) { + if (Get(&priority_) != 0) + priority_ = 0; } -void CreateCacheRequestHandler::Scheduler::ChangePolicy() { - struct sched_param param { - .sched_priority = 1, - }; - if (Set(SCHED_RR, ¶m) != 0) +void CreateCacheRequestHandler::Scheduler::ChangePriority() { + if (Set(-10) != 0) return; - int policy = -1; - Get(&policy, ¶m); - LOG(WARNING) << "Current policy: " << policy - << ", priority: " << param.sched_priority; + int priority = 0; + if (Get(&priority) == 0) + LOG(WARNING) << "Current priority: " << priority; } -void CreateCacheRequestHandler::Scheduler::ResetPolicy() { - if (Set(policy_, ¶m_) != 0) +void CreateCacheRequestHandler::Scheduler::ResetPriority() { + if (Set(priority_) != 0) return; - struct sched_param param = { - .sched_priority = 0, - }; - int policy = -1; - Get(&policy, ¶m); - LOG(WARNING) << "Current policy: " << policy - << ", priority: " << param.sched_priority; + int priority = 0; + if (Get(&priority) == 0) + LOG(WARNING) << "Current priority: " << priority; } -void CreateCacheRequestHandler::Scheduler::Get(int* policy, - struct sched_param* param) { - if (sched_getparam(tid_, param) != 0) - LOG(ERROR) << "sched_getparam() is failed. errno: " << errno; +int CreateCacheRequestHandler::Scheduler::Get(int* priority) { + errno = 0; + *priority = getpriority(PRIO_PROCESS, 0); + if (errno != 0) { + LOG(ERROR) << "getpriority() is failed. errno: " << errno; + return -1; + } - *policy = sched_getscheduler(tid_); - if (*policy < 0) - LOG(ERROR) << "sched_getscheduler() is failed. errno: " << errno; + return 0; } -int CreateCacheRequestHandler::Scheduler::Set(int policy, - struct sched_param* param) { - if (sched_setscheduler(tid_, policy, param) != 0) { - LOG(ERROR) << "sched_setscheduler() is failed. policy: " << policy - << ", errno: " << errno; +int CreateCacheRequestHandler::Scheduler::Set(int priority) { + if (setpriority(PRIO_PROCESS, 0, priority) != 0) { + LOG(ERROR) << "setpriority() is failed. , errno: " << errno; return -1; } - LOG(WARNING) << "policy: " << policy - << ", sched_priority: " << param->sched_priority; + LOG(WARNING) << "priority: " << priority; return 0; } @@ -85,11 +79,11 @@ std::vector CreateCacheRequestHandler::ExtractResult() { } void CreateCacheRequestHandler::PreExec() { - scheduler_.ChangePolicy(); + scheduler_.ChangePriority(); } void CreateCacheRequestHandler::PostExec() { - scheduler_.ResetPolicy(); + scheduler_.ResetPriority(); } } // namespace request_handler diff --git a/src/server/request_handler/create_cache_request_handler.hh b/src/server/request_handler/create_cache_request_handler.hh index 66d5bbd..f92ec4c 100644 --- a/src/server/request_handler/create_cache_request_handler.hh +++ b/src/server/request_handler/create_cache_request_handler.hh @@ -32,19 +32,16 @@ class EXPORT_API CreateCacheRequestHandler : public AbstractRequestHandler { public: explicit Scheduler(pid_t tid); - void ChangePolicy(); - void ResetPolicy(); + void ChangePriority(); + void ResetPriority(); private: - void Get(int* policy, struct sched_param* param); - int Set(int policy, struct sched_param* param); + int Get(int* priority); + int Set(int priority); private: pid_t tid_; - int policy_ = 0; - struct sched_param param_ = { - 0, - }; + int priority_; }; private: -- 2.7.4