*** BLURB HERE ***
Chenghai Huang (3): uadk tool: fix the logic for counting retransmissions when busy uadk/tools - support the nosva test of a specified device uadk tool: fix the msg pool release bug of async zip benchmark
Longfang Liu (1): uadk_tool: fix aead performance test issue
Qi Tao (4): uadk_tool: support sm4 ce benchmark test uadk_tool: modify the description of the zip and sec uadk_tool: fix switch-case statement error uadk_tool: fix queue application failure from multiple devices
Weili Qian (1): uadk_tool: support sm3/md5 multibuff benchmark test
Yang Shen (1): uadk/tools - support designated device testing
Zhiqi Song (1): uadk_tool: support sm3 ce benchmark and function test
uadk_tool/Makefile.am | 1 + uadk_tool/benchmark/hpre_uadk_benchmark.c | 151 ++++++++-- uadk_tool/benchmark/hpre_wd_benchmark.c | 8 + uadk_tool/benchmark/sec_uadk_benchmark.c | 211 ++++++++++++-- uadk_tool/benchmark/sec_wd_benchmark.c | 26 ++ uadk_tool/benchmark/trng_wd_benchmark.c | 8 + uadk_tool/benchmark/uadk_benchmark.c | 125 +++++--- uadk_tool/benchmark/uadk_benchmark.h | 42 +-- uadk_tool/benchmark/zip_uadk_benchmark.c | 335 +++++++++++++++------- uadk_tool/benchmark/zip_wd_benchmark.c | 40 ++- uadk_tool/test/test_sec.c | 35 ++- 11 files changed, 747 insertions(+), 235 deletions(-)
From: Longfang Liu liulongfang@huawei.com
in the current UADK code. Due to the new support for aead stream mode, a new msg_state state has been added. If the initial value is not assigned, an error will occur in the block mode check. As a result, the performance test cannot be executed.
Signed-off-by: Longfang Liu liulongfang@huawei.com --- uadk_tool/benchmark/sec_uadk_benchmark.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/uadk_tool/benchmark/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c index c99ae89..92e967a 100644 --- a/uadk_tool/benchmark/sec_uadk_benchmark.c +++ b/uadk_tool/benchmark/sec_uadk_benchmark.c @@ -1165,6 +1165,7 @@ static void *sec_uadk_aead_async(void *arg) areq.mac_bytes = auth_size; areq.assoc_bytes = SEC_AEAD_LEN; areq.in_bytes = g_pktlen; + areq.msg_state = 0; if (pdata->is_union) areq.mac_bytes = 32; if (areq.op_type) // decrypto @@ -1396,6 +1397,7 @@ static void *sec_uadk_aead_sync(void *arg) areq.assoc_bytes = SEC_AEAD_LEN; areq.in_bytes = g_pktlen; areq.mac_bytes = g_maclen; + areq.msg_state = 0; if (areq.op_type) // decrypto areq.out_bytes = g_pktlen + 16; // aadsize = 16; else
From: Chenghai Huang huangchenghai2@huawei.com
The try cnt should be set to 0 after the packet is successfully sent, not after BUSY is returned.
Signed-off-by: Chenghai Huang huangchenghai2@huawei.com --- uadk_tool/benchmark/zip_uadk_benchmark.c | 8 ++++---- uadk_tool/benchmark/zip_wd_benchmark.c | 7 +++---- 2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/uadk_tool/benchmark/zip_uadk_benchmark.c b/uadk_tool/benchmark/zip_uadk_benchmark.c index 435c0b4..9681c22 100644 --- a/uadk_tool/benchmark/zip_uadk_benchmark.c +++ b/uadk_tool/benchmark/zip_uadk_benchmark.c @@ -817,9 +817,8 @@ static void *zip_uadk_blk_lz77_async_run(void *arg)
while(1) { if (get_run_state() == 0) - break; + break;
- try_cnt = 0; i = count % MAX_POOL_LENTH_COMP; creq.src = uadk_pool->bds[i].src; creq.dst = &hw_buff_out[i]; //temp out @@ -845,6 +844,7 @@ static void *zip_uadk_blk_lz77_async_run(void *arg) } else if (ret || creq.status) { break; } + try_cnt = 0; count++; }
@@ -1037,9 +1037,8 @@ static void *zip_uadk_blk_async_run(void *arg)
while(1) { if (get_run_state() == 0) - break; + break;
- try_cnt = 0; i = count % MAX_POOL_LENTH_COMP; creq.src = uadk_pool->bds[i].src; creq.dst = uadk_pool->bds[i].dst; @@ -1062,6 +1061,7 @@ static void *zip_uadk_blk_async_run(void *arg) } else if (ret || creq.status) { break; } + try_cnt = 0; count++; }
diff --git a/uadk_tool/benchmark/zip_wd_benchmark.c b/uadk_tool/benchmark/zip_wd_benchmark.c index d2340e0..d7bafd6 100644 --- a/uadk_tool/benchmark/zip_wd_benchmark.c +++ b/uadk_tool/benchmark/zip_wd_benchmark.c @@ -708,9 +708,8 @@ static void *zip_wd_blk_lz77_async_run(void *arg)
while(1) { if (get_run_state() == 0) - break; + break;
- try_cnt = 0; i = count % MAX_POOL_LENTH_COMP; opdata.in = bd_pool[i].src; opdata.out = bd_pool[i].dst; //temp out @@ -737,6 +736,7 @@ static void *zip_wd_blk_lz77_async_run(void *arg) opdata.status == WD_IN_EPARA || opdata.status == WD_VERIFY_ERR) { break; } + try_cnt = 0; count++; }
@@ -984,7 +984,6 @@ static void *zip_wd_blk_async_run(void *arg) opdata.in_len = bd_pool[i].src_len; opdata.avail_out = out_len;
- try_cnt = 0; tag[i].ctx = ctx; tag[i].td_id = pdata->td_id; tag[i].bd_idx = i; @@ -1002,7 +1001,7 @@ static void *zip_wd_blk_async_run(void *arg) opdata.status == WD_IN_EPARA || opdata.status == WD_VERIFY_ERR) { break; } - + try_cnt = 0; count++; }
From: Chenghai Huang huangchenghai2@huawei.com
Add the description of device parameters. The input should use the device name from '/sys/class/uacce/<name>'. Only full matching device names are supported.
Signed-off-by: Chenghai Huang huangchenghai2@huawei.com --- uadk_tool/benchmark/hpre_wd_benchmark.c | 8 ++++++++ uadk_tool/benchmark/sec_wd_benchmark.c | 8 ++++++++ uadk_tool/benchmark/trng_wd_benchmark.c | 8 ++++++++ uadk_tool/benchmark/uadk_benchmark.c | 3 +++ uadk_tool/benchmark/zip_wd_benchmark.c | 8 ++++++++ 5 files changed, 35 insertions(+)
diff --git a/uadk_tool/benchmark/hpre_wd_benchmark.c b/uadk_tool/benchmark/hpre_wd_benchmark.c index 2873ffd..4f87e06 100644 --- a/uadk_tool/benchmark/hpre_wd_benchmark.c +++ b/uadk_tool/benchmark/hpre_wd_benchmark.c @@ -431,6 +431,14 @@ static int init_hpre_wd_queue(struct acc_option *options) /* nodemask need to be clean */ g_thread_queue.bd_res[i].queue->node_mask = 0x0; memset(g_thread_queue.bd_res[i].queue->dev_path, 0x0, PATH_STR_SIZE); + if (strlen(options->device) != 0) { + ret = snprintf(g_thread_queue.bd_res[i].queue->dev_path, + PATH_STR_SIZE, options->device); + if (ret < 0) { + WD_ERR("failed to copy dev file path!\n"); + return -WD_EINVAL; + } + }
ret = wd_request_queue(g_thread_queue.bd_res[i].queue); if (ret) { diff --git a/uadk_tool/benchmark/sec_wd_benchmark.c b/uadk_tool/benchmark/sec_wd_benchmark.c index aa03db8..62efe9a 100644 --- a/uadk_tool/benchmark/sec_wd_benchmark.c +++ b/uadk_tool/benchmark/sec_wd_benchmark.c @@ -600,6 +600,14 @@ static int init_wd_queue(struct acc_option *options) /* nodemask need to be clean */ g_thread_queue.bd_res[i].queue->node_mask = 0x0; memset(g_thread_queue.bd_res[i].queue->dev_path, 0x0, PATH_STR_SIZE); + if (strlen(options->device) != 0) { + ret = snprintf(g_thread_queue.bd_res[i].queue->dev_path, + PATH_STR_SIZE, options->device); + if (ret < 0) { + WD_ERR("failed to copy dev file path!\n"); + return -WD_EINVAL; + } + }
ret = wd_request_queue(g_thread_queue.bd_res[i].queue); if (ret) { diff --git a/uadk_tool/benchmark/trng_wd_benchmark.c b/uadk_tool/benchmark/trng_wd_benchmark.c index 64942f0..e643520 100644 --- a/uadk_tool/benchmark/trng_wd_benchmark.c +++ b/uadk_tool/benchmark/trng_wd_benchmark.c @@ -51,6 +51,14 @@ static int init_trng_wd_queue(struct acc_option *options) /* nodemask need to be clean */ g_thread_queue.bd_res[i].queue->node_mask = 0x0; memset(g_thread_queue.bd_res[i].queue->dev_path, 0x0, PATH_STR_SIZE); + if (strlen(options->device) != 0) { + ret = snprintf(g_thread_queue.bd_res[i].queue->dev_path, + PATH_STR_SIZE, options->device); + if (ret < 0) { + WD_ERR("failed to copy dev file path!\n"); + return -WD_EINVAL; + } + }
g_thread_queue.bd_res[i].in_bytes = options->pktlen; g_thread_queue.bd_res[i].out = malloc(options->pktlen); diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c index cf3a93c..0ebbb68 100644 --- a/uadk_tool/benchmark/uadk_benchmark.c +++ b/uadk_tool/benchmark/uadk_benchmark.c @@ -595,6 +595,7 @@ static void dump_param(struct acc_option *option) ACC_TST_PRT(" [--engine]: %s\n", option->engine); ACC_TST_PRT(" [--latency]: %u\n", option->latency); ACC_TST_PRT(" [--init2]: %u\n", option->inittype); + ACC_TST_PRT(" [--device]: %s\n", option->device); }
int acc_benchmark_run(struct acc_option *option) @@ -718,6 +719,8 @@ static void print_help(void) ACC_TST_PRT(" test the running time of packets\n"); ACC_TST_PRT(" [--init2]:\n"); ACC_TST_PRT(" select init2 mode in the init interface of UADK SVA\n"); + ACC_TST_PRT(" [--device]:\n"); + ACC_TST_PRT(" select device to do task\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"); diff --git a/uadk_tool/benchmark/zip_wd_benchmark.c b/uadk_tool/benchmark/zip_wd_benchmark.c index d7bafd6..7f85b3c 100644 --- a/uadk_tool/benchmark/zip_wd_benchmark.c +++ b/uadk_tool/benchmark/zip_wd_benchmark.c @@ -310,6 +310,14 @@ static int init_zip_wd_queue(struct acc_option *options) /* nodemask need to be clean */ g_thread_queue.bd_res[i].queue->node_mask = 0x0; memset(g_thread_queue.bd_res[i].queue->dev_path, 0x0, PATH_STR_SIZE); + if (strlen(options->device) != 0) { + ret = snprintf(g_thread_queue.bd_res[i].queue->dev_path, + PATH_STR_SIZE, options->device); + if (ret < 0) { + WD_ERR("failed to copy dev file path!\n"); + return -WD_EINVAL; + } + }
ret = wd_request_queue(g_thread_queue.bd_res[i].queue); if (ret) {
From: Yang Shen shenyang39@huawei.com
Add a parameter 'device' to designate a device. The input should use the device name from '/sys/class/uacce/<name>'. Only full matching device names are supported.
Signed-off-by: Yang Shen shenyang39@huawei.com --- uadk_tool/benchmark/hpre_uadk_benchmark.c | 86 ++++++++++++++------- uadk_tool/benchmark/sec_uadk_benchmark.c | 86 ++++++++++++++------- uadk_tool/benchmark/uadk_benchmark.c | 64 ++++++++------- uadk_tool/benchmark/uadk_benchmark.h | 36 +++++---- uadk_tool/benchmark/zip_uadk_benchmark.c | 94 ++++++++++++++++------- 5 files changed, 237 insertions(+), 129 deletions(-)
diff --git a/uadk_tool/benchmark/hpre_uadk_benchmark.c b/uadk_tool/benchmark/hpre_uadk_benchmark.c index 0cbbdf2..729728f 100644 --- a/uadk_tool/benchmark/hpre_uadk_benchmark.c +++ b/uadk_tool/benchmark/hpre_uadk_benchmark.c @@ -346,43 +346,66 @@ static int hpre_uadk_param_parse(thread_data *tddata, struct acc_option *options
static int init_hpre_ctx_config(struct acc_option *options) { + struct uacce_dev_list *list, *tmp; int subtype = options->subtype; char *alg = options->algclass; int mode = options->syncmode; + struct uacce_dev *dev = NULL; struct sched_params param; - struct uacce_dev *dev; - int max_node; + int max_node, i; + char *dev_name; int ret = 0; - int i = 0;
max_node = numa_max_node() + 1; if (max_node <= 0) return -EINVAL;
- memset(&g_ctx_cfg, 0, sizeof(struct wd_ctx_config)); - g_ctx_cfg.ctx_num = g_ctxnum; - g_ctx_cfg.ctxs = calloc(g_ctxnum, sizeof(struct wd_ctx)); - if (!g_ctx_cfg.ctxs) - return -ENOMEM; + list = wd_get_accel_list(alg); + if (!list) { + HPRE_TST_PRT("failed to get %s device\n", alg); + return -ENODEV; + }
- while (i < g_ctxnum) { - dev = wd_get_accel_dev(alg); - if (!dev) { - HPRE_TST_PRT("failed to get %s device\n", alg); - ret = -EINVAL; - goto out; + if (strlen(options->device) == 0) { + dev = list->dev; + } else { + for (tmp = list; tmp; tmp = tmp->next) { + dev_name = strrchr(tmp->dev->dev_root, '/') + 1; + if (!strcmp(dev_name, options->device)) { + dev = tmp->dev; + break; + } } + }
- for (; i < g_ctxnum; i++) { - g_ctx_cfg.ctxs[i].ctx = wd_request_ctx(dev); - if (!g_ctx_cfg.ctxs[i].ctx) - break; + if (dev == NULL) { + HPRE_TST_PRT("failed to find device %s\n", options->device); + ret = -ENODEV; + goto free_list; + } + + /* If there is no numa, we defualt config to zero */ + if (dev->numa_id < 0) + dev->numa_id = 0;
- g_ctx_cfg.ctxs[i].op_type = 0; // default op_type - g_ctx_cfg.ctxs[i].ctx_mode = (__u8)mode; + memset(&g_ctx_cfg, 0, sizeof(struct wd_ctx_config)); + g_ctx_cfg.ctx_num = g_ctxnum; + g_ctx_cfg.ctxs = calloc(g_ctxnum, sizeof(struct wd_ctx)); + if (!g_ctx_cfg.ctxs) { + ret = -ENOMEM; + goto free_list; + } + + for (i = 0; i < g_ctxnum; i++) { + g_ctx_cfg.ctxs[i].ctx = wd_request_ctx(dev); + if (!g_ctx_cfg.ctxs[i].ctx) { + HPRE_TST_PRT("failed to alloc %dth ctx\n", i); + ret = -ENODEV; + goto free_ctx; }
- free(dev); + g_ctx_cfg.ctxs[i].op_type = 0; + g_ctx_cfg.ctxs[i].ctx_mode = (__u8)mode; }
switch(subtype) { @@ -401,11 +424,11 @@ static int init_hpre_ctx_config(struct acc_option *options) break; default: HPRE_TST_PRT("failed to parse alg subtype!\n"); - return -EINVAL; + goto free_ctx; } if (!g_sched) { HPRE_TST_PRT("failed to alloc sched!\n"); - goto out; + goto free_ctx; }
g_sched->name = SCHED_SINGLE; @@ -417,7 +440,7 @@ static int init_hpre_ctx_config(struct acc_option *options) ret = wd_sched_rr_instance(g_sched, ¶m); if (ret) { HPRE_TST_PRT("failed to fill hpre sched data!\n"); - goto out; + goto free_sched; }
/* init */ @@ -438,17 +461,22 @@ static int init_hpre_ctx_config(struct acc_option *options) } if (ret) { HPRE_TST_PRT("failed to get hpre ctx!\n"); - goto out; + goto free_sched; }
return 0; -out: - for (i = i - 1; i >= 0; i--) - wd_release_ctx(g_ctx_cfg.ctxs[i].ctx);
- free(g_ctx_cfg.ctxs); +free_sched: wd_sched_rr_release(g_sched);
+free_ctx: + for (; i >= 0; i--) + wd_release_ctx(g_ctx_cfg.ctxs[i].ctx); + free(g_ctx_cfg.ctxs); + +free_list: + wd_free_list_accels(list); + return ret; }
diff --git a/uadk_tool/benchmark/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c index 92e967a..105fb1a 100644 --- a/uadk_tool/benchmark/sec_uadk_benchmark.c +++ b/uadk_tool/benchmark/sec_uadk_benchmark.c @@ -516,42 +516,66 @@ static int sec_uadk_param_parse(thread_data *tddata, struct acc_option *options)
static int init_ctx_config(struct acc_option *options) { + struct uacce_dev_list *list, *tmp; struct sched_params param = {0}; - struct uacce_dev *dev = NULL; - char *alg = options->algclass; int subtype = options->subtype; + char *alg = options->algclass; int mode = options->syncmode; - int max_node = 0; + struct uacce_dev *dev = NULL; + int max_node, i; + char *dev_name; int ret = 0; - int i = 0;
max_node = numa_max_node() + 1; if (max_node <= 0) return -EINVAL;
- memset(&g_ctx_cfg, 0, sizeof(struct wd_ctx_config)); - g_ctx_cfg.ctx_num = g_ctxnum; - g_ctx_cfg.ctxs = calloc(g_ctxnum, sizeof(struct wd_ctx)); - if (!g_ctx_cfg.ctxs) - return -ENOMEM; + list = wd_get_accel_list(alg); + if (!list) { + SEC_TST_PRT("failed to get %s device\n", alg); + return -ENODEV; + }
- while (i < g_ctxnum) { - dev = wd_get_accel_dev(alg); - if (!dev) { - SEC_TST_PRT("failed to get %s device\n", alg); - goto out; + if (strlen(options->device) == 0) { + dev = list->dev; + } else { + for (tmp = list; tmp; tmp = tmp->next) { + dev_name = strrchr(tmp->dev->dev_root, '/') + 1; + if (!strcmp(dev_name, options->device)) { + dev = tmp->dev; + break; + } } + }
- for (; i < g_ctxnum; i++) { - g_ctx_cfg.ctxs[i].ctx = wd_request_ctx(dev); - if (!g_ctx_cfg.ctxs[i].ctx) - break; + if (dev == NULL) { + SEC_TST_PRT("failed to find device %s\n", options->device); + ret = -ENODEV; + goto free_list; + } + + /* If there is no numa, we defualt config to zero */ + if (dev->numa_id < 0) + dev->numa_id = 0; + + memset(&g_ctx_cfg, 0, sizeof(struct wd_ctx_config)); + g_ctx_cfg.ctx_num = g_ctxnum; + g_ctx_cfg.ctxs = calloc(g_ctxnum, sizeof(struct wd_ctx)); + if (!g_ctx_cfg.ctxs) { + ret = -ENOMEM; + goto free_list; + }
- g_ctx_cfg.ctxs[i].op_type = 0; // default op_type - g_ctx_cfg.ctxs[i].ctx_mode = (__u8)mode; + for (i = 0; i < g_ctxnum; i++) { + g_ctx_cfg.ctxs[i].ctx = wd_request_ctx(dev); + if (!g_ctx_cfg.ctxs[i].ctx) { + SEC_TST_PRT("failed to alloc %dth ctx\n", i); + ret = -ENOMEM; + goto free_ctx; }
- free(dev); + g_ctx_cfg.ctxs[i].op_type = 0; + g_ctx_cfg.ctxs[i].ctx_mode = (__u8)mode; }
switch(subtype) { @@ -566,11 +590,11 @@ static int init_ctx_config(struct acc_option *options) break; default: SEC_TST_PRT("failed to parse alg subtype!\n"); - return -EINVAL; + goto free_ctx; } if (!g_sched) { SEC_TST_PRT("failed to alloc sched!\n"); - goto out; + goto free_ctx; }
g_sched->name = SCHED_SINGLE; @@ -582,7 +606,7 @@ static int init_ctx_config(struct acc_option *options) ret = wd_sched_rr_instance(g_sched, ¶m); if (ret) { SEC_TST_PRT("failed to fill sched data!\n"); - goto out; + goto free_sched; }
/* init */ @@ -599,17 +623,21 @@ static int init_ctx_config(struct acc_option *options) } if (ret) { SEC_TST_PRT("failed to cipher ctx!\n"); - goto out; + goto free_sched; }
return 0;
-out: - for (i--; i >= 0; i--) - wd_release_ctx(g_ctx_cfg.ctxs[i].ctx); +free_sched: + wd_sched_rr_release(g_sched);
+free_ctx: + for (; i >= 0; i--) + wd_release_ctx(g_ctx_cfg.ctxs[i].ctx); free(g_ctx_cfg.ctxs); - wd_sched_rr_release(g_sched); + +free_list: + wd_free_list_accels(list);
return ret; } diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c index 0ebbb68..5dbe26a 100644 --- a/uadk_tool/benchmark/uadk_benchmark.c +++ b/uadk_tool/benchmark/uadk_benchmark.c @@ -491,6 +491,7 @@ static void parse_alg_param(struct acc_option *option) void cal_perfermance_data(struct acc_option *option, u32 sttime) { u8 palgname[MAX_ALG_NAME]; + char *unit = "KiB/s"; double perfermance; double cpu_rate; u32 ttime = 1000; @@ -506,8 +507,8 @@ void cal_perfermance_data(struct acc_option *option, u32 sttime) if (option->syncmode == SYNC_MODE) { if (get_recv_time() == option->threads) break; - } else { // ASYNC_MODE - if (get_recv_time() == 1) // poll complete + } else { + if (get_recv_time() == 1) break; } usleep(1000); @@ -525,14 +526,17 @@ void cal_perfermance_data(struct acc_option *option, u32 sttime) palgname[i] = '\0';
ptime = ptime - sttime; + cpu_rate = (double)ptime / option->times; + perfdata = g_recv_data.pkg_len * g_recv_data.recv_cnt / 1024.0; - perfops = (double)(g_recv_data.recv_cnt) / 1000.0; perfermance = perfdata / option->times; + + perfops = g_recv_data.recv_cnt / 1000.0; ops = perfops / option->times; - cpu_rate = (double)ptime / option->times; - ACC_TST_PRT("algname: length: perf: iops: CPU_rate:\n" - "%s %-2uBytes %.1fKB/s %.1fKops %.2f%%\n", - palgname, option->pktlen, perfermance, ops, cpu_rate); + + ACC_TST_PRT("algname:\tlength:\t\tperf:\t\tiops:\t\tCPU_rate:\n" + "%s\t%-2uBytes \t%.2f%s\t%.1fKops \t%.2f%%\n", + palgname, option->pktlen, perfermance, unit, ops, cpu_rate); }
static int benchmark_run(struct acc_option *option) @@ -744,24 +748,25 @@ int acc_cmd_parse(int argc, char *argv[], struct acc_option *option) int c;
static struct option long_options[] = { - {"help", no_argument, 0, 0}, - {"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}, - {"winsize", required_argument, 0, 15}, - {"complevel", required_argument, 0, 16}, - {"init2", no_argument, 0, 17}, + {"help", no_argument, 0, 0}, + {"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}, + {"winsize", required_argument, 0, 15}, + {"complevel", required_argument, 0, 16}, + {"init2", no_argument, 0, 17}, + {"device", required_argument, 0, 18}, {0, 0, 0, 0} };
@@ -826,8 +831,15 @@ int acc_cmd_parse(int argc, char *argv[], struct acc_option *option) case 17: option->inittype = INIT2_TYPE; break; + case 18: + if (strlen(optarg) >= MAX_DEVICE_NAME) { + ACC_TST_PRT("invalid: device name is %s\n", optarg); + goto to_exit; + } + strcpy(option->device, optarg); + break; default: - ACC_TST_PRT("bad input test parameter!\n"); + ACC_TST_PRT("invalid: bad input parameter!\n"); print_help(); goto to_exit; } diff --git a/uadk_tool/benchmark/uadk_benchmark.h b/uadk_tool/benchmark/uadk_benchmark.h index 1752948..fd3ebe5 100644 --- a/uadk_tool/benchmark/uadk_benchmark.h +++ b/uadk_tool/benchmark/uadk_benchmark.h @@ -6,27 +6,28 @@ #include <errno.h> #include <fcntl.h> #include <getopt.h> +#include <linux/random.h> #include <pthread.h> -#include <unistd.h> #include <stdbool.h> +#include <string.h> #include <stdio.h> #include <stdlib.h> -#include <string.h> #include <signal.h> -#include <linux/random.h> #include <sys/syscall.h> #include <sys/time.h> +#include <unistd.h>
-#define ACC_TST_PRT printf -#define PROCESS_NUM 32 -#define THREADS_NUM 64 -#define MAX_CTX_NUM 64 +#define ACC_TST_PRT printf +#define PROCESS_NUM 32 +#define THREADS_NUM 64 +#define MAX_CTX_NUM 64 #define MAX_TIME_SECONDS 128 -#define BYTES_TO_MB 20 -#define MAX_OPT_TYPE 6 -#define MAX_DATA_SIZE (15 * 1024 * 1024) -#define MAX_ALG_NAME 64 -#define ACC_QUEUE_SIZE 1024 +#define BYTES_TO_MB 20 +#define MAX_OPT_TYPE 6 +#define MAX_DATA_SIZE (15 * 1024 * 1024) +#define MAX_ALG_NAME 64 +#define ACC_QUEUE_SIZE 1024 +#define MAX_DEVICE_NAME 64
#define MAX_BLOCK_NM 16384 /* BLOCK_NUM must 4 times of POOL_LENTH */ #define MAX_POOL_LENTH 4096 @@ -35,15 +36,15 @@ #define SEC_2_USEC 1000000 #define HASH_ZISE 16
+#define SCHED_SINGLE "sched_single" +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#define gettid() syscall(__NR_gettid) + typedef unsigned long long u64; typedef unsigned int u32; 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. * @algclass: 0:cipher 1:digest @@ -55,9 +56,10 @@ typedef unsigned char u8; * @latency: test packet running time */ struct acc_option { - char algname[64]; + char algname[MAX_ALG_NAME]; char algclass[64]; char engine[64]; + char device[MAX_DEVICE_NAME]; u32 algtype; u32 modetype; u32 optype; diff --git a/uadk_tool/benchmark/zip_uadk_benchmark.c b/uadk_tool/benchmark/zip_uadk_benchmark.c index 9681c22..63fbdab 100644 --- a/uadk_tool/benchmark/zip_uadk_benchmark.c +++ b/uadk_tool/benchmark/zip_uadk_benchmark.c @@ -16,6 +16,7 @@ #define MAX_POOL_LENTH_COMP 1 #define COMPRESSION_RATIO_FACTOR 0.7 #define CHUNK_SIZE (128 * 1024) + struct uadk_bd { u8 *src; u8 *dst; @@ -61,6 +62,7 @@ struct zip_file_head {
static struct wd_ctx_config g_ctx_cfg; static struct wd_sched *g_sched; +static struct sched_params param; static unsigned int g_thread_num; static unsigned int g_ctxnum; static unsigned int g_pktlen; @@ -240,7 +242,7 @@ static int zip_uadk_param_parse(thread_data *tddata, struct acc_option *options) u8 alg;
if (optype >= WD_DIR_MAX << 1) { - ZIP_TST_PRT("Fail to get zip optype!\n"); + ZIP_TST_PRT("failed to get zip optype!\n"); return -EINVAL; } else if (optype >= WD_DIR_MAX) { mode = STREAM_MODE; @@ -265,7 +267,7 @@ static int zip_uadk_param_parse(thread_data *tddata, struct acc_option *options) optype = WD_DIR_COMPRESS; break; default: - ZIP_TST_PRT("Fail to set zip alg\n"); + ZIP_TST_PRT("failed to set zip alg\n"); return -EINVAL; }
@@ -298,21 +300,22 @@ static int init_ctx_config2(struct acc_option *options) /* init */ ret = wd_comp_init2(alg_name, SCHED_POLICY_RR, TASK_HW); if (ret) { - ZIP_TST_PRT("Fail to do comp init2!\n"); + ZIP_TST_PRT("failed to do comp init2!\n"); return ret; }
return 0; }
-static struct sched_params param; static int init_ctx_config(struct acc_option *options) { - struct uacce_dev_list *list; + struct uacce_dev_list *list, *tmp; char *alg = options->algclass; int optype = options->optype; int mode = options->syncmode; - int i, max_node; + struct uacce_dev *dev = NULL; + int max_node, i; + char *dev_name; int ret = 0;
optype = optype % WD_DIR_MAX; @@ -322,61 +325,96 @@ static int init_ctx_config(struct acc_option *options)
list = wd_get_accel_list(alg); if (!list) { - ZIP_TST_PRT("Fail to get %s device\n", alg); + ZIP_TST_PRT("failed to get %s device\n", alg); return -ENODEV; } - memset(&g_ctx_cfg, 0, sizeof(struct wd_ctx_config)); - g_ctx_cfg.ctx_num = g_ctxnum; - g_ctx_cfg.ctxs = calloc(g_ctxnum, sizeof(struct wd_ctx)); - if (!g_ctx_cfg.ctxs) - return -ENOMEM;
- g_sched = wd_sched_rr_alloc(SCHED_POLICY_RR, 2, max_node, wd_comp_poll_ctx); - if (!g_sched) { - ZIP_TST_PRT("Fail to alloc sched!\n"); - goto out; + if (strlen(options->device) == 0) { + dev = list->dev; + } else { + for (tmp = list; tmp; tmp = tmp->next) { + dev_name = strrchr(tmp->dev->dev_root, '/') + 1; + if (!strcmp(dev_name, options->device)) { + dev = tmp->dev; + break; + } + } + } + + if (dev == NULL) { + ZIP_TST_PRT("failed to find device %s\n", options->device); + ret = -ENODEV; + goto free_list; }
/* If there is no numa, we defualt config to zero */ - if (list->dev->numa_id < 0) - list->dev->numa_id = 0; + if (dev->numa_id < 0) + dev->numa_id = 0; + + memset(&g_ctx_cfg, 0, sizeof(struct wd_ctx_config)); + g_ctx_cfg.ctx_num = g_ctxnum; + g_ctx_cfg.ctxs = calloc(g_ctxnum, sizeof(struct wd_ctx)); + if (!g_ctx_cfg.ctxs) { + ret = -ENOMEM; + goto free_list; + }
for (i = 0; i < g_ctxnum; i++) { - g_ctx_cfg.ctxs[i].ctx = wd_request_ctx(list->dev); - g_ctx_cfg.ctxs[i].op_type = optype; // default op_type + g_ctx_cfg.ctxs[i].ctx = wd_request_ctx(dev); + if (!g_ctx_cfg.ctxs[i].ctx) { + ZIP_TST_PRT("failed to alloc %dth ctx\n", i); + goto free_ctx; + } + + g_ctx_cfg.ctxs[i].op_type = optype; g_ctx_cfg.ctxs[i].ctx_mode = (__u8)mode; } + + g_sched = wd_sched_rr_alloc(SCHED_POLICY_RR, 2, max_node, wd_comp_poll_ctx); + if (!g_sched) { + ZIP_TST_PRT("failed to alloc sched!\n"); + ret = -ENOMEM; + goto free_ctx; + } + g_sched->name = SCHED_SINGLE;
/* * All contexts for 2 modes & 2 types. * The test only uses one kind of contexts at the same time. */ - param.numa_id = list->dev->numa_id; + param.numa_id = dev->numa_id; param.type = optype; param.mode = mode; param.begin = 0; param.end = g_ctxnum - 1; ret = wd_sched_rr_instance(g_sched, ¶m); if (ret) { - ZIP_TST_PRT("Fail to fill sched data!\n"); - goto out; + ZIP_TST_PRT("failed to fill sched data!\n"); + goto free_sched; }
- /* init */ ret = wd_comp_init(&g_ctx_cfg, g_sched); if (ret) { - ZIP_TST_PRT("Fail to cipher ctx!\n"); - goto out; + ZIP_TST_PRT("failed to cipher ctx!\n"); + goto free_sched; }
wd_free_list_accels(list);
return 0; -out: - free(g_ctx_cfg.ctxs); + +free_sched: wd_sched_rr_release(g_sched);
+free_ctx: + for (; i >= 0; i--) + wd_release_ctx(g_ctx_cfg.ctxs[i].ctx); + free(g_ctx_cfg.ctxs); + +free_list: + wd_free_list_accels(list); + return ret; }
From: Zhiqi Song songzhiqi1@huawei.com
Support performance and function test for sm3-ce.
Signed-off-by: Zhiqi Song songzhiqi1@huawei.com --- uadk_tool/Makefile.am | 1 + uadk_tool/benchmark/sec_uadk_benchmark.c | 22 +++++++++++++-- uadk_tool/benchmark/uadk_benchmark.c | 29 ++++++++++++-------- uadk_tool/benchmark/uadk_benchmark.h | 1 + uadk_tool/test/test_sec.c | 35 +++++++++++++++++++++--- 5 files changed, 69 insertions(+), 19 deletions(-)
diff --git a/uadk_tool/Makefile.am b/uadk_tool/Makefile.am index 7f00087..6fa0d9d 100644 --- a/uadk_tool/Makefile.am +++ b/uadk_tool/Makefile.am @@ -29,6 +29,7 @@ uadk_tool_LDADD=$(libwd_la_OBJECTS) \ ../.libs/libhisi_sec.a \ ../.libs/libhisi_hpre.a \ ../.libs/libhisi_zip.a \ + ../.libs/libisa_ce.a \ -ldl -lnuma else uadk_tool_LDADD=-L../.libs -l:libwd.so.2 -l:libwd_crypto.so.2 \ diff --git a/uadk_tool/benchmark/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c index 105fb1a..c3da616 100644 --- a/uadk_tool/benchmark/sec_uadk_benchmark.c +++ b/uadk_tool/benchmark/sec_uadk_benchmark.c @@ -679,6 +679,7 @@ static void uninit_ctx_config2(int subtype) wd_aead_uninit2(); break; case DIGEST_TYPE: + case DIGEST_INSTR_TYPE: wd_digest_uninit2(); break; default: @@ -703,12 +704,23 @@ static int init_ctx_config2(struct acc_option *options) switch(subtype) { case CIPHER_TYPE: ret = wd_cipher_init2(alg_name, SCHED_POLICY_RR, TASK_HW); + if (ret) + SEC_TST_PRT("failed to do cipher init2!\n"); break; case AEAD_TYPE: ret = wd_aead_init2(alg_name, SCHED_POLICY_RR, TASK_HW); + if (ret) + SEC_TST_PRT("failed to do aead init2!\n"); break; case DIGEST_TYPE: ret = wd_digest_init2(alg_name, SCHED_POLICY_RR, TASK_HW); + if (ret) + SEC_TST_PRT("failed to do digest init2!\n"); + break; + case DIGEST_INSTR_TYPE: + ret = wd_digest_init2(alg_name, SCHED_POLICY_NONE, TASK_INSTR); + if (ret) + SEC_TST_PRT("failed to do digest intruction init2!\n"); break; } if (ret) { @@ -716,7 +728,7 @@ static int init_ctx_config2(struct acc_option *options) return ret; }
- return 0; + return ret; }
static void get_aead_data(u8 *addr, u32 size) @@ -1489,8 +1501,8 @@ static void *sec_uadk_digest_sync(void *arg) } } dreq.in_bytes = g_pktlen; - dreq.out_bytes = 16; - dreq.out_buf_bytes = 16; + dreq.out_bytes = 32; + dreq.out_buf_bytes = 32; dreq.data_fmt = 0; dreq.state = 0; dreq.has_next = 0; @@ -1536,8 +1548,12 @@ int sec_uadk_sync_threads(struct acc_option *options) uadk_sec_sync_run = sec_uadk_aead_sync; break; case DIGEST_TYPE: + case DIGEST_INSTR_TYPE: uadk_sec_sync_run = sec_uadk_digest_sync; break; + default: + SEC_TST_PRT("Invalid subtype!\n"); + return -EINVAL; }
for (i = 0; i < g_thread_num; i++) { diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c index 5dbe26a..9c025cf 100644 --- a/uadk_tool/benchmark/uadk_benchmark.c +++ b/uadk_tool/benchmark/uadk_benchmark.c @@ -37,6 +37,7 @@ enum test_type { SOFT_MODE = 0x4, SVA_SOFT = 0x5, NOSVA_SOFT = 0x6, + INSTR_MODE = 0x7, INVALID_MODE = 0x8, };
@@ -51,6 +52,7 @@ static struct acc_sva_item sys_name_item[] = { {"soft", SOFT_MODE}, {"sva-soft", SVA_SOFT}, {"nosva-soft", NOSVA_SOFT}, + {"instr", INSTR_MODE}, };
struct acc_alg_item { @@ -286,7 +288,7 @@ static int get_alg_type(const char *alg_name)
for (i = 0; i < ALG_MAX; i++) { if (strcmp(alg_name, alg_options[i].name) == 0) { - alg = alg_options[i].alg; + alg = alg_options[i].alg; break; } } @@ -482,8 +484,11 @@ static void parse_alg_param(struct acc_option *option) option->subtype = AEAD_TYPE; } else if (option->algtype <= SHA512_256) { snprintf(option->algclass, MAX_ALG_NAME, "%s", "digest"); + if (option->modetype == INSTR_MODE) + option->subtype = DIGEST_INSTR_TYPE; + else + option->subtype = DIGEST_TYPE; option->acctype = SEC_TYPE; - option->subtype = DIGEST_TYPE; } } } @@ -545,35 +550,35 @@ static int benchmark_run(struct acc_option *option)
switch(option->acctype) { case SEC_TYPE: - if (option->modetype & SVA_MODE) { + if ((option->modetype == SVA_MODE) || (option->modetype == INSTR_MODE)) { ret = sec_uadk_benchmark(option); - } else if (option->modetype & NOSVA_MODE) { + } else if (option->modetype == NOSVA_MODE) { ret = sec_wd_benchmark(option); } usleep(20000); #ifdef HAVE_CRYPTO - if (option->modetype & SOFT_MODE) { + if (option->modetype == SOFT_MODE) { ret = sec_soft_benchmark(option); } #endif break; case HPRE_TYPE: - if (option->modetype & SVA_MODE) { + if (option->modetype == SVA_MODE) { ret = hpre_uadk_benchmark(option); - } else if (option->modetype & NOSVA_MODE) { + } else if (option->modetype == NOSVA_MODE) { ret = hpre_wd_benchmark(option); } break; case ZIP_TYPE: - if (option->modetype & SVA_MODE) { + if (option->modetype == SVA_MODE) { ret = zip_uadk_benchmark(option); - } else if (option->modetype & NOSVA_MODE) { + } else if (option->modetype == NOSVA_MODE) { ret = zip_wd_benchmark(option); } case TRNG_TYPE: - if (option->modetype & SVA_MODE) + if (option->modetype == SVA_MODE) ACC_TST_PRT("TRNG not support sva mode..\n"); - else if (option->modetype & NOSVA_MODE) + else if (option->modetype == NOSVA_MODE) ret = trng_wd_benchmark(option);
break; @@ -698,7 +703,7 @@ static void print_help(void) ACC_TST_PRT("DESCRIPTION\n"); ACC_TST_PRT(" [--alg aes-128-cbc ]:\n"); ACC_TST_PRT(" The name of the algorithm for benchmarking\n"); - ACC_TST_PRT(" [--mode sva/nosva/soft/sva-soft/nosva-soft]: start UADK or Warpdrive or Openssl mode test\n"); + ACC_TST_PRT(" [--mode sva/nosva/soft/sva-soft/nosva-soft/instr]: start UADK or Warpdrive or Openssl or Instruction mode test\n"); ACC_TST_PRT(" [--sync/--async]: start asynchronous/synchronous mode test\n"); ACC_TST_PRT(" [--opt 0,1,2,3,4,5]:\n"); ACC_TST_PRT(" SEC/ZIP: 0/1:encryption/decryption or compression/decompression\n"); diff --git a/uadk_tool/benchmark/uadk_benchmark.h b/uadk_tool/benchmark/uadk_benchmark.h index fd3ebe5..e370d3e 100644 --- a/uadk_tool/benchmark/uadk_benchmark.h +++ b/uadk_tool/benchmark/uadk_benchmark.h @@ -104,6 +104,7 @@ enum alg_type { SM2_TYPE, X25519_TYPE, X448_TYPE, + DIGEST_INSTR_TYPE, };
enum sync_type { diff --git a/uadk_tool/test/test_sec.c b/uadk_tool/test/test_sec.c index 16feaf0..87fc718 100644 --- a/uadk_tool/test/test_sec.c +++ b/uadk_tool/test/test_sec.c @@ -32,7 +32,7 @@ #define SCHED_SINGLE "sched_single" #define SCHED_NULL_CTX_SIZE 4 #define TEST_WORD_LEN 4096 -#define MAX_ALGO_PER_TYPE 16 +#define MAX_ALGO_PER_TYPE 17 #define MIN_SVA_BD_NUM 1 #define AES_KEYSIZE_128 16 #define AES_KEYSIZE_192 24 @@ -83,6 +83,8 @@ enum digest_type { LOCAL_AES_GMAC_192, LOCAL_AES_GMAC_256, LOCAL_AES_XCBC_MAC_96, + LOCAL_AES_XCBC_PRF_128, + LOCAL_AES_CCM, };
char *digest_names[MAX_ALGO_PER_TYPE] = { @@ -102,6 +104,7 @@ char *digest_names[MAX_ALGO_PER_TYPE] = { "xcbc-mac-96(aes)", "xcbc-prf-128(aes)", "ccm(aes)", /* --digest 15: for error alg test */ + "sm3-ce", };
char *aead_names[MAX_ALGO_PER_TYPE] = { @@ -1464,11 +1467,14 @@ static int digest_init2(int type, int mode) { struct wd_ctx_params cparams = {0}; struct wd_ctx_nums *ctx_set_num; + char *alg_name; int ret;
if (g_testalg >= MAX_ALGO_PER_TYPE) return -WD_EINVAL;
+ alg_name = digest_names[g_testalg]; + ctx_set_num = calloc(1, sizeof(*ctx_set_num)); if (!ctx_set_num) { WD_ERR("failed to alloc ctx_set_size!\n"); @@ -1492,7 +1498,10 @@ static int digest_init2(int type, int mode) if (mode == CTX_MODE_ASYNC) ctx_set_num->async_ctx_num = g_ctxnum;
- ret = wd_digest_init2_(digest_names[g_testalg], 0, 0, &cparams); + if (!strcmp(alg_name, "sm3-ce")) + ret = wd_digest_init2("sm3", SCHED_POLICY_NONE, TASK_INSTR); + else + ret = wd_digest_init2_(digest_names[g_testalg], 0, 0, &cparams); if (ret) goto out_freebmp;
@@ -1780,7 +1789,22 @@ int get_digest_resource(struct hash_testvec **alg_tv, int* alg, int* mode) tv->dsize = 16; alg_type = WD_DIGEST_AES_XCBC_PRF_128; break; - + case 16: /* SM3-CE */ + switch (g_alg_op_type) { + case 0: + mode_type = WD_DIGEST_NORMAL; + SEC_TST_PRT("test alg: %s\n", "normal(sm3-ce)"); + tv = &sm3_tv_template[0]; + break; + case 1: + mode_type = WD_DIGEST_HMAC; + SEC_TST_PRT("test alg: %s\n", "hmac(sm3-ce)"); + tv = &hmac_sm3_tv_template[0]; + break; + } + tv->dsize = 32; + alg_type = WD_DIGEST_SM3; + break; default: SEC_TST_PRT("keylenth error, default test alg: %s\n", "normal(sm3)"); return -EINVAL; @@ -4229,7 +4253,7 @@ static void print_help(void) SEC_TST_PRT(" 4 : SHA224; 5 : SHA384; 6 : SHA512; 7 : SHA512_224\n"); SEC_TST_PRT(" 8 : SHA512_256; 9 : AES_CMAC; 10 : AES_GMAC_128\n"); SEC_TST_PRT(" 11 : AES_GMAC_192; 12 : AES_GMAC_256; 13 : AES_XCBC_MAC_96\n"); - SEC_TST_PRT(" 14 : AES_XCBC_PRF_128\n"); + SEC_TST_PRT(" 14 : AES_XCBC_PRF_128; 15 : SM3-CE\n"); SEC_TST_PRT(" [--aead ]:\n"); SEC_TST_PRT(" specify symmetric aead algorithm\n"); SEC_TST_PRT(" 0 : AES-CCM; 1 : AES-GCM; 2 : Hmac(sha256),cbc(aes)\n"); @@ -4257,6 +4281,9 @@ static void print_help(void) SEC_TST_PRT(" set the steam mode for digest\n"); SEC_TST_PRT(" [--sglnum]:\n"); SEC_TST_PRT(" the number of scatterlist number used by the entire test task\n"); + SEC_TST_PRT(" [--init]:\n"); + SEC_TST_PRT(" 1: use init API of uadk\n"); + SEC_TST_PRT(" 2: use init2 API of uadk\n"); SEC_TST_PRT(" [--help] = usage\n"); SEC_TST_PRT("Example\n"); SEC_TST_PRT(" ./uadk_tool test --m sec --cipher 0 --sync --optype 0\n");
Support performance test for sm4-ce. Add CBC-CS1、CBC-CS2 and CBC-CS3 mode for SM4 algorithm in benchmark tool.
Signed-off-by: Qi Tao taoqi10@huawei.com --- uadk_tool/benchmark/sec_uadk_benchmark.c | 25 ++++++++++++++++++++++++ uadk_tool/benchmark/sec_wd_benchmark.c | 18 +++++++++++++++++ uadk_tool/benchmark/uadk_benchmark.c | 11 ++++++++++- uadk_tool/benchmark/uadk_benchmark.h | 4 ++++ 4 files changed, 57 insertions(+), 1 deletion(-)
diff --git a/uadk_tool/benchmark/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c index c3da616..f8b19ba 100644 --- a/uadk_tool/benchmark/sec_uadk_benchmark.c +++ b/uadk_tool/benchmark/sec_uadk_benchmark.c @@ -346,6 +346,24 @@ static int sec_uadk_param_parse(thread_data *tddata, struct acc_option *options) mode = WD_CIPHER_CBC; alg = WD_CIPHER_SM4; break; + case SM4_128_CBC_CS1: + keysize = 16; + ivsize = 16; + mode = WD_CIPHER_CBC_CS1; + alg = WD_CIPHER_SM4; + break; + case SM4_128_CBC_CS2: + keysize = 16; + ivsize = 16; + mode = WD_CIPHER_CBC_CS2; + alg = WD_CIPHER_SM4; + break; + case SM4_128_CBC_CS3: + keysize = 16; + ivsize = 16; + mode = WD_CIPHER_CBC_CS3; + alg = WD_CIPHER_SM4; + break; case SM4_128_CTR: keysize = 16; ivsize = 16; @@ -673,6 +691,7 @@ static void uninit_ctx_config2(int subtype) /* uninit2 */ switch(subtype) { case CIPHER_TYPE: + case CIPHER_INSTR_TYPE: wd_cipher_uninit2(); break; case AEAD_TYPE: @@ -707,6 +726,11 @@ static int init_ctx_config2(struct acc_option *options) if (ret) SEC_TST_PRT("failed to do cipher init2!\n"); break; + case CIPHER_INSTR_TYPE: + ret = wd_cipher_init2(alg_name, SCHED_POLICY_NONE, TASK_INSTR); + if (ret) + SEC_TST_PRT("failed to do cipher intruction init2!\n"); + break; case AEAD_TYPE: ret = wd_aead_init2(alg_name, SCHED_POLICY_RR, TASK_HW); if (ret) @@ -1542,6 +1566,7 @@ int sec_uadk_sync_threads(struct acc_option *options)
switch (options->subtype) { case CIPHER_TYPE: + case CIPHER_INSTR_TYPE: uadk_sec_sync_run = sec_uadk_cipher_sync; break; case AEAD_TYPE: diff --git a/uadk_tool/benchmark/sec_wd_benchmark.c b/uadk_tool/benchmark/sec_wd_benchmark.c index 62efe9a..66e0112 100644 --- a/uadk_tool/benchmark/sec_wd_benchmark.c +++ b/uadk_tool/benchmark/sec_wd_benchmark.c @@ -412,6 +412,24 @@ static int sec_wd_param_parse(thread_data *tddata, struct acc_option *options) mode = WCRYPTO_CIPHER_CBC; alg = WCRYPTO_CIPHER_SM4; break; + case SM4_128_CBC_CS1: + keysize = 16; + ivsize = 16; + mode = WCRYPTO_CIPHER_CBC_CS1; + alg = WCRYPTO_CIPHER_SM4; + break; + case SM4_128_CBC_CS2: + keysize = 16; + ivsize = 16; + mode = WCRYPTO_CIPHER_CBC_CS2; + alg = WCRYPTO_CIPHER_SM4; + break; + case SM4_128_CBC_CS3: + keysize = 16; + ivsize = 16; + mode = WCRYPTO_CIPHER_CBC_CS3; + alg = WCRYPTO_CIPHER_SM4; + break; case SM4_128_CTR: keysize = 16; ivsize = 16; diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c index 9c025cf..f9bb69c 100644 --- a/uadk_tool/benchmark/uadk_benchmark.c +++ b/uadk_tool/benchmark/uadk_benchmark.c @@ -120,6 +120,9 @@ static struct acc_alg_item alg_options[] = { {"3des-192-cbc", DES3_192_CBC}, {"sm4-128-ecb", SM4_128_ECB}, {"sm4-128-cbc", SM4_128_CBC}, + {"sm4-128-cbc-cs1", SM4_128_CBC_CS1}, + {"sm4-128-cbc-cs2", SM4_128_CBC_CS2}, + {"sm4-128-cbc-cs3", SM4_128_CBC_CS3}, {"sm4-128-ctr", SM4_128_CTR}, {"sm4-128-ofb", SM4_128_OFB}, {"sm4-128-cfb", SM4_128_CFB}, @@ -209,6 +212,9 @@ static struct acc_alg_item alg_name_options[] = { {"cbc(des3_ede)", DES3_192_CBC}, {"ecb(sm4)", SM4_128_ECB}, {"cbc(sm4)", SM4_128_CBC}, + {"cbc-cs1(sm4)", SM4_128_CBC_CS1}, + {"cbc-cs2(sm4)", SM4_128_CBC_CS2}, + {"cbc-cs3(sm4)", SM4_128_CBC_CS3}, {"ctr(sm4)", SM4_128_CTR}, {"ofb(sm4)", SM4_128_OFB}, {"cfb(sm4)", SM4_128_CFB}, @@ -476,8 +482,11 @@ static void parse_alg_param(struct acc_option *option) option->subtype = ECDSA_TYPE; } else if (option->algtype <= SM4_128_XTS_GB) { snprintf(option->algclass, MAX_ALG_NAME, "%s", "cipher"); + if (option->modetype == INSTR_MODE) + option->subtype = CIPHER_INSTR_TYPE; + else + option->subtype = CIPHER_TYPE; option->acctype = SEC_TYPE; - option->subtype = CIPHER_TYPE; } else if (option->algtype <= SM4_128_GCM) { snprintf(option->algclass, MAX_ALG_NAME, "%s", "aead"); option->acctype = SEC_TYPE; diff --git a/uadk_tool/benchmark/uadk_benchmark.h b/uadk_tool/benchmark/uadk_benchmark.h index e370d3e..ea8e437 100644 --- a/uadk_tool/benchmark/uadk_benchmark.h +++ b/uadk_tool/benchmark/uadk_benchmark.h @@ -105,6 +105,7 @@ enum alg_type { X25519_TYPE, X448_TYPE, DIGEST_INSTR_TYPE, + CIPHER_INSTR_TYPE, };
enum sync_type { @@ -172,6 +173,9 @@ enum test_alg { DES3_192_CBC, SM4_128_ECB, SM4_128_CBC, + SM4_128_CBC_CS1, + SM4_128_CBC_CS2, + SM4_128_CBC_CS3, SM4_128_CTR, SM4_128_OFB, SM4_128_CFB,
From: Weili Qian qianweili@huawei.com
Support sm3/md5 multibuff benchmark test/
Signed-off-by: Weili Qian qianweili@huawei.com --- uadk_tool/benchmark/sec_uadk_benchmark.c | 31 +++++++++++++++--------- uadk_tool/benchmark/uadk_benchmark.c | 26 ++++++++++++++------ uadk_tool/benchmark/uadk_benchmark.h | 3 ++- 3 files changed, 40 insertions(+), 20 deletions(-)
diff --git a/uadk_tool/benchmark/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c index f8b19ba..2c12c20 100644 --- a/uadk_tool/benchmark/sec_uadk_benchmark.c +++ b/uadk_tool/benchmark/sec_uadk_benchmark.c @@ -53,6 +53,7 @@ typedef struct uadk_thread_res { bool is_union; u32 dalg; u32 dmode; + u32 d_outbytes; } thread_data;
static struct wd_ctx_config g_ctx_cfg; @@ -146,6 +147,7 @@ static int sec_uadk_param_parse(thread_data *tddata, struct acc_option *options) u32 algtype = options->algtype; u32 optype = options->optype; bool is_union = false; + u32 out_bytes = 32; u8 keysize = 0; u8 ivsize = 0; u8 dmode = 0; @@ -472,45 +474,54 @@ static int sec_uadk_param_parse(thread_data *tddata, struct acc_option *options) case SM3_ALG: // digest mode is optype keysize = 4; mode = optype; + out_bytes = 32; alg = WD_DIGEST_SM3; break; case MD5_ALG: keysize = 4; + out_bytes = 16; mode = optype; alg = WD_DIGEST_MD5; break; case SHA1_ALG: keysize = 4; + out_bytes = 20; mode = optype; alg = WD_DIGEST_SHA1; break; case SHA256_ALG: keysize = 4; + out_bytes = 32; mode = optype; alg = WD_DIGEST_SHA256; break; case SHA224_ALG: keysize = 4; + out_bytes = 28; mode = optype; alg = WD_DIGEST_SHA224; break; case SHA384_ALG: keysize = 4; + out_bytes = 48; mode = optype; alg = WD_DIGEST_SHA384; break; case SHA512_ALG: keysize = 4; + out_bytes = 64; mode = optype; alg = WD_DIGEST_SHA512; break; case SHA512_224: keysize = 4; + out_bytes = 28; mode = optype; alg = WD_DIGEST_SHA512_224; break; case SHA512_256: keysize = 4; + out_bytes = 32; mode = optype; alg = WD_DIGEST_SHA512_256; break; @@ -528,6 +539,7 @@ static int sec_uadk_param_parse(thread_data *tddata, struct acc_option *options) tddata->is_union = is_union; tddata->optype = options->optype; tddata->subtype = options->subtype; + tddata->d_outbytes = out_bytes;
return 0; } @@ -698,7 +710,6 @@ static void uninit_ctx_config2(int subtype) wd_aead_uninit2(); break; case DIGEST_TYPE: - case DIGEST_INSTR_TYPE: wd_digest_uninit2(); break; default: @@ -737,15 +748,10 @@ static int init_ctx_config2(struct acc_option *options) SEC_TST_PRT("failed to do aead init2!\n"); break; case DIGEST_TYPE: - ret = wd_digest_init2(alg_name, SCHED_POLICY_RR, TASK_HW); + ret = wd_digest_init2(alg_name, options->sched_type, options->task_type); if (ret) SEC_TST_PRT("failed to do digest init2!\n"); break; - case DIGEST_INSTR_TYPE: - ret = wd_digest_init2(alg_name, SCHED_POLICY_NONE, TASK_INSTR); - if (ret) - SEC_TST_PRT("failed to do digest intruction init2!\n"); - break; } if (ret) { SEC_TST_PRT("failed to do cipher init2!\n"); @@ -1305,8 +1311,8 @@ static void *sec_uadk_digest_async(void *arg) } } dreq.in_bytes = g_pktlen; - dreq.out_bytes = 16; - dreq.out_buf_bytes = 16; + dreq.out_bytes = pdata->d_outbytes; + dreq.out_buf_bytes = pdata->d_outbytes; dreq.data_fmt = 0; dreq.state = 0; dreq.has_next = 0; @@ -1525,8 +1531,8 @@ static void *sec_uadk_digest_sync(void *arg) } } dreq.in_bytes = g_pktlen; - dreq.out_bytes = 32; - dreq.out_buf_bytes = 32; + dreq.out_bytes = pdata->d_outbytes; + dreq.out_buf_bytes = pdata->d_outbytes; dreq.data_fmt = 0; dreq.state = 0; dreq.has_next = 0; @@ -1573,7 +1579,6 @@ int sec_uadk_sync_threads(struct acc_option *options) uadk_sec_sync_run = sec_uadk_aead_sync; break; case DIGEST_TYPE: - case DIGEST_INSTR_TYPE: uadk_sec_sync_run = sec_uadk_digest_sync; break; default: @@ -1591,6 +1596,7 @@ int sec_uadk_sync_threads(struct acc_option *options) threads_args[i].ivsize = threads_option.ivsize; threads_args[i].optype = threads_option.optype; threads_args[i].td_id = i; + threads_args[i].d_outbytes = threads_option.d_outbytes; ret = pthread_create(&tdid[i], NULL, uadk_sec_sync_run, &threads_args[i]); if (ret) { SEC_TST_PRT("Create sync thread fail!\n"); @@ -1662,6 +1668,7 @@ int sec_uadk_async_threads(struct acc_option *options) threads_args[i].ivsize = threads_option.ivsize; threads_args[i].optype = threads_option.optype; threads_args[i].td_id = i; + threads_args[i].d_outbytes = threads_option.d_outbytes; ret = pthread_create(&tdid[i], NULL, uadk_sec_async_run, &threads_args[i]); if (ret) { SEC_TST_PRT("Create async thread fail!\n"); diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c index f9bb69c..c1accc6 100644 --- a/uadk_tool/benchmark/uadk_benchmark.c +++ b/uadk_tool/benchmark/uadk_benchmark.c @@ -2,6 +2,8 @@
#include <sys/types.h> #include <sys/wait.h> +#include "include/wd_alg_common.h" +#include "include/wd_sched.h"
#include "uadk_benchmark.h" #include "sec_uadk_benchmark.h" @@ -38,7 +40,8 @@ enum test_type { SVA_SOFT = 0x5, NOSVA_SOFT = 0x6, INSTR_MODE = 0x7, - INVALID_MODE = 0x8, + MULTIBUF_MODE = 0x8, + INVALID_MODE = 0x9, };
struct acc_sva_item { @@ -53,6 +56,7 @@ static struct acc_sva_item sys_name_item[] = { {"sva-soft", SVA_SOFT}, {"nosva-soft", NOSVA_SOFT}, {"instr", INSTR_MODE}, + {"multibuff", MULTIBUF_MODE}, };
struct acc_alg_item { @@ -493,11 +497,15 @@ static void parse_alg_param(struct acc_option *option) option->subtype = AEAD_TYPE; } else if (option->algtype <= SHA512_256) { snprintf(option->algclass, MAX_ALG_NAME, "%s", "digest"); - if (option->modetype == INSTR_MODE) - option->subtype = DIGEST_INSTR_TYPE; - else - option->subtype = DIGEST_TYPE; + option->subtype = DIGEST_TYPE; option->acctype = SEC_TYPE; + if (option->modetype == INSTR_MODE) { + option->sched_type = SCHED_POLICY_NONE; + option->task_type = TASK_INSTR; + } else if (option->modetype == MULTIBUF_MODE) { + option->sched_type = SCHED_POLICY_SINGLE; + option->task_type = TASK_INSTR; + } } } } @@ -559,7 +567,9 @@ static int benchmark_run(struct acc_option *option)
switch(option->acctype) { case SEC_TYPE: - if ((option->modetype == SVA_MODE) || (option->modetype == INSTR_MODE)) { + if ((option->modetype == SVA_MODE) || + (option->modetype == INSTR_MODE) || + (option->modetype == MULTIBUF_MODE)) { ret = sec_uadk_benchmark(option); } else if (option->modetype == NOSVA_MODE) { ret = sec_wd_benchmark(option); @@ -623,6 +633,8 @@ int acc_benchmark_run(struct acc_option *option) int i, ret = 0; int status;
+ option->sched_type = SCHED_POLICY_RR; + option->task_type = TASK_HW; parse_alg_param(option); dump_param(option); g_run_options = option; @@ -712,7 +724,7 @@ static void print_help(void) ACC_TST_PRT("DESCRIPTION\n"); ACC_TST_PRT(" [--alg aes-128-cbc ]:\n"); ACC_TST_PRT(" The name of the algorithm for benchmarking\n"); - ACC_TST_PRT(" [--mode sva/nosva/soft/sva-soft/nosva-soft/instr]: start UADK or Warpdrive or Openssl or Instruction mode test\n"); + ACC_TST_PRT(" [--mode sva/nosva/soft/sva-soft/nosva-soft/instr/multibuff]: start UADK or Warpdrive or Openssl or Instruction mode test\n"); ACC_TST_PRT(" [--sync/--async]: start asynchronous/synchronous mode test\n"); ACC_TST_PRT(" [--opt 0,1,2,3,4,5]:\n"); ACC_TST_PRT(" SEC/ZIP: 0/1:encryption/decryption or compression/decompression\n"); diff --git a/uadk_tool/benchmark/uadk_benchmark.h b/uadk_tool/benchmark/uadk_benchmark.h index ea8e437..c493ac3 100644 --- a/uadk_tool/benchmark/uadk_benchmark.h +++ b/uadk_tool/benchmark/uadk_benchmark.h @@ -77,6 +77,8 @@ struct acc_option { u32 complevel; u32 inittype; bool latency; + u32 sched_type; + int task_type; };
enum acc_type { @@ -104,7 +106,6 @@ enum alg_type { SM2_TYPE, X25519_TYPE, X448_TYPE, - DIGEST_INSTR_TYPE, CIPHER_INSTR_TYPE, };
From: Chenghai Huang huangchenghai2@huawei.com
Ensure that all packets in the msg pool are removed before end. In V2, resources such as tags are released in a centralized manner to avoid errors caused by asynchronous resource release sequence. In V1, before the packet sending thread releases the tag, ensure that the poll thread has ended.
Signed-off-by: Chenghai Huang huangchenghai2@huawei.com --- uadk_tool/benchmark/zip_uadk_benchmark.c | 151 ++++++++++++----------- uadk_tool/benchmark/zip_wd_benchmark.c | 25 ++-- 2 files changed, 96 insertions(+), 80 deletions(-)
diff --git a/uadk_tool/benchmark/zip_uadk_benchmark.c b/uadk_tool/benchmark/zip_uadk_benchmark.c index 63fbdab..1dd3990 100644 --- a/uadk_tool/benchmark/zip_uadk_benchmark.c +++ b/uadk_tool/benchmark/zip_uadk_benchmark.c @@ -16,7 +16,7 @@ #define MAX_POOL_LENTH_COMP 1 #define COMPRESSION_RATIO_FACTOR 0.7 #define CHUNK_SIZE (128 * 1024) - +#define MAX_UNRECV_PACKET_NUM 2 struct uadk_bd { u8 *src; u8 *dst; @@ -37,11 +37,17 @@ enum ZIP_OP_MODE { STREAM_MODE };
+enum ZIP_THREAD_STATE { + THREAD_PROCESSING, + THREAD_COMPLETED +}; + struct zip_async_tag { handle_t sess; u32 td_id; u32 bd_idx; u32 cm_len; + u32 recv_cnt; ZSTD_CCtx *cctx; };
@@ -52,6 +58,10 @@ typedef struct uadk_thread_res { u32 td_id; u32 win_sz; u32 comp_lv; + u32 send_cnt; + struct zip_async_tag *tag; + COMP_TUPLE_TAG *ftuple; + char *hw_buff_out; } thread_data;
struct zip_file_head { @@ -67,6 +77,7 @@ static unsigned int g_thread_num; static unsigned int g_ctxnum; static unsigned int g_pktlen; static unsigned int g_prefetch; +static unsigned int g_state;
#ifndef ZLIB_FSE static ZSTD_CCtx* zstd_soft_fse_init(unsigned int level) @@ -541,6 +552,7 @@ static void *zip_lz77_async_cb(struct wd_comp_req *req, void *data) zstd_output.dst = uadk_pool->bds[idx].dst; zstd_output.size = tag->cm_len; zstd_output.pos = 0; + __atomic_add_fetch(&tag->recv_cnt, 1, __ATOMIC_RELAXED); fse_size = zstd_soft_fse(req->priv, &zstd_input, &zstd_output, cctx, ZSTD_e_end);
uadk_pool->bds[idx].dst_len = fse_size; @@ -554,6 +566,7 @@ static void *zip_async_cb(struct wd_comp_req *req, void *data) struct bd_pool *uadk_pool; int td_id = tag->td_id; int idx = tag->bd_idx; + __atomic_add_fetch(&tag->recv_cnt, 1, __ATOMIC_RELAXED);
uadk_pool = &g_zip_pool.pool[td_id]; uadk_pool->bds[idx].dst_len = req->dst_len; @@ -566,15 +579,14 @@ static void *zip_uadk_poll(void *data) 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; - int ret; + int ret;
if (id > g_ctxnum) return NULL;
- while (last_time) { + while (g_state == THREAD_PROCESSING) { ret = wd_comp_poll_ctx(id, expt, &recv); count += recv; recv = 0; @@ -582,9 +594,6 @@ static void *zip_uadk_poll(void *data) ZIP_TST_PRT("poll ret: %d!\n", ret); goto recv_error; } - - if (get_run_state() == 0) - last_time--; }
recv_error: @@ -596,12 +605,11 @@ recv_error: static void *zip_uadk_poll2(void *data) { u32 expt = ACC_QUEUE_SIZE * g_thread_num; - u32 last_time = 2; // poll need one more recv time u32 count = 0; u32 recv = 0; int ret;
- while (last_time) { + while (g_state == THREAD_PROCESSING) { ret = wd_comp_poll(expt, &recv); count += recv; recv = 0; @@ -609,9 +617,6 @@ static void *zip_uadk_poll2(void *data) ZIP_TST_PRT("poll ret: %d!\n", ret); goto recv_error; } - - if (get_run_state() == 0) - last_time--; }
recv_error: @@ -803,11 +808,8 @@ static void *zip_uadk_blk_lz77_async_run(void *arg) thread_data *pdata = (thread_data *)arg; struct wd_comp_sess_setup comp_setup = {0}; ZSTD_CCtx *cctx = zstd_soft_fse_init(15); - COMP_TUPLE_TAG *ftuple = NULL; struct bd_pool *uadk_pool; struct wd_comp_req creq; - struct zip_async_tag *tag; - char *hw_buff_out = NULL; handle_t h_sess; u32 out_len = 0; u32 count = 0; @@ -838,37 +840,22 @@ static void *zip_uadk_blk_lz77_async_run(void *arg) creq.data_fmt = 0; creq.status = 0;
- ftuple = malloc(sizeof(COMP_TUPLE_TAG) * MAX_POOL_LENTH_COMP); - if (!ftuple) - goto fse_err; - - hw_buff_out = malloc(out_len * MAX_POOL_LENTH_COMP); - if (!hw_buff_out) - goto hw_buff_err; - memset(hw_buff_out, 0x0, out_len * MAX_POOL_LENTH_COMP); - - tag = malloc(sizeof(*tag) * MAX_POOL_LENTH_COMP); - if (!tag) { - ZIP_TST_PRT("failed to malloc zip tag!\n"); - goto tag_err; - } - while(1) { if (get_run_state() == 0) break;
i = count % MAX_POOL_LENTH_COMP; creq.src = uadk_pool->bds[i].src; - creq.dst = &hw_buff_out[i]; //temp out + creq.dst = &pdata->hw_buff_out[i]; //temp out creq.src_len = uadk_pool->bds[i].src_len; creq.dst_len = out_len; - creq.priv = &ftuple[i]; + creq.priv = &pdata->ftuple[i];
- tag[i].td_id = pdata->td_id; - tag[i].bd_idx = i; - tag[i].cm_len = out_len; - tag[i].cctx = cctx; - creq.cb_param = &tag[i]; + pdata->tag[i].td_id = pdata->td_id; + pdata->tag[i].bd_idx = i; + pdata->tag[i].cm_len = out_len; + pdata->tag[i].cctx = cctx; + creq.cb_param = &pdata->tag[i];
ret = wd_do_comp_async(h_sess, &creq); if (ret == -WD_EBUSY) { @@ -884,20 +871,8 @@ static void *zip_uadk_blk_lz77_async_run(void *arg) } try_cnt = 0; count++; + __atomic_add_fetch(&pdata->send_cnt, 1, __ATOMIC_RELAXED); } - - while (1) { - if (get_recv_time() > 0) // wait Async mode finish recv - break; - usleep(SEND_USLEEP); - } - -tag_err: - free(tag); -hw_buff_err: - free(hw_buff_out); -fse_err: - free(ftuple); wd_comp_free_sess(h_sess); add_send_complete();
@@ -1033,7 +1008,6 @@ static void *zip_uadk_blk_async_run(void *arg) thread_data *pdata = (thread_data *)arg; struct wd_comp_sess_setup comp_setup = {0}; struct bd_pool *uadk_pool; - struct zip_async_tag *tag; struct wd_comp_req creq; handle_t h_sess; int try_cnt = 0; @@ -1066,13 +1040,6 @@ static void *zip_uadk_blk_async_run(void *arg) creq.priv = 0; creq.status = 0;
- tag = malloc(sizeof(*tag) * MAX_POOL_LENTH_COMP); - if (!tag) { - ZIP_TST_PRT("failed to malloc zip tag!\n"); - wd_comp_free_sess(h_sess); - return NULL; - } - while(1) { if (get_run_state() == 0) break; @@ -1083,9 +1050,9 @@ static void *zip_uadk_blk_async_run(void *arg) creq.src_len = uadk_pool->bds[i].src_len; creq.dst_len = out_len;
- tag[i].td_id = pdata->td_id; - tag[i].bd_idx = i; - creq.cb_param = &tag[i]; + pdata->tag[i].td_id = pdata->td_id; + pdata->tag[i].bd_idx = i; + creq.cb_param = &pdata->tag[i];
ret = wd_do_comp_async(h_sess, &creq); if (ret == -WD_EBUSY) { @@ -1101,15 +1068,9 @@ static void *zip_uadk_blk_async_run(void *arg) } try_cnt = 0; count++; + __atomic_add_fetch(&pdata->send_cnt, 1, __ATOMIC_RELAXED); }
- while (1) { - if (get_recv_time() > 0) // wait Async mode finish recv - break; - usleep(SEND_USLEEP); - } - - free(tag); wd_comp_free_sess(h_sess);
add_send_complete(); @@ -1215,10 +1176,35 @@ static int zip_uadk_async_threads(struct acc_option *options) threads_args[i].win_sz = threads_option.win_sz; threads_args[i].comp_lv = threads_option.comp_lv; threads_args[i].td_id = i; + if (threads_option.alg == LZ77_ZSTD) { + struct bd_pool *uadk_pool = &g_zip_pool.pool[i]; + u32 out_len = uadk_pool->bds[0].dst_len; + + threads_args[i].ftuple = malloc(sizeof(COMP_TUPLE_TAG) * + MAX_POOL_LENTH_COMP); + if (!threads_args[i].ftuple) { + ZIP_TST_PRT("failed to malloc lz77 ftuple!\n"); + goto lz77_free; + } + + threads_args[i].hw_buff_out = malloc(out_len * MAX_POOL_LENTH_COMP); + if (!threads_args[i].hw_buff_out) { + ZIP_TST_PRT("failed to malloc lz77 hw_buff_out!\n"); + goto lz77_free; + } + memset(threads_args[i].hw_buff_out, 0x0, out_len * MAX_POOL_LENTH_COMP); + } + threads_args[i].tag = malloc(sizeof(struct zip_async_tag) * MAX_POOL_LENTH_COMP); + if (!threads_args[i].tag) { + ZIP_TST_PRT("failed to malloc zip tag!\n"); + goto tag_free; + } + threads_args[i].tag->recv_cnt = 0; + threads_args[i].send_cnt = 0; ret = pthread_create(&tdid[i], NULL, uadk_zip_async_run, &threads_args[i]); if (ret) { ZIP_TST_PRT("Create async thread fail!\n"); - goto async_error; + goto tag_free; } }
@@ -1227,18 +1213,41 @@ static int zip_uadk_async_threads(struct acc_option *options) ret = pthread_join(tdid[i], NULL); if (ret) { ZIP_TST_PRT("Join async thread fail!\n"); - goto async_error; + goto tag_free; } }
+ /* wait for the poll to clear packets */ + g_state = THREAD_PROCESSING; + for (i = 0; i < g_thread_num;) { + if (threads_args[i].send_cnt <= threads_args[i].tag->recv_cnt + MAX_UNRECV_PACKET_NUM) + i++; + } + g_state = THREAD_COMPLETED; // finish poll + for (i = 0; i < g_ctxnum; i++) { ret = pthread_join(pollid[i], NULL); if (ret) { ZIP_TST_PRT("Join poll thread fail!\n"); - goto async_error; + goto tag_free; } }
+tag_free: + for (i = 0; i < g_thread_num; i++) { + if (threads_args[i].tag) + free(threads_args[i].tag); + } +lz77_free: + if (threads_option.alg == LZ77_ZSTD) { + for (i = 0; i < g_thread_num; i++) { + if (threads_args[i].ftuple) + free(threads_args[i].ftuple); + + if (threads_args[i].hw_buff_out) + free(threads_args[i].hw_buff_out); + } + } async_error: return ret; } diff --git a/uadk_tool/benchmark/zip_wd_benchmark.c b/uadk_tool/benchmark/zip_wd_benchmark.c index 7f85b3c..a65447a 100644 --- a/uadk_tool/benchmark/zip_wd_benchmark.c +++ b/uadk_tool/benchmark/zip_wd_benchmark.c @@ -21,6 +21,7 @@ #define COMPRESSION_RATIO_FACTOR 0.7 #define MAX_POOL_LENTH_COMP 512 #define CHUNK_SIZE (128 * 1024) +#define MAX_UNRECV_PACKET_NUM 2
#define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask)) #define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1) @@ -49,6 +50,11 @@ enum ZIP_OP_MODE { STREAM_MODE };
+enum ZIP_THREAD_STATE { + THREAD_PROCESSING, + THREAD_COMPLETED +}; + struct zip_async_tag { void *ctx; u32 td_id; @@ -75,6 +81,8 @@ struct zip_file_head {
static unsigned int g_thread_num; static unsigned int g_pktlen; +static unsigned int g_send_cnt[THREADS_NUM]; +static unsigned int g_recv_state[THREADS_NUM];
static int save_file_data(const char *alg, u32 pkg_len, u32 optype) { @@ -470,9 +478,10 @@ static void *zip_wd_poll(void *data) count += recv; recv = 0;
- if (get_run_state() == 0) + if (get_run_state() == 0 && g_send_cnt[id] <= count + MAX_UNRECV_PACKET_NUM) last_time--; } + g_recv_state[id] = THREAD_COMPLETED;
recv_error: add_recv_data(count, g_pktlen); @@ -746,13 +755,11 @@ static void *zip_wd_blk_lz77_async_run(void *arg) } try_cnt = 0; count++; + __atomic_add_fetch(&g_send_cnt[pdata->td_id], 1, __ATOMIC_RELAXED); }
- while (1) { - if (get_recv_time() > 0) // wait Async mode finish recv - break; + while (g_recv_state[pdata->td_id] == THREAD_PROCESSING) usleep(SEND_USLEEP); - }
free(tag); tag_err: @@ -1011,13 +1018,11 @@ static void *zip_wd_blk_async_run(void *arg) } try_cnt = 0; count++; + __atomic_add_fetch(&g_send_cnt[pdata->td_id], 1, __ATOMIC_RELAXED); }
- while (1) { - if (get_recv_time() > 0) // wait Async mode finish recv - break; + while (g_recv_state[pdata->td_id] == THREAD_PROCESSING) usleep(SEND_USLEEP); - }
tag_release: free(tag); @@ -1107,6 +1112,7 @@ static int zip_wd_async_threads(struct acc_option *options)
for (i = 0; i < g_thread_num; i++) { threads_args[i].td_id = i; + g_recv_state[i] = THREAD_PROCESSING; /* poll thread */ ret = pthread_create(&pollid[i], NULL, zip_wd_poll, &threads_args[i]); if (ret) { @@ -1122,6 +1128,7 @@ static int zip_wd_async_threads(struct acc_option *options) threads_args[i].comp_lv = threads_option.comp_lv; threads_args[i].win_size = threads_option.win_size; threads_args[i].td_id = i; + g_send_cnt[i] = 0; ret = pthread_create(&tdid[i], NULL, wd_zip_async_run, &threads_args[i]); if (ret) { ZIP_TST_PRT("Create async thread fail!\n");
Modify the description on --opt parameter.
Signed-off-by: Qi Tao taoqi10@huawei.com --- uadk_tool/benchmark/uadk_benchmark.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c index c1accc6..7b275b2 100644 --- a/uadk_tool/benchmark/uadk_benchmark.c +++ b/uadk_tool/benchmark/uadk_benchmark.c @@ -727,7 +727,8 @@ static void print_help(void) ACC_TST_PRT(" [--mode sva/nosva/soft/sva-soft/nosva-soft/instr/multibuff]: start UADK or Warpdrive or Openssl or Instruction mode test\n"); ACC_TST_PRT(" [--sync/--async]: start asynchronous/synchronous mode test\n"); ACC_TST_PRT(" [--opt 0,1,2,3,4,5]:\n"); - ACC_TST_PRT(" SEC/ZIP: 0/1:encryption/decryption or compression/decompression\n"); + ACC_TST_PRT(" SEC: cipher,aead: 0/1:encryption/decryption; digest: 0/1:normal/hmac\n"); + ACC_TST_PRT(" ZIP: 0~1:block compression, block decompression; 2~3:stream compression, stream decompression\n"); ACC_TST_PRT(" HPRE: 0~5:keygen, key compute, Enc, Dec, Sign, Verify\n"); ACC_TST_PRT(" [--pktlen]:\n"); ACC_TST_PRT(" set the length of BD message in bytes\n");
If 'break' is not added to the switch-case statement, the program continues to execute the next case statement, causing an error.
Signed-off-by: Qi Tao taoqi10@huawei.com --- uadk_tool/benchmark/uadk_benchmark.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c index 7b275b2..1262a2a 100644 --- a/uadk_tool/benchmark/uadk_benchmark.c +++ b/uadk_tool/benchmark/uadk_benchmark.c @@ -594,6 +594,7 @@ static int benchmark_run(struct acc_option *option) } else if (option->modetype == NOSVA_MODE) { ret = zip_wd_benchmark(option); } + break; case TRNG_TYPE: if (option->modetype == SVA_MODE) ACC_TST_PRT("TRNG not support sva mode..\n");
Specified device: apply queues from a designated device. No specified device: apply queues from multiple devices.
Signed-off-by: Qi Tao taoqi10@huawei.com --- uadk_tool/benchmark/hpre_uadk_benchmark.c | 143 ++++++++++++++++----- uadk_tool/benchmark/sec_uadk_benchmark.c | 141 +++++++++++++++----- uadk_tool/benchmark/zip_uadk_benchmark.c | 150 ++++++++++++++++------ 3 files changed, 329 insertions(+), 105 deletions(-)
diff --git a/uadk_tool/benchmark/hpre_uadk_benchmark.c b/uadk_tool/benchmark/hpre_uadk_benchmark.c index 729728f..0148e56 100644 --- a/uadk_tool/benchmark/hpre_uadk_benchmark.c +++ b/uadk_tool/benchmark/hpre_uadk_benchmark.c @@ -344,21 +344,17 @@ static int hpre_uadk_param_parse(thread_data *tddata, struct acc_option *options return 0; }
-static int init_hpre_ctx_config(struct acc_option *options) +static int specified_device_request_ctx(struct acc_option *options) { - struct uacce_dev_list *list, *tmp; - int subtype = options->subtype; + struct uacce_dev_list *list = NULL; + struct uacce_dev_list *tmp = NULL; char *alg = options->algclass; int mode = options->syncmode; struct uacce_dev *dev = NULL; - struct sched_params param; - int max_node, i; + int avail_ctx = 0; char *dev_name; int ret = 0; - - max_node = numa_max_node() + 1; - if (max_node <= 0) - return -EINVAL; + int i = 0;
list = wd_get_accel_list(alg); if (!list) { @@ -366,15 +362,11 @@ static int init_hpre_ctx_config(struct acc_option *options) return -ENODEV; }
- if (strlen(options->device) == 0) { - dev = list->dev; - } else { - for (tmp = list; tmp; tmp = tmp->next) { - dev_name = strrchr(tmp->dev->dev_root, '/') + 1; - if (!strcmp(dev_name, options->device)) { - dev = tmp->dev; - break; - } + for (tmp = list; tmp != NULL; tmp = tmp->next) { + dev_name = strrchr(tmp->dev->dev_root, '/') + 1; + if (!strcmp(dev_name, options->device)) { + dev = tmp->dev; + break; } }
@@ -384,30 +376,114 @@ static int init_hpre_ctx_config(struct acc_option *options) goto free_list; }
- /* If there is no numa, we defualt config to zero */ - if (dev->numa_id < 0) - dev->numa_id = 0; - - memset(&g_ctx_cfg, 0, sizeof(struct wd_ctx_config)); - g_ctx_cfg.ctx_num = g_ctxnum; - g_ctx_cfg.ctxs = calloc(g_ctxnum, sizeof(struct wd_ctx)); - if (!g_ctx_cfg.ctxs) { - ret = -ENOMEM; + avail_ctx = wd_get_avail_ctx(dev); + if (avail_ctx < 0) { + HPRE_TST_PRT("failed to get the number of available ctx from %s\n", options->device); + ret = avail_ctx; + goto free_list; + } else if (avail_ctx < g_ctxnum) { + HPRE_TST_PRT("error: not enough ctx available in %s\n", options->device); + ret = -ENODEV; goto free_list; }
+ /* If there is no numa, we default config to zero */ + if (dev->numa_id < 0) + dev->numa_id = 0; + for (i = 0; i < g_ctxnum; i++) { g_ctx_cfg.ctxs[i].ctx = wd_request_ctx(dev); if (!g_ctx_cfg.ctxs[i].ctx) { HPRE_TST_PRT("failed to alloc %dth ctx\n", i); - ret = -ENODEV; + ret = -ENOMEM; goto free_ctx; } - g_ctx_cfg.ctxs[i].op_type = 0; g_ctx_cfg.ctxs[i].ctx_mode = (__u8)mode; }
+ wd_free_list_accels(list); + return 0; + +free_ctx: + for (; i >= 0; i--) + wd_release_ctx(g_ctx_cfg.ctxs[i].ctx); + +free_list: + wd_free_list_accels(list); + + return ret; +} + +static int non_specified_device_request_ctx(struct acc_option *options) +{ + char *alg = options->algclass; + int mode = options->syncmode; + struct uacce_dev *dev = NULL; + int ret = 0; + int i = 0; + + while (i < g_ctxnum) { + dev = wd_get_accel_dev(alg); + if (!dev) { + HPRE_TST_PRT("failed to get %s device\n", alg); + ret = -ENODEV; + goto free_ctx; + } + + /* If there is no numa, we default config to zero */ + if (dev->numa_id < 0) + dev->numa_id = 0; + + for (; i < g_ctxnum; i++) { + g_ctx_cfg.ctxs[i].ctx = wd_request_ctx(dev); + if (!g_ctx_cfg.ctxs[i].ctx) + break; + + g_ctx_cfg.ctxs[i].op_type = 0; + g_ctx_cfg.ctxs[i].ctx_mode = (__u8)mode; + } + + free(dev); + } + + return 0; + +free_ctx: + for (; i >= 0; i--) + wd_release_ctx(g_ctx_cfg.ctxs[i].ctx); + + return ret; +} + +static int init_hpre_ctx_config(struct acc_option *options) +{ + struct sched_params param = {0}; + int subtype = options->subtype; + int mode = options->syncmode; + int max_node; + int ret = 0; + + max_node = numa_max_node() + 1; + if (max_node <= 0) + return -EINVAL; + + memset(&g_ctx_cfg, 0, sizeof(struct wd_ctx_config)); + g_ctx_cfg.ctx_num = g_ctxnum; + g_ctx_cfg.ctxs = calloc(g_ctxnum, sizeof(struct wd_ctx)); + if (!g_ctx_cfg.ctxs) + return -ENOMEM; + + if (strlen(options->device) != 0) + ret = specified_device_request_ctx(options); + else + ret = non_specified_device_request_ctx(options); + + if (ret) { + HPRE_TST_PRT("failed to request hpre ctx!\n"); + goto free_ctxs; + } + switch(subtype) { case RSA_TYPE: g_sched = wd_sched_rr_alloc(SCHED_POLICY_RR, 1, max_node, wd_rsa_poll_ctx); @@ -460,7 +536,7 @@ static int init_hpre_ctx_config(struct acc_option *options) break; } if (ret) { - HPRE_TST_PRT("failed to get hpre ctx!\n"); + HPRE_TST_PRT("failed to init hpre ctx!\n"); goto free_sched; }
@@ -470,12 +546,11 @@ free_sched: wd_sched_rr_release(g_sched);
free_ctx: - for (; i >= 0; i--) + for (int i = g_ctxnum; i >= 0; i--) wd_release_ctx(g_ctx_cfg.ctxs[i].ctx); - free(g_ctx_cfg.ctxs);
-free_list: - wd_free_list_accels(list); +free_ctxs: + free(g_ctx_cfg.ctxs);
return ret; } diff --git a/uadk_tool/benchmark/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c index 2c12c20..56f4fa6 100644 --- a/uadk_tool/benchmark/sec_uadk_benchmark.c +++ b/uadk_tool/benchmark/sec_uadk_benchmark.c @@ -544,21 +544,17 @@ static int sec_uadk_param_parse(thread_data *tddata, struct acc_option *options) return 0; }
-static int init_ctx_config(struct acc_option *options) +static int specified_device_request_ctx(struct acc_option *options) { - struct uacce_dev_list *list, *tmp; - struct sched_params param = {0}; - int subtype = options->subtype; + struct uacce_dev_list *list = NULL; + struct uacce_dev_list *tmp = NULL; char *alg = options->algclass; int mode = options->syncmode; struct uacce_dev *dev = NULL; - int max_node, i; + int avail_ctx = 0; char *dev_name; int ret = 0; - - max_node = numa_max_node() + 1; - if (max_node <= 0) - return -EINVAL; + int i = 0;
list = wd_get_accel_list(alg); if (!list) { @@ -566,15 +562,11 @@ static int init_ctx_config(struct acc_option *options) return -ENODEV; }
- if (strlen(options->device) == 0) { - dev = list->dev; - } else { - for (tmp = list; tmp; tmp = tmp->next) { - dev_name = strrchr(tmp->dev->dev_root, '/') + 1; - if (!strcmp(dev_name, options->device)) { - dev = tmp->dev; - break; - } + for (tmp = list; tmp != NULL; tmp = tmp->next) { + dev_name = strrchr(tmp->dev->dev_root, '/') + 1; + if (!strcmp(dev_name, options->device)) { + dev = tmp->dev; + break; } }
@@ -584,18 +576,21 @@ static int init_ctx_config(struct acc_option *options) goto free_list; }
- /* If there is no numa, we defualt config to zero */ - if (dev->numa_id < 0) - dev->numa_id = 0; - - memset(&g_ctx_cfg, 0, sizeof(struct wd_ctx_config)); - g_ctx_cfg.ctx_num = g_ctxnum; - g_ctx_cfg.ctxs = calloc(g_ctxnum, sizeof(struct wd_ctx)); - if (!g_ctx_cfg.ctxs) { - ret = -ENOMEM; + avail_ctx = wd_get_avail_ctx(dev); + if (avail_ctx < 0) { + SEC_TST_PRT("failed to get the number of available ctx from %s\n", options->device); + ret = avail_ctx; + goto free_list; + } else if (avail_ctx < g_ctxnum) { + SEC_TST_PRT("error: not enough ctx available in %s\n", options->device); + ret = -ENODEV; goto free_list; }
+ /* If there is no numa, we default config to zero */ + if (dev->numa_id < 0) + dev->numa_id = 0; + for (i = 0; i < g_ctxnum; i++) { g_ctx_cfg.ctxs[i].ctx = wd_request_ctx(dev); if (!g_ctx_cfg.ctxs[i].ctx) { @@ -603,11 +598,92 @@ static int init_ctx_config(struct acc_option *options) ret = -ENOMEM; goto free_ctx; } - g_ctx_cfg.ctxs[i].op_type = 0; g_ctx_cfg.ctxs[i].ctx_mode = (__u8)mode; }
+ wd_free_list_accels(list); + return 0; + +free_ctx: + for (; i >= 0; i--) + wd_release_ctx(g_ctx_cfg.ctxs[i].ctx); + +free_list: + wd_free_list_accels(list); + + return ret; +} + +static int non_specified_device_request_ctx(struct acc_option *options) +{ + char *alg = options->algclass; + int mode = options->syncmode; + struct uacce_dev *dev = NULL; + int ret = 0; + int i = 0; + + while (i < g_ctxnum) { + dev = wd_get_accel_dev(alg); + if (!dev) { + SEC_TST_PRT("failed to get %s device\n", alg); + ret = -ENODEV; + goto free_ctx; + } + + /* If there is no numa, we default config to zero */ + if (dev->numa_id < 0) + dev->numa_id = 0; + + for (; i < g_ctxnum; i++) { + g_ctx_cfg.ctxs[i].ctx = wd_request_ctx(dev); + if (!g_ctx_cfg.ctxs[i].ctx) + break; + + g_ctx_cfg.ctxs[i].op_type = 0; + g_ctx_cfg.ctxs[i].ctx_mode = (__u8)mode; + } + + free(dev); + } + + return 0; + +free_ctx: + for (; i >= 0; i--) + wd_release_ctx(g_ctx_cfg.ctxs[i].ctx); + + return ret; +} + +static int init_ctx_config(struct acc_option *options) +{ + struct sched_params param = {0}; + int subtype = options->subtype; + int mode = options->syncmode; + int max_node; + int ret = 0; + + max_node = numa_max_node() + 1; + if (max_node <= 0) + return -EINVAL; + + memset(&g_ctx_cfg, 0, sizeof(struct wd_ctx_config)); + g_ctx_cfg.ctx_num = g_ctxnum; + g_ctx_cfg.ctxs = calloc(g_ctxnum, sizeof(struct wd_ctx)); + if (!g_ctx_cfg.ctxs) + return -ENOMEM; + + if (strlen(options->device) != 0) + ret = specified_device_request_ctx(options); + else + ret = non_specified_device_request_ctx(options); + + if (ret) { + SEC_TST_PRT("failed to request sec ctx!\n"); + goto free_ctxs; + } + switch(subtype) { case CIPHER_TYPE: g_sched = wd_sched_rr_alloc(SCHED_POLICY_RR, 1, max_node, wd_cipher_poll_ctx); @@ -652,7 +728,7 @@ static int init_ctx_config(struct acc_option *options) break; } if (ret) { - SEC_TST_PRT("failed to cipher ctx!\n"); + SEC_TST_PRT("failed to init sec ctx!\n"); goto free_sched; }
@@ -662,12 +738,11 @@ free_sched: wd_sched_rr_release(g_sched);
free_ctx: - for (; i >= 0; i--) + for (int i = g_ctxnum; i >= 0; i--) wd_release_ctx(g_ctx_cfg.ctxs[i].ctx); - free(g_ctx_cfg.ctxs);
-free_list: - wd_free_list_accels(list); +free_ctxs: + free(g_ctx_cfg.ctxs);
return ret; } diff --git a/uadk_tool/benchmark/zip_uadk_benchmark.c b/uadk_tool/benchmark/zip_uadk_benchmark.c index 1dd3990..e2876a9 100644 --- a/uadk_tool/benchmark/zip_uadk_benchmark.c +++ b/uadk_tool/benchmark/zip_uadk_benchmark.c @@ -318,21 +318,17 @@ static int init_ctx_config2(struct acc_option *options) return 0; }
-static int init_ctx_config(struct acc_option *options) +static int specified_device_request_ctx(struct acc_option *options) { - struct uacce_dev_list *list, *tmp; + struct uacce_dev_list *list = NULL; + struct uacce_dev_list *tmp = NULL; char *alg = options->algclass; - int optype = options->optype; int mode = options->syncmode; struct uacce_dev *dev = NULL; - int max_node, i; + int avail_ctx = 0; char *dev_name; int ret = 0; - - optype = optype % WD_DIR_MAX; - max_node = numa_max_node() + 1; - if (max_node <= 0) - return -EINVAL; + int i = 0;
list = wd_get_accel_list(alg); if (!list) { @@ -340,15 +336,11 @@ static int init_ctx_config(struct acc_option *options) return -ENODEV; }
- if (strlen(options->device) == 0) { - dev = list->dev; - } else { - for (tmp = list; tmp; tmp = tmp->next) { - dev_name = strrchr(tmp->dev->dev_root, '/') + 1; - if (!strcmp(dev_name, options->device)) { - dev = tmp->dev; - break; - } + for (tmp = list; tmp != NULL; tmp = tmp->next) { + dev_name = strrchr(tmp->dev->dev_root, '/') + 1; + if (!strcmp(dev_name, options->device)) { + dev = tmp->dev; + break; } }
@@ -358,29 +350,114 @@ static int init_ctx_config(struct acc_option *options) goto free_list; }
- /* If there is no numa, we defualt config to zero */ - if (dev->numa_id < 0) - dev->numa_id = 0; - - memset(&g_ctx_cfg, 0, sizeof(struct wd_ctx_config)); - g_ctx_cfg.ctx_num = g_ctxnum; - g_ctx_cfg.ctxs = calloc(g_ctxnum, sizeof(struct wd_ctx)); - if (!g_ctx_cfg.ctxs) { - ret = -ENOMEM; + avail_ctx = wd_get_avail_ctx(dev); + if (avail_ctx < 0) { + ZIP_TST_PRT("failed to get the number of available ctx from %s\n", options->device); + ret = avail_ctx; + goto free_list; + } else if (avail_ctx < g_ctxnum) { + ZIP_TST_PRT("error: not enough ctx available in %s\n", options->device); + ret = -ENODEV; goto free_list; }
- for (i = 0; i < g_ctxnum; i++) { + /* If there is no numa, we default config to zero */ + if (dev->numa_id < 0) + dev->numa_id = 0; + + for (; i < g_ctxnum; i++) { g_ctx_cfg.ctxs[i].ctx = wd_request_ctx(dev); if (!g_ctx_cfg.ctxs[i].ctx) { ZIP_TST_PRT("failed to alloc %dth ctx\n", i); + ret = -ENOMEM; goto free_ctx; } - - g_ctx_cfg.ctxs[i].op_type = optype; + g_ctx_cfg.ctxs[i].op_type = 0; g_ctx_cfg.ctxs[i].ctx_mode = (__u8)mode; }
+ wd_free_list_accels(list); + return 0; + +free_ctx: + for (; i >= 0; i--) + wd_release_ctx(g_ctx_cfg.ctxs[i].ctx); + +free_list: + wd_free_list_accels(list); + + return ret; +} + +static int non_specified_device_request_ctx(struct acc_option *options) +{ + char *alg = options->algclass; + int mode = options->syncmode; + struct uacce_dev *dev = NULL; + int ret = 0; + int i = 0; + + while (i < g_ctxnum) { + dev = wd_get_accel_dev(alg); + if (!dev) { + ZIP_TST_PRT("failed to get %s device\n", alg); + ret = -ENODEV; + goto free_ctx; + } + + /* If there is no numa, we default config to zero */ + if (dev->numa_id < 0) + dev->numa_id = 0; + + for (; i < g_ctxnum; i++) { + g_ctx_cfg.ctxs[i].ctx = wd_request_ctx(dev); + if (!g_ctx_cfg.ctxs[i].ctx) + break; + + g_ctx_cfg.ctxs[i].op_type = 0; + g_ctx_cfg.ctxs[i].ctx_mode = (__u8)mode; + } + + free(dev); + } + + return 0; + +free_ctx: + for (; i >= 0; i--) + wd_release_ctx(g_ctx_cfg.ctxs[i].ctx); + + return ret; +} + +static int init_ctx_config(struct acc_option *options) +{ + int optype = options->optype; + int mode = options->syncmode; + int max_node; + int ret = 0; + + optype = optype % WD_DIR_MAX; + max_node = numa_max_node() + 1; + if (max_node <= 0) + return -EINVAL; + + memset(&g_ctx_cfg, 0, sizeof(struct wd_ctx_config)); + g_ctx_cfg.ctx_num = g_ctxnum; + g_ctx_cfg.ctxs = calloc(g_ctxnum, sizeof(struct wd_ctx)); + if (!g_ctx_cfg.ctxs) + return -ENOMEM; + + if (strlen(options->device) != 0) + ret = specified_device_request_ctx(options); + else + ret = non_specified_device_request_ctx(options); + + if (ret) { + ZIP_TST_PRT("failed to request zip ctx!\n"); + goto free_ctxs; + } + g_sched = wd_sched_rr_alloc(SCHED_POLICY_RR, 2, max_node, wd_comp_poll_ctx); if (!g_sched) { ZIP_TST_PRT("failed to alloc sched!\n"); @@ -394,7 +471,7 @@ static int init_ctx_config(struct acc_option *options) * All contexts for 2 modes & 2 types. * The test only uses one kind of contexts at the same time. */ - param.numa_id = dev->numa_id; + param.numa_id = 0; param.type = optype; param.mode = mode; param.begin = 0; @@ -407,24 +484,21 @@ static int init_ctx_config(struct acc_option *options)
ret = wd_comp_init(&g_ctx_cfg, g_sched); if (ret) { - ZIP_TST_PRT("failed to cipher ctx!\n"); + ZIP_TST_PRT("failed to init zip ctx!\n"); goto free_sched; }
- wd_free_list_accels(list); - return 0;
free_sched: wd_sched_rr_release(g_sched);
free_ctx: - for (; i >= 0; i--) + for (int i = g_ctxnum; i >= 0; i--) wd_release_ctx(g_ctx_cfg.ctxs[i].ctx); - free(g_ctx_cfg.ctxs);
-free_list: - wd_free_list_accels(list); +free_ctxs: + free(g_ctx_cfg.ctxs);
return ret; }