LCOV - code coverage report
Current view: top level - aicpu_schedule/core/hwts_kernel - hwts_kernel_dfx.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 83.3 % 72 60
Test Date: 2026-08-12 11:05:02 Functions: 100.0 % 4 4

            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              : 
      11              : #include "hwts_kernel_dfx.h"
      12              : 
      13              : #include "aicpu_context.h"
      14              : #include "aicpu_prof.h"
      15              : #include "aicpusd_profiler.h"
      16              : #include "profiling_adp.h"
      17              : #include "aicpusd_monitor.h"
      18              : #include "aicpusd_threads_process.h"
      19              : #include "aicpusd_hal_interface_ref.h"
      20              : #include "tsd.h"
      21              : #include "aicpusd_drv_manager.h"
      22              : #include "aicpusd_model_err_process.h"
      23              : #include "dump_task.h"
      24              : #include "hwts_kernel_common.h"
      25              : 
      26              : namespace AicpuSchedule {
      27              : namespace {
      28              : const std::string CFG_LOG_ADDR = "CfgLogAddr";
      29              : const std::string DUMP_DATA_INFO = "DumpDataInfo";
      30              : const std::string SET_AICPU_DFX = "SetAicpuDfx";
      31              : constexpr uint32_t CUSTOM_CP_CCPU_GROUP_ID = 31U;
      32              : 
      33              : enum class DfxCpType : uint8_t {
      34              :     AICPUSD = 0,        /* aicpusd */
      35              :     CUSTOM_AICPUSD = 1, /* custom_aicpusd */
      36              : };
      37              : } // namespace
      38              : 
      39            1 : int32_t CfgLogAddrTsKernel::Compute(const aicpu::HwtsTsKernel& tsKernelInfo)
      40              : {
      41            1 :     aicpusd_info("Begin to process ts kernel CfgLogAddr event.");
      42            1 :     const auto cfgMsg = PtrToPtr<void, aicpu::AicpuConfigMsg>(ValueToPtr(tsKernelInfo.kernelBase.cceKernel.paramBase));
      43            1 :     if (cfgMsg == nullptr) {
      44            0 :         aicpusd_err("param base for config log is null.");
      45            0 :         return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
      46              :     }
      47              : 
      48            1 :     AicpuModelErrProc::GetInstance().ProcessLogBuffCfgMsg(*cfgMsg);
      49            1 :     return AICPU_SCHEDULE_OK;
      50              : }
      51              : 
      52            8 : int32_t DumpDataInfoTsKernel::Compute(const aicpu::HwtsTsKernel& tsKernelInfo)
      53              : {
      54            8 :     aicpusd_info("Begin to process ts kernel dump data event");
      55            8 :     const aicpu::HwtsCceKernel& kernel = tsKernelInfo.kernelBase.cceKernel;
      56              :     // dump op has two param, one is protobuf addr
      57            8 :     constexpr uint32_t singleOpDumpParamNum = 2U;
      58            8 :     constexpr size_t len = sizeof(aicpu::AicpuParamHead) + (singleOpDumpParamNum * sizeof(uint64_t));
      59            8 :     const aicpu::AicpuParamHead* const paramHead = PtrToPtr<void, aicpu::AicpuParamHead>(ValueToPtr(kernel.paramBase));
      60            8 :     if (paramHead == nullptr) {
      61            0 :         aicpusd_err("paramHead for DumpDataKernel is nullptr");
      62            0 :         return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
      63              :     }
      64              : 
      65            8 :     if (static_cast<size_t>(paramHead->length) != len) {
      66            0 :         aicpusd_err("data dump param length[%u] shoulf be [%zu]", paramHead->length, len);
      67            0 :         return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
      68              :     }
      69              : 
      70            8 :     const auto ioAddrBase = PtrToPtr<void, uint64_t>(ValueToPtr(kernel.paramBase + sizeof(aicpu::AicpuParamHead)));
      71            8 :     const uint64_t opMappingInfoAddr = ioAddrBase[0];
      72            8 :     const uint64_t* const lenAddr = PtrToPtr<void, uint64_t>(ValueToPtr(ioAddrBase[1]));
      73            8 :     if (lenAddr == nullptr) {
      74            0 :         aicpusd_err("data dump proto length address is null");
      75            0 :         return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
      76              :     }
      77              : 
      78            8 :     aicpusd_info("Get proto len from address[%llu]", ioAddrBase[1]);
      79            8 :     const uint64_t opMappingInfoLen = *lenAddr;
      80            8 :     aicpusd_info("Proto len[%llu] from address[%llu]", opMappingInfoLen, opMappingInfoAddr);
      81              : 
      82            8 :     const AicpuSchedule::OpDumpTaskManager& dumpTaskMgr = AicpuSchedule::OpDumpTaskManager::GetInstance();
      83            8 :     return dumpTaskMgr.DumpOpInfoForUnknowShape(opMappingInfoAddr, opMappingInfoLen);
      84              : }
      85              : 
      86            4 : int32_t SetAicpuDfxTsKernel::Compute(const aicpu::HwtsTsKernel& tsKernelInfo)
      87              : {
      88            4 :     aicpusd_info("Begin to process ts kernel SetAicpuDfx event.");
      89            4 :     const auto dfxInfo = PtrToPtr<void, aicpu::AicpuDfxInfo>(ValueToPtr(tsKernelInfo.kernelBase.cceKernel.paramBase));
      90            4 :     if (dfxInfo == nullptr) {
      91            1 :         aicpusd_err("param base for dfx info is null.");
      92            1 :         return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
      93              :     }
      94            3 :     const auto cpType = static_cast<DfxCpType>(dfxInfo->cpType);
      95            3 :     if (cpType == DfxCpType::AICPUSD) {
      96            1 :         aicpusd_info("Set dfx info for aicpusd, infoAddr is %lu.", dfxInfo->infoAddr);
      97            1 :         aicpu::AicpuSetDfxInfo(dfxInfo->infoAddr);
      98            1 :         return AICPU_SCHEDULE_OK;
      99              :     }
     100            2 :     if (cpType == DfxCpType::CUSTOM_AICPUSD) {
     101            1 :         aicpusd_info("Set dfx info for custom_aicpusd, infoAddr is %lu.", dfxInfo->infoAddr);
     102            1 :         return SetDfxInfoToCustomSd(dfxInfo->infoAddr);
     103              :     } else {
     104            1 :         aicpusd_err("dfx info cpType[%u] is invalid", dfxInfo->cpType);
     105            1 :         return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
     106              :     }
     107              : }
     108              : 
     109            1 : int32_t SetAicpuDfxTsKernel::SetDfxInfoToCustomSd(const uint64_t infoAddr) const
     110              : {
     111            1 :     AicpuDfxInfoReq req = {};
     112            1 :     req.infoAddr = infoAddr;
     113            1 :     event_summary syncDfxInfo = {};
     114            1 :     syncDfxInfo.msg = PtrToPtr<AicpuDfxInfoReq, char_t>(&req);
     115            1 :     syncDfxInfo.msg_len = static_cast<uint32_t>(sizeof(AicpuDfxInfoReq));
     116            1 :     syncDfxInfo.dst_engine = CCPU_DEVICE;
     117            1 :     syncDfxInfo.policy = ONLY;
     118            1 :     syncDfxInfo.pid = AicpuScheduleInterface::GetInstance().GetAicpuCustSdProcId();
     119            1 :     syncDfxInfo.grp_id = CUSTOM_CP_CCPU_GROUP_ID;
     120            1 :     syncDfxInfo.event_id = EVENT_CCPU_CTRL_MSG;
     121            1 :     syncDfxInfo.subevent_id = AICPU_SUB_EVENT_SET_DFX_INFO;
     122              : 
     123            1 :     int32_t syncRet = 0;
     124            1 :     event_reply drvAck = {};
     125            1 :     drvAck.buf = PtrToPtr<int32_t, char>(&syncRet);
     126            1 :     drvAck.buf_len = sizeof(int32_t);
     127            1 :     const int32_t timeOutMs = 5000;
     128              :     const auto drvRet =
     129            1 :         halEschedSubmitEventSync(AicpuDrvManager::GetInstance().GetDeviceId(), &syncDfxInfo, timeOutMs, &drvAck);
     130            1 :     if (drvRet != DRV_ERROR_NONE) {
     131            0 :         aicpusd_err("Failed to submit event to custom sd, ret=[%d].", static_cast<int32_t>(drvRet));
     132            0 :         return AICPU_SCHEDULE_ERROR_INNER_ERROR;
     133              :     }
     134            1 :     if (syncRet != AICPU_SCHEDULE_OK) {
     135            0 :         aicpusd_err("Failed to set dfx info for custom sd, ret=[%d].", syncRet);
     136            0 :         return AICPU_SCHEDULE_ERROR_INNER_ERROR;
     137              :     }
     138            1 :     return AICPU_SCHEDULE_OK;
     139              : }
     140              : 
     141              : REGISTER_HWTS_KERNEL(CFG_LOG_ADDR, CfgLogAddrTsKernel);
     142              : REGISTER_HWTS_KERNEL(DUMP_DATA_INFO, DumpDataInfoTsKernel);
     143              : REGISTER_HWTS_KERNEL(SET_AICPU_DFX, SetAicpuDfxTsKernel);
     144              : } // namespace AicpuSchedule
        

Generated by: LCOV version 2.0-1