#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 {
unsigned long long cpu_idle_time;
guint idle_checker;
int threshold;
+ int threshold_max;
+ int threshold_min;
} candidate_process_context_t;
typedef struct {
static candidate_process_context_t *__add_slot(int type, int loader_id,
int caller_pid, const char *loader_path, const char *extra,
- int detection_method, int timeout_val);
+ int detection_method, int timeout_val,
+ int threshold_max, int threshold_min);
static int __remove_slot(int type, int loader_id);
static int __add_default_slots(void);
static gboolean __handle_idle_checker(gpointer data);
return G_SOURCE_CONTINUE;
}
-static float __interpolator(float input)
+static float __interpolator(float input, int cpu_max, int cpu_min)
{
float ret;
- float min = MIN_THRESHOLD / 100.0f;
- float max = DEFAULT_THRESHOLD / 100.0f;
+ float min = cpu_min / 100.0f;
+ float max = cpu_max / 100.0f;
if (input > 1.0f)
input = 1.0f;
if (pos > 1.0f)
pos = 1.0f;
- cpc->threshold = (int)(__interpolator(pos) * 100);
+ cpc->threshold = (int)(__interpolator(pos,
+ cpc->threshold_max, cpc->threshold_min) * 100);
_D("[CPU] type:%d / delta:%f / input cursor : %f / threshold : %d",
cpc->type, delta, pos, cpc->threshold);
}
lid = __make_loader_id();
cpc = __add_slot(LAUNCHPAD_TYPE_DYNAMIC, lid, atoi(caller_pid),
add_slot_str, extra,
- METHOD_TIMEOUT | METHOD_VISIBILITY, 2000);
+ METHOD_TIMEOUT | METHOD_VISIBILITY, 2000,
+ DEFAULT_CPU_THRESHOLD_MAX, DEFAULT_CPU_THRESHOLD_MIN);
__set_timer(cpc);
return lid;
}
static candidate_process_context_t *__add_slot(int type, int loader_id,
int caller_pid, const char *loader_path,
const char *loader_extra, int detection_method,
- int timeout_val)
+ int timeout_val, int threshold_max, int threshold_min)
{
candidate_process_context_t *cpc;
int fd = -1;
cpc->cpu_total_time = 0;
cpc->cpu_idle_time = 0;
cpc->idle_checker = 0;
- cpc->threshold = DEFAULT_THRESHOLD;
+ cpc->threshold = threshold_max;
+ cpc->threshold_max = threshold_max;
+ cpc->threshold_min = threshold_min;
fd = __listen_candidate_process(cpc->type, cpc->loader_id);
if (fd == -1) {
if (!strcmp(info->exe, "null")) {
cpc = __add_slot(LAUNCHPAD_TYPE_USER + user_slot_offset,
PAD_LOADER_ID_DIRECT,
- 0, info->exe, NULL, 0, 0);
+ 0, info->exe, NULL, 0, 0,
+ info->cpu_threshold_max, info->cpu_threshold_min);
if (cpc == NULL)
return;
cpc = __add_slot(LAUNCHPAD_TYPE_USER + user_slot_offset,
PAD_LOADER_ID_STATIC,
0, info->exe, (char *)extra,
- info->detection_method, info->timeout_val);
+ info->detection_method, info->timeout_val,
+ info->cpu_threshold_max, info->cpu_threshold_min);
if (cpc == NULL)
return;
#define TAG_EXTRA_ARRAY_VAL "EXTRA_ARRAY_VAL"
#define TAG_ALTERNATIVE_LOADER "ALTERNATIVE_LOADER"
#define TAG_HW_ACC "HW_ACC"
+#define TAG_CPU_THRESHOLD_MAX "CPU_THRESHOLD_MAX"
+#define TAG_CPU_THRESHOLD_MIN "CPU_THRESHOLD_MIN"
#define VAL_ON "ON"
#define VAL_OFF "OFF"
#define VAL_METHOD_TIMEOUT "TIMEOUT"
{
loader_info_t *info = malloc(sizeof(loader_info_t));
+ if (!info)
+ return NULL;
+
info->type = 0;
info->name = NULL;
info->exe = NULL;
info->detection_method = METHOD_TIMEOUT | METHOD_VISIBILITY;
info->timeout_val = 5000;
info->extra = bundle_create();
+ info->cpu_threshold_max = DEFAULT_CPU_THRESHOLD_MAX;
+ info->cpu_threshold_min = DEFAULT_CPU_THRESHOLD_MIN;
return info;
}
continue;
}
- if (!tok1 || !tok2)
+ if (!tok1 || !tok2 || !cur_info)
continue;
if (tok1[0] == '\0' || tok2[0] == '\0' || tok1[0] == '#')
continue;
cur_info->alternative_loaders =
g_list_append(cur_info->alternative_loaders,
strdup(tok2));
+ } else if (strcasecmp(TAG_CPU_THRESHOLD_MAX, tok1) == 0) {
+ cur_info->cpu_threshold_max = atoi(tok2);
+ } else if (strcasecmp(TAG_CPU_THRESHOLD_MIN, tok1) == 0) {
+ cur_info->cpu_threshold_min = atoi(tok2);
}
}