Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 : #include "aicpusd_event_manager.h"
11 : #include <algorithm>
12 : #include <cstdint>
13 : #include <securec.h>
14 : #include <unistd.h>
15 : #include <sstream>
16 : #include "ascend_hal.h"
17 : #include "aicpusd_interface_process.h"
18 : #include "aicpusd_event_process.h"
19 : #include "aicpusd_threads_process.h"
20 : #include "dump_task.h"
21 : #include "ts_api.h"
22 : #include "aicpu_context.h"
23 : #include "aicpu_async_event.h"
24 : #include "aicpu_sched/common/aicpu_task_struct.h"
25 : #include "aicpusd_resource_manager.h"
26 : #include "aicpusd_drv_manager.h"
27 : #include "aicpusd_model_execute.h"
28 : #include "aicpu_engine.h"
29 : #include "aicpusd_monitor.h"
30 : #include "aicpusd_lastword.h"
31 : #include "task_queue.h"
32 : #include "aicpusd_profiler.h"
33 : #include "aicpusd_msg_send.h"
34 : #include "common/aicpusd_util.h"
35 : #include "aicpusd_mpi_mgr.h"
36 : #include "aicpu_pulse.h"
37 : #include "aicpusd_queue_event_process.h"
38 : #include "type_def.h"
39 : #include "aicpusd_message_queue.h"
40 :
41 : namespace AicpuSchedule {
42 : namespace {
43 : // dvpp kernels so
44 : const char_t* const DVPP_KERNELS_SO_NAME = "libdvpp_kernels.so";
45 : // dvpp event handle kernel name
46 : const char_t* const DVPP_EVENT_HANDLE_KERNEL_NAME = "DvppHandleEvent";
47 : // dvpp mpi kernels so
48 : const char_t* const DVPP_MPI_KERNELS_SO_NAME = "libmpi_dvpp_kernels.so";
49 : // dvpp mpi handle kernel name
50 : const char_t* const DVPP_MPI_EVENT_HANDLE_KERNEL_NAME = "ProcessDvppMpiEvent";
51 : // retr kernels so
52 : const char_t* const RETR_KERNELS_SO_NAME = "libretr_kernels.so";
53 : // retr event handle kernel name
54 : const char_t* const RETR_EVENT_KERNEL_NAME = "RetrEventKernel";
55 : // context key: streamId
56 : const std::string CONTEXT_KEY_STREAM_ID = "streamId";
57 : // task flag: convert driver task
58 : constexpr uint64_t CONVER_DRIVER_2_AICPU = 0x0000FFFFFFFFFFFFU;
59 : // running thread flag
60 : thread_local bool g_runningThreadFlag(true);
61 : // first array index
62 : constexpr size_t FIRST_INDEX = 0LU;
63 : // litehisi wait event timeout 120s
64 : constexpr uint32_t BIT_8 = 8;
65 : constexpr uint32_t TIMEOUT_LOOP_MAX_INTERVAL = 40U;
66 : constexpr uint32_t EVENT_PROXY_MSG = static_cast<uint32_t>(EVENT_ID::EVENT_USR_START) + 8U;
67 : constexpr uint8_t VERSION_0 = 0;
68 : constexpr uint8_t VERSION_1 = 1;
69 :
70 : constexpr uint32_t AICPU_TOPIC_USER_DATA_PAYLOAD_LEN = 40U;
71 : constexpr uint32_t AICPU_TOPIC_DEFAULT_KERNEL_TYPE = 127U;
72 : struct AicpuHwtsTaskInfo {
73 : uint64_t taskSoNamePtr; /* kernelSo */
74 : uint64_t paraPtr; /* paramBase */
75 : uint64_t taskNamePtr; /* kernelName */
76 : uint64_t l2StructPtr; /* l2Ctrl */
77 : uint64_t extraFieldPtr;
78 : };
79 : } // namespace
80 : /**
81 : * @ingroup AicpuEventManager
82 : * @brief it is used to construct a object of AicpuEventManager.
83 : */
84 2 : AicpuEventManager::AicpuEventManager()
85 2 : : noThreadFlag_(true), runningFlag_(true), groupId_(0U), eventGetFunc_(nullptr), eventRspFunc_(nullptr)
86 : {
87 : /* init all event to make all event handle is not null */
88 130 : for (uint32_t i = 0U; i < EVENT_MAX_NUM; ++i) {
89 128 : aicpuEventProcFunc_[i] = &AicpuEventManager::ProcDefaultEvent;
90 : }
91 :
92 2 : aicpuEventProcFunc_[EVENT_TS_HWTS_KERNEL] = &AicpuEventManager::ProcTsHWTSEvent;
93 2 : aicpuEventProcFunc_[EVENT_DVPP_MSG] = &AicpuEventManager::ProcDvppMsgEvent;
94 2 : aicpuEventProcFunc_[EVENT_DVPP_MPI_MSG] = &AicpuEventManager::ProcDvppMpiMsgEvent;
95 2 : aicpuEventProcFunc_[EVENT_FR_MSG] = &AicpuEventManager::ProcFrMsgEvent;
96 2 : aicpuEventProcFunc_[EVENT_SPLIT_KERNEL] = &AicpuEventManager::ProcSplitKernelEvent;
97 2 : aicpuEventProcFunc_[EVENT_RANDOM_KERNEL] = &AicpuEventManager::ProcRandomKernelEvent;
98 2 : aicpuEventProcFunc_[EVENT_TS_CTRL_MSG] = &AicpuEventManager::ProcTsCtrlEvent;
99 2 : aicpuEventProcFunc_[EVENT_QUEUE_EMPTY_TO_NOT_EMPTY] = &AicpuEventManager::ProcQueueEmptyToNotEmptyEvent;
100 2 : aicpuEventProcFunc_[EVENT_QUEUE_FULL_TO_NOT_FULL] = &AicpuEventManager::ProcQueueFullToNotFullEvent;
101 2 : aicpuEventProcFunc_[EVENT_AICPU_MSG] = &AicpuEventManager::ProcAicpuMsgEvent;
102 2 : aicpuEventProcFunc_[EVENT_QUEUE_ENQUEUE] = &AicpuEventManager::ProcQueueEvent;
103 2 : aicpuEventProcFunc_[EVENT_TDT_ENQUEUE] = &AicpuEventManager::ProcOnPreprocessEvent;
104 2 : aicpuEventProcFunc_[EVENT_ACPU_MSG_TYPE1] = &AicpuEventManager::ProcOnPreprocessEvent;
105 2 : aicpuEventProcFunc_[EVENT_CDQ_MSG] = &AicpuEventManager::ProcCDQEvent;
106 2 : aicpuEventProcFunc_[EVENT_QS_MSG] = &AicpuEventManager::ProcQsEvent;
107 2 : aicpuEventProcFunc_[EVENT_DRV_MSG] = &AicpuEventManager::ProcDrvEvent;
108 2 : aicpuEventProcFunc_[EVENT_PROXY_MSG] = &AicpuEventManager::ProcProxyEvent;
109 2 : }
110 :
111 314 : AicpuEventManager& AicpuEventManager::GetInstance()
112 : {
113 314 : static AicpuEventManager instance;
114 314 : return instance;
115 : }
116 :
117 : /**
118 : * @ingroup AicpuEventManager
119 : * @brief it use to init.
120 : * @param [in] noThreadFlag : have thread flag.
121 : * @param [in] runningFlag : running flag.
122 : * @param [in] grpId : group id.
123 : * @return AICPU_SCHEDULE_OK: success, other: error code
124 : */
125 32 : void AicpuEventManager::InitEventMgr(const bool noThreadFlag, const bool runningFlag, const uint32_t grpId)
126 : {
127 32 : noThreadFlag_ = noThreadFlag;
128 32 : runningFlag_ = runningFlag;
129 32 : groupId_ = grpId;
130 :
131 1056 : for (uint32_t i = 0; i < MAX_AICPU_THREAD_NUM; i++) {
132 66560 : for (int j = 0; j < EVENT_MAX_NUM; j++) {
133 65536 : recvEventStat_[i][j] = 0;
134 65536 : procEventStat_[i][j] = 0;
135 : }
136 : }
137 32 : InitLastwordCallback();
138 32 : }
139 :
140 16 : void AicpuEventManager::InitEventFunc(const AicpuSchedMode aicpuSchedMode)
141 : {
142 16 : eventGetFunc_ = (aicpuSchedMode == AicpuSchedMode::SCHED_MODE_MSGQ) ? &AicpuEventManager::DoOnceMsq :
143 : &AicpuEventManager::DoOnceEsched;
144 16 : eventRspFunc_ = (aicpuSchedMode == AicpuSchedMode::SCHED_MODE_MSGQ) ? &AicpuEventManager::ResponseMsq :
145 : &AicpuEventManager::ResponseEsched;
146 16 : }
147 :
148 32 : void AicpuEventManager::InitLastwordCallback()
149 : {
150 371 : auto lastwordCallback = [this]() {
151 371 : aicpusd_run_info("Event sd stat:");
152 47488 : auto accumulate = [](const uint64_t stat[MAX_AICPU_THREAD_NUM][EVENT_MAX_NUM], int eventId) {
153 47488 : uint64_t sum = 0;
154 1567104 : for (uint32_t i = 0; i < MAX_AICPU_THREAD_NUM; i++) {
155 1519616 : sum += stat[i][eventId];
156 : }
157 47488 : return sum;
158 : };
159 :
160 : uint64_t eventTotal;
161 24115 : for (uint32_t i = 0; i < EVENT_MAX_NUM; i++) {
162 23744 : eventTotal = accumulate(this->recvEventStat_, i);
163 23744 : aicpusd_run_info("---Recv event id[%d]: %llu", i, eventTotal);
164 : }
165 :
166 24115 : for (uint32_t i = 0; i < EVENT_MAX_NUM; i++) {
167 23744 : eventTotal = accumulate(this->procEventStat_, i);
168 23744 : aicpusd_run_info("---Proc event id[%d]: %llu", i, eventTotal);
169 : }
170 371 : };
171 96 : AicpusdLastword::GetInstance().RegLastwordCallback("aicpu sd event mng", lastwordCallback, cancelLastword_);
172 32 : }
173 :
174 387605 : int32_t AicpuEventManager::DoOnce(const uint32_t threadIndex, const uint32_t deviceId, const int32_t timeout)
175 : {
176 387605 : return (this->*eventGetFunc_)(threadIndex, deviceId, timeout);
177 : }
178 :
179 116 : int32_t AicpuEventManager::SendResponse(const uint32_t deviceId, const uint32_t subEventId, hwts_response_t& resp) const
180 : {
181 116 : return (this->*eventRspFunc_)(deviceId, subEventId, resp);
182 : }
183 :
184 : /**
185 : * @ingroup AicpuEventManager
186 : * @brief it use to process for call interface.
187 : * @param [in] modelId : the model id.
188 : * @return AICPU_SCHEDULE_OK: success, other: error code
189 : */
190 9 : int32_t AicpuEventManager::ExecuteProcess(const uint32_t modelId)
191 : {
192 9 : const auto model = AicpuModelManager::GetInstance().GetModel(modelId);
193 9 : if (model == nullptr) {
194 1 : aicpusd_err("Model[%u] not found.", modelId);
195 1 : return AICPU_SCHEDULE_ERROR_MODEL_NOT_FOUND;
196 : }
197 :
198 8 : const int32_t ret = model->ModelExecute();
199 8 : if (ret != AICPU_SCHEDULE_OK) {
200 1 : aicpusd_err("Failed to execute model[%u], ret[%d].", modelId, ret);
201 1 : return ret;
202 : }
203 :
204 7 : aicpusd_info("Finished to execute the head stream, modelId[%u], ret[%d].", modelId, ret);
205 7 : AicpuMsgSend::SendEvent();
206 7 : CallModeLoopProcess();
207 :
208 7 : return AICPU_SCHEDULE_OK;
209 : }
210 :
211 : /**
212 : * @ingroup AicpuEventManager
213 : * @brief it use to execute the model from call interface.
214 : * @param [in] drvEventInfo : event info.
215 : * @param [out] drvEventAck : event ack.
216 : * @return 0: success, other: error code
217 : */
218 3 : int32_t AicpuEventManager::ExecuteProcessSyc(const event_info* const drvEventInfo, event_ack* const drvEventAck)
219 : {
220 3 : int32_t ret = AICPU_SCHEDULE_OK;
221 3 : switch (drvEventInfo->comm.event_id) {
222 1 : case EVENT_TS_HWTS_KERNEL:
223 1 : ret = ProcessHWTSKernelEvent(*drvEventInfo, 0U);
224 1 : aicpusd_info("Finish to process HWTS event, ret[%d].", ret);
225 1 : break;
226 1 : case EVENT_TS_CTRL_MSG:
227 1 : ret = ProcessHWTSControlEvent(*drvEventInfo);
228 1 : aicpusd_info("Finish to process TS CTRL event, ret[%d].", ret);
229 1 : break;
230 1 : default:
231 1 : aicpusd_warn("Don't support this event, event_id[%u]", drvEventInfo->comm.event_id);
232 1 : break;
233 : }
234 3 : drvEventAck->event_id = drvEventInfo->comm.event_id;
235 3 : return ret;
236 : }
237 :
238 : /**
239 : * @ingroup AicpuEventManager
240 : * @brief it use to execute the model from ts.
241 : * @param [in] modelId : the id of model.
242 : * @return AICPU_SCHEDULE_OK: success, other: error code
243 : */
244 4 : int32_t AicpuEventManager::TsControlExecuteProcess(const uint32_t modelId) const
245 : {
246 4 : const auto model = AicpuModelManager::GetInstance().GetModel(modelId);
247 4 : if (model == nullptr) {
248 2 : aicpusd_err("Model[%u] not found.", modelId);
249 2 : return AICPU_SCHEDULE_ERROR_MODEL_NOT_FOUND;
250 : }
251 :
252 2 : const int32_t ret = model->ModelExecute();
253 2 : if (ret != AICPU_SCHEDULE_OK) {
254 1 : aicpusd_err("Failed to execute model[%u], ret[%d].", modelId, ret);
255 1 : return ret;
256 : }
257 1 : return AICPU_SCHEDULE_OK;
258 : }
259 :
260 : /**
261 : * @ingroup AicpuEventManager
262 : * @brief it use to set the exit flag of loop which wait event.
263 : */
264 2 : void AicpuEventManager::CheckAndSetExitFlag() const
265 : {
266 2 : if (noThreadFlag_) {
267 2 : aicpusd_info("Set the exit flag.");
268 2 : g_runningThreadFlag = false;
269 : }
270 2 : }
271 :
272 1 : int32_t AicpuEventManager::ProcessTsAicpuModelDestroy(const AicpuSqeAdapter::AicpuModelOperateInfo& info) const
273 : {
274 1 : const uint32_t modelId = static_cast<uint32_t>(info.model_id);
275 1 : const AicpuModelStatus modelStatus = AicpuModelManager::GetInstance().GetModelStatus(modelId);
276 1 : if (modelStatus == AicpuModelStatus::MODEL_STATUS_RUNNING) {
277 0 : const auto ret = TsControlTaskAbort(info);
278 0 : if (ret != AICPU_SCHEDULE_OK) {
279 0 : aicpusd_err("Failed to abort modelId[%u] ret[%d]", modelId, ret);
280 0 : return ret;
281 : }
282 : }
283 1 : const auto ret = AicpuScheduleInterface::GetInstance().Destroy(modelId);
284 1 : if (ret != AICPU_SCHEDULE_OK) {
285 1 : aicpusd_err("Failed to destroy modelId[%u].", modelId);
286 1 : return ret;
287 : }
288 0 : CheckAndSetExitFlag();
289 0 : aicpusd_info("The destroy task is complete, ret[%d]", ret);
290 0 : return ret;
291 : }
292 :
293 : /**
294 : * @ingroup AicpuEventManager
295 : * @brief it use to process distributing event.
296 : * @param [in] info : the information of task.
297 : * @return AICPU_SCHEDULE_OK: success, other: error code
298 : */
299 6 : int32_t AicpuEventManager::EventDistribution(const AicpuSqeAdapter::AicpuModelOperateInfo& info) const
300 : {
301 6 : int32_t ret = AICPU_SCHEDULE_OK;
302 6 : const uint32_t cmdType = static_cast<uint32_t>(info.cmd_type);
303 6 : switch (cmdType) {
304 2 : case TS_AICPU_MODEL_LOAD: {
305 2 : aicpusd_info("Begin to load task.");
306 2 : const void* const argPtr = ValueToPtr(info.arg_ptr);
307 2 : ret = AicpuScheduleInterface::GetInstance().LoadProcess(const_cast<const void*>(argPtr));
308 2 : aicpusd_info("The load task is complete, ret[%d].", ret);
309 2 : break;
310 : }
311 1 : case TS_AICPU_MODEL_EXECUTE: {
312 1 : const uint32_t modelId = static_cast<uint32_t>(info.model_id);
313 1 : ret = TsControlExecuteProcess(modelId);
314 1 : aicpusd_info("The execute task is complete, modelId[%u], ret[%d].", modelId, ret);
315 1 : break;
316 : }
317 1 : case TS_AICPU_MODEL_ABORT: {
318 1 : const uint32_t modelId = static_cast<uint32_t>(info.model_id);
319 1 : ret = TsControlTaskAbort(info);
320 1 : if (ret != AICPU_SCHEDULE_OK) {
321 1 : aicpusd_err("Failed to abort modelId[%u] ret[%d]", modelId, ret);
322 1 : return ret;
323 : }
324 0 : CheckAndSetExitFlag();
325 0 : aicpusd_info("The abort task is complete, ret[%d]", ret);
326 0 : break;
327 : }
328 1 : case TS_AICPU_MODEL_DESTROY: {
329 1 : ret = ProcessTsAicpuModelDestroy(info);
330 1 : if (ret != AICPU_SCHEDULE_OK) {
331 1 : return ret;
332 : }
333 0 : break;
334 : }
335 1 : default: {
336 1 : aicpusd_err("The type is not found, type[%u]", cmdType);
337 1 : CheckAndSetExitFlag();
338 1 : ret = AICPU_SCHEDULE_ERROR_NOT_FOUND_CMD_TYPE;
339 1 : break;
340 : }
341 : }
342 4 : return ret;
343 : }
344 :
345 : /**
346 : * @ingroup AicpuEventManager
347 : * @brief it use to abort task.
348 : * @return AICPU_SCHEDULE_OK: success, other: error code
349 : */
350 2 : int32_t AicpuEventManager::TsControlTaskAbort(const AicpuSqeAdapter::AicpuModelOperateInfo& info) const
351 : {
352 2 : const uint32_t modelId = static_cast<uint32_t>(info.model_id);
353 2 : AicpuModel* const model = AicpuModelManager::GetInstance().GetModel(modelId);
354 2 : if (model == nullptr) {
355 1 : aicpusd_err("Model[%u] abort failed, no model found.", modelId);
356 1 : return AICPU_SCHEDULE_ERROR_MODEL_NOT_FOUND;
357 : }
358 1 : const auto ret = model->ModelAbort();
359 1 : aicpusd_info("End to process abort task for modelId[%u] from ts, ret[%d].", modelId, ret);
360 1 : return ret;
361 : }
362 :
363 : /**
364 : * @ingroup AicpuEventManager
365 : * @brief it use to process control task from ts
366 : * @param [in] ctrlMsg : the struct of control task.
367 : * @param [in] subEvent : it is used to store subeventid which is in receive struct.
368 : * @return AICPU_SCHEDULE_OK: success, other: error code
369 : */
370 4 : int32_t AicpuEventManager::ProcessModelEvent(AicpuSqeAdapter& aicpuSqeAdapter, const uint32_t subEvent)
371 : {
372 4 : AicpuSqeAdapter::AicpuModelOperateInfo info{};
373 4 : aicpuSqeAdapter.GetAicpuModelOperateInfo(info);
374 4 : int32_t ret = EventDistribution(info);
375 :
376 4 : ret = AicpuEventProcess::GetInstance().ProcessResponseInfo(
377 : aicpuSqeAdapter, static_cast<uint16_t>(ret), subEvent, noThreadFlag_);
378 4 : return ret;
379 : }
380 :
381 : /**
382 : * @ingroup AicpuEventManager
383 : * @brief it use to process control task from ts version 0
384 : * @param [in] drvEventInfo : the event information from ts.
385 : * @return AICPU_SCHEDULE_OK: success, other: error code
386 : */
387 32 : int32_t AicpuEventManager::ProcessHWTSControlEventV0(const event_info& drvEventInfo)
388 : {
389 : // for the msg is address of array, it is not a nullptr.
390 : // so the info is not used to judge whether is nullptr;
391 32 : const TsAicpuSqe* const ctrlMsg = PtrToPtr<const char_t, const TsAicpuSqe>(drvEventInfo.priv.msg);
392 32 : const uint16_t version = FeatureCtrl::GetTsMsgVersion();
393 32 : AicpuSqeAdapter aicpuSqeAdapter(*ctrlMsg, version);
394 32 : uint8_t cmdType = aicpuSqeAdapter.GetCmdType();
395 32 : aicpusd_info("Begin to process version[%hu] ctrl msg, cmd type[%u].", version, cmdType);
396 32 : int32_t ret = AICPU_SCHEDULE_OK;
397 32 : switch (cmdType) {
398 4 : case AICPU_MSG_VERSION: {
399 4 : ret = AicpuEventProcess::GetInstance().ProcessMsgVersionEvent(aicpuSqeAdapter);
400 4 : break;
401 : }
402 2 : case AICPU_MODEL_OPERATE: {
403 2 : ret = ProcessModelEvent(aicpuSqeAdapter, drvEventInfo.comm.subevent_id);
404 2 : if (ret != AICPU_SCHEDULE_OK) {
405 0 : return ret;
406 : }
407 2 : break;
408 : }
409 2 : case AIC_TASK_REPORT: {
410 2 : ret = AicpuEventProcess::GetInstance().ProcessTaskReportEvent(aicpuSqeAdapter);
411 2 : if (ret != AICPU_SCHEDULE_OK) {
412 2 : aicpusd_err("Failed to execute task report from ts.");
413 2 : return ret;
414 : }
415 0 : aicpusd_info("Finish to execute the task report from ts.");
416 0 : CheckAndSetExitFlag();
417 0 : break;
418 : }
419 1 : case AICPU_NOTIFY_RECORD:
420 1 : break;
421 3 : case AICPU_DATADUMP_REPORT: // dump data
422 3 : ret = AicpuEventProcess::GetInstance().ProcessDumpDataEvent(aicpuSqeAdapter);
423 3 : break;
424 2 : case AICPU_DATADUMP_LOADINFO: // load op mapping info for dump
425 2 : ret = AicpuEventProcess::GetInstance().ProcessLoadOpMappingEvent(aicpuSqeAdapter);
426 2 : break;
427 12 : case AICPU_TIMEOUT_CONFIG: // set op execute timeout config send by ts: include execute and wait timeout
428 12 : ret = AicpuEventProcess::GetInstance().ProcessSetTimeoutEvent(aicpuSqeAdapter);
429 12 : break;
430 2 : case AICPU_FFTS_PLUS_DATADUMP_REPORT: // dump FFTSPlus data
431 2 : ret = AicpuEventProcess::GetInstance().ProcessDumpFFTSPlusDataEvent(aicpuSqeAdapter);
432 2 : break;
433 2 : case AICPU_INFO_LOAD: // load platform info from buf
434 2 : ret = AicpuEventProcess::GetInstance().ProcessLoadPlatformFromBuf(aicpuSqeAdapter);
435 2 : break;
436 1 : case AIC_ERROR_REPORT: {
437 : AicpuSqeAdapter::AicErrReportInfo reportInfo;
438 1 : aicpuSqeAdapter.GetAicErrReportInfo(reportInfo);
439 1 : aicpu::OpEventParam param = {};
440 1 : param.resultCode = static_cast<uint32_t>(reportInfo.u.aicError.result_code);
441 1 : param.aivErrorBitMap = reportInfo.u.aicError.aiv_err_bitmap;
442 1 : param.aicErrorBitMap = reportInfo.u.aicError.aic_err_bitmap;
443 1 : aicpu::AsyncEventManager::GetInstance().ProcessOpEvent(drvEventInfo.comm.event_id, cmdType, ¶m);
444 1 : break;
445 : }
446 1 : default:
447 1 : aicpusd_err("The event is not found, cmd type[%u]", cmdType);
448 1 : return AICPU_SCHEDULE_ERROR_NOT_FOUND_EVENT;
449 : }
450 29 : return ret;
451 32 : }
452 :
453 : /**
454 : * @ingroup AicpuEventManager
455 : * @brief it use to process control task from ts version 1
456 : * @param [in] drvEventInfo : the event information from ts.
457 : * @return AICPU_SCHEDULE_OK: success, other: error code
458 : */
459 19 : int32_t AicpuEventManager::ProcessHWTSControlEventV1(const event_info& drvEventInfo)
460 : {
461 : // for the msg is address of array, it is not a nullptr.
462 : // so the info is not used to judge whether is nullptr;
463 19 : const TsAicpuMsgInfo* const msgInfo = PtrToPtr<const char_t, const TsAicpuMsgInfo>(drvEventInfo.priv.msg);
464 19 : const uint16_t version = FeatureCtrl::GetTsMsgVersion();
465 19 : AicpuSqeAdapter aicpuSqeAdapter(*msgInfo, version);
466 19 : uint8_t cmdType = aicpuSqeAdapter.GetCmdType();
467 19 : aicpusd_info("Begin to process version[%hu] ctrl msg, cmd type[%u].", version, cmdType);
468 19 : int32_t ret = AICPU_SCHEDULE_OK;
469 19 : switch (cmdType) {
470 0 : case TS_AICPU_MSG_VERSION: {
471 0 : ret = AicpuEventProcess::GetInstance().ProcessMsgVersionEvent(aicpuSqeAdapter);
472 0 : break;
473 : }
474 2 : case TS_AICPU_MODEL_OPERATE: {
475 2 : ret = ProcessModelEvent(aicpuSqeAdapter, drvEventInfo.comm.subevent_id);
476 2 : break;
477 : }
478 1 : case TS_AICPU_TASK_REPORT: {
479 1 : ret = AicpuEventProcess::GetInstance().ProcessTaskReportEvent(aicpuSqeAdapter);
480 1 : if (ret != AICPU_SCHEDULE_OK) {
481 1 : aicpusd_err("Failed to execute task report from ts.");
482 1 : return ret;
483 : }
484 0 : aicpusd_info("Finish to execute the task report from ts.");
485 0 : CheckAndSetExitFlag();
486 0 : break;
487 : }
488 7 : case TS_AICPU_NORMAL_DATADUMP_REPORT:
489 : case TS_AICPU_DEBUG_DATADUMP_REPORT: {
490 7 : ret = AicpuEventProcess::GetInstance().ProcessDumpDataEvent(aicpuSqeAdapter);
491 7 : break;
492 : }
493 6 : case TS_AICPU_DATADUMP_INFO_LOAD: {
494 6 : ret = AicpuEventProcess::GetInstance().ProcessLoadOpMappingEvent(aicpuSqeAdapter);
495 6 : break;
496 : }
497 1 : case TS_AICPU_TIMEOUT_CONFIG: {
498 1 : ret = AicpuEventProcess::GetInstance().ProcessSetTimeoutEvent(aicpuSqeAdapter);
499 1 : break;
500 : }
501 1 : case TS_AICPU_INFO_LOAD: {
502 1 : ret = AicpuEventProcess::GetInstance().ProcessLoadPlatformFromBuf(aicpuSqeAdapter);
503 1 : break;
504 : }
505 1 : case TS_AIC_ERROR_REPORT: {
506 : AicpuSqeAdapter::AicErrReportInfo reportInfo;
507 1 : aicpuSqeAdapter.GetAicErrReportInfo(reportInfo);
508 1 : aicpu::OpEventParam param = {};
509 1 : PrintAicErrReportInfo(reportInfo);
510 1 : break;
511 : }
512 0 : default:
513 0 : aicpusd_err("The event is not found, cmd type[%u]", cmdType);
514 0 : return AICPU_SCHEDULE_ERROR_NOT_FOUND_EVENT;
515 : }
516 18 : return ret;
517 19 : }
518 :
519 : /**
520 : * @ingroup AicpuEventManager
521 : * @brief it use to init control event version function map
522 : */
523 52 : void AicpuEventManager::InitControlVersionFunc()
524 : {
525 52 : controlEventVersionFuncMap_[VERSION_0] = &AicpuEventManager::ProcessHWTSControlEventV0;
526 52 : controlEventVersionFuncMap_[VERSION_1] = &AicpuEventManager::ProcessHWTSControlEventV1;
527 52 : return;
528 : }
529 : /**
530 : * @ingroup AicpuEventManager
531 : * @brief print aic error report info
532 : * @param [in] reportInfo : info from aicpu sd adapter.
533 : */
534 3 : void AicpuEventManager::PrintAicErrReportInfo(const AicpuSqeAdapter::AicErrReportInfo& reportInfo)
535 : {
536 3 : TsToAicpuAicErrMsgReport aicAivErrMsg = reportInfo.u.aicErrorMsg;
537 3 : uint16_t aicBitmapNum = aicAivErrMsg.aic_bitmap_num;
538 3 : uint16_t aivBitmapNum = aicAivErrMsg.aiv_bitmap_num;
539 3 : size_t bitMapTotalNum = static_cast<size_t>(aicBitmapNum) + static_cast<size_t>(aivBitmapNum);
540 3 : size_t bitMapCapacity = sizeof(aicAivErrMsg.bitmap) / sizeof(aicAivErrMsg.bitmap[FIRST_INDEX]);
541 3 : if (bitMapTotalNum > bitMapCapacity) {
542 1 : aicpusd_err(
543 : "The total number of bit maps of AIC[%hu] and AIV[%hu] exceeds bitmap capacity[%zu].", aicBitmapNum,
544 : aivBitmapNum, bitMapCapacity);
545 1 : return;
546 : }
547 2 : std::ostringstream oss;
548 3 : for (size_t i = 0; i < aicBitmapNum; i++) {
549 : oss << "aicmap"
550 1 : << "[" << i << "] : " << std::bitset<BIT_8>(aicAivErrMsg.bitmap[i]).to_string() << ",";
551 : }
552 4 : for (size_t i = aicBitmapNum; i < (aicBitmapNum + aivBitmapNum); i++) {
553 : oss << "aivmap"
554 2 : << "[" << i << "] : " << std::bitset<BIT_8>(aicAivErrMsg.bitmap[i]).to_string() << ",";
555 : }
556 2 : aicpusd_info("Bit map is : %s", oss.str().c_str());
557 2 : return;
558 2 : }
559 :
560 : /**
561 : * @ingroup AicpuEventManager
562 : * @brief it use to process control task from ts
563 : * @param [in] drvEventInfo : the event information from ts.
564 : * @return AICPU_SCHEDULE_OK: success, other: error code
565 : */
566 52 : int32_t AicpuEventManager::ProcessHWTSControlEvent(const event_info& drvEventInfo)
567 : {
568 52 : uint16_t version = FeatureCtrl::GetTsMsgVersion();
569 52 : aicpusd_info("Begin to process version[%hu] ctrl msg.", version);
570 52 : InitControlVersionFunc();
571 52 : int32_t ret = AICPU_SCHEDULE_OK;
572 52 : if (controlEventVersionFuncMap_.find(version) == controlEventVersionFuncMap_.end()) {
573 1 : aicpusd_err("The version[%hu] does not have a corresponding processing function.", version);
574 1 : return AICPU_SCHEDULE_ERROR_NOT_FOUND_VERSION;
575 : }
576 51 : ret = (this->*controlEventVersionFuncMap_[version])(drvEventInfo);
577 51 : return ret;
578 : }
579 : /**
580 : * @ingroup AicpuEventManager
581 : * @brief it use to init control event version function map
582 : */
583 130 : void AicpuEventManager::GetStreamIdAndTaskIdFromEvent(
584 : const hwts_ts_kernel& tsKernel, uint32_t& streamId, uint64_t& taskId, uint32_t subevent_id) const
585 : {
586 130 : uint32_t tmpStreamId = 0U;
587 130 : aicpusd_info("Get stream id[%u] and task id[%u] from hwts.", tsKernel.streamID, tsKernel.taskID);
588 129 : tmpStreamId = static_cast<uint32_t>(tsKernel.streamID);
589 129 : if (subevent_id != EVENT_FFTS_PLUS_MSG) {
590 127 : taskId = static_cast<uint32_t>(tsKernel.taskID);
591 : }
592 129 : uint16_t version = FeatureCtrl::GetTsMsgVersion();
593 129 : if (version == VERSION_0) {
594 109 : streamId = tmpStreamId;
595 : } else {
596 20 : streamId = INVALID_VAL;
597 : }
598 129 : aicpusd_info("Get stream id[%u] and task id[%u] in version[%hu].", streamId, taskId, version);
599 129 : return;
600 : }
601 : /**
602 : * @ingroup AicpuEventManager
603 : * @brief it is used to parse the struct and get some parameter.
604 : * @param [in] drvEventInfo : the event information from mailbox.
605 : * @param [in] mailboxId : mailbox id
606 : * @param [in] info : the info is used to execute task.
607 : * @param [in] serialNo : the serial no. in mailbox, which is need to use in response package.
608 : * @param [out] streamId : streamId is used to cache task, version 1 stream id is invalid
609 : * @return AICPU_SCHEDULE_OK: success, other: error code
610 : */
611 130 : int32_t AicpuEventManager::HWTSKernelEventMessageParse(
612 : const event_info& drvEventInfo, uint32_t& mailboxId, aicpu::HwtsTsKernel& info, uint64_t& serialNo,
613 : uint32_t& streamId, uint64_t& taskId, uint16_t& dataDumpEnableMode) const
614 : {
615 : // for the msg is address of array, it is not a nullptr.
616 130 : const hwts_ts_task* const eventMsg = PtrToPtr<const char_t, const hwts_ts_task>(drvEventInfo.priv.msg);
617 130 : mailboxId = eventMsg->mailbox_id;
618 130 : serialNo = static_cast<uint64_t>(eventMsg->serial_no);
619 : // for the msg is address of array, it is not a nullptr.
620 130 : const hwts_ts_kernel tsKernel = eventMsg->kernel_info;
621 130 : GetStreamIdAndTaskIdFromEvent(tsKernel, streamId, taskId, drvEventInfo.comm.subevent_id);
622 129 : const uint32_t kernelType = tsKernel.kernel_type;
623 129 : switch (kernelType) {
624 1 : case aicpu::KERNEL_TYPE_AICPU_KFC: {
625 1 : info.kernelType = kernelType;
626 1 : info.kernelBase.cceKernel.kernelName = static_cast<uint64_t>(tsKernel.kernelName & CONVER_DRIVER_2_AICPU);
627 1 : info.kernelBase.cceKernel.kernelSo = static_cast<uint64_t>(tsKernel.kernelSo & CONVER_DRIVER_2_AICPU);
628 1 : info.kernelBase.cceKernel.paramBase = static_cast<uint64_t>(tsKernel.paramBase & CONVER_DRIVER_2_AICPU);
629 1 : info.kernelBase.cceKernel.blockId = static_cast<uint32_t>(tsKernel.blockId);
630 1 : info.kernelBase.cceKernel.blockNum = static_cast<uint32_t>(tsKernel.blockNum);
631 1 : break;
632 : }
633 125 : case aicpu::KERNEL_TYPE_CCE:
634 : case aicpu::KERNEL_TYPE_AICPU:
635 : case aicpu::KERNEL_TYPE_AICPU_CUSTOM: {
636 125 : info.kernelType = kernelType;
637 125 : info.kernelBase.cceKernel.kernelName = static_cast<uint64_t>(tsKernel.kernelName & CONVER_DRIVER_2_AICPU);
638 125 : info.kernelBase.cceKernel.kernelSo = static_cast<uint64_t>(tsKernel.kernelSo & CONVER_DRIVER_2_AICPU);
639 125 : info.kernelBase.cceKernel.paramBase = static_cast<uint64_t>(tsKernel.paramBase & CONVER_DRIVER_2_AICPU);
640 125 : info.kernelBase.cceKernel.l2VaddrBase = static_cast<uint64_t>(tsKernel.l2VaddrBase & CONVER_DRIVER_2_AICPU);
641 125 : info.kernelBase.cceKernel.blockId = static_cast<uint32_t>(tsKernel.blockId);
642 125 : info.kernelBase.cceKernel.blockNum = static_cast<uint32_t>(tsKernel.blockNum);
643 125 : info.kernelBase.cceKernel.l2Size = 0U;
644 125 : info.kernelBase.cceKernel.l2InMain = static_cast<uint32_t>(tsKernel.l2InMain);
645 125 : break;
646 : }
647 1 : case aicpu::KERNEL_TYPE_FWK: {
648 1 : info.kernelType = aicpu::KERNEL_TYPE_FWK;
649 1 : info.kernelBase.fwkKernel.size = 0U;
650 1 : info.kernelBase.fwkKernel.kernel = static_cast<uint64_t>(tsKernel.paramBase & CONVER_DRIVER_2_AICPU);
651 1 : break;
652 : }
653 2 : default: {
654 2 : aicpusd_err("Don't support kernel_type[%u].", kernelType);
655 2 : return AICPU_SCHEDULE_ERROR_DRV_ERR;
656 : }
657 : }
658 :
659 127 : dataDumpEnableMode = static_cast<uint16_t>((tsKernel.l2Ctrl >> DATADUMP_ENABLE_MODE_OFFSET) & 1U);
660 127 : aicpusd_info("Kernel type of current task is [%u], dataDumpEnableMode[%u].", kernelType, dataDumpEnableMode);
661 127 : return AICPU_SCHEDULE_OK;
662 : }
663 1 : int32_t AicpuEventManager::ExecuteHWTSKFCEventTask(
664 : const event_info& drvEventInfo, const aicpu::HwtsTsKernel& aicpufwKernelInfo, const uint32_t threadIndex,
665 : const uint32_t streamId, const uint64_t taskId) const
666 : {
667 1 : aicpusd_info("kfc task, streamId[%u], taskId[%lu].", streamId, taskId);
668 1 : std::shared_ptr<aicpu::ProfMessage> profMsg = nullptr;
669 1 : const bool profFlag = aicpu::IsProfOpen();
670 1 : uint64_t tickBeforeRun = 0LLU;
671 1 : (void)aicpu::SetTaskAndStreamId(taskId, streamId);
672 1 : if (profFlag) {
673 1 : aicpusd_info("Profiling is open, start malloc.");
674 : try {
675 1 : profMsg = std::make_shared<aicpu::ProfMessage>("AICPU");
676 0 : } catch (std::exception& threadException) {
677 0 : aicpusd_err("make shared for ProfMessage failed. Exception[%s]", threadException.what());
678 0 : return TASK_FAIL;
679 0 : }
680 1 : (void)aicpu::SetProfHandle(profMsg);
681 1 : tickBeforeRun = aicpu::GetSystemTick();
682 : }
683 1 : const int32_t ret = aeCallInterface(&aicpufwKernelInfo);
684 1 : if (profFlag) {
685 1 : aicpu::aicpuProfContext_t aicpuProfCtx = {
686 : .tickBeforeRun = tickBeforeRun,
687 1 : .drvSubmitTick = static_cast<uint64_t>(drvEventInfo.comm.submit_timestamp),
688 1 : .drvSchedTick = static_cast<uint64_t>(drvEventInfo.comm.sched_timestamp),
689 1 : .kernelType = aicpu::KERNEL_TYPE_AICPU_KFC};
690 :
691 : const ProfIdentity profIdentity = {
692 : .taskId = taskId,
693 1 : .streamId = streamId,
694 : .threadIndex = threadIndex,
695 1 : .deviceId = AicpuDrvManager::GetInstance().GetDeviceId()};
696 1 : (void)AicpuUtil::SetProfData(profMsg, aicpuProfCtx, profIdentity);
697 : }
698 1 : return ret;
699 1 : }
700 : /**
701 : * @ingroup AicpuEventManager
702 : * @brief it is used to parse the struct and get some parameter.
703 : * @param [in] drvEventInfo : the event information from mailbox.
704 : * @param [in] threadIndex : thread index assign by aicpu index, but when running time they are different.
705 : * @return AICPU_SCHEDULE_OK: success, other: error code
706 : */
707 127 : int32_t AicpuEventManager::ProcessHWTSKernelEvent(const event_info& drvEventInfo, const uint32_t threadIndex) const
708 : {
709 127 : aicpu::HwtsTsKernel aicpufwKernelInfo = {};
710 127 : uint32_t mailboxId = 0U;
711 127 : uint32_t streamId = 0U;
712 127 : uint64_t taskId = 0LU;
713 127 : uint64_t serialNo = 0LU;
714 127 : uint16_t dataDumpEnableMode = 0U;
715 127 : int32_t ret = HWTSKernelEventMessageParse(
716 : drvEventInfo, mailboxId, aicpufwKernelInfo, serialNo, streamId, taskId, dataDumpEnableMode);
717 126 : if (ret != AICPU_SCHEDULE_OK) {
718 1 : return ret;
719 : }
720 : hwts_response_t hwtsResp;
721 125 : hwtsResp.mailbox_id = mailboxId;
722 125 : hwtsResp.serial_no = serialNo;
723 125 : const auto kernelType = aicpufwKernelInfo.kernelType;
724 125 : if (kernelType == aicpu::KERNEL_TYPE_AICPU_KFC) {
725 1 : ret = ExecuteHWTSKFCEventTask(drvEventInfo, aicpufwKernelInfo, threadIndex, streamId, taskId);
726 1 : hwtsResp.status =
727 1 : (ret == AICPU_SCHEDULE_OK) ? static_cast<uint32_t>(TASK_SUCC) : static_cast<uint32_t>(TASK_FAIL);
728 : } else {
729 124 : const TaskInfoForMonitor monitorTaskInfo = {
730 124 : .serialNo = serialNo, .taskId = taskId, .streamId = streamId, .isHwts = true};
731 124 : AicpuMonitor::GetInstance().SetTaskInfo(threadIndex, monitorTaskInfo);
732 124 : ret = ExecuteHWTSEventTask(
733 : threadIndex, streamId, taskId, serialNo, aicpufwKernelInfo, drvEventInfo, mailboxId, hwtsResp,
734 : dataDumpEnableMode);
735 : }
736 118 : hwtsResp.result = static_cast<uint32_t>(AicpuUtil::TransformInnerErrCode(ret));
737 : const auto kernelName =
738 118 : PtrToPtr<const void, const char_t>(ValueToPtr(aicpufwKernelInfo.kernelBase.cceKernel.kernelName));
739 118 : if ((noThreadFlag_) && (kernelName != nullptr) && (strcmp(kernelName, "endGraph") == 0)) {
740 0 : g_runningThreadFlag = false;
741 0 : return AICPU_SCHEDULE_OK;
742 : }
743 118 : const uint32_t drvSubeventId = drvEventInfo.comm.subevent_id;
744 118 : const uint32_t deviceId = AicpuDrvManager::GetInstance().GetDeviceId();
745 116 : const int32_t drvRet = SendResponse(deviceId, drvSubeventId, hwtsResp);
746 126 : if (drvRet != DRV_ERROR_NONE) {
747 0 : aicpusd_err(
748 : "Failed to send ack to Ts, kernelType[%u] deviceId[%u], subevent_id[%u], mailboxId[%u], "
749 : "serialNo[%lu], streamId[%u], taskId[%lu], result[%d], originResult[%d], status[%d], error[%d].",
750 : kernelType, deviceId, drvSubeventId, mailboxId, serialNo, streamId, taskId, hwtsResp.result, ret,
751 : hwtsResp.status, drvRet);
752 0 : return AICPU_SCHEDULE_ERROR_INNER_ERROR;
753 : }
754 126 : aicpusd_info(
755 : "End send ack to Ts, kernelType[%u], deviceId[%u], subevent_id[%u], mailboxId[%u], "
756 : "serialNo[%lu], streamId[%u], taskId[%lu], result[%d], originResult[%d], status[%d].",
757 : kernelType, deviceId, drvSubeventId, mailboxId, serialNo, streamId, taskId, hwtsResp.result, ret,
758 : hwtsResp.status);
759 126 : return AICPU_SCHEDULE_OK;
760 : }
761 125 : int32_t AicpuEventManager::ExecuteHWTSEventTask(
762 : const uint32_t& threadIndex, const uint32_t& streamId, const uint64_t taskId, const uint64_t& serialNo,
763 : aicpu::HwtsTsKernel& aicpufwKernelInfo, const event_info& drvEventInfo, const uint32_t& mailboxId,
764 : hwts_response_t& hwtsResp, uint16_t& dataDumpEnableMode) const
765 : {
766 125 : (void)aicpu::SetThreadLocalCtx(CONTEXT_KEY_STREAM_ID, std::to_string(streamId));
767 126 : (void)aicpu::SetTaskAndStreamId(taskId, streamId);
768 :
769 126 : aicpusd_info(
770 : "Begin to ExecuteTsKernelTask, mailboxId[%u], serialNo[%lu], streamId[%u], taskId[%lu], "
771 : "dataDumpEnableMode[%u], kernelType[%u], subeventId[%u].",
772 : mailboxId, serialNo, streamId, taskId, dataDumpEnableMode, aicpufwKernelInfo.kernelType,
773 : drvEventInfo.comm.subevent_id);
774 126 : int32_t ret = AicpuEventProcess::GetInstance().ExecuteTsKernelTask(
775 126 : aicpufwKernelInfo, threadIndex, static_cast<uint64_t>(drvEventInfo.comm.submit_timestamp),
776 126 : static_cast<uint64_t>(drvEventInfo.comm.sched_timestamp), static_cast<uint64_t>(streamId), taskId);
777 118 : hwtsResp.status = (ret == AICPU_SCHEDULE_OK) ? static_cast<uint32_t>(TASK_SUCC) : static_cast<uint32_t>(TASK_FAIL);
778 118 : if ((dataDumpEnableMode == 1U) && (ret == AICPU_SCHEDULE_OK)) {
779 1 : aicpusd_info("Datadump. Begin Dump Self.");
780 1 : TaskInfoExt dumpTaskInfo(streamId, static_cast<uint32_t>(taskId));
781 1 : const DumpFileName fileName(streamId, static_cast<uint32_t>(taskId));
782 1 : const int32_t dumpRet = AicpuSchedule::OpDumpTaskManager::GetInstance().DumpOpInfo(dumpTaskInfo, fileName);
783 1 : ret = (dumpRet != AICPU_SCHEDULE_OK) ? dumpRet : ret;
784 : }
785 118 : return ret;
786 : }
787 :
788 : /**
789 : * @ingroup AicpuEventManager
790 : * @brief it is used to process dvpp event.
791 : * @param [in] drvEventInfo : the event information from mailbox.
792 : * @param [in] threadIndex : thread index assign by aicpu index, but when running time they are different.
793 : * @return AICPU_SCHEDULE_OK: success, other: error code
794 : */
795 1 : int32_t AicpuEventManager::ProcessDvppEvent(const event_info& drvEventInfo, const uint32_t threadIndex) const
796 : {
797 : // create parambase for aicpu task,
798 1 : const size_t argsSize = sizeof(aicpu::AicpuParamHead) + sizeof(uint64_t);
799 1 : char_t args[argsSize] = {};
800 1 : const auto paramHead = reinterpret_cast<aicpu::AicpuParamHead*>(&args[FIRST_INDEX]);
801 1 : paramHead->length = argsSize;
802 1 : paramHead->ioAddrNum = 0U; // no io addr
803 : uint64_t* const attr =
804 1 : PtrToPtr<char_t, uint64_t>(PtrAdd<char_t>(&args[0UL], argsSize, sizeof(aicpu::AicpuParamHead)));
805 1 : *attr = PtrToValue(PtrToPtr<const event_info, const void>(&drvEventInfo));
806 :
807 : // create dvpp event task
808 1 : aicpu::HwtsTsKernel dvppKernel = {};
809 : // KERNEL_TYPE_AICPU
810 1 : dvppKernel.kernelType = 2U;
811 1 : dvppKernel.kernelBase.cceKernel.kernelName = reinterpret_cast<uintptr_t>(DVPP_EVENT_HANDLE_KERNEL_NAME);
812 1 : dvppKernel.kernelBase.cceKernel.kernelSo = reinterpret_cast<uintptr_t>(DVPP_KERNELS_SO_NAME);
813 1 : dvppKernel.kernelBase.cceKernel.paramBase = reinterpret_cast<uintptr_t>(&args[0UL]);
814 :
815 1 : const auto taskRet = AicpuEventProcess::GetInstance().ExecuteTsKernelTask(
816 1 : dvppKernel, threadIndex, static_cast<uint64_t>(drvEventInfo.comm.submit_timestamp),
817 1 : static_cast<uint64_t>(drvEventInfo.comm.sched_timestamp));
818 1 : aicpusd_info(
819 : "Find and execute dvpp task end, threadIndex[%u], taskRet[%d], argsSize[%zu].", threadIndex, taskRet, argsSize);
820 1 : return taskRet;
821 : }
822 :
823 1 : int32_t AicpuEventManager::ProcessMpiDvppEvent(const event_info& drvEventInfo, const uint32_t threadIndex) const
824 : {
825 : // record Mpi Dvpp event
826 1 : mpi::MpiDvppStatisticManager::Instance().InitMpiDvpp();
827 1 : mpi::MpiDvppStatisticManager::Instance().Record();
828 1 : aicpu::HwtsTsKernel mpiKernel = {};
829 : // KERNEL_TYPE_AICPU
830 1 : mpiKernel.kernelType = 2U;
831 1 : mpiKernel.kernelBase.cceKernel.kernelName = reinterpret_cast<uintptr_t>(DVPP_MPI_EVENT_HANDLE_KERNEL_NAME);
832 1 : mpiKernel.kernelBase.cceKernel.kernelSo = reinterpret_cast<uintptr_t>(DVPP_MPI_KERNELS_SO_NAME);
833 1 : mpiKernel.kernelBase.cceKernel.paramBase = reinterpret_cast<uintptr_t>(&drvEventInfo);
834 :
835 1 : const auto taskRet = AicpuEventProcess::GetInstance().ExecuteTsKernelTask(
836 1 : mpiKernel, threadIndex, static_cast<uint64_t>(drvEventInfo.comm.submit_timestamp),
837 1 : static_cast<uint64_t>(drvEventInfo.comm.sched_timestamp));
838 1 : aicpusd_info("Find and execute mpi dvpp task end, threadIndex[%u], taskRet[%d].", threadIndex, taskRet);
839 1 : return taskRet;
840 : }
841 :
842 1 : int32_t AicpuEventManager::ProcessRetrEvent(const event_info& drvEventInfo, const uint32_t threadIndex) const
843 : {
844 : // create parambase for aicpu task,
845 1 : const size_t argsSize = sizeof(aicpu::AicpuParamHead) + sizeof(uint64_t);
846 1 : char_t args[argsSize] = {};
847 1 : const auto paramHead = reinterpret_cast<aicpu::AicpuParamHead*>(&args[FIRST_INDEX]);
848 1 : paramHead->length = argsSize;
849 1 : paramHead->ioAddrNum = 0U; // no io addr
850 : uint64_t* const attr =
851 1 : PtrToPtr<char_t, uint64_t>(PtrAdd<char_t>(&args[0UL], argsSize, sizeof(aicpu::AicpuParamHead)));
852 1 : *attr = PtrToValue(PtrToPtr<const event_info, const void>(&drvEventInfo));
853 :
854 : // create retr event task
855 1 : aicpu::HwtsTsKernel retrKernel = {};
856 : // KERNEL_TYPE_AICPU
857 1 : retrKernel.kernelType = 2U;
858 1 : retrKernel.kernelBase.cceKernel.kernelName = reinterpret_cast<uintptr_t>(RETR_EVENT_KERNEL_NAME);
859 1 : retrKernel.kernelBase.cceKernel.kernelSo = reinterpret_cast<uintptr_t>(RETR_KERNELS_SO_NAME);
860 1 : retrKernel.kernelBase.cceKernel.paramBase = reinterpret_cast<uintptr_t>(&args[0UL]);
861 :
862 1 : const auto taskRet = AicpuEventProcess::GetInstance().ExecuteTsKernelTask(
863 1 : retrKernel, threadIndex, static_cast<uint64_t>(drvEventInfo.comm.submit_timestamp),
864 1 : static_cast<uint64_t>(drvEventInfo.comm.sched_timestamp));
865 1 : aicpusd_info(
866 : "Find and execute retr task end, threadIndex[%u], taskRet[%d], argsSize[%zu].", threadIndex, taskRet, argsSize);
867 1 : return taskRet;
868 : }
869 :
870 : /**
871 : * @ingroup AicpuScheduleInterface
872 : * @brief it is used to process CDQ event.
873 : * @param [in] drvEventInfo : the event information from mailbox.
874 : * @return AICPU_SCHEDULE_OK: success, other: error code
875 : */
876 2 : int32_t AicpuEventManager::ProcessCdqEvent(const event_info& drvEventInfo) const
877 : {
878 2 : const uint32_t drvEventId = drvEventInfo.comm.event_id;
879 2 : const uint32_t drvSubeventId = drvEventInfo.comm.subevent_id;
880 2 : void* const param = PtrToPtr<event_info, void>(const_cast<event_info*>(&drvEventInfo));
881 2 : aicpu::AsyncEventManager::GetInstance().ProcessEvent(drvEventId, drvSubeventId, param);
882 2 : aicpusd_info("ProcessCdqEvent by eventId[%u] subeventId[%u] end", drvEventId, drvSubeventId);
883 2 : return AICPU_SCHEDULE_OK;
884 : }
885 :
886 125 : int32_t AicpuEventManager::ProcTsHWTSEvent(const event_info& drvEventInfo, const uint32_t threadIndex)
887 : {
888 125 : return ProcessHWTSKernelEvent(drvEventInfo, threadIndex);
889 : }
890 :
891 1 : int32_t AicpuEventManager::ProcDefaultEvent(const event_info& drvEventInfo, const uint32_t threadIndex)
892 : {
893 : (void)threadIndex;
894 1 : aicpusd_err("Receive event but no process handle, eventID=%d", static_cast<int32_t>(drvEventInfo.comm.event_id));
895 1 : return AICPU_SCHEDULE_ERROR_NOT_FOUND_EVENT;
896 : }
897 :
898 1 : int32_t AicpuEventManager::ProcDvppMsgEvent(const event_info& drvEventInfo, const uint32_t threadIndex)
899 : {
900 1 : const int32_t ret = ProcessDvppEvent(drvEventInfo, threadIndex);
901 1 : return ret;
902 : }
903 :
904 1 : int32_t AicpuEventManager::ProcDvppMpiMsgEvent(const event_info& drvEventInfo, const uint32_t threadIndex)
905 : {
906 1 : const int32_t ret = ProcessMpiDvppEvent(drvEventInfo, threadIndex);
907 1 : return ret;
908 : }
909 :
910 1 : int32_t AicpuEventManager::ProcFrMsgEvent(const event_info& drvEventInfo, const uint32_t threadIndex)
911 : {
912 1 : const int32_t ret = ProcessRetrEvent(drvEventInfo, threadIndex);
913 1 : return ret;
914 : }
915 :
916 4 : int32_t AicpuEventManager::ProcSplitKernelEvent(const event_info& drvEventInfo, const uint32_t threadIndex)
917 : {
918 : (void)threadIndex;
919 4 : const AICPUSubEventInfo* const eventInfo = PtrToPtr<const char_t, const AICPUSubEventInfo>(drvEventInfo.priv.msg);
920 4 : aicpusd_info(
921 : "Begin to process split kernel event. parallelId=%u, type=wait", eventInfo->para.sharderTaskInfo.parallelId);
922 :
923 4 : const bool ret = ComputeProcess::GetInstance().DoSplitKernelTask(eventInfo->para.sharderTaskInfo);
924 4 : if (!ret) {
925 0 : aicpusd_err(
926 : "Process split kernel event failed. parallelId=%u, type=wait", eventInfo->para.sharderTaskInfo.parallelId);
927 0 : return static_cast<int32_t>(AICPU_SCHEDULE_FAIL);
928 : }
929 :
930 4 : return AICPU_SCHEDULE_OK;
931 : }
932 :
933 4 : int32_t AicpuEventManager::ProcRandomKernelEvent(const event_info& drvEventInfo, const uint32_t threadIndex)
934 : {
935 : (void)drvEventInfo;
936 : (void)threadIndex;
937 4 : aicpusd_info("Begin to process random kernel event. threadIndex=%u", threadIndex);
938 4 : const bool ret = ComputeProcess::GetInstance().DoRandomKernelTask();
939 4 : if (!ret) {
940 4 : aicpusd_err("Process random kernel event failed. threadIndex=%u", threadIndex);
941 4 : return static_cast<int32_t>(AICPU_SCHEDULE_FAIL);
942 : }
943 :
944 0 : return AICPU_SCHEDULE_OK;
945 : }
946 :
947 12 : int32_t AicpuEventManager::ProcTsCtrlEvent(const event_info& drvEventInfo, const uint32_t threadIndex)
948 : {
949 : (void)threadIndex;
950 12 : const int32_t ret = ProcessHWTSControlEvent(drvEventInfo);
951 12 : aicpusd_info(
952 : "Finish to process CTRL event, eventid[%u], threadIndex[%u], ret[%d].", drvEventInfo.comm.event_id, threadIndex,
953 : ret);
954 12 : return ret;
955 : }
956 :
957 1 : int32_t AicpuEventManager::ProcQueueEmptyToNotEmptyEvent(const event_info& drvEventInfo, const uint32_t threadIndex)
958 : {
959 : (void)threadIndex;
960 1 : const uint32_t queueId = drvEventInfo.comm.subevent_id;
961 1 : const int32_t ret = AicpuEventProcess::GetInstance().ProcessQueueNotEmptyEvent(queueId);
962 1 : aicpusd_info(
963 : "Finish to process non-empty event, queueId[%u], threadIndex[%u], ret[%d].", queueId, threadIndex, ret);
964 1 : return ret;
965 : }
966 :
967 1 : int32_t AicpuEventManager::ProcQueueFullToNotFullEvent(const event_info& drvEventInfo, const uint32_t threadIndex)
968 : {
969 : (void)threadIndex;
970 1 : const uint32_t queueId = drvEventInfo.comm.subevent_id;
971 1 : const int32_t ret = AicpuEventProcess::GetInstance().ProcessQueueNotFullEvent(queueId);
972 1 : aicpusd_info("Finish to process not full event, queueId[%u], threadIndex[%u], ret[%d].", queueId, threadIndex, ret);
973 1 : return ret;
974 : }
975 :
976 1 : int32_t AicpuEventManager::ProcAicpuMsgEvent(const event_info& drvEventInfo, const uint32_t threadIndex)
977 : {
978 : (void)threadIndex;
979 1 : const int32_t ret = AicpuEventProcess::GetInstance().ProcessAICPUEvent(drvEventInfo);
980 1 : return ret;
981 : }
982 :
983 1 : int32_t AicpuEventManager::ProcQueueEvent(const event_info& drvEventInfo, const uint32_t threadIndex)
984 : {
985 : (void)threadIndex;
986 1 : const int32_t ret = AicpuEventProcess::GetInstance().ProcessEnqueueEvent(drvEventInfo);
987 1 : return ret;
988 : }
989 :
990 3 : int32_t AicpuEventManager::ProcOnPreprocessEvent(const event_info& drvEventInfo, const uint32_t threadIndex)
991 : {
992 : (void)threadIndex;
993 3 : if (FeatureCtrl::IsAosCore()) {
994 1 : return AICPU_SCHEDULE_OK;
995 : }
996 2 : DataPreprocess::TaskQueueMgr::GetInstance().OnPreprocessEvent(static_cast<uint32_t>(drvEventInfo.comm.event_id));
997 2 : aicpusd_info(
998 : "Finish to process queue enqueue event, event id[%d], threadIndex[%u]", drvEventInfo.comm.event_id,
999 : threadIndex);
1000 2 : return AICPU_SCHEDULE_OK;
1001 : }
1002 :
1003 1 : int32_t AicpuEventManager::ProcCDQEvent(const event_info& drvEventInfo, const uint32_t threadIndex)
1004 : {
1005 : (void)threadIndex;
1006 1 : const int32_t ret = ProcessCdqEvent(drvEventInfo);
1007 1 : return ret;
1008 : }
1009 :
1010 27 : int32_t AicpuEventManager::ProcQsEvent(const event_info& drvEventInfo, const uint32_t threadIndex)
1011 : {
1012 : (void)threadIndex;
1013 27 : const int32_t ret = AicpuQueueEventProcess::GetInstance().ProcessQsMsg(drvEventInfo);
1014 27 : aicpusd_info(
1015 : "Finish to process queue event qs, event id[%d], threadIndex[%u], ret[%d]", drvEventInfo.comm.event_id,
1016 : threadIndex, ret);
1017 27 : return ret;
1018 : }
1019 :
1020 6 : int32_t AicpuEventManager::ProcDrvEvent(const event_info& drvEventInfo, const uint32_t threadIndex)
1021 : {
1022 : (void)threadIndex;
1023 6 : const int32_t ret = AicpuQueueEventProcess::GetInstance().ProcessDrvMsg(drvEventInfo);
1024 6 : return ret;
1025 : }
1026 :
1027 : /**
1028 : * @ingroup AicpuEventManager
1029 : * @brief it use to process all event.
1030 : * @param [in] drvEventInfo : the event information from ts.
1031 : * @param [in] threadIndex : thread index assign by aicpu index, but when running time they are different.
1032 : * @return AICPU_SCHEDULE_OK: success, other: error code
1033 : */
1034 190 : int32_t AicpuEventManager::ProcessEvent(const event_info& drvEventInfo, const uint32_t threadIndex)
1035 : {
1036 190 : const uint32_t curEventId = drvEventInfo.comm.event_id;
1037 190 : if (curEventId >= EVENT_MAX_NUM) {
1038 1 : aicpusd_err("Unknown event type, event_id[%u].", drvEventInfo.comm.event_id);
1039 1 : return AICPU_SCHEDULE_ERROR_NOT_FOUND_EVENT;
1040 : }
1041 189 : const uint32_t threadid = (threadIndex >= MAX_AICPU_THREAD_NUM) ? 0U : threadIndex;
1042 189 : ++recvEventStat_[threadid][curEventId];
1043 189 : const int32_t ret = (this->*aicpuEventProcFunc_[curEventId])(drvEventInfo, threadIndex);
1044 189 : ++procEventStat_[threadid][curEventId];
1045 189 : return ret;
1046 : }
1047 :
1048 387123 : int32_t AicpuEventManager::DoOnceEsched(const uint32_t threadIndex, const uint32_t deviceId, const int32_t timeout)
1049 : {
1050 : event_info drvEventInfo;
1051 387123 : const int32_t retVal = halEschedWaitEvent(deviceId, groupId_, threadIndex, timeout, &drvEventInfo);
1052 391836 : if (retVal == DRV_ERROR_NONE) {
1053 137 : if (g_aicpuProfiler.GetHiperfSoStatus()) {
1054 137 : g_aicpuProfiler.InitProfiler(getpid(), static_cast<pid_t>(GetTid()));
1055 137 : g_aicpuProfiler.SetProcEventStart();
1056 137 : g_aicpuProfiler.SetEventId(drvEventInfo.comm.event_id);
1057 137 : (void)ProcessEvent(drvEventInfo, threadIndex);
1058 137 : g_aicpuProfiler.SetProcEventEnd();
1059 137 : g_aicpuProfiler.Profiler();
1060 137 : AicpuMsgSend::SendEvent();
1061 : } else {
1062 0 : (void)ProcessEvent(drvEventInfo, threadIndex);
1063 0 : AicpuMsgSend::SendEvent();
1064 : }
1065 391699 : } else if ((retVal == DRV_ERROR_SCHED_WAIT_TIMEOUT) || (retVal == DRV_ERROR_NO_EVENT)) {
1066 : // if timeout, will continue wait event.
1067 4 : } else if ((retVal == DRV_ERROR_SCHED_PROCESS_EXIT) || (retVal == DRV_ERROR_SCHED_PARA_ERR)) {
1068 2 : if (runningFlag_) {
1069 0 : runningFlag_ = false;
1070 : }
1071 2 : aicpusd_warn(
1072 : "Failed to get event, error code=%d, deviceId[%u], groupId[%u], threadIndex[%u]", retVal, deviceId,
1073 : groupId_, threadIndex);
1074 2 : } else if (retVal == DRV_ERROR_SCHED_RUN_IN_ILLEGAL_CPU) {
1075 1 : runningFlag_ = false;
1076 1 : aicpusd_err(
1077 : "Cpu Illegal get event, error code[%d], deviceId[%u], groupId[%u], threadIndex[%u]", retVal, deviceId,
1078 : groupId_, threadIndex);
1079 1 : AicpuMonitor::GetInstance().SendKillMsgToTsd();
1080 : } else {
1081 : // record a error code
1082 1 : aicpusd_err(
1083 : "Failed to get event, error code[%d], deviceId[%u], groupId[%u], threadIndex[%u]", retVal, deviceId,
1084 : groupId_, threadIndex);
1085 : }
1086 391863 : return retVal;
1087 : }
1088 :
1089 3 : int32_t AicpuEventManager::DoOnceMsq(const uint32_t threadIndex, const uint32_t deviceId, const int32_t timeout)
1090 : {
1091 : (void)deviceId;
1092 : (void)timeout;
1093 3 : MsqDatas datas = {};
1094 3 : if (MessageQueue::WaitMsqInfoOnce(datas)) {
1095 3 : event_info drvEventInfo = {};
1096 3 : if (FillEvent(*(PtrToPtr<MsqDatas, AicpuTopicMailbox>(&datas)), drvEventInfo) != AICPU_SCHEDULE_OK) {
1097 : // if the PID is 0, it indicates an AICPU rescue op, directly return success.
1098 1 : hwts_response_t resp = {};
1099 1 : resp.result = 0U;
1100 1 : resp.status = 0U;
1101 1 : (void)ResponseMsq(0U, 0U, resp);
1102 1 : return AICPU_SCHEDULE_OK;
1103 : }
1104 2 : const int32_t ret = ProcessEvent(drvEventInfo, threadIndex);
1105 2 : hwts_response_t resp = {};
1106 2 : resp.result = static_cast<uint32_t>(AicpuUtil::TransformInnerErrCode(ret));
1107 2 : resp.status = (ret == AICPU_SCHEDULE_OK) ? static_cast<uint32_t>(TASK_SUCC) : static_cast<uint32_t>(TASK_FAIL);
1108 2 : (void)ResponseMsq(0U, 0U, resp);
1109 : }
1110 :
1111 2 : return AICPU_SCHEDULE_OK;
1112 : }
1113 :
1114 9 : int32_t AicpuEventManager::ResponseMsq(const uint32_t deviceId, const uint32_t subEventId, hwts_response_t& resp) const
1115 : {
1116 : (void)deviceId;
1117 : (void)subEventId;
1118 9 : if (MessageQueue::IsMsqRspComplete()) {
1119 1 : aicpusd_info("msq already response complete, skip send response");
1120 1 : return AICPU_SCHEDULE_OK;
1121 : }
1122 8 : MessageQueue::SendResponse(resp.result, resp.status);
1123 8 : return AICPU_SCHEDULE_OK;
1124 : }
1125 :
1126 113 : int32_t AicpuEventManager::ResponseEsched(
1127 : const uint32_t deviceId, const uint32_t subEventId, hwts_response_t& resp) const
1128 : {
1129 113 : return halEschedAckEvent(
1130 : deviceId, EVENT_TS_HWTS_KERNEL, subEventId, PtrToPtr<hwts_response_t, char_t>(&resp),
1131 123 : static_cast<uint32_t>(sizeof(hwts_response_t)));
1132 : }
1133 :
1134 5 : int32_t AicpuEventManager::FillEvent(const AicpuTopicMailbox& mb, event_info& eventInfo) const
1135 : {
1136 5 : (void)FillEventCommInfo(mb, eventInfo);
1137 :
1138 5 : if ((mb.topicId == EVENT_TS_HWTS_KERNEL) && (mb.kernelType != AICPU_TOPIC_DEFAULT_KERNEL_TYPE)) {
1139 2 : return FillEventPrivHwtsInfo(mb, eventInfo);
1140 : } else {
1141 3 : (void)FillEventPrivCommInfo(mb, eventInfo);
1142 : }
1143 :
1144 3 : return AICPU_SCHEDULE_OK;
1145 : }
1146 :
1147 5 : int32_t AicpuEventManager::FillEventCommInfo(const AicpuTopicMailbox& mb, event_info& eventInfo) const
1148 : {
1149 5 : const uint64_t timeStamp = GetCurrentTime();
1150 5 : eventInfo.comm.event_id = static_cast<EVENT_ID>(mb.topicId);
1151 5 : eventInfo.comm.subevent_id = mb.subtopicId;
1152 5 : eventInfo.comm.pid = mb.pid;
1153 5 : eventInfo.comm.host_pid = AicpuDrvManager::GetInstance().GetHostPid();
1154 5 : eventInfo.comm.grp_id = mb.gid;
1155 5 : eventInfo.comm.submit_timestamp = timeStamp;
1156 5 : eventInfo.comm.sched_timestamp = timeStamp;
1157 :
1158 5 : return AICPU_SCHEDULE_OK;
1159 : }
1160 :
1161 2 : int32_t AicpuEventManager::FillEventPrivHwtsInfo(const AicpuTopicMailbox& mb, event_info& eventInfo) const
1162 : {
1163 2 : if (mb.pid == 0U) {
1164 1 : aicpusd_run_info("Receive rescue aicpu op, start send response.");
1165 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
1166 : }
1167 :
1168 : static std::atomic<uint64_t> serialNo(0UL);
1169 1 : const AicpuHwtsTaskInfo* const rtsTask = PtrToPtr<const uint32_t, const AicpuHwtsTaskInfo>(mb.userData);
1170 1 : hwts_ts_task* task = PtrToPtr<char, hwts_ts_task>(eventInfo.priv.msg);
1171 1 : task->mailbox_id = mb.mailboxId;
1172 1 : task->kernel_info.pid = mb.pid;
1173 1 : task->serial_no = serialNo;
1174 1 : task->kernel_info.kernel_type = mb.kernelType;
1175 1 : task->kernel_info.batchMode = mb.batchMode;
1176 1 : task->kernel_info.satMode = mb.satMode;
1177 1 : task->kernel_info.rspMode = mb.rspMode;
1178 1 : task->kernel_info.streamID = mb.streamId;
1179 1 : task->kernel_info.kernelName = rtsTask->taskNamePtr;
1180 1 : task->kernel_info.kernelSo = rtsTask->taskSoNamePtr;
1181 1 : task->kernel_info.paramBase = rtsTask->paraPtr;
1182 1 : task->kernel_info.l2Ctrl = rtsTask->l2StructPtr;
1183 1 : task->kernel_info.l2VaddrBase = 0ULL;
1184 1 : task->kernel_info.blockId = mb.blkId;
1185 1 : task->kernel_info.blockNum = mb.blkDim;
1186 1 : task->kernel_info.l2InMain = 0U;
1187 1 : task->kernel_info.taskID = rtsTask->extraFieldPtr;
1188 :
1189 1 : eventInfo.priv.msg_len = static_cast<uint32_t>(sizeof(hwts_ts_task));
1190 :
1191 1 : serialNo++;
1192 :
1193 1 : return AICPU_SCHEDULE_OK;
1194 : }
1195 :
1196 3 : int32_t AicpuEventManager::FillEventPrivCommInfo(const AicpuTopicMailbox& mb, event_info& eventInfo) const
1197 : {
1198 3 : const uint32_t userDataLen = std::min(static_cast<uint32_t>(mb.userDataLen), AICPU_TOPIC_USER_DATA_PAYLOAD_LEN);
1199 : const int32_t ret =
1200 3 : memcpy_s(eventInfo.priv.msg, EVENT_MAX_MSG_LEN, &mb.userData[0], static_cast<uint64_t>(userDataLen));
1201 3 : if (ret != AICPU_SCHEDULE_OK) {
1202 1 : aicpusd_err(
1203 : "Failed to copy event msg, eventId=%u, subEventId=%u, max=%d, userDataLen=%u", mb.topicId, mb.subtopicId,
1204 : EVENT_MAX_MSG_LEN, userDataLen);
1205 1 : return AICPU_SCHEDULE_ERROR_SAFE_FUNCTION_ERR;
1206 : }
1207 :
1208 2 : eventInfo.priv.msg_len = userDataLen;
1209 :
1210 2 : return AICPU_SCHEDULE_OK;
1211 : }
1212 :
1213 : /**
1214 : * @ingroup AicpuEventManager
1215 : * @param [in] threadIndex : thread index assign by aicpu index, but when running time they are different.
1216 : * @brief it is used in multi-thread.
1217 : */
1218 13 : void AicpuEventManager::LoopProcess(const uint32_t threadIndex)
1219 : {
1220 13 : const uint32_t deviceId = AicpuDrvManager::GetInstance().GetDeviceId();
1221 390332 : while (runningFlag_) {
1222 388332 : (void)DoOnce(threadIndex, deviceId);
1223 : }
1224 1 : aicpusd_info("The loop of getting event is exit in thread[%u].", threadIndex);
1225 1 : }
1226 :
1227 2 : bool AicpuEventManager::ModelLoopTimeOut(const int32_t retVal, uint32_t& waitCounter, const uint32_t maxCounter)
1228 : {
1229 2 : if (retVal == DRV_ERROR_NONE) {
1230 1 : waitCounter = 0U;
1231 1 : } else if (++waitCounter >= maxCounter) {
1232 1 : return true;
1233 : }
1234 1 : return false;
1235 : }
1236 : /**
1237 : * @ingroup AicpuEventManager
1238 : * @brief it is used in call model, which is used in different thread need different while loop variable.
1239 : */
1240 4 : void AicpuEventManager::CallModeLoopProcess()
1241 : {
1242 4 : g_runningThreadFlag = true;
1243 4 : const uint32_t deviceId = AicpuDrvManager::GetInstance().GetDeviceId();
1244 4 : uint32_t waitCounter = 0U;
1245 4 : while (g_runningThreadFlag) {
1246 4 : const int32_t retVal = DoOnce(0U, deviceId);
1247 4 : const bool timeoutFlag = ModelLoopTimeOut(retVal, waitCounter, TIMEOUT_LOOP_MAX_INTERVAL);
1248 4 : if (timeoutFlag) {
1249 4 : g_runningThreadFlag = false;
1250 4 : break;
1251 : }
1252 : }
1253 4 : aicpusd_info("The loop of getting event is exit in call mode.");
1254 4 : }
1255 :
1256 87 : void AicpuEventManager::SetRunningFlag(const bool runningFlag) { runningFlag_ = runningFlag; }
1257 :
1258 1 : int32_t AicpuEventManager::ProcProxyEvent(const event_info& drvEventInfo, const uint32_t threadIndex)
1259 : {
1260 : (void)threadIndex;
1261 1 : const int32_t ret = AicpuQueueEventProcess::GetInstance().ProcessProxyMsg(drvEventInfo);
1262 1 : return ret;
1263 : }
1264 : } // namespace AicpuSchedule
|