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

Generated by: LCOV version 2.0-1