LCOV - code coverage report
Current view: top level - aicpu_schedule/common - aicpusd_status.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 3 3
Test Date: 2026-07-28 10:54:05 Functions: 100.0 % 1 1

            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 <unistd.h>
      15              : #include <sys/syscall.h>
      16              : #include "aicpusd_weak_log.h"
      17              : #include "ascend_hal.h"
      18              : 
      19              : namespace AicpuSchedule {
      20        59659 : inline uint64_t GetTid()
      21              : {
      22        59659 :     thread_local static const uint64_t tid = static_cast<uint64_t>(syscall(__NR_gettid));
      23        59659 :     return tid;
      24              : }
      25              : 
      26              : constexpr int32_t INNER_ERROR_BASE = 500000;
      27              : 
      28              : // 21001 ~ 21200: error codes for hwts task execution
      29              : // 21201 ~: inner error code
      30              : using StatusCode = int32_t;
      31              : constexpr int32_t AICPU_SCHEDULE_OK = 0;
      32              : constexpr int32_t AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID = 21001;
      33              : constexpr int32_t AICPU_SCHEDULE_ERROR_DUMP_FAILED = 21002;
      34              : constexpr int32_t AICPU_SCHEDULE_ERROR_FROM_DRV =  21003;
      35              : constexpr int32_t AICPU_SCHEDULE_ERROR_TOOL_ERR = 21004;
      36              : constexpr int32_t AICPU_SCHEDULE_ERROR_NOT_FOUND_LOGICAL_TASK = 21005;
      37              : constexpr int32_t AICPU_SCHEDULE_ERROR_TASK_EXECUTE_FAILED = 21006;
      38              : constexpr int32_t AICPU_SCHEDULE_ERROR_TASK_EXECUTE_TIMEOUT = 21007;
      39              : constexpr int32_t AICPU_SCHEDULE_ERROR_INNER_ERROR = 21008;
      40              : // error code for overflow
      41              : constexpr int32_t AICPU_SCHEDULE_ERROR_UNDERFLOW = 21010;
      42              : constexpr int32_t AICPU_SCHEDULE_ERROR_OVERFLOW = 21011;
      43              : constexpr int32_t AICPU_SCHEDULE_ERROR_DIVISIONZERO = 21012;
      44              : // error code for model
      45              : constexpr int32_t AICPU_SCHEDULE_ERROR_IN_WORKING = 21100;
      46              : constexpr int32_t AICPU_SCHEDULE_ERROR_MODEL_NOT_FOUND = 21101;
      47              : constexpr int32_t AICPU_SCHEDULE_ERROR_STREAM_NOT_FOUND = 21102;
      48              : constexpr int32_t AICPU_SCHEDULE_ERROR_MODEL_STATUS_NOT_ALLOW_OPERATE = 21103;
      49              : constexpr int32_t AICPU_SCHEDULE_ERROR_MODEL_EXIT_ERR = 21104;
      50              : constexpr int32_t AICPU_SCHEDULE_ERROR_NOT_SUPPORT = 21105;
      51              : constexpr int32_t AICPU_SCHEDULE_ERROR_MODEL_EXECUTE_FAILED = 21106;
      52              : constexpr int32_t AICPU_SCHEDULE_ERROR_TSCH_OTHER_ERROR = 21107;
      53              : constexpr int32_t AICPU_SCHEDULE_ERROR_DISCARD_DATA = 21108;
      54              : // reserved inner error
      55              : constexpr int32_t AICPU_SCHEDULE_ERROR_RESERVED = 21200;
      56              : 
      57              : // the following error codes are uniformly normalized to AICPU_SCHEDULE_ERROR_INNER_ERROR
      58              : constexpr int32_t AICPU_SCHEDULE_ERROR_NOT_FOUND_CMD_TYPE = 21201;
      59              : constexpr int32_t AICPU_SCHEDULE_ERROR_NOT_FOUND_EVENT = 21202;
      60              : constexpr int32_t AICPU_SCHEDULE_ERROR_INIT_CP_FAILED = 21203;
      61              : constexpr int32_t AICPU_SCHEDULE_ERROR_REPEART_INIT = 21204;
      62              : constexpr int32_t AICPU_SCHEDULE_ERROR_INIT_FAILED = 21205;
      63              : constexpr int32_t AICPU_SCHEDULE_ERROR_DRV_ERR = 21206;
      64              : constexpr int32_t AICPU_SCHEDULE_ERROR_MALLOC_MEM_FAIL_THROUGH_DRV = 21207;
      65              : constexpr int32_t AICPU_SCHEDULE_ERROR_SAFE_FUNCTION_ERR = 21208;
      66              : constexpr int32_t AICPU_SCHEDULE_ERROR_INVAILD_EVENT_SUBMIT = 21209;
      67              : constexpr int32_t AICPU_SCHEDULE_ERROR_UNKNOW_AICPU_EVENT = 21210;
      68              : constexpr int32_t AICPU_SCHEDULE_ERROR_COMMON_ERROR = 21211;
      69              : constexpr int32_t AICPU_SCHEDULE_ERROR_NOT_FIND_KERNEL_ERROR = 21212;
      70              : constexpr int32_t AICPU_SCHEDULE_ERROR_LOAD_CONFIG_JSON_FILE_ERROR = 21213;
      71              : constexpr int32_t AICPU_SCHEDULE_ERROR_CGROUP_FAILED = 21214;
      72              : constexpr int32_t AICPU_SCHEDULE_ERROR_QUEUE_FULL = 21215;
      73              : constexpr int32_t AICPU_SCHEDULE_ERROR_MODEL_UNLOAD = 21216;
      74              : constexpr int32_t AICPU_SCHEDULE_ERROR_NOT_FOUND_VERSION = 21217;
      75              : constexpr int32_t AICPU_SCHEDULE_ERROR_INVALID_MAGIC_NUM = 21218;
      76              : constexpr int32_t AICPU_SCHEDULE_ERROR_NOT_FOUND_FUNCTION = 21219;
      77              : 
      78              : 
      79              : // error code for queue scheduler process
      80              : constexpr int32_t AICPU_SCHEDULE_CALL_DRIVER_ERROR = 21300;
      81              : constexpr int32_t AICPU_SCHEDULE_ERROR_GRANT_QUEUE_FAILED = 21301;
      82              : constexpr int32_t AICPU_SCHEDULE_ERROR_SLAVE_GRP_INVALID = 21302;
      83              : constexpr int32_t AICPU_SCHEDULE_ERROR_MULTI_GRP_ERROR = 21303;
      84              : constexpr int32_t AICPU_SCHEDULE_ERROR_GRP_AUTH_ERROR = 21304;
      85              : constexpr int32_t AICPU_SCHEDULE_ERROR_NOT_FOUND_QUEUE_SUB_EVENT_ID = 21305;
      86              : constexpr int32_t AICPU_SCHEDULE_ERROR_CREATE_CALLBACK_FAILED = 21306;
      87              : constexpr int32_t AICPU_SCHEDULE_ERROR_ADD_CALLBACK_FAILED = 21307;
      88              : constexpr int32_t AICPU_SCHEDULE_ERROR_GET_CALLBACK_FAILED = 21308;
      89              : constexpr int32_t AICPU_SCHEDULE_ERROR_REPEATED_BIND_QUEUE_INIT = 21309;
      90              : constexpr int32_t AICPU_SCHEDULE_ERROR_BIND_QUEUE_INIT_RET_FAILED = 21310;
      91              : constexpr int32_t AICPU_SCHEDULE_ERROR_ROUTE_NUM_IS_ZERO = 21311;
      92              : constexpr int32_t AICPU_SCHEDULE_ERROR_CP_QS_PIPELINE_NOT_INIT = 21312;
      93              : constexpr int32_t AICPU_SCHEDULE_ERROR_CALL_QS_BIND_FAILED = 21313;
      94              : constexpr int32_t AICPU_SCHEDULE_ERROR_TRANS_MODELINFO_FAILED = 21314;
      95              : constexpr int32_t AICPU_SCHEDULE_ERROR_SET_PRIORITY_FAILED = 21315;
      96              : 
      97              : // error code for mem info process
      98              : constexpr int32_t AICPU_SCHEDULE_ERROR_READ_JSON_FAILED = 21400;
      99              : constexpr int32_t AICPU_SCHEDULE_ERROR_GET_PATH_FAILED = 21401;
     100              : constexpr int32_t AICPU_SCHEDULE_ERROR_GET_APP_NAME_FAILED = 21402;
     101              : constexpr int32_t AICPU_SCHEDULE_ERROR_GET_RUN_MODE_FAILED = 21403;
     102              : 
     103              : // error code for hccl
     104              : constexpr int32_t AICPU_SCHEDULE_ERROR_CALL_HCCL = 21500;
     105              : }
     106              : 
     107              : #ifdef ONLY_ERROR
     108              : 
     109              : #define aicpusd_err(fmt, ...) \
     110              :     if (&DlogRecord != nullptr) {    \
     111              :         dlog_error(static_cast<int32_t>(CCECPU), "[%s][tid:%llu]" fmt, &__FUNCTION__[0], \
     112              :                    AicpuSchedule::GetTid(), ##__VA_ARGS__);   \
     113              :     }
     114              : 
     115              : #define aicpusd_warn(fmt, ...)
     116              : #define aicpusd_info(fmt, ...)
     117              : #define aicpusd_debug(fmt, ...)
     118              : #define aicpusd_memory_log(fmt, ...)
     119              : #define aicpusd_run_info(fmt, ...)
     120              : #define aicpusd_run_warn(fmt, ...)
     121              : 
     122              : #else
     123              : #define aicpusd_err(fmt, ...)   \
     124              :     if (&DlogRecord != nullptr) {    \
     125              :         dlog_error(static_cast<int32_t>(CCECPU), "[%s][tid:%llu] " fmt, \
     126              :                    &__FUNCTION__[0], AicpuSchedule::GetTid(), ##__VA_ARGS__); \
     127              :     }
     128              : 
     129              : #define aicpusd_warn(fmt, ...)  \
     130              :     if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) {  \
     131              :         dlog_warn(static_cast<int32_t>(CCECPU), "[%s][tid:%llu] " fmt, \
     132              :                   &__FUNCTION__[0], AicpuSchedule::GetTid(), ##__VA_ARGS__);  \
     133              :     }
     134              : 
     135              : #define aicpusd_info(fmt, ...)  \
     136              :     if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) {  \
     137              :         dlog_info(static_cast<int32_t>(CCECPU), "[%s][tid:%llu] " fmt, \
     138              :                   &__FUNCTION__[0], AicpuSchedule::GetTid(), ##__VA_ARGS__);  \
     139              :     }
     140              : 
     141              : #define aicpusd_debug(fmt, ...) \
     142              :     if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) {  \
     143              :         dlog_debug(static_cast<int32_t>(CCECPU), "[%s][tid:%llu] " fmt, \
     144              :                    &__FUNCTION__[0], AicpuSchedule::GetTid(), ##__VA_ARGS__);  \
     145              :     }
     146              : 
     147              : #define aicpusd_memory_log(fmt, ...)  \
     148              :     if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) {  \
     149              :         dlog_info(static_cast<int32_t>(CCECPU), "[%s][tid:%llu] " fmt, \
     150              :                   &__FUNCTION__[0], AicpuSchedule::GetTid(), ##__VA_ARGS__);  \
     151              :     }
     152              : 
     153              : #define aicpusd_run_info(fmt, ...)  \
     154              :     if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) {  \
     155              :         dlog_info(static_cast<int32_t>(static_cast<uint32_t>(CCECPU) |  \
     156              :                   static_cast<uint32_t>(RUN_LOG_MASK)), \
     157              :                   "[%s][tid:%llu] " fmt, &__FUNCTION__[0], AicpuSchedule::GetTid(), ##__VA_ARGS__);  \
     158              :     }
     159              : 
     160              : #define aicpusd_run_warn(fmt, ...)  \
     161              :     if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) {  \
     162              :         dlog_warn(static_cast<int32_t>(static_cast<uint32_t>(CCECPU) |  \
     163              :                   static_cast<uint32_t>(RUN_LOG_MASK)), \
     164              :                   "[%s][tid:%llu] " fmt, &__FUNCTION__[0], AicpuSchedule::GetTid(), ##__VA_ARGS__);  \
     165              :     }
     166              : #endif
     167              : 
     168              : #define UNUSED(expr) do { \
     169              :     (void)(expr); \
     170              : } while (false)
     171              : 
     172              : // 注意: 该宏第一项Condition是期望为真,否则将进行后续的返回和日志记录
     173              : #define AICPUSD_CHECK(condition, retValue, log, ...)                            \
     174              :     do {                                                                        \
     175              :         const bool cond = (condition);                                          \
     176              :         if (!cond) {                                                            \
     177              :             aicpusd_err(log, ##__VA_ARGS__);                                    \
     178              :             return (retValue);                                                  \
     179              :         }                                                                       \
     180              :     } while (false)
     181              : 
     182              : #endif
        

Generated by: LCOV version 2.0-1