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

Generated by: LCOV version 2.0-1