From: Longfang Liu liulongfang@huawei.com
Add latency test function for symmetric algorithm, asymmetric algorithm and compression algorithm in uadk_tools, and add this function for SVA mode and No-SVA mode at the same time.
Signed-off-by: Longfang Liu liulongfang@huawei.com Signed-off-by: Zhiqi Song songzhiqi@huawei.com --- uadk_tool/benchmark/hpre_uadk_benchmark.c | 3 +++ uadk_tool/benchmark/hpre_wd_benchmark.c | 3 +++ uadk_tool/benchmark/sec_soft_benchmark.c | 4 ++++ uadk_tool/benchmark/sec_uadk_benchmark.c | 3 +++ uadk_tool/benchmark/sec_wd_benchmark.c | 1 + uadk_tool/benchmark/uadk_benchmark.c | 29 +++++++++++++++++++++-- uadk_tool/benchmark/uadk_benchmark.h | 11 ++++++--- uadk_tool/benchmark/zip_uadk_benchmark.c | 12 ++++------ uadk_tool/benchmark/zip_wd_benchmark.c | 12 ++++------ 9 files changed, 57 insertions(+), 21 deletions(-)
diff --git a/uadk_tool/benchmark/hpre_uadk_benchmark.c b/uadk_tool/benchmark/hpre_uadk_benchmark.c index e722c36..495f50b 100644 --- a/uadk_tool/benchmark/hpre_uadk_benchmark.c +++ b/uadk_tool/benchmark/hpre_uadk_benchmark.c @@ -1198,6 +1198,7 @@ key_release: free(key_info);
wd_rsa_free_sess(h_sess); + cal_avg_latency(count); add_recv_data(count, key_size);
return NULL; @@ -1651,6 +1652,7 @@ param_release: free(req.pri); sess_release: wd_dh_free_sess(h_sess); + cal_avg_latency(count); add_recv_data(count, key_size);
return NULL; @@ -2083,6 +2085,7 @@ msg_release: if (subtype == SM2_TYPE) free(setup.msg);
+ cal_avg_latency(count); add_recv_data(count, key_size);
return NULL; diff --git a/uadk_tool/benchmark/hpre_wd_benchmark.c b/uadk_tool/benchmark/hpre_wd_benchmark.c index 354e0e1..231b569 100644 --- a/uadk_tool/benchmark/hpre_wd_benchmark.c +++ b/uadk_tool/benchmark/hpre_wd_benchmark.c @@ -928,6 +928,7 @@ key_release: free(key_info);
wcrypto_del_rsa_ctx(ctx); + cal_avg_latency(count); add_recv_data(count, key_size);
return NULL; @@ -1324,6 +1325,7 @@ param_release: wd_free_blk(pool, opdata.pri); ctx_release: wcrypto_del_dh_ctx(ctx); + cal_avg_latency(count); add_recv_data(count, key_size);
return NULL; @@ -2193,6 +2195,7 @@ sess_release: msg_release: if (subtype == SM2_TYPE) free(setup.msg); + cal_avg_latency(count); add_recv_data(count, key_size);
return NULL; diff --git a/uadk_tool/benchmark/sec_soft_benchmark.c b/uadk_tool/benchmark/sec_soft_benchmark.c index c7870aa..a4a2fdb 100644 --- a/uadk_tool/benchmark/sec_soft_benchmark.c +++ b/uadk_tool/benchmark/sec_soft_benchmark.c @@ -867,6 +867,7 @@ static void *sec_soft_cipher_sync(void *arg) EVP_CIPHER_CTX_cleanup(ctx); EVP_CIPHER_CTX_free(ctx);
+ cal_avg_latency(count); add_recv_data(count, g_pktlen);
return NULL; @@ -963,6 +964,7 @@ static void *sec_soft_aead_sync(void *arg) } EVP_CIPHER_CTX_free(ctx);
+ cal_avg_latency(count); add_recv_data(count, g_pktlen);
return NULL; @@ -1032,6 +1034,8 @@ static void *sec_soft_digest_sync(void *arg) } HMAC_CTX_free(hm_ctx); } + + cal_avg_latency(count); add_recv_data(count, g_pktlen);
return NULL; diff --git a/uadk_tool/benchmark/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c index 11cf8a1..7828eab 100644 --- a/uadk_tool/benchmark/sec_uadk_benchmark.c +++ b/uadk_tool/benchmark/sec_uadk_benchmark.c @@ -901,6 +901,7 @@ static void *sec_uadk_cipher_sync(void *arg) } wd_cipher_free_sess(h_sess);
+ cal_avg_latency(count); add_recv_data(count, g_pktlen);
return NULL; @@ -988,6 +989,7 @@ static void *sec_uadk_aead_sync(void *arg) } wd_aead_free_sess(h_sess);
+ cal_avg_latency(count); add_recv_data(count, g_pktlen);
return NULL; @@ -1047,6 +1049,7 @@ static void *sec_uadk_digest_sync(void *arg) } wd_digest_free_sess(h_sess);
+ cal_avg_latency(count); add_recv_data(count, g_pktlen);
return NULL; diff --git a/uadk_tool/benchmark/sec_wd_benchmark.c b/uadk_tool/benchmark/sec_wd_benchmark.c index 6d3f8da..50c966c 100644 --- a/uadk_tool/benchmark/sec_wd_benchmark.c +++ b/uadk_tool/benchmark/sec_wd_benchmark.c @@ -1112,6 +1112,7 @@ static void *sec_wd_aead_sync(void *arg)
wcrypto_del_aead_ctx(ctx);
+ cal_avg_latency(count); add_recv_data(count, g_pktlen);
return NULL; diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c index 752553d..6313ac6 100644 --- a/uadk_tool/benchmark/uadk_benchmark.c +++ b/uadk_tool/benchmark/uadk_benchmark.c @@ -18,6 +18,7 @@
/*----------------------------------------head struct--------------------------------------------------------*/ static unsigned int g_run_state = 1; +static struct acc_option *g_run_options; static pthread_mutex_t acc_mutex = PTHREAD_MUTEX_INITIALIZER; static struct _recv_data { double pkg_len; @@ -290,6 +291,18 @@ void get_rand_data(u8 *addr, u32 size) #endif }
+ +void cal_avg_latency(u32 count) +{ + double latency; + + if (!g_run_options || !g_run_options->latency) + return; + + latency = (double)g_run_options->times * SEC_2_USEC / count; + ACC_TST_PRT("thread<%lu> avg latency: %.1fus\n", gettid(), latency); +} + /*-------------------------------------main code------------------------------------------------------*/
static void parse_alg_param(struct acc_option *option) @@ -474,6 +487,7 @@ int acc_benchmark_run(struct acc_option *option) ACC_TST_PRT("start UADK benchmark test.\n"); parse_alg_param(option); dump_param(option); + g_run_options = option;
pthread_mutex_init(&acc_mutex, NULL); if (option->multis <= 1) { @@ -580,6 +594,8 @@ static void print_help(void) ACC_TST_PRT(" set the test openssl engine\n"); ACC_TST_PRT(" [--alglist]:\n"); ACC_TST_PRT(" list the all support alg\n"); + ACC_TST_PRT(" [--latency]:\n"); + ACC_TST_PRT(" test the running time of packets\n"); ACC_TST_PRT(" [--help] = usage\n"); ACC_TST_PRT("Example\n"); ACC_TST_PRT(" ./uadk_tool benchmark --alg aes-128-cbc --mode sva --opt 0 --sync\n"); @@ -616,7 +632,8 @@ int acc_cmd_parse(int argc, char *argv[], struct acc_option *option) {"prefetch", no_argument, 0, 12}, {"engine", required_argument, 0, 13}, {"alglist", no_argument, 0, 14}, - {"help", no_argument, 0, 15}, + {"latency", no_argument, 0, 15}, + {"help", no_argument, 0, 16}, {0, 0, 0, 0} };
@@ -665,8 +682,11 @@ int acc_cmd_parse(int argc, char *argv[], struct acc_option *option) break; case 14: print_support_alg(); - goto to_exit; + break; case 15: + option->latency = true; + break; + case 16: print_help(); goto to_exit; default: @@ -735,6 +755,11 @@ int acc_option_convert(struct acc_option *option) goto param_err; }
+ if (option->syncmode == ASYNC_MODE && option->latency) { + ACC_TST_PRT("uadk benchmark async mode can't test latency\n"); + goto param_err; + } + return 0;
param_err: diff --git a/uadk_tool/benchmark/uadk_benchmark.h b/uadk_tool/benchmark/uadk_benchmark.h index a344fac..5071457 100644 --- a/uadk_tool/benchmark/uadk_benchmark.h +++ b/uadk_tool/benchmark/uadk_benchmark.h @@ -32,12 +32,14 @@ #define MAX_POOL_LENTH 4096 #define MAX_TRY_CNT 5000 #define SEND_USLEEP 100 +#define SEC_2_USEC 1000000
-typedef unsigned char u8; -typedef unsigned int u32; -typedef unsigned long long u64; +typedef unsigned char u8; +typedef unsigned int u32; +typedef unsigned long long u64; #define SCHED_SINGLE "sched_single" #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#define gettid() syscall(__NR_gettid)
/** * struct acc_option - Define the test acc app option list. @@ -47,6 +49,7 @@ typedef unsigned long long u64; * @modetype: sva, no-sva, soft mode * @optype: enc/dec, comp/decomp * @prefetch: write allocated memory to prevent page faults + * @latency: test packet running time */ struct acc_option { char algname[64]; @@ -65,6 +68,7 @@ struct acc_option { char engine[64]; u32 engine_flag; u32 prefetch; + bool latency; };
enum acc_type { @@ -177,6 +181,7 @@ extern void get_rand_data(u8 *addr, u32 size); extern void add_recv_data(u32 cnt, u32 pkglen); extern void add_send_complete(void); extern u32 get_recv_time(void); +extern void cal_avg_latency(u32 count);
int acc_cmd_parse(int argc, char *argv[], struct acc_option *option); int acc_default_case(struct acc_option *option); diff --git a/uadk_tool/benchmark/zip_uadk_benchmark.c b/uadk_tool/benchmark/zip_uadk_benchmark.c index ba18e6d..ffffa9b 100644 --- a/uadk_tool/benchmark/zip_uadk_benchmark.c +++ b/uadk_tool/benchmark/zip_uadk_benchmark.c @@ -603,8 +603,7 @@ fse_err: free(ftuple); wd_comp_free_sess(h_sess);
- // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n", - // MAX_POOL_LENTH, count, creq.dst_len); + cal_avg_latency(count); if (pdata->optype == WD_DIR_COMPRESS) add_recv_data(count, creq.src_len); else @@ -700,8 +699,7 @@ fse_err: free(ftuple); wd_comp_free_sess(h_sess);
- // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n", - // MAX_POOL_LENTH, count, creq.dst_len); + cal_avg_latency(count); if (pdata->optype == WD_DIR_COMPRESS) add_recv_data(count, creq.src_len); else @@ -872,8 +870,7 @@ static void *zip_uadk_blk_sync_run(void *arg) } wd_comp_free_sess(h_sess);
- //ZIP_TST_PRT("valid pool len: %u, send count BD: %u, input len: %u, output len: %u!\n", - // MAX_POOL_LENTH, count, creq.src_len, g_pktlen); + cal_avg_latency(count); add_recv_data(count, g_pktlen);
return NULL; @@ -936,8 +933,7 @@ static void *zip_uadk_stm_sync_run(void *arg) } wd_comp_free_sess(h_sess);
- // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n", - // MAX_POOL_LENTH, count, creq.dst_len); + cal_avg_latency(count); add_recv_data(count, g_pktlen);
return NULL; diff --git a/uadk_tool/benchmark/zip_wd_benchmark.c b/uadk_tool/benchmark/zip_wd_benchmark.c index 0df78cd..8d013c5 100644 --- a/uadk_tool/benchmark/zip_wd_benchmark.c +++ b/uadk_tool/benchmark/zip_wd_benchmark.c @@ -591,8 +591,7 @@ fse_err: free(ftuple); wcrypto_del_comp_ctx(ctx);
- // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n", - // MAX_POOL_LENTH, count, opdata.produced); + cal_avg_latency(count); if (pdata->optype == WCRYPTO_DEFLATE) add_recv_data(count, opdata.in_len); else @@ -703,8 +702,7 @@ fse_err: free(ftuple); wcrypto_del_comp_ctx(ctx);
- // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n", - // MAX_POOL_LENTH, count, opdata.produced); + cal_avg_latency(count); if (pdata->optype == WCRYPTO_DEFLATE) add_recv_data(count, opdata.in_len); else @@ -906,8 +904,7 @@ static void *zip_wd_blk_sync_run(void *arg) } wcrypto_del_comp_ctx(ctx);
- // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n", - // MAX_POOL_LENTH, count, opdata.produced); + cal_avg_latency(count); add_recv_data(count, g_pktlen);
return NULL; @@ -983,8 +980,7 @@ static void *zip_wd_stm_sync_run(void *arg) } wcrypto_del_comp_ctx(ctx);
- // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n", - // MAX_POOL_LENTH, count, opdata.produced); + cal_avg_latency(count); add_recv_data(count, g_pktlen);
return NULL;