1 /*
2  * Copyright (c) 2023 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 GLOBAL_CONFIG_H
17 #define GLOBAL_CONFIG_H
18 
19 #include "qos.h"
20 #include "types.h"
21 
22 namespace ffrt {
23 constexpr unsigned int DEFAULT_GLOBAL_HARDLIMIT = 96;
24 constexpr unsigned int DEFAULT_PARAMS_VALUE = 0Xffffffff;
25 
26 constexpr unsigned int DEFAULT_MAXCONCURRENCY = 8;
27 constexpr unsigned int MAX_MAXCONCURRENCY = 12;
28 constexpr unsigned int DEFAULT_HARDLIMIT = 44;
29 constexpr unsigned int DEFAULT_SINGLE_NUM = 8;
30 
31 constexpr unsigned int DEFAULT_GLOBAL_RESERVE_NUM = 24;
32 constexpr unsigned int DEFAULT_LOW_RESERVE_NUM = 12;
33 constexpr unsigned int DEFAULT_HIGH_RESERVE_NUM = 12;
34 constexpr unsigned int GLOBAL_QOS_MAXNUM = 256;
35 
36 class QosWorkerConfig {
37 public:
38     struct FfrtQosWorkerNumCfg {
39         unsigned int hardLimit = DEFAULT_HARDLIMIT;
40         unsigned int maxConcurrency = DEFAULT_MAXCONCURRENCY;
41         unsigned int reserveNum = DEFAULT_SINGLE_NUM;
42     };
43 
QosWorkerConfig(int workerNum)44     QosWorkerConfig(int workerNum)
45     {
46         mQosWorkerCfg.resize(workerNum);
47     }
48     QosWorkerConfig(const QosWorkerConfig&) = delete;
49     QosWorkerConfig& operator=(const QosWorkerConfig&) = delete;
~QosWorkerConfig()50     ~QosWorkerConfig() {}
51 
GetGlobalMaxWorkerNum() const52     unsigned int GetGlobalMaxWorkerNum() const
53     {
54         unsigned int ret = 0;
55         ret += mLowQosReserveWorkerNum;
56         ret += mHighQosReserveWorkerNum;
57         ret += mGlobalReserveWorkerNum;
58         for (const auto &tmpStru : mQosWorkerCfg) {
59             ret += tmpStru.reserveNum;
60         }
61         return ret;
62     }
63 
64     std::vector<FfrtQosWorkerNumCfg> mQosWorkerCfg;
65     unsigned int mLowQosReserveWorkerNum = DEFAULT_LOW_RESERVE_NUM;
66     unsigned int mHighQosReserveWorkerNum = DEFAULT_HIGH_RESERVE_NUM;
67     unsigned int mGlobalReserveWorkerNum = DEFAULT_GLOBAL_RESERVE_NUM;
68 };
69 }
70 
71 #endif /* GLOBAL_CONFIG_H */
72