Skip to content

Commit

Permalink
uadk_tool: use wd_xxx_init2_ instead of wd_xxx_init2
Browse files Browse the repository at this point in the history
wd_xxx_init2 does not take para cparam, which take ctx number.
So default ctx number is used with poor performance.

numactl --cpubind=0 --membind=0 \
uadk_tool benchmark --alg sha512 --mode sva --opt 0 --async --pktlen 8192 \
--seconds 20 --multi 1 --thread 8 --ctxnum 8 --init2
sha512          8192Bytes       3982625.60KiB/s 497.8Kops       1292.90%

after fix:
numactl --cpubind=0 --membind=0 \
uadk_tool benchmark --alg sha512 --mode sva --opt 0 --async --pktlen 8192 \
--seconds 20 --multi 1 --thread 8 --ctxnum 8 --init2
sha512          8192Bytes       11276124.40KiB/s  1409.5Kops    1026.70%

Signed-off-by: Zhangfei Gao <[email protected]>
  • Loading branch information
zhangfeigao authored and Liulongfang committed Aug 29, 2024
1 parent d458dab commit c0c3359
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 8 deletions.
36 changes: 33 additions & 3 deletions uadk_tool/benchmark/hpre_uadk_benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,10 @@ static void uninit_hpre_ctx_config2(int subtype)

static int init_hpre_ctx_config2(struct acc_option *options)
{
struct wd_ctx_params cparams = {0};
struct wd_ctx_nums *ctx_set_num;
int subtype = options->subtype;
int mode = options->syncmode;
char alg_name[MAX_ALG_NAME];
int ret;

Expand All @@ -620,22 +623,49 @@ static int init_hpre_ctx_config2(struct acc_option *options)
return -EINVAL;
}

ctx_set_num = calloc(1, sizeof(*ctx_set_num));
if (!ctx_set_num) {
WD_ERR("failed to alloc ctx_set_size!\n");
return -WD_ENOMEM;
}

cparams.op_type_num = 1;
cparams.ctx_set_num = ctx_set_num;
cparams.bmp = numa_allocate_nodemask();
if (!cparams.bmp) {
WD_ERR("failed to create nodemask!\n");
ret = -WD_ENOMEM;
goto out_freectx;
}

numa_bitmask_setall(cparams.bmp);

if (mode == CTX_MODE_SYNC)
ctx_set_num->sync_ctx_num = g_ctxnum;
else
ctx_set_num->async_ctx_num = g_ctxnum;

/* init2 */
switch (subtype) {
case RSA_TYPE:
return wd_rsa_init2(alg_name, SCHED_POLICY_RR, TASK_HW);
return wd_rsa_init2_(alg_name, SCHED_POLICY_RR, TASK_HW, &cparams);
case DH_TYPE:
return wd_dh_init2(alg_name, SCHED_POLICY_RR, TASK_HW);
return wd_dh_init2_(alg_name, SCHED_POLICY_RR, TASK_HW, &cparams);
case ECDH_TYPE:
case ECDSA_TYPE:
case SM2_TYPE:
case X25519_TYPE:
case X448_TYPE:
return wd_ecc_init2(alg_name, SCHED_POLICY_RR, TASK_HW);
return wd_ecc_init2_(alg_name, SCHED_POLICY_RR, TASK_HW, &cparams);
default:
HPRE_TST_PRT("failed to parse alg subtype on uninit2!\n");
return -EINVAL;
}

out_freectx:
free(ctx_set_num);

return ret;
}

/*-------------------------------uadk benchmark main code-------------------------------------*/
Expand Down
35 changes: 32 additions & 3 deletions uadk_tool/benchmark/sec_uadk_benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,10 @@ static void uninit_ctx_config2(int subtype)

static int init_ctx_config2(struct acc_option *options)
{
struct wd_ctx_params cparams = {0};
struct wd_ctx_nums *ctx_set_num;
int subtype = options->subtype;
int mode = options->syncmode;
char alg_name[MAX_ALG_NAME];
int ret;

Expand All @@ -805,10 +808,32 @@ static int init_ctx_config2(struct acc_option *options)
return -EINVAL;
}

