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

Generated by: LCOV version 2.0-1