Add new options to blink feature 50/309650/1
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 15 Apr 2024 04:33:04 +0000 (13:33 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 15 Apr 2024 04:33:04 +0000 (13:33 +0900)
The aul-blink checks AUL_BLINK_LEVEL and AUL_BLINK_OPTION to parse options.
The value of AUL_BLINK_LEVEL environment is able to be 'strong', 'medium' and
'weak'. The value of AUL_BLINK_OPTION environment is able to be 'reset-on-fork'
and 'inherit-on-fork'.

Change-Id: Iafd0016c15f6f8eee3362cde0021ae8acdff5bac
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/blink/aul_blink.cc

index 8b60676..42c2a28 100644 (file)
@@ -22,6 +22,7 @@
 #include <unistd.h>
 
 #include <cctype>
+#include <string_view>
 
 #include "blink/log_private.hh"
 
@@ -35,6 +36,8 @@ namespace aul {
 
 constexpr const char kAulBlink[] = "AUL_BLINK";
 constexpr const char kAulBlinkTimeout[] = "AUL_BLINK_TIMEOUT";
+constexpr const char kAulBlinkLevel[] = "AUL_BLINK_LEVEL";
+constexpr const char kAulBlinkOption[] = "AUL_BLINK_OPTION";
 
 class Blink {
  public:
@@ -45,6 +48,12 @@ class Blink {
       if (timeout && isdigit(timeout[0]))
         timeout_ = atoi(timeout);
 
+      const char* level = getenv(kAulBlinkLevel);
+      if (level) SetLevel(std::string_view(level));
+
+      const char* option = getenv(kAulBlinkOption);
+      if (option) SetOption(std::string_view(option));
+
       Set();
     }
   }
@@ -52,6 +61,26 @@ class Blink {
   ~Blink() { Clear(); }
 
  private:
+  void SetLevel(const std::string_view& level) {
+    if (level == "strong")
+      level_ = CPU_BOOSTING_LEVEL_STRONG;
+    else if (level == "medium")
+      level_ = CPU_BOOSTING_LEVEL_MEDIUM;
+    else if (level == "weak")
+      level_ = CPU_BOOSTING_LEVEL_WEAK;
+    else
+      _E("Unknown level=%s", level.data());
+  }
+
+  void SetOption(const std::string_view& option) {
+    if (option == "reset-on-fork")
+      option_ = CPU_BOOSTING_RESET_ON_FORK;
+    else if (option == "inherit-on-fork")
+      option_ = static_cast<cpu_boosting_flag_e>(0);
+    else
+      _E("Unknown option=%s", option.data());
+  }
+
   void Set() {
     pid_t pid = getpid();
     resource_pid_t res_pid = {
@@ -60,9 +89,7 @@ class Blink {
         .tid_count = 1,
     };
 
-    int ret =
-        resource_set_cpu_boosting(res_pid, CPU_BOOSTING_LEVEL_STRONG,
-                                  CPU_BOOSTING_RESET_ON_FORK, -1);
+    int ret = resource_set_cpu_boosting(res_pid, level_, option_, -1);
     if (ret != 0) {
       _E("resource_set_cpu_boosting() is failed. error=%d", ret);
       return;
@@ -102,6 +129,8 @@ class Blink {
  private:
   bool enabled_ = false;
   int timeout_ = 5000;
+  cpu_boosting_level_e level_ = CPU_BOOSTING_LEVEL_STRONG;
+  cpu_boosting_flag_e option_ = CPU_BOOSTING_RESET_ON_FORK;
   guint source_ = 0;
 };