Modify CPU inheritance feature
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 17 May 2023 00:15:34 +0000 (00:15 +0000)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 17 May 2023 07:10:26 +0000 (07:10 +0000)
If the request is APP_SEND_LAUNCH_REQUEST or APP_SEND_RESUME_REQUEST,
the cpu inheritance should continue until the result event is received.
This patch separates the cpu inheritance class from the aul sock code.
The class is added to the ErrorInfo to inherit the CPU boosting.

Change-Id: Ife5c6a07957af7c8fbcbda51701b150b656a6c56
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/aul_sock.cc
src/cpu_inheritance.cc [new file with mode: 0644]
src/cpu_inheritance.hh [new file with mode: 0644]
src/launch_with_result.cc

index d301d113a4e5b4c370c9eb1009b4065e733f6e42..7a23fcaed708bc655782633d4e9c2bccdd7fb968 100644 (file)
@@ -16,7 +16,6 @@
 
 #include "include/aul_sock.h"
 
-#include <cpu-boosting.h>
 #include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -38,6 +37,7 @@
 #include "aul/socket/client_socket.hh"
 #include "aul/socket/packet.hh"
 #include "aul/socket/server_socket.hh"
+#include "cpu_inheritance.hh"
 
 using namespace aul;
 
@@ -48,7 +48,6 @@ constexpr const int MAX_PAYLOAD_SIZE = 1024 * 1024 * 1;
 constexpr const char PATH_AUL_SOCKET_TIMEOUT[] = "/run/aul/.socket_timeout";
 constexpr const char PATH_AMD_SOCK[] = "/run/aul/daemons/.amd-sock";
 int MAX_FDS = sysconf(_SC_OPEN_MAX);
