LCOV - code coverage report
Current view: top level - aicpu_schedule/core/platform_info - aicpusd_send_platform_Info_to_custom.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 61.6 % 73 45
Test Date: 2026-08-12 11:05:02 Functions: 83.3 % 6 5

            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              : #include "aicpusd_send_platform_Info_to_custom.h"
      11              : 
      12              : #include <string>
      13              : #include <sched.h>
      14              : #include <memory>
      15              : #include <semaphore.h>
      16              : #include <unistd.h>
      17              : #include "aicpusd_drv_manager.h"
      18              : #include "aicpusd_info.h"
      19              : #include "aicpusd_util.h"
      20              : #include "aicpusd_proc_mgr_sys_operator_agent.h"
      21              : #include "aicpusd_interface_process.h"
      22              : #include "type_def.h"
      23              : 
      24              : namespace AicpuSchedule {
      25              : namespace {
      26              : // aicpusd 与 custaicpusd 是同样的groupid
      27              : constexpr const uint64_t DATA_DUMP_EVENT_MASK = (1ULL << static_cast<uint32_t>(EVENT_CCPU_CTRL_MSG));
      28              : constexpr const int32_t DATA_DUMP_TIMEOUT_INTERVAL = 3000;
      29              : constexpr const uint32_t SLEEP_USECS = 50000U;
      30              : }; // namespace
      31              : 
      32            9 : AicpuSdLoadPlatformInfoProcess& AicpuSdLoadPlatformInfoProcess::GetInstance()
      33              : {
      34              :     static AicpuSdLoadPlatformInfoProcess instance;
      35            9 :     return instance;
      36              : }
      37            2 : void AicpuSdLoadPlatformInfoProcess::LoadPlatformInfoSemPost() { sem_post(&loadPlatformInfoProcessSem_); }
      38            0 : int32_t AicpuSdLoadPlatformInfoProcess::SendLoadPlatformInfoMessageToCustSync(
      39              :     const uint8_t* const msg, const uint32_t len) const
      40              : {
      41              :     event_reply drvAck;
      42              :     event_proc_result result;
      43            0 :     drvAck.buf = PtrToPtr<event_proc_result, char_t>(&result);
      44            0 :     drvAck.buf_len = sizeof(event_proc_result);
      45              : 
      46            0 :     pid_t aicpuCustomPid = AicpuScheduleInterface::GetInstance().GetAicpuCustSdProcId();
      47            0 :     event_summary drvEvent = {};
      48            0 :     drvEvent.dst_engine = CCPU_DEVICE;
      49            0 :     drvEvent.policy = ONLY;
      50            0 :     drvEvent.pid = aicpuCustomPid;
      51            0 :     drvEvent.grp_id = 31U;
      52            0 :     drvEvent.event_id = EVENT_CCPU_CTRL_MSG;
      53            0 :     drvEvent.subevent_id = static_cast<uint32_t>(AICPU_SUB_EVENT_CUST_LOAD_PLATFORM);
      54            0 :     drvEvent.msg_len = EVENT_MAX_MSG_LEN;
      55            0 :     uint8_t eventMsg[EVENT_MAX_MSG_LEN] = {};
      56            0 :     auto eRet = memset_s(eventMsg, drvEvent.msg_len, 0, drvEvent.msg_len);
      57            0 :     if (eRet != EOK) {
      58            0 :         aicpusd_run_warn("Mem set error, ret=%d", eRet);
      59              :     }
      60              :     eRet =
      61            0 :         memcpy_s(eventMsg + sizeof(struct event_sync_msg), EVENT_MAX_MSG_LEN - sizeof(struct event_sync_msg), msg, len);
      62            0 :     if (eRet != EOK) {
      63            0 :         aicpusd_err("Fail to memcpy, ret=[%d].", eRet);
      64            0 :         return eRet;
      65              :     }
      66            0 :     drvEvent.msg = PtrToPtr<uint8_t, char_t>(eventMsg);
      67            0 :     const uint32_t deviceId = AicpuDrvManager::GetInstance().GetDeviceId();
      68            0 :     int32_t ret = halEschedSubmitEventSync(deviceId, &drvEvent, 5000, &drvAck);
      69            0 :     if (ret != DRV_ERROR_NONE) {
      70            0 :         aicpusd_err(
      71              :             "halEschedSubmitEventSync failed, ret:%d, devid:%u, aicpuCustomPid:%u", ret, deviceId, aicpuCustomPid);
      72            0 :         return AICPU_SCHEDULE_ERROR_DRV_ERR;
      73              :     }
      74            0 :     aicpusd_info("send Platform Info msg success, devid:%u, aicpuCustomPid:%u", deviceId, aicpuCustomPid);
      75            0 :     return AICPU_SCHEDULE_OK;
      76              : }
      77              : 
      78            6 : int32_t AicpuSdLoadPlatformInfoProcess::SendMsgToMain(const void* const msg, const uint32_t len)
      79              : {
      80            6 :     TsdSubEventInfo msgInfo = {};
      81            6 :     auto eRet = memcpy_s(&msgInfo, sizeof(TsdSubEventInfo), msg, len);
      82            6 :     if (eRet != EOK) {
      83            1 :         aicpusd_err("Fail to memcpy, ret=[%d].", eRet);
      84            1 :         return eRet;
      85              :     }
      86            5 :     event_summary eventInfo = {};
      87            5 :     eventInfo.pid = static_cast<pid_t>(getpid());
      88            5 :     eventInfo.grp_id = 30U;
      89            5 :     eventInfo.dst_engine = CCPU_DEVICE;
      90            5 :     eventInfo.event_id = EVENT_CCPU_CTRL_MSG;
      91            5 :     eventInfo.subevent_id = TSD_EVENT_LOAD_PLATFORM_TO_CUST;
      92            5 :     eventInfo.msg_len = sizeof(TsdSubEventInfo);
      93            5 :     eventInfo.msg = PtrToPtr<TsdSubEventInfo, char_t>(&msgInfo);
      94              : 
      95            5 :     uint32_t deviceId = AicpuDrvManager::GetInstance().GetDeviceId();
      96            5 :     const int32_t semRet = sem_init(&loadPlatformInfoProcessSem_, 0, 0U);
      97            5 :     if (semRet == -1) {
      98            1 :         aicpusd_err("loadPlatformInfoProcessSem_ init failed, %s", strerror(errno));
      99            1 :         return AICPU_SCHEDULE_ERROR_INIT_FAILED;
     100              :     }
     101            4 :     const drvError_t ret = halEschedSubmitEvent(deviceId, &eventInfo);
     102            4 :     if (ret != DRV_ERROR_NONE) {
     103            1 :         sem_destroy(&loadPlatformInfoProcessSem_);
     104            1 :         aicpusd_err("Failed to submit, eventId: [%d], ret: [%d].", TSD_EVENT_LOAD_PLATFORM_TO_CUST, ret);
     105            1 :         return AICPU_SCHEDULE_ERROR_DRV_ERR;
     106              :     }
     107            3 :     const int32_t semWaitRet = sem_wait(&loadPlatformInfoProcessSem_);
     108            3 :     if (semWaitRet == -1) {
     109            1 :         sem_destroy(&loadPlatformInfoProcessSem_);
     110            1 :         aicpusd_err("workerSme wait failed, %s", strerror(errno));
     111            1 :         return AICPU_SCHEDULE_ERROR_INIT_FAILED;
     112              :     }
     113            2 :     sem_destroy(&loadPlatformInfoProcessSem_);
     114            2 :     return AICPU_SCHEDULE_OK;
     115              : }
     116              : } // namespace AicpuSchedule
     117              : 
     118            2 : int32_t SendLoadPlatformInfoToCust(const struct TsdSubEventInfo* const msg)
     119              : {
     120            2 :     uint8_t message[EVENT_MAX_MSG_LEN] = {};
     121            2 :     auto len = sizeof(struct AICPULoadPlatformCustInfo);
     122              :     const AicpuSchedule::ScopeGuard ideSessGuard(
     123            4 :         []() { AicpuSchedule::AicpuSdLoadPlatformInfoProcess::GetInstance().LoadPlatformInfoSemPost(); });
     124            2 :     auto ret = memcpy_s(message, EVENT_MAX_MSG_LEN, msg, len);
     125            2 :     if (ret != 0) {
     126            1 :         aicpusd_err("Memcpy failed. ret[%d], size[%u].", ret, len);
     127            1 :         return AicpuSchedule::AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
     128              :     }
     129            1 :     return AicpuSchedule::AicpuSdLoadPlatformInfoProcess::GetInstance().SendLoadPlatformInfoMessageToCustSync(
     130            1 :         message, len);
     131            2 : }
        

Generated by: LCOV version 2.0-1