• 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 #include "qos_manager.h"
17 #include <unistd.h>
18 #include "concurrent_task_log.h"
19 
20 static struct QosPolicyDatas g_defaultQosPolicy = {
21     .policyType = static_cast<unsigned int>(QosPolicyType::QOS_POLICY_DEFAULT),
22     .policyFlag = QOS_FLAG_ALL,
23     .policys = {
24         {0, 0, 0, 1024, 0},
25         {0, 0, 0, 1024, 0},
26         {0, 0, 0, 1024, 0},
27         {0, 0, 0, 1024, 0},
28         {0, 0, 0, 1024, 0},
29         {0, 0, 0, 1024, 0},
30         {0, 0, 0, 1024, 0},
31     }
32 };
33 
34 static struct QosPolicyDatas g_foregroundQosPolicy = {
35     .policyType = static_cast<unsigned int>(QosPolicyType::QOS_POLICY_FRONT),
36     .policyFlag = QOS_FLAG_ALL,
37     .policys = {
38         {0, 0, 0, 1024, 0},
39         {10, 10, 0, 200, 0},
40         {5, 5, 0, 250, 0},
41         {0, 0, 0, 1024, 0},
42         {-5, -5, 300, 1024, 0},
43         {-10, -10, 500, 1024, 0},
44         {-10, -10, 500, 1024, 2},
45     }
46 };
47 
48 static struct QosPolicyDatas g_backgroundQosPolicy = {
49     .policyType = static_cast<unsigned int>(QosPolicyType::QOS_POLICY_BACK),
50     .policyFlag = QOS_FLAG_ALL & ~QOS_FLAG_RT,
51     .policys = {
52         {0, 0, 0, 1024, 0},
53         {15, 15, 0, 150, 0},
54         {10, 10, 0, 200, 0},
55         {5, 5, 0, 250, 0},
56         {0, 0, 0, 300, 0},
57         {-5, -5, 0, 350, 0},
58         {-5, -5, 0, 350, 3},
59     }
60 };
61 
62 static struct QosPolicyDatas g_systemServerQosPolicy = {
63     .policyType = static_cast<unsigned int>(QosPolicyType::QOS_POLICY_SYSTEM_SERVER),
64     .policyFlag = QOS_FLAG_ALL,
65     .policys = {
66         {0, 0, 0, 1024, 0},
67         {10, 10, 0, 200, 0},
68         {5, 5, 0, 250, 0},
69         {0, 0, 0, 1024, 0},
70         {-5, -5, 300, 1024, 0},
71         {-10, -10, 500, 1024, 0},
72         {-10, -10, 500, 1024, 2},
73     }
74 };
75 
76 namespace OHOS {
77 namespace ConcurrentTask {
SetQosPolicy(struct QosPolicyDatas * policyDatas)78 int QosManager::SetQosPolicy(struct QosPolicyDatas *policyDatas)
79 {
80     return QosPolicy(policyDatas);
81 }
82 
Init()83 void QosManager::Init()
84 {
85     int ret;
86 
87     ret = SetQosPolicy(&g_defaultQosPolicy);
88     if (ret) {
89         CONCUR_LOGE("%{public}d set g_defaultQosPolicy failed", getuid());
90     }
91 
92     ret = SetQosPolicy(&g_foregroundQosPolicy);
93     if (ret) {
94         CONCUR_LOGE("%{public}d set g_foregroundQosPolicy failed", getuid());
95     }
96 
97     ret = SetQosPolicy(&g_backgroundQosPolicy);
98     if (ret) {
99         CONCUR_LOGE("%{public}d set g_backgroundQosPolicy failed", getuid());
100     }
101 
102     ret = SetQosPolicy(&g_systemServerQosPolicy);
103     if (ret) {
104         CONCUR_LOGE("%{public}d set g_systemServerQosPolicy failed", getuid());
105     }
106     CONCUR_LOGI("set qos policy finish");
107 }
108 }
109 }