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 "sched/qos.h" 20 #include "types.h" 21 22 namespace ffrt { 23 constexpr int DEFAULT_MINCONCURRENCY = 4; 24 constexpr int INTERACTIVE_MAXCONCURRENCY = USE_COROUTINE ? 4 : 40000; 25 constexpr int DEFAULT_MAXCONCURRENCY = USE_COROUTINE ? 8 : 80000; 26 constexpr int DEFAULT_HARDLIMIT = 16; 27 28 class GlobalConfig { 29 public: 30 GlobalConfig(const GlobalConfig&) = delete; 31 32 GlobalConfig& operator=(const GlobalConfig&) = delete; 33 ~GlobalConfig()34 ~GlobalConfig() {} 35 Instance()36 static inline GlobalConfig& Instance() 37 { 38 static GlobalConfig cfg; 39 return cfg; 40 } 41 setCpuWorkerNum(const QoS & qos,int num)42 void setCpuWorkerNum(const QoS& qos, int num) 43 { 44 if ((num <= 0) || (num > DEFAULT_MAXCONCURRENCY)) { 45 num = DEFAULT_MAXCONCURRENCY; 46 } 47 this->cpu_worker_num[qos()] = static_cast<size_t>(num); 48 } 49 getCpuWorkerNum(const QoS & qos)50 size_t getCpuWorkerNum(const QoS& qos) 51 { 52 return this->cpu_worker_num[qos()]; 53 } 54 55 private: GlobalConfig()56 GlobalConfig() 57 { 58 for (auto qos = QoS::Min(); qos < QoS::Max(); ++qos) { 59 if (qos == static_cast<int>(qos_user_interactive)) { 60 this->cpu_worker_num[qos] = INTERACTIVE_MAXCONCURRENCY; 61 } else { 62 this->cpu_worker_num[qos] = DEFAULT_MAXCONCURRENCY; 63 } 64 } 65 } 66 67 size_t cpu_worker_num[QoS::Max()]; 68 }; 69 } 70 71 #endif /* GLOBAL_CONFIG_H */ 72