Fix cpu boosting level check
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 27 Jan 2023 07:59:28 +0000 (07:59 +0000)
committerHwankyu Jhun <h.jhun@samsung.com>
Fri, 27 Jan 2023 08:13:36 +0000 (08:13 +0000)
To reduce calling fgets() in the resource API, AMD sets the tid and
the tid_count.

Change-Id: Ie8fddfae91dc9c1cd2501c6237cefad0537b3aac
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/lib/request/request_manager.cc

index 323991d0687c8847a59bdbfc4e6791eeee2ba2d3..9861a1e77ae859000042cc19c29e6b711df5d0e6 100644 (file)
@@ -42,22 +42,25 @@ bool IsCpuBoostingHighLevel(pid_t pid) {
   if (pid < 1)
     return false;
 
-  resource_pid_t resource_pid { .pid = pid, };
+  resource_pid_t resource_pid {
+    .pid = 0,
+    .tid = &pid,
+    .tid_count = 1
+  };
+
   cpu_boosting_level_info_t info;
-  _W("resource_get_cpu_boosting_level(%d) ++", pid);
+  _W("resource_get_cpu_boosting_level() ++ pid(%d)", pid);
   int ret = resource_get_cpu_boosting_level(resource_pid, &info);
-  _W("resource_get_cpu_boosting_level(%d) --", pid);
+  _W("resource_get_cpu_boosting_level() -- pid(%d)", pid);
   if (ret != 0)
     return false;
 
   std::unique_ptr<int, decltype(std::free)*> auto_free(info.tid_level,
       std::free);
 
-  for (int i = 0; i < info.tid_count; ++i) {
-    if (info.tid_level[i] == CPU_BOOSTING_LEVEL_STRONG ||
-        info.tid_level[i] == CPU_BOOSTING_LEVEL_MEDIUM)
-      return true;
-  }
+  if (info.tid_level[0] == CPU_BOOSTING_LEVEL_STRONG ||
+      info.tid_level[0] == CPU_BOOSTING_LEVEL_MEDIUM)
+    return true;
 
   return false;
 }