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 FFRT_EXECUTE_UNIT_HPP 17 #define FFRT_EXECUTE_UNIT_HPP 18 19 20 #include "sched/workgroup_internal.h" 21 #include "eu/worker_manager.h" 22 #include "eu/thread_group.h" 23 #include "eu/cpu_monitor.h" 24 #include "internal_inc/osal.h" 25 #include "util/cb_func.h" 26 27 namespace ffrt { 28 class ExecuteUnit { 29 public: 30 static ExecuteUnit& Instance(); 31 32 static void RegistInsCb(SingleInsCB<ExecuteUnit>::Instance &&cb); 33 34 ThreadGroup* BindTG(const DevType dev, QoS& qos); 35 void UnbindTG(const DevType dev, QoS& qos); 36 void BindWG(const DevType dev, QoS& qos); 37 NotifyTaskAdded(const QoS & qos)38 void NotifyTaskAdded(const QoS& qos) 39 { 40 if (likely(wManager[static_cast<size_t>(DevType::CPU)])) { 41 wManager[static_cast<size_t>(DevType::CPU)]->NotifyTaskAdded(qos); 42 } 43 } 44 NotifyWorkers(const QoS & qos,int number)45 void NotifyWorkers(const QoS& qos, int number) 46 { 47 if (likely(wManager[static_cast<size_t>(DevType::CPU)])) { 48 wManager[static_cast<size_t>(DevType::CPU)]->NotifyWorkers(qos, number); 49 } 50 } 51 NotifyLocalTaskAdded(const QoS & qos)52 void NotifyLocalTaskAdded(const QoS& qos) 53 { 54 { 55 wManager[static_cast<size_t>(DevType::CPU)]->NotifyLocalTaskAdded(qos); 56 } 57 } 58 GetSleepCtl(int qos)59 std::mutex* GetSleepCtl(int qos) 60 { 61 return wManager[static_cast<size_t>(DevType::CPU)]->GetSleepCtl(qos); 62 } 63 GetGroupCtl()64 WorkerGroupCtl* GetGroupCtl() 65 { 66 return wManager[static_cast<size_t>(DevType::CPU)]->GetGroupCtl(); 67 } 68 GetCPUMonitor()69 CPUMonitor* GetCPUMonitor() 70 { 71 return wManager[static_cast<size_t>(DevType::CPU)]->GetCPUMonitor(); 72 } 73 74 virtual std::unique_ptr<WorkerManager> InitManager() = 0; 75 76 void CreateWorkerManager(); 77 78 protected: 79 ExecuteUnit(); 80 virtual ~ExecuteUnit() = default; 81 82 std::array<std::unique_ptr<WorkerManager>, static_cast<size_t>(DevType::DEVMAX)> wManager; 83 }; 84 85 } // namespace ffrt 86 #endif 87