LCOV - code coverage report
Current view: top level - aicpu_cust_schedule/core/cust_platform_info - aicpu_cust_platform_info_process.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 92.8 % 83 77
Test Date: 2026-07-28 10:54:05 Functions: 100.0 % 7 7

            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 "aicpu_cust_platform_info_process.h"
      11              : 
      12              : #include <dlfcn.h>
      13              : #include <semaphore.h>
      14              : #include "aicpusd_drv_manager.h"
      15              : #include "aicpusd_info.h"
      16              : #include "aicpusd_util.h"
      17              : #include "aicpu_cust_sd_proc_mgr_sys_operator_agent.h"
      18              : #include "aicpusd_interface_process.h"
      19              : namespace AicpuSchedule {
      20              : 
      21              :     const std::string CUSTOM_EXTEND_SO_PLATFORM_FUNC_NAME = "AicpuCustExtendKernelsLoadPlatformInfo";
      22            3 :     AicpuPlatformFuncPtr AicpuCustomSdLoadPlatformInfoProcess::GetAicpuPlatformFuncPtr()
      23              :     { 
      24            3 :         const std::lock_guard<std::mutex> lk(mutexForPlatformPtr);
      25            3 :         if (platformFuncPtr != nullptr) {
      26            0 :             return platformFuncPtr;
      27              :         }
      28            3 :         platformFuncPtr = reinterpret_cast<AicpuPlatformFuncPtr>(dlsym(RTLD_DEFAULT,
      29              :             CUSTOM_EXTEND_SO_PLATFORM_FUNC_NAME.c_str()));
      30            3 :         if (platformFuncPtr == nullptr) {
      31            3 :             aicpusd_err("failed to find func:%s, err:%s", CUSTOM_EXTEND_SO_PLATFORM_FUNC_NAME.c_str(), dlerror());
      32              :         }
      33            3 :         return platformFuncPtr;
      34            3 :     }
      35            1 :     AicpuCustomSdLoadPlatformInfoProcess::AicpuCustomSdLoadPlatformInfoProcess():platformFuncPtr(nullptr)
      36              :     {
      37            1 :     }
      38            1 :     AicpuCustomSdLoadPlatformInfoProcess::~AicpuCustomSdLoadPlatformInfoProcess()
      39              :     {
      40            1 :     }
      41            8 :     AicpuCustomSdLoadPlatformInfoProcess &AicpuCustomSdLoadPlatformInfoProcess::GetInstance()
      42              :     {
      43            8 :         static AicpuCustomSdLoadPlatformInfoProcess instance;
      44            8 :         return instance;
      45              :     }
      46            3 :     int32_t AicpuCustomSdLoadPlatformInfoProcess::ProcessLoadPlatform(const uint8_t * const msgInfo, const uint32_t infoLen)
      47              :     {
      48            3 :         aicpusd_info("ProcessLoadPlatform begin.");
      49            3 :         int32_t ret = 0;
      50            3 :         uint32_t headLen = sizeof(struct event_sync_msg);
      51            3 :         uint8_t msg[EVENT_MAX_MSG_LEN] = {};
      52            3 :         int32_t len = sizeof(uint8_t) * EVENT_MAX_MSG_LEN - headLen;
      53            3 :         int32_t rLen = infoLen - headLen;
      54            3 :         ret = memcpy_s(msg, len, (msgInfo + headLen), rLen);
      55            3 :         if (ret != 0) {
      56            0 :             aicpusd_err("Memcpy failed. ret[%d] len[%d], rlen[%d]", ret, len, rLen);
      57            0 :             return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
      58              :         }
      59            3 :         const AICPULoadPlatformCustInfo * const info = PtrToPtr<const uint8_t, const AICPULoadPlatformCustInfo>(msg);
      60              : 
      61            3 :         AicpuPlatformFuncPtr funcPtr = GetAicpuPlatformFuncPtr();
      62            3 :         if (funcPtr == nullptr) {
      63            2 :             aicpusd_err("failed to find func:%s", CUSTOM_EXTEND_SO_PLATFORM_FUNC_NAME.c_str());
      64            2 :             return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
      65              :         }
      66            1 :         if (info->platformInfo == 0LU || info->length == 0LU) {
      67            1 :             aicpusd_err("info->platformInfo is nullptr or info->length is %llu", info->length);
      68              :         }
      69            1 :         aicpusd_info("func:%s process, info[%llu], length[%llu], pid[%u]", CUSTOM_EXTEND_SO_PLATFORM_FUNC_NAME.c_str(), info->platformInfo, info->length, info->aicpuPid);
      70            1 :         ret = funcPtr(info->platformInfo, info->length);
      71            1 :         if (ret != AICPU_SCHEDULE_OK) {
      72            0 :             aicpusd_err("func:%s process failed, ret:%u, info[%llu], length[%llu], pid[%u]",
      73              :                 CUSTOM_EXTEND_SO_PLATFORM_FUNC_NAME.c_str(), ret, info->platformInfo, info->length, info->aicpuPid);
      74              :         }
      75            1 :         struct event_proc_result rsp = {};
      76            1 :         rsp.ret = ret;
      77            1 :         ret = DoSubmitEventSync(msg, len, rsp);
      78            1 :         if (ret != 0) {
      79            0 :             aicpusd_err("DoSubmitEventSync failed, ret[%d]", ret);
      80            0 :             return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
      81              :         }
      82            1 :         aicpusd_info("ProcessLoadPlatform finish.");
      83            1 :         return AICPU_SCHEDULE_OK;
      84              :     }
      85            4 :     int32_t AicpuCustomSdLoadPlatformInfoProcess::DoSubmitEventSync(const uint8_t * const msg,
      86              :         const uint32_t len, struct event_proc_result &rsp) const
      87              :     {
      88            4 :         uint32_t headLen = sizeof(struct event_sync_msg);
      89            4 :         if (len < headLen) {
      90            1 :             aicpusd_err("len[%u], headLen[%u].", len, headLen);
      91            1 :             return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
      92              :         }
      93            3 :         struct event_sync_msg msgHead = {};
      94            3 :         auto ret = memcpy_s(&msgHead, headLen, msg, headLen);
      95            3 :         if (ret != 0) {
      96            1 :             aicpusd_err("Memcpy failed. ret[%d], size[%u].", ret, headLen);
      97            1 :             return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
      98              :         }
      99            2 :         struct event_summary backEvent = {};
     100              : 
     101            2 :         backEvent.dst_engine = msgHead.dst_engine;
     102            2 :         backEvent.policy = ONLY;
     103            2 :         backEvent.pid = msgHead.pid;
     104            2 :         backEvent.grp_id = msgHead.gid;
     105            2 :         backEvent.event_id =  static_cast<EVENT_ID>(msgHead.event_id);
     106            2 :         backEvent.subevent_id = msgHead.subevent_id;
     107            2 :         backEvent.msg_len = sizeof(struct event_proc_result);
     108            2 :         backEvent.msg = PtrToPtr<struct event_proc_result, char_t>(&rsp);
     109            2 :         const uint32_t deviceId = AicpuDrvManager::GetInstance().GetDeviceId();
     110            2 :         ret = halEschedSubmitEvent(deviceId, &backEvent);
     111            2 :         aicpusd_info("backEvent dst[%d], pid[%d], grpId[%d], eventId[%d], subeventId[%d], msgLen[%d], deviceId[%u]",
     112              :             backEvent.dst_engine, backEvent.pid, backEvent.grp_id, backEvent.event_id,
     113              :             backEvent.subevent_id, backEvent.msg_len, deviceId);
     114            2 :         if (ret != 0) {
     115            1 :             aicpusd_err("halEschedSubmitEvent, ret=%d. dst[%d],pid[%d],"
     116              :                 " grpId[%d], eventId[%d], subeventId[%d], msgLen[%d], deviceId[%u]",
     117              :                 ret, backEvent.dst_engine, backEvent.pid, backEvent.grp_id,
     118              :                 backEvent.event_id, backEvent.subevent_id, backEvent.msg_len, deviceId);
     119            1 :                 return ret;
     120              :         }
     121            1 :         return AICPU_SCHEDULE_OK;
     122              :     }
     123              : }
     124            4 : int32_t CustProcessLoadPlatform(const struct event_info * const msg)
     125              : {
     126            4 :     if (msg == nullptr) {
     127            1 :         aicpusd_err("msg is nullptr.");
     128            1 :         return AicpuSchedule::AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
     129              :     }
     130            3 :     uint8_t message[EVENT_MAX_MSG_LEN] = {};
     131            3 :     auto ret = memcpy_s(message, EVENT_MAX_MSG_LEN, msg->priv.msg, msg->priv.msg_len);
     132            3 :     if (ret != 0) {
     133            1 :         aicpusd_err("Memcpy failed. ret[%d], size[%u].", ret, msg->priv.msg_len);
     134            1 :         return AicpuSchedule::AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
     135              :     }
     136            2 :     return AicpuSchedule::AicpuCustomSdLoadPlatformInfoProcess::GetInstance().ProcessLoadPlatform(message,
     137            2 :         EVENT_MAX_MSG_LEN);
     138              : }
        

Generated by: LCOV version 2.0-1