-constexpr const char DEST_PROCESS[] = "amd";
 
 // POD type
 struct PacketHeader {
@@ -57,50 +56,6 @@ struct PacketHeader {
   int opt;
 };
 
-class CPUInheritance {
- public:
-  CPUInheritance(int pid, int cmd) {
-    if (pid == -2 && IsLaunchRequest(cmd)) {
-      int ret = resource_set_cpu_inheritance(gettid(),
-          const_cast<char*>(DEST_PROCESS), -1);
-      if (ret != 0)
-        _E("resource_set_cpu_inheritance() is failed. error(%d)", ret);
-      else
-        inherited_ = true;
-    }
-  }
-
-  ~CPUInheritance() {
-    if (inherited_) {
-      int ret = resource_clear_cpu_inheritance(gettid(),
-          const_cast<char*>(DEST_PROCESS));
-      if (ret != 0)
-        _E("resource_clear_cpu_inheritance() is failed. error(%d)", ret);
-    }
-  }
-
- private:
-  static bool IsLaunchRequest(int cmd) {
-    switch (cmd) {
-      case APP_START:
-      case APP_OPEN:
-      case APP_RESUME:
-      case APP_START_RES:
-      case APP_START_ASYNC:
-      case APP_SEND_LAUNCH_REQUEST:
-      case APP_SEND_LAUNCH_REQUEST_SYNC:
-      case RPC_PORT_PREPARE_STUB:
-      case APP_SEND_RESUME_REQUEST:
-        return true;
-      default:
-        return false;
-    }
-  }
-
- private:
-  bool inherited_ = false;
-};
-
 class SocketTimeout {
  public:
   SocketTimeout() = default;
@@ -260,7 +215,7 @@ int SendAndReceive(int pid, uid_t uid, int cmd, unsigned char* data,
     client.Connect(endpoint);
     aul_sock_set_sock_option(client.GetFd(), 1);
 
-    const auto& inherit = CPUInheritance(pid, cmd);
+    const auto& inherit = internal::CPUInheritance(pid, cmd);
     ret = SendAndReceive(&client, cmd, data, datalen, opt);
   } catch (const Exception& e) {
     _E("Exception occurs. error(%d)", e.GetErrorCode());
diff --git a/src/cpu_inheritance.cc b/src/cpu_inheritance.cc
new file mode 100644 (file)
index 0000000..3eac883
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "cpu_inheritance.hh"
+
+#include <cpu-boosting.h>
+
+#include "include/aul_cmd.h"
+#include "aul_util.h"
+
+namespace aul {
+namespace internal {
+namespace {
+
+constexpr const char DEST_PROCESS[] = "amd";
+
+}  // namespace
+
+CPUInheritance::CPUInheritance(pid_t pid, int cmd) {
+  if (pid == -2 && IsLaunchRequest(cmd)) {
+    int ret = resource_set_cpu_inheritance(gettid(),
+        const_cast<char*>(DEST_PROCESS), -1);
+    if (ret != 0)
+      _E("resource_set_cpu_inheritance() is failed. error(%d)", ret);
+    else
+      inherited_ = true;
+  }
+}
+
+CPUInheritance::CPUInheritance() {
+  int ret = resource_set_cpu_inheritance(gettid(),
+      const_cast<char*>(DEST_PROCESS), -1);
+  if (ret != 0)
+    _E("resource_set_cpu_inheritance() is failed. error(%d)", ret);
+  else
+    inherited_ = true;
+}
+
+CPUInheritance::~CPUInheritance() {
+  if (inherited_) {
+    int ret = resource_clear_cpu_inheritance(gettid(),
+        const_cast<char*>(DEST_PROCESS));
+    if (ret != 0)
+      _E("resource_clear_cpu_inheritance() is failed. error(%d)", ret);
+  }
+}
+
+bool CPUInheritance::IsLaunchRequest(int cmd) {
+  switch (cmd) {
+    case APP_START:
+    case APP_OPEN:
+    case APP_RESUME:
+    case APP_START_RES:
+    case APP_START_ASYNC:
+    case APP_SEND_LAUNCH_REQUEST_SYNC:
+    case RPC_PORT_PREPARE_STUB:
+      return true;
+    default:
+      return false;
+  }
+}
+
+}  // namespace internal
+}  // namespace aul
diff --git a/src/cpu_inheritance.hh b/src/cpu_inheritance.hh
new file mode 100644 (file)
index 0000000..e25c8c7
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CPU_INHERITANCE_HH_
+#define CPU_INHERITANCE_HH_
+
+#include <sys/types.h>
+
+namespace aul {
+namespace internal {
+
+class CPUInheritance {
+ public:
+  CPUInheritance(pid_t pid, int cmd);
+  CPUInheritance();
+  ~CPUInheritance();
+
+ private:
+  static bool IsLaunchRequest(int cmd);
+
+ private:
+  bool inherited_ = false;
+};
+
+}  // namespace internal
+}  // namespace aul
+
+#endif  // CPU_INHERITANCE_HH_
index 9a95d49e3db75e0681bc1dfd8596b2fa5c51f289..7cec306f4cdb51b4597791be53b59cc3ccc80043 100644 (file)
@@ -32,6 +32,7 @@
 #include "aul_svc.h"
 #include "aul_svc_priv_key.h"
 #include "aul_util.h"
+#include "cpu_inheritance.hh"
 #include "launch.h"
 
 using namespace aul::internal;
@@ -239,8 +240,10 @@ class ErrorInfo {
  public:
   ErrorInfo(std::string seq_num, tizen_base::Bundle b, int cmd,
       ErrCb error_cb, void* user_data)
-      : seq_num_(std::move(seq_num)), b_(std::move(b)), cmd_(cmd),
-          error_cb_(std::move(error_cb)), user_data_(user_data) {
+      : seq_num_(std::move(seq_num)),
+        b_(std::move(b)), cmd_(cmd),
+        error_cb_(std::move(error_cb)),
+        user_data_(user_data) {
   }
 
   ErrorInfo(const ErrorInfo&) = delete;
@@ -310,6 +313,7 @@ class ErrorInfo {
   int cmd_;
   ErrCb error_cb_;
   void* user_data_;
+  CPUInheritance inheritance_;
 };
 
 std::string __gen_seq_num() {