libwd/0050-uadk_tool-add-latency-test-function-for-uadk_tools.patch
2023-11-23 10:41:04 +08:00

532 lines
16 KiB
Diff

From ca646cd14b69137795a90d8ec527743c43d0f897 Mon Sep 17 00:00:00 2001
From: Longfang Liu <liulongfang@huawei.com>
Date: Fri, 10 Nov 2023 11:52:19 +0800
Subject: [PATCH 50/85] uadk_tool: add latency test function for uadk_tools
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>
---
uadk_tool/benchmark/hpre_uadk_benchmark.c | 3 +
uadk_tool/benchmark/hpre_wd_benchmark.c | 3 +
uadk_tool/benchmark/sec_soft_benchmark.c | 3 +
uadk_tool/benchmark/sec_uadk_benchmark.c | 3 +
uadk_tool/benchmark/sec_wd_benchmark.c | 3 +
uadk_tool/benchmark/uadk_benchmark.c | 105 ++++++++++++++--------
uadk_tool/benchmark/uadk_benchmark.h | 15 +++-
uadk_tool/benchmark/zip_uadk_benchmark.c | 12 +--
uadk_tool/benchmark/zip_wd_benchmark.c | 12 +--
9 files changed, 102 insertions(+), 57 deletions(-)
diff --git a/uadk_tool/benchmark/hpre_uadk_benchmark.c b/uadk_tool/benchmark/hpre_uadk_benchmark.c
index 5e84d61..13e24ca 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;
@@ -1670,6 +1671,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;
@@ -2102,6 +2104,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 ea84393..f3510b1 100644
--- a/uadk_tool/benchmark/sec_soft_benchmark.c
+++ b/uadk_tool/benchmark/sec_soft_benchmark.c
@@ -882,6 +882,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;
@@ -986,6 +987,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;
@@ -1056,6 +1058,7 @@ 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 1ea57ee..ff83769 100644
--- a/uadk_tool/benchmark/sec_uadk_benchmark.c
+++ b/uadk_tool/benchmark/sec_uadk_benchmark.c
@@ -934,6 +934,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;
@@ -1024,6 +1025,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;
@@ -1083,6 +1085,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 038d3ab..5dd1501 100644
--- a/uadk_tool/benchmark/sec_wd_benchmark.c
+++ b/uadk_tool/benchmark/sec_wd_benchmark.c
@@ -1032,6 +1032,7 @@ static void *sec_wd_cipher_sync(void *arg)
}
wcrypto_del_cipher_ctx(ctx);
+ cal_avg_latency(count);
add_recv_data(count, g_pktlen);
return NULL;
@@ -1156,6 +1157,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;
@@ -1245,6 +1247,7 @@ static void *sec_wd_digest_sync(void *arg)
}
wcrypto_del_digest_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..2791f84 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;
@@ -116,6 +117,9 @@ static struct acc_alg_item alg_options[] = {
{"aes-128-gcm", AES_128_GCM},
{"aes-192-gcm", AES_192_GCM},
{"aes-256-gcm", AES_256_GCM},
+ {"aes-128-cbc-sha256-hmac", AES_128_CBC_SHA256_HMAC},
+ {"aes-192-cbc-sha256-hmac", AES_192_CBC_SHA256_HMAC},
+ {"aes-256-cbc-sha256-hmac", AES_256_CBC_SHA256_HMAC},
{"sm4-128-ccm", SM4_128_CCM},
{"sm4-128-gcm", SM4_128_GCM},
{"sm3", SM3_ALG},
@@ -290,6 +294,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)
@@ -382,7 +398,7 @@ void cal_perfermance_data(struct acc_option *option, u32 sttime)
if (get_recv_time() == option->threads)
break;
} else { // ASYNC_MODE
- if (get_recv_time() == 1)
+ if (get_recv_time() == 1) // poll complete
break;
}
usleep(1000);
@@ -471,9 +487,9 @@ int acc_benchmark_run(struct acc_option *option)
int i, ret = 0;
int status;
- 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) {
@@ -549,12 +565,12 @@ int acc_default_case(struct acc_option *option)
static void print_help(void)
{
ACC_TST_PRT("NAME\n");
- ACC_TST_PRT(" uadk_tool benchmark: test UADK acc performance,etc\n");
+ ACC_TST_PRT(" benchmark: test UADK acc performance,etc\n");
ACC_TST_PRT("USAGE\n");
- ACC_TST_PRT(" uadk_tool benchmark [--alg aes-128-cbc] [--alg rsa-2048]\n");
- ACC_TST_PRT(" uadk_tool benchmark [--mode] [--pktlen] [--keylen] [--seconds]\n");
- ACC_TST_PRT(" uadk_tool benchmark [--multi] [--sync] [--async] [--help]\n");
- ACC_TST_PRT(" numactl --cpubind=0 --membind=0,1 ./uadk_tool benchmark xxxx\n");
+ ACC_TST_PRT(" benchmark [--alg aes-128-cbc] [--alg rsa-2048]\n");
+ ACC_TST_PRT(" benchmark [--mode] [--pktlen] [--keylen] [--seconds]\n");
+ ACC_TST_PRT(" benchmark [--multi] [--sync] [--async] [--help]\n");
+ ACC_TST_PRT(" numactl --cpubind=0 --membind=0,1 ./uadk_benchmark xxxx\n");
ACC_TST_PRT(" specify numa nodes for cpu and memory\n");
ACC_TST_PRT("DESCRIPTION\n");
ACC_TST_PRT(" [--alg aes-128-cbc ]:\n");
@@ -569,7 +585,7 @@ static void print_help(void)
ACC_TST_PRT(" [--seconds]:\n");
ACC_TST_PRT(" set the test times\n");
ACC_TST_PRT(" [--multi]:\n");
- ACC_TST_PRT(" set the number of process\n");
+ ACC_TST_PRT(" set the number of threads\n");
ACC_TST_PRT(" [--thread]:\n");
ACC_TST_PRT(" set the number of threads\n");
ACC_TST_PRT(" [--ctxnum]:\n");
@@ -580,11 +596,13 @@ 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");
- ACC_TST_PRT(" --pktlen 1024 --seconds 1 --multi 1 --thread 1 --ctxnum 4\n");
- ACC_TST_PRT("UPDATE:2022-7-18\n");
+ ACC_TST_PRT(" --pktlen 1024 --seconds 1 --multi 1 --thread 1 --ctxnum 2\n");
+ ACC_TST_PRT("UPDATE:2022-3-28\n");
}
static void print_support_alg(void)
@@ -603,20 +621,21 @@ int acc_cmd_parse(int argc, char *argv[], struct acc_option *option)
int c;
static struct option long_options[] = {
- {"alg", required_argument, 0, 2},
- {"mode", required_argument, 0, 3},
- {"opt", required_argument, 0, 4},
- {"sync", no_argument, 0, 5},
- {"async", no_argument, 0, 6},
- {"pktlen", required_argument, 0, 7},
- {"seconds", required_argument, 0, 8},
- {"thread", required_argument, 0, 9},
- {"multi", required_argument, 0, 10},
- {"ctxnum", required_argument, 0, 11},
- {"prefetch", no_argument, 0, 12},
- {"engine", required_argument, 0, 13},
- {"alglist", no_argument, 0, 14},
- {"help", no_argument, 0, 15},
+ {"alg", required_argument, 0, 1},
+ {"mode", required_argument, 0, 2},
+ {"opt", required_argument, 0, 3},
+ {"sync", no_argument, 0,4},
+ {"async", no_argument, 0,5},
+ {"pktlen", required_argument, 0, 6},
+ {"seconds", required_argument, 0, 7},
+ {"thread", required_argument, 0, 8},
+ {"multi", required_argument, 0, 9},
+ {"ctxnum", required_argument, 0, 10},
+ {"prefetch", no_argument, 0,11},
+ {"engine", required_argument, 0,12},
+ {"alglist", no_argument, 0, 13},
+ {"latency", no_argument, 0, 14},
+ {"help", no_argument, 0, 15},
{0, 0, 0, 0}
};
@@ -626,46 +645,49 @@ int acc_cmd_parse(int argc, char *argv[], struct acc_option *option)
break;
switch (c) {
- case 2:
+ case 1:
option->algtype = get_alg_type(optarg);
strcpy(option->algname, optarg);
break;
- case 3:
+ case 2:
option->modetype = get_mode_type(optarg);
break;
- case 4:
+ case 3:
option->optype = strtol(optarg, NULL, 0);
break;
- case 5:
+ case 4:
option->syncmode = SYNC_MODE;
break;
- case 6:
+ case 5:
option->syncmode = ASYNC_MODE;
break;
- case 7:
+ case 6:
option->pktlen = strtol(optarg, NULL, 0);
break;
- case 8:
+ case 7:
option->times = strtol(optarg, NULL, 0);
break;
- case 9:
+ case 8:
option->threads = strtol(optarg, NULL, 0);
break;
- case 10:
+ case 9:
option->multis = strtol(optarg, NULL, 0);
break;
- case 11:
+ case 10:
option->ctxnums = strtol(optarg, NULL, 0);
break;
- case 12:
+ case 11:
option->prefetch = 1;
break;
- case 13:
+ case 12:
strcpy(option->engine, optarg);
break;
- case 14:
+ case 13:
print_support_alg();
goto to_exit;
+ case 14:
+ option->latency = true;
+ break;
case 15:
print_help();
goto to_exit;
@@ -729,9 +751,14 @@ int acc_option_convert(struct acc_option *option)
if (!strlen(option->engine)) {
option->engine_flag = false;
return 0;
- } else if (strcmp(option->engine, "uadk")) {
+ } else if (strcmp(option->engine, "uadk_engine")) {
option->engine_flag = false;
- ACC_TST_PRT("uadk benchmark just support engine: uadk\n");
+ ACC_TST_PRT("uadk benchmark just support engine: uadk_engine\n");
+ 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;
}
diff --git a/uadk_tool/benchmark/uadk_benchmark.h b/uadk_tool/benchmark/uadk_benchmark.h
index a344fac..2c8de11 100644
--- a/uadk_tool/benchmark/uadk_benchmark.h
+++ b/uadk_tool/benchmark/uadk_benchmark.h
@@ -32,12 +32,17 @@
#define MAX_POOL_LENTH 4096
#define MAX_TRY_CNT 5000
#define SEND_USLEEP 100
+#define SEC_2_USEC 1000000
+#define HASH_ZISE 16
-typedef unsigned char u8;
+typedef unsigned long long u64;
typedef unsigned int u32;
-typedef unsigned long long u64;
+typedef unsigned short u16;
+typedef unsigned char u8;
+
#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 +52,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 +71,7 @@ struct acc_option {
char engine[64];
u32 engine_flag;
u32 prefetch;
+ bool latency;
};
enum acc_type {
@@ -153,6 +160,9 @@ enum test_alg {
AES_128_GCM,
AES_192_GCM,
AES_256_GCM,
+ AES_128_CBC_SHA256_HMAC,
+ AES_192_CBC_SHA256_HMAC,
+ AES_256_CBC_SHA256_HMAC,
SM4_128_CCM,
SM4_128_GCM,
SM3_ALG, // digest
@@ -177,6 +187,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;
--
2.25.1