• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SEXECUTE_UNIT_HPP
17 #define FFRT_SEXECUTE_UNIT_HPP
18 
19 #include "execute_unit.h"
20 #include "util/ffrt_facade.h"
21 
22 namespace ffrt {
23 class SExecuteUnit : public ExecuteUnit {
24 public:
Instance()25     static SExecuteUnit& Instance()
26     {
27         static SExecuteUnit ins;
28         return ins;
29     }
30 
WorkerInit()31     void WorkerInit() override {}
32 
WorkerPrepare(CPUWorker * thread)33     void WorkerPrepare(CPUWorker* thread) override
34     {
35         WorkerJoinTg(thread->GetQos(), thread->Id());
36     }
37 
38     WorkerAction WorkerIdleAction(CPUWorker* thread) override;
39 
40     void WakeupWorkers(const QoS& qos) override;
41 
IntoSleep(const QoS & qos)42     void IntoSleep(const QoS& qos) override
43     {
44         CPUWorkerGroup& group = workerGroup[qos];
45         std::lock_guard lg(group.lock);
46         group.sleepingNum++;
47         group.executingNum--;
48     }
49 
50     /* strategy options for handling task notify events */
51     static void HandleTaskNotifyDefault(SExecuteUnit* manager, const QoS& qos, TaskNotifyType notifyType);
52     static void HandleTaskNotifyConservative(SExecuteUnit* manager, const QoS& qos, TaskNotifyType notifyType);
53     static void HandleTaskNotifyUltraConservative(SExecuteUnit* manager, const QoS& qos, TaskNotifyType notifyType);
54 private:
55     SExecuteUnit();
56     ~SExecuteUnit() override;
57 
PokeAdd(const QoS & qos)58     void PokeAdd(const QoS& qos) override
59     {
60         handleTaskNotify(this, qos, TaskNotifyType::TASK_ADDED);
61     }
PokePick(const QoS & qos)62     void PokePick(const QoS& qos) override
63     {
64         handleTaskNotify(this, qos, TaskNotifyType::TASK_PICKED);
65     }
PokeLocal(const QoS & qos)66     void PokeLocal(const QoS& qos) override
67     {
68         if (!FFRTFacade::GetSchedInstance()->GetScheduler(qos).IsStealerActive()) {
69             handleTaskNotify(this, qos, TaskNotifyType::TASK_LOCAL);
70         }
71     }
PokeEscape(const QoS & qos,bool isPollWait)72     void PokeEscape(const QoS& qos, bool isPollWait) override
73     {
74         handleTaskNotify(this, qos, TaskNotifyType::TASK_ESCAPED);
75     }
76 
PokeAddRtq(const QoS & qos,bool isRisingEdge)77     void PokeAddRtq(const QoS &qos, bool isRisingEdge) override
78     {
79         (void)isRisingEdge; // deprecated
80         handleTaskNotify(this, qos, TaskNotifyType::TASK_ADDED);
81     }
82 
83     void PokeImpl(const QoS& qos, uint32_t taskCount, TaskNotifyType notifyType);
84     void ExecuteEscape(int qos) override;
85 
86     std::function<void (SExecuteUnit*, const QoS&, TaskNotifyType)> handleTaskNotify { nullptr };
87 };
88 } // namespace ffrt
89 #endif
90