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 "tp_mgr.h"
12 :
13 : #include <algorithm>
14 : #include <vector>
15 :
16 : #include "hccp_ctx.h"
17 : #include "hccp_async_ctx.h"
18 :
19 : #include "hccl_common.h"
20 : #include "exception_handler.h"
21 : #include "network_api_exception.h"
22 : #include "orion_adapter_hccp.h"
23 : #include "rdma_handle_manager.h"
24 : #include "dev_type.h"
25 : #include "orion_adapter_rts.h"
26 : #include "env_config/env_config.h"
27 : #include "tp_qos.h"
28 :
29 : namespace hcomm {
30 :
31 : namespace {
32 : constexpr uint32_t kTpAttrSlAvailableBit = 17U;
33 : static constexpr uint32_t kTpAttrBitmapSl = (1U << 10U);
34 : static constexpr uint32_t kTpAttrBitmapDscp = (1U << 8U);
35 : static constexpr uint32_t kTpAttrDscpConfigModeBit = 18U;
36 :
37 728 : static constexpr QosKey QosMapKey(uint32_t qos) noexcept
38 : {
39 728 : return static_cast<QosKey>(qos & 0xFFU);
40 : }
41 :
42 : // MAINBOARD_PCIE_STD(PCIE 标卡):跳过 GetTpAttr/SL 策略,固定使用 TP 列表首个 TP;
43 : // jetty priority(SL)取 2,为标卡 UB 互通方案约定档位,与现网标卡环境对齐。
44 : static constexpr uint32_t kPcieStdMappedSl = 2U;
45 :
46 268 : static HcclResult IsPcieStdMainboardByPhyId(uint32_t devPhyId, bool &isPcieStd)
47 : {
48 268 : isPcieStd = false;
49 268 : u32 devLogicId = 0U;
50 268 : CHK_RET(hrtGetDeviceIndexByPhyId(devPhyId, devLogicId));
51 268 : Hccl::HcclMainboardId mainboardId = Hccl::HcclMainboardId::MAINBOARD_OTHERS;
52 268 : CHK_RET(Hccl::HrtGetMainboardId(devLogicId, mainboardId));
53 268 : isPcieStd = (mainboardId == Hccl::HcclMainboardId::MAINBOARD_PCIE_STD);
54 268 : return HcclResult::HCCL_SUCCESS;
55 : }
56 :
57 : struct TpInfoAddrKey {
58 : Hccl::IpAddress locAddr{};
59 : Hccl::IpAddress rmtAddr{};
60 : QosKey qosKey{0};
61 : };
62 :
63 639 : static HcclResult ResolveTpInfoAddrKey(const GetTpInfoParam ¶m, TpInfoAddrKey &out)
64 : {
65 639 : CHK_RET(CommAddrToIpAddress(param.locAddr, out.locAddr));
66 639 : CHK_RET(CommAddrToIpAddress(param.rmtAddr, out.rmtAddr));
67 639 : out.qosKey = QosMapKey(param.qos);
68 639 : return HcclResult::HCCL_SUCCESS;
69 : }
70 :
71 178 : static uint32_t CalSlAvailableCnt(uint32_t mask)
72 : {
73 178 : uint32_t c = 0;
74 3026 : for (uint32_t i = 0; i < 16U; ++i) {
75 2848 : if ((mask & (1U << i)) != 0U) {
76 526 : ++c;
77 : }
78 : }
79 178 : return c;
80 : }
81 :
82 89 : static uint32_t SlValueAtRankInMask16(uint32_t mask, uint32_t rank)
83 : {
84 89 : uint32_t seen = 0;
85 154 : for (uint32_t bit = 0; bit < 16U; ++bit) {
86 154 : if ((mask & (1U << bit)) != 0U) {
87 119 : if (seen == rank) {
88 89 : return bit;
89 : }
90 30 : ++seen;
91 : }
92 : }
93 0 : return 0;
94 : }
95 :
96 96 : static uint16_t ReadSlAvailableMask16(const struct TpAttr &attr)
97 : {
98 96 : return static_cast<uint16_t>(attr.slBitmap);
99 : }
100 :
101 89 : static uint32_t ResolveSlAvailableCntForPolicy(uint16_t slMask, uint32_t slLevelCount)
102 : {
103 89 : uint32_t slAvailableCnt = CalSlAvailableCnt(slMask);
104 89 : if (slLevelCount != 0U) {
105 1 : slAvailableCnt = std::min(slLevelCount, slAvailableCnt);
106 : }
107 89 : return slAvailableCnt;
108 : }
109 :
110 89 : static bool ApplyQosTpSlPolicy(const GetTpInfoParam ¶m, uint16_t slMask,
111 : uint32_t &tpListIndexOut, uint32_t &mappedSlOut)
112 : {
113 89 : const uint32_t slAvailableCnt = ResolveSlAvailableCntForPolicy(slMask, param.slLevelCount);
114 89 : if (slAvailableCnt == 0U) {
115 0 : return false;
116 : }
117 89 : if (param.loopFirstTpLowestSl) {
118 64 : tpListIndexOut = 0U;
119 64 : mappedSlOut = SlValueAtRankInMask16(slMask, 0U);
120 64 : return true;
121 : }
122 :
123 25 : const uint32_t qos = param.qos;
124 25 : const uint32_t numGroups = slAvailableCnt;
125 25 : const uint32_t groupIdx = Hccl::TpQosResolveQosSlGroupIdx(qos, numGroups);
126 25 : if (groupIdx >= numGroups) {
127 0 : HCCL_ERROR("[TpMgr][%s] groupIdx out of range: groupIdx[%u] numGroups[%u] qos[%u] slAvailableCnt[%u].",
128 : __func__, groupIdx, numGroups, qos, slAvailableCnt);
129 0 : return false;
130 : }
131 :
132 25 : tpListIndexOut = 0U;
133 25 : const uint32_t slRank = (slAvailableCnt - 1U) - groupIdx;
134 25 : mappedSlOut = SlValueAtRankInMask16(slMask, slRank);
135 25 : return true;
136 : }
137 :
138 7 : static uint8_t ResolveUboeDscpLookupQos(const GetTpInfoParam ¶m, uint32_t nTp, uint16_t slMask)
139 : {
140 : (void)nTp;
141 : (void)slMask;
142 7 : if (param.loopFirstTpLowestSl) {
143 1 : return 0U;
144 : }
145 6 : return static_cast<uint8_t>(param.qos & 0xFFU);
146 : }
147 :
148 : /// isSync=false(异步 GetTpInfo 写回 SL/DSCP):HrtRaSetTpAttrAsync。
149 : /// 阻塞等待在 adapter 内(RaSetTpAttrAsync + WaitRequestResult),本函数返回时 Set 已生效。
150 : /// 不用 RaCtxSetTpAttr,避免 Rs 路径 phyId 无效(与 TpManager::SetTpAttrAsync 一致)。
151 92 : static HcclResult SetTpAttrAsync(const Hccl::RdmaHandle rdmaHandle, uint64_t tpHandle, uint32_t attrBitmap,
152 : struct TpAttr &attr, const char *logTag)
153 : {
154 92 : Hccl::RequestHandle reqHandle = 0;
155 : try {
156 : const HcclResult hret =
157 92 : Hccl::HrtRaSetTpAttrAsync(rdmaHandle, tpHandle, attrBitmap, attr, reqHandle);
158 92 : if (hret != HcclResult::HCCL_SUCCESS) {
159 0 : HCCL_ERROR("[TpMgr][%s] HrtRaSetTpAttrAsync failed hcclRet[%d] tpHandle[%llu].", logTag,
160 : static_cast<int>(hret), tpHandle);
161 : }
162 92 : return hret;
163 0 : } catch (const Hccl::NetworkApiException &ex) {
164 0 : HCCL_ERROR("[TpMgr][%s] HrtRaSetTpAttrAsync exception: %s tpHandle[%llu].", logTag, ex.what(), tpHandle);
165 0 : return HcclResult::HCCL_E_NETWORK;
166 0 : }
167 : }
168 :
169 85 : static HcclResult CommitMappedSlToTpAttr(const uint32_t devPhyId, const CommAddr &locCommAddr, uint64_t tpHandle,
170 : uint32_t mappedSl)
171 : {
172 85 : if (tpHandle == 0U) {
173 0 : HCCL_ERROR("[TpMgr][CommitMappedSlToTpAttr] tpHandle is 0");
174 0 : return HcclResult::HCCL_E_INTERNAL;
175 : }
176 85 : Hccl::IpAddress locAddr{};
177 85 : CHK_RET(CommAddrToIpAddress(locCommAddr, locAddr));
178 85 : const Hccl::RdmaHandle rdmaHandle = Hccl::RdmaHandleManager::GetInstance().GetByIp(devPhyId, locAddr);
179 85 : CHK_PTR_NULL(rdmaHandle);
180 :
181 85 : struct TpAttr tpSlAttr {};
182 85 : tpSlAttr.sl = static_cast<uint8_t>(mappedSl & 0xFU);
183 : const HcclResult hret =
184 85 : SetTpAttrAsync(rdmaHandle, tpHandle, kTpAttrBitmapSl, tpSlAttr, "CommitMappedSlToTpAttr");
185 85 : if (hret == HcclResult::HCCL_SUCCESS) {
186 85 : HCCL_INFO("[TpMgr][CommitMappedSlToTpAttr] ok tpHandle[%llu] sl[%u].", tpHandle,
187 : static_cast<unsigned>(mappedSl & 0xFU));
188 : }
189 85 : return hret;
190 : }
191 :
192 7 : static HcclResult CommitUboeDscpToTpAttr(const uint32_t devPhyId, const CommAddr &locCommAddr, uint64_t tpHandle,
193 : uint8_t dscp)
194 : {
195 7 : if (tpHandle == 0U) {
196 0 : HCCL_ERROR("[TpMgr][CommitUboeDscpToTpAttr] tpHandle is 0");
197 0 : return HcclResult::HCCL_E_INTERNAL;
198 : }
199 7 : Hccl::IpAddress locAddr{};
200 7 : CHK_RET(CommAddrToIpAddress(locCommAddr, locAddr));
201 7 : const Hccl::RdmaHandle rdmaHandle = Hccl::RdmaHandleManager::GetInstance().GetByIp(devPhyId, locAddr);
202 7 : CHK_PTR_NULL(rdmaHandle);
203 :
204 7 : struct TpAttr tpDscpAttr {};
205 7 : tpDscpAttr.dscp = static_cast<uint8_t>(dscp & 0x3FU);
206 : const HcclResult hret =
207 7 : SetTpAttrAsync(rdmaHandle, tpHandle, kTpAttrBitmapDscp, tpDscpAttr, "CommitUboeDscpToTpAttr");
208 7 : if (hret == HcclResult::HCCL_SUCCESS) {
209 7 : HCCL_INFO("[TpMgr][CommitUboeDscpToTpAttr] ok tpHandle[%llu] dscp[%u].", tpHandle,
210 : static_cast<unsigned>(tpDscpAttr.dscp));
211 : }
212 7 : return hret;
213 : }
214 :
215 : } // namespace
216 :
217 315 : TpMgr &TpMgr::GetInstance(const uint32_t devicePhyId)
218 : {
219 447 : static TpMgr tpMgr[MAX_MODULE_DEVICE_NUM + 1];
220 :
221 315 : uint32_t devPhyId = devicePhyId;
222 315 : if (devPhyId >= MAX_MODULE_DEVICE_NUM) {
223 1 : HCCL_WARNING("[TpMgr][%s] use the backup device, devPhyId[%u] should be "
224 : "less than %u.",
225 : __func__, devPhyId, MAX_MODULE_DEVICE_NUM);
226 1 : devPhyId = MAX_MODULE_DEVICE_NUM;
227 : }
228 :
229 315 : tpMgr[devPhyId].devPhyId_ = devPhyId;
230 :
231 315 : return tpMgr[devPhyId];
232 : }
233 :
234 211 : static HcclResult CheckRequestResult(RequestHandle &reqHandle)
235 : {
236 211 : if (reqHandle == 0) {
237 0 : return HcclResult::HCCL_SUCCESS;
238 : }
239 :
240 211 : RequestResult result = HccpGetAsyncReqResult(reqHandle);
241 211 : if (result == RequestResult::NOT_COMPLETED) {
242 0 : return HcclResult::HCCL_E_AGAIN;
243 : }
244 :
245 211 : if (result != RequestResult::COMPLETED) {
246 0 : HCCL_ERROR("[TpMgr][%s] failed, result[%s] is unexpected.", __func__, result.Describe().c_str());
247 0 : return HcclResult::HCCL_E_NETWORK;
248 : }
249 :
250 211 : return HcclResult::HCCL_SUCCESS;
251 : }
252 :
253 284 : HcclResult CheckTpProtocol(const TpProtocol tpProtocol)
254 : {
255 284 : if (tpProtocol != TpProtocol::CTP && tpProtocol != TpProtocol::RTP && tpProtocol != TpProtocol::UBOE) {
256 1 : HCCL_ERROR("[TpMgr][%s] failed, tpProtocol[%d] is not supported.", __func__, tpProtocol);
257 1 : return HcclResult::HCCL_E_NOT_SUPPORT;
258 : }
259 :
260 283 : return HcclResult::HCCL_SUCCESS;
261 : }
262 :
263 360 : HcclResult TpMgr::LookupInfoCtxEntry(InfoCtxMap &infoMap, const Hccl::IpAddress &locAddr,
264 : const Hccl::IpAddress &rmtAddr, const QosKey qosKey, InfoCtxMap::iterator &lit, InfoRmtMap::iterator &rit,
265 : InfoQosMap::iterator &qosIt) const
266 : {
267 360 : lit = infoMap.find(locAddr);
268 360 : if (lit == infoMap.end()) {
269 282 : return HcclResult::HCCL_E_NOT_FOUND;
270 : }
271 78 : rit = lit->second.find(rmtAddr);
272 78 : if (rit == lit->second.end()) {
273 0 : return HcclResult::HCCL_E_NOT_FOUND;
274 : }
275 78 : qosIt = rit->second.find(qosKey);
276 78 : if (qosIt == rit->second.end()) {
277 4 : return HcclResult::HCCL_E_NOT_FOUND;
278 : }
279 74 : return HcclResult::HCCL_SUCCESS;
280 : }
281 :
282 283 : HcclResult TpMgr::FindAndGetTpInfo(const GetTpInfoParam ¶m, TpInfo &tpInfo)
283 : {
284 283 : TpInfoAddrKey key{};
285 283 : CHK_RET(ResolveTpInfoAddrKey(param, key));
286 283 : std::lock_guard<std::mutex> lock(GetInfoCtxMutex(param.tpProtocol));
287 283 : auto &infoMap = GetInfoCtxMap(param.tpProtocol);
288 283 : InfoCtxMap::iterator lit;
289 283 : InfoRmtMap::iterator rit;
290 283 : InfoQosMap::iterator qosIt;
291 283 : const auto lookupRet = LookupInfoCtxEntry(infoMap, key.locAddr, key.rmtAddr, key.qosKey, lit, rit, qosIt);
292 283 : if (lookupRet != HcclResult::HCCL_SUCCESS) {
293 279 : return lookupRet;
294 : }
295 : // 复用缓存:useCnt 仅在此处(命中)递增,与 CommitTpInfoToCache 写入路径分离。
296 4 : qosIt->second.useCnt += 1;
297 4 : tpInfo = qosIt->second.tpInfo;
298 4 : return HcclResult::HCCL_SUCCESS;
299 283 : }
300 :
301 100 : HcclResult TpMgr::BeginGetTpInfoListRequest(const GetTpInfoParam ¶m, ReqQosMap &qosMap, const QosKey qosKey)
302 : {
303 100 : RequestCtx &reqCtx = qosMap[qosKey];
304 100 : CHK_RET(StartGetTpInfoListRequest(param, reqCtx));
305 100 : HCCL_INFO("[TpMgr][GetTpInfo] RaGetTpInfoListAsync submitted, devPhyId[%u] reqHandle[%llu] phase[WAIT_LIST] "
306 : "param[%s].",
307 : devPhyId_, static_cast<unsigned long long>(reqCtx.handle), param.Describe().c_str());
308 100 : return HcclResult::HCCL_E_AGAIN;
309 : }
310 :
311 90 : HcclResult TpMgr::AdvanceGetTpInfoWaitList(const GetTpInfoParam ¶m, RequestCtx &reqCtx, ReqQosMap &qosMap,
312 : const ReqQosMap::iterator it, std::unique_lock<std::mutex> &reqCtxLock, TpInfo &tpInfo)
313 : {
314 90 : if (reqCtx.tpInfoNum == 0U) {
315 0 : qosMap.erase(it);
316 0 : reqCtxLock.unlock();
317 0 : HCCL_WARNING("[TpMgr][%s] failed to find tp info, tpInfoNum is 0, param[%s].", __func__, param.Describe().c_str());
318 0 : return HcclResult::HCCL_E_NOT_FOUND;
319 : }
320 90 : bool isPcieStd = false;
321 90 : CHK_RET(IsPcieStdMainboardByPhyId(devPhyId_, isPcieStd));
322 90 : if (isPcieStd) {
323 0 : const struct HccpTpInfo *list = reinterpret_cast<const struct HccpTpInfo *>(reqCtx.dataBuffer.data());
324 0 : HCCL_INFO("[TpMgr][%s] pcie std mainboard: skip GetTpAttr, devPhyId[%u] tpInfoNum[%u] mappedSl[%u] "
325 : "tpHandle[%llu] param[%s].",
326 : __func__, devPhyId_, reqCtx.tpInfoNum, kPcieStdMappedSl,
327 : static_cast<unsigned long long>(list[0].tpHandle), param.Describe().c_str());
328 0 : RequestCtx completedReqCtx = std::move(it->second);
329 0 : qosMap.erase(it);
330 0 : reqCtxLock.unlock();
331 0 : CHK_RET(HandleCompletedRequest(std::move(completedReqCtx), param, tpInfo));
332 0 : return HcclResult::HCCL_SUCCESS;
333 0 : }
334 90 : const struct HccpTpInfo *list = reinterpret_cast<const struct HccpTpInfo *>(reqCtx.dataBuffer.data());
335 90 : HCCL_INFO("[TpMgr][GetTpInfo] list stage ok, devPhyId[%u] tpInfoNum[%u] firstTpHandle[%llu] param[%s].",
336 : devPhyId_, reqCtx.tpInfoNum, static_cast<unsigned long long>(list[0].tpHandle), param.Describe().c_str());
337 : try {
338 90 : CHK_RET(StartGetTpAttrForFirstTp(param, reqCtx));
339 0 : } catch (...) {
340 0 : qosMap.erase(it);
341 0 : throw;
342 0 : }
343 90 : HCCL_INFO("[TpMgr][GetTpInfo] RaGetTpAttrAsync submitted, devPhyId[%u] reqHandle[%llu] phase[WAIT_TP_ATTR] "
344 : "tpAttrBitmap[0x%x] param[%s].",
345 : devPhyId_, static_cast<unsigned long long>(reqCtx.handle), reqCtx.tpAttrBitmap, param.Describe().c_str());
346 90 : return HcclResult::HCCL_E_AGAIN;
347 : }
348 :
349 279 : HcclResult TpMgr::PollGetTpInfoReqCtx(std::unique_lock<std::mutex> &reqCtxLock, const GetTpInfoParam ¶m,
350 : TpInfo &tpInfo)
351 : {
352 279 : auto &reqCtxMap = GetReqCtxMap(param.tpProtocol);
353 279 : TpInfoAddrKey key{};
354 279 : CHK_RET(ResolveTpInfoAddrKey(param, key));
355 279 : auto &qosMap = reqCtxMap[key.locAddr][key.rmtAddr];
356 279 : auto it = qosMap.find(key.qosKey);
357 279 : if (it == qosMap.end()) {
358 100 : return BeginGetTpInfoListRequest(param, qosMap, key.qosKey);
359 : }
360 :
361 179 : RequestCtx &reqCtx = it->second;
362 179 : const auto ret = CheckRequestResult(reqCtx.handle);
363 179 : if (ret == HcclResult::HCCL_E_AGAIN) {
364 0 : return ret;
365 : }
366 179 : CHK_RET(ret);
367 :
368 179 : if (reqCtx.phase == ReqPhase::WAIT_LIST) {
369 90 : return AdvanceGetTpInfoWaitList(param, reqCtx, qosMap, it, reqCtxLock, tpInfo);
370 : }
371 :
372 : // 先 move 出槽位再 erase,避免 erase 析构槽内对象后再 move(UB / double free)
373 89 : RequestCtx completedReqCtx = std::move(it->second);
374 89 : qosMap.erase(it);
375 89 : reqCtxLock.unlock();
376 89 : CHK_RET(HandleCompletedRequest(std::move(completedReqCtx), param, tpInfo));
377 89 : return HcclResult::HCCL_SUCCESS;
378 89 : }
379 :
380 284 : HcclResult TpMgr::GetTpInfo(const GetTpInfoParam ¶m, TpInfo &tpInfo)
381 : {
382 284 : CHK_RET(CheckTpProtocol(param.tpProtocol));
383 283 : if (FindAndGetTpInfo(param, tpInfo) == HcclResult::HCCL_SUCCESS) {
384 4 : return HcclResult::HCCL_SUCCESS;
385 : }
386 :
387 279 : std::unique_lock<std::mutex> reqCtxLock(GetReqCtxMutex(param.tpProtocol));
388 279 : return PollGetTpInfoReqCtx(reqCtxLock, param, tpInfo);
389 279 : }
390 :
391 77 : HcclResult TpMgr::ReleaseTpInfo(const GetTpInfoParam ¶m, const TpInfo &tpInfo)
392 : {
393 77 : TpInfoAddrKey key{};
394 77 : CHK_RET(ResolveTpInfoAddrKey(param, key));
395 77 : std::lock_guard<std::mutex> lock(GetInfoCtxMutex(param.tpProtocol));
396 77 : auto &infoMap = GetInfoCtxMap(param.tpProtocol);
397 77 : InfoCtxMap::iterator lit;
398 77 : InfoRmtMap::iterator rmtIt;
399 77 : InfoQosMap::iterator qosIt;
400 77 : const auto lookupRet = LookupInfoCtxEntry(infoMap, key.locAddr, key.rmtAddr, key.qosKey, lit, rmtIt, qosIt);
401 77 : if (lookupRet != HcclResult::HCCL_SUCCESS) {
402 7 : if (lit == infoMap.end()) {
403 6 : HCCL_ERROR("[TpMgr][%s] failed, tp info is not found, param[%s].", __func__, param.Describe().c_str());
404 1 : } else if (rmtIt == lit->second.end()) {
405 0 : HCCL_ERROR("[TpMgr][%s] failed, tp info is not found, param[%s].", __func__, param.Describe().c_str());
406 : } else {
407 1 : HCCL_ERROR("[TpMgr][%s] failed, tp info is not found for qosKey[%u], param[%s].", __func__,
408 : static_cast<unsigned>(key.qosKey), param.Describe().c_str());
409 : }
410 7 : return HcclResult::HCCL_E_NOT_FOUND;
411 : }
412 :
413 : // 未入缓存的并发 GetTpInfo 结果:与缓存 tpHandle 不一致,无需操作缓存。
414 70 : if (tpInfo.tpHandle != qosIt->second.tpInfo.tpHandle) {
415 1 : return HcclResult::HCCL_SUCCESS;
416 : }
417 :
418 69 : if (qosIt->second.useCnt > 1) {
419 3 : qosIt->second.useCnt -= 1;
420 3 : return HcclResult::HCCL_SUCCESS;
421 : }
422 :
423 66 : rmtIt->second.erase(qosIt);
424 66 : if (rmtIt->second.empty()) {
425 66 : lit->second.erase(rmtIt);
426 : }
427 66 : if (lit->second.empty()) {
428 66 : infoMap.erase(lit);
429 : }
430 66 : return HcclResult::HCCL_SUCCESS;
431 77 : }
432 :
433 100 : static HcclResult GetTpInfoListAsync(const CtxHandle ctxHandle, const GetTpInfoParam ¶m,
434 : std::vector<char> &out, uint32_t &num, RequestHandle &reqHandle)
435 : {
436 100 : Hccl::IpAddress locAddr{};
437 100 : Hccl::IpAddress rmtAddr{};
438 100 : CHK_RET(CommAddrToIpAddress(param.locAddr, locAddr));
439 100 : CHK_RET(CommAddrToIpAddress(param.rmtAddr, rmtAddr));
440 100 : const auto &tpProtocol = param.tpProtocol;
441 :
442 100 : struct GetTpCfg cfg {};
443 100 : cfg.flag.bs.rtp = tpProtocol == TpProtocol::RTP ? 1 : 0;
444 100 : cfg.flag.bs.ctp = tpProtocol == TpProtocol::CTP ? 1 : 0;
445 100 : cfg.flag.bs.uboe = tpProtocol == TpProtocol::UBOE ? 1 : 0;
446 100 : cfg.transMode = TransportModeT::CONN_RM;
447 100 : CHK_RET(IpAddressToHccpEid(locAddr, cfg.localEid));
448 100 : HCCL_INFO("RaUbGetTpInfoAsync cfg.local_eid[subnetPrefix[%016llx], interfaceId[%016llx]]",
449 : cfg.localEid.in6.subnetPrefix, cfg.localEid.in6.interfaceId);
450 100 : CHK_RET(IpAddressToHccpEid(rmtAddr, cfg.peerEid));
451 100 : HCCL_INFO("RaUbGetTpInfoAsync cfg.peer_eid[subnetPrefix[%016llx], interfaceId[%016llx]]",
452 : cfg.peerEid.in6.subnetPrefix, cfg.peerEid.in6.interfaceId);
453 :
454 : // buffer 须至少容纳本次请求的个数,避免 RS 按 num 写多条 HccpTpInfo 时越界破坏堆
455 100 : out.resize(static_cast<size_t>(Hccl::TP_HANDLE_REQUEST_NUM) * sizeof(struct HccpTpInfo));
456 100 : struct HccpTpInfo *info = reinterpret_cast<struct HccpTpInfo *>(out.data());
457 :
458 100 : void *raReqHandle = nullptr;
459 100 : num = Hccl::TP_HANDLE_REQUEST_NUM; // 指定需要从管控面申请 tp handle 的上限;完成后 num 为实际个数
460 100 : const s32 ret = RaGetTpInfoListAsync(ctxHandle, &cfg, info, &num, &raReqHandle);
461 100 : if (ret != 0 || !raReqHandle) {
462 0 : HCCL_ERROR("[%s] failed, call interface error[%d] raReqHandle[%p], ctxHandle[%p] locAddr[%s] rmtAddr[%s].",
463 : __func__, ret, raReqHandle, ctxHandle, locAddr.Describe().c_str(), rmtAddr.Describe().c_str());
464 0 : return HcclResult::HCCL_E_NETWORK;
465 : }
466 :
467 100 : reqHandle = reinterpret_cast<RequestHandle>(raReqHandle);
468 100 : HCCL_INFO("[%s] get request handle[%llu].", __func__, reqHandle);
469 100 : return HcclResult::HCCL_SUCCESS;
470 : }
471 :
472 100 : HcclResult TpMgr::StartGetTpInfoListRequest(const GetTpInfoParam ¶m, RequestCtx &reqCtx) const
473 : {
474 : EXCEPTION_HANDLE_BEGIN
475 100 : reqCtx.phase = ReqPhase::WAIT_LIST;
476 100 : reqCtx.tpAttrBitmap = 0;
477 100 : (void)memset_s(&reqCtx.tpAttr, sizeof(reqCtx.tpAttr), 0, sizeof(reqCtx.tpAttr));
478 :
479 100 : Hccl::IpAddress ipAddr{};
480 100 : CHK_RET(CommAddrToIpAddress(param.locAddr, ipAddr));
481 : const CtxHandle ctxHandle =
482 100 : static_cast<CtxHandle>(Hccl::RdmaHandleManager::GetInstance().GetByIp(devPhyId_, ipAddr));
483 100 : CHK_PTR_NULL(ctxHandle);
484 :
485 100 : CHK_RET(GetTpInfoListAsync(ctxHandle, param, reqCtx.dataBuffer, reqCtx.tpInfoNum, reqCtx.handle));
486 0 : EXCEPTION_HANDLE_END
487 100 : return HcclResult::HCCL_SUCCESS;
488 : }
489 :
490 90 : HcclResult TpMgr::StartGetTpAttrForFirstTp(const GetTpInfoParam ¶m, RequestCtx &reqCtx) const
491 : {
492 : EXCEPTION_HANDLE_BEGIN
493 90 : (void)memset_s(&reqCtx.tpAttr, sizeof(reqCtx.tpAttr), 0, sizeof(reqCtx.tpAttr));
494 90 : reqCtx.tpAttrBitmap = (1U << kTpAttrSlAvailableBit) | kTpAttrBitmapSl;
495 90 : if (param.tpProtocol == TpProtocol::UBOE) {
496 10 : reqCtx.tpAttrBitmap |= kTpAttrBitmapDscp | (1U << kTpAttrDscpConfigModeBit);
497 : }
498 :
499 90 : const struct HccpTpInfo *list = reinterpret_cast<const struct HccpTpInfo *>(reqCtx.dataBuffer.data());
500 90 : const uint64_t firstTpHandle = list[0].tpHandle;
501 :
502 90 : Hccl::IpAddress ipAddr{};
503 90 : CHK_RET(CommAddrToIpAddress(param.locAddr, ipAddr));
504 : const CtxHandle ctxHandle =
505 90 : static_cast<CtxHandle>(Hccl::RdmaHandleManager::GetInstance().GetByIp(devPhyId_, ipAddr));
506 90 : CHK_PTR_NULL(ctxHandle);
507 :
508 90 : void *raReqHandle = nullptr;
509 : const s32 ret =
510 90 : RaGetTpAttrAsync(ctxHandle, firstTpHandle, &reqCtx.tpAttrBitmap, &reqCtx.tpAttr, &raReqHandle);
511 90 : if (ret != 0 || !raReqHandle) {
512 0 : HCCL_ERROR("[TpMgr][%s] RaGetTpAttrAsync failed ret[%d] raReqHandle[%p] ctx[%p] tpHandle[%llu].", __func__,
513 : ret, raReqHandle, ctxHandle, firstTpHandle);
514 0 : return HcclResult::HCCL_E_NETWORK;
515 : }
516 90 : reqCtx.handle = reinterpret_cast<RequestHandle>(raReqHandle);
517 90 : reqCtx.phase = ReqPhase::WAIT_TP_ATTR;
518 0 : EXCEPTION_HANDLE_END
519 90 : return HcclResult::HCCL_SUCCESS;
520 : }
521 :
522 100 : HcclResult TpMgr::FindAndGetTpAttr(const TpHandle tpHandle, TpAttrInfo &tpAttrInfo)
523 : {
524 100 : std::lock_guard<std::mutex> lock(tpAttrCtxMutex_);
525 100 : auto attrIter = tpAttrCtxMap_.find(tpHandle);
526 100 : if (attrIter != tpAttrCtxMap_.end()) {
527 36 : attrIter->second.useCnt += 1;
528 36 : tpAttrInfo = attrIter->second.tpAttrInfo;
529 36 : return HcclResult::HCCL_SUCCESS;
530 : }
531 :
532 64 : return HcclResult::HCCL_E_NOT_FOUND;
533 100 : }
534 :
535 100 : HcclResult TpMgr::GetTpAttr(const GetTpAttrParam ¶m, TpAttrInfo &tpAttrInfo, CtxHandle ctxHandle)
536 : {
537 100 : const TpHandle tpHandle = param.tpHandle;
538 100 : if (FindAndGetTpAttr(tpHandle, tpAttrInfo) == HcclResult::HCCL_SUCCESS) {
539 36 : return HcclResult::HCCL_SUCCESS;
540 : }
541 :
542 64 : std::unique_lock<std::mutex> reqCtxLock(tpAttrReqMutex_);
543 64 : auto reqCtxIter = tpAttrReqCtxMap_.find(tpHandle);
544 64 : if (reqCtxIter == tpAttrReqCtxMap_.end()) {
545 32 : HCCL_INFO("[TpMgr][%s] get new tpAttr, param[%s].", __func__,
546 : param.Describe().c_str());
547 :
548 32 : TpAttrRequestCtx &reqCtx = tpAttrReqCtxMap_[tpHandle];
549 32 : CHK_RET(StartGetTpAttrRequest(param, reqCtx, ctxHandle));
550 32 : return HcclResult::HCCL_E_AGAIN;
551 : }
552 :
553 32 : auto &reqCtx = reqCtxIter->second;
554 32 : auto ret = CheckRequestResult(reqCtx.handle);
555 32 : if (ret == HcclResult::HCCL_E_AGAIN) {
556 0 : return ret;
557 : }
558 32 : CHK_RET(ret);
559 :
560 32 : TpAttrRequestCtx completedReqCtx = reqCtxIter->second;
561 32 : tpAttrReqCtxMap_.erase(reqCtxIter);
562 32 : reqCtxLock.unlock();
563 32 : CHK_RET(HandleCompletedTpAttrRequest(std::move(completedReqCtx), tpHandle, tpAttrInfo));
564 32 : return HcclResult::HCCL_SUCCESS;
565 64 : }
566 :
567 32 : HcclResult TpMgr::StartGetTpAttrRequest(const GetTpAttrParam ¶m,
568 : TpMgr::TpAttrRequestCtx &reqCtx, CtxHandle ctxHandle) const
569 : {
570 32 : void *raReqHandle = nullptr;
571 64 : s32 ret = RaGetTpAttrAsync(ctxHandle, param.tpHandle,
572 32 : const_cast<uint32_t*>(¶m.attrBitmap), &reqCtx.tpAttr, &raReqHandle);
573 32 : if (ret != 0 || !raReqHandle) {
574 0 : HCCL_ERROR("[TpMgr][%s] failed, call RaGetTpAttrAsync error[%d] raReqHandle[%p], "
575 : "tpHandle[0x%llx] attrBitmap[0x%x].", __func__, ret, raReqHandle,
576 : param.tpHandle, param.attrBitmap);
577 0 : return HcclResult::HCCL_E_NETWORK;
578 : }
579 :
580 32 : reqCtx.handle = reinterpret_cast<RequestHandle>(raReqHandle);
581 32 : HCCL_INFO("[TpMgr][%s] success, tpHandle[0x%llx] reqHandle[%llu].",
582 : __func__, param.tpHandle, reqCtx.handle);
583 32 : return HcclResult::HCCL_SUCCESS;
584 : }
585 :
586 32 : HcclResult TpMgr::HandleCompletedTpAttrRequest(const TpMgr::TpAttrRequestCtx reqCtx,
587 : const TpHandle tpHandle, TpAttrInfo &tpAttrInfo)
588 : {
589 32 : TpAttrInfo tmpTpAttrInfo(reqCtx.tpAttr);
590 :
591 32 : std::lock_guard<std::mutex> lock(tpAttrCtxMutex_);
592 32 : tpAttrCtxMap_[tpHandle] = {std::move(tmpTpAttrInfo), 1};
593 :
594 32 : tpAttrInfo = tpAttrCtxMap_[tpHandle].tpAttrInfo;
595 32 : return HcclResult::HCCL_SUCCESS;
596 32 : }
597 :
598 74 : HcclResult TpMgr::ReleaseTpAttr(const TpHandle tpHandle, const TpAttrInfo &tpAttrInfo)
599 : {
600 74 : std::lock_guard<std::mutex> lock(tpAttrCtxMutex_);
601 74 : auto attrIter = tpAttrCtxMap_.find(tpHandle);
602 74 : if (attrIter == tpAttrCtxMap_.end()) {
603 7 : HCCL_ERROR("[TpMgr][%s] failed, tp attr is not found, "
604 : "tpHandle[0x%llx].", __func__, tpHandle);
605 7 : return HcclResult::HCCL_E_NOT_FOUND;
606 : }
607 :
608 67 : if (attrIter->second.useCnt > 1) {
609 36 : attrIter->second.useCnt -= 1;
610 36 : return HcclResult::HCCL_SUCCESS;
611 : }
612 :
613 31 : tpAttrCtxMap_.erase(attrIter);
614 31 : return HcclResult::HCCL_SUCCESS;
615 74 : }
616 :
617 71 : HcclResult TpMgr::GetTpTotalTimeout(const TpAttrInfo &tpAttrInfo, uint32_t &tpTimeOutMs)
618 : {
619 71 : uint8_t rawAtGear = tpAttrInfo.tpAttr.at;
620 71 : uint8_t rawRetryTimes = tpAttrInfo.tpAttr.retryTimesInit;
621 :
622 71 : uint8_t finalAtGear = rawAtGear;
623 71 : if (rawAtGear > AT_GEAR_MAX) {
624 1 : finalAtGear = AT_GEAR_DEFAULT;
625 1 : HCCL_WARNING("%s Invalid at gear[%u], expect [%u, %u], use default gear[%u].",
626 : __func__, rawAtGear, AT_GEAR_MIN, AT_GEAR_MAX, finalAtGear);
627 : }
628 :
629 71 : uint32_t singleAtTimeoutMs = AT_TIMEOUT_MAP[finalAtGear];
630 71 : tpTimeOutMs = singleAtTimeoutMs * static_cast<uint32_t>(rawRetryTimes + 1);
631 :
632 71 : HCCL_INFO("%s TP timeout calc success: raw_at_gear[%u], final_at_gear[%u], "
633 : "single_timeout[%ums], retry_times[%u], total_timeout[%ums].",
634 : __func__, rawAtGear, finalAtGear, singleAtTimeoutMs, rawRetryTimes, tpTimeOutMs);
635 :
636 71 : return HcclResult::HCCL_SUCCESS;
637 : }
638 :
639 69 : static uint32_t TaHwValueToMs(uint8_t hwValue)
640 : {
641 69 : uint8_t gear = hwValue / 8;
642 69 : switch (gear) {
643 1 : case TA_GEAR_INDEX_0: return TA_TIMEOUT_MS_GEAR0;
644 66 : case TA_GEAR_INDEX_1: return TA_TIMEOUT_MS_GEAR1;
645 1 : case TA_GEAR_INDEX_2: return TA_TIMEOUT_MS_GEAR2;
646 1 : case TA_GEAR_INDEX_3: return TA_TIMEOUT_MS_GEAR3;
647 0 : default: return TA_TIMEOUT_MS_GEAR2;
648 : }
649 : }
650 :
651 1 : static uint8_t FindMinTaHwValue(uint32_t tpTotalTimeoutMs)
652 : {
653 1 : if (tpTotalTimeoutMs < TA_TIMEOUT_MS_GEAR0) {
654 0 : return TA_HW_GEAR0_BASE;
655 : }
656 1 : if (tpTotalTimeoutMs < TA_TIMEOUT_MS_GEAR1) {
657 0 : return TA_HW_GEAR1_BASE;
658 : }
659 1 : if (tpTotalTimeoutMs < TA_TIMEOUT_MS_GEAR2) {
660 1 : return TA_HW_GEAR2_BASE;
661 : }
662 0 : return TA_HW_GEAR3_BASE;
663 : }
664 :
665 68 : uint8_t TpMgr::CalcTaTimeout(const TpAttrInfo &tpAttrInfo)
666 : {
667 68 : constexpr uint8_t UB_TIMEOUT_DEFAULT = 8; // 默认 UBC_CTP 和 UBC_TP 超时配置为8
668 68 : uint8_t envValue = static_cast<uint8_t>(Hccl::EnvConfig::GetInstance().GetRdmaConfig().GetUbTimeOut());
669 68 : uint32_t envTimeoutMs = TaHwValueToMs(envValue);
670 :
671 68 : uint32_t tpTimeOutMs = 0;
672 68 : (void)GetTpTotalTimeout(tpAttrInfo, tpTimeOutMs);
673 :
674 68 : uint8_t errTimeout = UB_TIMEOUT_DEFAULT;
675 68 : if (envTimeoutMs < tpTimeOutMs) {
676 1 : errTimeout = FindMinTaHwValue(tpTimeOutMs);
677 1 : HCCL_WARNING("[TpMgr][%s] Env timeout [%ums] < TP timeout [%ums]. Auto upgrade TA to hw_val[%u] (%ums).",
678 : __func__, envTimeoutMs, tpTimeOutMs, errTimeout, TaHwValueToMs(errTimeout));
679 : } else {
680 67 : errTimeout = envValue;
681 67 : HCCL_INFO("[TpMgr][%s] Env timeout [%ums] >= TP timeout [%ums]. Use env gear base hw_val[%u] (%ums).",
682 : __func__, envTimeoutMs, tpTimeOutMs, envValue, envTimeoutMs);
683 : }
684 :
685 68 : return errTimeout;
686 : }
687 :
688 89 : HcclResult TpMgr::BuildTpInfoAndCommitQosAttr(const GetTpInfoParam ¶m, const RequestCtx &reqCtx,
689 : const struct HccpTpInfo *baseInfoPtr, const uint32_t tpListIndex, const uint32_t mappedSl, TpInfo &tpInfo)
690 : {
691 89 : tpInfo = TpInfo{};
692 89 : tpInfo.tpHandle = baseInfoPtr[tpListIndex].tpHandle;
693 89 : tpInfo.mappedJettyPriority = mappedSl & 0xFU;
694 89 : tpInfo.hasMappedJettyPriority = true;
695 :
696 89 : bool isPcieStd = false;
697 89 : CHK_RET(IsPcieStdMainboardByPhyId(devPhyId_, isPcieStd));
698 89 : if (isPcieStd) {
699 0 : HCCL_INFO("[TpMgr][%s] pcie std mainboard: skip SetTpAttr, devPhyId[%u] tpProtocol[%s] tpHandle[%llu] "
700 : "param[%s].",
701 : __func__, devPhyId_, param.tpProtocol.Describe().c_str(), tpInfo.tpHandle, param.Describe().c_str());
702 89 : } else if (param.tpProtocol == TpProtocol::RTP || param.tpProtocol == TpProtocol::UBOE) {
703 85 : CHK_RET(CommitMappedSlToTpAttr(devPhyId_, param.locAddr, tpInfo.tpHandle, mappedSl));
704 : }
705 99 : if (!isPcieStd && param.tpProtocol == TpProtocol::UBOE &&
706 10 : reqCtx.tpAttr.dscpConfigMode == 0) {
707 7 : const uint8_t dscpBefore = static_cast<uint8_t>(reqCtx.tpAttr.dscp & 0x3FU);
708 7 : const uint8_t requestQos = static_cast<uint8_t>(param.qos & 0xFFU);
709 7 : const uint16_t slMask = ReadSlAvailableMask16(reqCtx.tpAttr);
710 7 : const uint8_t dscpLookupQos = ResolveUboeDscpLookupQos(param, reqCtx.tpInfoNum, slMask);
711 7 : uint8_t dscp = Hccl::kUboeDefaultDscp;
712 7 : (void)Hccl::TpQosGetDscpByQosFromHccnCfg(devPhyId_, dscpLookupQos, dscp);
713 7 : CHK_RET(CommitUboeDscpToTpAttr(devPhyId_, param.locAddr, tpInfo.tpHandle, dscp));
714 7 : HCCL_INFO("[TpMgr][%s] UBOE dscp updated: tpHandle[%llu] requestQos[%u] dscpLookupQos[%u] dscpBefore[%u] "
715 : "dscpAfter[%u].",
716 : __func__, tpInfo.tpHandle, static_cast<unsigned>(requestQos), static_cast<unsigned>(dscpLookupQos),
717 : static_cast<unsigned>(dscpBefore), static_cast<unsigned>(dscp));
718 : }
719 89 : HCCL_INFO("[TpMgr][%s] tp qos mapping ok: tpHandle[%llu] tpListIndex[%u] mappedSl[%u] jettyPriority[%u] qos[%u] param[%s].",
720 : __func__, tpInfo.tpHandle, tpListIndex, static_cast<unsigned>(mappedSl & 0xFU), tpInfo.mappedJettyPriority,
721 : param.qos & 0xFFU, param.Describe().c_str());
722 89 : return HcclResult::HCCL_SUCCESS;
723 : }
724 :
725 : // GetTpInfo 完成后写入缓存。useCnt 仅在 FindAndGetTpInfo 命中时 +1,此处不做引用计数。
726 : // 并发首次 GetTpInfo 时,先完成者写入缓存;后完成者若 tpHandle 不同则跳过写入,直接使用本地结果。
727 89 : HcclResult TpMgr::CommitTpInfoToCache(const GetTpInfoParam ¶m, TpInfo &tpInfo)
728 : {
729 89 : Hccl::IpAddress locAddr{};
730 89 : Hccl::IpAddress rmtAddr{};
731 89 : CHK_RET(CommAddrToIpAddress(param.locAddr, locAddr));
732 89 : CHK_RET(CommAddrToIpAddress(param.rmtAddr, rmtAddr));
733 89 : const QosKey qosKey = QosMapKey(param.qos);
734 :
735 89 : std::lock_guard<std::mutex> lock(GetInfoCtxMutex(param.tpProtocol));
736 89 : auto &infoMap = GetInfoCtxMap(param.tpProtocol);
737 89 : auto &rmtMap = infoMap[locAddr][rmtAddr];
738 89 : const auto qIt = rmtMap.find(qosKey);
739 89 : if (qIt == rmtMap.end()) {
740 89 : rmtMap[qosKey] = TpInfoCtx{tpInfo, 1U};
741 89 : return HcclResult::HCCL_SUCCESS;
742 : }
743 :
744 : // 缓存已存在:不再覆盖(避免并发后写覆盖先写的 tpHandle);tpInfo 保持 GetTpInfo 本地结果。
745 0 : if (qIt->second.tpInfo.tpHandle != tpInfo.tpHandle) {
746 0 : HCCL_WARNING("[TpMgr][%s] skip cache store, cached tpHandle[%llu] != local tpHandle[%llu] param[%s].",
747 : __func__, qIt->second.tpInfo.tpHandle, tpInfo.tpHandle, param.Describe().c_str());
748 : }
749 0 : return HcclResult::HCCL_SUCCESS;
750 89 : }
751 :
752 89 : HcclResult TpMgr::HandleCompletedRequest(RequestCtx reqCtx, const GetTpInfoParam ¶m, TpInfo &tpInfo)
753 : {
754 89 : const uint32_t tpInfoNum = reqCtx.tpInfoNum;
755 89 : if (tpInfoNum == 0U) {
756 0 : HCCL_WARNING("[TpMgr][%s] failed to find tp info, tpInfoNum is 0, param[%s].", __func__,
757 : param.Describe().c_str());
758 0 : return HcclResult::HCCL_E_NOT_FOUND;
759 : }
760 :
761 89 : tpInfo = TpInfo{};
762 :
763 89 : const struct HccpTpInfo *baseInfoPtr = reinterpret_cast<const struct HccpTpInfo *>(reqCtx.dataBuffer.data());
764 89 : bool isPcieStd = false;
765 89 : CHK_RET(IsPcieStdMainboardByPhyId(devPhyId_, isPcieStd));
766 89 : if (isPcieStd) {
767 0 : tpInfo.tpHandle = baseInfoPtr[0].tpHandle;
768 0 : tpInfo.mappedJettyPriority = kPcieStdMappedSl;
769 0 : tpInfo.hasMappedJettyPriority = true;
770 0 : HCCL_INFO("[TpMgr][%s] pcie std mainboard: skip GetTpAttr/SetTpAttr, devPhyId[%u] tpInfoNum[%u] "
771 : "mappedSl[%u] tpHandle[%llu] param[%s].",
772 : __func__, devPhyId_, tpInfoNum, kPcieStdMappedSl, tpInfo.tpHandle, param.Describe().c_str());
773 0 : return CommitTpInfoToCache(param, tpInfo);
774 : }
775 :
776 89 : const uint16_t slMask = ReadSlAvailableMask16(reqCtx.tpAttr);
777 89 : const uint32_t slAvailableCnt = CalSlAvailableCnt(slMask);
778 89 : HCCL_INFO("[TpMgr][%s] after get_tp_attr: slMask[0x%04x] slAvailableCnt[%u] slBitmap[0x%x] dscp[%u] dscpConfigMode[%u] "
779 : "tpAttrBitmap[0x%x] param[%s].",
780 : __func__, static_cast<unsigned>(slMask), slAvailableCnt, static_cast<unsigned>(reqCtx.tpAttr.slBitmap),
781 : static_cast<unsigned>(reqCtx.tpAttr.dscp & 0x3FU),
782 : static_cast<unsigned>(reqCtx.tpAttr.dscpConfigMode & 1U), reqCtx.tpAttrBitmap, param.Describe().c_str());
783 89 : if (slAvailableCnt == 0U) {
784 0 : HCCL_ERROR("[TpMgr][%s] sl_available mask empty after get_tp_attr, param[%s].", __func__,
785 : param.Describe().c_str());
786 0 : return HcclResult::HCCL_E_INTERNAL;
787 : }
788 89 : uint32_t tpListIndex = 0;
789 89 : uint32_t mappedSl = 0;
790 89 : if (!ApplyQosTpSlPolicy(param, slMask, tpListIndex, mappedSl)) {
791 0 : HCCL_ERROR("[TpMgr][%s] ApplyQosTpSlPolicy failed, param[%s] nTp[%u] slAvailableCnt[%u] mask[%u].",
792 : __func__, param.Describe().c_str(), tpInfoNum, slAvailableCnt, static_cast<unsigned>(slMask));
793 0 : return HcclResult::HCCL_E_INTERNAL;
794 : }
795 89 : if (tpListIndex >= tpInfoNum) {
796 0 : HCCL_ERROR("[TpMgr][%s] tpListIndex out of range: tpListIndex[%u] tpInfoNum[%u] mappedSl[%u] param[%s].",
797 : __func__, tpListIndex, tpInfoNum, static_cast<unsigned>(mappedSl & 0xFU), param.Describe().c_str());
798 0 : return HcclResult::HCCL_E_INTERNAL;
799 : }
800 :
801 89 : CHK_RET(BuildTpInfoAndCommitQosAttr(param, reqCtx, baseInfoPtr, tpListIndex, mappedSl, tpInfo));
802 89 : return CommitTpInfoToCache(param, tpInfo);
803 : }
804 :
805 449 : TpMgr::InfoCtxMap &TpMgr::GetInfoCtxMap(const TpProtocol tpProtocol)
806 : {
807 449 : switch (tpProtocol) {
808 28 : case TpProtocol::CTP:
809 28 : return ctpInfoMap_;
810 381 : case TpProtocol::RTP:
811 381 : return rtpInfoMap_;
812 40 : case TpProtocol::UBOE:
813 40 : return uboeInfoMap_;
814 0 : default:
815 0 : return rtpInfoMap_;
816 : }
817 : }
818 :
819 279 : TpMgr::ReqCtxMap &TpMgr::GetReqCtxMap(const TpProtocol tpProtocol)
820 : {
821 279 : switch (tpProtocol) {
822 24 : case TpProtocol::CTP:
823 24 : return ctpReqMap_;
824 225 : case TpProtocol::RTP:
825 225 : return rtpReqMap_;
826 30 : case TpProtocol::UBOE:
827 30 : return uboeReqMap_;
828 0 : default:
829 0 : return rtpReqMap_;
830 : }
831 : }
832 :
833 449 : std::mutex &TpMgr::GetInfoCtxMutex(const TpProtocol tpProtocol)
834 : {
835 449 : switch (tpProtocol) {
836 28 : case TpProtocol::CTP:
837 28 : return ctpInfoMutex_;
838 381 : case TpProtocol::RTP:
839 381 : return rtpInfoMutex_;
840 40 : case TpProtocol::UBOE:
841 40 : return uboeInfoMutex_;
842 0 : default:
843 0 : return rtpInfoMutex_;
844 : }
845 : }
846 :
847 279 : std::mutex &TpMgr::GetReqCtxMutex(const TpProtocol tpProtocol)
848 : {
849 279 : switch (tpProtocol) {
850 24 : case TpProtocol::CTP:
851 24 : return ctpReqMutex_;
852 225 : case TpProtocol::RTP:
853 225 : return rtpReqMutex_;
854 30 : case TpProtocol::UBOE:
855 30 : return uboeReqMutex_;
856 0 : default:
857 0 : return rtpReqMutex_;
858 : }
859 : }
860 :
861 : } // namespace hcomm
|