Set nice value -10 when making cache 96/277696/3
authorIlho Kim <ilho159.kim@samsung.com>
Tue, 12 Jul 2022 07:21:34 +0000 (16:21 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Tue, 12 Jul 2022 08:35:50 +0000 (17:35 +0900)
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 <ilho159.kim@samsung.com>
src/server/request_handler/create_cache_request_handler.cc
src/server/request_handler/create_cache_request_handler.hh

index e83adaa..012d746 100644 (file)
@@ -4,6 +4,8 @@
 
 #include "create_cache_request_handler.hh"
 
+#include <sys/resource.h>
+
 #include <string>
 
 #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_, &param_);
+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, &param) != 0)
+void CreateCacheRequestHandler::Scheduler::ChangePriority() {
+  if (Set(-10) != 0)
     return;
 
-  int policy = -1;
-  Get(&policy, &param);
-  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_, &param_) != 0)
+void CreateCacheRequestHandler::Scheduler::ResetPriority() {
+  if (Set(priority_) != 0)
     return;
 
-  struct sched_param param = {
-    .sched_priority = 0,
-  };
-  int policy = -1;
-  Get(&policy, &param);
-  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<uint8_t> CreateCacheRequestHandler::ExtractResult() {
 }
 
 void CreateCacheRequestHandler::PreExec() {
-  scheduler_.ChangePolicy();
+  scheduler_.ChangePriority();
 }
 
 void CreateCacheRequestHandler::PostExec() {
-  scheduler_.ResetPolicy();
+  scheduler_.ResetPriority();
 }
 
 }  // namespace request_handler
index 66d5bbd..f92ec4c 100644 (file)
@@ -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: