return;
}
- if (output.level.tid_level && output.level.tid_count > 0) {
+ if (output.success) {
/* Send a header first */
byte = send(sock, (const void *)&output, sizeof(output), 0);
if (byte != sizeof(output)) {
return;
}
- if (output.level.tid_level)
- free(output.level.tid_level);
}
else {
/* Send a header */
return;
}
}
+
+ if (output.level.tid_level)
+ free(output.level.tid_level);
}
static int cpu_boosting_enqueue_by_socket(int sock, struct cpu_boosting_input **input_p)
* info is NULL when clearing boosting before timeout
* info->gsource_id != *(input->gsource_id) when setting boosting again before timeout
*/
- if (info == NULL || info->gsource_id != *(input->gsource_id)) {
+ if (info == NULL || info->gsource_id != *(input->gsource_id))
continue;
- }
- ret = sched_setattr(tid_list[i], &info->origin_attr, 0);
g_hash_table_remove(tid_table, &tid_list[i]);
-
+ ret = sched_setattr(tid_list[i], &cpu_boosting_attr[CPU_BOOSTING_LEVEL_NONE], 0);
if (ret != RESOURCED_ERROR_NONE)
_E("[CPU-BOOSTING] Failed to clear boost cpu of (tid = %d)", tid_list[i]);
}
return G_SOURCE_REMOVE;
}
-static struct cpu_boosting_info *cpu_boosting_find_and_insert_attr(pid_t tid, cpu_boosting_level_e level)
+static void cpu_boosting_find_and_insert_attr(pid_t tid, cpu_boosting_level_e level, guint id)
{
- int ret;
-
struct cpu_boosting_info *info = g_hash_table_lookup(tid_table, &tid);
if (info == NULL) {
info = (struct cpu_boosting_info *)calloc(1, sizeof (struct cpu_boosting_info));
if (info == NULL) {
_E("[CPU-BOOSTING] Failed to allocate memory");
- return NULL;
+ return;
}
- ret = sched_getattr(tid, &info->origin_attr, 0);
- if (ret != RESOURCED_ERROR_NONE) {
- free(info);
- return NULL;
- }
info->tid = tid;
g_hash_table_insert(tid_table, &info->tid, info);
}
info->level = level;
- info->gsource_id = 0;
- return info;
-}
-
-static void cpu_boosting_set_gsource_id(pid_t tid, guint id)
-{
- struct cpu_boosting_info *info = g_hash_table_lookup(tid_table, &tid);
- if (info == NULL) {
- _E("[CPU-BOOSTING] cpu boosting info cannot be NULL");
- return;
- }
-
info->gsource_id = id;
}
int fail_cnt = 0;
int success_cnt = 0;
struct sched_attr attr;
- struct cpu_boosting_info *info;
int tid_count = input->client_input.pid.tid_count;
int *tid_list = input->client_input.pid.tid;
int timeout_msec = input->client_input.timeout_msec;
for (int i = 0; i < tid_count; i++) {
if (tid_list[i] > 0) {
- if ((info = cpu_boosting_find_and_insert_attr(tid_list[i], cpu_boosting_level)) == NULL) {
- fail_cnt++;
- continue;
- }
-
if (sched_setattr(tid_list[i], &attr, 0) < 0) {
- g_hash_table_remove(tid_table, &tid_list[i]);
-
_E("[CPU-BOOSTING] Failed to boost cpu of (tid = %d) with (level = %d)",
tid_list[i], cpu_boosting_level);
fail_cnt++;
if (fail_cnt > 0)
_E("[CPU-BOOSTING] Boosting success ratio = %d/%d", success_cnt, fail_cnt + success_cnt);
- /*
- * If timeout value is larger than 0 and at least one boosting succeed,
- * then set the timer to restore
- */
- if (timeout_msec > 0 && success_cnt > 0) {
- GSource *source;
- input->gsource_id = g_new(guint, 1);
-
- source = g_timeout_source_new(timeout_msec);
- g_source_set_callback(source, cpu_boosting_timeout, input, NULL);
- *(input->gsource_id) = g_source_attach(source, cpu_boosting_context);
- g_source_unref(source);
+ if (success_cnt > 0) {
+ guint id;
+ /*
+ * If timeout value is larger than 0 and at least one boosting succeed,
+ * then set the timer to restore
+ */
+ if (timeout_msec > 0) {
+ GSource *source;
+ input->gsource_id = g_new(guint, 1);
+
+ source = g_timeout_source_new(timeout_msec);
+ g_source_set_callback(source, cpu_boosting_timeout, input, NULL);
+ *(input->gsource_id) = g_source_attach(source, cpu_boosting_context);
+ g_source_unref(source);
+
+ id = *(input->gsource_id);
+ }
+ else
+ id = 0; /* No timer source */
for (int i = 0; i < tid_count; i++) {
if (tid_list[i] > 0)
- cpu_boosting_set_gsource_id(tid_list[i], *(input->gsource_id));
+ cpu_boosting_find_and_insert_attr(tid_list[i], cpu_boosting_level, id);
}
}
- else
- cpu_boosting_destroy_request(input);
}
static void cpu_boosting_clear(struct cpu_boosting_input *input)
for (int i = 0; i < tid_count; i++) {
if (tid_list[i] > 0) {
- struct cpu_boosting_info *info = g_hash_table_lookup(tid_table, &tid_list[i]);
- if (info == NULL) {
- struct sched_attr attr;
- if (sched_getattr(tid_list[i], &attr, 0) < 0) {
- _E("[CPU-BOOSTING] Failed to get boost cpu of (tid = %d)", tid_list[i]);
- fail_cnt++;
- continue;
- }
+ g_hash_table_remove(tid_table, &tid_list[i]);
- cpu_boosting_level_e level = cpu_boosting_level_search(attr);
- if (level != CPU_BOOSTING_LEVEL_NONE) {
- ret = sched_setattr(tid_list[i],
- &cpu_boosting_attr[CPU_BOOSTING_LEVEL_NONE], 0);
- if (ret != RESOURCED_ERROR_NONE) {
- _E("[CPU-BOOSTING] Failed to clear boost cpu of (tid = %d)", tid_list[i]);
- fail_cnt++;
- continue;
- }
- }
- else {
- _W("[CPU-BOOSTING] Try to clear non-boosted process (policy = %d, priority = %d, nice = %d", attr.sched_policy, attr.sched_priority, attr.sched_nice);
- continue;
- }
- }
- else {
- ret = sched_setattr(tid_list[i], &info->origin_attr, 0);
- g_hash_table_remove(tid_table, &tid_list[i]);
- if (ret != RESOURCED_ERROR_NONE) {
- _E("[CPU-BOOSTING] Failed to clear boost cpu of (tid = %d)", tid_list[i]);
- fail_cnt++;
- continue;
- }
+ ret = sched_setattr(tid_list[i],
+ &cpu_boosting_attr[CPU_BOOSTING_LEVEL_NONE], 0);
+ if (ret != RESOURCED_ERROR_NONE) {
+ _E("[CPU-BOOSTING] Failed to clear boost cpu of (tid = %d)", tid_list[i]);
+ fail_cnt++;
+ continue;
}
success_cnt++;
}
}
output.level.tid_count = success_cnt;
- if (success_cnt == 0)
- free(output.level.tid_level);
output_update:
if (fail_cnt > 0) {
_E("[CPU-BOOSTING] Get boosting success ratio = %d/%d", success_cnt, fail_cnt + success_cnt);
output.success = false;
}
- else {
+ else
output.success = true;
- }
cpu_boosting_send_reply(input->sock, output);
cpu_boosting_destroy_request(input);