Change threshold to detect idle time dynamically 53/131053/9
authorJunghoon Park <jh9216.park@samsung.com>
Thu, 25 May 2017 07:52:45 +0000 (16:52 +0900)
committerHwanKyu Jhun <h.jhun@samsung.com>
Wed, 31 May 2017 23:33:10 +0000 (23:33 +0000)
- Some devices may have not enough cpu power to reach maximum threshold.
- To cover this issue, the threshold should be changed properly

Change-Id: I28dcfc5e1e2353b9eef47a83e68b834412560cd5
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
CMakeLists.txt
src/launchpad.c

index 23a351c..6a03d54 100755 (executable)
@@ -109,7 +109,7 @@ SET(${LAUNCHPAD_PROCESS_POOL}_SOURCE_FILES
        )
 ADD_EXECUTABLE(${LAUNCHPAD_PROCESS_POOL} ${${LAUNCHPAD_PROCESS_POOL}_SOURCE_FILES})
 
-TARGET_LINK_LIBRARIES(${LAUNCHPAD_PROCESS_POOL} ${${this_target_pool}_LDFLAGS} "-pie")
+TARGET_LINK_LIBRARIES(${LAUNCHPAD_PROCESS_POOL} ${${this_target_pool}_LDFLAGS} "-pie -lm")
 SET_TARGET_PROPERTIES(${LAUNCHPAD_PROCESS_POOL} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_pool})
 SET_TARGET_PROPERTIES(${LAUNCHPAD_PROCESS_POOL}
        PROPERTIES SKIP_BUILD_RPATH TRUE
index ce1a77f..a9a55b4 100755 (executable)
@@ -34,6 +34,7 @@
 #include <linux/limits.h>
 #include <ttrace.h>
 #include <vconf.h>
+#include <math.h>
 
 #include "perf.h"
 #include "launchpad_common.h"
@@ -59,6 +60,9 @@
 #define PAD_ERR_INVALID_ARGUMENT       -3
 #define PAD_ERR_INVALID_PATH           -4
 #define CPU_CHECKER_TIMEOUT            1000
+#define DEFAULT_THRESHOLD              90
+#define MIN_THRESHOLD                  40
+#define PI                             3.14159265
 
 typedef struct {
        int type;
@@ -103,6 +107,7 @@ static int user_slot_offset;
 static GList *candidate_slot_list;
 static app_labels_monitor *label_monitor;
 static GList *launcher_info_list;
+static int __threshold = DEFAULT_THRESHOLD;
 
 static candidate_process_context_t *__add_slot(int type, int loader_id,
                int caller_pid, const char *loader_path, const char *extra,
@@ -1080,6 +1085,39 @@ static gboolean __handle_label_monitor(gpointer data)
        return G_SOURCE_CONTINUE;
 }
 
+static float __interpolator(float input)
+{
+       float ret;
+       float min = MIN_THRESHOLD / 100.0f;
+       float max = DEFAULT_THRESHOLD / 100.0f;
+
+       if (input > 1.0f)
+               input = 1.0f;
+       if (input < 0.0f)
+               input = 0.0f;
+
+       ret = cos(input * PI) / 2.0f + 0.5f;
+       ret *= max - min;
+       ret += min;
+
+       return ret;
+}
+
+static void __update_threshold(float delta)
+{
+       static float pos = 0.0f;
+
+       pos += delta;
+       if (pos < 0.0f)
+               pos = 0.0f;
+
+       if (pos > 1.0f)
+               pos = 1.0f;
+
+       __threshold = (int)(__interpolator(pos) * 100);
+       _D("[CPU] delta:%f / input cursor : %f / threshold : %d", delta, pos, __threshold);
+}
+
 static gboolean __handle_idle_checker(gpointer data)
 {
        unsigned long long total = 0;
@@ -1092,9 +1130,10 @@ static gboolean __handle_idle_checker(gpointer data)
                total++;
 
        per = (idle - cpc->cpu_idle_time) * 100 / (total - cpc->cpu_total_time);
-       _D("CPU Idle : %d %d", per, cpc->type);
+       _D("[CPU] Idle : %d / type : %d", per, cpc->type);
 
-       if (per >= 90) {
+       if (per >= __threshold) {
+               __update_threshold(-0.02f * (per - __threshold));
                __prepare_candidate_process(cpc->type, cpc->loader_id);
                cpc->idle_checker = 0;
                return G_SOURCE_REMOVE;
@@ -1102,6 +1141,8 @@ static gboolean __handle_idle_checker(gpointer data)
 
        cpc->cpu_idle_time = idle;
        cpc->cpu_total_time = total;
+       __update_threshold(0.05f);
+
        return G_SOURCE_CONTINUE;
 }