libwd/0046-uadk_tool-release-memory-after-all-tasks-are-complet.patch
2023-11-23 10:41:04 +08:00

92 lines
2.4 KiB
Diff

From 36363fb48e8653a6efbacc32a1374e76a86592a4 Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Fri, 10 Nov 2023 11:52:15 +0800
Subject: [PATCH 46/85] uadk_tool: release memory after all tasks are complete
In asynchronous scenarios, memory is released after all tasks are complete.
This prevents segmentation errors caused by the polling thread uses the
memory after the memory is freed.
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
uadk_tool/benchmark/hpre_uadk_benchmark.c | 49 ++++++++++++++++++++++-
1 file changed, 48 insertions(+), 1 deletion(-)
diff --git a/uadk_tool/benchmark/hpre_uadk_benchmark.c b/uadk_tool/benchmark/hpre_uadk_benchmark.c
index 653232f..5e84d61 100644
--- a/uadk_tool/benchmark/hpre_uadk_benchmark.c
+++ b/uadk_tool/benchmark/hpre_uadk_benchmark.c
@@ -1314,7 +1314,22 @@ static void *rsa_uadk_async_run(void *arg)
count++;
} while(true);
- /* clean output buffer remainings in the last time operation */
+ /* Release memory after all tasks are complete. */
+ if (count) {
+ i = 0;
+ while (get_recv_time() != g_ctxnum) {
+ if (i++ >= MAX_TRY_CNT) {
+ HPRE_TST_PRT("failed to wait poll thread finish!\n");
+ break;
+ }
+
+ usleep(SEND_USLEEP);
+ }
+
+ /* Wait for the device to complete the tasks. */
+ usleep(SEND_USLEEP * MAX_TRY_CNT);
+ }
+
if (req.op_type == WD_RSA_GENKEY) {
wd_rsa_del_kg_in(h_sess, req.src);
req.src = NULL;
@@ -1576,6 +1591,22 @@ static void *dh_uadk_async_run(void *arg)
count++;
} while(true);
+ /* Release memory after all tasks are complete. */
+ if (count) {
+ i = 0;
+ while (get_recv_time() != g_ctxnum) {
+ if (i++ >= MAX_TRY_CNT) {
+ HPRE_TST_PRT("failed to wait poll thread finish!\n");
+ break;
+ }
+
+ usleep(SEND_USLEEP);
+ }
+
+ /* Wait for the device to complete the tasks. */
+ usleep(SEND_USLEEP * MAX_TRY_CNT);
+ }
+
free(tag);
param_release:
free(req.x_p);
@@ -2227,6 +2258,22 @@ static void *ecc_uadk_async_run(void *arg)
count++;
} while(true);
+ /* Release memory after all tasks are complete. */
+ if (count) {
+ i = 0;
+ while (get_recv_time() != g_ctxnum) {
+ if (i++ >= MAX_TRY_CNT) {
+ HPRE_TST_PRT("failed to wait poll thread finish!\n");
+ break;
+ }
+
+ usleep(SEND_USLEEP);
+ }
+
+ /* Wait for the device to complete the tasks. */
+ usleep(SEND_USLEEP * MAX_TRY_CNT);
+ }
+
free(tag);
src_release:
if (req.src)
--
2.25.1