LCOV - code coverage report
Current view: top level - server/entity_manager - entity.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 35 35
Test Date: 2026-08-12 11:05:07 Functions: 97.2 % 36 35

            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 DGW_ENTITY_H
      12              : #define DGW_ENTITY_H
      13              : 
      14              : #include <list>
      15              : #include <vector>
      16              : #include "data_obj_manager.h"
      17              : #include "dynamic_sched_mgr.hpp"
      18              : #include "fsm/state_define.h"
      19              : #include "statistic_manager.h"
      20              : 
      21              : #include "dgw_client.h"
      22              : #include "hccl/comm_channel_manager.h"
      23              : #include "bqs_util.h"
      24              : namespace dgw {
      25              : 
      26              : // invalid group id
      27              : constexpr int32_t INVALID_GROUP_ID = -1;
      28              : struct EntityMaterial {
      29              :     EntityType eType;
      30              :     EntityDirection direction;
      31              :     uint32_t id;
      32              :     uint32_t globalId;
      33              :     uint32_t uuId;
      34              :     uint32_t schedCfgKey;
      35              :     uint32_t resId; // deviceId
      36              :     int32_t hostGroupId = INVALID_GROUP_ID;
      37              :     const CommChannel* channel = nullptr;
      38              :     bqs::GroupPolicy groupPolicy = bqs::GroupPolicy::HASH;
      39              :     uint32_t peerInstanceNum = 1U;
      40              :     uint32_t localInstanceIndex = 0U;
      41              :     uint32_t queueType = bqs::LOCAL_Q;
      42              : };
      43              : 
      44              : using DynamicRequestPtr = std::shared_ptr<DynamicSchedMgr::RequestInfo>;
      45              : 
      46              : constexpr uint32_t MBUF_HEAD_MAX_SIZE = 256U;
      47              : 
      48              : class Entity {
      49              : public:
      50              :     explicit Entity(const EntityMaterial& material, const uint32_t resIndex);
      51          369 :     virtual ~Entity() = default;
      52              :     Entity(const Entity&) = delete;
      53              :     Entity(const Entity&&) = delete;
      54              :     Entity& operator=(const Entity&) = delete;
      55              :     Entity& operator=(Entity&&) = delete;
      56              : 
      57              :     virtual FsmStatus Dequeue() = 0;
      58              :     virtual void SelectDstEntities(
      59              :         const uint64_t key, std::vector<Entity*>& toPushDstEntities, std::vector<Entity*>& reprocessDstEntities,
      60              :         std::vector<Entity*>& abnormalDstEntities) = 0;
      61              :     virtual FsmStatus ClearQueue() = 0;
      62              :     virtual FsmStatus PauseSubscribe(const Entity& fullEntity) = 0;
      63              :     virtual FsmStatus ResumeSubscribe(const Entity& notFullEntity) = 0;
      64              : 
      65              :     virtual FsmStatus Init(const FsmState state, const EntityDirection direction);
      66              :     virtual FsmStatus Uninit();
      67              :     virtual uint32_t GetQueueId() const;
      68              :     virtual FsmStatus ResetSrcState();
      69              :     virtual void ResetSrcSubState();
      70              :     virtual void ReprocessInTryPush(const Entity& srcEntity, DynamicRequestPtr& dynamicRequest, uint32_t& schedCfgKey);
      71              :     virtual FsmStatus AbProcessInTryPush();
      72              :     virtual FsmStatus SendData(const DataObjPtr dataObj);
      73              :     virtual bool IsDataPeeked() const;
      74              :     virtual FsmStatus MakeSureOutputCompletion();
      75              :     virtual uint32_t GetMbufDeviceId() const;
      76              :     virtual uint32_t GetMbufQueueType() const;
      77              : 
      78              :     FsmStatus AllowDeque();
      79              :     FsmStatus ProcessMessage(const InnerMessage& msg);
      80              :     FsmStatus ChangeState(const FsmState nextState);
      81              :     FsmStatus RemoveDataObjFromSendList(const DataObjPtr& dataObj);
      82              :     void RemoveRecvEntityFromSendList(const Entity* const recvEntityPtr);
      83              :     FsmStatus AddDataObjToSendList(const DataObjPtr& dataObj);
      84              :     FsmStatus AddDataObjToRecvList(const DataObjPtr& dataObj);
      85              :     const std::string& GetTypeDesc() const;
      86              :     const std::string& GetStateDesc(const FsmState id) const;
      87              :     bool Equal(const Entity* const recvEntityPtr) const;
      88              :     bool UpdateSendObject(const EntityPtr group, const EntityPtr elem);
      89              : 
      90           15 :     inline void AddScheduleCount() { scheduleCount_++; }
      91           50 :     inline void ResetScheduleCount() { scheduleCount_ = 0U; }
      92           24 :     inline uint32_t GetScheduleCount() const { return scheduleCount_; }
      93           58 :     inline EntityType GetType() const { return type_; }
      94          442 :     inline uint32_t GetId() const { return id_; }
      95           26 :     inline Mbuf* GetMbuf() const { return mbuf_; }
      96            2 :     inline void SetMbuf(Mbuf* const mbuf) { mbuf_ = mbuf; }
      97          795 :     inline uint32_t GetDeviceId() const { return deviceId_; }
      98           61 :     inline DataObjList& GetRecvDataObjs() { return recvDataObjs_; }
      99           34 :     inline const DataObjList& GetSendDataObjs() const { return sendDataObjs_; }
     100          279 :     inline uint32_t GetRefCount() const { return refCount_; }
     101          279 :     inline void DecreaseRefCount() { refCount_--; }
     102          294 :     inline void IncreaseRefCount() { refCount_++; }
     103         1802 :     inline EntityDirection GetDirection() const { return direction_; }
     104          944 :     inline FsmState GetCurState() const { return curState_; }
     105           51 :     inline uint64_t GetTransId() const { return transId_; }
     106            4 :     inline void SetTransId(const uint64_t transId) { transId_ = transId; }
     107           42 :     inline uint32_t GetRouteLabel() const { return routeLabel_; }
     108            4 :     inline void SetRouteLabel(const uint32_t routeLabel) { routeLabel_ = routeLabel; }
     109              : 
     110           59 :     inline uint32_t GetQueueType() const { return queueType_; }
     111              : 
     112           80 :     inline int32_t GetHostGroupId() const { return hostGroupId_; }
     113           49 :     inline void SetNeedTransId(const bool needTransId) { needTransId_ = needTransId; }
     114          160 :     inline bool IsNeedTransId() const { return needTransId_; }
     115            2 :     inline void SetMessageType(const InnerMsgType msgType) { msgType_ = msgType; }
     116           10 :     inline InnerMsgType GetMessageType() const { return msgType_; }
     117              : 
     118         1629 :     inline const std::string& ToString() const { return entityDesc_; }
     119              :     inline bqs::EntityStatisticInfo& GetStatisticInfo() { return statInfo_; }
     120            3 :     inline void SetWaitDecisionState(const bool waitState) { waitingDecision_ = waitState; }
     121           51 :     inline bool GetWaitDecisionState() const { return waitingDecision_; }
     122          289 :     inline uint32_t GetGlobalId() const { return globalId_; }
     123              : 
     124            3 :     inline uint32_t GetUuId() const { return uuId_; }
     125              : 
     126          286 :     inline uint32_t GetSchedCfgKey() const { return schedCfgKey_; }
     127              : 
     128          114 :     inline uint32_t GetResIndex() const { return resIndex_; }
     129              : 
     130            2 :     inline void SetDynamicReqTime(const uint64_t dynamicReqTime) { dynamicReqTime_ = dynamicReqTime; }
     131              : 
     132            1 :     inline uint64_t GetDynamicReqTime() const { return dynamicReqTime_; }
     133              : 
     134              : protected:
     135              :     EntityType type_;
     136              :     uint32_t id_;
     137              :     uint32_t deviceId_;
     138              :     // the group which this entity belong to
     139              :     int32_t hostGroupId_;
     140              :     uint32_t globalId_;
     141              :     uint32_t uuId_;
     142              :     uint32_t schedCfgKey_;
     143              :     uint32_t resIndex_;
     144              :     uint32_t queueType_;
     145              :     SubscribeStatus subscribeStatus_;
     146              :     uint32_t scheduleCount_;
     147              :     FsmState curState_;
     148              :     Mbuf* mbuf_;
     149              :     uint64_t transId_;
     150              :     uint32_t refCount_;
     151              :     EntityDirection direction_;
     152              :     // whether src entity need get transId from mbuf head
     153              :     bool needTransId_;
     154              :     InnerMsgType msgType_;
     155              :     uint32_t routeLabel_;
     156              :     bool waitingDecision_;
     157              :     uint64_t dynamicReqTime_;
     158              :     // entity desc
     159              :     std::string entityDesc_;
     160              :     // statistic info
     161              :     bqs::EntityStatisticInfo statInfo_;
     162              :     DataObjList recvDataObjs_;
     163              :     DataObjList sendDataObjs_;
     164              : };
     165              : } // namespace dgw
     166              : #endif
        

Generated by: LCOV version 2.0-1