LCOV - code coverage report
Current view: top level - adump/dump_statistics/dump_stat_fw - dump_stats_server.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 7 7
Test Date: 2026-08-31 10:09:28 Functions: 100.0 % 2 2

            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              : #ifndef DUMP_STATS_SERVER_H
      11              : #define DUMP_STATS_SERVER_H
      12              : 
      13              : #include <string>
      14              : #include <cstdint>
      15              : #include <unistd.h>
      16              : #include <sys/syscall.h>
      17              : #include "dump_stats_param.h"
      18              : 
      19              : namespace kfc_dump_stats {
      20              : constexpr uint64_t NSEC_PER_USEC = 1000U;
      21              : constexpr uint64_t NSEC_PER_SEC = 1000000000U;
      22              : constexpr uint64_t DEFAULT_KFC_DUMP_WAIT_TIMEOUT = 30 * NSEC_PER_SEC;
      23              : constexpr uint32_t DUMP_MSG_CNT = 16U;
      24              : constexpr uint32_t MSG_BODY_SIZE = 2048;
      25              : constexpr uint32_t MSGQ_SIZE = 1024 * 1024;
      26              : constexpr uint32_t SYNC_SPACE_BYTES_PER_CORE = 32U;
      27              : constexpr uint32_t DUMP_MSG_VALID_MASK = 0x5CDF123A;
      28              : 
      29     70919170 : inline uint64_t GetCurCpuTimestamp()
      30              : {
      31              :     struct timespec timestamp;
      32     70919170 :     (void)clock_gettime(CLOCK_MONOTONIC_RAW, &timestamp);
      33     70919170 :     return static_cast<uint64_t>((timestamp.tv_sec * NSEC_PER_SEC) + (timestamp.tv_nsec));
      34              : }
      35              : 
      36              : extern uint64_t g_kfcDumpWaitTimeout;
      37              : 
      38     70917178 : inline KfcDumpResult CheckTimeOut(uint64_t startTime)
      39              : {
      40     70917178 :     if (GetCurCpuTimestamp() - startTime > g_kfcDumpWaitTimeout) {
      41            2 :         return KFC_DUMP_E_TIMEOUT;
      42              :     }
      43     70917176 :     return KFC_DUMP_SUCCESS;
      44              : }
      45              : 
      46              : // 64B对齐(AIV单cache line可回刷完成)
      47              : struct KfcDumpStatsMsg {
      48              :     DumpStatMsgType msgType;
      49              :     uint32_t dataType;
      50              :     uint64_t dataCount;
      51              :     uint64_t dataAddr;
      52              :     uint64_t dumpStatClass;
      53              :     uint64_t outputAddr;
      54              :     uint64_t outputAddrSize;
      55              :     uint32_t valid;
      56              :     uint32_t result;
      57              :     uint32_t reserved[2];
      58              : };
      59              : 
      60              : struct KfcDumpMsgBody {
      61              :     KfcDumpStatsMsg msgRcvArea[DUMP_MSG_CNT];
      62              :     KfcDumpStatsMsg msgSndArea[DUMP_MSG_CNT];
      63              : };
      64              : 
      65              : class KfcDumpStatsServer {
      66              : public:
      67              :     KfcDumpStatsServer() = default;
      68              : 
      69              :     ~KfcDumpStatsServer() = default;
      70              : 
      71              :     void Init(uint64_t workSpaceAddr);
      72              : 
      73              :     KfcDumpResult RcvMsg(KfcDumpStatsMsg* rMsg);
      74              : 
      75              :     KfcDumpResult PostMsg(KfcDumpStatsMsg* rMsg);
      76              : 
      77              :     KfcDumpResult CheckDumpResult(KfcDumpStatsMsg* rMsg);
      78              : 
      79              :     bool ReadValidMsg(KfcDumpStatsMsg* rMsg, KfcDumpStatsMsg* msg);
      80              : 
      81              : private:
      82              :     KfcDumpMsgBody* msgBody_ = nullptr;
      83              :     uint32_t rcvMsgPos_ = 0;
      84              :     uint32_t sndMsgPos_ = 0;
      85              : };
      86              : } // namespace kfc_dump_stats
      87              : 
      88              : #endif // DUMP_STATS_SERVER_H
        

Generated by: LCOV version 2.0-1