Update CPU idle model 72/232572/3
authorKichan Kwon <k_c.kwon@samsung.com>
Wed, 6 May 2020 10:54:02 +0000 (19:54 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Thu, 7 May 2020 02:41:55 +0000 (11:41 +0900)
- Reset CPU idle counter on busy
- Threshold variance policy is changed
  - On idle, decrease threshold with variance
  - Initialize after idle accept count times

Change-Id: Ifdb04013689926e7cda512dbd1590817376b28bd
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
config/bm_params.json
include/bm_config_parser.h
src/bm_config_parser.c
src/bm_power_engine.c

index 546c550..760d732 100644 (file)
@@ -8,7 +8,7 @@
        "cpu_usage_checker": {
                "timeout": 60000,
                "initial_threshold": 0.60,
-               "minimum_threshold": 0.50,
-               "threshold_reduction": 0.00
+               "maximum_threshold": 0.70,
+               "threshold_variance": 0.00
        }
 }
index c0f5f8e..bd00f1f 100644 (file)
@@ -51,7 +51,7 @@ int bm_get_battery_power_params(int *battery);
 
 int bm_get_job_scheduler_params(int *data_collection_period, int *data_collection_try_period, int *data_collection_accept_count, int *delete_db_period);
 
-int bm_get_cpu_usage_checker_params(int *timeout, double *initial_threshold, double *minimum_threshold, double *threshold_reduction);
+int bm_get_cpu_usage_checker_params(int *timeout, double *initial_threshold, double *maximum_threshold, double *threshold_variance);
 
 #ifdef __cplusplus
 }
