From: Unsung Lee Date: Fri, 22 Jul 2022 02:26:34 +0000 (+0900) Subject: Add flag argument on the resource_set_cpu_boosting X-Git-Tag: submit/tizen/20220722.040833^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d4f61361eb2d651f8470181adc2ea0b35e3c5a09;p=platform%2Fcore%2Fapi%2Fresource.git Add flag argument on the resource_set_cpu_boosting Change-Id: Id0b161df3ad8910cbbf8734dc1d17a0347de35be Signed-off-by: Unsung Lee --- diff --git a/include/cpu-boosting-type.h b/include/cpu-boosting-type.h index 79084ee..25555e0 100644 --- a/include/cpu-boosting-type.h +++ b/include/cpu-boosting-type.h @@ -29,6 +29,10 @@ 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, diff --git a/include/cpu-boosting.h b/include/cpu-boosting.h index 9ec06a1..eec7420 100644 --- a/include/cpu-boosting.h +++ b/include/cpu-boosting.h @@ -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). diff --git a/include/private/cpu-boosting-private.h b/include/private/cpu-boosting-private.h index dc3db61..a4b68eb 100644 --- a/include/private/cpu-boosting-private.h +++ b/include/private/cpu-boosting-private.h @@ -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; diff --git a/src/cpu-boosting.c b/src/cpu-boosting.c index 3841978..0b49db6 100644 --- a/src/cpu-boosting.c +++ b/src/cpu-boosting.c @@ -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 diff --git a/src/plugin/plugin.c b/src/plugin/plugin.c index 1cb48b9..a7793c8 100644 --- a/src/plugin/plugin.c +++ b/src/plugin/plugin.c @@ -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; } diff --git a/tests/main.c b/tests/main.c index f719060..a50e7a7 100644 --- a/tests/main.c +++ b/tests/main.c @@ -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 >>>>>>>>>>");