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-18 17:47:01 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          571 : CcuPfeCfgMgr& CcuPfeCfgMgr::GetInstance(const int32_t deviceLogicId)
      22              : {
      23          637 :     static CcuPfeCfgMgr ccuPfeCfgMgr[MAX_MODULE_DEVICE_NUM + 1];
      24              : 
      25          571 :     int32_t devLogicId = deviceLogicId;
      26          571 :     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          571 :     ccuPfeCfgMgr[devLogicId].devLogicId_ = deviceLogicId;
      35              : 
      36          571 :     return ccuPfeCfgMgr[devLogicId];
      37              : }
      38              : 
      39          174 : HcclResult CcuPfeCfgMgr::Init()
      40              : {
      41          174 :     if (initFlag_) {
      42           77 :         return HcclResult::HCCL_SUCCESS;
      43              :     }
      44              : 
      45           97 :     CHK_RET(hrtGetDevicePhyIdByIndex(static_cast<uint32_t>(devLogicId_), devPhyId_));
      46              : 
      47           97 :     std::vector<DevEidInfo> eidInfos;
      48           97 :     CHK_RET(EidInfoMgr::GetInstance(devPhyId_).GetEidInfos(eidInfos));
      49              : 
      50           97 :     bool dieEnableFlags[CCU_MAX_IODIE_NUM] = {false, false};
      51          291 :     for (uint8_t i = 0; i < CCU_MAX_IODIE_NUM; i++) {
      52          194 :         const auto& ccuResSpecs = CcuResSpecifications::GetInstance(devLogicId_);
      53          194 :         (void)ccuResSpecs.GetDieEnableFlag(i, dieEnableFlags[i]);
      54              :     }
      55              : 
      56              :     // 不同die的feId独立分配,可能一致,需要die粒度去重
      57           97 :     std::array<std::unordered_set<uint32_t>, CCU_MAX_IODIE_NUM> dieFuncIdSet;
      58          388 :     for (auto& param : eidInfos) {
      59          291 :         const uint32_t dieId = param.dieId;
      60          291 :         if (dieId >= CCU_MAX_IODIE_NUM) {
      61           99 :             continue; // 跳过HCCL不使用的dieId
      62              :         }
      63              : 
      64          291 :         if (!dieEnableFlags[dieId]) {
      65            3 :             continue; // die如果未使能认为无需分配
      66              :         }
      67              : 
      68          288 :         const uint32_t feId = param.funcId;
      69          288 :         if (dieFuncIdSet[dieId].find(feId) != dieFuncIdSet[dieId].end()) {
      70           96 :             continue; // 跳过已配置的feId
      71              :         }
      72              : 
      73          192 :         constexpr uint32_t startJettyCtxId = 0;
      74          192 :         constexpr uint32_t startTaJettyId = CCU_START_TA_JETTY_ID;
      75          192 :         constexpr uint8_t pfeJettyNum = CCU_PER_DIE_JETTY_RESERVED_NUM;
      76              : 
      77          192 :         PfeJettyCtxCfg cfg{feId, startJettyCtxId, startTaJettyId, pfeJettyNum};
      78          192 :         pfeJettyCtxCfgs_[dieId].emplace_back(std::move(cfg));
      79          192 :         dieFuncIdSet[dieId].insert(feId);
      80              : 
      81          192 :         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           97 :     initFlag_ = true;
      88           97 :     return HcclResult::HCCL_SUCCESS;
      89           97 : }
      90              : 
      91          173 : HcclResult CcuPfeCfgMgr::Deinit()
      92              : {
      93          519 :     for (auto& cfg : pfeJettyCtxCfgs_) {
      94          346 :         cfg.clear();
      95              :     }
      96          173 :     initFlag_ = false;
      97          173 :     return HcclResult::HCCL_SUCCESS;
      98              : }
      99              : 
     100          224 : std::vector<PfeJettyCtxCfg> CcuPfeCfgMgr::GetPfeJettyCtxCfg(const uint8_t dieId)
     101              : {
     102          224 :     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          223 :     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          200 :     return pfeJettyCtxCfgs_[dieId];
     113              : }
     114              : 
     115              : } // namespace hcomm
        

Generated by: LCOV version 2.0-1