From: Unsung Lee Date: Wed, 4 Jun 2025 03:00:08 +0000 (+0900) Subject: cpu-boosting: Reset CPU boosting with a flag when set instead of clear X-Git-Tag: accepted/tizen/unified/20250611.024018^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Ftizen;p=platform%2Fcore%2Fsystem%2Fresourced.git cpu-boosting: Reset CPU boosting with a flag when set instead of clear Reset CPU boosting if CPU boosting set comes with CPU_BOOSTING_FORCE_RESET_ON_SET flag. Previously reset is done with this flag by CPU boosting clear instead of set. Change-Id: Ic5c4b33250c06ba5110ba5017b76fc0d3ebf248b Signed-off-by: Unsung Lee --- diff --git a/src/resource-optimizer/cpu/cpu-boosting.c b/src/resource-optimizer/cpu/cpu-boosting.c index 99ac94e6..f2e69e96 100644 --- a/src/resource-optimizer/cpu/cpu-boosting.c +++ b/src/resource-optimizer/cpu/cpu-boosting.c @@ -989,35 +989,18 @@ static void cpu_boosting_find_and_insert_info(pid_t tid, return; } - find_cpu_boosting_info_in_tables(&cpu_boosting_info, &tid); - - switch (cpu_boosting_level) { - case CPU_BOOSTING_LEVEL_NONE: - if (cpu_boosting_info == NULL) - return; - - if ((cpu_boosting_flags & CPU_BOOSTING_FORCE_RESET_ON_CLEAR) == 0) - return; - - /** - * Set only CPU_BOOSTING_FORCE_RESET_ON_CLEAR flag - * when CPU boosting level is CPU_BOOSTING_LEVEL_NONE. - * This is because, except for the flag, no other information is correct. - */ - cpu_boosting_info_set_flag = CPU_BOOSTING_INFO_SET_CPU_BOOSTING_FLAGS; - set_cpu_boosting_info(cpu_boosting_info_set_flag, cpu_boosting_info, - 0, 0, cpu_boosting_info->cpu_boosting_flags | CPU_BOOSTING_FORCE_RESET_ON_CLEAR, - NULL, CPU_BOOSTING_LEVEL_NONE); - return; - case CPU_BOOSTING_LEVEL_STRONG: - case CPU_BOOSTING_LEVEL_MEDIUM: - case CPU_BOOSTING_LEVEL_WEAK: - break; - default: - _E("Invalid CPU boosting level"); + /** + * If CPU_BOOSTING_FORCE_RESET_ON_SET flag is set, + * remove previous cpu boosting info of the thread regardless of CPU boosting level. + * This is because, this flag ignores previous cpu boosting set instructions. + */ + if (cpu_boosting_flags & CPU_BOOSTING_FORCE_RESET_ON_SET) { + remove_cpu_boosting_info_in_tables(&tid); return; } + find_cpu_boosting_info_in_tables(&cpu_boosting_info, &tid); + cpu_boosting_info_set_flag = CPU_BOOSTING_INFO_SET_TID | CPU_BOOSTING_INFO_SET_REF_CNT | CPU_BOOSTING_INFO_SET_CPU_BOOSTING_FLAGS | CPU_BOOSTING_INFO_SET_GSOURCE_ID | @@ -1077,6 +1060,9 @@ static int update_cpu_sched_of_thread_list(int tid_count, int *tid_list, int success_cnt = 0; uint32_t sched_attr_set_flag; + if (cpu_boosting_flags & CPU_BOOSTING_FORCE_RESET_ON_SET) + attr = cpu_boosting_attr[CPU_BOOSTING_LEVEL_NONE]; + if (cpu_boosting_flags & CPU_BOOSTING_RESET_ON_FORK) { _I("[CPU-BOOSTING] Turn on SCHED_RESET_ON_FORK flag"); @@ -1118,7 +1104,6 @@ cpu_boosting_set(struct syscommon_resourced_cpu_boosting_input *input) int timeout_msec = input->client_input.timeout_msec; cpu_boosting_level_e cpu_boosting_level = input->client_input.level; cpu_boosting_flag_e cpu_boosting_flags = input->client_input.flags; - bool update_cpu_boosting_info = false; if (!is_valid_cpu_boosting_level(cpu_boosting_level)) { _E("[CPU-BOOSTING] Unknown boosting level"); @@ -1134,16 +1119,12 @@ cpu_boosting_set(struct syscommon_resourced_cpu_boosting_input *input) */ switch (cpu_boosting_level) { case CPU_BOOSTING_LEVEL_NONE: - update_cpu_boosting_info = true; - break; case CPU_BOOSTING_LEVEL_STRONG: case CPU_BOOSTING_LEVEL_MEDIUM: case CPU_BOOSTING_LEVEL_WEAK: update_cpu_sched_of_thread_list(tid_count, tid_list, cpu_boosting_flags, cpu_boosting_level, &fail_cnt, &success_cnt); - if (success_cnt > 0) - update_cpu_boosting_info = true; break; default: _E("Invalid CPU boosting level"); @@ -1174,9 +1155,7 @@ cpu_boosting_set(struct syscommon_resourced_cpu_boosting_input *input) id = *(input->gsource_id); } - } - if (update_cpu_boosting_info) { for (int i = 0; i < tid_count; i++) { if (tid_list[i] <= 0) continue; @@ -1198,14 +1177,10 @@ static bool should_reset_cpu_boosting(int *tid) if (cpu_boosting_info == NULL) return false; - if (cpu_boosting_info->cpu_boosting_flags & CPU_BOOSTING_FORCE_RESET_ON_CLEAR) - return true; - /** - * TODO: check count when the CPU_BOOSTING_FORCE_RESET_ON_CLEAR is disabled. + * TODO: Check reference count. * - * Currently CPU_BOOSTING_COMMAND_CLEAR resets CPU boosting forcely - * regardless of CPU_BOOSTING_FORCE_RESET_ON_CLEAR flag. + * Currently CPU_BOOSTING_COMMAND_CLEAR resets CPU boosting forcely. * It may cause unintended early termination of CPU boosting. */ return true;