* Copyright (c) 2025 Huawei Technologies Co., Ltd.
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
* CANN Open Software License Agreement Version 2.0 (the "License").
* Please refer to the License for details. You may not use this file except in compliance with the License.
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
* See LICENSE in the root of the software repository for the full text of the License.
*/
#ifndef INC_TDT_TSD_H
#define INC_TDT_TSD_H
#include <sys/types.h>
#include <unistd.h>
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
* @ingroup Tsdaemon.
*
* Identifies that HCCP or Compute_process is waiting for
* Tsdaemon to issue a shutdown command.
*/
typedef enum {
TSD_HCCP = 0,
TSD_COMPUTE,
TSD_CUSTOM_COMPUTE,
TSD_QS,
TSD_WAITTYPE_MAX
} TsdWaitType;
typedef enum {
TSD_EVENT_START_RSP = 0,
TSD_EVENT_SHUTDOWN_RSP = 1,
TSD_EVENT_NOTIFY_AICPUINFO = 2,
TSD_EVENT_NOTIFY_AICPUINFO_RSP = 3,
TSD_EVENT_ABNORMAL = 4,
TSD_EVENT_SHUTDOWN = 5,
TSD_EVENT_LOAD_SO = 6,
TSD_EVENT_START_OR_STOP_FAIL = 7,
TSD_EVENT_GET_CAPABILITY = 8,
TSD_EVENT_START_AICPU_SD_MODULE = 30,
TSD_EVENT_START_AICPU_SD_MODULE_RSP = 31,
TSD_EVENT_START_QS_MODULE = 32,
TSD_EVENT_START_QS_MODULE_RSP = 33,
TSD_EVENT_STOP_AICPU_SD_MODULE = 34,
TSD_EVENT_STOP_AICPU_SD_MODULE_RSP = 35,
TSD_EVENT_STOP_QS_MODULE = 36,
TSD_EVENT_STOP_QS_MODULE_RSP = 37,
TSD_EVENT_STOP_SUB_PROCESS_WAIT = 38,
TSD_EVENT_STOP_AICPU_PROCESS_WAIT = 39,
TSD_EVENT_START_MC2_THREAD = 40,
TSD_EVENT_UPDATE_PROFILING_RSP = 41,
TSD_EVENT_START_UDF_DATADUMP_THREAD = 42,
TSD_EVENT_SET_SCHEDULE_MODE = 43,
TSD_EVENT_LOAD_PLATFORM_TO_CUST = 44,
TSD_EVENT_TYPE_MAX
} TsdSubEventType;
struct TsdCapabilityMsgInfo {
uint32_t subCapabityType;
uint32_t resultInfo;
};
#define MAX_THREAD_ID_CNT (23)
struct SubProcScheduleModeInfo {
uint32_t totalNum;
pid_t threadIdList[MAX_THREAD_ID_CNT];
};
#define MAX_EVENT_PRI_MSG_LENGTH (96U)
struct TsdSubEventInfo {
uint32_t deviceId;
uint32_t srcPid;
uint32_t dstPid;
uint32_t hostPid;
uint8_t vfId;
uint8_t rsv;
uint16_t reqId;
uint32_t procType;
uint32_t eventType;
uint32_t startProcPid;
char priMsg[MAX_EVENT_PRI_MSG_LENGTH];
};
typedef int32_t (* SubProcEventCallBackFuncInfo)(const struct TsdSubEventInfo * const msg);
struct SubProcEventCallBackInfo {
uint32_t eventType;
SubProcEventCallBackFuncInfo callBackFunc;
};
* @ingroup TsdWaitForShutdown
* @brief Wait for the TSD process to issue the shutdown command
*
* @par Function
* Wait for the TSD process to issue the shutdown command
*
* @param NA
* @param deviceId [IN] type #unsigned int. Physical device ID
* @param waitType [IN] type #TsdWaitType. HCCP or CP
* @param hostPid [IN] type #unsigned int. Host pid
* @param vfId [IN] type #unsigned int. Virtual force Id
* @retval 0 Success
* @retval OtherValues 0 Fail
*
* @par Dependency
* @li libtsdppc.so: Library to which the interface belongs.
* @li tsd.h: Header file where the interface declaration is located.
*/
int32_t TsdWaitForShutdown(const uint32_t deviceId, const TsdWaitType waitType,
const uint32_t hostPid, const uint32_t vfId);
* @ingroup TsdDestroy
* @brief tsd event client send abnormal msg to tsd event server
*
* @par Function
* tsd event client send abnormal msg to tsd event server
*
* @param NA
* @param deviceID [IN] type #unsigned int. Physical device ID
* @param waitType [IN] type #TsdWaitType. HCCP or CP
* @param hostPid [IN] type #unsigned int. Host pid
* @param vfId [IN] type #unsigned int. Virtual force id
* @retval 0 Success
* @retval OtherValues 0 Fail
*
* @par Dependency
* @li libtsdppc.so: Library to which the interface belongs.
* @li tsd.h: Header file where the interface declaration is located.
*/
int32_t TsdDestroy(const uint32_t deviceId, const TsdWaitType waitType,
const uint32_t hostPid, const uint32_t vfId);
* @ingroup CreateOrFindCustPid
* @brief inform tsdaemon start aicpu_cust_schedule
*
* @par Function
* inform tsdaemon start aicpu_cust_schedule
*
* @param NA
* @param deviceID [IN] type #unsigned int. Physical device ID
* @param loadLibNum [IN] type #unsigned int. Load so nums
* @param loadLibName [IN] type #char *. Load so names
* @param hostPid [IN] type #unsigned int. Host pid
* @param vfId [IN] vf id
* @param groupNameList [IN] group name list which cust aicpu need to attach
* @param groupNameNum [IN] group name number which cust aicpu need to attach
* @param custProcPid [OUT] cust aicpu pid
* @retval 0 Success
* @retval OtherValues 0 Fail
*
* @par Dependency
* @li libtsdppc.so: Library to which the interface belongs.
* @li tsd.h: Header file where the interface declaration is located.
*/
int32_t CreateOrFindCustPid(const uint32_t deviceId, const uint32_t loadLibNum, const char * const loadLibName[],
const uint32_t hostPid, const uint32_t vfId, const char * const groupNameList,
const uint32_t groupNameNum, int32_t * const custProcPid, bool * const firstStart);
* @ingroup TsdStartupResponse
* @brief Wait for the TSD process to issue the shutdown command
*
* @par Function
* Wait for the TSD process to issue the shutdown command
*
* @param NA
* @param deviceId [IN] type #unsigned int. Physical device ID
* @param waitType [IN] type #TsdWaitType. HCCP or CP
* @param hostPid [IN] type #unsigned int. Host pid
* @param vfId [IN] type #unsigned int. Virtual force Id
* @retval 0 Success
* @retval OtherValues 0 Fail
*
* @par Dependency
* @li libtsdppc.so: Library to which the interface belongs.
* @li tsd.h: Header file where the interface declaration is located.
*/
int32_t StartupResponse(const uint32_t deviceId, const TsdWaitType waitType,
const uint32_t hostPid, const uint32_t vfId);
* @ingroup TsdDoLoopProcessEvent
* @brief loop to keep process main thread running
*
* @par Function
* loop to keep process main thread running
*
* @param NA
* @param deviceId [IN] type #unsigned int. Physical device ID
* @retval 0 Success
* @retval OtherValues 0 Fail
*
* @par Dependency
* @li libtsdppc.so: Library to which the interface belongs.
* @li tsd.h: Header file where the interface declaration is located.
*/
int32_t WaitForShutDown(const uint32_t deviceId);
* @ingroup tsd_event_client
* @brief sub process send error code while start/stop period
* @param [in] deviceId : device id
* @param [in] waitType : process type
* @param [in] hostPid : host pid
* @param [in] vfId : vf id
* @param [in] errCode : errCode: errMsg code produced by host
* @param [in] errLen : errLen: errMsg code length
* @return TSD_OK: sucess, other: error code
*/
int32_t TsdReportStartOrStopErrCode(const uint32_t deviceId, const TsdWaitType waitType,
const uint32_t hostPid, const uint32_t vfId,
const char *errCode, const uint32_t errLen);
* @ingroup tsd_event_client
* @brief sub process send capability msg to tsd
* @param [in] deviceId : device id
* @param [in] waitType : process type
* @param [in] hostPid : host pid
* @param [in] vfId : vf id
* @param [in] msgInfo : capability
* @return TSD_OK: sucess, other: error code
*/
int32_t ReportMsgToTsd(const uint32_t deviceId, const TsdWaitType waitType,
const uint32_t hostPid, const uint32_t vfId,
const char * const msgInfo);
* @ingroup tsd_event_client
* @brief reg event call back func to tsdclient
* @param [in] SubProcEventCallBackInfo : event id, callbackfunc
* @return TSD_OK: sucess, other: error code
*/
int32_t RegEventMsgCallBackFunc(const struct SubProcEventCallBackInfo *regInfo);
* @ingroup tsd_event_client
* @brief unreg event call back func to tsdclient
* @param [in] : event id
* @return void
*/
void UnRegEventMsgCallBackFunc(const uint32_t eventType);
* @ingroup tsd_event_client
* @brief reg event call back func to tsdclient
* @param [in] SubProcEventCallBackInfo : event id, callbackfunc
* @return TSD_OK: sucess, other: error code
*/
* @ingroup tsd_event_client
* @brief sub module send start success message to tsd
* @param [in] deviceId : device id
* @param [in] waitType : process type
* @param [in] hostPid : host pid
* @param [in] vfId : vf id
* @param [in] eventType : eventType
* @return TSD_OK: sucess, other: error code
*/
int32_t SubModuleProcessResponse(const uint32_t deviceId, const TsdWaitType waitType,
const uint32_t hostPid, const uint32_t vfId,
const uint32_t eventType);
* @ingroup tsd_event_client
* @brief send start up msg to tsd and wait process
* @param [in] deviceId : device id
* @param [in] waitType : process type
* @param [in] hostPid : host pid
* @param [in] vfId : vf id
* @return TSD_OK: sucess, other: error code
*/
int32_t StartUpRspAndWaitProcess(const uint32_t deviceId, const TsdWaitType waitType,
const uint32_t hostPid, const uint32_t vfId);
* @ingroup StopWaitForCustAicpu
* @brief aicpu wait aicpu_cust_schedule attatch grp success
* @return TSD_OK: sucess, other: error code
*/
int32_t StopWaitForCustAicpu();
* @ingroup tsd_event_client
* @brief set tsd event dst pid
* @return TSD_OK: sucess, other: error code
*/
int32_t SetDstTsdEventPid(const uint32_t dstPid);
* @ingroup tsd_event_client
* @brief send profiling response msg to tsd and wait process
* @param [in] deviceId : device id
* @param [in] waitType : process type
* @param [in] hostPid : host pid
* @param [in] vfId : vf id
* @return TSD_OK: sucess, other: error code
*/
int32_t SendUpdateProfilingRspToTsd(const uint32_t deviceId, const uint32_t waitType,
const uint32_t hostPid, const uint32_t vfId);
* @ingroup tsd_event_client
* @brief send schedule mode to tsd
* @param [in] deviceId : device id
* @param [in] waitType : process type
* @param [in] hostPid : host pid
* @param [in] vfId : vf id
* @param [in] vfId : vf id
* @return TSD_OK: sucess, other: error code
*/
int32_t SetSubProcScheduleMode(const uint32_t deviceId, const uint32_t waitType,
const uint32_t hostPid, const uint32_t vfId,
const struct SubProcScheduleModeInfo *scheInfo);
* @ingroup SendStartUpFinishMsg
* @brief sub process start finisn and Wait for the TSD process to issue the shutdown command
*
* @par Function
* Wait for the TSD process to issue the shutdown command
*
* @param NA
* @param deviceId [IN] type #unsigned int. Physical device ID
* @param waitType [IN] type #TsdWaitType. HCCP or CP
* @param hostPid [IN] type #unsigned int. Host pid
* @param vfId [IN] type #unsigned int. Virtual force Id
* @retval 0 Success
* @retval OtherValues 0 Fail
*
* @par Dependency
* @li libtsdppc.so: Library to which the interface belongs.
* @li tsd.h: Header file where the interface declaration is located.
*/
int32_t SendStartUpFinishMsg(const uint32_t deviceId, const TsdWaitType waitType,
const uint32_t hostPid, const uint32_t vfId);
* @ingroup tsd_event_client
* @brief sub process send error code while start/stop period
* @param [in] deviceId : device id
* @param [in] waitType : process type
* @param [in] hostPid : host pid
* @param [in] vfId : vf id
* @param [in] errCode : errCode: errMsg code produced by host
* @param [in] errLen : errLen: errMsg code length
* @return TSD_OK: sucess, other: error code
*/
int32_t ReportProcessStartUpErrorCode(const uint32_t deviceId, const TsdWaitType waitType,
const uint32_t hostPid, const uint32_t vfId,
const char *errCode, const uint32_t errLen);
* @ingroup DestroySubProcess
* @brief tsd event client send abnormal msg to tsd event server
*
* @par Function
* tsd event client send abnormal msg to tsd event server
*
* @param NA
* @param deviceID [IN] type #unsigned int. Physical device ID
* @param waitType [IN] type #TsdWaitType. HCCP or CP
* @param hostPid [IN] type #unsigned int. Host pid
* @param vfId [IN] type #unsigned int. Virtual force id
* @retval 0 Success
* @retval OtherValues 0 Fail
*/
int32_t DestroySubProcess(const uint32_t deviceId, const TsdWaitType waitType,
const uint32_t hostPid, const uint32_t vfId);
#ifdef __cplusplus
}
#endif
#endif