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 : #ifndef AICPUSD_STATUS_H
12 : #define AICPUSD_STATUS_H
13 :
14 : #include <string>
15 : #include <unistd.h>
16 : #include <sys/syscall.h>
17 : #include "aicpucust_weak_log.h"
18 : #include "type_def.h"
19 :
20 : namespace AicpuSchedule {
21 : constexpr const char_t *AICPUSD_MODULE = "AICPU_SCHEDULE";
22 : constexpr const char_t *REPORT_DRV_MODULE = "DRV";
23 : constexpr const char_t *REPORT_AICPU_MODULE = "AICPU";
24 267 : inline uint64_t GetTid()
25 : {
26 267 : thread_local static const uint64_t tid = static_cast<uint64_t>(syscall(__NR_gettid));
27 267 : return tid;
28 : }
29 :
30 : // 22001 ~ 22200: error codes for hwts task execution
31 : // 22201 ~: inner error code
32 : using StatusCode = int32_t;
33 : constexpr int32_t AICPU_SCHEDULE_OK = 0;
34 : constexpr int32_t AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID = 22001;
35 : constexpr int32_t AICPU_SCHEDULE_ERROR_DRV_ERR = 22002;
36 : constexpr int32_t AICPU_SCHEDULE_ERROR_TOOL_ERR = 22003;
37 : constexpr int32_t AICPU_SCHEDULE_ERROR_TASK_EXECUTE_PARAM_INVALID = 22004;
38 : constexpr int32_t AICPU_SCHEDULE_ERROR_TASK_EXECUTE_FAILED = 22005;
39 : constexpr int32_t AICPU_SCHEDULE_ERROR_TASK_EXECUTE_TIMEOUT = 22006;
40 : constexpr int32_t AICPU_SCHEDULE_ERROR_INNER_ERROR = 22007;
41 : constexpr int32_t AICPU_SCHEDULE_ERROR_DUMP_FAILED = 22008;
42 : // error code for overflow
43 : constexpr int32_t AICPU_SCHEDULE_ERROR_UNDERFLOW = 22010;
44 : constexpr int32_t AICPU_SCHEDULE_ERROR_OVERFLOW = 22011;
45 : constexpr int32_t AICPU_SCHEDULE_ERROR_DIVISIONZERO = 22012;
46 : // reserved inner error
47 : constexpr int32_t AICPU_SCHEDULE_ERROR_RESERVED = 22200;
48 :
49 : // the following error codes are uniformly normalized to AICPU_SCHEDULE_ERROR_INNER_ERROR
50 : constexpr int32_t AICPU_SCHEDULE_ERROR_INIT_CP_FAILED = 22201;
51 : constexpr int32_t AICPU_SCHEDULE_ERROR_INIT_FAILED = 22202;
52 : constexpr int32_t AICPU_SCHEDULE_ERROR_UNKNOW_AICPU_EVENT = 22203;
53 : constexpr int32_t AICPU_SCHEDULE_COMMON_FAILED = 22204;
54 : constexpr int32_t AICPU_SCHEDULE_ERROR_COMMON_ERROR = 22205;
55 : constexpr int32_t AICPU_SCHEDULE_ERROR_DUMP_TASK_WAIT_ERROR = 22206;
56 : // the following error codes are uniformly normalized to AICPU_SCHEDULE_ERROR_INNER_ERROR
57 : constexpr int32_t AICPU_SCHEDULE_ERROR_NOT_FOUND_CMD_TYPE = 21201;
58 : constexpr int32_t AICPU_SCHEDULE_ERROR_NOT_FOUND_EVENT = 21202;
59 : constexpr int32_t AICPU_SCHEDULE_ERROR_NOT_FOUND_VERSION = 21203;
60 : constexpr int32_t AICPU_SCHEDULE_ERROR_INVALID_MAGIC_NUM = 21204;
61 : constexpr int32_t AICPU_SCHEDULE_ERROR_NOT_FOUND_FUNCTION = 21205;
62 : constexpr int32_t AICPU_SCHEDULE_ERROR_FROM_DRV = 21206;
63 : }
64 :
65 : #define aicpusd_err(fmt, ...) \
66 : do { \
67 : if (&DlogRecord != nullptr) { \
68 : dlog_error(static_cast<int32_t>(CCECPU), "[%s][tid:%lu][%s] " fmt, &__func__[0], \
69 : AicpuSchedule::GetTid(), AicpuSchedule::AICPUSD_MODULE, ##__VA_ARGS__); \
70 : } \
71 : } while (0)
72 :
73 : #define aicpusd_warn(fmt, ...) \
74 : do { \
75 : if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) { \
76 : dlog_warn(static_cast<int32_t>(CCECPU), "[%s][tid:%lu][%s] " fmt, &__func__[0], \
77 : AicpuSchedule::GetTid(), AicpuSchedule::AICPUSD_MODULE, ##__VA_ARGS__); \
78 : } \
79 : } while (0)
80 :
81 : #define aicpusd_info(fmt, ...) \
82 : do { \
83 : if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) { \
84 : dlog_info(static_cast<int32_t>(CCECPU), "[%s][tid:%lu][%s] " fmt, &__func__[0], \
85 : AicpuSchedule::GetTid(), AicpuSchedule::AICPUSD_MODULE, ##__VA_ARGS__); \
86 : } \
87 : } while (0)
88 :
89 : #define aicpusd_debug(fmt, ...) \
90 : do { \
91 : if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) { \
92 : dlog_debug(static_cast<int32_t>(CCECPU), "[%s][tid:%lu][%s] " fmt, &__func__[0], \
93 : AicpuSchedule::GetTid(), AicpuSchedule::AICPUSD_MODULE, ##__VA_ARGS__); \
94 : } \
95 : } while (0)
96 :
97 : #define aicpusd_memory_log(fmt, ...) \
98 : do { \
99 : if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) { \
100 : dlog_info(static_cast<int32_t>(CCECPU), "[%s][tid:%lu][%s] " fmt, &__func__[0], \
101 : AicpuSchedule::GetTid(), AicpuSchedule::AICPUSD_MODULE, ##__VA_ARGS__); \
102 : } \
103 : } while (0)
104 :
105 : #define aicpusd_run_info(fmt, ...) \
106 : do { \
107 : if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) { \
108 : dlog_info(static_cast<int32_t>(static_cast<uint32_t>(CCECPU) | \
109 : static_cast<uint32_t>(RUN_LOG_MASK)), "[%s][tid:%lu][%s] " fmt, \
110 : &__func__[0], AicpuSchedule::GetTid(), AicpuSchedule::AICPUSD_MODULE, ##__VA_ARGS__); \
111 : } \
112 : } while (0)
113 :
114 : #define aicpusd_run_warn(fmt, ...) \
115 : do { \
116 : if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) { \
117 : dlog_warn(static_cast<int32_t>(static_cast<uint32_t>(CCECPU) | \
118 : static_cast<uint32_t>(RUN_LOG_MASK)), "[%s][tid:%llu][%s] " fmt, \
119 : &__FUNCTION__[0], AicpuSchedule::GetTid(), AicpuSchedule::AICPUSD_MODULE, ##__VA_ARGS__); \
120 : } \
121 : } while (0)
122 :
123 : #define UNUSED(expr) do { \
124 : (void)(expr); \
125 : } while (false)
126 :
127 : // 注意: 该宏第一项Condition是期望为真,否则将进行后续的返回和日志记录
128 : #define AICPUSD_CHECK(condition, retValue, log, ...) \
129 : do { \
130 : const bool cond = (condition); \
131 : if (!cond) { \
132 : aicpusd_err(log, ##__VA_ARGS__); \
133 : return (retValue); \
134 : } \
135 : } while (false)
136 :
137 : #endif
|