LCOV - code coverage report
Current view: top level - base_comm/resources/ccu/ccu_device/ccu_comp/ccu_channel/ccu_channel_ctx_v2 - ccu_wqebb_mgr_v2.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 34 34
Test Date: 2026-08-04 10:52:23 Functions: 100.0 % 3 3

            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_wqebb_mgr_v2.h"
      12              : 
      13              : #include "ccu_res_specs.h"
      14              : 
      15              : namespace hcomm {
      16              : 
      17           59 : HcclResult CcuWqeBBMgrV2::Init()
      18              : {
      19           59 :     uint32_t wqeBBNum = 0; // 获取失败或为0场景,分配将按资源不足操作
      20           59 :     uint32_t jettyNum = 0;
      21           59 :     uint32_t blockNum = 0;
      22           59 :     (void)CcuResSpecifications::GetInstance(devLogicId_).GetWqeBBNum(dieId_, wqeBBNum);
      23           59 :     (void)CcuResSpecifications::GetInstance(devLogicId_).GetJettyNum(dieId_, jettyNum);
      24           59 :     if (jettyNum == 0) {
      25            1 :         HCCL_WARNING("[CcuWqeBBMgrV2][%s] failed, jettyNum is [%u].", __func__, jettyNum);
      26            1 :         return HcclResult::HCCL_E_UNAVAIL;
      27              :     }
      28              : 
      29           58 :     blockNum = wqeBBNum / CCU_V2_FIXED_SQ_SIZE;
      30           58 :     allocatedWqeBBBlocks_.resize(blockNum, false);
      31           58 :     return HcclResult::HCCL_SUCCESS;
      32              : }
      33              : 
      34           47 : HcclResult CcuWqeBBMgrV2::Alloc(const WqeBBReq& wqeBBReq, ResInfo &wqeBBInfo)
      35              : {
      36           47 :     wqeBBInfo.startId = wqeBBReq.jettyCtxStartId * CCU_V2_FIXED_SQ_SIZE;
      37           47 :     wqeBBInfo.num = CCU_V2_FIXED_SQ_SIZE;
      38              :     // 检查是否可用,防止重新分配
      39           47 :     if (wqeBBReq.jettyCtxStartId >= allocatedWqeBBBlocks_.size()) { 
      40            1 :         HCCL_ERROR("[CcuWqeBBMgrV2][%s] failed, jetty ctx start id[%u] is not expected, "
      41              :             "more than specNum[%zu].", __func__, wqeBBReq.jettyCtxStartId,  allocatedWqeBBBlocks_.size());
      42            1 :         return HcclResult::HCCL_E_INTERNAL;
      43              :     }
      44              : 
      45           46 :     if (allocatedWqeBBBlocks_[wqeBBReq.jettyCtxStartId]) {
      46            1 :         HCCL_ERROR("[CcuWqeBBMgrV2][%s] failed, the jetty ctx id[%u] has been allocated.",
      47              :             __func__, wqeBBReq.jettyCtxStartId);
      48            1 :         return HcclResult::HCCL_E_INTERNAL;
      49              :     }
      50              : 
      51           45 :     allocatedWqeBBBlocks_[wqeBBReq.jettyCtxStartId] = true;
      52           45 :     HCCL_INFO("[CcuWqeBBMgrV2][%s] jettyCtxStartId[%u], wqeBBInfo.startId[%u], wqeBBInfo.num[%u]",
      53              :         __func__, wqeBBReq.jettyCtxStartId, wqeBBInfo.startId, wqeBBInfo.num);
      54           45 :     return HcclResult::HCCL_SUCCESS;
      55              : }
      56              : 
      57            6 : HcclResult CcuWqeBBMgrV2::Release(const ResInfo &wqeBBInfo)
      58              : {
      59            6 :     auto startId = wqeBBInfo.startId / CCU_V2_FIXED_SQ_SIZE;
      60            6 :     if (startId >= allocatedWqeBBBlocks_.size()) {
      61            1 :         HCCL_ERROR("[CcuWqeBBMgrV2][%s] failed, jetty ctx start id[%u] is not expected, "
      62              :             "more than specNum[%zu].", __func__, startId,  allocatedWqeBBBlocks_.size());
      63            1 :         return HcclResult::HCCL_E_INTERNAL;
      64              :     }
      65              : 
      66            5 :     if (!allocatedWqeBBBlocks_[startId]) {
      67            1 :         HCCL_ERROR("[CcuWqeBBMgrV2][%s] failed, jetty ctx start id[%u] is not allocated.",
      68              :             __func__, startId, allocatedWqeBBBlocks_.size());
      69            1 :         return HcclResult::HCCL_E_PARA;
      70              :     }
      71              : 
      72            4 :     allocatedWqeBBBlocks_[startId] = false;
      73            4 :     return HcclResult::HCCL_SUCCESS;
      74              : }
      75              : 
      76              : }; // namespace hcomm
        

Generated by: LCOV version 2.0-1