LCOV - code coverage report
Current view: top level - acl/acl_tdt_queue - queue_process_sp.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 96.6 % 146 141
Test Date: 2026-07-28 10:53:01 Functions: 100.0 % 9 9

            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 "queue_process_sp.h"
      11              : #include "log_inner.h"
      12              : #include "runtime/rt_mem_queue.h"
      13              : #include "runtime/dev.h"
      14              : #include "queue_schedule/qs_client.h"
      15              : #include "utils/data_type_utils.h"
      16              : 
      17              : namespace acl {
      18            1 : aclError QueueProcessorSp::GrantQueue2Cp(const int32_t deviceId, const uint32_t qid) const
      19              : {
      20              :     int32_t cpPid;
      21              :     // if cp is found
      22            1 :     if (GetDstInfo(deviceId, CP_PID, cpPid) == ACL_SUCCESS) {
      23              :         rtMemQueueShareAttr_t permission;
      24            2 :         ACL_REQUIRES_OK(GetQueuePermission(deviceId, qid, permission));
      25            1 :         if (permission.manage != 0U) {
      26            0 :             ACL_REQUIRES_RTS_OK_WARN_NOT_SUPPORT(rtMemQueueGrant(deviceId, qid, cpPid, &permission), rtMemQueueGrant);
      27              :         } else {
      28            1 :             ACL_LOG_INNER_ERROR("current process has no manage permission on qid %u", qid);
      29            1 :             return ACL_ERROR_FAILURE;
      30              :         }
      31              :     }
      32            0 :     return ACL_SUCCESS;
      33              : }
      34              : 
      35            3 : aclError QueueProcessorSp::acltdtCreateQueue(const acltdtQueueAttr* const attr, uint32_t* const qid)
      36              : {
      37            3 :     ACL_LOG_INFO("Start to acltdtCreateQueue");
      38            3 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(qid);
      39            2 :     constexpr int32_t deviceId = 0;
      40              :     static bool isQueueIint = false;
      41            2 :     const std::lock_guard<std::recursive_mutex> lk(muForQueueCtrl_);
      42            2 :     if (!isQueueIint) {
      43            1 :         ACL_LOG_INFO("need to init queue once");
      44            1 :         const rtError_t ret = rtMemQueueInit(deviceId);
      45            1 :         if ((ret != ACL_RT_SUCCESS) && (ret != ACL_ERROR_RT_REPEATED_INIT)) {
      46            0 :             return ret;
      47              :         }
      48            1 :         isQueueIint = true;
      49              :     }
      50              : 
      51            2 :     ACL_REQUIRES_OK(acltdtCreateQueueWithAttr(deviceId, attr, qid));
      52            2 :     int32_t cpPid = 0;
      53            2 :     if (GetDstInfo(deviceId, CP_PID, cpPid) == ACL_SUCCESS) {
      54            2 :         ACL_LOG_INFO("get cp pid %d", cpPid);
      55            2 :         rtMemQueueShareAttr_t rtAttr = {0U, 0U, 0U, 0U};
      56            2 :         rtAttr.read = 1U;
      57            2 :         rtAttr.manage = 1U;
      58            2 :         rtAttr.write = 1U;
      59            2 :         ACL_REQUIRES_RTS_OK_WARN_NOT_SUPPORT(rtMemQueueGrant(deviceId, *qid, cpPid, &rtAttr), rtMemQueueGrant);
      60              :     }
      61            2 :     ACL_LOG_INFO("Successfully to execute acltdtCreateQueue, qid is %u", *qid);
      62            2 :     return ACL_SUCCESS;
      63            2 : }
      64              : 
      65            1 : aclError QueueProcessorSp::acltdtDestroyQueue(const uint32_t qid) { return acltdtDestroyQueueOndevice(qid); }
      66              : 
      67            1 : aclError QueueProcessorSp::acltdtGrantQueue(
      68              :     const uint32_t qid, const int32_t pid, const uint32_t permission, const int32_t timeout)
      69              : {
      70            1 :     ACL_LOG_INFO(
      71              :         "start to acltdtGrantQueue, qid is %u, pid is %d, permisiion is %u, timeout is %d", qid, pid, permission,
      72              :         timeout);
      73            1 :     constexpr int32_t deviceId = 0;
      74            1 :     rtMemQueueShareAttr_t attr = {0U, 0U, 0U, 0U};
      75            1 :     attr.manage = permission & static_cast<uint32_t>(ACL_TDT_QUEUE_PERMISSION_MANAGE);
      76            1 :     attr.read = permission & static_cast<uint32_t>(ACL_TDT_QUEUE_PERMISSION_DEQUEUE);
      77            1 :     attr.write = permission & static_cast<uint32_t>(ACL_TDT_QUEUE_PERMISSION_ENQUEUE);
      78            1 :     const std::lock_guard<std::recursive_mutex> lk(muForQueueCtrl_);
      79            1 :     ACL_REQUIRES_RTS_OK_WARN_NOT_SUPPORT(rtMemQueueGrant(deviceId, qid, pid, &attr), rtMemQueueGrant);
      80            1 :     ACL_LOG_INFO(
      81              :         "successfully execute acltdtGrantQueue, qid is %u, pid is %d, permisiion is %u, timeout is %d", qid, pid,
      82              :         permission, timeout);
      83            1 :     return ACL_SUCCESS;
      84            1 : }
      85              : 
      86            1 : aclError QueueProcessorSp::acltdtAttachQueue(const uint32_t qid, const int32_t timeout, uint32_t* const permission)
      87              : {
      88            1 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(permission);
      89            1 :     ACL_LOG_INFO("start to acltdtAttachQueue, qid is %u, permisiion is %u, timeout is %d", qid, *permission, timeout);
      90            1 :     constexpr int32_t deviceId = 0;
      91            1 :     const std::lock_guard<std::recursive_mutex> lk(muForQueueCtrl_);
      92            1 :     ACL_REQUIRES_RTS_OK_WARN_NOT_SUPPORT(rtMemQueueAttach(deviceId, qid, timeout), rtMemQueueAttach);
      93            1 :     (void)GrantQueue2Cp(deviceId, qid);
      94              :     rtMemQueueShareAttr_t attr;
      95            1 :     ACL_REQUIRES_OK(GetQueuePermission(deviceId, qid, attr));
      96            1 :     uint32_t tmp = 0U;
      97            1 :     tmp = (attr.manage != 0) ? (tmp | static_cast<uint32_t>(ACL_TDT_QUEUE_PERMISSION_MANAGE)) : tmp;
      98            1 :     tmp = (attr.read != 0) ? (tmp | static_cast<uint32_t>(ACL_TDT_QUEUE_PERMISSION_DEQUEUE)) : tmp;
      99            1 :     tmp = (attr.write != 0) ? (tmp | static_cast<uint32_t>(ACL_TDT_QUEUE_PERMISSION_ENQUEUE)) : tmp;
     100            1 :     *permission = tmp;
     101            1 :     ACL_LOG_INFO(
     102              :         "successfully execute acltdtAttachQueue, qid is %u, permisiion is %u, timeout is %d", qid, *permission,
     103              :         timeout);
     104            1 :     return ACL_SUCCESS;
     105            1 : }
     106              : 
     107            2 : aclError QueueProcessorSp::acltdtBindQueueRoutes(acltdtQueueRouteList* const qRouteList)
     108              : {
     109            2 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(qRouteList);
     110            2 :     ACL_LOG_INFO("Start to acltdtBindQueueRoutes, queue route is %zu", qRouteList->routeList.size());
     111            2 :     constexpr int32_t deviceId = 0;
     112              :     // get dst id
     113            2 :     ACL_REQUIRES_OK(InitQueueSchedule(deviceId));
     114            2 :     int32_t dstPid = 0;
     115            2 :     ACL_REQUIRES_OK(GetDstInfo(deviceId, QS_PID, dstPid));
     116            2 :     const std::lock_guard<std::recursive_mutex> lk(muForQueueCtrl_);
     117            4 :     for (size_t i = 0UL; i < qRouteList->routeList.size(); ++i) {
     118            2 :         rtMemQueueShareAttr_t attrSrc = {0U, 0U, 0U, 0U};
     119            2 :         attrSrc.read = 1U;
     120            2 :         rtMemQueueShareAttr_t attrDst = {0U, 0U, 0U, 0U};
     121            2 :         attrDst.write = 1U;
     122            2 :         ACL_REQUIRES_RTS_OK_WARN_NOT_SUPPORT(
     123              :             rtMemQueueGrant(deviceId, qRouteList->routeList[i].srcId, dstPid, &attrSrc), rtMemQueueGrant);
     124            2 :         ACL_REQUIRES_RTS_OK_WARN_NOT_SUPPORT(
     125              :             rtMemQueueGrant(deviceId, qRouteList->routeList[i].dstId, dstPid, &attrDst), rtMemQueueGrant);
     126              :     }
     127            2 :     rtEschedEventSummary_t eventSum = {0, 0U, 0, 0U, 0U, nullptr, 0U, 0};
     128            2 :     rtEschedEventReply_t ack = {nullptr, 0U, 0U};
     129            2 :     bqs::QsProcMsgRsp qsRsp = {0UL, 0, 0U, 0U, 0U, {0}};
     130            2 :     eventSum.pid = dstPid;
     131            2 :     eventSum.grpId = bqs::BIND_QUEUE_GROUP_ID;
     132            2 :     eventSum.eventId = RT_MQ_SCHED_EVENT_QS_MSG;
     133            2 :     eventSum.dstEngine = static_cast<uint32_t>(RT_MQ_DST_ENGINE_CCPU_DEVICE);
     134            2 :     ack.buf = reinterpret_cast<char_t*>(&qsRsp);
     135            2 :     ack.bufLen = sizeof(qsRsp);
     136            2 :     if (!isQsInit_) {
     137            1 :         ACL_REQUIRES_OK(SendConnectQsMsg(deviceId, eventSum, ack));
     138            1 :         ACL_REQUIRES_RTS_OK_WARN_NOT_SUPPORT(rtMemQueueAttach(deviceId, qsContactId_, 0), rtMemQueueAttach);
     139            1 :         isQsInit_ = true;
     140              :     }
     141            2 :     ACL_REQUIRES_OK(SendBindUnbindMsgOnDevice(qRouteList, true, eventSum, ack));
     142            0 :     ACL_LOG_INFO("Successfully to execute acltdtBindQueueRoutes, queue route is %zu", qRouteList->routeList.size());
     143            0 :     return ACL_SUCCESS;
     144            2 : }
     145              : 
     146            1 : aclError QueueProcessorSp::acltdtUnbindQueueRoutes(acltdtQueueRouteList* const qRouteList)
     147              : {
     148            1 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(qRouteList);
     149            1 :     ACL_LOG_INFO("Start to acltdtUnBindQueueRoutes, queue route is %zu", qRouteList->routeList.size());
     150            1 :     constexpr int32_t deviceId = 0;
     151              :     // get dst id
     152            1 :     int32_t dstPid = 0;
     153            1 :     ACL_REQUIRES_OK(GetDstInfo(deviceId, QS_PID, dstPid));
     154            1 :     rtEschedEventSummary_t eventSum = {0, 0U, 0, 0U, 0U, nullptr, 0U, 0};
     155            1 :     rtEschedEventReply_t ack = {nullptr, 0U, 0U};
     156            1 :     bqs::QsProcMsgRsp qsRsp = {0UL, 0, 0U, 0U, 0U, {0}};
     157            1 :     eventSum.pid = dstPid;
     158            1 :     eventSum.grpId = bqs::BIND_QUEUE_GROUP_ID;
     159            1 :     eventSum.eventId = RT_MQ_SCHED_EVENT_QS_MSG;
     160            1 :     eventSum.dstEngine = static_cast<uint32_t>(RT_MQ_DST_ENGINE_CCPU_DEVICE);
     161            1 :     ack.buf = reinterpret_cast<char_t*>(&qsRsp);
     162            1 :     ack.bufLen = sizeof(qsRsp);
     163            1 :     const std::lock_guard<std::recursive_mutex> lk(muForQueueCtrl_);
     164            1 :     ACL_REQUIRES_OK(SendBindUnbindMsgOnDevice(qRouteList, false, eventSum, ack));
     165            1 :     ACL_LOG_INFO("Successfully to execute acltdtUnBindQueueRoutes, queue route is %zu", qRouteList->routeList.size());
     166            1 :     return ACL_SUCCESS;
     167            1 : }
     168              : 
     169            1 : aclError QueueProcessorSp::acltdtQueryQueueRoutes(
     170              :     const acltdtQueueRouteQueryInfo* const queryInfo, acltdtQueueRouteList* const qRouteList)
     171              : {
     172            1 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(queryInfo);
     173            1 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(qRouteList);
     174            1 :     ACL_LOG_INFO("Start to acltdtQueryQueueRoutes");
     175            1 :     constexpr int32_t deviceId = 0;
     176              :     // get dst id
     177            1 :     int32_t dstPid = 0;
     178            1 :     ACL_REQUIRES_OK(GetDstInfo(deviceId, QS_PID, dstPid));
     179            1 :     rtEschedEventSummary_t eventSum = {0, 0U, 0, 0U, 0U, nullptr, 0U, 0};
     180            1 :     rtEschedEventReply_t ack = {nullptr, 0U, 0U};
     181            1 :     bqs::QsProcMsgRsp qsRsp = {0UL, 0, 0U, 0U, 0U, {0}};
     182            1 :     eventSum.pid = dstPid;
     183            1 :     eventSum.grpId = bqs::BIND_QUEUE_GROUP_ID;
     184            1 :     eventSum.eventId = RT_MQ_SCHED_EVENT_QS_MSG;
     185            1 :     eventSum.dstEngine = static_cast<uint32_t>(RT_MQ_DST_ENGINE_CCPU_DEVICE);
     186            1 :     ack.buf = reinterpret_cast<char_t*>(&qsRsp);
     187            1 :     ack.bufLen = sizeof(qsRsp);
     188            1 :     const std::lock_guard<std::recursive_mutex> lk(muForQueueCtrl_);
     189            1 :     size_t routeNum = 0UL;
     190            1 :     ACL_REQUIRES_OK(GetQueueRouteNum(queryInfo, deviceId, eventSum, ack, routeNum));
     191            1 :     ACL_REQUIRES_OK(QueryQueueRoutesOnDevice(queryInfo, routeNum, eventSum, ack, qRouteList));
     192            1 :     return ACL_SUCCESS;
     193            1 : }
     194              : 
     195            6 : aclError QueueProcessorSp::acltdtAllocBuf(const size_t size, const uint32_t type, acltdtBuf* const buf)
     196              : {
     197            6 :     if ((type != static_cast<uint32_t>(ACL_TDT_NORMAL_MEM)) && (type != static_cast<uint32_t>(ACL_TDT_DVPP_MEM))) {
     198            1 :         acl::AclErrorLogManager::ReportInputError(
     199            2 :             acl::INVALID_VALUE_MSG, std::vector<const char*>({"func", "value", "param", "expect"}),
     200            1 :             std::vector<const char*>(
     201            2 :                 {__func__, acl::GetAllocBufTypeDesc(static_cast<acltdtAllocBufType>(type)), "type",
     202            2 :                  "[ACL_TDT_NORMAL_MEM, ACL_TDT_DVPP_MEM]"}));
     203            1 :         ACL_LOG_ERROR("[Check][Param]param type must be equal to zero currently");
     204            1 :         return ACL_ERROR_INVALID_PARAM;
     205              :     }
     206            5 :     ACL_REQUIRES_OK(QueryAllocGroup());
     207            5 :     ACL_REQUIRES_OK(acltdtAllocBufData(size, type, buf));
     208            5 :     return ACL_SUCCESS;
     209              : }
     210              : } // namespace acl
        

Generated by: LCOV version 2.0-1