LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/resource/ccu_transport - ccu_jetty.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 91.7 % 72 66
Test Date: 2026-08-18 17:47:01 Functions: 78.6 % 14 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              : 
      11              : #include "ccu_jetty.h"
      12              : 
      13              : #include "hccp_ctx.h"
      14              : #include "rdma_handle_manager.h"
      15              : #include "local_ub_rma_buffer.h"
      16              : 
      17              : namespace Hccl {
      18              : 
      19           14 : HcclResult CcuCreateJetty(const IpAddress& ipAddr, const CcuJettyInfo& jettyInfo, std::unique_ptr<CcuJetty>& ccuJetty)
      20              : {
      21           14 :     TRY_CATCH_RETURN(ccuJetty = std::make_unique<CcuJetty>(ipAddr, jettyInfo););
      22           14 :     return HcclResult::HCCL_SUCCESS;
      23              : }
      24              : 
      25          808 : CcuJetty::CcuJetty(const IpAddress& ipAddr, const CcuJettyInfo& jettyInfo) : ipAddr_(ipAddr), jettyInfo_(jettyInfo)
      26              : {
      27          808 :     devLogicId_ = HrtGetDevice();
      28          808 :     Hccl::CqCreateInfo cqInfo{};
      29          808 :     uint32_t devPhyId = HrtGetDevicePhyIdByIndex(devLogicId_);
      30          808 :     auto& rdmaHandleMgr = RdmaHandleManager::GetInstance();
      31          808 :     rdmaHandle_ = rdmaHandleMgr.GetByIp(devPhyId, ipAddr);
      32          808 :     const auto jfcHandle = rdmaHandleMgr.GetJfcHandle(rdmaHandle_, cqInfo, HrtUbJfcMode::CCU_POLL);
      33          808 :     const auto tokenValue = GetUbToken();
      34          808 :     const auto jettyMode = HrtJettyMode::CCU_CCUM_CACHE; // 当前仅支持该模式
      35              : 
      36          808 :     inParam_ = HrtRaUbCreateJettyParam{
      37              :         jfcHandle,
      38              :         jfcHandle,
      39              :         tokenValue,
      40              :         0,
      41              :         jettyMode,
      42          808 :         jettyInfo.taJettyId,
      43          808 :         jettyInfo.sqBufVa,
      44          808 :         jettyInfo.sqBufSize,
      45          808 :         jettyInfo.wqeBBStartId,
      46          808 :         jettyInfo.sqDepth};
      47          808 : }
      48              : 
      49          808 : CcuJetty::~CcuJetty()
      50              : {
      51          808 :     DECTOR_TRY_CATCH("CcuJetty", {
      52              :         if (isCreated_ && outParam_.handle != 0) {
      53              :             HrtRaUbDestroyJetty(outParam_.handle);
      54              :         }
      55              :     });
      56          808 : }
      57              : 
      58            1 : bool CheckRequestResult(RequestHandle& reqHandle)
      59              : {
      60            1 :     if (reqHandle == 0) {
      61            0 :         return true;
      62              :     }
      63              : 
      64            1 :     ReqHandleResult result = HrtRaGetAsyncReqResult(reqHandle);
      65            1 :     if (result == ReqHandleResult::NOT_COMPLETED) {
      66            0 :         return false;
      67              :     }
      68              : 
      69            1 :     if (result != ReqHandleResult::COMPLETED) {
      70            0 :         THROW<InternalException>(
      71            0 :             "[CcuJetty][%s] failed, result[%s] is unexpected.", __func__, result.Describe().c_str());
      72              :     }
      73              : 
      74            1 :     return true;
      75              : }
      76              : 
      77            1 : static HcclResult ParseCreateInfo(
      78              :     const struct QpCreateInfo* infoPtr, const JettyHandle jettyHandle, HrtRaUbJettyCreatedOutParam& outParam)
      79              : {
      80            1 :     outParam.handle = jettyHandle;
      81            1 :     auto ret = memcpy_s(outParam.key, HRT_UB_QP_KEY_MAX_LEN, infoPtr->key.value, infoPtr->key.size);
      82            1 :     if (ret != 0) {
      83            0 :         HCCL_ERROR("[CcuJetty][%s] create info key memcpy_s failed, ret[%d].", __func__, ret);
      84            0 :         return HcclResult::HCCL_E_MEMORY;
      85              :     }
      86            1 :     outParam.jettyVa = infoPtr->va;
      87            1 :     outParam.uasid = infoPtr->ub.uasid;
      88            1 :     outParam.id = infoPtr->ub.id;
      89            1 :     outParam.keySize = infoPtr->key.size;
      90            1 :     outParam.dbVa = infoPtr->ub.dbAddr;
      91            1 :     outParam.dbTokenId = infoPtr->ub.dbTokenId >> URMA_TOKEN_ID_RIGHT_SHIFT;
      92              :     // 不提供 tokenValue,不得打印token相关信息
      93            1 :     return HcclResult::HCCL_SUCCESS;
      94              : }
      95              : 
      96            3 : HcclResult CcuJetty::HandleAsyncRequest()
      97              : {
      98            6 :     TRY_CATCH_RETURN(
      99              :         if (reqHandle_ == 0) {
     100              :             reqHandle_ = RaUbCreateJettyAsync(rdmaHandle_, inParam_, reqDataBuffer_, jettyHandlePtr_);
     101              :             return HcclResult::HCCL_E_AGAIN;
     102              :         }
     103              : 
     104              :         if (!CheckRequestResult(reqHandle_)) { return HcclResult::HCCL_E_AGAIN; };);
     105              : 
     106            1 :     const struct QpCreateInfo* info = reinterpret_cast<const QpCreateInfo*>(reqDataBuffer_.data());
     107            1 :     const JettyHandle jettyHandle = reinterpret_cast<JettyHandle>(jettyHandlePtr_);
     108            1 :     return ParseCreateInfo(info, jettyHandle, outParam_);
     109              : }
     110              : 
     111            5 : HcclResult CcuJetty::CreateJetty()
     112              : {
     113            5 :     if (isError_) {
     114            3 :         HCCL_ERROR(
     115              :             "[CcuJetty][%s] failed, jetty[%u] is error, "
     116              :             "refused to create.",
     117              :             __func__, inParam_.jettyId);
     118            1 :         return HcclResult::HCCL_E_INTERNAL;
     119              :     }
     120              : 
     121            4 :     if (isCreated_) {
     122            3 :         HCCL_INFO("[CcuJetty][%s] passed, jetty[%u] has been created.", __func__, inParam_.jettyId);
     123            1 :         return HcclResult::HCCL_SUCCESS;
     124              :     }
     125              : 
     126            3 :     auto ret = HandleAsyncRequest();
     127            3 :     if (ret == HcclResult::HCCL_SUCCESS) {
     128            1 :         isCreated_ = true;
     129            2 :     } else if (ret != HcclResult::HCCL_E_AGAIN) {
     130            1 :         isError_ = true;
     131              :     }
     132              : 
     133            3 :     return ret;
     134              : }
     135              : 
     136           40 : HrtRaUbCreateJettyParam CcuJetty::GetCreateJettyParam() const { return inParam_; }
     137              : 
     138           52 : HrtRaUbJettyCreatedOutParam CcuJetty::GetJettyedOutParam() const { return outParam_; }
     139              : 
     140           24 : void CcuJetty::GetJettyInfo(ConnJettyInfo& connJettyInfo)
     141              : {
     142           24 :     if (isCreated_ && outParam_.handle != 0) {
     143           14 :         connJettyInfo.localJetty = outParam_.handle;
     144              :     }
     145           24 : }
     146              : 
     147           26 : HcclResult CcuJetty::Clean()
     148              : {
     149           26 :     TRY_CATCH_RETURN(if (isCreated_ && outParam_.handle != 0) {
     150              :         isCreated_ = false;
     151              :         reqHandle_ = 0;
     152              :         jettyHandlePtr_ = nullptr;
     153              :         reqDataBuffer_.clear();
     154              :     } isError_ = false;);
     155           26 :     return HcclResult::HCCL_SUCCESS;
     156              : }
     157              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1