From b7dca8d5599d1692546c5da07d5223befd756f80 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 15 Apr 2024 13:33:04 +0900 Subject: [PATCH] Add new options to blink feature 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 --- src/blink/aul_blink.cc | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/blink/aul_blink.cc b/src/blink/aul_blink.cc index 8b60676..42c2a28 100644 --- a/src/blink/aul_blink.cc +++ b/src/blink/aul_blink.cc @@ -22,6 +22,7 @@ #include #include +#include #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(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; }; -- 2.7.4