cpu-boosting: parse CpuBoostingLevel conf 41/276341/7
authorUnsung Lee <unsung.lee@samsung.com>
Wed, 15 Jun 2022 04:05:09 +0000 (13:05 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Wed, 15 Jun 2022 05:51:43 +0000 (14:51 +0900)
Change-Id: I7f3accb4d20d1a51b172157510bcfcf8ef8b05a8
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
12 files changed:
conf/optimizer.conf
packaging/resourced.spec
src/CMakeLists.txt
src/common/config-parser.c
src/common/config-parser.h
src/common/cpu-common.c
src/common/cpu-common.h
src/common/notifier.h
src/common/proc-common.h
src/resource-limiter/cpu/cpu-throttling.c [moved from src/resource-limiter/cpu/cpu.c with 99% similarity]
src/resource-optimizer/cpu/cpu-boosting.c [new file with mode: 0644]
src/resourced/init.c

index d29a83b..af09070 100644 (file)
@@ -32,3 +32,15 @@ FragLevel=800
 
 [CpuAffinity]
 #ForegroundApps=1,2,4-6
+
+[CpuBoostingLevelStrong]
+CpuSched=rr
+CpuRTPriority=49
+
+[CpuBoostingLevelMedium]
+CpuSched=rr
+CpuRTPriority=1
+
+[CpuBoostingLevelWeak]
+CpuSched=other
+CpuNice=-20 # Priority=100
index 94da3d0..277e557 100644 (file)
@@ -16,9 +16,10 @@ License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
 
 # Notice : to use freezer module, you should install system-freezer plugin
-%define cpu_module          ON
-%define memory_module       ON
-%define watchdog_module     ON
+%define cpu_throttling_module   ON
+%define cpu_boosting_module     ON
+%define memory_module           ON
+%define watchdog_module         ON
 
 %define confdir %{_sysconfdir}/resourced
 %define plugindir %{_libdir}/resourced/plugins
@@ -38,10 +39,11 @@ BuildRequires:  pkgconfig(libtzplatform-config)
 BuildRequires:  pkgconfig(storage)
 BuildRequires:  pkgconfig(libgum)
 BuildRequires:  pkgconfig(capi-system-device)
+BuildRequires:  pkgconfig(capi-system-resource)
 BuildRequires:  pkgconfig(cmocka)
 BuildRequires:  pkgconfig(libsyscommon)
-
 BuildRequires: gperf
+
 # for swap plugin
 Requires:      %{_sbindir}/mkswap
 Requires:      %{_bindir}/dd
@@ -103,18 +105,19 @@ Summary:  watchdog module for resourced
 %build
 mkdir -p build
 pushd build
-%cmake .. -DFULLVER=%{version} \
-        -DCMAKE_BUILD_TYPE=Release \
-        -DCPU_MODULE=%{cpu_module} \
-        -DMEMORY_MODULE=%{memory_module} \
-        -DPROC_WATCHDOG=%{watchdog_module} \
-        -DRD_SYS_ETC=%{TZ_SYS_ETC} \
-        -DRD_SYS_DATA=%{TZ_SYS_GLOBALUSER_DATA} \
-        -DRD_SYS_DB=%{TZ_SYS_GLOBALUSER_DB} \
-        -DRD_CONFIG_PATH=%{confdir} \
-        -DRD_PLUGIN_PATH=%{plugindir} \
-        -DRD_TESTS_PATH=%{_libdir}/resourced-tests \
-        -DRD_BINARY_NAME=resourced \
+%cmake .. -DFULLVER=%{version}                        \
+        -DCMAKE_BUILD_TYPE=Release                       \
+        -DCPU_THROTTLING_MODULE=%{cpu_throttling_module} \
+        -DCPU_BOOSTING_MODULE=%{cpu_boosting_module}     \
+        -DMEMORY_MODULE=%{memory_module}                 \
+        -DPROC_WATCHDOG=%{watchdog_module}               \
+        -DRD_SYS_ETC=%{TZ_SYS_ETC}                       \
+        -DRD_SYS_DATA=%{TZ_SYS_GLOBALUSER_DATA}          \
+        -DRD_SYS_DB=%{TZ_SYS_GLOBALUSER_DB}              \
+        -DRD_CONFIG_PATH=%{confdir}                      \
+        -DRD_PLUGIN_PATH=%{plugindir}                    \
+        -DRD_TESTS_PATH=%{_libdir}/resourced-tests       \
+        -DRD_BINARY_NAME=resourced                       \
         %{?asan:-DASAN_BUILD=True}
 
 make %{?jobs:-j%jobs}
index 032be94..8e71e70 100644 (file)
@@ -71,13 +71,20 @@ IF("${MEMORY_MODULE}" STREQUAL "ON")
   ENDFOREACH()
 ENDIF()
 
-IF("${CPU_MODULE}" STREQUAL "ON")
+IF("${CPU_THROTTLING_MODULE}" STREQUAL "ON")
   FILE(GLOB FILES "${CPU_LIMITER_SOURCE_DIR}/*.c")
   FOREACH(FILE ${FILES})
       SET(SOURCES ${SOURCES} ${FILE})
   ENDFOREACH()
 ENDIF()
 
+IF("${CPU_BOOSTING_MODULE}" STREQUAL "ON")
+  FILE(GLOB FILES "${CPU_RESOURCE_OPTIMIZER_SOURCE_DIR}/cpu-boosting.c")
+  FOREACH(FILE ${FILES})
+      SET(SOURCES ${SOURCES} ${FILE})
+  ENDFOREACH()
+ENDIF()
+
 SET(REQUIRES_LIST ${REQUIRES_LIST}
        dlog
        glib-2.0
@@ -91,6 +98,7 @@ SET(REQUIRES_LIST ${REQUIRES_LIST}
        libgum
        libtzplatform-config
        capi-system-device
+       capi-system-resource
        capi-system-info
        libudev
        dbus-1
@@ -159,7 +167,6 @@ ADD_LIBRARY(cpu-sched MODULE
 TARGET_LINK_LIBRARIES(cpu-sched resourced-private-api ${RESOURCED_REQUIRE_PKGS_LDFLAGS})
 INSTALL(TARGETS cpu-sched DESTINATION ${MAKE_INSTALL_PREFIX}${RD_PLUGIN_PATH})
 
-
 INSTALL(FILES ${CONF_DIR}/optimizer.conf DESTINATION ${RD_CONFIG_PATH})
 INSTALL(FILES ${CONF_DIR}/optimizer-profile-tv.conf DESTINATION ${RD_CONFIG_PATH})
 
index 1894931..4162aa7 100644 (file)
@@ -191,6 +191,21 @@ static int config_parse_sched_type(const char *value)
        }
 }
 
+static cpu_boosting_level_e config_parse_boosting_level(const char *value)
+{
+       if (!strncmp(value, CPU_BOOSTING_LEVEL_STRONG_VALUE_CONF,
+                               strlen(CPU_BOOSTING_LEVEL_STRONG_VALUE_CONF) + 1))
+               return CPU_BOOSTING_LEVEL_STRONG;
+       else if (!strncmp(value, CPU_BOOSTING_LEVEL_MEDIUM_VALUE_CONF,
+                               strlen(CPU_BOOSTING_LEVEL_MEDIUM_VALUE_CONF) + 1))
+               return CPU_BOOSTING_LEVEL_MEDIUM;
+       else if (!strncmp(value, CPU_BOOSTING_LEVEL_WEAK_VALUE_CONF,
+                               strlen(CPU_BOOSTING_LEVEL_WEAK_VALUE_CONF) + 1))
+               return CPU_BOOSTING_LEVEL_WEAK;
+       else
+               return CPU_BOOSTING_LEVEL_NONE;
+}
+
 static int optimizer_config(struct parse_result *result, void *user_data)
 {
        if (!result)
@@ -198,19 +213,19 @@ static int optimizer_config(struct parse_result *result, void *user_data)
 
        struct swap_conf *swap_conf = get_swap_conf();
        if (swap_conf == NULL) {
-               _E("[CONFIG] swap configuration is NULL");
+               _E("[CONFIG] memory swap configuration is NULL");
                return RESOURCED_ERROR_FAIL;
        }
 
        struct dedup_conf *dedup_conf = get_dedup_conf();
        if (dedup_conf == NULL) {
-               _E("[CONFIG] dedup configuration is NULL");
+               _E("[CONFIG] memory dedup configuration is NULL");
                return RESOURCED_ERROR_FAIL;
        }
 
        struct compact_conf *compact_conf = get_compact_conf();
        if (compact_conf == NULL) {
-               _E("[CONFIG] compact configuration is NULL");
+               _E("[CONFIG] memory compact configuration is NULL");
                return RESOURCED_ERROR_FAIL;
        }
 
@@ -367,6 +382,102 @@ static int optimizer_config(struct parse_result *result, void *user_data)
 
                return error;
        }
+       else if (!strncmp(result->section, CPU_BOOSTING_LEVEL_STRONG_SECTION,
+                               strlen(CPU_BOOSTING_LEVEL_STRONG_SECTION)+1)) {
+               struct cpu_boosting_conf *cpu_boosting_conf =
+                       get_cpu_boosting_conf(CPU_BOOSTING_LEVEL_STRONG);
+               if (cpu_boosting_conf == NULL) {
+                       _E("[CONFIG] cpu_boosting configuration is NULL");
+                       return RESOURCED_ERROR_FAIL;
+               }
+
+               if (!cpu_boosting_conf->enable)
+                       cpu_boosting_conf->enable = true;
+
+               if (!strncmp(result->name, CPU_SCHED_NAME_CONF,
+                                       strlen(CPU_SCHED_NAME_CONF) + 1)) {
+                       cpu_boosting_conf->cpu_sched_info.cpu_sched_type =
+                               config_parse_sched_type(result->value);
+               }
+               else if (!strncmp(result->name, CPU_NICE_NAME_CONF,
+                                       strlen(CPU_NICE_NAME_CONF) + 1)) {
+                       cpu_boosting_conf->cpu_sched_info.cpu_nice =
+                               atoi(result->value);
+               }
+               else if (!strncmp(result->name, CPU_RT_PRIORITY_NAME_CONF,
+                                       strlen(CPU_RT_PRIORITY_NAME_CONF) + 1)) {
+                       cpu_boosting_conf->cpu_sched_info.cpu_rt_priority =
+                               atoi(result->value);
+               }
+               else {
+                       _E("[CONFIG] Unknown configuration name (%s) and value (%s) on section (%s)",
+                                       result->name, result->value, result->section);
+               }
+       }
+       else if (!strncmp(result->section, CPU_BOOSTING_LEVEL_MEDIUM_SECTION,
+                               strlen(CPU_BOOSTING_LEVEL_MEDIUM_SECTION)+1)) {
+               struct cpu_boosting_conf *cpu_boosting_conf =
+                       get_cpu_boosting_conf(CPU_BOOSTING_LEVEL_MEDIUM);
+               if (cpu_boosting_conf == NULL) {
+                       _E("[CONFIG] cpu_boosting configuration is NULL");
+                       return RESOURCED_ERROR_FAIL;
+               }
+
+               if (!cpu_boosting_conf->enable)
+                       cpu_boosting_conf->enable = true;
+
+               if (!strncmp(result->name, CPU_SCHED_NAME_CONF,
+                                       strlen(CPU_SCHED_NAME_CONF) + 1)) {
+                       cpu_boosting_conf->cpu_sched_info.cpu_sched_type =
+                               config_parse_sched_type(result->value);
+               }
+               else if (!strncmp(result->name, CPU_NICE_NAME_CONF,
+                                       strlen(CPU_NICE_NAME_CONF) + 1)) {
+                       cpu_boosting_conf->cpu_sched_info.cpu_nice =
+                               atoi(result->value);
+               }
+               else if (!strncmp(result->name, CPU_RT_PRIORITY_NAME_CONF,
+                                       strlen(CPU_RT_PRIORITY_NAME_CONF) + 1)) {
+                       cpu_boosting_conf->cpu_sched_info.cpu_rt_priority =
+                               atoi(result->value);
+               }
+               else {
+                       _E("[CONFIG] Unknown configuration name (%s) and value (%s) on section (%s)",
+                                       result->name, result->value, result->section);
+               }
+       }
+       else if (!strncmp(result->section, CPU_BOOSTING_LEVEL_WEAK_SECTION,
+                               strlen(CPU_BOOSTING_LEVEL_WEAK_SECTION)+1)) {
+               struct cpu_boosting_conf *cpu_boosting_conf =
+                       get_cpu_boosting_conf(CPU_BOOSTING_LEVEL_WEAK);
+               if (cpu_boosting_conf == NULL) {
+                       _E("[CONFIG] cpu_boosting configuration is NULL");
+                       return RESOURCED_ERROR_FAIL;
+               }
+
+               if (!cpu_boosting_conf->enable)
+                       cpu_boosting_conf->enable = true;
+
+               if (!strncmp(result->name, CPU_SCHED_NAME_CONF,
+                                       strlen(CPU_SCHED_NAME_CONF) + 1)) {
+                       cpu_boosting_conf->cpu_sched_info.cpu_sched_type =
+                               config_parse_sched_type(result->value);
+               }
+               else if (!strncmp(result->name, CPU_NICE_NAME_CONF,
+                                       strlen(CPU_NICE_NAME_CONF) + 1)) {
+                       cpu_boosting_conf->cpu_sched_info.cpu_nice =
+                               atoi(result->value);
+               }
+               else if (!strncmp(result->name, CPU_RT_PRIORITY_NAME_CONF,
+                                       strlen(CPU_RT_PRIORITY_NAME_CONF) + 1)) {
+                       cpu_boosting_conf->cpu_sched_info.cpu_rt_priority =
+                               atoi(result->value);
+               }
+               else {
+                       _E("[CONFIG] Unknown configuration name (%s) and value (%s) on section (%s)",
+                                       result->name, result->value, result->section);
+               }
+       }
        else {
                _E("[CONFIG] Unknown section name (%s) and value (%s) on section (%s)",
                                result->name, result->value, result->section);
@@ -577,6 +688,7 @@ static int vendor_config(struct parse_result *result, void *user_data)
                        pci->cpu_sched_info.cpu_nice = CPU_INIT_NICE;
                        pci->watchdog_action = PROC_ACTION_KILL;
                        pci->fail_action = PROC_ACTION_IGNORE;
+                       pci->cpu_boosting_level = CPU_BOOSTING_LEVEL_NONE;
                        strncpy(pci->name, result->value, sizeof(pci->name)-1);
 
                        if (result->name[0] == 'A') {
@@ -663,6 +775,7 @@ static int vendor_config(struct parse_result *result, void *user_data)
                        _E("process configuration information pointer should not be NULL");
                        return RESOURCED_ERROR_FAIL;
                }
+
                pci->cpu_sched_info.cpu_nice = atoi(result->value);
        }
        else if (!strncmp(result->name, CPU_RT_PRIORITY_NAME_CONF,
@@ -671,8 +784,18 @@ static int vendor_config(struct parse_result *result, void *user_data)
                        _E("process configuration information pointer should not be NULL");
                        return RESOURCED_ERROR_FAIL;
                }
+
                pci->cpu_sched_info.cpu_rt_priority = atoi(result->value);
        }
+       else if (!strncmp(result->name, CPU_BOOSTING_LEVEL_NAME_CONF,
+                               strlen(CPU_BOOSTING_LEVEL_NAME_CONF)+1) && *config_type == OPTIMIZER_CONFIG) {
+               if (!pci) {
+                       _E("process configuration information pointer should not be NULL");
+                       return RESOURCED_ERROR_FAIL;
+               }
+
+               pci->cpu_boosting_level = config_parse_boosting_level(result->value);
+       }
 /*     else if (!strncmp(result->name, CPU_RT_RUN_TIME_NAME_CONF,
                                strlen(CPU_RT_RUN_TIME_NAME_CONF)+1) &&
                        *config_type == OPTIMIZER_CONFIG) {
index 914fead..5e82945 100644 (file)
@@ -54,9 +54,9 @@ extern "C" {
 #define COMPACTION_SECTION                  "MemoryCompaction"
 #define CPU_SCHED_SECTION                   "CpuSched"
 #define CPU_AFFINITY_SECTION                "CpuAffinity"
-#define CPU_BOOSTING_LEVEL_STRONG           "CpuBoostingLevelStrong"
-#define CPU_BOOSTING_LEVEL_MEDIUM           "CpuBoostingLevelMedium"
-#define CPU_BOOSTING_LEVEL_WEAK             "CpuBoostingLevelWeak"
+#define CPU_BOOSTING_LEVEL_STRONG_SECTION   "CpuBoostingLevelStrong"
+#define CPU_BOOSTING_LEVEL_MEDIUM_SECTION   "CpuBoostingLevelMedium"
+#define CPU_BOOSTING_LEVEL_WEAK_SECTION     "CpuBoostingLevelWeak"
 
 /* configuration name */
 /* limiter.conf */
index 0cb4f93..f264360 100644 (file)
 static struct cpu_sched_conf *cpu_sched_conf = NULL;
 static struct cpu_affinity_conf *cpu_affinity_conf = NULL;
 static struct cpu_throttling_conf *cpu_throttling_conf = NULL;
+static struct cpu_boosting_conf *cpu_boosting_conf[CPU_BOOSTING_LEVEL_END] = {NULL, };
 
 struct cpu_sched_conf *get_cpu_sched_conf(void)
 {
        if (!cpu_sched_conf) {
                cpu_sched_conf = (struct cpu_sched_conf *)calloc(1, sizeof (struct cpu_sched_conf));
                if (!cpu_sched_conf) {
-                       _E("Failed to alloc memory for cpu configuration");
+                       _E("Failed to alloc memory for cpu scheduler configuration");
                        return NULL;
                }
                else {
@@ -70,7 +71,7 @@ int set_cpu_affinity_conf(const char *name, const char *value)
        if (!cpu_affinity_conf) {
                cpu_affinity_conf = (struct cpu_affinity_conf *)calloc(1, sizeof (struct cpu_affinity_conf));
                if (!cpu_affinity_conf) {
-                       _E("Failed to alloc memory for cpu configuration");
+                       _E("Failed to alloc memory for cpu affinity configuration");
                        return RESOURCED_ERROR_OUT_OF_MEMORY;
                }
        }
@@ -101,7 +102,7 @@ struct cpu_throttling_conf *get_cpu_throttling_conf(void)
        if (!cpu_throttling_conf) {
                cpu_throttling_conf = (struct cpu_throttling_conf *)calloc(1, sizeof (struct cpu_throttling_conf));
                if (!cpu_throttling_conf) {
-                       _E("Failed to alloc memory for cpu configuration");
+                       _E("Failed to alloc memory for cpu throttling configuration");
                        return NULL;
                }
                else {
@@ -123,3 +124,29 @@ void free_cpu_throttling_conf(void)
                free(cpu_throttling_conf);
 }
 
+struct cpu_boosting_conf *get_cpu_boosting_conf(cpu_boosting_level_e level)
+{
+       if (!cpu_boosting_conf[level]) {
+               cpu_boosting_conf[level] = (struct cpu_boosting_conf *)
+                       calloc(1, sizeof (struct cpu_boosting_conf));
+
+               if (!cpu_boosting_conf[level]) {
+                       _E("Failed to alloc memory for cpu boosting (level = %d) configuration", level);
+                       return NULL;
+               }
+               else {
+                       cpu_boosting_conf[level]->enable = false;
+                       cpu_boosting_conf[level]->cpu_sched_info.cpu_sched_type = CPU_SCHED_NONE;
+                       cpu_boosting_conf[level]->cpu_sched_info.cpu_nice = CPU_INIT_NICE;
+                       cpu_boosting_conf[level]->cpu_sched_info.cpu_rt_priority = CPU_INIT_PRIO;
+               }
+       }
+
+       return cpu_boosting_conf[level];
+}
+
+void free_cpu_boosting_conf(cpu_boosting_level_e level)
+{
+       if (cpu_boosting_conf[level])
+               free(cpu_boosting_conf[level]);
+}
index 64e5d26..67ec557 100644 (file)
@@ -3,6 +3,8 @@
 
 #include <stdbool.h>
 
+#include <cpu-boosting-type.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif /* __cplusplus */
@@ -69,6 +71,11 @@ struct cpu_throttling_conf {
        struct cpu_cgroup_info cpu_cgroup_info;
 };
 
+struct cpu_boosting_conf {
+       bool enable;
+       struct cpu_sched_info cpu_sched_info;
+};
+
 struct cpu_sched_conf *get_cpu_sched_conf(void);
 void free_cpu_sched_conf(void);
 
@@ -79,6 +86,10 @@ void free_cpu_affinity_conf(void);
 
 struct cpu_throttling_conf *get_cpu_throttling_conf(void);
 void free_cpu_throttling_conf(void);
+
+struct cpu_boosting_conf *get_cpu_boosting_conf(cpu_boosting_level_e level);
+void free_cpu_boosting_conf(cpu_boosting_level_e level);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
index 7fa0032..e3cd6d4 100644 (file)
@@ -88,6 +88,7 @@ enum notifier_type {
        RESOURCED_NOTIFIER_MEM_CONTROL,
        RESOURCED_NOTIFIER_LIMIT_APP,
        RESOURCED_NOTIFIER_THROTTLING_RESOURCE,
+       RESOURCED_NOTIFIER_BOOSTING_RESOURCE,
 
        /*
         * control system service (*.service)
index 5b09622..9ac5960 100644 (file)
@@ -68,6 +68,7 @@ struct proc_conf_info {
        struct cpu_sched_info cpu_sched_info;
        bool memory_throttling_enable;
        bool cpu_throttling_enable;
+       cpu_boosting_level_e cpu_boosting_level;
        pid_t pid;
 };
 
similarity index 99%
rename from src/resource-limiter/cpu/cpu.c
rename to src/resource-limiter/cpu/cpu-throttling.c
index 1a5a028..f11eb8d 100644 (file)
@@ -174,7 +174,7 @@ static void load_cpu_throttling_config(void)
        }
 
        if (!cpu_throttling_conf->enable) {
-               _D("[CPU-THROTTLING] cpu throttling is disabled");
+               _I("[CPU-THROTTLING] cpu throttling is disabled");
                goto free_cpu_throttling_conf;
        }
 
@@ -288,7 +288,7 @@ static int resourced_cpu_finalize(void *data)
 
 static struct module_ops cpu_modules_ops = {
        .priority = MODULE_PRIORITY_NORMAL,
-       .name = "cpu",
+       .name = "cpu-throttling",
        .init = resourced_cpu_init,
        .exit = resourced_cpu_finalize,
 };
diff --git a/src/resource-optimizer/cpu/cpu-boosting.c b/src/resource-optimizer/cpu/cpu-boosting.c
new file mode 100644 (file)
index 0000000..27d193e
--- /dev/null
@@ -0,0 +1,132 @@
+#include <stdio.h>
+#include "module.h"
+#include "macro.h"
+#include "util.h"
+#include "trace.h"
+#include "notifier.h"
+#include "resourced.h"
+#include "cpu-common.h"
+#include "proc-common.h"
+
+bool boosting_success[CPU_BOOSTING_LEVEL_END] = {false, };
+struct sched_attr boosting_attr[CPU_BOOSTING_LEVEL_END];
+
+static bool load_cpu_boosting_config(cpu_boosting_level_e level)
+{
+       int cpu_nice, cpu_rt_priority, cpu_policy;
+
+       enum cpu_sched_type cpu_sched_type;
+
+       struct cpu_boosting_conf *cpu_boosting_conf = get_cpu_boosting_conf(level);
+       if (cpu_boosting_conf == NULL) {
+               _E("[CPU-BOOSTING] Boosting (level = %d) configuration structure should not be NULL",
+                               level);
+               return false;
+       }
+
+       if (!cpu_boosting_conf->enable) {
+               _D("[CPU-BOOSTING] Cpu boosting is disabled");
+               return false;
+       }
+
+       cpu_nice = cpu_boosting_conf->cpu_sched_info.cpu_nice;
+       cpu_rt_priority = cpu_boosting_conf->cpu_sched_info.cpu_rt_priority;
+       cpu_sched_type = cpu_boosting_conf->cpu_sched_info.cpu_sched_type;
+
+       if (cpu_sched_type < CPU_SCHED_BATCH || cpu_sched_type > CPU_SCHED_RR) {
+               _E("[CPU-BOOSTING] Cpu scheduler type is unknown or idle");
+               return false;
+       }
+
+       memset(&boosting_attr[level], 0, sizeof(struct sched_attr));
+
+       if (cpu_sched_type == CPU_SCHED_BATCH || cpu_sched_type == CPU_SCHED_OTHER) {
+               if (cpu_nice < CPU_MIN_NICE || cpu_nice > CPU_MAX_NICE) {
+                       _E("[CPU-BOOSTING] Cpu nice (= %d) is out of scope", cpu_nice);
+                       return false;
+               }
+
+               if (cpu_rt_priority != CPU_INIT_PRIO) {
+                       _E("[CPU-BOOSTING] Cpu rt priority (= %d) is out of scope", cpu_rt_priority);
+                       return false;
+               }
+
+               if (cpu_sched_type == CPU_SCHED_BATCH)
+                       cpu_policy = SCHED_BATCH;
+               else
+                       cpu_policy = SCHED_OTHER;
+
+               boosting_attr[level].sched_nice = cpu_nice;
+       }
+       else {
+               if (cpu_rt_priority < CPU_MIN_PRIO || cpu_rt_priority > CPU_MAX_PRIO) {
+                       _E("[CPU-BOOSTING] Cpu rt priority (= %d) is out of scope", cpu_rt_priority);
+                       return false;
+               }
+
+               if (cpu_sched_type == CPU_SCHED_RR)
+                       cpu_policy = SCHED_RR;
+               else
+                       cpu_policy = SCHED_FIFO;
+       }
+
+       boosting_attr[level].size = sizeof(struct sched_attr);
+       boosting_attr[level].sched_policy = cpu_policy;
+       boosting_attr[level].sched_priority = cpu_rt_priority;
+
+       _I("[CPU-BOOSTING] Boosting (level = %d) policy = %s", level,
+               boosting_attr[level].sched_policy == SCHED_BATCH ? "SCHED_BATCH" :
+                       boosting_attr[level].sched_policy == SCHED_OTHER ? "SCHED_OTHER" :
+                       boosting_attr[level].sched_policy == SCHED_RR ? "SCHED_RR" : "SCHED_FIFO");
+       _I("[CPU-BOOSTING] Boosting (level = %d) nice = %d", level, boosting_attr[level].sched_nice);
+       _I("[CPU-BOOSTING] Boosting (level = %d) priority = %d", level, boosting_attr[level].sched_priority);
+
+       return true;
+}
+
+static void load_cpu_boosting_configs(void)
+{
+       for (int i = CPU_BOOSTING_LEVEL_STRONG; i < CPU_BOOSTING_LEVEL_END; i++) {
+               boosting_success[i] = load_cpu_boosting_config(i);
+               if (!boosting_success[i])
+                       _I("[CPU-BOOSTING] Boosting (level = %d) is not supported", i);
+               free_cpu_boosting_conf(i);
+       }
+}
+
+static int cpu_boosting_enqueue(void *data)
+{
+       assert(data);
+
+       struct proc_status *ps = (struct proc_status *)data;
+
+       if (ps->pci == NULL)
+               return RESOURCED_ERROR_NONE;
+
+       _I("[CPU-BOOSTING] pid = %d, level = %d", ps->pid, ps->pci->cpu_boosting_level);
+
+       return RESOURCED_ERROR_NONE;
+}
+
+static int cpu_boosting_init(void *data)
+{
+       load_cpu_boosting_configs();
+
+       register_notifier(RESOURCED_NOTIFIER_BOOSTING_RESOURCE, cpu_boosting_enqueue);
+       return RESOURCED_ERROR_NONE;
+}
+
+static int cpu_boosting_finalize(void *data)
+{
+       unregister_notifier(RESOURCED_NOTIFIER_BOOSTING_RESOURCE, cpu_boosting_enqueue);
+       return RESOURCED_ERROR_NONE;
+}
+
+static struct module_ops cpu_boosting_modules_ops = {
+       .priority = MODULE_PRIORITY_HIGH,
+       .name = "cpu-boosting",
+       .init = cpu_boosting_init,
+       .exit = cpu_boosting_finalize,
+};
+
+MODULE_REGISTER(&cpu_boosting_modules_ops)
index 497a9df..10451f2 100644 (file)
@@ -356,6 +356,14 @@ int fixed_service_list_init(void *data)
                _I("[CPU-SCHED] %s's priority = %d", pci->name, attr.sched_priority);
 
 skip_scheduler_update:
+               /* Put a system service into (cpu) boosting group */
+               if (pci->cpu_boosting_level != CPU_BOOSTING_LEVEL_NONE) {
+                       struct proc_status ps = {0, };
+                       ps.pid = pid;
+                       ps.pci = pci;
+                       resourced_notify(RESOURCED_NOTIFIER_BOOSTING_RESOURCE, &ps);
+               }
+
                /* register a notification when this service is released */
                switch (pci->fail_action) {
                        case PROC_ACTION_REBOOT:
@@ -367,20 +375,6 @@ skip_scheduler_update:
                                _W("[WATCHDOG] Currently we support only REBOOT when a service is released");
                }
 
-/*             if (pci->cpu_sched_info.cpu_sched_type == CPU_SCHED_FIFO ||
-                   pci->cpu_sched_info.cpu_sched_type == CPU_SCHED_RR ||
-                       pci->cpu_sched_info.cpu_sched_type == CPU_SCHED_DEADLINE) {
-                       if (pci->cpu_sched_info.rt_period_us > 0 &&
-                           pci->cpu_sched_info.rt_runtime_us > 0 &&
-                               pci->cpu_sched_info.rt_period_us > pci->cpu_sched_info.rt_runtime_us) {
-                               struct proc_status ps = {0, };
-
-                               ps.pid = pid;
-                               ps.pci = pci;
-                               resourced_notify(RESOURCED_NOTIFIER_RT_SCHEDULER, &ps);
-                       }
-               }*/
-
                /* Put a system service into (memory) throttling group */
                if (pci->memory_throttling_enable)
                        cgroup_write_pid_fullpath(MEMCG_THROTTLING_PATH, pid);