LCOV - code coverage report
Current view: top level - base_comm/resources/ccu/ccu_device/ccu_comp/ccu_channel/ccu_pfe - ccu_pfe_cfg_mgr.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 96.1 % 51 49
Test Date: 2026-08-25 19:18:03 Functions: 100.0 % 4 4

            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_pfe_cfg_mgr.h"
      12              : 
      13              : #include <unordered_set>
      14              : 
      15              : #include "hccl_common.h"
      16              : #include "eid_info_mgr.h"
      17              : #include "ccu_res_specs.h"
      18              : 
      19              : namespace hcomm {
      20              : 
      21          581 : CcuPfeCfgMgr& CcuPfeCfgMgr::GetInstance(const int32_t deviceLogicId)
      22              : {
      23          647 :     static CcuPfeCfgMgr ccuPfeCfgMgr[MAX_MODULE_DEVICE_NUM + 1];
      24              : 
      25          581 :     int32_t devLogicId = deviceLogicId;
      26          581 :     if (devLogicId < 0 || static_cast<uint32_t>(devLogicId) >= MAX_MODULE_DEVICE_NUM) {
      27            0 :         HCCL_WARNING(
      28              :             "[CcuPfeCfgMgr][%s] use the backup device, devLogicId[%d] should be "
      29              :             "less than %u.",
      30              :             __func__, devLogicId, MAX_MODULE_DEVICE_NUM);
      31            0 :         devLogicId = MAX_MODULE_DEVICE_NUM; // 使用备份设备
      32              :     }
      33              : 
      34          581 :     ccuPfeCfgMgr[devLogicId].devLogicId_ = deviceLogicId;
      35              : 
      36          581 :     return ccuPfeCfgMgr[devLogicId];
      37              : }
      38              : 
      39          178 : HcclResult CcuPfeCfgMgr::Init()
      40              : {
      41          178 :     if (initFlag_) {
      42           79 :         return HcclResult::HCCL_SUCCESS;
      43              :     }
      44              : 
      45           99 :     CHK_RET(hrtGetDevicePhyIdByIndex(static_cast<uint32_t>(devLogicId_), devPhyId_));
      46              : 
      47           99 :     std::vector<DevEidInfo> eidInfos;
      48           99 :     CHK_RET(EidInfoMgr::GetInstance(devPhyId_).GetEidInfos(eidInfos));
      49              : 
      50           99 :     bool dieEnableFlags[CCU_MAX_IODIE_NUM] = {false, false};
      51          297 :     for (uint8_t i = 0; i < CCU_MAX_IODIE_NUM; i++) {
      52          198 :         const auto& ccuResSpecs = CcuResSpecifications::GetInstance(devLogicId_);
      53          198 :         (void)ccuResSpecs.GetDieEnableFlag(i, dieEnableFlags[i]);
      54              :     }
      55              : 
      56              :     // 不同die的feId独立分配,可能一致,需要die粒度去重
      57           99 :     std::array<std::unordered_set<uint32_t>, CCU_MAX_IODIE_NUM> dieFuncIdSet;
      58          396 :     for (auto& param : eidInfos) {
      59          297 :         const uint32_t dieId = param.dieId;
      60          297 :         if (dieId >= CCU_MAX_IODIE_NUM) {
      61          101 :             continue; // 跳过HCCL不使用的dieId
      62              :         }
      63              : 
      64          297 :         if (!dieEnableFlags[dieId]) {
      65            3 :             continue; // die如果未使能认为无需分配
      66              :         }
      67              : 
      68          294 :         const uint32_t feId = param.funcId;
      69          294 :         if (dieFuncIdSet[dieId].find(feId) != dieFuncIdSet[dieId].end()) {
      70           98 :             continue; // 跳过已配置的feId
      71              :         }
      72              : 
      73          196 :         constexpr uint32_t startJettyCtxId = 0;
      74          196 :         constexpr uint32_t startTaJettyId = CCU_START_TA_JETTY_ID;
      75          196 :         constexpr uint8_t pfeJettyNum = CCU_PER_DIE_JETTY_RESERVED_NUM;
      76              : 
      77          196 :         PfeJettyCtxCfg cfg{feId, startJettyCtxId, startTaJettyId, pfeJettyNum};
      78          196 :         pfeJettyCtxCfgs_[dieId].emplace_back(std::move(cfg));
      79          196 :         dieFuncIdSet[dieId].insert(feId);
      80              : 
      81          196 :         HCCL_RUN_INFO(
      82              :             "[CcuPfeCfgMgr] new pfe cfg set: dieId[%u] feId[%u] startJettyCtxId[%u] "
      83              :             "startTaJettyId[%u] pfeJettyNum[%u].",
      84              :             dieId, feId, startJettyCtxId, startTaJettyId, pfeJettyNum);
      85              :     }
      86              : 
      87           99 :     initFlag_ = true;
      88           99 :     return HcclResult::HCCL_SUCCESS;
      89           99 : }
      90              : 
      91          175 : HcclResult CcuPfeCfgMgr::Deinit()
      92              : {
      93          525 :     for (auto& cfg : pfeJettyCtxCfgs_) {
      94          350 :         cfg.clear();
      95              :     }
      96          175 :     initFlag_ = false;
      97          175 :     return HcclResult::HCCL_SUCCESS;
      98              : }
      99              : 
     100          228 : std::vector<PfeJettyCtxCfg> CcuPfeCfgMgr::GetPfeJettyCtxCfg(const uint8_t dieId)
     101              : {
     102          228 :     if (dieId >= CCU_MAX_IODIE_NUM) {
     103            1 :         HCCL_WARNING("[CcuPfeCfgMgr][PfeJettyCtxCfg] invalid dieId[%u]", dieId);
     104            1 :         return std::vector<PfeJettyCtxCfg>();
     105              :     }
     106              : 
     107          227 :     if (pfeJettyCtxCfgs_[dieId].empty()) {
     108           23 :         HCCL_WARNING("[CcuPfeCfgMgr][PfeJettyCtxCfg] pfeJettyCtxCfgMap is empty, dieId[%u]", dieId);
     109           23 :         return std::vector<PfeJettyCtxCfg>();
     110              :     }
     111              : 
     112          204 :     return pfeJettyCtxCfgs_[dieId];
     113              : }
     114              : 
     115              : } // namespace hcomm
        

Generated by: LCOV version 2.0-1