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