LCOV - code coverage report
Current view: top level - aicpu_cust_schedule/common - aicpusd_status.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 3 3
Test Date: 2026-08-12 11:05:02 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 <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          265 : inline uint64_t GetTid()
      25              : {
      26          265 :     thread_local static const uint64_t tid = static_cast<uint64_t>(syscall(__NR_gettid));
      27          265 :     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              : } // namespace AicpuSchedule
      64              : 
      65              : #define aicpusd_err(fmt, ...)                                                                                  \
      66              :     do {                                                                                                       \
      67              :         if (&DlogRecord != nullptr) {                                                                          \
      68              :             dlog_error(                                                                                        \
      69              :                 static_cast<int32_t>(CCECPU), "[%s][tid:%lu][%s] " fmt, &__func__[0], AicpuSchedule::GetTid(), \
      70              :                 AicpuSchedule::AICPUSD_MODULE, ##__VA_ARGS__);                                                 \
      71              :         }                                                                                                      \
      72              :     } while (0)
      73              : 
      74              : #define aicpusd_warn(fmt, ...)                                                                                 \
      75              :     do {                                                                                                       \
      76              :         if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) {                                         \
      77              :             dlog_warn(                                                                                         \
      78              :                 static_cast<int32_t>(CCECPU), "[%s][tid:%lu][%s] " fmt, &__func__[0], AicpuSchedule::GetTid(), \
      79              :                 AicpuSchedule::AICPUSD_MODULE, ##__VA_ARGS__);                                                 \
      80              :         }                                                                                                      \
      81              :     } while (0)
      82              : 
      83              : #define aicpusd_info(fmt, ...)                                                                                 \
      84              :     do {                                                                                                       \
      85              :         if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) {                                         \
      86              :             dlog_info(                                                                                         \
      87              :                 static_cast<int32_t>(CCECPU), "[%s][tid:%lu][%s] " fmt, &__func__[0], AicpuSchedule::GetTid(), \
      88              :                 AicpuSchedule::AICPUSD_MODULE, ##__VA_ARGS__);                                                 \
      89              :         }                                                                                                      \
      90              :     } while (0)
      91              : 
      92              : #define aicpusd_debug(fmt, ...)                                                                                \
      93              :     do {                                                                                                       \
      94              :         if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) {                                         \
      95              :             dlog_debug(                                                                                        \
      96              :                 static_cast<int32_t>(CCECPU), "[%s][tid:%lu][%s] " fmt, &__func__[0], AicpuSchedule::GetTid(), \
      97              :                 AicpuSchedule::AICPUSD_MODULE, ##__VA_ARGS__);                                                 \
      98              :         }                                                                                                      \
      99              :     } while (0)
     100              : 
     101              : #define aicpusd_memory_log(fmt, ...)                                                                           \
     102              :     do {                                                                                                       \
     103              :         if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) {                                         \
     104              :             dlog_info(                                                                                         \
     105              :                 static_cast<int32_t>(CCECPU), "[%s][tid:%lu][%s] " fmt, &__func__[0], AicpuSchedule::GetTid(), \
     106              :                 AicpuSchedule::AICPUSD_MODULE, ##__VA_ARGS__);                                                 \
     107              :         }                                                                                                      \
     108              :     } while (0)
     109              : 
     110              : #define aicpusd_run_info(fmt, ...)                                                                              \
     111              :     do {                                                                                                        \
     112              :         if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) {                                          \
     113              :             dlog_info(                                                                                          \
     114              :                 static_cast<int32_t>(static_cast<uint32_t>(CCECPU) | static_cast<uint32_t>(RUN_LOG_MASK)),      \
     115              :                 "[%s][tid:%lu][%s] " fmt, &__func__[0], AicpuSchedule::GetTid(), AicpuSchedule::AICPUSD_MODULE, \
     116              :                 ##__VA_ARGS__);                                                                                 \
     117              :         }                                                                                                       \
     118              :     } while (0)
     119              : 
     120              : #define aicpusd_run_warn(fmt, ...)                                                                                   \
     121              :     do {                                                                                                             \
     122              :         if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) {                                               \
     123              :             dlog_warn(                                                                                               \
     124              :                 static_cast<int32_t>(static_cast<uint32_t>(CCECPU) | static_cast<uint32_t>(RUN_LOG_MASK)),           \
     125              :                 "[%s][tid:%llu][%s] " fmt, &__FUNCTION__[0], AicpuSchedule::GetTid(), AicpuSchedule::AICPUSD_MODULE, \
     126              :                 ##__VA_ARGS__);                                                                                      \
     127              :         }                                                                                                            \
     128              :     } while (0)
     129              : 
     130              : #define UNUSED(expr)  \
     131              :     do {              \
     132              :         (void)(expr); \
     133              :     } while (false)
     134              : 
     135              : // 注意: 该宏第一项Condition是期望为真,否则将进行后续的返回和日志记录
     136              : #define AICPUSD_CHECK(condition, retValue, log, ...) \
     137              :     do {                                             \
     138              :         const bool cond = (condition);               \
     139              :         if (!cond) {                                 \
     140              :             aicpusd_err(log, ##__VA_ARGS__);         \
     141              :             return (retValue);                       \
     142              :         }                                            \
     143              :     } while (false)
     144              : 
     145              : #endif
        

Generated by: LCOV version 2.0-1