From 47705e97580314d97c6ad781b0252a80d8024fc1 Mon Sep 17 00:00:00 2001 From: Liulongfang Date: Tue, 22 Feb 2022 11:47:02 +0800 Subject: [PATCH 71/76] uadk/tool: modify uadk_benchmark toos code 1.bugfix some alg parameter 2.add multi thread for async mode to poll BD Signed-off-by: Liulongfang --- uadk_tool/sec_uadk_benchmark.c | 55 +++++++++++++++++-------------- uadk_tool/sec_wd_benchmark.c | 59 +++++++++++++++++++--------------- uadk_tool/uadk_benchmark.c | 4 +-- 3 files changed, 66 insertions(+), 52 deletions(-) diff --git a/uadk_tool/sec_uadk_benchmark.c b/uadk_tool/sec_uadk_benchmark.c index d68ac25..467e621 100644 --- a/uadk_tool/sec_uadk_benchmark.c +++ b/uadk_tool/sec_uadk_benchmark.c @@ -180,13 +180,13 @@ static int sec_uadk_param_parse(thread_data *tddata, struct acc_option *options) break; case DES3_128_ECB: keysize = 16; - ivsize = 8; + ivsize = 0; mode = WD_CIPHER_ECB; alg = WD_CIPHER_3DES; break; case DES3_192_ECB: keysize = 24; - ivsize = 8; + ivsize = 0; mode = WD_CIPHER_ECB; alg = WD_CIPHER_3DES; break; @@ -204,7 +204,7 @@ static int sec_uadk_param_parse(thread_data *tddata, struct acc_option *options) break; case SM4_128_ECB: keysize = 16; - ivsize = 16; + ivsize = 0; mode = WD_CIPHER_ECB; alg = WD_CIPHER_SM4; break; @@ -233,7 +233,7 @@ static int sec_uadk_param_parse(thread_data *tddata, struct acc_option *options) alg = WD_CIPHER_SM4; break; case SM4_128_XTS: - keysize = 16; + keysize = 32; ivsize = 16; mode = WD_CIPHER_XTS; alg = WD_CIPHER_SM4; @@ -560,11 +560,14 @@ void *sec_uadk_poll(void *data) poll_ctx uadk_poll_ctx = NULL; thread_data *pdata = (thread_data *)data; u32 expt = ACC_QUEUE_SIZE * g_thread_num; + u32 id = pdata->td_id; u32 last_time = 2; /* poll need one more recv time */ u32 count = 0; u32 recv = 0; - u32 i = 0; - int ret; + int ret; + + if (id > g_ctxnum) + return NULL; switch(pdata->subtype) { case CIPHER_TYPE: @@ -582,15 +585,13 @@ void *sec_uadk_poll(void *data) } while (last_time) { - for (i = 0; i < g_ctx_cfg.ctx_num; i++) { - ret = uadk_poll_ctx(i, expt, &recv); - // SEC_TST_PRT("expt %u, poll %d recv: %u!\n", expt, i, recv); - count += recv; - recv = 0; - if (unlikely(ret != -WD_EAGAIN && ret < 0)) { - SEC_TST_PRT("poll ret: %u!\n", ret); - goto recv_error; - } + ret = uadk_poll_ctx(id, expt, &recv); + // SEC_TST_PRT("expt %u, poll %d recv: %u!\n", expt, i, recv); + count += recv; + recv = 0; + if (unlikely(ret != -WD_EAGAIN && ret < 0)) { + SEC_TST_PRT("poll ret: %u!\n", ret); + goto recv_error; } if (get_run_state() == 0) @@ -989,7 +990,7 @@ int sec_uadk_async_threads(struct acc_option *options) thread_data threads_args[THREADS_NUM]; thread_data threads_option; pthread_t tdid[THREADS_NUM]; - pthread_t pollid; + pthread_t pollid[THREADS_NUM]; int i, ret; /* alg param parse and set to thread data */ @@ -998,10 +999,14 @@ int sec_uadk_async_threads(struct acc_option *options) return ret; /* poll thread */ - ret = pthread_create(&pollid, NULL, sec_uadk_poll, &threads_option); - if (ret) { - SEC_TST_PRT("Create poll thread fail!\n"); - goto async_error; + for (i = 0; i < g_ctxnum; i++) { + threads_args[i].subtype = threads_option.subtype; + threads_args[i].td_id = i; + ret = pthread_create(&pollid, NULL, sec_uadk_poll, &threads_args[i]); + if (ret) { + SEC_TST_PRT("Create poll thread fail!\n"); + goto async_error; + } } for (i = 0; i < g_thread_num; i++) { @@ -1028,10 +1033,12 @@ int sec_uadk_async_threads(struct acc_option *options) } } - ret = pthread_join(pollid, NULL); - if (ret) { - SEC_TST_PRT("Join poll thread fail!\n"); - goto async_error; + for (i = 0; i < g_ctxnum; i++) { + ret = pthread_join(pollid[i], NULL); + if (ret) { + SEC_TST_PRT("Join poll thread fail!\n"); + goto async_error; + } } async_error: diff --git a/uadk_tool/sec_wd_benchmark.c b/uadk_tool/sec_wd_benchmark.c index dffd3a7..74b106e 100644 --- a/uadk_tool/sec_wd_benchmark.c +++ b/uadk_tool/sec_wd_benchmark.c @@ -200,13 +200,13 @@ static int sec_wd_param_parse(thread_data *tddata, struct acc_option *options) break; case DES3_128_ECB: keysize = 16; - ivsize = 8; + ivsize = 0; mode = WCRYPTO_CIPHER_ECB; alg = WCRYPTO_CIPHER_3DES; break; case DES3_192_ECB: keysize = 24; - ivsize = 8; + ivsize = 0; mode = WCRYPTO_CIPHER_ECB; alg = WCRYPTO_CIPHER_3DES; break; @@ -224,7 +224,7 @@ static int sec_wd_param_parse(thread_data *tddata, struct acc_option *options) break; case SM4_128_ECB: keysize = 16; - ivsize = 16; + ivsize = 0; mode = WCRYPTO_CIPHER_ECB; alg = WCRYPTO_CIPHER_SM4; break; @@ -253,7 +253,7 @@ static int sec_wd_param_parse(thread_data *tddata, struct acc_option *options) alg = WCRYPTO_CIPHER_SM4; break; case SM4_128_XTS: - keysize = 16; + keysize = 32; ivsize = 16; mode = WCRYPTO_CIPHER_XTS; alg = WCRYPTO_CIPHER_SM4; @@ -525,9 +525,9 @@ void *sec_wd_poll(void *data) poll_ctx uadk_poll_ctx = NULL; u32 expt = ACC_QUEUE_SIZE * g_thread_num; u32 last_time = 2; /* poll need one more recv time */ + u32 id = pdata->td_id; u32 count = 0; u32 recv = 0; - u32 i = 0; switch(pdata->subtype) { case CIPHER_TYPE: @@ -544,20 +544,21 @@ void *sec_wd_poll(void *data) return NULL; } + if (id > g_thread_num) + return NULL; + while (last_time) { - for (i = 0; i < g_thread_num; i++) { - recv = uadk_poll_ctx(g_thread_queue.bd_res[i].queue, expt); - /* - * warpdrive async mode poll easy to 100% with small package. - * SEC_TST_PRT("warpdrive poll %d recv: %u!\n", i, recv); - */ - if (unlikely(recv < 0)) { - SEC_TST_PRT("poll ret: %u!\n", recv); - goto recv_error; - } - count += recv; - recv = 0; + recv = uadk_poll_ctx(g_thread_queue.bd_res[id].queue, expt); + /* + * warpdrive async mode poll easy to 100% with small package. + * SEC_TST_PRT("warpdrive poll %d recv: %u!\n", i, recv); + */ + if (unlikely(recv < 0)) { + SEC_TST_PRT("poll ret: %u!\n", recv); + goto recv_error; } + count += recv; + recv = 0; if (get_run_state() == 0) last_time--; @@ -1186,7 +1187,7 @@ int sec_wd_async_threads(struct acc_option *options) thread_data threads_args[THREADS_NUM]; thread_data threads_option; pthread_t tdid[THREADS_NUM]; - pthread_t pollid; + pthread_t pollid[THREADS_NUM]; int i, ret; /* alg param parse and set to thread data */ @@ -1195,10 +1196,14 @@ int sec_wd_async_threads(struct acc_option *options) return ret; /* poll thread */ - ret = pthread_create(&pollid, NULL, sec_wd_poll, &threads_option); - if (ret) { - SEC_TST_PRT("Create poll thread fail!\n"); - goto async_error; + for (i = 0; i < g_thread_num; i++) { + threads_args[i].subtype = threads_option.subtype; + threads_args[i].td_id = i; + ret = pthread_create(&pollid[i], NULL, sec_wd_poll, &threads_args[i]); + if (ret) { + SEC_TST_PRT("Create poll thread fail!\n"); + goto async_error; + } } for (i = 0; i < g_thread_num; i++) { @@ -1225,10 +1230,12 @@ int sec_wd_async_threads(struct acc_option *options) } } - ret = pthread_join(pollid, NULL); - if (ret) { - SEC_TST_PRT("Join poll thread fail!\n"); - goto async_error; + for (i = 0; i < g_thread_num; i++) { + ret = pthread_join(pollid[i], NULL); + if (ret) { + SEC_TST_PRT("Join poll thread fail!\n"); + goto async_error; + } } async_error: diff --git a/uadk_tool/uadk_benchmark.c b/uadk_tool/uadk_benchmark.c index 0d7fc71..8c3c96f 100644 --- a/uadk_tool/uadk_benchmark.c +++ b/uadk_tool/uadk_benchmark.c @@ -271,7 +271,7 @@ int get_rand_int(int range) ACC_TST_PRT("rand range error!\n"); return 1; } - srand((unsigned) time(NULL) * getpid()); + srand((unsigned)time(NULL) * getpid()); randnum = rand() % range; return randnum; @@ -281,7 +281,7 @@ void get_rand_data(u8 *addr, int size) { int i; - srand((unsigned) time(NULL) * getpid()); + srand((unsigned)time(NULL) * getpid()); for (i = 0; i < size; i++) { addr[i] = rand() % 0xFF; } -- 2.25.1