LCOV - code coverage report
Current view: top level - acl/acl_tdt_queue - queue_process_ccpu.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 85.8 % 134 115
Test Date: 2026-07-28 10:53:01 Functions: 88.9 % 9 8

            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_ccpu.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              : 
      16              : namespace acl {
      17            0 : aclError QueueProcessorCcpu::acltdtCreateQueue(const acltdtQueueAttr* const attr, uint32_t* const qid)
      18              : {
      19            0 :     ACL_LOG_INFO("Start to create queue");
      20            0 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(qid);
      21            0 :     ACL_REQUIRES_OK(acltdtCreateGroup());
      22            0 :     constexpr int32_t deviceId = 0;
      23              :     static bool isQueueIint = false;
      24            0 :     if (!isQueueIint) {
      25            0 :         ACL_LOG_INFO("need to init queue once");
      26            0 :         const rtError_t ret = rtMemQueueInit(deviceId);
      27            0 :         if ((ret != ACL_RT_SUCCESS) && (ret != ACL_ERROR_RT_REPEATED_INIT)) {
      28            0 :             return ret;
      29              :         }
      30            0 :         isQueueIint = true;
      31              :     }
      32            0 :     ACL_REQUIRES_OK(acltdtCreateQueueWithAttr(deviceId, attr, qid));
      33            0 :     ACL_LOG_INFO("Successfully to execute create queue, qid is %u", *qid);
      34            0 :     return ACL_SUCCESS;
      35              : }
      36              : 
      37            1 : aclError QueueProcessorCcpu::acltdtCreateGroup()
      38              : {
      39              :     static bool isGroupCreate = false;
      40            1 :     if (isGroupCreate) {
      41            0 :         return ACL_SUCCESS;
      42              :     }
      43            1 :     ACL_LOG_INFO("Start to create group");
      44            1 :     size_t grpNum = 0U;
      45            1 :     std::string grpName;
      46            1 :     const int32_t pid = mmGetPid();
      47            1 :     const std::lock_guard<std::mutex> groupLock(muForCreateGroup_);
      48            1 :     if (isGroupCreate) {
      49            0 :         return ACL_SUCCESS;
      50              :     }
      51            1 :     ACL_REQUIRES_OK(QueryGroup(pid, grpNum, grpName));
      52            1 :     if (grpNum == 0U) {
      53            1 :         ACL_LOG_INFO("need to create group");
      54            1 :         const rtMemGrpConfig_t grpConfig = {};
      55            1 :         const std::string gName = "acltdt" + std::to_string(pid);
      56            1 :         ACL_REQUIRES_RTS_OK_WARN_NOT_SUPPORT(rtMemGrpCreate(gName.c_str(), &grpConfig), rtMemGrpCreate);
      57              : 
      58            1 :         rtMemGrpShareAttr_t shareAttr = {};
      59            1 :         shareAttr.admin = 1;
      60            1 :         shareAttr.read = 1;
      61            1 :         shareAttr.write = 1;
      62            1 :         shareAttr.alloc = 1;
      63            1 :         ACL_REQUIRES_RTS_OK_WARN_NOT_SUPPORT(rtMemGrpAddProc(gName.c_str(), pid, &shareAttr), rtMemGrpAddProc);
      64            1 :         ACL_REQUIRES_RTS_OK_WARN_NOT_SUPPORT(rtMemGrpAttach(gName.c_str(), 0), rtMemGrpAttach);
      65            1 :         ACL_REQUIRES_OK(QueryGroupId(gName));
      66            1 :     } else {
      67            0 :         ACL_REQUIRES_OK(QueryGroupId(grpName));
      68              :     }
      69            1 :     ACL_REQUIRES_OK(MbufInit());
      70            1 :     isGroupCreate = true;
      71            1 :     return ACL_SUCCESS;
      72            1 : }
      73              : 
      74            1 : aclError QueueProcessorCcpu::acltdtDestroyQueue(const uint32_t qid) { return acltdtDestroyQueueOndevice(qid, true); }
      75              : 
      76            1 : aclError QueueProcessorCcpu::acltdtBindQueueRoutes(acltdtQueueRouteList* const qRouteList)
      77              : {
      78            1 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(qRouteList);
      79            1 :     ACL_LOG_INFO("Start to acltdtBindQueueRoutes, queue route is %zu", qRouteList->routeList.size());
      80              :     // qs is thread mode, so no need to grant queue to qs
      81            1 :     constexpr int32_t deviceId = 0;
      82            1 :     ACL_REQUIRES_OK(InitQueueSchedule(deviceId));
      83              :     // get dst id
      84            1 :     const int32_t dstPid = mmGetPid();
      85            1 :     rtEschedEventSummary_t eventSum = {0, 0U, 0, 0U, 0U, nullptr, 0U, 0};
      86            1 :     rtEschedEventReply_t ack = {nullptr, 0U, 0U};
      87            1 :     bqs::QsProcMsgRsp qsRsp = {0UL, 0, 0U, 0U, 0U, {0}};
      88            1 :     eventSum.pid = dstPid;
      89            1 :     eventSum.grpId = bqs::BIND_QUEUE_GROUP_ID;
      90            1 :     eventSum.eventId = RT_MQ_SCHED_EVENT_QS_MSG;
      91            1 :     eventSum.dstEngine = static_cast<uint32_t>(RT_MQ_DST_ENGINE_CCPU_DEVICE);
      92            1 :     ack.buf = reinterpret_cast<char_t*>(&qsRsp);
      93            1 :     ack.bufLen = sizeof(qsRsp);
      94            1 :     const std::lock_guard<std::recursive_mutex> lk(muForQueueCtrl_);
      95            1 :     if (!isQsInit_) {
      96            1 :         ACL_REQUIRES_OK(SendConnectQsMsg(deviceId, eventSum, ack));
      97            1 :         ACL_REQUIRES_RTS_OK_WARN_NOT_SUPPORT(rtMemQueueAttach(deviceId, qsContactId_, 0), rtMemQueueAttach);
      98            1 :         isQsInit_ = true;
      99              :     }
     100            1 :     ACL_REQUIRES_OK(SendBindUnbindMsgOnDevice(qRouteList, true, eventSum, ack));
     101            1 :     ACL_LOG_INFO("Successfully to execute acltdtBindQueueRoutes, queue route is %zu", qRouteList->routeList.size());
     102            1 :     return ACL_SUCCESS;
     103            1 : }
     104              : 
     105            1 : aclError QueueProcessorCcpu::acltdtUnbindQueueRoutes(acltdtQueueRouteList* const qRouteList)
     106              : {
     107            1 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(qRouteList);
     108            1 :     ACL_LOG_INFO("Start to acltdtUnBindQueueRoutes, queue route is %zu", qRouteList->routeList.size());
     109              :     // get dst id
     110            1 :     const int32_t dstPid = mmGetPid();
     111            1 :     rtEschedEventSummary_t eventSum = {0, 0U, 0, 0U, 0U, nullptr, 0U, 0};
     112            1 :     rtEschedEventReply_t ack = {nullptr, 0U, 0U};
     113            1 :     bqs::QsProcMsgRsp qsRsp = {0UL, 0, 0U, 0U, 0U, {0}};
     114            1 :     eventSum.pid = dstPid;
     115            1 :     eventSum.grpId = bqs::BIND_QUEUE_GROUP_ID;
     116            1 :     eventSum.eventId = RT_MQ_SCHED_EVENT_QS_MSG;
     117            1 :     eventSum.dstEngine = static_cast<uint32_t>(RT_MQ_DST_ENGINE_CCPU_DEVICE);
     118            1 :     ack.buf = reinterpret_cast<char_t*>(&qsRsp);
     119            1 :     ack.bufLen = sizeof(qsRsp);
     120            1 :     const std::lock_guard<std::recursive_mutex> lk(muForQueueCtrl_);
     121            1 :     ACL_REQUIRES_OK(SendBindUnbindMsgOnDevice(qRouteList, false, eventSum, ack));
     122            1 :     ACL_LOG_INFO("Successfully to execute acltdtUnBindQueueRoutes, queue route is %zu", qRouteList->routeList.size());
     123            1 :     return ACL_SUCCESS;
     124            1 : }
     125              : 
     126            1 : aclError QueueProcessorCcpu::acltdtQueryQueueRoutes(
     127              :     const acltdtQueueRouteQueryInfo* const queryInfo, acltdtQueueRouteList* const qRouteList)
     128              : {
     129            1 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(queryInfo);
     130            1 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(qRouteList);
     131            1 :     ACL_LOG_INFO("Start to acltdtQueryQueueRoutes");
     132            1 :     constexpr int32_t deviceId = 0;
     133              :     // get dst id
     134            1 :     const int32_t dstPid = mmGetPid();
     135            1 :     rtEschedEventSummary_t eventSum = {0, 0U, 0, 0U, 0U, nullptr, 0U, 0};
     136            1 :     rtEschedEventReply_t ack = {nullptr, 0U, 0U};
     137            1 :     bqs::QsProcMsgRsp qsRsp = {0UL, 0, 0U, 0U, 0U, {0}};
     138            1 :     eventSum.pid = dstPid;
     139            1 :     eventSum.grpId = bqs::BIND_QUEUE_GROUP_ID;
     140            1 :     eventSum.eventId = RT_MQ_SCHED_EVENT_QS_MSG;
     141            1 :     eventSum.dstEngine = static_cast<uint32_t>(RT_MQ_DST_ENGINE_CCPU_DEVICE);
     142            1 :     ack.buf = reinterpret_cast<char_t*>(&qsRsp);
     143            1 :     ack.bufLen = sizeof(qsRsp);
     144            1 :     const std::lock_guard<std::recursive_mutex> lk(muForQueueCtrl_);
     145            1 :     size_t routeNum = 0UL;
     146            1 :     ACL_REQUIRES_OK(GetQueueRouteNum(queryInfo, deviceId, eventSum, ack, routeNum));
     147            1 :     ACL_REQUIRES_OK(QueryQueueRoutesOnDevice(queryInfo, routeNum, eventSum, ack, qRouteList));
     148            1 :     return ACL_SUCCESS;
     149            1 : }
     150              : 
     151            1 : aclError QueueProcessorCcpu::QueryGroup(const int32_t pid, size_t& grpNum, std::string& grpName) const
     152              : {
     153            1 :     rtMemGrpQueryInput_t input = {};
     154            1 :     input.cmd = RT_MEM_GRP_QUERY_GROUPS_OF_PROCESS;
     155            1 :     input.grpQueryByProc.pid = pid;
     156            1 :     rtMemGrpQueryOutput_t output = {};
     157            1 :     rtMemGrpOfProc_t outputInfo[QUERY_BUFF_GRP_MAX_NUM] = {{}};
     158            1 :     output.groupsOfProc = outputInfo;
     159            1 :     output.maxNum = QUERY_BUFF_GRP_MAX_NUM;
     160              : 
     161            1 :     ACL_REQUIRES_RTS_OK_WARN_NOT_SUPPORT(rtMemGrpQuery(&input, &output), rtMemGrpQuery);
     162            1 :     grpNum = output.resultNum;
     163            1 :     if (grpNum > 0) {
     164            0 :         grpName = std::string(output.groupsOfProc->groupName);
     165              :     }
     166            1 :     ACL_LOG_INFO("This proc [%d] has [%zu] group, name is %s", input.grpQueryByProc.pid, grpNum, grpName.c_str());
     167              : 
     168            1 :     return ACL_SUCCESS;
     169              : }
     170              : 
     171            1 : aclError QueueProcessorCcpu::MbufInit() const
     172              : {
     173              :     static bool isMbufInit = false;
     174            1 :     if (!isMbufInit) {
     175            1 :         rtMemBuffCfg_t cfg = {{}};
     176            1 :         const rtError_t ret = rtMbufInit(&cfg);
     177            1 :         if ((ret != ACL_RT_SUCCESS) && (ret != ACL_ERROR_RT_REPEATED_INIT)) {
     178            0 :             return ret;
     179              :         }
     180            1 :         isMbufInit = true;
     181              :     }
     182            1 :     return ACL_SUCCESS;
     183              : }
     184              : 
     185            1 : aclError QueueProcessorCcpu::acltdtAllocBuf(const size_t size, const uint32_t type, acltdtBuf* const buf)
     186              : {
     187            1 :     ACL_REQUIRES_OK(acltdtCreateGroup());
     188            1 :     ACL_REQUIRES_OK(acltdtAllocBufData(size, type, buf));
     189            1 :     return ACL_SUCCESS;
     190              : }
     191              : } // namespace acl
        

Generated by: LCOV version 2.0-1