From: Weili Qian qianweili@huawei.com
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)