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

Generated by: LCOV version 2.0-1