index 9641bc6..730db07 100644 (file)
@@ -615,7 +615,7 @@ END:
 }
 
 int bm_get_cpu_usage_checker_params(int *timeout, double *initial_threshold,
-                                       double *minimum_threshold, double *threshold_reduction)
+                                       double *maximum_threshold, double *threshold_variance)
 {
        ENTER;
 
@@ -626,8 +626,8 @@ int bm_get_cpu_usage_checker_params(int *timeout, double *initial_threshold,
 
        BM_CHECK_INPUT_PARAM(timeout);
        BM_CHECK_INPUT_PARAM(initial_threshold);
-       BM_CHECK_INPUT_PARAM(minimum_threshold);
-       BM_CHECK_INPUT_PARAM(threshold_reduction);
+       BM_CHECK_INPUT_PARAM(maximum_threshold);
+       BM_CHECK_INPUT_PARAM(threshold_variance);
 
        contents = bm_read_content_from_file(BATTERY_MONITOR_CONFIG_FILE_PATH);
 
@@ -652,19 +652,19 @@ int bm_get_cpu_usage_checker_params(int *timeout, double *initial_threshold,
                goto END;
        *initial_threshold = json_object_get_double(jdouble);
 
-       json_object_object_get_ex(jvalue, "minimum_threshold", &jdouble);
+       json_object_object_get_ex(jvalue, "maximum_threshold", &jdouble);
        if (!jdouble)
                goto END;
-       *minimum_threshold = json_object_get_double(jdouble);
+       *maximum_threshold = json_object_get_double(jdouble);
 
-       json_object_object_get_ex(jvalue, "threshold_reduction", &jdouble);
+       json_object_object_get_ex(jvalue, "threshold_variance", &jdouble);
        if (!jdouble)
                goto END;
-       *threshold_reduction = json_object_get_double(jdouble);
+       *threshold_variance = json_object_get_double(jdouble);
 
        _DBG("data collection params - timeout[%d], initial_threshold[%lf], \
-               minimum_threshold[%lf], threshold_reduction[%lf]", *timeout, *initial_threshold,
-               *minimum_threshold, *threshold_reduction);
+               maximum_threshold[%lf], threshold_variance[%lf]", *timeout, *initial_threshold,
+               *maximum_threshold, *threshold_variance);
 
        ret = BATTERY_MONITOR_ERROR_NONE;
 END:
index def2488..f02f1cc 100644 (file)
@@ -1844,17 +1844,9 @@ int bm_get_up_time(double *up_time)
        return BATTERY_MONITOR_ERROR_NONE;
 }
 
-gboolean is_cpu_idle(void)
+gboolean is_cpu_idle(double usage_ratio_threshold)
 {
-       static gboolean is_parameter_loaded = FALSE;
-       static int timeout = 60000;
-       static double initial_threshold = 0.60;
-       static double minimum_threshold = 0.50;
-       static double threshold_reduction = 0.0;
-       static int num_cpu_core = 1;
-
-       static int remaining_timeout = 60000;
-       static double usage_ratio_threshold = 0.60;
+       static int num_cpu_core = -1;
 
        int idx;
        unsigned long long cpu_time_cur[CT_NUM];
@@ -1863,37 +1855,23 @@ gboolean is_cpu_idle(void)
        double up_time_diff;
        double usage_ratio;
 
-       if (!is_parameter_loaded) {
-               if (bm_get_cpu_usage_checker_params(&timeout, &initial_threshold, &minimum_threshold, &threshold_reduction) != BATTERY_MONITOR_ERROR_NONE) {
-                       _ERR("error getting cpu usage checker parameters");
-                       return FALSE;
-               }
-               remaining_timeout = timeout;
-               usage_ratio_threshold = initial_threshold;
-
+       if (num_cpu_core < 0) {
                if (runtime_info_get_processor_count(&num_cpu_core) != RUNTIME_INFO_ERROR_NONE) {
                        _ERR("error getting the number of cpu core");
                        return FALSE;
                }
-
-               is_parameter_loaded = TRUE;
-       }
-
-       if (remaining_timeout <= 0) {
-               _DBG("timeout!");
-               goto satisfy;
        }
 
        // Get CPU time
        if (bm_get_cpu_time(cpu_time_cur) != BATTERY_MONITOR_ERROR_NONE) {
                _ERR("error getting CPU time");
-               goto unsatisfy;
+               return FALSE;
        }
 
        for (idx = 0; idx < CT_NUM; idx++) {
                if (cpu_time_last[idx] > cpu_time_cur[idx]) {
                        _ERR("error invalid CPU time");
-                       goto unsatisfy;
+                       return FALSE;
                }
                cpu_time_diff[idx] = cpu_time_cur[idx] - cpu_time_last[idx];
        }
@@ -1904,12 +1882,12 @@ gboolean is_cpu_idle(void)
        // Get uptime
        if (bm_get_up_time(&up_time_cur) != BATTERY_MONITOR_ERROR_NONE) {
                _ERR("error getting uptime");
-               goto unsatisfy;
+               return FALSE;
        }
 
        if (up_time_last >= up_time_cur) {
                _ERR("error invalid uptime");
-               goto unsatisfy;
+               return FALSE;
        }
 
        up_time_diff = up_time_cur - up_time_last;
@@ -1921,23 +1899,11 @@ gboolean is_cpu_idle(void)
                usage_ratio = 1.0;
        if (usage_ratio > usage_ratio_threshold) {
                _WARN("CPU usage = %.2lf%% (BUSY, criteria[%.2lf%%])", usage_ratio * 100, usage_ratio_threshold * 100);
-               goto unsatisfy;
+               return FALSE;
        }
 
-       _DBG("CPU usage = %.2lf%% (IDLE)", usage_ratio * 100);
-
-satisfy:
-       remaining_timeout = timeout;
-       usage_ratio_threshold = initial_threshold;
-
+       _DBG("CPU usage = %.2lf%% (IDLE, criteria[%.2lf%%])", usage_ratio * 100, usage_ratio_threshold * 100);
        return TRUE;
-
-unsatisfy:
-       remaining_timeout -= data_collection_try_period;
-       if (usage_ratio_threshold > minimum_threshold)
-               usage_ratio_threshold -= threshold_reduction;
-
-       return FALSE;
 }
 
 gboolean bm_try_request_feature_data(gpointer data)
@@ -1947,19 +1913,56 @@ gboolean bm_try_request_feature_data(gpointer data)
                CALC_AND_STORE,
        };
 
+       static gboolean is_parameter_loaded = FALSE;
+       static int timeout = 60000;
+       static double initial_threshold = 0.60;
+       static double maximum_threshold = 0.70;
+       static double threshold_variance = 0.0;
+
+       static int remaining_timeout = 60000;
+       static double usage_ratio_threshold = 0.60;
+
        static enum status status = GET_DATA;
        static int idle_count = 0;
        int ret_val;
 
-       if (!is_cpu_idle())
+       if (!is_parameter_loaded) {
+               if (bm_get_cpu_usage_checker_params(&timeout, &initial_threshold, &maximum_threshold, &threshold_variance) != BATTERY_MONITOR_ERROR_NONE) {
+                       _ERR("error getting cpu usage checker parameters");
+                       return G_SOURCE_REMOVE;
+               }
+               remaining_timeout = timeout;
+               usage_ratio_threshold = initial_threshold;
+
+               is_parameter_loaded = TRUE;
+       }
+
+       if (remaining_timeout <= 0) {
+               _DBG("timeout!");
+               goto request;
+       }
+       remaining_timeout -= data_collection_try_period;
+
+       if (!is_cpu_idle(usage_ratio_threshold)) {
+               idle_count = 0;
+               if (usage_ratio_threshold < maximum_threshold)
+                       usage_ratio_threshold += threshold_variance;
+
                return G_SOURCE_CONTINUE;
+       }
 
        idle_count++;
+       if (usage_ratio_threshold > initial_threshold)
+               usage_ratio_threshold -= threshold_variance;
+
        _DBG("Idle count(%d/%d)", idle_count, data_collection_accept_count);
        if (idle_count < data_collection_accept_count)
                return G_SOURCE_CONTINUE;
 
+request:
        idle_count = 0;
+       remaining_timeout = timeout;
+       usage_ratio_threshold = initial_threshold;
 
        switch (status) {
        case GET_DATA:  // Request data to plugin