Check CPU boosting level before calling boost API 81/297881/2
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 28 Aug 2023 05:42:32 +0000 (14:42 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 28 Aug 2023 05:55:25 +0000 (14:55 +0900)
If the boosting is already applied to the launchpad-process-pool,
calling the resource_set_cpu_boosting() is not needed.

Change-Id: I14e564fa644e312c7eb6ca1305b222dd208ff3ca
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/launchpad-process-pool/launchpad.cc
src/lib/launchpad-common/cpu_boost_controller.cc
src/lib/launchpad-common/cpu_boost_controller.hh

index 13bc490..4733c99 100644 (file)
@@ -196,7 +196,18 @@ Launchpad::Launchpad(int argc, char** argv)
           std::placeholders::_1) },
   };
 
-  CPUBoostController::DoBoost(getpid(), CPUBoostController::Level::Strong, -1);
+  CPUBoostController::Level level;
+  int ret = CPUBoostController::GetBoostLevel(getpid(), &level);
+  if (ret != 0)
+    CPUBoostController::Clear(getpid());
+
+  if (ret != 0 ||
+      level == CPUBoostController::Level::None ||
+      level == CPUBoostController::Level::Weak) {
+    CPUBoostController::DoBoost(getpid(), CPUBoostController::Level::Strong,
+        -1);
+  }
+
   g_timeout_add(1000, [](gpointer data) {
         CPUBoostController::Clear(getpid());
         return G_SOURCE_REMOVE;
index eb06ffe..c72d80b 100644 (file)
@@ -18,6 +18,8 @@
 
 #include <cpu-boosting.h>
 
+#include <memory>
+
 #include "launchpad-common/log_private.hh"
 
 namespace launchpad {
@@ -58,4 +60,40 @@ void CPUBoostController::Clear(pid_t pid) {
     _D("resource_clear_cpu_boosting() is successful");
 }
 
+int CPUBoostController::GetBoostLevel(pid_t pid,
+    CPUBoostController::Level* level) {
+  if (pid < 1 || level == nullptr) {
+    _E("Invalid parameter");
+    return -EINVAL;
+  }
+
+  resource_pid_t res_pid = {
+      .pid = 0,
+      .tid = &pid,
+      .tid_count = 1,
+  };
+  cpu_boosting_level_info_t info;
+  _W("resource_get_cpu_boosting_level() ++");
+  int ret = resource_get_cpu_boosting_level(res_pid, &info);
+  _W("resource_get_cpu_boosting_level() --");
+  if (ret != 0) {
+    _E("resource_get_cpu_boosting_level() is failed. error: %d", ret);
+    return -1;
+  }
+
+  std::unique_ptr<int, decltype(std::free)*> auto_free(info.tid_level,
+      std::free);
+
+  if (info.tid_level[0] == CPU_BOOSTING_LEVEL_STRONG)
+    *level = CPUBoostController::Level::Strong;
+  else if (info.tid_level[0] == CPU_BOOSTING_LEVEL_MEDIUM)
+    *level = CPUBoostController::Level::Medium;
+  else if (info.tid_level[0] == CPU_BOOSTING_LEVEL_WEAK)
+    *level = CPUBoostController::Level::Weak;
+  else
+    *level = CPUBoostController::Level::None;
+
+  return 0;
+}
+
 }  // namespace launchpad
index 308f598..ae0df27 100644 (file)
@@ -35,6 +35,7 @@ class EXPORT_API CPUBoostController {
 
   static void DoBoost(pid_t pid, Level level, int timeout_msec);
   static void Clear(pid_t pid);
+  static int GetBoostLevel(pid_t pid, Level* level);
 };
 
 }  // namespace launchpad