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 "config_log.h"
12 : #include "mmpa_api.h"
13 :
14 : namespace hccl {
15 :
16 : static u64 g_debugConfig = 0ULL;
17 : static bool g_debugConfigInited = false;
18 :
19 401 : u64 GetDebugConfig()
20 : {
21 401 : return g_debugConfig;
22 : }
23 :
24 63 : HcclResult InitDebugConfigByEnv()
25 : {
26 63 : g_debugConfig = 0;
27 63 : char* env = nullptr; // 环境变量值
28 63 : MM_SYS_GET_ENV(MM_ENV_HCCL_DEBUG_CONFIG, env);
29 63 : if (env == nullptr) {
30 49 : HCCL_RUN_INFO("HCCL_DEBUG_CONFIG is not set, debugConfig set by default to 0x%llx", g_debugConfig);
31 49 : return HCCL_SUCCESS;
32 : }
33 :
34 14 : bool invert = (env[0] == '^');
35 14 : g_debugConfig = invert ? ~0ULL : 0ULL; // 第一个字符是'^', 使用取反模式, 用户配置的项关闭, 未配置的项打开
36 14 : char* configValue = (env[0] == '^') ? env + 1 : env; // 去掉'^'符号
37 14 : char* configDup = strdup(configValue); // 需要使用strdup避免修改字符串常量
38 14 : CHK_PTR_NULL(configDup);
39 :
40 14 : char* left = nullptr;
41 14 : char* subConfig = strtok_r(configDup, ",", &left); // 按逗号分割
42 28 : while (subConfig != nullptr) {
43 14 : u64 mask = 0;
44 14 : if (strcasecmp(subConfig, "ALG") == 0) {
45 7 : mask = HCCL_ALG;
46 7 : } else if (strcasecmp(subConfig, "TASK") == 0) {
47 0 : mask = HCCL_TASK;
48 7 : } else if (strcasecmp(subConfig, "RESOURCE") == 0) {
49 0 : mask = HCCL_RES;
50 7 : } else if (strcasecmp(subConfig, "AIV_OPS_EXC") == 0) {
51 7 : HCCL_WARNING("HCCL_DEBUG_CONFIG:%s subConfig:%s is deprecated and ignored", env, subConfig);
52 : } else {
53 0 : HCCL_ERROR("HCCL_DEBUG_CONFIG:%s is invalid, subConfig:%s is not supported", env, subConfig);
54 0 : free(configDup);
55 0 : return HCCL_E_PARA;
56 : }
57 14 : g_debugConfig = invert ? (g_debugConfig & (~mask)) : (g_debugConfig | mask);
58 14 : subConfig = strtok_r(nullptr, ",", &left);
59 : }
60 14 : free(configDup);
61 14 : HCCL_RUN_INFO("HCCL_DEBUG_CONFIG[%s], set debugConfig[0x%llx]", env, g_debugConfig);
62 14 : g_debugConfigInited = true;
63 14 : return HCCL_SUCCESS;
64 : }
65 :
66 5 : bool GetDebugConfigInited()
67 : {
68 5 : return g_debugConfigInited;
69 : }
70 :
71 11 : void InitDebugConfigByValue(u64 config)
72 : {
73 11 : g_debugConfig = config;
74 11 : HCCL_INFO("set debugConfig[0x%llx] by value", g_debugConfig);
75 11 : }
76 :
77 : }
|