1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef CGROUP_SCHED_FRAMEWORK_SCHED_CONTROLLER_INCLUDE_CGROUP_ADJUSTER_H_ 17 #define CGROUP_SCHED_FRAMEWORK_SCHED_CONTROLLER_INCLUDE_CGROUP_ADJUSTER_H_ 18 19 #include <sys/types.h> 20 #include "sched_policy.h" 21 #include "supervisor.h" 22 23 namespace OHOS { 24 namespace ResourceSchedule { 25 enum class AdjustSource { 26 ADJS_BEGIN = 0, 27 ADJS_FG_APP_CHANGE = ADJS_BEGIN, 28 ADJS_ABILITY_STATE, 29 ADJS_EXTENSION_STATE, 30 ADJS_PROCESS_CREATE, 31 ADJS_TRANSIENT_BEGIN, 32 ADJS_TRANSIENT_END, 33 ADJS_CONTINUOUS_BEGIN, 34 ADJS_CONTINUOUS_END, 35 ADJS_FOCUSED_WINDOW, 36 ADJS_UNFOCUSED_WINDOW, 37 ADJS_WINDOW_VISIBILITY_CHANGED, 38 ADJS_REPORT_RENDER_THREAD, 39 ADJS_REPORT_MMI_SERVICE_THREAD, 40 ADJS_END 41 }; 42 43 class CgroupAdjuster { 44 public: 45 static CgroupAdjuster& GetInstance(); 46 47 void InitAdjuster(); 48 void AdjustProcessGroup(Application &app, ProcessRecord &pr, AdjustSource source); 49 void AdjustAllProcessGroup(Application &app, AdjustSource source); 50 void ApplyProcessGroup(Application &app, ProcessRecord &pr); 51 52 private: 53 CgroupAdjuster() = default; 54 ~CgroupAdjuster() = default; 55 56 CgroupAdjuster(const CgroupAdjuster&) = delete; 57 CgroupAdjuster& operator=(const CgroupAdjuster &) = delete; 58 CgroupAdjuster(CgroupAdjuster&&) = delete; 59 CgroupAdjuster& operator=(CgroupAdjuster&&) = delete; 60 61 void ComputeProcessGroup(Application &app, ProcessRecord &pr, AdjustSource source); 62 inline void AdjustSelfProcessGroup(); 63 }; 64 } // namespace ResourceSchedule 65 } // namespace OHOS 66 #endif // CGROUP_SCHED_FRAMEWORK_SCHED_CONTROLLER_INCLUDE_CGROUP_ADJUSTER_H_ 67