LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/ccu/ccu_device/ccu_component/ccu_channel/ccu_channel_v1 - ccu_jetty_ctx_mgr_v1.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 89.1 % 55 49
Test Date: 2026-08-04 10:52:23 Functions: 71.4 % 7 5

            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_ctx_mgr_v1.h"
      12              : 
      13              : 
      14              : namespace Hccl {
      15              : 
      16           24 : CcuJettyCtxMgrV1::CcuJettyCtxMgrV1(const int32_t devLogicId, const uint8_t dieId, const uint32_t devPhyId)
      17           24 :     : CcuJettyCtxMgr(devLogicId, dieId, devPhyId)
      18              : {
      19           24 : }
      20              : 
      21           28 : HcclResult CcuJettyCtxMgrV1::Alloc(const uint32_t feId, const uint32_t jettyNum,
      22              :     const uint32_t sqSize, std::vector<JettyInfo> &jettyInfos)
      23              : {
      24           28 :     JettyAllocator *allocatorHandle = nullptr;
      25           28 :     auto ret = GetJettyAllocator(feId, allocatorHandle);
      26           28 :     CHK_PRT_RET(ret != HcclResult::HCCL_SUCCESS,
      27              :         HCCL_WARNING("[CcuJettyCtxMgrV1][%s] failed, failed to get jetty allocator handle, "
      28              :             "devLogicId[%d], dieId[%u], feId[%u].", __func__, devLogicId, dieId, feId),
      29              :         HcclResult::HCCL_E_INTERNAL);
      30              : 
      31           28 :     vector<ResInfo> jettyResInfos; // jettys分配必须要求连续,故返回一个元素
      32           56 :     ret = allocatorHandle->idAllocator->Alloc(jettyNum, true, jettyResInfos, "ResType::Jetty");
      33           28 :     CHK_PRT_RET(ret != HcclResult::HCCL_SUCCESS,
      34              :         HCCL_WARNING("[CcuJettyCtxMgrV1][%s] failed, allocator failed to allocate, "
      35              :             "devLogicId[%d], dieId[%u], feId[%u].", __func__, devLogicId, dieId, feId),
      36              :         ret);
      37              : 
      38           28 :     const auto &strategy = allocatorHandle->strategy;
      39           28 :     const uint32_t jettyResStartId = jettyResInfos[0].startId; // 资源分配器中的索引号
      40           28 :     const uint32_t jettyCtxStartId = strategy.startLocalJettyCtxId + jettyResStartId;
      41           28 :     const uint32_t taJettyStartId = strategy.startTaJettyId + jettyResStartId;
      42           28 :     CHK_PRT_RET(jettyCtxStartId > jettySpecNum - jettyNum,
      43              :         HCCL_WARNING("[CcuJettyCtxMgrV1][%s] jetty resource is not enough, allocated "
      44              :             "jettyCtxId[%u] should be less than %u, devLogicId[%d], dieId[%u], feId[%u].",
      45              :             __func__, jettyCtxStartId, jettySpecNum, devLogicId, dieId, feId),
      46              :         HcclResult::HCCL_E_UNAVAIL);
      47              : 
      48           28 :     constexpr CcuJettyType type_ = CcuJettyType::CCUM_CACHED_JETTY;
      49           28 :     jettyInfos.resize(jettyNum);
      50           28 :     ret = TryAllocWqeBBResource(sqSize, jettyCtxStartId, taJettyStartId, type_, jettyInfos);
      51           28 :     if (ret != HcclResult::HCCL_SUCCESS) {
      52            0 :         HCCL_WARNING("[CcuJettyCtxMgrV1][%s] failed, try to release temp resource, "
      53              :             "devLogicId[%d], dieId[%u], feId[%u].", __func__, devLogicId, dieId, feId);
      54            0 :         CHK_RET(ReleaseWqeBBResource(jettyInfos)); // jettyInfos已分配的wqeBB资源信息
      55            0 :         jettyInfos.clear(); // 清理wqebb资源信息
      56            0 :         CHK_RET(allocatorHandle->idAllocator->Release(jettyResStartId, jettyNum));
      57              :     }
      58           28 :     return ret;
      59           28 : }
      60              : 
      61           30 : HcclResult CcuJettyCtxMgrV1::GetJettyAllocator(uint32_t feId, JettyAllocator* &allocatorHandle)
      62              : {
      63           30 :     if (allocator_ == nullptr) {
      64           72 :         HCCL_INFO("[CcuJettyCtxMgrV1][%s] allocator is null, create an allocator", __func__);
      65           24 :         PfeJettyStrategy strategy = {};
      66           24 :         CHK_RET(pfeMgr.GetPfeStrategy(feId, strategy)); // 如果strategy为0,后续按资源不足处理
      67           24 :         TRY_CATCH_RETURN(allocator_ = std::make_unique<JettyAllocator>(strategy));
      68              :     }
      69              : 
      70           30 :     allocatorHandle = allocator_.get();
      71           30 :     CHK_PTR_NULL(allocatorHandle);
      72           30 :     return HcclResult::HCCL_SUCCESS;
      73              : }
      74              : 
      75           28 : HcclResult CcuJettyCtxMgrV1::Config(const uint32_t feId,
      76              :     const std::vector<JettyInfo> &jettyInfos,
      77              :     const std::vector<JettyCfg> &jettyCfgs)
      78              : {
      79           34 :     CHK_RET(CheckIfJettyCfgsValid(jettyInfos, jettyCfgs));
      80              : 
      81           26 :     std::vector<LocalJettyCtxData> jettyCtxData;
      82           26 :     const uint32_t jettyNum = jettyInfos.size();
      83           54 :     for (size_t i = 0; i < jettyNum; i++) {
      84           28 :         jettyCtxData.emplace_back(BuildJettyCtxData(dieId, feId, jettyInfos[i], jettyCfgs[i]));
      85              :     }
      86              : 
      87           26 :     const uint32_t startJettyCtxId = jettyInfos[0].jettyCtxId;
      88           26 :     TRY_CATCH_RETURN(ConfigJettyCtxData(devLogicId, dieId, startJettyCtxId, jettyCtxData));
      89           26 :     return HcclResult::HCCL_SUCCESS;
      90           26 : }
      91              : 
      92            2 : HcclResult CcuJettyCtxMgrV1::Release(const uint32_t feId, const std::vector<JettyInfo> &jettyInfos)
      93              : {
      94            2 :     if (jettyInfos.empty()) {
      95            0 :         HCCL_INFO("[CcuJettyCtxMgrV1][%s] passed, jettyInfos is empty, no need to release, ",
      96              :             "devLogicId[%d], dieId[%u], feId[%u].", __func__, devLogicId, dieId, feId);
      97            0 :         return HcclResult::HCCL_SUCCESS;
      98              :     }
      99            2 :     JettyAllocator* allocatorHandle = nullptr;
     100            2 :     CHK_RET(GetJettyAllocator(feId, allocatorHandle));
     101            2 :     CHK_RET(ReleaseWqeBBResource(jettyInfos));
     102              : 
     103            2 :     const uint32_t jettyStartCtxId = static_cast<uint32_t>(jettyInfos[0].jettyCtxId);
     104            2 :     const uint32_t jettyResStartId = jettyStartCtxId - allocatorHandle->strategy.startLocalJettyCtxId;
     105            2 :     CHK_RET(allocatorHandle->idAllocator->Release(jettyResStartId, jettyInfos.size()));
     106            2 :     return HcclResult::HCCL_SUCCESS;
     107              : }
     108              : 
     109              : }; // namespace Hccl
     110              : 
        

Generated by: LCOV version 2.0-1