LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/resource/stream/aicpu - rtsq_base.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 78.7 % 89 70
Test Date: 2026-08-04 10:52:23 Functions: 84.6 % 13 11

            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 "rtsq_base.h"
      11              : #include "log.h"
      12              : #include "drv_api_exception.h"
      13              : #include "exception_util.h"
      14              : #include "internal_exception.h"
      15              : #include "sqe_v82.h"
      16              : #include <unordered_map>
      17              : namespace Hccl {
      18          257 : RtsqBase::RtsqBase(u32 devPhyId, u32 streamId, u32 sqId) : devPhyId_(devPhyId), streamId_(streamId), sqId_(sqId)
      19              : {
      20          257 :     auto ret = drvGetLocalDevIDByHostDevID(devPhyId_, &localDevId_);
      21          257 :     if (ret != DRV_ERROR_NONE) {
      22              :         std::string formatStr = StringFormat(
      23            0 :             "RtsqBase::%s call drvGetLocalDevIDByHostDevID failed, devPhyId %u, ret %d", __func__, devPhyId_, ret);
      24            0 :         THROW<DrvApiException>(formatStr);
      25            0 :     }
      26              : 
      27          257 :     sqHead_     = QuerySqHead();
      28          257 :     sqTail_     = QuerySqTail();
      29          257 :     sqDepth_    = QuerySqDepth();
      30          257 :     sqBaseAddr_ = QuerySqBaseAddr();
      31              : 
      32          257 :     if (sqDepth_ == 0) {
      33            0 :         THROW<InternalException>("sqDepth_ cannot be zero.");
      34              :     }
      35          595 :     HCCL_INFO("%s, %s", __func__, GetHwSqDescribe().c_str());
      36          257 : }
      37              : 
      38            1 : void RtsqBase::Reset()
      39              : {
      40            1 :     sqHead_  = QuerySqHead();
      41            1 :     sqTail_  = QuerySqTail();
      42            1 :     sqDepth_ = QuerySqDepth();
      43            1 :     sqBaseAddr_ = QuerySqBaseAddr();
      44            1 :     SetTaskIdBySqeId();
      45            3 :     HCCL_INFO("%s, %s", __func__, GetHwSqDescribe().c_str());
      46            1 : }
      47              : 
      48          258 : std::string RtsqBase::GetHwSqDescribe() const
      49              : {
      50              :     return StringFormat("devPhyId=%u, localDevId=%u, streamId=%u, sqId=%u, sqDepth=%u, sqBaseAddr=0x%llx, "
      51              :                         "currentHead=%u, currentTail=%u, cqeStatus=%u, taskId=%u",
      52          258 :                         devPhyId_, localDevId_, streamId_, sqId_, sqDepth_, sqBaseAddr_, QuerySqHead(), QuerySqTail(), QueryCqeStatus(),
      53          258 :                         taskId_);
      54              : }
      55              : 
      56          529 : u32 RtsqBase::QuerySqStatusByType(drvSqCqPropType_t givenType) const
      57              : {
      58              :     halSqCqQueryInfo  queryInfo;
      59              : 
      60          529 :     queryInfo.tsId         = 0;
      61          529 :     queryInfo.sqId         = sqId_;
      62          529 :     queryInfo.cqId         = 0;
      63          529 :     queryInfo.type         = DRV_NORMAL_TYPE;
      64          529 :     queryInfo.prop         = givenType;
      65          529 :     drvError_t ret = halSqCqQuery(localDevId_, &queryInfo);
      66          529 :     if (ret != 0) {
      67              :         std::string formatStr = StringFormat("RtsqBase::%s call halSqCqQuery failed, localDevId %u, ret %d, givenType=%u",
      68            1 :                                              __func__, localDevId_, ret, givenType);
      69            1 :         THROW<DrvApiException>(formatStr);
      70            1 :     }
      71              : 
      72          528 :     return queryInfo.value[0];
      73              : }
      74              : 
      75           89 : u64 RtsqBase::QuerySqBaseAddr() const
      76              : {
      77              :     halSqCqQueryInfo queryInfo;
      78           89 :     queryInfo.tsId = 0;
      79           89 :     queryInfo.sqId = sqId_;
      80           89 :     queryInfo.cqId = 0;
      81           89 :     queryInfo.type = DRV_NORMAL_TYPE;
      82           89 :     queryInfo.prop = DRV_SQCQ_PROP_SQ_BASE;
      83           89 :     drvError_t ret = halSqCqQuery(localDevId_, &queryInfo);
      84           89 :     if (ret != 0) {
      85              :         std::string formatStr
      86            1 :             = StringFormat("RtsqBase::%s call halSqCqQuery failed, localDevId %u, ret %d", __func__, localDevId_, ret);
      87            1 :         THROW<DrvApiException>(formatStr);
      88            1 :     }
      89           88 :     HCCL_INFO("RtsqBase::%s end", __func__);
      90              : 
      91              :     // 参照 driver API,BaseAddress为64bit,由两个32bit拼接而成,高32bit为 value[1], 低32bit为value[0]
      92           88 :     return ((static_cast<u64>(queryInfo.value[1])) << 32) | queryInfo.value[0];
      93              : }
      94              : 
      95          519 : u32 RtsqBase::QuerySqHead() const
      96              : {
      97          519 :     return QuerySqStatusByType(drvSqCqPropType_t::DRV_SQCQ_PROP_SQ_HEAD);
      98              : }
      99          519 : u32 RtsqBase::QuerySqTail() const
     100              : {
     101          519 :     return QuerySqStatusByType(drvSqCqPropType_t::DRV_SQCQ_PROP_SQ_TAIL);
     102              : }
     103           88 : u32 RtsqBase::QuerySqDepth() const
     104              : {
     105           88 :     return QuerySqStatusByType(drvSqCqPropType_t::DRV_SQCQ_PROP_SQ_DEPTH);
     106              : }
     107          258 : u32 RtsqBase::QueryCqeStatus() const
     108              : {
     109          258 :     return QuerySqStatusByType(drvSqCqPropType_t::DRV_SQCQ_PROP_SQ_CQE_STATUS);
     110              : }
     111              : 
     112            1 : void RtsqBase::ConfigSqStatusByType(drvSqCqPropType_t givenType, u32 value) const
     113              : {
     114              :     halSqCqConfigInfo configInfo;
     115            1 :     configInfo.tsId     = 0;
     116            1 :     configInfo.sqId     = sqId_;
     117            1 :     configInfo.cqId     = 0;
     118            1 :     configInfo.type     = DRV_NORMAL_TYPE;
     119            1 :     configInfo.prop     = givenType;
     120            1 :     configInfo.value[0] = value;
     121              : 
     122            1 :     drvError_t ret = halSqCqConfig(localDevId_, &configInfo);
     123            1 :     if (UNLIKELY(ret != 0)) {
     124              :         std::string formatStr
     125            1 :             = StringFormat("RtsqBase::%s call halSqCqConfig failed, localDevId %u, ret %d", __func__, localDevId_, ret);
     126            1 :         THROW<DrvApiException>(formatStr);
     127            1 :     }
     128            0 : }
     129              : 
     130            3 : void RtsqBase::ConfigSqTail(u32 value)
     131              : {
     132            9 :     HCCL_INFO("RtsqBase::%s, value=%u", __func__, value);
     133            3 :     ConfigSqStatusByType(drvSqCqPropType_t::DRV_SQCQ_PROP_SQ_TAIL, value);
     134            3 : }
     135            0 : void RtsqBase::ConfigDisableToEnable(u32 value)
     136              : {
     137            0 :     HCCL_INFO("RtsqBase::%s, value=%u", __func__, value);
     138            0 :     ConfigSqStatusByType(drvSqCqPropType_t::DRV_SQCQ_PROP_SQ_DISABLE_TO_ENABLE, value);
     139            0 : }
     140              : 
     141            0 : HcclResult RtsqBase::GetStreamIdAndTaskIdBySqIdx(u32 sqIdx, uint16_t& streamId, uint16_t& taskId) const
     142              : {
     143            0 :     const u32 rtsqLength = 2048;
     144            0 :     if (sqBaseAddr_ == 0 || sqIdx >= rtsqLength) {
     145            0 :         HCCL_ERROR("[%s]fail, sqBaseAddr_[0x%llu], sqIdx[%u]", __func__, sqBaseAddr_, sqIdx);
     146            0 :         return HCCL_E_PARA;
     147              :     }
     148              : 
     149            0 :     Rt91095StarsNotifySqe* sqe = (Rt91095StarsNotifySqe*)(sqBaseAddr_ + sqIdx * RTSQ_SQE_SIZE);
     150            0 :     streamId = sqe->header.rtStreamId;
     151            0 :     taskId = sqe->header.taskId;
     152            0 :     HCCL_INFO("[%s]sqId:%u, streamId:%u, taskId:%u", __func__, sqId_, streamId, taskId);
     153            0 :     return HCCL_SUCCESS;
     154              : }
     155              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1