return true;
}
-API int resource_set_cpu_boosting (resource_pid_t pid,
- cpu_boosting_level_e level, int timeout_msec)
+static int resource_cpu_boosting_send_command (cpu_boosting_input_t input, int sock)
{
- pid_t tid;
int byte;
- int ret = 0;
- int sock;
- cpu_boosting_input_t input;
-// cpu_boosting_output_t output;
-
- if (!resource_pid_input_is_valid(pid))
- return -1;
-
- if (!resource_cpu_boosting_level_input_is_valid(level))
- return -1;
-
- if ((sock = resource_create_and_connect_sock()) < 0)
- return -1;
-
- input.command = CPU_BOOSTING_COMMAND_SET;
- input.pid = pid;
- input.level = level;
- input.timeout_msec = timeout_msec;
+ pid_t tid;
if (input.pid.pid > 0)
input.body_size = 0;
_E("[CPU-BOOSTING-PLUGIN] error is based on %s", strerror(errno));
_E("[CPU-BOOSTING-PLUGIN] client input size is %u, but sent size is %d",
(unsigned int)sizeof(input), byte);
- ret = -1;
- goto close_sock;
+ return -1;
}
if (input.body_size > 0) {
_E("[CPU-BOOSTING-PLUGIN] error is based on %s", strerror(errno));
_E("[CPU-BOOSTING-PLUGIN] client input size is %d, but sent size is %d",
input.body_size, byte);
- ret = -1;
- goto close_sock;
+ return -1;
}
}
-/* byte = recv(sock, (void *)&output, sizeof(bool), 0);
- if (byte != sizeof(bool)) {
- _E("[CPU-BOOSTING-PLUGIN] error is based on %s", strerror(errno));
- _E("[CPU-BOOSTING-PLUGIN] client output size is %u, but received size is %d",
- (unsigned int)sizeof(bool), byte);
- goto close_sock;
- }
+ return 0;
+}
+API int resource_set_cpu_boosting (resource_pid_t pid,
+ cpu_boosting_level_e level, int timeout_msec)
+{
+ int ret;
+ int sock;
+ cpu_boosting_input_t input;
- if (!output.success)
- _E("[CPU-BOOSTING-PLUGIN] fail to communicate");
- else {
- _D("[CPU-BOOSTING-PLUGIN] success to communicate");
- ret = 0;
- }*/
+ if (!resource_pid_input_is_valid(input.pid))
+ return -1;
-close_sock:
+ if (!resource_cpu_boosting_level_input_is_valid(level))
+ return -1;
+
+ if ((sock = resource_create_and_connect_sock()) < 0)
+ return -1;
+
+ input.command = CPU_BOOSTING_COMMAND_SET;
+ input.pid = pid;
+ input.level = level;
+ input.timeout_msec = timeout_msec;
+
+ ret = resource_cpu_boosting_send_command(input, sock);
close(sock);
return ret;
API int resource_clear_cpu_boosting (resource_pid_t pid)
{
- _D("[CPU-BOOSTING-PLUGIN] %s called", __func__);
+ int ret;
+ int sock;
+ cpu_boosting_input_t input;
- return 0;
+ if (!resource_pid_input_is_valid(input.pid))
+ return -1;
+
+ if ((sock = resource_create_and_connect_sock()) < 0)
+ return -1;
+
+ input.command = CPU_BOOSTING_COMMAND_CLEAR;
+ input.pid = pid;
+ input.level = CPU_BOOSTING_LEVEL_NONE;
+ input.timeout_msec = 0;
+
+ ret = resource_cpu_boosting_send_command(input, sock);
+ close(sock);
+
+ return ret;
}
API int resource_get_cpu_boosting_level (resource_pid_t pid,
cpu_boosting_level_info_t *level)
{
- _D("[CPU-BOOSTING-PLUGIN] %s called", __func__);
+ int ret;
+ int byte;
+ int sock;
+ cpu_boosting_output_t output;
+ cpu_boosting_input_t input;
- return 0;
+ if (!resource_pid_input_is_valid(pid))
+ return -1;
+
+ if ((sock = resource_create_and_connect_sock()) < 0)
+ return -1;
+
+ input.command = CPU_BOOSTING_COMMAND_GET;
+ input.pid = pid;
+
+ ret = resource_cpu_boosting_send_command(input, sock);
+ if (ret < 0)
+ goto close_sock;
+
+ byte = recv(sock, (void *)&output, sizeof(output), 0);
+ if (byte != sizeof(output)) {
+ _E("[CPU-BOOSTING-PLUGIN] error is based on %s", strerror(errno));
+ _E("[CPU-BOOSTING-PLUGIN] client output size is %u, but received size is %d",
+ (unsigned int)sizeof(output), byte);
+ ret = -1;
+ goto close_sock;
+ }
+
+ if (output.level.tid_count > 0) {
+ level->tid_level = (int *)calloc(output.level.tid_count, sizeof(int));
+ if (level->tid_level == NULL) {
+ _E("[CPU-BOOSTING-PLUGIN] Failed to allocate memory");
+ ret = -1;
+ goto close_sock;
+ }
+ else
+ level->tid_count = output.level.tid_count;
+
+ byte = recv(sock, (void *)level->tid_level, level->tid_count * sizeof(int), 0);
+ if (byte != level->tid_count * sizeof(int)) {
+ _E("[CPU-BOOSTING-PLUGIN] error is based on %s", strerror(errno));
+ _E("[CPU-BOOSTING-PLUGIN] client output size is %u, but received size is %d",
+ level->tid_count * (unsigned int)sizeof(int), byte);
+ free(level->tid_level);
+ ret = -1;
+ goto close_sock;
+ }
+ }
+
+ if (!output.success) {
+ _E("[CPU-BOOSTING-PLUGIN] Failed to get boosting");
+ ret = -1;
+ }
+ else
+ _D("[CPU-BOOSTING-PLUGIN] Success to get boosting");
+
+close_sock:
+ close(sock);
+
+ return ret;
}
API int resource_set_cpu_inheritance (pid_t source_tid, const char *dest_process, int timeout_msec)