1484543d1Sopenharmony_ci/*
2484543d1Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
3484543d1Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4484543d1Sopenharmony_ci * you may not use this file except in compliance with the License.
5484543d1Sopenharmony_ci * You may obtain a copy of the License at
6484543d1Sopenharmony_ci *
7484543d1Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8484543d1Sopenharmony_ci *
9484543d1Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10484543d1Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11484543d1Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12484543d1Sopenharmony_ci * See the License for the specific language governing permissions and
13484543d1Sopenharmony_ci * limitations under the License.
14484543d1Sopenharmony_ci */
15484543d1Sopenharmony_ci
16484543d1Sopenharmony_ci#ifndef FFRT_CPU_MANAGER_INTERFACE_HPP
17484543d1Sopenharmony_ci#define FFRT_CPU_MANAGER_INTERFACE_HPP
18484543d1Sopenharmony_ci
19484543d1Sopenharmony_ci#include "eu/worker_thread.h"
20484543d1Sopenharmony_ci#include "qos.h"
21484543d1Sopenharmony_ci#include "sync/poller.h"
22484543d1Sopenharmony_ci#include "tm/cpu_task.h"
23484543d1Sopenharmony_ci
24484543d1Sopenharmony_cinamespace ffrt {
25484543d1Sopenharmony_cienum class WorkerAction {
26484543d1Sopenharmony_ci    RETRY = 0,
27484543d1Sopenharmony_ci    RETIRE,
28484543d1Sopenharmony_ci    MAX,
29484543d1Sopenharmony_ci};
30484543d1Sopenharmony_ci
31484543d1Sopenharmony_cienum class TaskNotifyType {
32484543d1Sopenharmony_ci    TASK_PICKED = 0,
33484543d1Sopenharmony_ci    TASK_ADDED,
34484543d1Sopenharmony_ci    TASK_LOCAL,
35484543d1Sopenharmony_ci};
36484543d1Sopenharmony_ci
37484543d1Sopenharmony_cienum class SleepType {
38484543d1Sopenharmony_ci    SLEEP_UNTIL_WAKEUP = 0,
39484543d1Sopenharmony_ci    SLEEP_UNTIL_INTERRUPT,
40484543d1Sopenharmony_ci    SLEEP_BREAK,
41484543d1Sopenharmony_ci};
42484543d1Sopenharmony_ci
43484543d1Sopenharmony_cistruct CpuWorkerOps {
44484543d1Sopenharmony_ci    std::function<void (WorkerThread*)> WorkerLooper;
45484543d1Sopenharmony_ci    std::function<CPUEUTask* (WorkerThread*)> PickUpTask;
46484543d1Sopenharmony_ci    std::function<void (const WorkerThread*)> NotifyTaskPicked;
47484543d1Sopenharmony_ci    std::function<WorkerAction (const WorkerThread*)> WaitForNewAction;
48484543d1Sopenharmony_ci    std::function<void (WorkerThread*)> WorkerRetired;
49484543d1Sopenharmony_ci    std::function<void (WorkerThread*)> WorkerPrepare;
50484543d1Sopenharmony_ci    std::function<PollerRet (const WorkerThread*, int timeout)> TryPoll;
51484543d1Sopenharmony_ci    std::function<unsigned int (WorkerThread*)> StealTaskBatch;
52484543d1Sopenharmony_ci    std::function<CPUEUTask* (WorkerThread*)> PickUpTaskBatch;
53484543d1Sopenharmony_ci#ifdef FFRT_WORKERS_DYNAMIC_SCALING
54484543d1Sopenharmony_ci    std::function<bool (WorkerThread*)> IsExceedRunningThreshold;
55484543d1Sopenharmony_ci    std::function<bool (void)> IsBlockAwareInit;
56484543d1Sopenharmony_ci#endif
57484543d1Sopenharmony_ci};
58484543d1Sopenharmony_ci
59484543d1Sopenharmony_cistruct CpuMonitorOps {
60484543d1Sopenharmony_ci    std::function<bool (const QoS& qos)> IncWorker;
61484543d1Sopenharmony_ci    std::function<void (const QoS& qos)> WakeupWorkers;
62484543d1Sopenharmony_ci    std::function<int (const QoS& qos)> GetTaskCount;
63484543d1Sopenharmony_ci    std::function<int (const QoS& qos)> GetWorkerCount;
64484543d1Sopenharmony_ci    std::function<void (const QoS& qos, void*, TaskNotifyType)> HandleTaskNotity;
65484543d1Sopenharmony_ci};
66484543d1Sopenharmony_ci
67484543d1Sopenharmony_ciclass CPUMonitor;
68484543d1Sopenharmony_ciclass CPUManagerStrategy {
69484543d1Sopenharmony_cipublic:
70484543d1Sopenharmony_ci    static WorkerThread* CreateCPUWorker(const QoS& qos, void* manager);
71484543d1Sopenharmony_ci    static CPUMonitor* CreateCPUMonitor(void* manager);
72484543d1Sopenharmony_ci};
73484543d1Sopenharmony_ci}
74484543d1Sopenharmony_ci#endif
75