* @param[in] flags The cpu boosting flag bits
* 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.
+ * If #CPU_BOOSTING_FORCE_RESET_ON_CLEAR is set,
+ * reset CPU boosting forcely on resource_clear_cpu_boosting() regardless of duplicate CPU boosting sets.
* @param[in] timeout_msec The timeout in milliseconds, -1 to apply boosting permanently
*
* @return 0 on success, otherwise a negative error value.
static inline bool resource_cpu_boosting_level_input_is_valid(cpu_boosting_level_e level)
{
- if (level < CPU_BOOSTING_LEVEL_STRONG || level > CPU_BOOSTING_LEVEL_WEAK) {
- _E("[CPU-BOOSTING-PLUGIN] cpu boosting level should be located between %d and %d, but current level = %d", CPU_BOOSTING_LEVEL_STRONG, CPU_BOOSTING_LEVEL_WEAK, level);
+ switch (level) {
+ case CPU_BOOSTING_LEVEL_NONE:
+ case CPU_BOOSTING_LEVEL_STRONG:
+ case CPU_BOOSTING_LEVEL_MEDIUM:
+ case CPU_BOOSTING_LEVEL_WEAK:
+ return true;
+ default:
+ _E("[CPU-BOOSTING-PLUGIN] CPU boosting level (%d) is not valid", level);
return false;
}
-
- return true;
}
static int resource_cpu_boosting_send_command (cpu_boosting_input_t input, int sock)
while ((wpid = wait(&status)) > 0);
}
+static int test_multi_process_one_thread_force_reset(int pid_count, cpu_boosting_flag_e flags)
+{
+ int ret;
+ int status;
+ pid_t pid;
+ pid_t wpid;
+ resource_pid_t resource_pid = {0,};
+ cpu_boosting_level_info_t level = {0,};
+
+ if (pid_count < 1)
+ return -EINVAL;
+
+ resource_pid.pid = getpid();
+
+ /* Parent process sets CPU boosting level as CPU_BOOSTING_LEVEL_STRONG */
+ test_set_cpu_boosting(resource_pid, CPU_BOOSTING_LEVEL_STRONG, 0, -1);
+
+ for (int i = 1; i < pid_count; i++) {
+ pid = fork();
+
+ if (pid == 0) {
+ /**
+ * Child sets CPU boosting level of the parent process as CPU_BOOSTING_LEVEL_STRONG.
+ * After that, child clears CPU boosting level of the parent process.
+ * In this case, the boosting level of the parent process may not be cleared.
+ */
+ test_set_cpu_boosting(resource_pid, CPU_BOOSTING_LEVEL_STRONG, 0, -1);
+ exit(0);
+ }
+
+ if (pid > 0)
+ continue;
+
+ _W("Cannot make a new process using fork()");
+ break;
+ }
+
+ /* Parent process waits until all child processes are ended. */
+ while (1) {
+ wpid = wait(&status);
+ if (wpid < 0)
+ break;
+ }
+
+ /**
+ * Parent process forcely resets CPU boosting level as CPU_BOOSTING_LEVEL_NONE,
+ * when CPU_BOOSTING_FORCE_RESET_ON_CLEAR is set.
+ */
+ test_set_cpu_boosting(resource_pid, CPU_BOOSTING_LEVEL_NONE, flags, -1);
+ test_clear_cpu_boosting(resource_pid);
+ ret = resource_get_cpu_boosting_level(resource_pid, &level);
+ if (ret < 0) {
+ _E("Failed to get cpu boosting level: ret (%d)", ret);
+ return ret;
+ }
+
+ for(int i = 0; i < level.tid_count; i++) {
+ if (level.tid_level[i] != CPU_BOOSTING_LEVEL_NONE)
+ _W("The pid (%d) level (%s) is not CPU_BOOSTING_LEVEL_NONE",
+ resource_pid.pid,
+ level.tid_level[i] == CPU_BOOSTING_LEVEL_STRONG ? "CPU_BOOSTING_LEVEL_STRONG" :
+ level.tid_level[i] == CPU_BOOSTING_LEVEL_MEDIUM ? "CPU_BOOSTING_LEVEL_MEDIUM" :
+ level.tid_level[i] == CPU_BOOSTING_LEVEL_WEAK ? "CPU_BOOSTING_LEVEL_WEAK" : "Unknown");
+ }
+
+ if (level.tid_level) {
+ free(level.tid_level);
+ level.tid_level = NULL;
+ }
+
+ return 0;
+}
+
static void one_process_multi_thread_test(int tid_count)
{
int ret;
int main (void)
{
+ int ret = 0;
+
_D("[CPU-BOOSTING-TEST] Start");
/* Case 1: Boosting a process with a single thread */
/* Case 2: Boosting single-threaded processes */
_D("[CPU-BOOSTING-TEST] <<<<<<<<<< Multi Processes One Thread >>>>>>>>>>");
multi_process_one_thread_test(7);
+ ret = test_multi_process_one_thread_force_reset(7, CPU_BOOSTING_FORCE_RESET_ON_CLEAR);
+ if (ret < 0) {
+ _E("Failed to test multi process with CPU_BOOSTING_FORCE_RESET_ON_CLEAR: ret (%d)", ret);
+ return 1;
+ }
/* Case 3: Boosting a multi-threaded process */
_D("[CPU-BOOSTING-TEST] <<<<<<<<<< One Process Multi Threads >>>>>>>>>>");