• 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 #include "dependence_manager.h"
17 #include "util/ffrt_facade.h"
18 #include "util/singleton_register.h"
19 #include "tm/io_task.h"
20 
21 namespace ffrt {
Instance()22 DependenceManager& DependenceManager::Instance()
23 {
24     return SingletonRegister<DependenceManager>::Instance();
25 }
26 
RegistInsCb(SingleInsCB<DependenceManager>::Instance && cb)27 void DependenceManager::RegistInsCb(SingleInsCB<DependenceManager>::Instance &&cb)
28 {
29     SingletonRegister<DependenceManager>::RegistInsCb(std::move(cb));
30 }
31 
onSubmitUV(ffrt_executor_task_t * task,const task_attr_private * attr)32 void DependenceManager::onSubmitUV(ffrt_executor_task_t *task, const task_attr_private *attr)
33 {
34     FFRT_EXECUTOR_TASK_SUBMIT_MARKER(task);
35     FFRT_TRACE_SCOPE(1, onSubmitUV);
36     QoS qos = (attr == nullptr || attr->qos_ == qos_inherit) ? QoS() : QoS(attr->qos_);
37     FFRTTraceRecord::TaskSubmit<ffrt_uv_task>(qos);
38     LinkedList* node = reinterpret_cast<LinkedList *>(&task->wq);
39     FFRTScheduler* sch = FFRTFacade::GetSchedInstance();
40     if (!sch->InsertNode(node, qos)) {
41         FFRT_LOGE("Submit UV task failed!");
42         return;
43     }
44     FFRTTraceRecord::TaskEnqueue<ffrt_uv_task>(qos);
45 }
46 
onSubmitIO(const ffrt_io_callable_t & work,const task_attr_private * attr)47 void DependenceManager::onSubmitIO(const ffrt_io_callable_t& work, const task_attr_private* attr)
48 {
49     FFRT_TRACE_SCOPE(1, onSubmitIO);
50     IOTask* ioTask = TaskFactory<IOTask>::Alloc();
51     new (ioTask) IOTask(work, attr);
52     FFRTTraceRecord::TaskSubmit<ffrt_io_task>(ioTask->qos_);
53     if (!FFRTFacade::GetSchedInstance()->InsertNode(&ioTask->fq_we.node, ioTask->qos_)) {
54         FFRT_LOGE("Submit IO task failed!");
55         return;
56     }
57     FFRTTraceRecord::TaskEnqueue<ffrt_io_task>(ioTask->qos_);
58 }
59 }