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 "base_config.h"
12 :
13 : #include "log.h"
14 :
15 : namespace hcomm {
16 :
17 : // 环境变量错误上报:输出日志 + 上报故障码,返回错误码
18 9 : HcclResult ReportEnvError(const char* envName, const std::string& envValue, const std::string& reason)
19 : {
20 9 : std::string errMsg = std::string("[HCCL_ENV] Env config \"") + envName + "\" value \"" + envValue + "\" " + reason;
21 9 : HCCL_ERROR("%s", errMsg.c_str());
22 126 : RPT_ENV_ERR(
23 : true, "EI0001", std::vector<std::string>({"value", "env", "expect"}),
24 : std::vector<std::string>({envValue, envName, errMsg}));
25 9 : return HCCL_E_PARA;
26 27 : }
27 :
28 : // EnvRdmaConfig
29 :
30 27 : HcclResult EnvRdmaConfig::EnsureParsed()
31 : {
32 27 : if (isParsed_.load(std::memory_order_acquire)) {
33 5 : return HCCL_SUCCESS;
34 : }
35 22 : std::lock_guard<std::mutex> lock(parseMutex_);
36 22 : if (isParsed_.load(std::memory_order_relaxed)) { // double-check
37 0 : return HCCL_SUCCESS;
38 : }
39 22 : CHK_RET(taCtpUbTimeOut_.Parse());
40 19 : HCCL_RUN_INFO(
41 : "[HCCL_ENV] HCOMM_TA_CTP_UB_TIMEOUT set by %s to [%u]", taCtpUbTimeOut_.GetSource(), taCtpUbTimeOut_.Get());
42 :
43 19 : CHK_RET(taRtpUbTimeOut_.Parse());
44 17 : HCCL_RUN_INFO(
45 : "[HCCL_ENV] HCOMM_TA_RTP_UB_TIMEOUT set by %s to [%u]", taRtpUbTimeOut_.GetSource(), taRtpUbTimeOut_.Get());
46 :
47 17 : CHK_RET(taRtpUboeTimeOut_.Parse());
48 14 : HCCL_RUN_INFO(
49 : "[HCCL_ENV] HCOMM_TA_RTP_UBOE_TIMEOUT set by %s to [%u]", taRtpUboeTimeOut_.GetSource(),
50 : taRtpUboeTimeOut_.Get());
51 :
52 14 : isParsed_.store(true, std::memory_order_release);
53 14 : return HCCL_SUCCESS;
54 22 : }
55 :
56 22 : void EnvRdmaConfig::ResetParsed()
57 : {
58 22 : std::lock_guard<std::mutex> lock(parseMutex_);
59 22 : isParsed_.store(false, std::memory_order_release);
60 22 : }
61 :
62 8 : HcclResult EnvRdmaConfig::GetTaCtpUbTimeOut(uint32_t& value)
63 : {
64 8 : CHK_RET(EnsureParsed());
65 5 : value = taCtpUbTimeOut_.Get();
66 5 : return HCCL_SUCCESS;
67 : }
68 :
69 13 : HcclResult EnvRdmaConfig::GetTaRtpUbTimeOut(uint32_t& value)
70 : {
71 13 : CHK_RET(EnsureParsed());
72 11 : value = taRtpUbTimeOut_.Get();
73 11 : return HCCL_SUCCESS;
74 : }
75 :
76 6 : HcclResult EnvRdmaConfig::GetTaRtpUboeTimeOut(uint32_t& value)
77 : {
78 6 : CHK_RET(EnsureParsed());
79 3 : value = taRtpUboeTimeOut_.Get();
80 3 : return HCCL_SUCCESS;
81 : }
82 :
83 : } // namespace hcomm
|