Add a new launch mode 47/294747/3
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 26 Jun 2023 01:47:05 +0000 (01:47 +0000)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 26 Jun 2023 05:13:10 +0000 (05:13 +0000)
The "Always Loader With Low Priority" mode is added to the LaunchMode.
If it's set, an application will be executed using the loader process.
And, the loader process is executed with the low priority.
When getting the launch request, the launchpad-process-pool sets the high
priority to the process using the boosting API.

Change-Id: I46a6eef78c263c01f4a757717cbb069f4b8b28f5
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/launchpad-process-pool/conf/launchpad.conf.in
src/launchpad-process-pool/config.cc
src/launchpad-process-pool/config.hh
src/launchpad-process-pool/launchpad.cc
src/launchpad-process-pool/loader_context.cc
src/lib/launchpad-common/sched_priority.cc
src/lib/launchpad-common/sched_priority.hh
src/lib/launchpad-hydra/launchpad_hydra.cc
src/lib/launchpad/launchpad_loader.cc

index cc29900..e05b7ba 100644 (file)
@@ -31,5 +31,9 @@ NumberOfLoaderProcesses=1
 ## Mode=Always_Loader_Without_CPUChecker
 ## - This mode is the modified version of "Mode=Always_Loader".
 ## - After processing the launch request, the launchpad executes a new loader process without CPU Checker.
+## Mode=Always_Loader_With_Low_Priority
+## - This mode is the modified version of "Mode=Always_Loader_Without_CPUChecker".
+## - When the loader process is executed, the launchpad sets the low scheduling priority to the running process.
+## - And then, the launchpad sets the normal priority to the running process if the launch request is delivered.
 [LaunchMode]
 Mode=Default_Operation
index fa82d48..00f7689 100644 (file)
@@ -56,6 +56,8 @@ constexpr const char kValueModeDefaultOperation[] = "DEFAULT_OPERATION";
 constexpr const char kValueModeAlwaysLoader[] = "ALWAYS_LOADER";
 constexpr const char kValueModeAlwaysLoaderWithoutCPUChecker[] =
     "ALWAYS_LOADER_WITHOUT_CPUCHECKER";
+constexpr const char kValueModeAlwaysLoaderWithLowPriority[] =
+    "ALWAYS_LOADER_WITH_LOW_PRIORITY";
 
 }  // namespace
 
@@ -197,6 +199,8 @@ Config::LaunchMode::LaunchMode(const IniParser& parser) {
       mode_ = LaunchMode::Mode::AlwaysLoader;
     else if (mode == kValueModeAlwaysLoaderWithoutCPUChecker)
       mode_ = LaunchMode::Mode::AlwaysLoaderWithoutCPUChecker;
+    else if (mode == kValueModeAlwaysLoaderWithLowPriority)
+      mode_ = LaunchMode::Mode::AlwaysLoaderWithLowPriority;
   }
 
   _W("[LaunchMode] mode: %d(%s)", static_cast<int>(mode_), mode.c_str());
index 7d77e47..0daf5b2 100644 (file)
@@ -98,6 +98,7 @@ class Config {
       DefaultOperation = 1,
       AlwaysLoader = 2,
       AlwaysLoaderWithoutCPUChecker = 3,
+      AlwaysLoaderWithLowPriority = 4,
     };
 
     explicit LaunchMode(const IniParser& parser);
index ad33449..64dab34 100644 (file)
@@ -33,6 +33,7 @@
 #include <exception.hh>
 #include <executor.hh>
 #include <procfs.hh>
+#include <sched_priority.hh>
 #include <types.hh>
 #include <user_tracer.hh>
 #include <util.hh>
