LCOV - code coverage report
Current view: top level - aicpu_cust_schedule/common - aicpusd_sqe_adapter.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 126 126
Test Date: 2026-08-12 11:05:02 Functions: 100.0 % 17 17

            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_sqe_adapter.h"
      11              : 
      12              : namespace AicpuSchedule {
      13              : 
      14            5 : AicpuSqeAdapter::AicpuSqeAdapter(const TsAicpuSqe& sqe, const int16_t version)
      15            5 :     : pid_(sqe.pid),
      16            5 :       cmd_type_(sqe.cmd_type),
      17            5 :       vf_id_(sqe.vf_id),
      18            5 :       tid_(sqe.tid),
      19            5 :       ts_id_(sqe.ts_id),
      20            5 :       sqe_(sqe),
      21            5 :       version_(version),
      22            5 :       invalid_sqe_(false)
      23              : {
      24            5 :     aicpusd_info(
      25              :         "Enter cust aicpuSqeAdapter constructor, using TsAicpuSqe init, pid[%u], cmd_type[%u], vf id[%u], tid[%u], "
      26              :         "ts id[%u], version[%hu]",
      27              :         pid_, cmd_type_, vf_id_, tid_, ts_id_, version_);
      28            5 :     InitAdapterFuncMap();
      29            5 : }
      30              : 
      31            5 : AicpuSqeAdapter::AicpuSqeAdapter(const TsAicpuMsgInfo& msgInfo, const int16_t version)
      32            5 :     : pid_(msgInfo.pid),
      33            5 :       cmd_type_(msgInfo.cmd_type),
      34            5 :       vf_id_(msgInfo.vf_id),
      35            5 :       tid_(msgInfo.tid),
      36            5 :       ts_id_(msgInfo.ts_id),
      37            5 :       msg_Info_(msgInfo),
      38            5 :       version_(version),
      39            5 :       invalid_msg_info_(false)
      40              : {
      41            5 :     aicpusd_info(
      42              :         "Enter cust aicpuSqeAdapter constructor, using TsAicpuMsgInfo init, pid[%u], cmd_type[%u], vf "
      43              :         "id[%u], tid[%u], "
      44              :         "ts id[%u], version[%hu]",
      45              :         pid_, cmd_type_, vf_id_, tid_, ts_id_, version_);
      46            5 :     InitAdapterFuncMap();
      47            5 : }
      48              : 
      49            3 : AicpuSqeAdapter::AicpuSqeAdapter(const int16_t version) : version_(version), invalid_msg_info_(true), invalid_sqe_(true)
      50              : {
      51            3 :     aicpusd_info("Enter AicpuSqeAdapter constructor, using version init, version[%hu]", version_);
      52            3 :     InitAdapterFuncMap();
      53            3 : }
      54              : 
      55           10 : uint8_t AicpuSqeAdapter::GetCmdType() const { return cmd_type_; }
      56              : 
      57            1 : bool AicpuSqeAdapter::IsAdapterInvalidParameter() const { return invalid_sqe_ && invalid_msg_info_; }
      58              : 
      59           13 : void AicpuSqeAdapter::InitAdapterFuncMap()
      60              : {
      61           13 :     getDataDumpLoadInfoFuncMap_[VERSION_0] = &AicpuSqeAdapter::GetAicpuDataDumpInfoLoadV0;
      62           13 :     getDataDumpLoadInfoFuncMap_[VERSION_1] = &AicpuSqeAdapter::GetAicpuDataDumpInfoLoadV1;
      63              : 
      64           13 :     getDataDumpLoadRspFuncMap_[VERSION_0] = &AicpuSqeAdapter::AicpuDataDumpLoadResponseToTsV0;
      65           13 :     getDataDumpLoadRspFuncMap_[VERSION_1] = &AicpuSqeAdapter::AicpuDataDumpLoadResponseToTsV1;
      66           13 : }
      67              : 
      68            5 : void AicpuSqeAdapter::GetAicpuMsgVersionInfo(AicpuMsgVersionInfo& info)
      69              : {
      70            5 :     TsAicpuMsgVersion tmpInfo = sqe_.u.aicpu_msg_version;
      71            5 :     aicpusd_info("Get msg version msg: magic num[%u], version[%hu].", tmpInfo.magic_num, tmpInfo.version);
      72            5 :     info.magic_num = tmpInfo.magic_num;
      73            5 :     info.version = tmpInfo.version;
      74            5 : }
      75              : 
      76            1 : int32_t AicpuSqeAdapter::AicpuMsgVersionResponseToTs(const int32_t ret)
      77              : {
      78            1 :     TsAicpuMsgInfo msgInfo{};
      79            1 :     msgInfo.pid = static_cast<uint32_t>(AicpuDrvManager::GetInstance().GetHostPid());
      80            1 :     msgInfo.vf_id = static_cast<uint8_t>(AicpuDrvManager::GetInstance().GetVfId());
      81            1 :     msgInfo.tid = tid_;
      82            1 :     msgInfo.ts_id = ts_id_;
      83            1 :     msgInfo.cmd_type = cmd_type_;
      84            1 :     msgInfo.u.aicpu_resp.result_code = static_cast<uint16_t>(ret);
      85            1 :     msgInfo.u.aicpu_resp.task_id = INVALID_VALUE32;
      86            1 :     aicpusd_info(
      87              :         "Msg version response info: cmd_type[%u], ret code[%u], stream id[%u], task id[%u].", msgInfo.cmd_type,
      88              :         msgInfo.u.aicpu_resp.result_code, msgInfo.u.aicpu_resp.stream_id, msgInfo.u.aicpu_resp.task_id);
      89            2 :     return ResponseToTs(msgInfo, 0U, AicpuDrvManager::GetInstance().GetDeviceId(), msgInfo.ts_id);
      90              : }
      91              : 
      92            1 : void AicpuSqeAdapter::GetAicpuDataDumpInfoLoadV0(AicpuDataDumpInfoLoad& info)
      93              : {
      94            1 :     TsToAicpuDataDumpInfoLoad tmpinfo = sqe_.u.ts_to_aicpu_datadumploadinfo;
      95            1 :     aicpusd_info(
      96              :         "Get aicpu data dump load info: dumpinfoPtr[%p], length[%u], task_id[%u],stream_id[%u].", tmpinfo.dumpinfoPtr,
      97              :         tmpinfo.length, tmpinfo.task_id, tmpinfo.stream_id);
      98            1 :     info.dumpinfoPtr = tmpinfo.dumpinfoPtr;
      99            1 :     info.length = tmpinfo.length;
     100            1 :     info.task_id = tmpinfo.task_id;
     101            1 :     info.stream_id = tmpinfo.stream_id;
     102            1 : }
     103              : 
     104            1 : void AicpuSqeAdapter::GetAicpuDataDumpInfoLoadV1(AicpuDataDumpInfoLoad& info)
     105              : {
     106            1 :     TsToAicpuDataDumpInfoloadMsg tmpinfo = msg_Info_.u.ts_to_aicpu_datadump_info_load;
     107            1 :     aicpusd_info(
     108              :         "Get aicpu data dump load info: dumpinfoPtr[%p], length[%u], task_id[%u],stream_id[%u].", tmpinfo.dumpinfoPtr,
     109              :         tmpinfo.length, tmpinfo.task_id, tmpinfo.stream_id);
     110            1 :     info.dumpinfoPtr = tmpinfo.dumpinfoPtr;
     111            1 :     info.length = tmpinfo.length;
     112            1 :     info.task_id = tmpinfo.task_id;
     113            1 :     info.stream_id = tmpinfo.stream_id;
     114            1 : }
     115              : 
     116            3 : void AicpuSqeAdapter::GetAicpuDataDumpInfoLoad(AicpuDataDumpInfoLoad& info)
     117              : {
     118            3 :     aicpusd_info("Get aicpu datadump Info load.");
     119            3 :     if (getDataDumpLoadInfoFuncMap_.find(version_) == getDataDumpLoadInfoFuncMap_.end()) {
     120            1 :         aicpusd_err("The version[%hu] does not have a corresponding get data dump load info Function.", version_);
     121            1 :         return;
     122              :     }
     123            2 :     (this->*getDataDumpLoadInfoFuncMap_[version_])(info);
     124            2 :     return;
     125              : }
     126              : 
     127            1 : int32_t AicpuSqeAdapter::AicpuDataDumpLoadResponseToTsV1(const int32_t ret)
     128              : {
     129            1 :     TsAicpuMsgInfo msgInfo{};
     130            1 :     msgInfo.pid = static_cast<uint32_t>(AicpuDrvManager::GetInstance().GetHostPid());
     131            1 :     msgInfo.vf_id = static_cast<uint8_t>(AicpuDrvManager::GetInstance().GetVfId());
     132            1 :     msgInfo.tid = tid_;
     133            1 :     msgInfo.ts_id = ts_id_;
     134            1 :     msgInfo.cmd_type = cmd_type_;
     135            1 :     msgInfo.u.aicpu_resp.result_code = static_cast<uint16_t>(ret);
     136            1 :     msgInfo.u.aicpu_resp.stream_id = msg_Info_.u.ts_to_aicpu_datadump_info_load.stream_id;
     137            1 :     msgInfo.u.aicpu_resp.task_id = msg_Info_.u.ts_to_aicpu_datadump_info_load.task_id;
     138            1 :     aicpusd_info(
     139              :         "Aicpu data dump load response info: cmd_type[%u], ret[%u], streamid[%u], taskid[%u].", msgInfo.cmd_type, ret,
     140              :         msgInfo.u.aicpu_resp.stream_id, msgInfo.u.aicpu_resp.task_id);
     141            2 :     return ResponseToTs(msgInfo, 0U, AicpuDrvManager::GetInstance().GetDeviceId(), msgInfo.ts_id);
     142              : }
     143              : 
     144            1 : int32_t AicpuSqeAdapter::AicpuDataDumpLoadResponseToTsV0(const int32_t ret)
     145              : {
     146            1 :     TsAicpuSqe aicpuSqe{};
     147            1 :     aicpuSqe.pid = static_cast<uint32_t>(AicpuDrvManager::GetInstance().GetHostPid());
     148            1 :     aicpuSqe.vf_id = static_cast<uint8_t>(AicpuDrvManager::GetInstance().GetVfId());
     149            1 :     aicpuSqe.tid = tid_;
     150            1 :     aicpuSqe.ts_id = ts_id_;
     151            1 :     aicpuSqe.cmd_type = AICPU_DATADUMP_RESPONSE;
     152            1 :     aicpuSqe.u.aicpu_dump_resp.result_code = static_cast<uint16_t>(ret);
     153            1 :     aicpuSqe.u.aicpu_dump_resp.cmd_type = AICPU_DATADUMP_LOADINFO;
     154            1 :     aicpuSqe.u.aicpu_dump_resp.task_id = sqe_.u.ts_to_aicpu_datadumploadinfo.task_id;
     155            1 :     aicpuSqe.u.aicpu_dump_resp.stream_id = sqe_.u.ts_to_aicpu_datadumploadinfo.stream_id;
     156            1 :     aicpuSqe.u.aicpu_dump_resp.reserved = STARS_DATADUMP_LOAD_INFO;
     157            1 :     aicpusd_info(
     158              :         "Aicpu data dump load response info: cmd_type[%u], ret[%u], streamid[%u], taskid[%u].", aicpuSqe.cmd_type, ret,
     159              :         aicpuSqe.u.aicpu_dump_resp.stream_id, aicpuSqe.u.aicpu_dump_resp.task_id);
     160            2 :     return ResponseToTs(aicpuSqe, 0U, AicpuDrvManager::GetInstance().GetDeviceId(), aicpuSqe.ts_id);
     161              : }
     162              : 
     163            3 : int32_t AicpuSqeAdapter::AicpuDataDumpLoadResponseToTs(const int32_t ret)
     164              : {
     165            3 :     aicpusd_info("Aicpu datadump load response to ts.");
     166            3 :     if (getDataDumpLoadRspFuncMap_.find(version_) == getDataDumpLoadRspFuncMap_.end()) {
     167            1 :         aicpusd_err("The version[%hu] does not have a corresponding get data dump load response Function.", version_);
     168            1 :         return AICPU_SCHEDULE_ERROR_NOT_FOUND_FUNCTION;
     169              :     }
     170            2 :     return (this->*getDataDumpLoadRspFuncMap_[version_])(ret);
     171              : }
     172              : 
     173            1 : int32_t AicpuSqeAdapter::ResponseToTs(
     174              :     TsAicpuSqe& aicpuSqe, unsigned int handleId, unsigned int devId, unsigned int tsId)
     175              : {
     176            1 :     aicpusd_info("Begin to response use TsAicpuSqe.");
     177            1 :     const auto ret = tsDevSendMsgAsync(
     178              :         devId, static_cast<uint32_t>(tsId), PtrToPtr<TsAicpuSqe, char_t>(&aicpuSqe),
     179              :         static_cast<uint32_t>(sizeof(TsAicpuSqe)), handleId);
     180            1 :     AICPUSD_CHECK(
     181              :         (ret == DRV_ERROR_NONE), AICPU_SCHEDULE_ERROR_INNER_ERROR,
     182              :         "Response to ts use"
     183              :         "tsDevSendMsgAsync failed, ret[%d]",
     184              :         ret);
     185            1 :     aicpusd_info("Finished to response use TsAicpuSqe.");
     186            1 :     return AICPU_SCHEDULE_OK;
     187              : }
     188              : 
     189            3 : int32_t AicpuSqeAdapter::ResponseToTs(
     190              :     TsAicpuMsgInfo& aicpuMsgInfo, unsigned int handleId, unsigned int devId, unsigned int tsId)
     191              : {
     192            3 :     aicpusd_info("Begin to response use TsAicpuMsgInfo.");
     193            3 :     const auto ret = tsDevSendMsgAsync(
     194              :         devId, static_cast<uint32_t>(tsId), PtrToPtr<TsAicpuMsgInfo, char_t>(&aicpuMsgInfo),
     195              :         static_cast<uint32_t>(sizeof(TsAicpuMsgInfo)), handleId);
     196            3 :     AICPUSD_CHECK(
     197              :         (ret == DRV_ERROR_NONE), AICPU_SCHEDULE_ERROR_INNER_ERROR,
     198              :         "Response to ts use"
     199              :         "tsDevSendMsgAsync failed, ret[%d]",
     200              :         ret);
     201            3 :     aicpusd_info("Finished to response use TsAicpuMsgInfo.");
     202            3 :     return AICPU_SCHEDULE_OK;
     203              : }
     204              : 
     205            1 : int32_t AicpuSqeAdapter::ResponseToTs(hwts_response_t& hwtsResp, uint32_t devId, EVENT_ID eventId, uint32_t subeventId)
     206              : {
     207            1 :     aicpusd_info("Begin to response use hwtsResp.");
     208            1 :     const drvError_t ret = halEschedAckEvent(
     209              :         devId, eventId, subeventId, PtrToPtr<hwts_response_t, char_t>(&hwtsResp),
     210              :         static_cast<uint32_t>(sizeof(hwts_response_t)));
     211            1 :     AICPUSD_CHECK(
     212              :         (ret == DRV_ERROR_NONE), AICPU_SCHEDULE_ERROR_INNER_ERROR,
     213              :         "Response to ts use"
     214              :         "halEschedAckEvent failed, ret[%d]",
     215              :         ret);
     216            1 :     aicpusd_info("Finished to response use hwtsResp.");
     217            1 :     return AICPU_SCHEDULE_OK;
     218              : }
     219              : } // namespace AicpuSchedule
        

Generated by: LCOV version 2.0-1