ctx_set_num = calloc(1, sizeof(*ctx_set_num));
if (!ctx_set_num) {
WD_ERR("failed to alloc ctx_set_size!\n");
return -WD_ENOMEM;
}

cparams.op_type_num = 1;
cparams.ctx_set_num = ctx_set_num;
cparams.bmp = numa_allocate_nodemask();
if (!cparams.bmp) {
WD_ERR("failed to create nodemask!\n");
ret = -WD_ENOMEM;
goto out_freectx;
}

numa_bitmask_setall(cparams.bmp);

if (mode == CTX_MODE_SYNC)
ctx_set_num->sync_ctx_num = g_ctxnum;
else
ctx_set_num->async_ctx_num = g_ctxnum;

/* init */
switch(subtype) {
case CIPHER_TYPE:
ret = wd_cipher_init2(alg_name, SCHED_POLICY_RR, TASK_HW);
ret = wd_cipher_init2_(alg_name, SCHED_POLICY_RR, TASK_HW, &cparams);
if (ret)
SEC_TST_PRT("failed to do cipher init2!\n");
break;
Expand All @@ -818,12 +843,12 @@ static int init_ctx_config2(struct acc_option *options)
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);
ret = wd_aead_init2_(alg_name, SCHED_POLICY_RR, TASK_HW, &cparams);
if (ret)
SEC_TST_PRT("failed to do aead init2!\n");
break;
case DIGEST_TYPE:
ret = wd_digest_init2(alg_name, options->sched_type, options->task_type);
ret = wd_digest_init2_(alg_name, options->sched_type, options->task_type, &cparams);
if (ret)
SEC_TST_PRT("failed to do digest init2!\n");
break;
Expand All @@ -833,7 +858,11 @@ static int init_ctx_config2(struct acc_option *options)
return ret;
}

out_freectx:
free(ctx_set_num);

return ret;

}

static void get_aead_data(u8 *addr, u32 size)
Expand Down
36 changes: 34 additions & 2 deletions uadk_tool/benchmark/zip_uadk_benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,23 +299,55 @@ static void uninit_ctx_config2(void)

static int init_ctx_config2(struct acc_option *options)
{
struct wd_ctx_params cparams = {0};
struct wd_ctx_nums *ctx_set_num;
int mode = options->syncmode;
char alg_name[MAX_ALG_NAME];
int ret = 0;
int ret;

ret = get_alg_name(options->algtype, alg_name);
if (ret) {
ZIP_TST_PRT("failed to get valid alg name!\n");
return -EINVAL;
}

ctx_set_num = calloc(WD_DIR_MAX, sizeof(*ctx_set_num));
if (!ctx_set_num) {
WD_ERR("failed to alloc ctx_set_size!\n");
return -WD_ENOMEM;
}

cparams.op_type_num = WD_DIR_MAX;
cparams.ctx_set_num = ctx_set_num;
cparams.bmp = numa_allocate_nodemask();
if (!cparams.bmp) {
WD_ERR("failed to create nodemask!\n");
ret = -WD_ENOMEM;
goto out_freectx;
}

numa_bitmask_setall(cparams.bmp);

for (int i = 0; i < WD_DIR_MAX; i++) {
if (mode == CTX_MODE_SYNC)
ctx_set_num[i].sync_ctx_num = g_ctxnum;
else
ctx_set_num[i].async_ctx_num = g_ctxnum;
}

/* init */
ret = wd_comp_init2(alg_name, SCHED_POLICY_RR, TASK_HW);
ret = wd_comp_init2_(alg_name, SCHED_POLICY_RR, TASK_HW, &cparams);
if (ret) {
ZIP_TST_PRT("failed to do comp init2!\n");
return ret;
}

return 0;

out_freectx:
free(ctx_set_num);

return ret;
}

static int specified_device_request_ctx(struct acc_option *options)
Expand Down

0 comments on commit c0c3359

Please sign in to comment.