From: Zhushuai Yin <yinzhushuai@huawei.com> With the UADK framework updated to support heterogeneous hybrid acceleration functionality, the corresponding uadk_tool test framework also needs to be adapted and updated. It must simultaneously support both the legacy init interface and the new init2 interface, match new scheduling algorithm types, and add new DAE test functionality. Signed-off-by: Zhushuai Yin <yinzhushuai@huawei.com> Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com> Signed-off-by: Longfang Liu <liulongfang@huawei.com> Signed-off-by: lizhi <lizhi206@huawei.com> Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com> --- uadk_tool/benchmark/hpre_uadk_benchmark.c | 173 ++++++++++++++-------- uadk_tool/benchmark/sec_uadk_benchmark.c | 55 +++++-- uadk_tool/benchmark/uadk_benchmark.c | 81 +++++++++- uadk_tool/benchmark/uadk_benchmark.h | 7 + uadk_tool/benchmark/zip_uadk_benchmark.c | 98 +++++++++--- 5 files changed, 314 insertions(+), 100 deletions(-) diff --git a/uadk_tool/benchmark/hpre_uadk_benchmark.c b/uadk_tool/benchmark/hpre_uadk_benchmark.c index fa26a61..58394c7 100644 --- a/uadk_tool/benchmark/hpre_uadk_benchmark.c +++ b/uadk_tool/benchmark/hpre_uadk_benchmark.c @@ -21,6 +21,7 @@ #define SQE_SIZE 128 #define POOL_MULTIPLY_FACTOR 2 #define HPRE_OP_TYPE_MAX 6 +#define MAX_DRAIN_RETRY 10000 struct hpre_rsa_key_in { void *e; @@ -503,7 +504,7 @@ static int init_hpre_ctx_config(struct acc_option *options) switch(subtype) { case RSA_TYPE: if (options->mem_type == UADK_AUTO) - g_sched = wd_sched_rr_alloc(SCHED_POLICY_RR, HPRE_OP_TYPE_MAX, + g_sched = wd_sched_rr_alloc(options->sched_type, HPRE_OP_TYPE_MAX, max_node, wd_rsa_poll_ctx); else g_sched = wd_sched_rr_alloc(SCHED_POLICY_DEV, HPRE_OP_TYPE_MAX, @@ -511,7 +512,7 @@ static int init_hpre_ctx_config(struct acc_option *options) break; case DH_TYPE: if (options->mem_type == UADK_AUTO) - g_sched = wd_sched_rr_alloc(SCHED_POLICY_RR, HPRE_OP_TYPE_MAX, + g_sched = wd_sched_rr_alloc(options->sched_type, HPRE_OP_TYPE_MAX, max_node, wd_dh_poll_ctx); else g_sched = wd_sched_rr_alloc(SCHED_POLICY_DEV, HPRE_OP_TYPE_MAX, @@ -523,7 +524,7 @@ static int init_hpre_ctx_config(struct acc_option *options) case X25519_TYPE: case X448_TYPE: if (options->mem_type == UADK_AUTO) - g_sched = wd_sched_rr_alloc(SCHED_POLICY_RR, HPRE_OP_TYPE_MAX, + g_sched = wd_sched_rr_alloc(options->sched_type, HPRE_OP_TYPE_MAX, max_node, wd_ecc_poll_ctx); else g_sched = wd_sched_rr_alloc(SCHED_POLICY_DEV, HPRE_OP_TYPE_MAX, @@ -672,7 +673,10 @@ static int init_hpre_ctx_config2(struct acc_option *options) numa_bitmask_setall(cparams.bmp); - if (mode == CTX_MODE_SYNC) + if (options->sched_type == SCHED_POLICY_SINGLE) { + ctx_set_num->sync_ctx_num = g_ctxnum; + ctx_set_num->async_ctx_num = g_ctxnum; + } else if (mode == CTX_MODE_SYNC) ctx_set_num->sync_ctx_num = g_ctxnum; else ctx_set_num->async_ctx_num = g_ctxnum; @@ -681,26 +685,39 @@ static int init_hpre_ctx_config2(struct acc_option *options) switch (subtype) { case RSA_TYPE: if (options->mem_type == UADK_AUTO) - return wd_rsa_init2_(alg_name, SCHED_POLICY_RR, TASK_HW, &cparams); + ret = wd_rsa_init2_(alg_name, options->sched_type, + options->task_type, &cparams); else - return wd_rsa_init2_(alg_name, SCHED_POLICY_DEV, TASK_HW, &cparams); + ret = wd_rsa_init2_(alg_name, SCHED_POLICY_DEV, TASK_HW, &cparams); + if (ret) + HPRE_TST_PRT("failed to do rsa init2!\n"); + break; case DH_TYPE: if (options->mem_type == UADK_AUTO) - return wd_dh_init2_(alg_name, SCHED_POLICY_RR, TASK_HW, &cparams); + ret = wd_dh_init2_(alg_name, options->sched_type, + options->task_type, &cparams); else - return wd_dh_init2_(alg_name, SCHED_POLICY_DEV, TASK_HW, &cparams); + ret = wd_dh_init2_(alg_name, SCHED_POLICY_DEV, TASK_HW, &cparams); + if (ret) + HPRE_TST_PRT("failed to do dh init2!\n"); + break; case ECDH_TYPE: case ECDSA_TYPE: case SM2_TYPE: case X25519_TYPE: case X448_TYPE: if (options->mem_type == UADK_AUTO) - return wd_ecc_init2_(alg_name, SCHED_POLICY_RR, TASK_HW, &cparams); + ret = wd_ecc_init2_(alg_name, options->sched_type, + options->task_type, &cparams); else - return wd_ecc_init2_(alg_name, SCHED_POLICY_DEV, TASK_HW, &cparams); + ret = wd_ecc_init2_(alg_name, SCHED_POLICY_DEV, TASK_HW, &cparams); + if (ret) + HPRE_TST_PRT("failed to do ecc init2!\n"); + break; default: - HPRE_TST_PRT("failed to parse alg subtype on uninit2!\n"); - return -EINVAL; + HPRE_TST_PRT("failed to parse alg subtype on init2!\n"); + ret = -EINVAL; + break; } out_freectx: @@ -820,9 +837,9 @@ void *hpre_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; + u32 drain_retry = 0; int ret; if (id > g_ctxnum) @@ -847,17 +864,42 @@ void *hpre_uadk_poll(void *data) return NULL; } - while (last_time) { + while (1) { ret = uadk_poll_ctx(id, expt, &recv); count += recv; recv = 0; if (unlikely(ret != -WD_EAGAIN && ret < 0)) { HPRE_TST_PRT("poll ret: %d!\n", ret); + add_total_recv(count); goto recv_error; } + if (get_run_state() == 0) { + add_total_recv(count); + break; + } + } - if (get_run_state() == 0) - last_time--; + while (get_send_stopped() != g_thread_num || + get_total_recv() < get_total_sent()) { + ret = uadk_poll_ctx(id, expt, &recv); + if (unlikely(ret != -WD_EAGAIN && ret < 0)) { + HPRE_TST_PRT("poll ret: %d!\n", ret); + goto recv_error; + } + if (recv == 0) { + usleep(SEND_USLEEP); + drain_retry++; + } else { + add_total_recv(recv); + drain_retry = 0; + recv = 0; + } + if (drain_retry >= MAX_DRAIN_RETRY) { + HPRE_TST_PRT("drain timeout: sent=%llu recv=%llu stopped=%llu/%u\n", + get_total_sent(), get_total_recv(), + get_send_stopped(), g_thread_num); + break; + } } recv_error: @@ -872,10 +914,10 @@ void *hpre_uadk_poll2(void *data) thread_data *pdata = (thread_data *)data; u32 expt = ACC_QUEUE_SIZE * g_thread_num; poll_ctx uadk_poll = NULL; - u32 last_time = 2; // poll need one more recv time u32 count = 0; u32 recv = 0; - int ret; + u32 drain_retry = 0; + int ret; switch (pdata->subtype) { case RSA_TYPE: @@ -896,17 +938,42 @@ void *hpre_uadk_poll2(void *data) return NULL; } - while (last_time) { + while (1) { ret = uadk_poll(expt, &recv); count += recv; recv = 0; if (unlikely(ret != -WD_EAGAIN && ret < 0)) { HPRE_TST_PRT("poll ret: %d!\n", ret); + add_total_recv(count); goto recv_error; } + if (get_run_state() == 0) { + add_total_recv(count); + break; + } + } - if (get_run_state() == 0) - last_time--; + while (get_send_stopped() != g_thread_num || + get_total_recv() < get_total_sent()) { + ret = uadk_poll(expt, &recv); + if (unlikely(ret != -WD_EAGAIN && ret < 0)) { + HPRE_TST_PRT("poll ret: %d!\n", ret); + goto recv_error; + } + if (recv == 0) { + usleep(SEND_USLEEP); + drain_retry++; + } else { + add_total_recv(recv); + drain_retry = 0; + recv = 0; + } + if (drain_retry >= MAX_DRAIN_RETRY) { + HPRE_TST_PRT("drain timeout: sent=%llu recv=%llu stopped=%llu/%u\n", + get_total_sent(), get_total_recv(), + get_send_stopped(), g_thread_num); + break; + } } recv_error: @@ -1076,9 +1143,11 @@ static int get_rsa_key_from_sample(handle_t sess, char *privkey_file, } if (crt_privkey_file) { - memcpy(crt_privkey_file, wd_dq.data, (key_bits >> 4) * 5); - memcpy(crt_privkey_file + (key_bits >> 4) * 5, - wd_e.data, (key_bits >> 2)); + memcpy(crt_privkey_file, wd_dq.data, + dq_bytes + dp_bytes + qinv_bytes + q_bytes + p_bytes); + memcpy(crt_privkey_file + dq_bytes + dp_bytes + + qinv_bytes + q_bytes + p_bytes, + wd_e.data, e_bytes); } } else { @@ -1097,10 +1166,10 @@ static int get_rsa_key_from_sample(handle_t sess, char *privkey_file, if (privkey_file) { - memcpy(privkey_file, wd_d.data, key_size); - memcpy(privkey_file + key_size, wd_n.data, key_size); - memcpy(privkey_file + 2 * key_size, wd_e.data, key_size); - memcpy(privkey_file + 3 * key_size, wd_n.data, key_size); + memcpy(privkey_file, wd_d.data, d_bytes); + memcpy(privkey_file + key_size, wd_n.data, n_bytes); + memcpy(privkey_file + 2 * key_size, wd_e.data, e_bytes); + memcpy(privkey_file + 3 * key_size, wd_n.data, n_bytes); } } @@ -1735,20 +1804,12 @@ static void *rsa_uadk_async_run(void *arg) count++; } while(true); - /* Release memory after all tasks are complete. */ - if (count) { - i = 0; - while (get_recv_time() != g_ctxnum) { - if (i++ >= MAX_TRY_CNT) { - HPRE_TST_PRT("failed to wait poll thread finish!\n"); - break; - } + add_total_sent(count); + add_send_stopped(); + if (count) { + while (get_recv_time() != g_ctxnum) usleep(SEND_USLEEP); - } - - /* Wait for the device to complete the tasks. */ - usleep(SEND_USLEEP * MAX_TRY_CNT); } if (req.op_type == WD_RSA_GENKEY) { @@ -2021,20 +2082,12 @@ static void *dh_uadk_async_run(void *arg) count++; } while(true); - /* Release memory after all tasks are complete. */ - if (count) { - i = 0; - while (get_recv_time() != g_ctxnum) { - if (i++ >= MAX_TRY_CNT) { - HPRE_TST_PRT("failed to wait poll thread finish!\n"); - break; - } + add_total_sent(count); + add_send_stopped(); + if (count) { + while (get_recv_time() != g_ctxnum) usleep(SEND_USLEEP); - } - - /* Wait for the device to complete the tasks. */ - usleep(SEND_USLEEP * MAX_TRY_CNT); } free(tag); @@ -2789,20 +2842,12 @@ static void *ecc_uadk_async_run(void *arg) count++; } while(true); - /* Release memory after all tasks are complete. */ - if (count) { - i = 0; - while (get_recv_time() != g_ctxnum) { - if (i++ >= MAX_TRY_CNT) { - HPRE_TST_PRT("failed to wait poll thread finish!\n"); - break; - } + add_total_sent(count); + add_send_stopped(); + if (count) { + while (get_recv_time() != g_ctxnum) usleep(SEND_USLEEP); - } - - /* Wait for the device to complete the tasks. */ - usleep(SEND_USLEEP * MAX_TRY_CNT); } free(tag); diff --git a/uadk_tool/benchmark/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c index 4a64c94..7bfafda 100644 --- a/uadk_tool/benchmark/sec_uadk_benchmark.c +++ b/uadk_tool/benchmark/sec_uadk_benchmark.c @@ -730,8 +730,9 @@ static int init_ctx_config(struct acc_option *options) switch(subtype) { case CIPHER_TYPE: + case CIPHER_INSTR_TYPE: if (options->mem_type == UADK_AUTO) - g_sched = wd_sched_rr_alloc(SCHED_POLICY_RR, SEC_OP_TYPE_MAX, + g_sched = wd_sched_rr_alloc(options->sched_type, SEC_OP_TYPE_MAX, max_node, wd_cipher_poll_ctx); else g_sched = wd_sched_rr_alloc(SCHED_POLICY_DEV, SEC_OP_TYPE_MAX, @@ -739,15 +740,16 @@ static int init_ctx_config(struct acc_option *options) break; case AEAD_TYPE: if (options->mem_type == UADK_AUTO) - g_sched = wd_sched_rr_alloc(SCHED_POLICY_RR, SEC_OP_TYPE_MAX, + g_sched = wd_sched_rr_alloc(options->sched_type, SEC_OP_TYPE_MAX, max_node, wd_aead_poll_ctx); else g_sched = wd_sched_rr_alloc(SCHED_POLICY_DEV, SEC_OP_TYPE_MAX, max_node, wd_aead_poll_ctx); break; case DIGEST_TYPE: + case DIGEST_INSTR_TYPE: if (options->mem_type == UADK_AUTO) - g_sched = wd_sched_rr_alloc(SCHED_POLICY_RR, SEC_OP_TYPE_MAX, + g_sched = wd_sched_rr_alloc(options->sched_type, SEC_OP_TYPE_MAX, max_node, wd_digest_poll_ctx); else g_sched = wd_sched_rr_alloc(SCHED_POLICY_DEV, SEC_OP_TYPE_MAX, @@ -778,14 +780,19 @@ static int init_ctx_config(struct acc_option *options) /* init */ switch(subtype) { case CIPHER_TYPE: + case CIPHER_INSTR_TYPE: ret = wd_cipher_init(&g_ctx_cfg, g_sched); break; case AEAD_TYPE: ret = wd_aead_init(&g_ctx_cfg, g_sched); break; case DIGEST_TYPE: + case DIGEST_INSTR_TYPE: ret = wd_digest_init(&g_ctx_cfg, g_sched); break; + default: + SEC_TST_PRT("failed to parse alg subtype!\n"); + goto free_sched; } if (ret) { SEC_TST_PRT("failed to init sec ctx!\n"); @@ -814,12 +821,14 @@ static void uninit_ctx_config(int subtype) /* uninit */ switch(subtype) { case CIPHER_TYPE: + case CIPHER_INSTR_TYPE: wd_cipher_uninit(); break; case AEAD_TYPE: wd_aead_uninit(); break; case DIGEST_TYPE: + case DIGEST_INSTR_TYPE: wd_digest_uninit(); break; default: @@ -845,6 +854,7 @@ static void uninit_ctx_config2(int subtype) wd_aead_uninit2(); break; case DIGEST_TYPE: + case DIGEST_INSTR_TYPE: wd_digest_uninit2(); break; default: @@ -885,7 +895,12 @@ static int init_ctx_config2(struct acc_option *options) numa_bitmask_setall(cparams.bmp); - if (mode == CTX_MODE_SYNC) + /* SINGLE scheduler hardcodes idx=0 for sync, idx=1 for async, + * so both sync and async contexts must be allocated together */ + if (options->sched_type == SCHED_POLICY_SINGLE) { + ctx_set_num->sync_ctx_num = g_ctxnum; + ctx_set_num->async_ctx_num = g_ctxnum; + } else if (mode == CTX_MODE_SYNC) ctx_set_num->sync_ctx_num = g_ctxnum; else ctx_set_num->async_ctx_num = g_ctxnum; @@ -894,33 +909,39 @@ static int init_ctx_config2(struct acc_option *options) switch(subtype) { case CIPHER_TYPE: if (options->mem_type == UADK_AUTO) - ret = wd_cipher_init2_(alg_name, SCHED_POLICY_RR, TASK_HW, &cparams); + ret = wd_cipher_init2_(alg_name, options->sched_type, options->task_type, &cparams); else ret = wd_cipher_init2_(alg_name, SCHED_POLICY_DEV, TASK_HW, &cparams); 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); + ret = wd_cipher_init2_(alg_name, options->sched_type, options->task_type, &cparams); if (ret) - SEC_TST_PRT("failed to do cipher intruction init2!\n"); + SEC_TST_PRT("failed to do cipher instruction init2!\n"); break; case AEAD_TYPE: if (options->mem_type == UADK_AUTO) - ret = wd_aead_init2_(alg_name, SCHED_POLICY_RR, TASK_HW, &cparams); + ret = wd_aead_init2_(alg_name, options->sched_type, options->task_type, &cparams); else ret = wd_aead_init2_(alg_name, SCHED_POLICY_DEV, TASK_HW, &cparams); if (ret) SEC_TST_PRT("failed to do aead init2!\n"); break; case DIGEST_TYPE: - if (options->mem_type == UADK_AUTO) - ret = wd_digest_init2_(alg_name, SCHED_POLICY_RR, options->task_type, &cparams); - else + if (options->mem_type == UADK_AUTO) { + cparams.op_type_num = 1; + ret = wd_digest_init2_(alg_name, options->sched_type, options->task_type, &cparams); + } else ret = wd_digest_init2_(alg_name, SCHED_POLICY_DEV, options->task_type, &cparams); if (ret) SEC_TST_PRT("failed to do digest init2!\n"); break; + case DIGEST_INSTR_TYPE: + ret = wd_digest_init2_(alg_name, options->sched_type, options->task_type, &cparams); + if (ret) + SEC_TST_PRT("failed to do digest instruction init2!\n"); + break; } if (ret) { SEC_TST_PRT("failed to do cipher init2!\n"); @@ -931,7 +952,6 @@ out_freectx: free(ctx_set_num); return ret; - } static void get_aead_data(u8 *addr, u32 size) @@ -1662,12 +1682,14 @@ static void *sec_uadk_poll(void *data) switch(pdata->subtype) { case CIPHER_TYPE: + case CIPHER_INSTR_TYPE: uadk_poll_ctx = wd_cipher_poll_ctx; break; case AEAD_TYPE: uadk_poll_ctx = wd_aead_poll_ctx; break; case DIGEST_TYPE: + case DIGEST_INSTR_TYPE: uadk_poll_ctx = wd_digest_poll_ctx; break; default: @@ -1715,6 +1737,12 @@ static void *sec_uadk_poll2(void *data) case DIGEST_TYPE: uadk_poll_policy = wd_digest_poll; break; + case CIPHER_INSTR_TYPE: + uadk_poll_policy = wd_cipher_poll; + break; + case DIGEST_INSTR_TYPE: + uadk_poll_policy = wd_digest_poll; + break; default: SEC_TST_PRT("<<<<<<async poll interface is NULL!\n"); return NULL; @@ -2362,6 +2390,7 @@ 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: @@ -2418,12 +2447,14 @@ int sec_uadk_async_threads(struct acc_option *options) switch (options->subtype) { case CIPHER_TYPE: + case CIPHER_INSTR_TYPE: uadk_sec_async_run = sec_uadk_cipher_async; break; case AEAD_TYPE: uadk_sec_async_run = sec_uadk_aead_async; break; case DIGEST_TYPE: + case DIGEST_INSTR_TYPE: uadk_sec_async_run = sec_uadk_digest_async; break; } diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c index 09e99e2..a38cb3e 100644 --- a/uadk_tool/benchmark/uadk_benchmark.c +++ b/uadk_tool/benchmark/uadk_benchmark.c @@ -21,6 +21,9 @@ /*----------------------------------------head struct--------------------------------------------------------*/ static unsigned int g_run_state = 1; static struct acc_option *g_run_options; +static __u64 g_total_sent; +static __u64 g_total_recv; +static __u64 g_send_stopped; static pthread_mutex_t acc_mutex = PTHREAD_MUTEX_INITIALIZER; static struct _recv_data { double pkg_len; @@ -132,7 +135,7 @@ static struct acc_alg_item alg_options[] = { {"ofb(sm4)", "sm4-128-ofb", SM4_128_OFB}, {"cfb(sm4)", "sm4-128-cfb", SM4_128_CFB}, {"xts(sm4)", "sm4-128-xts", SM4_128_XTS}, - {"xts(sm4)", "sm4-128-xts-gb", SM4_128_XTS_GB}, + {"xts-gb(sm4)", "sm4-128-xts-gb", SM4_128_XTS_GB}, {"ccm(aes)", "aes-128-ccm", AES_128_CCM}, {"ccm(aes)", "aes-192-ccm", AES_192_CCM}, {"ccm(aes)", "aes-256-ccm", AES_256_CCM}, @@ -188,6 +191,9 @@ void init_recv_data(void) g_recv_data.pkg_len = 0.0; g_recv_data.send_times = 0; g_recv_data.recv_times = 0; + __atomic_store_n(&g_total_sent, 0, __ATOMIC_RELEASE); + __atomic_store_n(&g_total_recv, 0, __ATOMIC_RELEASE); + __atomic_store_n(&g_send_stopped, 0, __ATOMIC_RELEASE); } int get_run_state(void) @@ -200,6 +206,36 @@ void set_run_state(int state) g_run_state = state; } +void add_total_sent(__u32 cnt) +{ + __atomic_add_fetch(&g_total_sent, cnt, __ATOMIC_RELEASE); +} + +__u64 get_total_sent(void) +{ + return __atomic_load_n(&g_total_sent, __ATOMIC_ACQUIRE); +} + +void add_total_recv(__u32 cnt) +{ + __atomic_add_fetch(&g_total_recv, cnt, __ATOMIC_RELEASE); +} + +__u64 get_total_recv(void) +{ + return __atomic_load_n(&g_total_recv, __ATOMIC_ACQUIRE); +} + +void add_send_stopped(void) +{ + __atomic_add_fetch(&g_send_stopped, 1, __ATOMIC_RELEASE); +} + +__u64 get_send_stopped(void) +{ + return __atomic_load_n(&g_send_stopped, __ATOMIC_ACQUIRE); +} + int uadk_parse_dev_id(char *dev_name) { char *last_dash = NULL; @@ -359,7 +395,7 @@ void get_rand_data(u8 *addr, u32 size) } for (i = 0; i < num_u64; i++) { - /* Use nrand48��it will auto update rand_state */ + /* Use nrand48, it will auto update rand_state */ rand48_result = nrand48(rand_state); *((u64 *)addr + i) = rand48_result; } @@ -479,10 +515,17 @@ 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) + if (option->modetype == INSTR_MODE) { + option->subtype = CIPHER_INSTR_TYPE; + option->sched_type = SCHED_POLICY_NONE; + option->task_type = TASK_INSTR; + } else if (option->modetype == MULTIBUF_MODE) { option->subtype = CIPHER_INSTR_TYPE; - else + option->sched_type = SCHED_POLICY_SINGLE; + option->task_type = TASK_INSTR; + } else { option->subtype = CIPHER_TYPE; + } option->acctype = SEC_TYPE; } else if (option->algtype <= SM4_128_GCM) { snprintf(option->algclass, MAX_ALG_NAME, "%s", "aead"); @@ -493,9 +536,11 @@ static void parse_alg_param(struct acc_option *option) option->subtype = DIGEST_TYPE; option->acctype = SEC_TYPE; if (option->modetype == INSTR_MODE) { + option->subtype = DIGEST_INSTR_TYPE; option->sched_type = SCHED_POLICY_NONE; option->task_type = TASK_INSTR; } else if (option->modetype == MULTIBUF_MODE) { + option->subtype = DIGEST_INSTR_TYPE; option->sched_type = SCHED_POLICY_SINGLE; option->task_type = TASK_INSTR; } @@ -611,6 +656,8 @@ static void dump_param(struct acc_option *option) ACC_TST_PRT(" [--latency]: %u\n", option->latency); ACC_TST_PRT(" [--init2]: %u\n", option->inittype); ACC_TST_PRT(" [--device]: %s\n", option->device); + ACC_TST_PRT(" [--sched]: %u\n", option->sched_type); + ACC_TST_PRT(" [--task]: %u\n", option->task_type); } int acc_benchmark_run(struct acc_option *option) @@ -620,8 +667,6 @@ 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; @@ -694,6 +739,8 @@ int acc_default_case(struct acc_option *option) option->multis = 1; option->ctxnums = 2; option->inittype = INIT_TYPE; + option->sched_type = SCHED_POLICY_RR; + option->task_type = TASK_HW; return acc_benchmark_run(option); } @@ -739,6 +786,12 @@ void print_benchmark_help(void) 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(" [--memory]:\n"); + ACC_TST_PRT(" set memory type to do task\n"); + ACC_TST_PRT(" [--sched 0~6]:\n"); + ACC_TST_PRT(" set scheduler policy (0:RR 1:NONE 2:SINGLE 3:DEV 4:LOOP 5:HUNGRY 6:INSTR)\n"); + ACC_TST_PRT(" [--task 0~2]:\n"); + ACC_TST_PRT(" set task type (0:MIX 1:HW 2:INSTR)\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"); @@ -783,6 +836,8 @@ int acc_cmd_parse(int argc, char *argv[], struct acc_option *option) {"device", required_argument, 0, 18}, {"memory", required_argument, 0, 19}, {"sgl", no_argument, 0, 20}, + {"sched", required_argument, 0, 21}, + {"task", required_argument, 0, 22}, {0, 0, 0, 0} }; @@ -860,6 +915,12 @@ int acc_cmd_parse(int argc, char *argv[], struct acc_option *option) case 20: option->data_fmt = WD_SGL_BUF; break; + case 21: + option->sched_type = strtol(optarg, NULL, 0); + break; + case 22: + option->task_type = strtol(optarg, NULL, 0); + break; default: ACC_TST_PRT("invalid: bad input parameter!\n"); print_benchmark_help(); @@ -942,6 +1003,14 @@ int acc_option_convert(struct acc_option *option) goto param_err; } + if (option->sched_type >= SCHED_POLICY_BUTT) { + ACC_TST_PRT("uadk benchmark scheduler type set error!\n"); + goto param_err; + } + + if (option->task_type >= TASK_MAX_TYPE) + option->task_type = TASK_HW; + return 0; param_err: diff --git a/uadk_tool/benchmark/uadk_benchmark.h b/uadk_tool/benchmark/uadk_benchmark.h index 83fd7fa..e06c0ea 100644 --- a/uadk_tool/benchmark/uadk_benchmark.h +++ b/uadk_tool/benchmark/uadk_benchmark.h @@ -117,6 +117,7 @@ enum alg_type { X25519_TYPE, X448_TYPE, CIPHER_INSTR_TYPE, + DIGEST_INSTR_TYPE, }; enum sync_type { @@ -229,6 +230,12 @@ 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 add_total_sent(u32 cnt); +extern u64 get_total_sent(void); +extern void add_total_recv(u32 cnt); +extern u64 get_total_recv(void); +extern void add_send_stopped(void); +extern u64 get_send_stopped(void); extern void cal_avg_latency(u32 count); extern int get_alg_name(int alg, char *alg_name); extern void segmentfault_handler(int sig); diff --git a/uadk_tool/benchmark/zip_uadk_benchmark.c b/uadk_tool/benchmark/zip_uadk_benchmark.c index d0f1795..86e6404 100644 --- a/uadk_tool/benchmark/zip_uadk_benchmark.c +++ b/uadk_tool/benchmark/zip_uadk_benchmark.c @@ -20,7 +20,8 @@ #define MAX_POOL_LENTH_COMP 1 #define COMPRESSION_RATIO_FACTOR 0.7 #define CHUNK_SIZE (128 * 1024) -#define MAX_UNRECV_PACKET_NUM 1 +#define MAX_DRAIN_RETRY 10000 +#define ZIP_ASYNC_DRAIN_RETRY MAX_DRAIN_RETRY struct uadk_bd { u8 *src; u8 *dst; @@ -42,11 +43,6 @@ enum ZIP_OP_MODE { STREAM_MODE }; -enum ZIP_THREAD_STATE { - THREAD_PROCESSING, - THREAD_COMPLETED -}; - struct zip_async_tag { handle_t sess; u32 td_id; @@ -83,7 +79,6 @@ 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; static unsigned int g_dev_id; static unsigned int g_data_fmt; @@ -397,7 +392,7 @@ static int init_ctx_config2(struct acc_option *options) /* init */ if (options->mem_type == UADK_AUTO) - ret = wd_comp_init2_(alg_name, SCHED_POLICY_RR, TASK_HW, &cparams); + ret = wd_comp_init2_(alg_name, options->sched_type, options->task_type, &cparams); else ret = wd_comp_init2_(alg_name, SCHED_POLICY_DEV, TASK_HW, &cparams); if (ret) { @@ -982,19 +977,48 @@ static void *zip_uadk_poll(void *data) u32 id = pdata->td_id; u32 count = 0; u32 recv = 0; + u32 drain_retry = 0; int ret; if (id > g_ctxnum) return NULL; - while (g_state == THREAD_PROCESSING) { + while (1) { ret = wd_comp_poll_ctx(id, expt, &recv); count += recv; recv = 0; if (unlikely(ret != -WD_EAGAIN && ret < 0)) { ZIP_TST_PRT("poll ret: %d!\n", ret); + add_total_recv(count); goto recv_error; } + if (get_run_state() == 0) { + add_total_recv(count); + break; + } + } + + while (get_send_stopped() != g_thread_num || + get_total_recv() < get_total_sent()) { + ret = wd_comp_poll_ctx(id, expt, &recv); + if (unlikely(ret != -WD_EAGAIN && ret < 0)) { + ZIP_TST_PRT("poll ret: %d!\n", ret); + goto recv_error; + } + if (recv == 0) { + usleep(SEND_USLEEP); + drain_retry++; + } else { + add_total_recv(recv); + drain_retry = 0; + recv = 0; + } + if (drain_retry >= ZIP_ASYNC_DRAIN_RETRY) { + ZIP_TST_PRT("drain timeout: sent=%llu recv=%llu stopped=%llu/%u\n", + get_total_sent(), get_total_recv(), + get_send_stopped(), g_thread_num); + break; + } } recv_error: @@ -1008,16 +1032,45 @@ static void *zip_uadk_poll2(void *data) u32 expt = ACC_QUEUE_SIZE * g_thread_num; u32 count = 0; u32 recv = 0; + u32 drain_retry = 0; int ret; - while (g_state == THREAD_PROCESSING) { + while (1) { ret = wd_comp_poll(expt, &recv); count += recv; recv = 0; if (unlikely(ret != -WD_EAGAIN && ret < 0)) { ZIP_TST_PRT("poll ret: %d!\n", ret); + add_total_recv(count); goto recv_error; } + if (get_run_state() == 0) { + add_total_recv(count); + break; + } + } + + while (get_send_stopped() != g_thread_num || + get_total_recv() < get_total_sent()) { + ret = wd_comp_poll(expt, &recv); + if (unlikely(ret != -WD_EAGAIN && ret < 0)) { + ZIP_TST_PRT("poll ret: %d!\n", ret); + goto recv_error; + } + if (recv == 0) { + usleep(SEND_USLEEP); + drain_retry++; + } else { + add_total_recv(recv); + drain_retry = 0; + recv = 0; + } + if (drain_retry >= ZIP_ASYNC_DRAIN_RETRY) { + ZIP_TST_PRT("drain timeout: sent=%llu recv=%llu stopped=%llu/%u\n", + get_total_sent(), get_total_recv(), + get_send_stopped(), g_thread_num); + break; + } } recv_error: @@ -1331,6 +1384,15 @@ static void *zip_uadk_blk_lz77_async_run(void *arg) count++; __atomic_add_fetch(&pdata->send_cnt, 1, __ATOMIC_RELAXED); } + + add_total_sent(count); + add_send_stopped(); + + if (count) { + while (get_recv_time() != g_ctxnum) + usleep(SEND_USLEEP); + } + wd_comp_free_sess(h_sess); add_send_complete(); @@ -1574,6 +1636,14 @@ static void *zip_uadk_blk_async_run(void *arg) __atomic_add_fetch(&pdata->send_cnt, 1, __ATOMIC_RELAXED); } + add_total_sent(count); + add_send_stopped(); + + if (count) { + while (get_recv_time() != g_ctxnum) + usleep(SEND_USLEEP); + } + wd_comp_free_sess(h_sess); add_send_complete(); @@ -1726,14 +1796,6 @@ static int zip_uadk_async_threads(struct acc_option *options) } } - /* 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) { -- 2.43.0