cpu-boosting: Reset CPU boosting with a flag when set instead of clear 51/325151/3 accepted/tizen_unified accepted/tizen_unified_x tizen accepted/tizen/unified/20250611.024018 accepted/tizen/unified/x/20250611.044707
authorUnsung Lee <unsung.lee@samsung.com>
Wed, 4 Jun 2025 03:00:08 +0000 (12:00 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Thu, 5 Jun 2025 07:51:42 +0000 (16:51 +0900)
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 <unsung.lee@samsung.com>
src/resource-optimizer/cpu/cpu-boosting.c

index 99ac94e6174cd89870df49d0a35625b39d14a5b2..f2e69e9642685728eff527528898008dfa409a7f 100644 (file)
@@ -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;