LCOV - code coverage report
Current view: top level - aicpu_schedule/core/dfx - aicpusd_cust_dump_process.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 86.3 % 285 246
Test Date: 2026-07-28 10:54:05 Functions: 100.0 % 18 18

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

Generated by: LCOV version 2.0-1