From c0c3359090a8e6fcaf59c606dccee8e554c89ff2 Mon Sep 17 00:00:00 2001 From: Zhangfei Gao Date: Wed, 28 Aug 2024 09:42:39 +0000 Subject: [PATCH 19/39] uadk_tool: use wd_xxx_init2_ instead of wd_xxx_init2 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 --- uadk_tool/benchmark/hpre_uadk_benchmark.c | 36 +++++++++++++++++++++-- uadk_tool/benchmark/sec_uadk_benchmark.c | 35 ++++++++++++++++++++-- uadk_tool/benchmark/zip_uadk_benchmark.c | 36 +++++++++++++++++++++-- 3 files changed, 99 insertions(+), 8 deletions(-) diff --git a/uadk_tool/benchmark/hpre_uadk_benchmark.c b/uadk_tool/benchmark/hpre_uadk_benchmark.c index 5dd6a39..bc0687d 100644 --- a/uadk_tool/benchmark/hpre_uadk_benchmark.c +++ b/uadk_tool/benchmark/hpre_uadk_benchmark.c @@ -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; @@ -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-------------------------------------*/ diff --git a/uadk_tool/benchmark/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c index 41b7416..411d0c4 100644 --- a/uadk_tool/benchmark/sec_uadk_benchmark.c +++ b/uadk_tool/benchmark/sec_uadk_benchmark.c @@ -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; @@ -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; @@ -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; @@ -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) diff --git a/uadk_tool/benchmark/zip_uadk_benchmark.c b/uadk_tool/benchmark/zip_uadk_benchmark.c index 22aa916..2133297 100644 --- a/uadk_tool/benchmark/zip_uadk_benchmark.c +++ b/uadk_tool/benchmark/zip_uadk_benchmark.c @@ -299,8 +299,11 @@ 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) { @@ -308,14 +311,43 @@ static int init_ctx_config2(struct acc_option *options) 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) -- 2.25.1