* If pid.pid is zero and pid.tid is NULL, tid of the calling thread is used. \n
* The caller must (de)allocate the buffer in the pid.tid pointer.
* @param[in] level The cpu boosting level
+ * @param[in] flag The cpu boosting flag
+ * If CPU_BOOSTING_RESET_ON_FORK is set, child processes or threads created by fork() or pthread_create()
+ * do not inherit boosted CPU schedulder and priority from the parent.
* @param[in] timeout_msec The timeout in milliseconds, -1 to apply boosting permanently
*
* @return 0 on success, otherwise a negative error value.
*/
-int resource_set_cpu_boosting (resource_pid_t pid, cpu_boosting_level_e level, int timeout_msec);
+int resource_set_cpu_boosting (resource_pid_t pid, cpu_boosting_level_e level, cpu_boosting_flag_e flag, int timeout_msec);
/**
* @brief Clear cpu boosting for the boosted process (pid/tids).
}
API int resource_set_cpu_boosting (resource_pid_t pid,
- cpu_boosting_level_e level, int timeout_msec)
+ cpu_boosting_level_e level, cpu_boosting_flag_e flag, int timeout_msec)
{
int ret;
- int (*func)(resource_pid_t pid, cpu_boosting_level_e level, int timeout_msec) = NULL;
+ int (*func)(resource_pid_t pid, cpu_boosting_level_e level, cpu_boosting_flag_e flag, int timeout_msec) = NULL;
ret = open_cpu_boosting_plugin();
if (ret != RESOURCE_ERROR_NONE)
return RESOURCE_ERROR_NOT_SUPPORTED;
}
- ret = func(pid, level, timeout_msec);
+ ret = func(pid, level, flag, timeout_msec);
if (ret != RESOURCE_ERROR_NONE)
_E("[CPU-BOOSTING] Failed to set CPU boosting");
else
}
API int resource_set_cpu_boosting (resource_pid_t pid,
- cpu_boosting_level_e level, int timeout_msec)
+ cpu_boosting_level_e level, cpu_boosting_flag_e flag, int timeout_msec)
{
int ret;
int sock;
input.command = CPU_BOOSTING_COMMAND_SET;
input.pid = pid;
input.level = level;
+ input.flag = flag;
input.timeout_msec = timeout_msec;
ret = resource_cpu_boosting_send_command(input, sock);
if (errno == EAGAIN && retry == false) {
retry = true;
sleep(1);
- _I("[CPU-BOOSTING-PLUGIN] retry");
goto retry_header;
}
if (errno == EAGAIN && retry == false) {
retry = true;
sleep(1);
- _I("[CPU-BOOSTING-PLUGIN] retry");
goto retry_body;
}
pthread_exit(NULL);
}
-static void test_set_cpu_boosting(resource_pid_t pid, cpu_boosting_level_e level, int timeout_msec)
+static void test_set_cpu_boosting(resource_pid_t pid, cpu_boosting_level_e level, cpu_boosting_flag_e flag, int timeout_msec)
{
int ret;
- ret = resource_set_cpu_boosting(pid, level, timeout_msec);
+ ret = resource_set_cpu_boosting(pid, level, flag, timeout_msec);
if (ret) {
_E("[CPU-BOOSTING-TEST] error = %d", ret);
}
}
}
-static void test_cpu_boosting(resource_pid_t pid)
+static void test_cpu_boosting(resource_pid_t pid, cpu_boosting_flag_e flag)
{
cpu_boosting_level_info_t cur_level;
for (int level = CPU_BOOSTING_LEVEL_WEAK; level > CPU_BOOSTING_LEVEL_NONE; level--)
- test_set_cpu_boosting(pid, level, 3000);
+ test_set_cpu_boosting(pid, level, flag, 3000);
test_get_cpu_boosting(pid, &cur_level); /* Expect CPU_BOOSTING_LEVEL_STRONG */
test_clear_cpu_boosting(pid);
test_get_cpu_boosting(pid, &cur_level); /* Expect CPU_BOOSTING_LEVEL_NONE */
- sleep(3);
}
-static void one_process_one_thread_test(void)
+static void one_process_one_thread_test(cpu_boosting_flag_e flag)
{
resource_pid_t pid;
pid.tid = NULL;
pid.tid_count = 0;
- test_cpu_boosting(pid);
+ test_cpu_boosting(pid, flag);
}
static void multi_process_one_thread_test(int pid_count)
/* child */
if (pid == 0) {
- one_process_one_thread_test();
+ one_process_one_thread_test(0);
exit(0);
}
/* parent */
}
}
- one_process_one_thread_test();
+ one_process_one_thread_test(0);
while ((wpid = wait(&status)) > 0);
}
}
pid.pid = 0;
pid.tid_count = real_tid_count;
- test_cpu_boosting(pid);
+ test_cpu_boosting(pid, 0);
free(pid.tid);
}
_E("[CPU-BOOSTING-TEST] Failed to create a new thread");
}
}
- test_cpu_boosting(pid);
+ test_cpu_boosting(pid, 0);
}
int main (void)
{
_D("[CPU-BOOSTING-TEST] Start");
+ /* Case 1: Boosting a process with a single thread */
+ _D("[CPU-BOOSTING-TEST] <<<<<<<<<< One Process One Thread With CPU_BOOSTING_RESET_ON_FORK >>>>>>>>>>");
+ one_process_one_thread_test(CPU_BOOSTING_RESET_ON_FORK);
+
/* Case 1: Boosting a process with a single thread */
_D("[CPU-BOOSTING-TEST] <<<<<<<<<< One Process One Thread >>>>>>>>>>");
- one_process_one_thread_test();
+ one_process_one_thread_test(0);
+
+ return 0;
/* Case 2: Boosting single-threaded processes */
_D("[CPU-BOOSTING-TEST] <<<<<<<<<< Multi Processes One Thread >>>>>>>>>>");