@@ -385,6 +386,7 @@ bool Launchpad::CanUseLoaderContext(
 
   // Config::LaunchMode::Mode::AlwaysLoader
   // Config::LaunchMode::Mode::AlwaysLoaderWithoutCPUChecker
+  // Config::LaunchMode::Mode::AlwaysLoaderWithLowPriority
   if (context->GetPid() > 0)
     return true;
 
@@ -477,8 +479,10 @@ Launchpad::LaunchResult Launchpad::ForkProcessing(
 Launchpad::LaunchResult Launchpad::LaunchRequestPend(
     std::shared_ptr<Request> request) {
   auto loader_context = request->GetAvailableLoaderContext();
-  if (loader_context->IsPrepared())
+  if (loader_context->IsPrepared()) {
+    SchedPriority::Set(loader_context->GetPid(), 0);
     return LaunchResult::Continue;
+  }
 
   _W("Loader context is not prepared");
   loader_context->Ref();
@@ -515,6 +519,7 @@ Launchpad::LaunchResult Launchpad::LaunchRequestDo(
   request->SetPid(loader_context->Deploy(app_info));
 
   if ((mode_ == Config::LaunchMode::Mode::AlwaysLoaderWithoutCPUChecker) ||
+      (mode_ == Config::LaunchMode::Mode::AlwaysLoaderWithLowPriority) ||
       (mode_ == Config::LaunchMode::Mode::AlwaysLoader &&
        loader_context->RefCount() > 0))
     loader_context->Prepare();
@@ -618,8 +623,12 @@ void Launchpad::OnLoaderPrepared(LoaderContext* loader_context) {
 void Launchpad::OnLoaderLaunched(LoaderContext* loader_context) {
   _W("Loader is launched. name(%s), pid(%d)",
       loader_context->GetLoaderName().c_str(), loader_context->GetPid());
-  if (loader_context->RefCount() == 0)
+  if (loader_context->RefCount() == 0) {
+    if (mode_ == Config::LaunchMode::Mode::AlwaysLoaderWithLowPriority)
+      SchedPriority::Set(loader_context->GetPid(), 19);
+
     return;
+  }
 
   for (auto& request : pending_requests_) {
     auto context = request->GetAvailableLoaderContext();
index 729a7a3..17b327e 100644 (file)
@@ -34,6 +34,7 @@
 #include <types.hh>
 
 #include "launchpad-process-pool/app_labels_monitor.hh"
+#include "launchpad-process-pool/config.hh"
 #include "launchpad-process-pool/loader_executor.hh"
 #include "launchpad-process-pool/log.hh"
 #include "launchpad-process-pool/log_private.hh"
@@ -209,8 +210,10 @@ void LoaderContext::Dispose() {
 }
 
 pid_t LoaderContext::Prepare() {
+  bool set_priority = (Config::GetInst().GetLaunchMode().GetMode() !=
+      Config::LaunchMode::Mode::AlwaysLoaderWithLowPriority);
   pid_ = LoaderExecutor::GetInst().Execute(this,
-      loader_info_->GetSchedPriority());
+      set_priority ? loader_info_->GetSchedPriority() : 0);
   _W("Prepare. type(%d), name(%s), pid(%d)",
       GetType(), GetLoaderName().c_str(), pid_);
   if (pid_ == -1) {
index 19ccc91..a19d04c 100644 (file)
 namespace launchpad {
 
 int SchedPriority::Set(int priority) {
-  int ret = setpriority(PRIO_PGRP, 0, priority);
+  return Set(0, priority);
+}
+
+int SchedPriority::Set(pid_t pid, int priority) {
+  int ret = setpriority(PRIO_PGRP, pid, priority);
   if (ret != 0) {
-    _E("Failed to set process priority. priority(%d), errno(%d)",
-        priority, errno);
+    _E("Failed to set priority proriority. who(%d), priority(%d), errno(%d)",
+        pid, priority, errno);
   } else {
-    _D("Setting priority(%d) is sucessful", priority);
+    _D("Setting priority(%d) is sucessful. who(%d)", priority, pid);
   }
 
   return ret;
index 5b6e58a..f96fdd6 100644 (file)
@@ -17,6 +17,8 @@
 #ifndef LIB_LAUNCHPAD_COMMON_SCHED_PRIORITY_HH_
 #define LIB_LAUNCHPAD_COMMON_SCHED_PRIORITY_HH_
 
+#include <sys/types.h>
+
 #undef EXPORT_API
 #define EXPORT_API __attribute__((visibility("default")))
 
@@ -25,6 +27,7 @@ namespace launchpad {
 class EXPORT_API SchedPriority {
  public:
   static int Set(int priority);
+  static int Set(pid_t pid, int priority);
   static int Get();
 };
 
index c2648ab..f9fcae6 100644 (file)
@@ -130,7 +130,6 @@ void LaunchpadHydra::Run(hydra_lifecycle_callback_s* callback,
   candidate_pid_ = executor_->Execute(argc_, argv_);
   _D("Candidate process(%d)", candidate_pid_);
   socket_->Send(&candidate_pid_, sizeof(candidate_pid_));
-  SchedPriority::Set(0);
 
   EventLoop::GetInst().Run();
   OnTerminate();
index eac8621..14dc76e 100644 (file)
@@ -110,7 +110,6 @@ int LaunchpadLoader::Run(loader_lifecycle_callback_s* callback,
     return -1;
   }
 
-  SchedPriority::Set(0);
   OnAdapterLoopBegin();
   return OnTerminate();
 }