LCOV - code coverage report
Current view: top level - base_comm/resources/ccu/ccu_device/ccu_comp/ccu_channel/ccu_channel_ctx_v1 - ccu_jetty_ctx_mgr_v1.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 90.0 % 60 54
Test Date: 2026-08-04 10:52:23 Functions: 100.0 % 5 5

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2026 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_ctx_mgr_v1.h"
      12              : 
      13              : #include "ccu_res_specs.h"
      14              : 
      15              : #include "ccu_wqebb_mgr_v1.h"
      16              : 
      17              : namespace hcomm {
      18              : 
      19          142 : HcclResult CcuJettyCtxMgrV1::Init()
      20              : {
      21              :     // 获取失败或为0场景,分配将按资源不足操作
      22          142 :     (void)CcuResSpecifications::GetInstance(devLogicId_).GetJettyNum(dieId_, jettySpecNum_);
      23              :     // 获取地址为0在使用处校验
      24          142 :     (void)CcuResSpecifications::GetInstance(devLogicId_).GetResourceAddr(dieId_, ccuResBaseVa_);
      25              :     
      26          142 :     wqeBBMgr_.reset(new (std::nothrow) CcuWqeBBMgrV1(devLogicId_, dieId_));
      27          142 :     CHK_PTR_NULL(wqeBBMgr_);
      28          142 :     CHK_RET(wqeBBMgr_->Init());
      29          142 :     CHK_RET(pfeMgr_.Init());
      30          142 :     return HcclResult::HCCL_SUCCESS;
      31              : }
      32              : 
      33          155 : HcclResult CcuJettyCtxMgrV1::Alloc(const uint32_t feId, const uint32_t jettyNum,
      34              :     const uint32_t sqSize, std::vector<JettyInfo> &jettyInfos)
      35              : {
      36          155 :     JettyAllocator *allocatorHandle = nullptr;
      37          155 :     auto ret = GetJettyAllocator(feId, allocatorHandle);
      38          155 :     CHK_PRT_RET(ret != HcclResult::HCCL_SUCCESS,
      39              :         HCCL_WARNING("[CcuJettyCtxMgrV1][%s] failed, failed to get jetty allocator handle, "
      40              :             "devLogicId[%d], dieId[%u], feId[%u].", __func__, devLogicId_, dieId_, feId),
      41              :         HcclResult::HCCL_E_INTERNAL);
      42              : 
      43          155 :     std::vector<ResInfo> jettyResInfos; // jettys分配必须要求连续,故返回一个元素
      44          310 :     ret = allocatorHandle->idAllocator->Alloc(jettyNum, true, jettyResInfos, "ResType::Jetty");
      45          155 :     CHK_PRT_RET(ret != HcclResult::HCCL_SUCCESS,
      46              :         HCCL_WARNING("[CcuJettyCtxMgrV1][%s] failed, allocator failed to allocate, "
      47              :             "devLogicId[%d], dieId[%u], feId[%u].", __func__, devLogicId_, dieId_, feId),
      48              :         ret);
      49              : 
      50          155 :     const auto &strategy = allocatorHandle->strategy;
      51          155 :     const uint32_t jettyResStartId = jettyResInfos[0].startId; // 资源分配器中的索引号
      52          155 :     const uint32_t jettyCtxStartId = strategy.startLocalJettyCtxId + jettyResStartId;
      53          155 :     const uint32_t taJettyStartId = strategy.startTaJettyId + jettyResStartId;
      54          155 :     CHK_PRT_RET(jettyCtxStartId > jettySpecNum_ - jettyNum,
      55              :         HCCL_WARNING("[CcuJettyCtxMgrV1][%s] jetty resource is not enough, allocated "
      56              :             "jettyCtxId[%u] should be less than %u, devLogicId[%d], dieId[%u], feId[%u].",
      57              :             __func__, jettyCtxStartId, jettySpecNum_, devLogicId_, dieId_, feId),
      58              :         HcclResult::HCCL_E_UNAVAIL);
      59              : 
      60          155 :     constexpr CcuJettyType type_ = CcuJettyType::CCUM_CACHED_JETTY;
      61          155 :     jettyInfos.resize(jettyNum);
      62          155 :     ret = TryAllocWqeBBResource(sqSize, jettyCtxStartId, taJettyStartId, type_, jettyInfos);
      63          155 :     if (ret != HcclResult::HCCL_SUCCESS) {
      64            0 :         HCCL_WARNING("[CcuJettyCtxMgrV1][%s] failed, try to release temp resource, "
      65              :             "devLogicId[%d], dieId[%u], feId[%u].", __func__, devLogicId_, dieId_, feId);
      66            0 :         CHK_RET(ReleaseWqeBBResource(jettyInfos)); // jettyInfos已分配的wqeBB资源信息
      67            0 :         jettyInfos.clear(); // 清理wqebb资源信息
      68            0 :         CHK_RET(allocatorHandle->idAllocator->Release(jettyResStartId, jettyNum));
      69              :     }
      70          155 :     return ret;
      71          155 : }
      72              : 
      73          168 : HcclResult CcuJettyCtxMgrV1::GetJettyAllocator(uint32_t feId, JettyAllocator* &allocatorHandle)
      74              : {
      75          168 :     if (!allocator_) {
      76          142 :         PfeJettyStrategy strategy = {};
      77          142 :         CHK_RET(pfeMgr_.GetPfeStrategy(feId, strategy)); // 如果strategy为0,后续按资源不足处理
      78          142 :         allocator_.reset(new (std::nothrow) JettyAllocator(strategy));
      79          142 :         CHK_PTR_NULL(allocator_);
      80          142 :         CHK_PTR_NULL(allocator_->idAllocator);
      81              :     }
      82              : 
      83          168 :     allocatorHandle = allocator_.get();
      84          168 :     return HcclResult::HCCL_SUCCESS;
      85              : }
      86              : 
      87          142 : HcclResult CcuJettyCtxMgrV1::Config(const uint32_t feId,
      88              :     const std::vector<JettyInfo> &jettyInfos,
      89              :     const std::vector<JettyCfg> &jettyCfgs)
      90              : {
      91          142 :     CHK_RET(CheckIfJettyCfgsValid(jettyInfos, jettyCfgs));
      92              : 
      93          142 :     std::vector<LocalJettyCtxData> jettyCtxData;
      94          142 :     const uint32_t jettyNum = jettyInfos.size();
      95          284 :     for (size_t i = 0; i < jettyNum; i++) {
      96          142 :         jettyCtxData.emplace_back(BuildJettyCtxData(dieId_, feId, jettyInfos[i], jettyCfgs[i]));
      97              :     }
      98              : 
      99          142 :     const uint32_t startJettyCtxId = jettyInfos[0].jettyCtxId;
     100          142 :     CHK_RET(ConfigJettyCtxData(devLogicId_, dieId_, devPhyId_, startJettyCtxId, jettyCtxData));
     101          142 :     return HcclResult::HCCL_SUCCESS;
     102          142 : }
     103              : 
     104           13 : HcclResult CcuJettyCtxMgrV1::Release(const uint32_t feId, const std::vector<JettyInfo> &jettyInfos)
     105              : {
     106           13 :     if (jettyInfos.empty()) {
     107            0 :         HCCL_INFO("[CcuJettyCtxMgrV1][%s] passed, jettyInfos is empty, no need to release, ",
     108              :             "devLogicId[%d], dieId[%u], feId[%u].", __func__, devLogicId_, dieId_, feId);
     109            0 :         return HcclResult::HCCL_SUCCESS;
     110              :     }
     111           13 :     JettyAllocator* allocatorHandle = nullptr;
     112           13 :     CHK_RET(GetJettyAllocator(feId, allocatorHandle));
     113           13 :     CHK_RET(ReleaseWqeBBResource(jettyInfos));
     114              : 
     115           13 :     const uint32_t jettyStartCtxId = static_cast<uint32_t>(jettyInfos[0].jettyCtxId);
     116           13 :     const uint32_t jettyResStartId = jettyStartCtxId - allocatorHandle->strategy.startLocalJettyCtxId;
     117           13 :     CHK_RET(allocatorHandle->idAllocator->Release(jettyResStartId, jettyInfos.size()));
     118           13 :     return HcclResult::HCCL_SUCCESS;
     119              : }
     120              : 
     121              : }; // namespace hcomm
     122              : 
        

Generated by: LCOV version 2.0-1