LCOV - code coverage report
Current view: top level - tsdclient/inc - tsd_process_controller.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 4 4
Test Date: 2026-07-28 10:52:48 Functions: 100.0 % 4 4

            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              : 
      11              : #ifndef INNER_INC_TSD_PROCESS_CONTROLLER_H
      12              : #define INNER_INC_TSD_PROCESS_CONTROLLER_H
      13              : 
      14              : #include "inc/process_shared_context.h"
      15              : #include "capability_manager.h"
      16              : #include "package_manager.h"
      17              : #include "device_comm_agent.h"
      18              : #include "hdc_message_builder.h"
      19              : 
      20              : #include <chrono>
      21              : 
      22              : namespace tsd {
      23              : 
      24              : using TimePoint = std::chrono::high_resolution_clock::time_point;
      25              : 
      26              : struct TsdStartStatusInfo {
      27              :     bool startHccp_;
      28              :     bool startCp_;
      29              :     bool startQs_;
      30              : };
      31              : 
      32              : class TsdProcessController {
      33              : public:
      34              :     TsdProcessController(
      35              :         DeviceCommAgent& commAgent, CapabilityManager& capabilityMgr, PackageManager& packageMgr,
      36              :         ProcessSharedContext& sharedCtx, uint32_t aicpuDeviceMode);
      37              : 
      38              :     TSD_StatusT Open(uint32_t rankSize);
      39              :     TSD_StatusT OpenAicpuSd();
      40              :     TSD_StatusT OpenProcess(uint32_t rankSize);
      41              :     TSD_StatusT Close(uint32_t flag);
      42              :     TSD_StatusT GetHdcConctStatus(int32_t& hdcSessStat);
      43              :     TSD_StatusT InitQs(const InitFlowGwInfo* const initInfo);
      44              :     TSD_StatusT UpdateProfilingConf(const uint32_t& flag);
      45              : 
      46              :     TSD_StatusT InitTsdClient();
      47              :     TSD_StatusT WaitRsp(uint32_t timeout, bool ignoreRecvErr = false, bool isClose = false);
      48              :     MessageContext BuildBaseMessageContext() const;
      49              : 
      50              :     void SetTsdStartInfo(bool cpStatus, bool hccpStatus, bool qsStatus);
      51              :     bool CheckNeedToOpen(uint32_t rankSize, TsdStartStatusInfo& startInfo);
      52              : 
      53              :     TSD_StatusT ProcessQueueForAdc();
      54              :     TSD_StatusT SyncQueueAuthority() const;
      55              :     TSD_StatusT ProcessQueueGrant(
      56              :         const QueueQueryOutputPara& queueInfoOutBuff, const QueueQueryOutput* const queueInfoList,
      57              :         const pid_t aicpuPid) const;
      58              :     TSD_StatusT GetAicpusdPid(pid_t& aicpusdPid) const;
      59              : 
      60              :     TsdStartStatusInfo& GetTsdStartStatus() { return tsdStartStatus_; }
      61              :     const TsdStartStatusInfo& GetTsdStartStatus() const { return tsdStartStatus_; }
      62              :     uint32_t GetRankSize() const { return rankSize_; }
      63              :     void SetRankSize(uint32_t rankSize) { rankSize_ = rankSize; }
      64              :     const std::string& GetQsInitGrpName() const { return qsInitGrpName_; }
      65              :     void SetQsInitGrpName(const std::string& name) { qsInitGrpName_ = name; }
      66              :     uint64_t GetSchedPolicy() const { return schedPolicy_; }
      67              :     void SetSchedPolicy(uint64_t policy) { schedPolicy_ = policy; }
      68            5 :     uint32_t GetHccpPid() const { return hccpPid_; }
      69           10 :     void SetHccpPid(uint32_t pid) { hccpPid_ = pid; }
      70           13 :     bool IsStartedHccp() const { return isStartedHccp_; }
      71           10 :     void SetStartedHccp(bool started) { isStartedHccp_ = started; }
      72              : 
      73              : private:
      74              :     struct TsdCloseFlag {
      75              :         uint32_t quickCloseFlag : 1;
      76              :         uint32_t res : 31;
      77              :     };
      78              :     enum TsdCloseMode { QUICK_CLOSE_MODE = 1 };
      79              : 
      80              :     TSD_StatusT SendOpenMsg(uint32_t rankSize, TsdStartStatusInfo startInfo);
      81              :     TSD_StatusT SendCloseMsg();
      82              :     TSD_StatusT SendUpdateProfilingMsg(uint32_t flag);
      83              :     TSD_StatusT ConstructOpenMsg(HDCMessage& hdcMsg, const TsdStartStatusInfo& startInfo);
      84              :     TSD_StatusT ConstructCloseMsg(HDCMessage& msg);
      85              :     TSD_StatusT MapFailCodeToStatus() const;
      86              :     std::string BuildWaitRspErrReport(TSD_StatusT recvRet) const;
      87              :     void ParseTsdCloseFlag(uint32_t flag, TsdCloseFlag& tsdCloseFlag) const;
      88              :     TSD_StatusT LoadPackagesToDevice();
      89              :     TSD_StatusT WaitOpenRsp(const uint32_t rankSize);
      90              :     void LogOpenProcessDuration(
      91              :         const TimePoint& beginOpen, const TimePoint& finSendOpenMsg, const TimePoint& finRecvRsp,
      92              :         const TimePoint& finOpen) const;
      93              : 
      94              :     DeviceCommAgent& commAgent_;
      95              :     CapabilityManager& capabilityMgr_;
      96              :     PackageManager& packageMgr_;
      97              :     ProcessSharedContext& sharedCtx_;
      98              :     uint32_t aicpuDeviceMode_;
      99              :     TsdStartStatusInfo tsdStartStatus_ = {};
     100              :     uint32_t rankSize_ = 0U;
     101              :     std::string qsInitGrpName_;
     102              :     uint64_t schedPolicy_ = 0U;
     103              :     uint32_t hccpPid_ = 0U;
     104              :     bool isStartedHccp_ = false;
     105              : };
     106              : 
     107              : } // namespace tsd
     108              : #endif // INNER_INC_TSD_PROCESS_CONTROLLER_H
        

Generated by: LCOV version 2.0-1