Line data Source code
1 : /**
2 : * Copyright (c) 2026 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 : #include "plf_debug_config.h"
11 : #include "env_config.h"
12 : #include "config_plf_log.h"
13 :
14 : namespace Hccl {
15 :
16 22 : static u64 ParseDebugConfig(const char* envName, u64 domainMask)
17 : {
18 22 : char* env = getenv(envName);
19 22 : if (env == nullptr) {
20 15 : return 0;
21 : }
22 :
23 7 : bool invert = (env[0] == '^');
24 : // 第一个字符是'^', 使用取反模式,用户配置的项关闭,未配置的项打开
25 7 : u64 result = invert ? domainMask : 0ULL;
26 :
27 7 : char* configDup = strdup(invert ? env + 1 : env); // 去掉'^'符号
28 7 : if (configDup == nullptr) {
29 0 : HCCL_ERROR("[%s] strdup failed, env[%s]", __func__, env);
30 0 : return result;
31 : }
32 7 : char* left = nullptr;
33 7 : char* subConfig = strtok_r(configDup, ",", &left); // 按逗号分割
34 13 : while (subConfig != nullptr) {
35 7 : u64 mask = 0;
36 7 : if ((domainMask & PLF_TASK) && strcasecmp(subConfig, "TASK") == 0) {
37 4 : mask = PLF_TASK;
38 3 : } else if ((domainMask & PLF_ALG) && strcasecmp(subConfig, "ALG") == 0) {
39 0 : mask = PLF_ALG;
40 3 : } else if ((domainMask & PLF_RES) && strcasecmp(subConfig, "RESOURCE") == 0) {
41 0 : mask = PLF_RES;
42 3 : } else if ((domainMask & PLF_DATA_OP) && strcasecmp(subConfig, "DATA_OP") == 0) {
43 2 : mask = PLF_DATA_OP;
44 : } else {
45 3 : HCCL_ERROR("%s:%s subConfig:%s is not supported", envName, env, subConfig);
46 1 : free(configDup);
47 1 : return 0;
48 : }
49 6 : if (invert) {
50 1 : result &= ~mask;
51 : } else {
52 5 : result |= mask;
53 : }
54 6 : subConfig = strtok_r(nullptr, ",", &left);
55 : }
56 6 : free(configDup);
57 18 : HCCL_RUN_INFO("[HCCL_ENV] %s set by [%s] to [0x%llx]", envName, env, result);
58 6 : return result;
59 : }
60 :
61 11 : void EnvPlfDebugConfig::Parse()
62 : {
63 11 : plfDebugConfig_ = ParseDebugConfig("HCCL_DEBUG_CONFIG", PLF_TASK | PLF_ALG | PLF_RES);
64 11 : plfDebugConfig_ |= ParseDebugConfig("HCOMM_DEBUG_CONFIG", PLF_TASK | PLF_DATA_OP);
65 33 : HCCL_RUN_INFO("[HCCL_ENV] plfDebugConfig set to [0x%llx]", plfDebugConfig_);
66 11 : }
67 :
68 9 : u64 EnvPlfDebugConfig::GetConfigValue() const
69 : {
70 9 : return plfDebugConfig_;
71 : }
72 :
73 3 : u64 GetPlfDebugConfigValue()
74 : {
75 3 : return EnvConfig::GetInstance().GetPlfDebugConfig().GetConfigValue();
76 : }
77 :
78 : } // namespace Hccl
|