• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_REPORT_IMPORTANT_DISPLAY_THREAD,
41     ADJS_SELF_RENDER_THREAD,
42     ADJS_REPORT_WINDOW_STATE_CHANGED,
43     ADJS_REPORT_AUDIO_STATE_CHANGED,
44     ADJS_REPORT_WEBVIEW_AUDIO_STATE_CHANGED,
45     ADJS_REPORT_ENTER_NAP,
46     ADJS_REPORT_EXIT_NAP,
47     ADJS_PROCESS_STATE,
48     ADJS_REPORT_SCREEN_CAPTURE,
49     ADJS_REPORT_WEBVIEW_SCREEN_CAPTURE,
50     ADJS_REPORT_WEBVIEW_ENTER_NAP,
51     ADJS_SYSTEMLOAD_LEVEL_CHANGED,
52     ADJS_APP_PRELOAD,
53     ADJS_CALCULATE_AGAIN,
54     ADJS_END
55 };
56 
57 class CgroupAdjuster {
58 public:
59     static CgroupAdjuster& GetInstance();
60 
61     void InitAdjuster();
62     void AdjustForkProcessGroup(Application &app, ProcessRecord &pr);
63     void AdjustProcessGroup(Application &app, ProcessRecord &pr, AdjustSource source);
64     void AdjustAllProcessGroup(Application &app, AdjustSource source);
65     void ApplyProcessGroup(Application &app, ProcessRecord &pr);
66 
67 private:
68     CgroupAdjuster() = default;
69     ~CgroupAdjuster() = default;
70 
71     CgroupAdjuster(const CgroupAdjuster&) = delete;
72     CgroupAdjuster& operator=(const CgroupAdjuster &) = delete;
73     CgroupAdjuster(CgroupAdjuster&&) = delete;
74     CgroupAdjuster& operator=(CgroupAdjuster&&) = delete;
75 
76     void ComputeProcessGroup(Application &app, ProcessRecord &pr, AdjustSource source);
77     inline void AdjustSelfProcessGroup();
78 };
79 } // namespace ResourceSchedule
80 } // namespace OHOS
81 #endif // CGROUP_SCHED_FRAMEWORK_SCHED_CONTROLLER_INCLUDE_CGROUP_ADJUSTER_H_
82