Add flag argument on the resource_set_cpu_boosting 49/278549/3 submit/tizen/20220722.040833
authorUnsung Lee <unsung.lee@samsung.com>
Fri, 22 Jul 2022 02:26:34 +0000 (11:26 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Fri, 22 Jul 2022 03:50:43 +0000 (12:50 +0900)
Change-Id: Id0b161df3ad8910cbbf8734dc1d17a0347de35be
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
include/cpu-boosting-type.h
include/cpu-boosting.h
include/private/cpu-boosting-private.h
src/cpu-boosting.c
src/plugin/plugin.c
tests/main.c

index 79084ee3f23d39d702950b940bd4f7a0ec654b0e..25555e017fa2940761de672abbfb7302c8ec0830 100644 (file)
 extern "C" {
 #endif
 
+typedef enum resource_cpu_boosting_flag {
+       CPU_BOOSTING_RESET_ON_FORK = 0x01,
+} cpu_boosting_flag_e;
+
 typedef enum resource_cpu_boosting_level {
        CPU_BOOSTING_LEVEL_NONE = 0,
        CPU_BOOSTING_LEVEL_STRONG = 1,
index 9ec06a173377afe4f08a91a30709503a136f10f4..eec742056af748dad1ca4ab7d47a41e92bc516ae 100644 (file)
@@ -46,11 +46,14 @@ extern "C" {
  *                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).
index dc3db6135956ef6393c381a9bdb95845d6c1d05f..a4b68eb893b041482074cc267824a3c4801e0ce7 100644 (file)
@@ -40,6 +40,7 @@ typedef struct resource_cpu_boosting_input {
        int command;
        int timeout_msec;
        cpu_boosting_level_e level;
+       cpu_boosting_flag_e flag;
        int body_size;
        resource_pid_t pid;
 } cpu_boosting_input_t;
index 384197814f40e657b5a8ca3e09aa795dd9793364..0b49db6bc78b64804cab823c593de2c74f1b15c9 100644 (file)
@@ -51,10 +51,10 @@ static int open_cpu_boosting_plugin(void)
 }
 
 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)
@@ -66,7 +66,7 @@ API int resource_set_cpu_boosting (resource_pid_t pid,
                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
index 1cb48b9909c7fa058597b34fd70ff5a5db3687ef..a7793c81b61f8d117f1cc454d9ad80c4b6ee2cb5 100644 (file)
@@ -149,7 +149,7 @@ static int resource_cpu_boosting_send_command (cpu_boosting_input_t input, int s
 }
 
 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;
@@ -167,6 +167,7 @@ API int resource_set_cpu_boosting (resource_pid_t pid,
        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);
@@ -235,7 +236,6 @@ retry_header:
                        if (errno == EAGAIN && retry == false) {
                                retry = true;
                                sleep(1);
-                               _I("[CPU-BOOSTING-PLUGIN] retry");
                                goto retry_header;
                        }
 
@@ -267,7 +267,6 @@ retry_body:
                                if (errno == EAGAIN && retry == false) {
                                        retry = true;
                                        sleep(1);
-                                       _I("[CPU-BOOSTING-PLUGIN] retry");
                                        goto retry_body;
                                }
 
index f719060f582f1d5b8614d8352785fe2577baf30b..a50e7a7ec0dc02a69786d2ca3b8b56e71985bea4 100644 (file)
@@ -54,11 +54,11 @@ static void *thread_worker(void *arg)
        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);
        }
@@ -95,21 +95,20 @@ static void test_get_cpu_boosting(resource_pid_t pid, cpu_boosting_level_info_t
        }
 }
 
-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;
 
@@ -117,7 +116,7 @@ static void one_process_one_thread_test(void)
        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)
@@ -133,7 +132,7 @@ 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 */
@@ -145,7 +144,7 @@ static void multi_process_one_thread_test(int pid_count)
                }
        }
 
-       one_process_one_thread_test();
+       one_process_one_thread_test(0);
        while ((wpid = wait(&status)) > 0);
 }
 
@@ -179,7 +178,7 @@ static void one_process_multi_thread_test(int tid_count)
        }
        pid.pid = 0;
        pid.tid_count = real_tid_count;
-       test_cpu_boosting(pid);
+       test_cpu_boosting(pid, 0);
        free(pid.tid);
 }
 
@@ -207,16 +206,22 @@ static void one_process_all_thread_test(int tid_count)
                        _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 >>>>>>>>>>");