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 % 145 140
Test Date: 2026-08-06 15:29:52 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)
      66              :     {
      67            1 :         return acltdtDestroyQueueOndevice(qid);
      68              :     }
      69              : 
      70            1 :     aclError QueueProcessorSp::acltdtGrantQueue(const uint32_t qid, const int32_t pid, const uint32_t permission,
      71              :         const int32_t timeout)
      72              :     {
      73            1 :         ACL_LOG_INFO("start to acltdtGrantQueue, qid is %u, pid is %d, permisiion is %u, timeout is %d",
      74              :                      qid, pid, permission, timeout);
      75            1 :         constexpr int32_t deviceId = 0;
      76            1 :         rtMemQueueShareAttr_t attr = {0U, 0U, 0U, 0U};
      77            1 :         attr.manage = permission & static_cast<uint32_t>(ACL_TDT_QUEUE_PERMISSION_MANAGE);
      78            1 :         attr.read = permission & static_cast<uint32_t>(ACL_TDT_QUEUE_PERMISSION_DEQUEUE);
      79            1 :         attr.write = permission & static_cast<uint32_t>(ACL_TDT_QUEUE_PERMISSION_ENQUEUE);
      80            1 :         const std::lock_guard<std::recursive_mutex> lk(muForQueueCtrl_);
      81            1 :         ACL_REQUIRES_RTS_OK_WARN_NOT_SUPPORT(rtMemQueueGrant(deviceId, qid, pid, &attr), rtMemQueueGrant);
      82            1 :         ACL_LOG_INFO("successfully execute acltdtGrantQueue, qid is %u, pid is %d, permisiion is %u, timeout is %d",
      83              :                      qid, pid, permission, timeout);
      84            1 :         return ACL_SUCCESS;
      85            1 :     }
      86              : 
      87            1 :     aclError QueueProcessorSp::acltdtAttachQueue(const uint32_t qid, const int32_t timeout,
      88              :         uint32_t *const permission)
      89              :     {
      90            1 :         ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(permission);
      91            1 :         ACL_LOG_INFO("start to acltdtAttachQueue, qid is %u, permisiion is %u, timeout is %d",
      92              :                      qid, *permission, timeout);
      93            1 :         constexpr int32_t deviceId = 0;
      94            1 :         const std::lock_guard<std::recursive_mutex> lk(muForQueueCtrl_);
      95            1 :         ACL_REQUIRES_RTS_OK_WARN_NOT_SUPPORT(rtMemQueueAttach(deviceId, qid, timeout), rtMemQueueAttach);
      96            1 :         (void)GrantQueue2Cp(deviceId, qid);
      97              :         rtMemQueueShareAttr_t attr;
      98            1 :         ACL_REQUIRES_OK(GetQueuePermission(deviceId, qid, attr));
      99            1 :         uint32_t tmp = 0U;
     100            1 :         tmp = (attr.manage != 0) ? (tmp | static_cast<uint32_t>(ACL_TDT_QUEUE_PERMISSION_MANAGE)) : tmp;
     101            1 :         tmp = (attr.read != 0) ? (tmp | static_cast<uint32_t>(ACL_TDT_QUEUE_PERMISSION_DEQUEUE)) : tmp;
     102            1 :         tmp = (attr.write != 0) ? (tmp | static_cast<uint32_t>(ACL_TDT_QUEUE_PERMISSION_ENQUEUE)) : tmp;
     103            1 :         *permission = tmp;
     104            1 :         ACL_LOG_INFO("successfully execute acltdtAttachQueue, qid is %u, permisiion is %u, timeout is %d",
     105              :                      qid, *permission, timeout);
     106            1 :         return ACL_SUCCESS;
     107            1 :     }
     108              : 
     109            2 :     aclError QueueProcessorSp::acltdtBindQueueRoutes(acltdtQueueRouteList *const qRouteList)
     110              :     {
     111            2 :         ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(qRouteList);
     112            2 :         ACL_LOG_INFO("Start to acltdtBindQueueRoutes, queue route is %zu", qRouteList->routeList.size());
     113            2 :         constexpr int32_t deviceId = 0;
     114              :         // get dst id
     115            2 :         ACL_REQUIRES_OK(InitQueueSchedule(deviceId));
     116            2 :         int32_t dstPid = 0;
     117            2 :         ACL_REQUIRES_OK(GetDstInfo(deviceId, QS_PID, dstPid));
     118            2 :         const std::lock_guard<std::recursive_mutex> lk(muForQueueCtrl_);
     119            4 :         for (size_t i = 0UL; i < qRouteList->routeList.size(); ++i) {
     120            2 :             rtMemQueueShareAttr_t attrSrc = {0U, 0U, 0U, 0U};
     121            2 :             attrSrc.read = 1U;
     122            2 :             rtMemQueueShareAttr_t attrDst = {0U, 0U, 0U, 0U};
     123            2 :             attrDst.write = 1U;
     124            2 :             ACL_REQUIRES_RTS_OK_WARN_NOT_SUPPORT(rtMemQueueGrant(deviceId, qRouteList->routeList[i].srcId, dstPid, &attrSrc),
     125              :                                      rtMemQueueGrant);
     126            2 :             ACL_REQUIRES_RTS_OK_WARN_NOT_SUPPORT(rtMemQueueGrant(deviceId, qRouteList->routeList[i].dstId, dstPid, &attrDst),
     127              :                                      rtMemQueueGrant);
     128              :         }
     129            2 :         rtEschedEventSummary_t eventSum = {0, 0U, 0, 0U, 0U, nullptr, 0U, 0};
     130            2 :         rtEschedEventReply_t ack = {nullptr, 0U, 0U};
     131            2 :         bqs::QsProcMsgRsp qsRsp = {0UL, 0, 0U, 0U, 0U, {0}};
     132            2 :         eventSum.pid = dstPid;
     133            2 :         eventSum.grpId = bqs::BIND_QUEUE_GROUP_ID;
     134            2 :         eventSum.eventId = RT_MQ_SCHED_EVENT_QS_MSG;
     135            2 :         eventSum.dstEngine = static_cast<uint32_t>(RT_MQ_DST_ENGINE_CCPU_DEVICE);
     136            2 :         ack.buf = reinterpret_cast<char_t *>(&qsRsp);
     137            2 :         ack.bufLen = sizeof(qsRsp);
     138            2 :         if (!isQsInit_) {
     139            1 :             ACL_REQUIRES_OK(SendConnectQsMsg(deviceId, eventSum, ack));
     140            1 :             ACL_REQUIRES_RTS_OK_WARN_NOT_SUPPORT(rtMemQueueAttach(deviceId, qsContactId_, 0), rtMemQueueAttach);
     141            1 :             isQsInit_ = true;
     142              :         }
     143            2 :         ACL_REQUIRES_OK(SendBindUnbindMsgOnDevice(qRouteList, true, eventSum, ack));
     144            0 :         ACL_LOG_INFO("Successfully to execute acltdtBindQueueRoutes, queue route is %zu", qRouteList->routeList.size());
     145            0 :         return ACL_SUCCESS;
     146            2 :     }
     147              : 
     148            1 :     aclError QueueProcessorSp::acltdtUnbindQueueRoutes(acltdtQueueRouteList *const qRouteList)
     149              :     {
     150            1 :         ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(qRouteList);
     151            1 :         ACL_LOG_INFO("Start to acltdtUnBindQueueRoutes, queue route is %zu", qRouteList->routeList.size());
     152            1 :         constexpr int32_t deviceId = 0;
     153              :         // get dst id
     154            1 :         int32_t dstPid = 0;
     155            1 :         ACL_REQUIRES_OK(GetDstInfo(deviceId, QS_PID, dstPid));
     156            1 :         rtEschedEventSummary_t eventSum = {0, 0U, 0, 0U, 0U, nullptr, 0U, 0};
     157            1 :         rtEschedEventReply_t ack = {nullptr, 0U, 0U};
     158            1 :         bqs::QsProcMsgRsp qsRsp = {0UL, 0, 0U, 0U, 0U, {0}};
     159            1 :         eventSum.pid = dstPid;
     160            1 :         eventSum.grpId = bqs::BIND_QUEUE_GROUP_ID;
     161            1 :         eventSum.eventId = RT_MQ_SCHED_EVENT_QS_MSG;
     162            1 :         eventSum.dstEngine = static_cast<uint32_t>(RT_MQ_DST_ENGINE_CCPU_DEVICE);
     163            1 :         ack.buf = reinterpret_cast<char_t *>(&qsRsp);
     164            1 :         ack.bufLen = sizeof(qsRsp);
     165            1 :         const std::lock_guard<std::recursive_mutex> lk(muForQueueCtrl_);
     166            1 :         ACL_REQUIRES_OK(SendBindUnbindMsgOnDevice(qRouteList, false, eventSum, ack));
     167            1 :         ACL_LOG_INFO("Successfully to execute acltdtUnBindQueueRoutes, queue route is %zu",
     168              :                      qRouteList->routeList.size());
     169            1 :         return ACL_SUCCESS;
     170            1 :     }
     171              : 
     172            1 :     aclError QueueProcessorSp::acltdtQueryQueueRoutes(const acltdtQueueRouteQueryInfo *const queryInfo,
     173              :                                                        acltdtQueueRouteList *const qRouteList)
     174              :     {
     175            1 :         ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(queryInfo);
     176            1 :         ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(qRouteList);
     177            1 :         ACL_LOG_INFO("Start to acltdtQueryQueueRoutes");
     178            1 :         constexpr int32_t deviceId = 0;
     179              :         // get dst id
     180            1 :         int32_t dstPid = 0;
     181            1 :         ACL_REQUIRES_OK(GetDstInfo(deviceId, QS_PID, dstPid));
     182            1 :         rtEschedEventSummary_t eventSum = {0, 0U, 0, 0U, 0U, nullptr, 0U, 0};
     183            1 :         rtEschedEventReply_t ack = {nullptr, 0U, 0U};
     184            1 :         bqs::QsProcMsgRsp qsRsp = {0UL, 0, 0U, 0U, 0U, {0}};
     185            1 :         eventSum.pid = dstPid;
     186            1 :         eventSum.grpId = bqs::BIND_QUEUE_GROUP_ID;
     187            1 :         eventSum.eventId = RT_MQ_SCHED_EVENT_QS_MSG;
     188            1 :         eventSum.dstEngine = static_cast<uint32_t>(RT_MQ_DST_ENGINE_CCPU_DEVICE);
     189            1 :         ack.buf = reinterpret_cast<char_t *>(&qsRsp);
     190            1 :         ack.bufLen = sizeof(qsRsp);
     191            1 :         const std::lock_guard<std::recursive_mutex> lk(muForQueueCtrl_);
     192            1 :         size_t routeNum = 0UL;
     193            1 :         ACL_REQUIRES_OK(GetQueueRouteNum(queryInfo, deviceId, eventSum, ack, routeNum));
     194            1 :         ACL_REQUIRES_OK(QueryQueueRoutesOnDevice(queryInfo, routeNum, eventSum, ack, qRouteList));
     195            1 :         return ACL_SUCCESS;
     196            1 :     }
     197              : 
     198            6 :     aclError QueueProcessorSp::acltdtAllocBuf(const size_t size, const uint32_t type, acltdtBuf *const buf)
     199              :     {
     200            6 :         if ((type != static_cast<uint32_t>(ACL_TDT_NORMAL_MEM)) && (type != static_cast<uint32_t>(ACL_TDT_DVPP_MEM))) {
     201            1 :             acl::AclErrorLogManager::ReportInputError(acl::INVALID_VALUE_MSG,
     202            2 :                     std::vector<const char *>({"func", "value", "param", "expect"}),
     203            2 :                     std::vector<const char *>({__func__, acl::GetAllocBufTypeDesc(static_cast<acltdtAllocBufType>(type)), "type", "[ACL_TDT_NORMAL_MEM, ACL_TDT_DVPP_MEM]"}));
     204            1 :             ACL_LOG_ERROR("[Check][Param]param type must be equal to zero currently");
     205            1 :             return ACL_ERROR_INVALID_PARAM;
     206              :         }
     207            5 :         ACL_REQUIRES_OK(QueryAllocGroup());
     208            5 :         ACL_REQUIRES_OK(acltdtAllocBufData(size, type, buf));
     209            5 :         return ACL_SUCCESS;
     210              :     }
     211              : }
        

Generated by: LCOV version 2.0-1