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_cust_dump_process.h"
11 :
12 : #include <string>
13 : #include <sched.h>
14 : #include <semaphore.h>
15 : #include "aicpusd_drv_manager.h"
16 : #include "aicpusd_info.h"
17 : #include "aicpusd_util.h"
18 : #include "aicpusd_proc_mgr_sys_operator_agent.h"
19 : #include "aicpusd_interface_process.h"
20 : #include "type_def.h"
21 : #include "dump_task.h"
22 : #include "aicpusd_sqe_adapter.h"
23 :
24 : namespace AicpuSchedule {
25 : namespace {
26 : // aicpusd 与 custaicpusd 是同样的groupid
27 : constexpr const uint32_t DATA_DUMP_GRUOP_ID = 31U;
28 : constexpr const uint32_t DATA_DUMP_THREAD_INDEX = 0U;
29 : constexpr const uint64_t DATA_DUMP_EVENT_MASK = (1ULL << static_cast<uint32_t>(EVENT_CCPU_CTRL_MSG));
30 : constexpr const int32_t DATA_DUMP_TIMEOUT_INTERVAL = 3000;
31 : constexpr const uint32_t SLEEP_USECS = 50000U;
32 : }; // namespace
33 :
34 80 : AicpuSdCustDumpProcess& AicpuSdCustDumpProcess::GetInstance()
35 : {
36 80 : static AicpuSdCustDumpProcess instance;
37 80 : return instance;
38 : }
39 :
40 2 : AicpuSdCustDumpProcess::~AicpuSdCustDumpProcess() { UnitCustDataDumpProcess(); }
41 :
42 2 : AicpuSdCustDumpProcess::AicpuSdCustDumpProcess() : deviceId_(0U), runningFlag_(false), initFlag_(false) {}
43 :
44 10 : int32_t AicpuSdCustDumpProcess::InitCustDumpProcess(const uint32_t deviceId, const aicpu::AicpuRunMode runMode)
45 : {
46 10 : if (runMode != aicpu::AicpuRunMode::PROCESS_PCIE_MODE) {
47 8 : aicpusd_info("not pcie mode no need this thread");
48 8 : return AICPU_SCHEDULE_OK;
49 : }
50 2 : const std::lock_guard<std::mutex> lk(initMutex_);
51 2 : if (initFlag_) {
52 1 : aicpusd_info("already init before");
53 1 : return AICPU_SCHEDULE_OK;
54 : }
55 1 : initFlag_ = true;
56 1 : deviceId_ = deviceId;
57 1 : runningFlag_ = true;
58 1 : const int32_t semRet = sem_init(&workerSme_, 0, 0U);
59 1 : if (semRet == -1) {
60 1 : aicpusd_err("workerSme_ init failed, %s", strerror(errno));
61 1 : return AICPU_SCHEDULE_ERROR_INIT_FAILED;
62 : }
63 :
64 : try {
65 0 : msgThread_ = std::thread(&AicpuSdCustDumpProcess::StartProcessEvent, this);
66 0 : } catch (std::exception& e) {
67 0 : aicpusd_err("create thread file:%s", e.what());
68 0 : return AICPU_SCHEDULE_ERROR_INIT_FAILED;
69 0 : }
70 0 : const int32_t semWaitRet = sem_wait(&workerSme_);
71 0 : if (semWaitRet == -1) {
72 0 : aicpusd_err("workerSme wait failed, %s", strerror(errno));
73 0 : return AICPU_SCHEDULE_ERROR_INIT_FAILED;
74 : }
75 0 : return AICPU_SCHEDULE_OK;
76 2 : }
77 :
78 7 : int32_t AicpuSdCustDumpProcess::SetDataDumpThreadAffinity() const
79 : {
80 7 : std::vector<uint32_t> ccpuIds = AicpuDrvManager::GetInstance().GetCcpuList();
81 7 : if (ccpuIds.empty()) {
82 0 : aicpusd_run_info("ccpu list is empty no need bind core");
83 0 : return AICPU_SCHEDULE_OK;
84 : }
85 14 : if (AicpuUtil::IsEnvValEqual(ENV_NAME_PROCMGR_AICPU_CPUSET, "1")) {
86 2 : uint32_t tryTimes = 0;
87 2 : const pid_t tid = static_cast<pid_t>(GetTid());
88 2 : auto ret = ProcMgrBindThread(tid, ccpuIds);
89 4 : while ((ret != 0U) && (tryTimes <= 1)) {
90 2 : aicpusd_warn("set affinity failed ret[%d], will try again", ret);
91 2 : (void)usleep(SLEEP_USECS);
92 2 : ret = ProcMgrBindThread(tid, ccpuIds);
93 2 : tryTimes++;
94 : }
95 2 : if (ret != 0) {
96 1 : aicpusd_err("aicpu bind tid by pm res[%d].", ret);
97 1 : return AICPU_SCHEDULE_ERROR_INNER_ERROR;
98 : } else {
99 1 : aicpusd_run_info("aicpu bind by pm success");
100 1 : return AICPU_SCHEDULE_OK;
101 : }
102 : } else {
103 5 : pthread_t threadId = pthread_self();
104 : cpu_set_t cpuset;
105 5 : CPU_ZERO(&cpuset);
106 25 : for (const auto cpuId : ccpuIds) {
107 20 : CPU_SET(cpuId, &cpuset);
108 20 : aicpusd_info("prepare bind threadId=%lu to cpuId=%u", threadId, static_cast<uint32_t>(cpuId));
109 : }
110 5 : const int32_t ret = pthread_setaffinity_np(threadId, sizeof(cpu_set_t), &cpuset);
111 5 : if (ret != 0) {
112 1 : aicpusd_run_warn(
113 : "Binding datadump thread to control CPU was not successful, will run in aicpu. ret=%d, reason=%s", ret,
114 : strerror(errno));
115 : } else {
116 4 : aicpusd_run_info("aicpu bind by self success");
117 : }
118 : }
119 :
120 5 : return AICPU_SCHEDULE_OK;
121 7 : }
122 :
123 4 : void AicpuSdCustDumpProcess::StartProcessEvent()
124 : {
125 4 : int32_t ret = halEschedCreateGrp(deviceId_, DATA_DUMP_GRUOP_ID, GRP_TYPE_BIND_CP_CPU);
126 4 : if (ret != DRV_ERROR_NONE) {
127 1 : aicpusd_err(
128 : "halEschedCreateGrp dev[%u] group[%u] type[%d] failed, result[%d].", deviceId_, DATA_DUMP_GRUOP_ID,
129 : GRP_TYPE_BIND_CP_CPU, ret);
130 1 : sem_post(&workerSme_);
131 1 : return;
132 : }
133 :
134 3 : if (SetDataDumpThreadAffinity() != AICPU_SCHEDULE_OK) {
135 1 : aicpusd_err("datadump thread bind core failed.");
136 1 : sem_post(&workerSme_);
137 1 : return;
138 : }
139 2 : ret = halEschedSubscribeEvent(deviceId_, DATA_DUMP_GRUOP_ID, DATA_DUMP_THREAD_INDEX, DATA_DUMP_EVENT_MASK);
140 2 : if (ret != DRV_ERROR_NONE) {
141 1 : aicpusd_err(
142 : "halEschedSubscribeEvent failed, deviceId[%u], groupId[%u], threadIndex[%u]", deviceId_, DATA_DUMP_GRUOP_ID,
143 : DATA_DUMP_THREAD_INDEX);
144 1 : sem_post(&workerSme_);
145 1 : return;
146 : }
147 1 : ProcessMessage(0U);
148 1 : sem_post(&workerSme_);
149 1 : aicpusd_run_info("post work sem finish, dump process init finish. deviceId[%u]", deviceId_);
150 1 : LoopProcessEvent();
151 1 : aicpusd_run_info("dump thread stopped.");
152 : }
153 :
154 1 : void AicpuSdCustDumpProcess::LoopProcessEvent()
155 : {
156 2 : while (runningFlag_) {
157 1 : ProcessMessage(DATA_DUMP_TIMEOUT_INTERVAL);
158 : }
159 1 : }
160 :
161 6 : int32_t AicpuSdCustDumpProcess::ProcessMessage(const int32_t timeout)
162 : {
163 : event_info drvEventInfo;
164 : const int32_t retVal =
165 6 : halEschedWaitEvent(deviceId_, DATA_DUMP_GRUOP_ID, DATA_DUMP_THREAD_INDEX, timeout, &drvEventInfo);
166 6 : if (retVal == DRV_ERROR_NONE) {
167 1 : (void)DatadumpTaskProcess(drvEventInfo);
168 5 : } else if ((retVal == DRV_ERROR_SCHED_WAIT_TIMEOUT) || (retVal == DRV_ERROR_NO_EVENT)) {
169 : // if timeout, will continue wait event.
170 5 : } else if ((retVal == DRV_ERROR_SCHED_PROCESS_EXIT) || (retVal == DRV_ERROR_SCHED_PARA_ERR)) {
171 3 : if (runningFlag_) {
172 1 : runningFlag_ = false;
173 : }
174 3 : aicpusd_warn(
175 : "Failed to get event, error code=%d, deviceId[%u], groupId[%u], threadIndex[%u]", retVal, deviceId_,
176 : DATA_DUMP_GRUOP_ID, DATA_DUMP_THREAD_INDEX);
177 2 : } else if (retVal == DRV_ERROR_SCHED_RUN_IN_ILLEGAL_CPU) {
178 1 : runningFlag_ = false;
179 1 : aicpusd_err(
180 : "Cpu Illegal get event, error code[%d], deviceId[%u], groupId[%u], threadIndex[%u]", retVal, deviceId_,
181 : DATA_DUMP_GRUOP_ID, DATA_DUMP_THREAD_INDEX);
182 : } else {
183 : // record a error code
184 1 : aicpusd_err(
185 : "Failed to get event, error code[%d], deviceId[%u], groupId[%u], threadIndex[%u]", retVal, deviceId_,
186 : DATA_DUMP_GRUOP_ID, DATA_DUMP_THREAD_INDEX);
187 : }
188 6 : return retVal;
189 : }
190 :
191 28 : void AicpuSdCustDumpProcess::UnitCustDataDumpProcess()
192 : {
193 28 : aicpusd_info("UnitCustDataDumpProcess start");
194 28 : const std::lock_guard<std::mutex> lk(initMutex_);
195 28 : if (!initFlag_) {
196 26 : aicpusd_info("already uninit no need uninit");
197 26 : return;
198 : }
199 2 : runningFlag_ = false;
200 2 : initFlag_ = false;
201 2 : aicpusd_info("sem post finish");
202 2 : if (msgThread_.joinable()) {
203 0 : msgThread_.join();
204 : }
205 2 : aicpusd_info("UnitCustDataDumpProcess finish");
206 28 : }
207 :
208 5 : int32_t AicpuSdCustDumpProcess::DoCustDatadumpTask(const event_info& drvEventInfo) const
209 : {
210 5 : if (static_cast<size_t>(drvEventInfo.priv.msg_len) != sizeof(AICPUDumpCustInfo)) {
211 2 : aicpusd_err("The len[%u] is not correct[%zu].", drvEventInfo.priv.msg_len, sizeof(AICPUDumpCustInfo));
212 2 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
213 : }
214 3 : if (drvEventInfo.comm.subevent_id != static_cast<uint32_t>(AICPU_SUB_EVENT_REPORT_CUST_DUMPDATA)) {
215 1 : aicpusd_err("invalid event id:%u", drvEventInfo.comm.subevent_id);
216 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
217 : }
218 2 : if (!IsValidCustAicpu(drvEventInfo.comm.host_pid)) {
219 0 : aicpusd_err("invalid sender pid:%d", drvEventInfo.comm.host_pid);
220 0 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
221 : }
222 2 : const AICPUDumpCustInfo* const info = PtrToPtr<const char_t, const AICPUDumpCustInfo>(drvEventInfo.priv.msg);
223 : // version 1 the stream id of dump key is invalid(65535)
224 : // but ack stream id need keep stream id form event info.
225 2 : const uint32_t ackStreamId = info->streamId;
226 2 : uint32_t streamId = info->streamId;
227 2 : const uint32_t taskId = info->taskId;
228 2 : const uint32_t threadIndex = info->threadIndex;
229 2 : const uint32_t devId = deviceId_;
230 2 : const int32_t custPid = AicpuScheduleInterface::GetInstance().GetAicpuCustSdProcId();
231 2 : if (FeatureCtrl::GetTsMsgVersion() == AicpuSqeAdapter::VERSION_1) {
232 0 : streamId = AicpuSqeAdapter::INVALID_VALUE16;
233 : }
234 2 : aicpusd_info(
235 : "begin cust data dump streamid:%u, taskid:%u, threadindex:%u, custpid:%d, ackStreamId:%u", streamId, taskId,
236 : threadIndex, custPid, ackStreamId);
237 2 : OpDumpTaskManager& opDumpTaskMgr = OpDumpTaskManager::GetInstance();
238 2 : (void)opDumpTaskMgr.SetCustDumpTaskFlag(streamId, taskId, true);
239 2 : const int32_t dumpRet = opDumpTaskMgr.DumpOpInfo(streamId, taskId, INVALID_VAL, INVALID_VAL);
240 2 : if (dumpRet != AICPU_SCHEDULE_OK) {
241 0 : aicpusd_err(
242 : "cust data dump error streamid:%u, taskid:%u, threadindex:%u, custpid:%d", streamId, taskId, threadIndex,
243 : custPid);
244 : }
245 2 : event_summary dataDumpEvent = {};
246 : AICPUDumpCustInfo rspInfo;
247 2 : rspInfo.retCode = dumpRet;
248 2 : rspInfo.streamId = ackStreamId;
249 2 : rspInfo.taskId = taskId;
250 2 : rspInfo.threadIndex = threadIndex;
251 2 : dataDumpEvent.msg = PtrToPtr<AICPUDumpCustInfo, char_t>(&rspInfo);
252 2 : dataDumpEvent.msg_len = static_cast<uint32_t>(sizeof(rspInfo));
253 2 : dataDumpEvent.dst_engine = CCPU_DEVICE;
254 2 : dataDumpEvent.policy = ONLY;
255 2 : dataDumpEvent.pid = custPid;
256 2 : dataDumpEvent.grp_id = DATA_DUMP_GRUOP_ID;
257 2 : dataDumpEvent.event_id = EVENT_CCPU_CTRL_MSG;
258 2 : dataDumpEvent.subevent_id = AICPU_SUB_EVENT_REPORT_CUST_DUMPDATA;
259 2 : const auto drvRet = halEschedSubmitEvent(devId, &dataDumpEvent);
260 2 : if (drvRet != DRV_ERROR_NONE) {
261 1 : aicpusd_err("ERROR failed to dump event, result[%d], devId[%u]", static_cast<int32_t>(drvRet), devId);
262 1 : return AICPU_SCHEDULE_ERROR_DUMP_FAILED;
263 : }
264 1 : aicpusd_info(
265 : "sendback dump event to streamid[%u], taskid[%u], custpid[%d], devId[%u]", streamId, taskId, custPid, devId);
266 1 : return AICPU_SCHEDULE_OK;
267 : }
268 :
269 10 : int32_t AicpuSdCustDumpProcess::DoUdfDatadumpSubmitEventSync(
270 : const char_t* const msg, const uint32_t len, struct event_proc_result& rsp) const
271 : {
272 10 : uint32_t headLen = sizeof(struct event_sync_msg);
273 10 : if (len < headLen) {
274 1 : aicpusd_err("len[%u], headLen[%u].", len, headLen);
275 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
276 : }
277 9 : struct event_sync_msg msgHead = {};
278 9 : auto ret = memcpy_s(&msgHead, headLen, msg, headLen);
279 9 : if (ret != 0) {
280 1 : aicpusd_err("Memcpy failed. ret[%d], size[%u].", ret, headLen);
281 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
282 : }
283 8 : struct event_summary backEvent = {};
284 :
285 8 : backEvent.dst_engine = msgHead.dst_engine;
286 8 : backEvent.policy = ONLY;
287 8 : backEvent.pid = msgHead.pid;
288 8 : backEvent.grp_id = msgHead.gid;
289 8 : backEvent.event_id = static_cast<EVENT_ID>(msgHead.event_id);
290 8 : backEvent.subevent_id = msgHead.subevent_id;
291 8 : backEvent.msg_len = sizeof(struct event_proc_result);
292 8 : backEvent.msg = PtrToPtr<struct event_proc_result, char_t>(&rsp);
293 8 : const uint32_t deviceId = deviceId_;
294 8 : ret = halEschedSubmitEvent(deviceId, &backEvent);
295 8 : aicpusd_info(
296 : "backEvent dst[%d], pid[%d], grpId[%d], eventId[%d], subeventId[%d], msgLen[%d], deviceId[%u]",
297 : backEvent.dst_engine, backEvent.pid, backEvent.grp_id, backEvent.event_id, backEvent.subevent_id,
298 : backEvent.msg_len, deviceId);
299 8 : if (ret != 0) {
300 4 : aicpusd_err(
301 : "halEschedSubmitEvent, ret=%d. dst[%d],pid[%d],"
302 : " grpId[%d], eventId[%d], subeventId[%d], msgLen[%d], deviceId[%u]",
303 : ret, backEvent.dst_engine, backEvent.pid, backEvent.grp_id, backEvent.event_id, backEvent.subevent_id,
304 : backEvent.msg_len, deviceId);
305 4 : return ret;
306 : }
307 4 : return AICPU_SCHEDULE_OK;
308 : }
309 9 : int32_t AicpuSdCustDumpProcess::DoUdfDatadumpTask(const event_info& drvEventInfo) const
310 : {
311 9 : uint32_t headLen = sizeof(struct event_sync_msg);
312 9 : aicpusd_info(
313 : "event id[%u], headLen[%u], msg len[%u] udfInfo len[%u]", drvEventInfo.comm.subevent_id, headLen,
314 : static_cast<size_t>(drvEventInfo.priv.msg_len), sizeof(AICPUDumpUdfInfo));
315 9 : if (static_cast<size_t>(drvEventInfo.priv.msg_len) != (sizeof(AICPUDumpUdfInfo) + headLen)) {
316 2 : aicpusd_err(
317 : "The len[%u] is not correct[%u + %u].", drvEventInfo.priv.msg_len, sizeof(AICPUDumpUdfInfo), headLen);
318 2 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
319 : }
320 7 : if (!IsValidUdf(drvEventInfo.comm.host_pid)) {
321 0 : aicpusd_err("invalid sender pid:%d", drvEventInfo.comm.host_pid);
322 0 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
323 : }
324 7 : char msg[EVENT_MAX_MSG_LEN] = {};
325 7 : int32_t len = sizeof(char) * EVENT_MAX_MSG_LEN - headLen;
326 7 : int32_t rLen = drvEventInfo.priv.msg_len - headLen;
327 7 : int32_t ret = memcpy_s(msg, len, (drvEventInfo.priv.msg + headLen), rLen);
328 7 : if (ret != 0) {
329 1 : aicpusd_err("Memcpy failed. ret[%d] len[%d], rlen[%d]", ret, len, rLen);
330 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
331 : }
332 :
333 6 : const AICPUDumpUdfInfo* const info = PtrToPtr<const char_t, const AICPUDumpUdfInfo>(msg);
334 6 : uint8_t* dumpInfo = PtrToPtr<void, uint8_t>(ValueToPtr(info->udfInfo));
335 6 : uint64_t length = info->length;
336 6 : uint32_t udfPid = info->udfPid;
337 : UNUSED(udfPid);
338 6 : aicpusd_info(
339 : "udf data dump begin dumpInfo[%p], length[%llu], info->udfInfo[%llu], udfPid[%d]", dumpInfo, length,
340 : info->udfInfo, udfPid);
341 6 : const int32_t hostPid = static_cast<int32_t>(AicpuSchedule::AicpuDrvManager::GetInstance().GetHostPid());
342 6 : const uint32_t deviceId = deviceId_;
343 6 : std::shared_ptr<OpDumpTask> opDumpTaskPtr = nullptr;
344 6 : DATADUMP_MAKE_SHARED(
345 : opDumpTaskPtr = std::make_shared<OpDumpTask>(hostPid, deviceId), return AICPU_SCHEDULE_ERROR_DUMP_FAILED);
346 6 : ret = opDumpTaskPtr->PreProcessUdfOpMappingInfo(dumpInfo, length);
347 :
348 6 : struct event_proc_result rsp = {};
349 6 : rsp.ret = ret;
350 6 : ret = DoUdfDatadumpSubmitEventSync(drvEventInfo.priv.msg, drvEventInfo.priv.msg_len, rsp);
351 6 : if (ret != 0) {
352 3 : aicpusd_err("DoUdfDatadumpSubmitEventSync failed, ret[%d], deviceId[%u]", ret, deviceId);
353 3 : return AICPU_SCHEDULE_ERROR_DUMP_FAILED;
354 : }
355 3 : aicpusd_info(
356 : "udf data dump finish dumpInfo[%p], length[%lld], udfPid[%d], deviceId[%u]", dumpInfo, length, udfPid,
357 : deviceId);
358 3 : return AICPU_SCHEDULE_OK;
359 6 : }
360 1 : int32_t AicpuSdCustDumpProcess::DatadumpTaskProcess(const event_info& drvEventInfo) const
361 : {
362 1 : const uint32_t subEventId = drvEventInfo.comm.subevent_id;
363 1 : if (subEventId == static_cast<uint32_t>(AICPU_SUB_EVENT_REPORT_UDF_DUMPDATA)) {
364 0 : return DoUdfDatadumpTask(drvEventInfo);
365 1 : } else if (subEventId == static_cast<uint32_t>(AICPU_SUB_EVENT_REPORT_CUST_DUMPDATA)) {
366 0 : return DoCustDatadumpTask(drvEventInfo);
367 : }
368 1 : aicpusd_err("invalid event id:%u", subEventId);
369 1 : return AICPU_SCHEDULE_OK;
370 : }
371 3 : void AicpuSdCustDumpProcess::GetCustDumpProcessInitFlag(bool& flag)
372 : {
373 3 : const std::lock_guard<std::mutex> lk(initMutex_);
374 3 : flag = initFlag_;
375 3 : }
376 :
377 6 : int32_t AicpuSdCustDumpProcess::CreateUdfDatadumpThread(const char_t* msg, const uint32_t len)
378 : {
379 6 : aicpusd_info("create udf dump thread.");
380 6 : uint32_t runMode = 0;
381 6 : int32_t ret = 0;
382 6 : const aicpu::status_t status = aicpu::GetAicpuRunMode(runMode);
383 6 : if (status != aicpu::AICPU_ERROR_NONE) {
384 0 : aicpusd_err("Get current aicpu ctx failed.");
385 0 : return AICPU_SCHEDULE_ERROR_INNER_ERROR;
386 : }
387 6 : const uint32_t deviceId = AicpuDrvManager::GetInstance().GetDeviceId();
388 6 : ret = InitCustDumpProcess(deviceId, static_cast<aicpu::AicpuRunMode>(runMode));
389 6 : if (ret != 0) {
390 2 : aicpusd_err("InitCustDumpProcess failed.");
391 2 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
392 : }
393 4 : struct event_proc_result rsp = {};
394 4 : rsp.ret = ret;
395 4 : ret = DoUdfDatadumpSubmitEventSync(msg, len, rsp);
396 4 : if (ret != 0) {
397 3 : aicpusd_err("DoUdfDatadumpSubmitEventSync failed, ret[%d]", ret);
398 3 : return AICPU_SCHEDULE_ERROR_DUMP_FAILED;
399 : }
400 1 : aicpusd_info("create udf dump thread finish.");
401 1 : return AICPU_SCHEDULE_OK;
402 : }
403 :
404 7 : bool AicpuSdCustDumpProcess::IsValidUdf(const int32_t sendPid) const
405 : {
406 7 : if (!FeatureCtrl::IfCheckEventSender()) {
407 7 : return true;
408 : }
409 0 : unsigned int hostpid = 0;
410 0 : unsigned int cpType = DEVDRV_PROCESS_CPTYPE_MAX;
411 0 : auto ret = drvQueryProcessHostPid(sendPid, nullptr, nullptr, &hostpid, &cpType);
412 0 : if (ret != DRV_ERROR_NONE) {
413 0 : aicpusd_err("query host pid failed pid:%d, ret:%d", sendPid, ret);
414 0 : return false;
415 : }
416 0 : const int32_t curHostPid = AicpuDrvManager::GetInstance().GetHostPid();
417 0 : if (hostpid == static_cast<unsigned int>(curHostPid)) {
418 0 : return true;
419 : }
420 0 : aicpusd_err("invalid sender pid:%d, query hostpid:%d, curHostPid:%d", sendPid, hostpid, curHostPid);
421 0 : return false;
422 : }
423 :
424 2 : bool AicpuSdCustDumpProcess::IsValidCustAicpu(const int32_t sendPid) const
425 : {
426 2 : if (!FeatureCtrl::IfCheckEventSender()) {
427 2 : return true;
428 : }
429 0 : const int32_t custPid = AicpuScheduleInterface::GetInstance().GetAicpuCustSdProcId();
430 0 : if (sendPid == custPid) {
431 0 : return true;
432 : }
433 0 : aicpusd_err("invalid sender pid:%d, custpid:%d", sendPid, custPid);
434 0 : return false;
435 : }
436 : } // namespace AicpuSchedule
437 3 : int32_t CreateDatadumpThread(const struct TsdSubEventInfo* const msg)
438 : {
439 3 : char message[EVENT_MAX_MSG_LEN] = {};
440 3 : auto ret = memcpy_s(message, EVENT_MAX_MSG_LEN, msg, sizeof(struct TsdSubEventInfo));
441 3 : if (ret != 0) {
442 1 : aicpusd_err("Memcpy failed. ret[%d], size[%zu].", ret, sizeof(struct TsdSubEventInfo));
443 1 : return AicpuSchedule::AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
444 : }
445 2 : return AicpuSchedule::AicpuSdCustDumpProcess::GetInstance().CreateUdfDatadumpThread(message, EVENT_MAX_MSG_LEN);
446 : }
|