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 :
11 : #include "queue.h"
12 : #include <map>
13 : #include <sstream>
14 : #include "common/log_inner.h"
15 : #include "toolchain/prof_api_reg.h"
16 : #include "common/resource_statistics.h"
17 : #include "queue_process.h"
18 : #include "queue_manager.h"
19 : #include "runtime/rt_mem_queue.h"
20 : #include "utils/data_type_utils.h"
21 :
22 : namespace {
23 14 : aclError CopyParam(
24 : const void* const src, const size_t srcLen, void* const dst, const size_t dstLen,
25 : size_t* const realCopySize = nullptr)
26 : {
27 14 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT_AND_FUNC_DESC(src, "Parameter copy");
28 14 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT_AND_FUNC_DESC(dst, "Parameter copy");
29 14 : ACL_CHECK_INVALID_PARAM_WITH_REASON_AND_FUNC_DESC(
30 : srcLen > dstLen, srcLen, "srcLen must not be larger than dstLen", "Parameter copy");
31 14 : const auto ret = memcpy_s(dst, dstLen, src, srcLen);
32 14 : if (ret != EOK) {
33 0 : const std::string retVal = std::to_string(ret);
34 0 : std::stringstream ss;
35 0 : ss << std::hex << "src=0x" << reinterpret_cast<uintptr_t>(src) << ", dest=0x"
36 0 : << reinterpret_cast<uintptr_t>(dst) << std::dec << ", dest_max=" << dstLen << ", count=" << srcLen << ".";
37 0 : const std::string extendInfo = ss.str();
38 0 : acl::AclErrorLogManager::ReportInputError(
39 : acl::STANDARD_FUNC_FAILED_MSG,
40 0 : std::vector<const char*>({"func1", "func2", "ret_code", "reason", "extend_info"}),
41 0 : std::vector<const char*>(
42 0 : {"Parameter copy", "memcpy_s", retVal.c_str(), strerror(ret), extendInfo.c_str()}));
43 0 : ACL_LOG_ERROR("[Call][MemCpy]call memcpy failed, result=%d, srcLen=%zu, dstLen=%zu", ret, srcLen, dstLen);
44 0 : return ACL_ERROR_FAILURE;
45 0 : }
46 14 : if (realCopySize != nullptr) {
47 5 : *realCopySize = srcLen;
48 : }
49 14 : return ACL_SUCCESS;
50 : }
51 : } // namespace
52 :
53 : namespace acl {
54 10 : aclError CheckQueueRouteQueryInfo(const acltdtQueueRouteQueryInfo* const queryInfo)
55 : {
56 10 : if (!queryInfo->isConfigMode) {
57 2 : ACL_LOG_ERROR("mode must be set in acltdtQueueRouteQueryInfo, please use acltdtSetQueueRouteQueryInfo");
58 2 : acl::AclErrorLogManager::ReportInputError(
59 4 : acl::INVALID_PARAM_REASON_MSG, std::vector<const char*>({"func", "value", "param", "reason"}),
60 2 : std::vector<const char*>(
61 : {"Checking the validity of the queue route query operation", "false", "queryInfo->isConfigMode",
62 : "Currently, the query is configured based on queue. The queue must be configured through "
63 2 : "acltdtSetQueueRouteQueryInfo"}));
64 2 : return ACL_ERROR_INVALID_PARAM;
65 : }
66 8 : switch (queryInfo->mode) {
67 3 : case ACL_TDT_QUEUE_ROUTE_QUERY_SRC: {
68 3 : if (!queryInfo->isConfigSrc) {
69 2 : ACL_LOG_ERROR("src qid must be set in acltdtQueueRouteQueryInfo, "
70 : "please use acltdtSetQueueRouteQueryInfo");
71 2 : acl::AclErrorLogManager::ReportInputError(
72 4 : acl::INVALID_PARAM_REASON_MSG, std::vector<const char*>({"func", "value", "param", "reason"}),
73 2 : std::vector<const char*>(
74 : {"Checking the validity of the queue route query operation", "false", "queryInfo->isConfigSrc",
75 : "Currently, the query is configured based on the source queue. The source queue must be "
76 : "configured through "
77 2 : "acltdtSetQueueRouteQueryInfo"}));
78 2 : return ACL_ERROR_INVALID_PARAM;
79 : }
80 1 : break;
81 : }
82 2 : case ACL_TDT_QUEUE_ROUTE_QUERY_DST: {
83 2 : if (!queryInfo->isConfigDst) {
84 1 : ACL_LOG_ERROR("dst qid must be set in acltdtQueueRouteQueryInfo, "
85 : "please use acltdtSetQueueRouteQueryInfo");
86 1 : acl::AclErrorLogManager::ReportInputError(
87 2 : acl::INVALID_PARAM_REASON_MSG, std::vector<const char*>({"func", "value", "param", "reason"}),
88 1 : std::vector<const char*>(
89 : {"Checking the validity of the queue route query operation", "false", "queryInfo->isConfigDst",
90 : "Currently, the query is configured based on the destination queue. The destination queue "
91 : "must be configured through "
92 1 : "acltdtSetQueueRouteQueryInfo"}));
93 1 : return ACL_ERROR_INVALID_PARAM;
94 : }
95 1 : break;
96 : }
97 3 : case ACL_TDT_QUEUE_ROUTE_QUERY_SRC_AND_DST: {
98 3 : if ((!queryInfo->isConfigSrc) || (!queryInfo->isConfigDst)) {
99 1 : ACL_LOG_ERROR("src and dst qid must be set in acltdtQueueRouteQueryInfo, "
100 : "please use acltdtSetQueueRouteQueryInfo");
101 1 : const char_t* argList[] = {"func", "value", "param", "reason"};
102 : std::string value =
103 1 : std::to_string(queryInfo->isConfigSrc) + '/' + std::to_string(queryInfo->isConfigDst);
104 1 : const char_t* argVal[] = {
105 1 : "Checking the validity of the queue route query operation", value.c_str(),
106 : "queryInfo->isConfigSrc/isConfigDst",
107 : "Currently, the query is configured based on the source queue and the destination queue. The "
108 : "source queue and destination queue must be configured through "
109 1 : "acltdtSetQueueRouteQueryInfo"};
110 1 : acl::AclErrorLogManager::ReportInputErrorWithChar(acl::INVALID_PARAM_REASON_MSG, argList, argVal, 4UL);
111 1 : return ACL_ERROR_INVALID_PARAM;
112 1 : }
113 2 : break;
114 : }
115 0 : case ACL_TDT_QUEUE_ROUTE_QUERY_ABNORMAL: {
116 0 : break;
117 : }
118 0 : default: {
119 0 : ACL_LOG_ERROR("[Check][Type]unknown mode %d.", queryInfo->mode);
120 0 : const char_t* argList[] = {"func", "value", "param", "expect"};
121 0 : const char_t* argVal[] = {
122 : "Checking the validity of the queue route query operation",
123 0 : acl::GetQueueRouteQueryModeDesc(static_cast<acltdtQueueRouteQueryMode>(queryInfo->mode)),
124 : "queryInfo->mode",
125 : "ACL_TDT_QUEUE_ROUTE_QUERY_SRC or ACL_TDT_QUEUE_ROUTE_QUERY_DST or "
126 0 : "ACL_TDT_QUEUE_ROUTE_QUERY_SRC_AND_DST or ACL_TDT_QUEUE_ROUTE_QUERY_ABNORMAL"};
127 0 : acl::AclErrorLogManager::ReportInputErrorWithChar(acl::INVALID_VALUE_MSG, argList, argVal, 4UL);
128 0 : return ACL_ERROR_INVALID_PARAM;
129 : }
130 : }
131 4 : return ACL_SUCCESS;
132 : }
133 : } // namespace acl
134 :
135 3 : aclError acltdtCreateQueue(const acltdtQueueAttr* attr, uint32_t* qid)
136 : {
137 3 : ACL_ADD_APPLY_TOTAL_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_QUEUE_ID);
138 3 : auto& qManager = acl::QueueManager::GetInstance();
139 3 : const auto processor = qManager.GetQueueProcessor();
140 3 : ACL_REQUIRES_NOT_NULL_WITH_INNER_REPORT(processor);
141 3 : ACL_REQUIRES_OK(processor->acltdtCreateQueue(attr, qid));
142 2 : ACL_ADD_APPLY_SUCCESS_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_QUEUE_ID);
143 2 : return ACL_SUCCESS;
144 : }
145 :
146 1 : aclError acltdtDestroyQueue(uint32_t qid)
147 : {
148 1 : ACL_ADD_RELEASE_TOTAL_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_QUEUE_ID);
149 1 : auto& qManager = acl::QueueManager::GetInstance();
150 1 : const auto processor = qManager.GetQueueProcessor();
151 1 : ACL_REQUIRES_NOT_NULL_WITH_INNER_REPORT(processor);
152 1 : ACL_REQUIRES_OK(processor->acltdtDestroyQueue(qid));
153 1 : ACL_ADD_RELEASE_SUCCESS_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_QUEUE_ID);
154 1 : return ACL_SUCCESS;
155 : }
156 :
157 0 : aclError acltdtEnqueue(uint32_t qid, acltdtBuf buf, int32_t timeout)
158 : {
159 0 : ACL_PROFILING_REG(acl::AclTdtQueueProfType::AcltdtEnqueue);
160 0 : auto& qManager = acl::QueueManager::GetInstance();
161 0 : const auto processor = qManager.GetQueueProcessor();
162 0 : ACL_REQUIRES_NOT_NULL_WITH_INNER_REPORT(processor);
163 0 : ACL_REQUIRES_OK(processor->acltdtEnqueue(qid, buf, timeout));
164 0 : return ACL_SUCCESS;
165 0 : }
166 :
167 0 : aclError acltdtDequeue(uint32_t qid, acltdtBuf* buf, int32_t timeout)
168 : {
169 0 : ACL_PROFILING_REG(acl::AclTdtQueueProfType::AcltdtDequeue);
170 0 : auto& qManager = acl::QueueManager::GetInstance();
171 0 : const auto processor = qManager.GetQueueProcessor();
172 0 : ACL_REQUIRES_NOT_NULL_WITH_INNER_REPORT(processor);
173 0 : ACL_REQUIRES_OK(processor->acltdtDequeue(qid, buf, timeout));
174 0 : return ACL_SUCCESS;
175 0 : }
176 :
177 1 : aclError acltdtEnqueueData(
178 : uint32_t qid, const void* data, size_t dataSize, const void* userData, size_t userDataSize, int32_t timeout,
179 : uint32_t rsv)
180 : {
181 1 : ACL_PROFILING_REG(acl::AclTdtQueueProfType::AcltdtEnqueueData);
182 1 : auto& qManager = acl::QueueManager::GetInstance();
183 1 : const auto processor = qManager.GetQueueProcessor();
184 1 : ACL_REQUIRES_NOT_NULL_WITH_INNER_REPORT(processor);
185 1 : ACL_REQUIRES_OK(processor->acltdtEnqueueData(qid, data, dataSize, userData, userDataSize, timeout, rsv));
186 1 : return ACL_SUCCESS;
187 1 : }
188 :
189 3 : aclError acltdtDequeueData(
190 : uint32_t qid, void* data, size_t dataSize, size_t* retDataSize, void* userData, size_t userDataSize,
191 : int32_t timeout)
192 : {
193 3 : ACL_PROFILING_REG(acl::AclTdtQueueProfType::AcltdtDequeueData);
194 3 : auto& qManager = acl::QueueManager::GetInstance();
195 3 : const auto processor = qManager.GetQueueProcessor();
196 3 : ACL_REQUIRES_NOT_NULL_WITH_INNER_REPORT(processor);
197 3 : ACL_REQUIRES_OK(processor->acltdtDequeueData(qid, data, dataSize, retDataSize, userData, userDataSize, timeout));
198 1 : return ACL_SUCCESS;
199 3 : }
200 :
201 1 : aclError acltdtGrantQueue(uint32_t qid, int32_t pid, uint32_t permission, int32_t timeout)
202 : {
203 1 : auto& qManager = acl::QueueManager::GetInstance();
204 1 : const auto processor = qManager.GetQueueProcessor();
205 1 : ACL_REQUIRES_NOT_NULL_WITH_INNER_REPORT(processor);
206 1 : ACL_REQUIRES_OK(processor->acltdtGrantQueue(qid, pid, permission, timeout));
207 0 : return ACL_SUCCESS;
208 : }
209 :
210 1 : aclError acltdtAttachQueue(uint32_t qid, int32_t timeout, uint32_t* permission)
211 : {
212 1 : auto& qManager = acl::QueueManager::GetInstance();
213 1 : const auto processor = qManager.GetQueueProcessor();
214 1 : ACL_REQUIRES_NOT_NULL_WITH_INNER_REPORT(processor);
215 1 : ACL_REQUIRES_OK(processor->acltdtAttachQueue(qid, timeout, permission));
216 0 : return ACL_SUCCESS;
217 : }
218 :
219 2 : aclError acltdtBindQueueRoutes(acltdtQueueRouteList* qRouteList)
220 : {
221 2 : auto& qManager = acl::QueueManager::GetInstance();
222 2 : const auto processor = qManager.GetQueueProcessor();
223 2 : ACL_REQUIRES_NOT_NULL_WITH_INNER_REPORT(processor);
224 2 : ACL_REQUIRES_OK(processor->acltdtBindQueueRoutes(qRouteList));
225 1 : return ACL_SUCCESS;
226 : }
227 :
228 4 : aclError acltdtUnbindQueueRoutes(acltdtQueueRouteList* qRouteList)
229 : {
230 4 : auto& qManager = acl::QueueManager::GetInstance();
231 4 : const auto processor = qManager.GetQueueProcessor();
232 4 : ACL_REQUIRES_NOT_NULL_WITH_INNER_REPORT(processor);
233 4 : ACL_REQUIRES_OK(processor->acltdtUnbindQueueRoutes(qRouteList));
234 4 : return ACL_SUCCESS;
235 : }
236 :
237 2 : aclError acltdtQueryQueueRoutes(const acltdtQueueRouteQueryInfo* queryInfo, acltdtQueueRouteList* qRouteList)
238 : {
239 2 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(qRouteList);
240 2 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(queryInfo);
241 2 : qRouteList->routeList.clear();
242 2 : ACL_REQUIRES_OK(acl::CheckQueueRouteQueryInfo(queryInfo));
243 1 : auto& qManager = acl::QueueManager::GetInstance();
244 1 : const auto processor = qManager.GetQueueProcessor();
245 1 : ACL_REQUIRES_NOT_NULL_WITH_INNER_REPORT(processor);
246 1 : ACL_REQUIRES_OK(processor->acltdtQueryQueueRoutes(queryInfo, qRouteList));
247 1 : return ACL_SUCCESS;
248 : }
249 :
250 1 : aclError acltdtAllocBuf(size_t size, uint32_t type, acltdtBuf* buf)
251 : {
252 1 : if ((type != static_cast<uint32_t>(ACL_TDT_NORMAL_MEM)) && (type != static_cast<uint32_t>(ACL_TDT_DVPP_MEM))) {
253 1 : const char_t* argList[] = {"func", "value", "param", "expect"};
254 1 : std::string expect = "[" + std::to_string(ACL_TDT_NORMAL_MEM) + ", " + std::to_string(ACL_TDT_DVPP_MEM) + "]";
255 1 : const std::string typeVal = acl::GetAllocBufTypeDesc(static_cast<acltdtAllocBufType>(type));
256 1 : const char_t* argVal[] = {__func__, typeVal.c_str(), "type", expect.c_str()};
257 1 : acl::AclErrorLogManager::ReportInputErrorWithChar(acl::INVALID_VALUE_MSG, argList, argVal, 4UL);
258 1 : ACL_LOG_ERROR("[Check][Param]param type must be equal to 0 or 1 currently");
259 1 : return ACL_ERROR_INVALID_PARAM;
260 1 : }
261 0 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(buf);
262 0 : ACL_ADD_APPLY_TOTAL_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_MBUF);
263 0 : auto& qManager = acl::QueueManager::GetInstance();
264 0 : const auto processor = qManager.GetQueueProcessor();
265 0 : ACL_REQUIRES_NOT_NULL_WITH_INNER_REPORT(processor);
266 0 : ACL_ADD_APPLY_SUCCESS_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_MBUF);
267 0 : return processor->acltdtAllocBuf(size, type, buf);
268 : }
269 :
270 0 : aclError acltdtFreeBuf(acltdtBuf buf)
271 : {
272 0 : ACL_ADD_RELEASE_TOTAL_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_MBUF);
273 0 : auto& qManager = acl::QueueManager::GetInstance();
274 0 : const auto processor = qManager.GetQueueProcessor();
275 0 : ACL_REQUIRES_NOT_NULL_WITH_INNER_REPORT(processor);
276 0 : ACL_REQUIRES_OK(processor->acltdtFreeBuf(buf));
277 0 : ACL_ADD_RELEASE_SUCCESS_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_MBUF);
278 0 : return ACL_SUCCESS;
279 : }
280 :
281 0 : aclError acltdtGetBufData(const acltdtBuf buf, void** dataPtr, size_t* size)
282 : {
283 0 : auto& qManager = acl::QueueManager::GetInstance();
284 0 : const auto processor = qManager.GetQueueProcessor();
285 0 : ACL_REQUIRES_NOT_NULL_WITH_INNER_REPORT(processor);
286 0 : ACL_REQUIRES_OK(processor->acltdtGetBufData(buf, dataPtr, size));
287 0 : return ACL_SUCCESS;
288 : }
289 :
290 0 : aclError acltdtSetBufDataLen(acltdtBuf buf, size_t len)
291 : {
292 0 : auto& qManager = acl::QueueManager::GetInstance();
293 0 : const auto processor = qManager.GetQueueProcessor();
294 0 : ACL_REQUIRES_NOT_NULL_WITH_INNER_REPORT(processor);
295 0 : ACL_REQUIRES_OK(processor->acltdtSetBufDataLen(buf, len));
296 0 : return ACL_SUCCESS;
297 : }
298 :
299 0 : aclError acltdtGetBufDataLen(acltdtBuf buf, size_t* len)
300 : {
301 0 : auto& qManager = acl::QueueManager::GetInstance();
302 0 : const auto processor = qManager.GetQueueProcessor();
303 0 : ACL_REQUIRES_NOT_NULL_WITH_INNER_REPORT(processor);
304 0 : ACL_REQUIRES_OK(processor->acltdtGetBufDataLen(buf, len));
305 0 : return ACL_SUCCESS;
306 : }
307 :
308 0 : aclError acltdtAppendBufChain(acltdtBuf headBuf, acltdtBuf buf)
309 : {
310 0 : auto& qManager = acl::QueueManager::GetInstance();
311 0 : const auto processor = qManager.GetQueueProcessor();
312 0 : ACL_REQUIRES_NOT_NULL_WITH_INNER_REPORT(processor);
313 0 : ACL_REQUIRES_OK(processor->acltdtAppendBufChain(headBuf, buf));
314 0 : return ACL_SUCCESS;
315 : }
316 :
317 0 : aclError acltdtGetBufChainNum(acltdtBuf headBuf, uint32_t* num)
318 : {
319 0 : auto& qManager = acl::QueueManager::GetInstance();
320 0 : const auto processor = qManager.GetQueueProcessor();
321 0 : ACL_REQUIRES_NOT_NULL_WITH_INNER_REPORT(processor);
322 0 : ACL_REQUIRES_OK(processor->acltdtGetBufChainNum(headBuf, num));
323 0 : return ACL_SUCCESS;
324 : }
325 :
326 0 : aclError acltdtGetBufFromChain(acltdtBuf headBuf, uint32_t index, acltdtBuf* buf)
327 : {
328 0 : auto& qManager = acl::QueueManager::GetInstance();
329 0 : const auto processor = qManager.GetQueueProcessor();
330 0 : ACL_REQUIRES_NOT_NULL_WITH_INNER_REPORT(processor);
331 0 : ACL_REQUIRES_OK(processor->acltdtGetBufFromChain(headBuf, index, buf));
332 0 : return ACL_SUCCESS;
333 : }
334 :
335 0 : aclError acltdtGetBufUserData(const acltdtBuf buf, void* dataPtr, size_t size, size_t offset)
336 : {
337 0 : auto& qManager = acl::QueueManager::GetInstance();
338 0 : const auto processor = qManager.GetQueueProcessor();
339 0 : ACL_REQUIRES_NOT_NULL_WITH_INNER_REPORT(processor);
340 0 : ACL_REQUIRES_OK(processor->acltdtGetBufUserData(buf, dataPtr, size, offset));
341 0 : return ACL_SUCCESS;
342 : }
343 :
344 0 : aclError acltdtSetBufUserData(acltdtBuf buf, const void* dataPtr, size_t size, size_t offset)
345 : {
346 0 : auto& qManager = acl::QueueManager::GetInstance();
347 0 : const auto processor = qManager.GetQueueProcessor();
348 0 : ACL_REQUIRES_NOT_NULL_WITH_INNER_REPORT(processor);
349 0 : ACL_REQUIRES_OK(processor->acltdtSetBufUserData(buf, dataPtr, size, offset));
350 0 : return ACL_SUCCESS;
351 : }
352 :
353 0 : aclError acltdtCopyBufRef(const acltdtBuf buf, acltdtBuf* newBuf)
354 : {
355 0 : auto& qManager = acl::QueueManager::GetInstance();
356 0 : const auto processor = qManager.GetQueueProcessor();
357 0 : ACL_REQUIRES_NOT_NULL_WITH_INNER_REPORT(processor);
358 0 : ACL_REQUIRES_OK(processor->acltdtCopyBufRef(buf, newBuf));
359 0 : return ACL_SUCCESS;
360 : }
361 :
362 1 : acltdtQueueAttr* acltdtCreateQueueAttr()
363 : {
364 1 : ACL_ADD_APPLY_TOTAL_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_QUEUE_ATTR);
365 1 : acltdtQueueAttr* const attr = new (std::nothrow) acltdtQueueAttr();
366 1 : ACL_CHECK_MALLOC_RESULT_REPORT_RET(attr, sizeof(acltdtQueueAttr), "new", nullptr);
367 1 : acl::QueueProcessor::acltdtSetDefaultQueueAttr(*attr);
368 1 : ACL_ADD_APPLY_SUCCESS_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_QUEUE_ATTR);
369 1 : return attr;
370 : }
371 :
372 1 : aclError acltdtDestroyQueueAttr(const acltdtQueueAttr* attr)
373 : {
374 1 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(attr);
375 1 : ACL_ADD_RELEASE_TOTAL_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_QUEUE_ATTR);
376 1 : ACL_DELETE_AND_SET_NULL(attr);
377 1 : ACL_ADD_RELEASE_SUCCESS_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_QUEUE_ATTR);
378 1 : return ACL_SUCCESS;
379 : }
380 :
381 6 : aclError acltdtSetQueueAttr(acltdtQueueAttr* attr, acltdtQueueAttrType type, size_t len, const void* param)
382 : {
383 6 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(attr);
384 5 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(param);
385 4 : switch (type) {
386 3 : case ACL_TDT_QUEUE_NAME_PTR: {
387 3 : char_t* tmp = nullptr;
388 3 : ACL_REQUIRES_OK(CopyParam(param, len, static_cast<void*>(&tmp), sizeof(size_t)));
389 3 : ACL_REQUIRES_NOT_NULL(tmp);
390 3 : const size_t tmpLen = strnlen(tmp, static_cast<size_t>(RT_MQ_MAX_NAME_LEN));
391 3 : if ((tmpLen + 1U) > static_cast<size_t>(RT_MQ_MAX_NAME_LEN)) {
392 1 : const std::string tmpLenVal = std::to_string(tmpLen + 1U);
393 1 : const std::string expectVal = "[0, " + std::to_string(RT_MQ_MAX_NAME_LEN) + "]";
394 1 : acl::AclErrorLogManager::ReportInputError(
395 2 : acl::INVALID_VALUE_MSG, std::vector<const char*>({"func", "value", "param", "expect"}),
396 2 : std::vector<const char*>({__func__, tmpLenVal.c_str(), "queue name length", expectVal.c_str()}));
397 1 : return ACL_ERROR_INVALID_PARAM;
398 1 : }
399 2 : return CopyParam(tmp, tmpLen + 1U, static_cast<void*>(attr->name), static_cast<size_t>(RT_MQ_MAX_NAME_LEN));
400 : }
401 1 : case ACL_TDT_QUEUE_DEPTH_UINT32:
402 1 : return CopyParam(param, len, static_cast<void*>(&attr->depth), sizeof(uint32_t));
403 0 : default: {
404 0 : ACL_LOG_ERROR("[Check][Type]unknown acltdtQueueAttrType %d.", type);
405 0 : acl::AclErrorLogManager::ReportInputError(
406 0 : acl::INVALID_VALUE_MSG, std::vector<const char*>({"func", "value", "param", "expect"}),
407 0 : std::vector<const char*>(
408 0 : {__func__, acl::GetQueueAttrTypeDesc(type), "type",
409 0 : "[ACL_TDT_QUEUE_NAME_PTR, ACL_TDT_QUEUE_DEPTH_UINT32]"}));
410 0 : return ACL_ERROR_INVALID_PARAM;
411 : }
412 : }
413 : }
414 :
415 5 : aclError acltdtGetQueueAttr(
416 : const acltdtQueueAttr* attr, acltdtQueueAttrType type, size_t len, size_t* paramRetSize, void* param)
417 : {
418 5 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(attr);
419 4 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(param);
420 3 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(paramRetSize);
421 2 : ACL_LOG_INFO("start to get queue attr, type is %d, len is %zu", type, len);
422 2 : switch (type) {
423 1 : case ACL_TDT_QUEUE_NAME_PTR: {
424 1 : const char_t* tmp = &attr->name[0];
425 1 : return CopyParam(static_cast<const void*>(&tmp), sizeof(size_t), param, len, paramRetSize);
426 : }
427 1 : case ACL_TDT_QUEUE_DEPTH_UINT32:
428 1 : return CopyParam(static_cast<const void*>(&attr->depth), sizeof(uint32_t), param, len, paramRetSize);
429 0 : default: {
430 0 : ACL_LOG_ERROR("[Check][Type]unknown acltdtQueueAttrType %d.", type);
431 0 : acl::AclErrorLogManager::ReportInputError(
432 0 : acl::INVALID_VALUE_MSG, std::vector<const char*>({"func", "value", "param", "expect"}),
433 0 : std::vector<const char*>(
434 0 : {__func__, acl::GetQueueAttrTypeDesc(type), "type",
435 0 : "[ACL_TDT_QUEUE_NAME_PTR, ACL_TDT_QUEUE_DEPTH_UINT32]"}));
436 0 : return ACL_ERROR_INVALID_PARAM;
437 : }
438 : }
439 : }
440 :
441 1 : acltdtQueueRoute* acltdtCreateQueueRoute(uint32_t srcId, uint32_t dstId)
442 : {
443 1 : ACL_ADD_APPLY_TOTAL_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_QUEUE_ROUTE);
444 1 : acltdtQueueRoute* const route = new (std::nothrow) acltdtQueueRoute();
445 1 : ACL_CHECK_MALLOC_RESULT_REPORT_RET(route, sizeof(acltdtQueueRoute), "new", nullptr);
446 1 : route->srcId = srcId;
447 1 : route->dstId = dstId;
448 1 : route->status = 0;
449 1 : ACL_ADD_APPLY_SUCCESS_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_QUEUE_ROUTE);
450 1 : return route;
451 : }
452 :
453 1 : aclError acltdtDestroyQueueRoute(const acltdtQueueRoute* route)
454 : {
455 1 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(route);
456 1 : ACL_ADD_RELEASE_TOTAL_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_QUEUE_ROUTE);
457 1 : ACL_DELETE_AND_SET_NULL(route);
458 1 : ACL_ADD_RELEASE_SUCCESS_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_QUEUE_ROUTE);
459 1 : return ACL_SUCCESS;
460 : }
461 :
462 6 : aclError acltdtGetQueueRouteParam(
463 : const acltdtQueueRoute* route, acltdtQueueRouteParamType type, size_t len, size_t* paramRetSize, void* param)
464 : {
465 6 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(route);
466 5 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(param);
467 4 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(paramRetSize);
468 3 : ACL_LOG_INFO("get route type %d, len is %zu", type, len);
469 3 : switch (type) {
470 1 : case ACL_TDT_QUEUE_ROUTE_SRC_UINT32:
471 1 : return CopyParam(static_cast<const void*>(&route->srcId), sizeof(uint32_t), param, len, paramRetSize);
472 1 : case ACL_TDT_QUEUE_ROUTE_DST_UINT32:
473 1 : return CopyParam(static_cast<const void*>(&route->dstId), sizeof(uint32_t), param, len, paramRetSize);
474 1 : case ACL_TDT_QUEUE_ROUTE_STATUS_INT32:
475 1 : return CopyParam(static_cast<const void*>(&route->status), sizeof(int32_t), param, len, paramRetSize);
476 0 : default: {
477 0 : ACL_LOG_ERROR("[Check][Type]unknown acltdtQueueRouteParamType %d.", type);
478 0 : acl::AclErrorLogManager::ReportInputError(
479 0 : acl::INVALID_VALUE_MSG, std::vector<const char*>({"func", "value", "param", "expect"}),
480 0 : std::vector<const char*>(
481 0 : {__func__, acl::GetQueueRouteParamTypeDesc(type), "type",
482 0 : "[ACL_TDT_QUEUE_ROUTE_SRC_UINT32, ACL_TDT_QUEUE_ROUTE_STATUS_INT32]"}));
483 0 : return ACL_ERROR_INVALID_PARAM;
484 : }
485 : }
486 : }
487 :
488 1 : acltdtQueueRouteList* acltdtCreateQueueRouteList()
489 : {
490 1 : ACL_ADD_APPLY_TOTAL_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_QUEUE_ROUTE_LIST);
491 1 : ACL_ADD_APPLY_SUCCESS_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_QUEUE_ROUTE_LIST);
492 1 : return new (std::nothrow) acltdtQueueRouteList();
493 : }
494 :
495 1 : aclError acltdtDestroyQueueRouteList(const acltdtQueueRouteList* routeList)
496 : {
497 1 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(routeList);
498 1 : ACL_ADD_RELEASE_TOTAL_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_QUEUE_ROUTE_LIST);
499 1 : ACL_DELETE_AND_SET_NULL(routeList);
500 1 : ACL_ADD_RELEASE_SUCCESS_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_QUEUE_ROUTE_LIST);
501 1 : return ACL_SUCCESS;
502 : }
503 :
504 4 : aclError acltdtAddQueueRoute(acltdtQueueRouteList* routeList, const acltdtQueueRoute* route)
505 : {
506 4 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(routeList);
507 3 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(route);
508 2 : routeList->routeList.emplace_back(*route);
509 2 : return ACL_SUCCESS;
510 : }
511 :
512 4 : aclError acltdtGetQueueRoute(const acltdtQueueRouteList* routeList, size_t index, acltdtQueueRoute* route)
513 : {
514 4 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(routeList);
515 3 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(route);
516 2 : if (index >= routeList->routeList.size()) {
517 1 : ACL_LOG_ERROR("[Check][index] index [%zu] must be smaller than [%zu]", index, routeList->routeList.size());
518 1 : const char_t* argList[] = {"func", "value", "param", "reason"};
519 1 : std::string reason = "must be less than routeList size " + std::to_string(routeList->routeList.size());
520 1 : const std::string indexVal = std::to_string(index);
521 1 : const char_t* argVal[] = {__func__, indexVal.c_str(), "index", reason.c_str()};
522 1 : acl::AclErrorLogManager::ReportInputErrorWithChar(acl::INVALID_PARAM_REASON_MSG, argList, argVal, 4UL);
523 1 : return ACL_ERROR_INVALID_PARAM;
524 1 : }
525 1 : *route = routeList->routeList[index];
526 1 : return ACL_SUCCESS;
527 : }
528 :
529 2 : size_t acltdtGetQueueRouteNum(const acltdtQueueRouteList* routeList)
530 : {
531 6 : ACL_REQUIRES_NOT_NULL_RET_INPUT_REPORT(routeList, 0U);
532 1 : return routeList->routeList.size();
533 : }
534 :
535 2 : acltdtQueueRouteQueryInfo* acltdtCreateQueueRouteQueryInfo()
536 : {
537 2 : ACL_ADD_APPLY_TOTAL_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_QUEUE_ROUTE_QUERY);
538 2 : acltdtQueueRouteQueryInfo* const info = new (std::nothrow) acltdtQueueRouteQueryInfo();
539 2 : ACL_CHECK_MALLOC_RESULT_REPORT_RET(info, sizeof(acltdtQueueRouteQueryInfo), "new", nullptr);
540 2 : ACL_ADD_APPLY_SUCCESS_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_QUEUE_ROUTE_QUERY);
541 2 : info->isConfigDst = false;
542 2 : info->isConfigSrc = false;
543 2 : info->isConfigMode = false;
544 2 : return info;
545 : }
546 :
547 5 : aclError acltdtSetQueueRouteQueryInfo(
548 : acltdtQueueRouteQueryInfo* param, acltdtQueueRouteQueryInfoParamType type, size_t len, const void* value)
549 : {
550 5 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(param);
551 4 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(value);
552 3 : switch (type) {
553 1 : case ACL_TDT_QUEUE_ROUTE_QUERY_MODE_ENUM: {
554 1 : const auto ret = CopyParam(value, len, static_cast<void*>(¶m->mode), sizeof(acltdtQueueRouteQueryMode));
555 1 : if (ret == ACL_SUCCESS) {
556 1 : param->isConfigMode = true;
557 : }
558 1 : return ret;
559 : }
560 1 : case ACL_TDT_QUEUE_ROUTE_QUERY_SRC_ID_UINT32: {
561 1 : const auto ret = CopyParam(value, len, static_cast<void*>(¶m->srcId), sizeof(uint32_t));
562 1 : if (ret == ACL_SUCCESS) {
563 1 : param->isConfigSrc = true;
564 : }
565 1 : return ret;
566 : }
567 1 : case ACL_TDT_QUEUE_ROUTE_QUERY_DST_ID_UINT32: {
568 1 : const auto ret = CopyParam(value, len, static_cast<void*>(¶m->dstId), sizeof(uint32_t));
569 1 : if (ret == ACL_SUCCESS) {
570 1 : param->isConfigDst = true;
571 : }
572 1 : return ret;
573 : }
574 0 : default: {
575 0 : ACL_LOG_ERROR("[Check][Type]unknown acltdtQueueRouteQueryInfoParamType %d.", type);
576 0 : acl::AclErrorLogManager::ReportInputError(
577 0 : acl::INVALID_VALUE_MSG, std::vector<const char*>({"func", "value", "param", "expect"}),
578 0 : std::vector<const char*>(
579 0 : {__func__, acl::GetQueueRouteQueryInfoParamTypeDesc(type), "type",
580 0 : "[ACL_TDT_QUEUE_ROUTE_QUERY_MODE_ENUM, ACL_TDT_QUEUE_ROUTE_QUERY_DST_ID_UINT32]"}));
581 0 : return ACL_ERROR_INVALID_PARAM;
582 : }
583 : }
584 : }
585 :
586 2 : aclError acltdtDestroyQueueRouteQueryInfo(const acltdtQueueRouteQueryInfo* info)
587 : {
588 2 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(info);
589 2 : ACL_ADD_RELEASE_TOTAL_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_QUEUE_ROUTE_QUERY);
590 2 : ACL_DELETE_AND_SET_NULL(info);
591 2 : ACL_ADD_RELEASE_SUCCESS_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_QUEUE_ROUTE_QUERY);
592 2 : return ACL_SUCCESS;
593 : }
|