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 45 #ifdef FFRT_IO_TASK_SCHEDULER NotifyLocalTaskAdded(const QoS & qos)46 void NotifyLocalTaskAdded(const QoS& qos) 47 { 48 { 49 wManager[static_cast<size_t>(DevType::CPU)]->NotifyLocalTaskAdded(qos); 50 } 51 } 52 #endif 53 GetSleepCtl(int qos)54 std::mutex* GetSleepCtl(int qos) 55 { 56 return wManager[static_cast<size_t>(DevType::CPU)]->GetSleepCtl(qos); 57 } 58 GetGroupCtl()59 WorkerGroupCtl* GetGroupCtl() 60 { 61 return wManager[static_cast<size_t>(DevType::CPU)]->GetGroupCtl(); 62 } 63 GetCPUMonitor()64 CPUMonitor* GetCPUMonitor() 65 { 66 return wManager[static_cast<size_t>(DevType::CPU)]->GetCPUMonitor(); 67 } 68 69 protected: 70 ExecuteUnit(); 71 72 std::array<std::unique_ptr<WorkerManager>, static_cast<size_t>(DevType::DEVMAX)> wManager; 73 }; 74 } // namespace ffrt 75 #endif 76