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_CPU_MANAGER_STRATEGY_HPP 17 #define FFRT_CPU_MANAGER_STRATEGY_HPP 18 19 #include "eu/worker_thread.h" 20 #include "qos.h" 21 #include "sync/poller.h" 22 #include "tm/cpu_task.h" 23 24 namespace ffrt { 25 enum class WorkerAction { 26 RETRY = 0, 27 RETIRE, 28 MAX, 29 }; 30 31 enum class TaskNotifyType { 32 TASK_PICKED = 0, 33 TASK_ADDED, 34 TASK_LOCAL, 35 TASK_ESCAPED, 36 }; 37 38 struct CpuWorkerOps { 39 std::function<void (WorkerThread*)> WorkerLooper; 40 std::function<CPUEUTask* (WorkerThread*)> PickUpTask; 41 std::function<void (const WorkerThread*)> NotifyTaskPicked; 42 std::function<WorkerAction (const WorkerThread*)> WaitForNewAction; 43 std::function<void (WorkerThread*)> WorkerRetired; 44 std::function<void (WorkerThread*)> WorkerPrepare; 45 std::function<PollerRet (const WorkerThread*, int timeout)> TryPoll; 46 std::function<unsigned int (WorkerThread*)> StealTaskBatch; 47 std::function<CPUEUTask* (WorkerThread*)> PickUpTaskBatch; 48 #ifdef FFRT_WORKERS_DYNAMIC_SCALING 49 std::function<bool (WorkerThread*)> IsExceedRunningThreshold; 50 std::function<bool (void)> IsBlockAwareInit; 51 #endif 52 }; 53 54 struct CpuMonitorOps { 55 std::function<bool (const QoS& qos)> IncWorker; 56 std::function<void (const QoS& qos)> WakeupWorkers; 57 std::function<int (const QoS& qos)> GetTaskCount; 58 std::function<int (const QoS& qos)> GetWorkerCount; 59 std::function<void (const QoS& qos, void*, TaskNotifyType)> HandleTaskNotity; 60 }; 61 62 class CPUMonitor; 63 class CPUManagerStrategy { 64 public: 65 static WorkerThread* CreateCPUWorker(const QoS& qos, void* manager); 66 static CPUMonitor* CreateCPUMonitor(void* manager); 67 }; 68 } 69 #endif