From: Longfang Liu liulongfang@huawei.com
Update the performance test code of sec's no-sva mode, and optimize the performance test code of sec's no-sva mode by splitting sub-functions.
Signed-off-by: Longfang Liu liulongfang@huawei.com Signed-off-by: Zhiqi Song songzhiqi1@huawei.com --- uadk_tool/benchmark/sec_wd_benchmark.c | 934 +++++++++++++++---------- 1 file changed, 556 insertions(+), 378 deletions(-)
diff --git a/uadk_tool/benchmark/sec_wd_benchmark.c b/uadk_tool/benchmark/sec_wd_benchmark.c index d2da73b..6d3f8da 100644 --- a/uadk_tool/benchmark/sec_wd_benchmark.c +++ b/uadk_tool/benchmark/sec_wd_benchmark.c @@ -14,6 +14,7 @@ #define MAX_IVK_LENTH 64 #define DEF_IVK_DATA 0xAA #define SQE_SIZE 128 +#define SEC_PERF_KEY_LEN 16
typedef struct wd_thread_res { u32 subtype; @@ -23,6 +24,9 @@ typedef struct wd_thread_res { u32 ivsize; u32 optype; u32 td_id; + bool is_union; + u32 dalg; + u32 dmode; } thread_data;
struct thread_bd_res { @@ -47,6 +51,9 @@ static struct thread_queue_res g_thread_queue; static unsigned int g_thread_num; static unsigned int g_pktlen;
+static char wd_aead_key[] = "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7" + "\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"; + static void *cipher_async_cb(void *message, void *cipher_tag) { return NULL; @@ -547,15 +554,11 @@ recv_error: return NULL; }
-static void *sec_wd_async_run(void *arg) +static void *sec_wd_cipher_async(void *arg) { thread_data *pdata = (thread_data *)arg; struct wcrypto_cipher_ctx_setup cipher_setup = {0}; - struct wcrypto_aead_ctx_setup aead_setup = {0}; - struct wcrypto_digest_ctx_setup digest_setup = {0}; struct wcrypto_cipher_op_data copdata; - struct wcrypto_aead_op_data aopdata; - struct wcrypto_digest_op_data dopdata; struct wcrypto_async_tag *tag = NULL; char priv_key[MAX_IVK_LENTH]; struct thread_bd_res *bd_res; @@ -566,7 +569,6 @@ static void *sec_wd_async_run(void *arg) void **res_iv; u32 count = 0; int try_cnt = 0; - u32 authsize; int ret, i = 0; void *pool;
@@ -588,211 +590,305 @@ static void *sec_wd_async_run(void *arg) } tag->thread_id = pdata->td_id;
- switch(pdata->subtype) { - case CIPHER_TYPE: - cipher_setup.alg = pdata->alg; - cipher_setup.mode = pdata->mode; - cipher_setup.cb = (void *)cipher_async_cb; - cipher_setup.br.alloc = (void *)wd_alloc_blk; - cipher_setup.br.free = (void *)wd_free_blk; - cipher_setup.br.iova_map = (void *)wd_blk_iova_map; - cipher_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; - cipher_setup.br.get_bufsize = (void *)wd_blksize; - cipher_setup.br.usr = pool; - - ctx = wcrypto_create_cipher_ctx(queue, &cipher_setup); - if (!ctx) { - SEC_TST_PRT("wd create cipher ctx fail!\n"); - return NULL; - } - tag->ctx = ctx; + cipher_setup.alg = pdata->alg; + cipher_setup.mode = pdata->mode; + cipher_setup.cb = (void *)cipher_async_cb; + cipher_setup.br.alloc = (void *)wd_alloc_blk; + cipher_setup.br.free = (void *)wd_free_blk; + cipher_setup.br.iova_map = (void *)wd_blk_iova_map; + cipher_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; + cipher_setup.br.get_bufsize = (void *)wd_blksize; + cipher_setup.br.usr = pool; + + ctx = wcrypto_create_cipher_ctx(queue, &cipher_setup); + if (!ctx) { + SEC_TST_PRT("wd create cipher ctx fail!\n"); + return NULL; + } + tag->ctx = ctx;
- ret = wcrypto_set_cipher_key(ctx, (__u8*)priv_key, (__u16)pdata->keysize); - if (ret) { - SEC_TST_PRT("wd cipher set key fail!\n"); - wcrypto_del_cipher_ctx(ctx); - return NULL; + ret = wcrypto_set_cipher_key(ctx, (__u8*)priv_key, (__u16)pdata->keysize); + if (ret) { + SEC_TST_PRT("wd cipher set key fail!\n"); + wcrypto_del_cipher_ctx(ctx); + return NULL; + } + + if (queue->capa.priv.direction == 0) + copdata.op_type = WCRYPTO_CIPHER_ENCRYPTION; + else + copdata.op_type = WCRYPTO_CIPHER_DECRYPTION; + + copdata.in_bytes = g_pktlen; + copdata.out_bytes = g_pktlen; + copdata.iv_bytes = pdata->ivsize; + copdata.priv = NULL; + + tag->cnt = 0; + copdata.in = res_in[0]; + copdata.out = res_out[0]; + copdata.iv = res_iv[0]; + usleep(SEND_USLEEP); + while(1) { + if (get_run_state() == 0) + break; + + ret = wcrypto_do_cipher(ctx, &copdata, (void *)tag); + if (ret == -WD_EBUSY) { + usleep(SEND_USLEEP * try_cnt); + try_cnt++; + if (try_cnt > MAX_TRY_CNT) { + SEC_TST_PRT("Test cipher send fail %d times!\n", MAX_TRY_CNT); + try_cnt = 0; + } + continue; }
- if (queue->capa.priv.direction == 0) - copdata.op_type = WCRYPTO_CIPHER_ENCRYPTION; - else - copdata.op_type = WCRYPTO_CIPHER_DECRYPTION; + count++; + i = count % MAX_POOL_LENTH; + tag->cnt = i; + try_cnt = 0; + copdata.in = res_in[i]; + copdata.out = res_out[i]; + copdata.iv = res_iv[i]; + }
- copdata.in_bytes = g_pktlen; - copdata.out_bytes = g_pktlen; - copdata.iv_bytes = pdata->ivsize; - copdata.priv = NULL; + add_send_complete();
- tag->cnt = 0; - copdata.in = res_in[0]; - copdata.out = res_out[0]; - copdata.iv = res_iv[0]; + while (1) { + if (get_recv_time() > 0) // wait async mode finish recv + break; usleep(SEND_USLEEP); - while(1) { - if (get_run_state() == 0) - break; - - ret = wcrypto_do_cipher(ctx, &copdata, (void *)tag); - if (ret == -WD_EBUSY) { - usleep(SEND_USLEEP * try_cnt); - try_cnt++; - if (try_cnt > MAX_TRY_CNT) { - SEC_TST_PRT("Test cipher send fail %d times!\n", MAX_TRY_CNT); - try_cnt = 0; - } - continue; - } + }
- count++; - i = count % MAX_POOL_LENTH; - tag->cnt = i; - try_cnt = 0; - copdata.in = res_in[i]; - copdata.out = res_out[i]; - copdata.iv = res_iv[i]; - } + wcrypto_del_cipher_ctx(ctx);
- break; - case AEAD_TYPE: // just ccm and gcm - aead_setup.calg = pdata->alg; - aead_setup.cmode = pdata->mode; - aead_setup.cb = (void *)aead_async_cb; - aead_setup.br.alloc = (void *)wd_alloc_blk; - aead_setup.br.free = (void *)wd_free_blk; - aead_setup.br.iova_map = (void *)wd_blk_iova_map; - aead_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; - aead_setup.br.get_bufsize = (void *)wd_blksize; - aead_setup.br.usr = pool; - - ctx = wcrypto_create_aead_ctx(queue, &aead_setup); - if (!ctx) { - SEC_TST_PRT("wd create aead ctx fail!\n"); - return NULL; - } - tag->ctx = ctx; + return NULL; +}
- ret = wcrypto_set_aead_ckey(ctx, (__u8*)priv_key, (__u16)pdata->keysize); - if (ret) { - SEC_TST_PRT("wd aead set key fail!\n"); - wcrypto_del_aead_ctx(ctx); - return NULL; - } +static void *sec_wd_aead_async(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + struct wcrypto_aead_ctx_setup aead_setup = {0}; + struct wcrypto_aead_op_data aopdata; + struct wcrypto_async_tag *tag = NULL; + char priv_key[MAX_IVK_LENTH]; + char priv_hash[MAX_IVK_LENTH]; + struct thread_bd_res *bd_res; + struct wd_queue *queue; + void *ctx = NULL; + void **res_in; + void **res_out; + void **res_iv; + u32 count = 0; + int try_cnt = 0; + u32 authsize; + int ret, i = 0; + void *pool;
- authsize = 16; //set defaut size - ret = wcrypto_aead_setauthsize(ctx, authsize); - if (ret) { - SEC_TST_PRT("set authsize fail!\n"); - wcrypto_del_aead_ctx(ctx); - return NULL; - } + if (pdata->td_id > g_thread_num) + return NULL; + + bd_res = &g_thread_queue.bd_res[pdata->td_id]; + queue = bd_res->queue; + pool = bd_res->pool; + res_in = bd_res->in; + res_out = bd_res->out; + res_iv = bd_res->iv; + + memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH); + memset(priv_hash, DEF_IVK_DATA, MAX_IVK_LENTH); + tag = malloc(sizeof(struct wcrypto_async_tag)); // set the user tag + if (!tag) { + SEC_TST_PRT("wcrypto async alloc tag fail!\n"); + return NULL; + } + tag->thread_id = pdata->td_id; + + aead_setup.calg = pdata->alg; + aead_setup.cmode = pdata->mode; + aead_setup.cb = (void *)aead_async_cb; + aead_setup.br.alloc = (void *)wd_alloc_blk; + aead_setup.br.free = (void *)wd_free_blk; + aead_setup.br.iova_map = (void *)wd_blk_iova_map; + aead_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; + aead_setup.br.get_bufsize = (void *)wd_blksize; + aead_setup.br.usr = pool; + if (pdata->is_union) { + aead_setup.dalg = pdata->dalg; + aead_setup.dmode = pdata->dmode; + } + + + ctx = wcrypto_create_aead_ctx(queue, &aead_setup); + if (!ctx) { + SEC_TST_PRT("wd create aead ctx fail!\n"); + return NULL; + } + tag->ctx = ctx; + + ret = wcrypto_set_aead_ckey(ctx, (__u8*)priv_key, (__u16)pdata->keysize); + if (ret) { + SEC_TST_PRT("wd aead set key fail!\n"); + wcrypto_del_aead_ctx(ctx); + return NULL; + } + + authsize = 16; //set defaut size + ret = wcrypto_aead_setauthsize(ctx, authsize); + if (ret) { + SEC_TST_PRT("set authsize fail!\n"); + wcrypto_del_aead_ctx(ctx); + return NULL; + }
- if (queue->capa.priv.direction == 0) { - aopdata.op_type = WCRYPTO_CIPHER_ENCRYPTION_DIGEST; - aopdata.out_bytes = g_pktlen + 32; // aad + plen + authsize; - } else { + if (queue->capa.priv.direction == 0) { + aopdata.op_type = WCRYPTO_CIPHER_ENCRYPTION_DIGEST; + aopdata.out_bytes = g_pktlen + 32; // aad + plen + authsize; + } else { aopdata.op_type = WCRYPTO_CIPHER_DECRYPTION_DIGEST; aopdata.out_bytes = g_pktlen + 16; // aad + plen; }
- aopdata.assoc_size = 16; - aopdata.in_bytes = g_pktlen; - aopdata.out_bytes = g_pktlen; - aopdata.iv_bytes = pdata->ivsize; - aopdata.priv = NULL; - aopdata.out_buf_bytes = g_pktlen * 2; - - tag->cnt = 0; - aopdata.in = res_in[0]; - aopdata.out = res_out[0]; - aopdata.iv = res_iv[0]; - usleep(SEND_USLEEP); - while(1) { - if (get_run_state() == 0) - break; - - ret = wcrypto_do_aead(ctx, &aopdata, (void *)tag); - if (ret == -WD_EBUSY) { - usleep(SEND_USLEEP * try_cnt); - try_cnt++; - if (try_cnt > MAX_TRY_CNT) { - SEC_TST_PRT("Test aead send fail %d times!\n", MAX_TRY_CNT); - try_cnt = 0; - } - continue; - } + aopdata.assoc_size = 16; + aopdata.in_bytes = g_pktlen; + aopdata.out_bytes = g_pktlen; + aopdata.iv_bytes = pdata->ivsize; + aopdata.priv = NULL; + aopdata.out_buf_bytes = g_pktlen * 2; + + tag->cnt = 0; + aopdata.in = res_in[0]; + aopdata.out = res_out[0]; + aopdata.iv = res_iv[0]; + usleep(SEND_USLEEP); + while(1) { + if (get_run_state() == 0) + break;
- count++; - i = count % MAX_POOL_LENTH; - tag->cnt = i; - try_cnt = 0; - aopdata.in = res_in[i]; - aopdata.out = res_out[i]; - aopdata.iv = res_iv[i]; + ret = wcrypto_do_aead(ctx, &aopdata, (void *)tag); + if (ret == -WD_EBUSY) { + usleep(SEND_USLEEP * try_cnt); + try_cnt++; + if (try_cnt > MAX_TRY_CNT) { + SEC_TST_PRT("Test aead send fail %d times!\n", MAX_TRY_CNT); + try_cnt = 0; + } + continue; }
- break; - case DIGEST_TYPE: - digest_setup.alg = pdata->alg; - digest_setup.mode = pdata->mode; - digest_setup.cb = (void *)digest_async_cb; - digest_setup.br.alloc = (void *)wd_alloc_blk; - digest_setup.br.free = (void *)wd_free_blk; - digest_setup.br.iova_map = (void *)wd_blk_iova_map; - digest_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; - digest_setup.br.get_bufsize = (void *)wd_blksize; - digest_setup.br.usr = pool; - - ctx = wcrypto_create_digest_ctx(queue, &digest_setup); - if (!ctx) { - SEC_TST_PRT("wd create digest ctx fail!\n"); + count++; + i = count % MAX_POOL_LENTH; + tag->cnt = i; + try_cnt = 0; + aopdata.in = res_in[i]; + aopdata.out = res_out[i]; + aopdata.iv = res_iv[i]; + } + + add_send_complete(); + + while (1) { + if (get_recv_time() > 0) // wait async mode finish recv + break; + usleep(SEND_USLEEP); + } + + wcrypto_del_aead_ctx(ctx); + + return NULL; +} + +static void *sec_wd_digest_async(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + struct wcrypto_digest_ctx_setup digest_setup = {0}; + struct wcrypto_digest_op_data dopdata; + struct wcrypto_async_tag *tag = NULL; + char priv_key[MAX_IVK_LENTH]; + struct thread_bd_res *bd_res; + struct wd_queue *queue; + void *ctx = NULL; + void **res_in; + void **res_out; + u32 count = 0; + int try_cnt = 0; + int ret, i = 0; + void *pool; + + if (pdata->td_id > g_thread_num) + return NULL; + + bd_res = &g_thread_queue.bd_res[pdata->td_id]; + queue = bd_res->queue; + pool = bd_res->pool; + res_in = bd_res->in; + res_out = bd_res->out; + + memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH); + tag = malloc(sizeof(struct wcrypto_async_tag)); // set the user tag + if (!tag) { + SEC_TST_PRT("wcrypto async alloc tag fail!\n"); + return NULL; + } + tag->thread_id = pdata->td_id; + + digest_setup.alg = pdata->alg; + digest_setup.mode = pdata->mode; + digest_setup.cb = (void *)digest_async_cb; + digest_setup.br.alloc = (void *)wd_alloc_blk; + digest_setup.br.free = (void *)wd_free_blk; + digest_setup.br.iova_map = (void *)wd_blk_iova_map; + digest_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; + digest_setup.br.get_bufsize = (void *)wd_blksize; + digest_setup.br.usr = pool; + + ctx = wcrypto_create_digest_ctx(queue, &digest_setup); + if (!ctx) { + SEC_TST_PRT("wd create digest ctx fail!\n"); + return NULL; + } + tag->ctx = ctx; + + if (digest_setup.mode == WCRYPTO_DIGEST_HMAC) { + ret = wcrypto_set_digest_key(ctx, (__u8*)priv_key, + (__u16)pdata->keysize); + if (ret) { + SEC_TST_PRT("wd digest set key fail!\n"); + wcrypto_del_digest_ctx(ctx); return NULL; } - tag->ctx = ctx; - - if (digest_setup.mode == WCRYPTO_DIGEST_HMAC) { - ret = wcrypto_set_digest_key(ctx, (__u8*)priv_key, - (__u16)pdata->keysize); - if (ret) { - SEC_TST_PRT("wd digest set key fail!\n"); - wcrypto_del_digest_ctx(ctx); - return NULL; - } - } + }
- dopdata.in_bytes = g_pktlen; - dopdata.out_bytes = 16; - dopdata.has_next = 0; - dopdata.priv = NULL; + dopdata.in_bytes = g_pktlen; + dopdata.out_bytes = 16; + dopdata.has_next = 0; + dopdata.priv = NULL; + tag->cnt = 0; + dopdata.in = res_in[0]; + dopdata.out = res_out[0]; + usleep(SEND_USLEEP); + while(1) { + if (get_run_state() == 0) + break;
- tag->cnt = 0; - dopdata.in = res_in[0]; - dopdata.out = res_out[0]; - usleep(SEND_USLEEP); - while(1) { - if (get_run_state() == 0) - break; - - ret = wcrypto_do_digest(ctx, &dopdata, (void *)tag); - if (ret == -WD_EBUSY) { - usleep(SEND_USLEEP * try_cnt); - try_cnt++; - if (try_cnt > MAX_TRY_CNT) { - SEC_TST_PRT("Test digest send fail %d times!\n", MAX_TRY_CNT); - try_cnt = 0; - } - continue; + ret = wcrypto_do_digest(ctx, &dopdata, (void *)tag); + if (ret == -WD_EBUSY) { + usleep(SEND_USLEEP * try_cnt); + try_cnt++; + if (try_cnt > MAX_TRY_CNT) { + SEC_TST_PRT("Test digest send fail %d times!\n", MAX_TRY_CNT); + try_cnt = 0; } - - count++; - i = count % MAX_POOL_LENTH; - tag->cnt = i; - try_cnt = 0; - dopdata.in = res_in[i]; - dopdata.out = res_out[i]; + continue; }
- break; + count++; + i = count % MAX_POOL_LENTH; + tag->cnt = i; + try_cnt = 0; + dopdata.in = res_in[i]; + dopdata.out = res_out[i]; }
add_send_complete(); @@ -803,30 +899,16 @@ static void *sec_wd_async_run(void *arg) usleep(SEND_USLEEP); }
- switch(pdata->subtype) { - case CIPHER_TYPE: - wcrypto_del_cipher_ctx(ctx); - break; - case AEAD_TYPE: - wcrypto_del_aead_ctx(ctx); - break; - case DIGEST_TYPE: - wcrypto_del_digest_ctx(ctx); - break; - } + wcrypto_del_digest_ctx(ctx);
return NULL; }
-static void *sec_wd_sync_run(void *arg) +static void *sec_wd_cipher_sync(void *arg) { thread_data *pdata = (thread_data *)arg; struct wcrypto_cipher_ctx_setup cipher_setup = {0}; - struct wcrypto_aead_ctx_setup aead_setup = {0}; - struct wcrypto_digest_ctx_setup digest_setup = {0}; struct wcrypto_cipher_op_data copdata; - struct wcrypto_aead_op_data aopdata; - struct wcrypto_digest_op_data dopdata; char priv_key[MAX_IVK_LENTH]; struct thread_bd_res *bd_res; struct wd_queue *queue; @@ -837,7 +919,6 @@ static void *sec_wd_sync_run(void *arg) void **res_iv; u32 count = 0; int try_cnt = 0; - u32 authsize; int ret, i = 0; void *pool;
@@ -853,203 +934,272 @@ static void *sec_wd_sync_run(void *arg)
memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
- switch(pdata->subtype) { - case CIPHER_TYPE: - cipher_setup.alg = pdata->alg; - cipher_setup.mode = pdata->mode; - cipher_setup.br.alloc = (void *)wd_alloc_blk; - cipher_setup.br.free = (void *)wd_free_blk; - cipher_setup.br.iova_map = (void *)wd_blk_iova_map; - cipher_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; - cipher_setup.br.get_bufsize = (void *)wd_blksize; - cipher_setup.br.usr = pool; - - ctx = wcrypto_create_cipher_ctx(queue, &cipher_setup); - if (!ctx) { - SEC_TST_PRT("wd create cipher ctx fail!\n"); - return NULL; - } + cipher_setup.alg = pdata->alg; + cipher_setup.mode = pdata->mode; + cipher_setup.br.alloc = (void *)wd_alloc_blk; + cipher_setup.br.free = (void *)wd_free_blk; + cipher_setup.br.iova_map = (void *)wd_blk_iova_map; + cipher_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; + cipher_setup.br.get_bufsize = (void *)wd_blksize; + cipher_setup.br.usr = pool; + + ctx = wcrypto_create_cipher_ctx(queue, &cipher_setup); + if (!ctx) { + SEC_TST_PRT("wd create cipher ctx fail!\n"); + return NULL; + }
- ret = wcrypto_set_cipher_key(ctx, (__u8*)priv_key, (__u16)pdata->keysize); - if (ret) { - SEC_TST_PRT("wd cipher set key fail!\n"); - wcrypto_del_cipher_ctx(ctx); - return NULL; + ret = wcrypto_set_cipher_key(ctx, (__u8*)priv_key, (__u16)pdata->keysize); + if (ret) { + SEC_TST_PRT("wd cipher set key fail!\n"); + wcrypto_del_cipher_ctx(ctx); + return NULL; + } + + if (queue->capa.priv.direction == 0) + copdata.op_type = WCRYPTO_CIPHER_ENCRYPTION; + else + copdata.op_type = WCRYPTO_CIPHER_DECRYPTION; + + copdata.in_bytes = g_pktlen; + copdata.out_bytes = g_pktlen; + copdata.iv_bytes = pdata->ivsize; + copdata.priv = NULL; + + copdata.in = res_in[0]; + copdata.out = res_out[0]; + copdata.iv = res_iv[0]; + usleep(SEND_USLEEP); + while(1) { + if (get_run_state() == 0) + break; + + ret = wcrypto_do_cipher(ctx, &copdata, tag); + if (ret == -WD_EBUSY) { + usleep(SEND_USLEEP * try_cnt); + try_cnt++; + if (try_cnt > MAX_TRY_CNT) { + SEC_TST_PRT("Test cipher send fail %d times!\n", MAX_TRY_CNT); + try_cnt = 0; + } + continue; }
- if (queue->capa.priv.direction == 0) - copdata.op_type = WCRYPTO_CIPHER_ENCRYPTION; - else - copdata.op_type = WCRYPTO_CIPHER_DECRYPTION; + count++; + try_cnt = 0; + i = count % MAX_POOL_LENTH; + copdata.in = res_in[i]; + copdata.out = res_out[i]; + copdata.iv = res_iv[i]; + } + wcrypto_del_cipher_ctx(ctx);
- copdata.in_bytes = g_pktlen; - copdata.out_bytes = g_pktlen; - copdata.iv_bytes = pdata->ivsize; - copdata.priv = NULL; + add_recv_data(count, g_pktlen);
- copdata.in = res_in[0]; - copdata.out = res_out[0]; - copdata.iv = res_iv[0]; - usleep(SEND_USLEEP); - while(1) { - if (get_run_state() == 0) - break; - - ret = wcrypto_do_cipher(ctx, &copdata, tag); - if (ret == -WD_EBUSY) { - usleep(SEND_USLEEP * try_cnt); - try_cnt++; - if (try_cnt > MAX_TRY_CNT) { - SEC_TST_PRT("Test cipher send fail %d times!\n", MAX_TRY_CNT); - try_cnt = 0; - } - continue; - } + return NULL; +}
- count++; - try_cnt = 0; - i = count % MAX_POOL_LENTH; - copdata.in = res_in[i]; - copdata.out = res_out[i]; - copdata.iv = res_iv[i]; - } - wcrypto_del_cipher_ctx(ctx); +static void *sec_wd_aead_sync(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + struct wcrypto_aead_ctx_setup aead_setup = {0}; + struct wcrypto_aead_op_data aopdata; + char priv_key[MAX_IVK_LENTH]; + char priv_hash[MAX_IVK_LENTH]; + struct thread_bd_res *bd_res; + struct wd_queue *queue; + void *ctx = NULL; + void *tag = NULL; + void **res_in; + void **res_out; + void **res_iv; + u32 count = 0; + int try_cnt = 0; + u32 authsize; + int ret, i; + void *pool;
- break; - case AEAD_TYPE: // just ccm and gcm - aead_setup.calg = pdata->alg; - aead_setup.cmode = pdata->mode; - aead_setup.br.alloc = (void *)wd_alloc_blk; - aead_setup.br.free = (void *)wd_free_blk; - aead_setup.br.iova_map = (void *)wd_blk_iova_map; - aead_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; - aead_setup.br.get_bufsize = (void *)wd_blksize; - aead_setup.br.usr = pool; - - ctx = wcrypto_create_aead_ctx(queue, &aead_setup); - if (!ctx) { - SEC_TST_PRT("wd create aead ctx fail!\n"); - return NULL; - } + if (pdata->td_id > g_thread_num) + return NULL;
- ret = wcrypto_set_aead_ckey(ctx, (__u8*)priv_key, (__u16)pdata->keysize); - if (ret) { - SEC_TST_PRT("wd aead set key fail!\n"); - wcrypto_del_aead_ctx(ctx); - return NULL; - } + bd_res = &g_thread_queue.bd_res[pdata->td_id]; + queue = bd_res->queue; + pool = bd_res->pool; + res_in = bd_res->in; + res_out = bd_res->out; + res_iv = bd_res->iv;
- authsize = 16; //set defaut size - ret = wcrypto_aead_setauthsize(ctx, authsize); - if (ret) { - SEC_TST_PRT("set authsize fail!\n"); - wcrypto_del_aead_ctx(ctx); - return NULL; - } + memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH); + memcpy(priv_hash, wd_aead_key, SEC_PERF_KEY_LEN); + + aead_setup.calg = pdata->alg; + aead_setup.cmode = pdata->mode; + aead_setup.br.alloc = (void *)wd_alloc_blk; + aead_setup.br.free = (void *)wd_free_blk; + aead_setup.br.iova_map = (void *)wd_blk_iova_map; + aead_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; + aead_setup.br.get_bufsize = (void *)wd_blksize; + aead_setup.br.usr = pool; + if (pdata->is_union) { + aead_setup.dalg = pdata->dalg; + aead_setup.dmode = pdata->dmode; + }
- if (queue->capa.priv.direction == 0) { - aopdata.op_type = WCRYPTO_CIPHER_ENCRYPTION_DIGEST; - aopdata.out_bytes = g_pktlen + 32; // aad + plen + authsize; - } else { - aopdata.op_type = WCRYPTO_CIPHER_DECRYPTION_DIGEST; - aopdata.out_bytes = g_pktlen + 16; // aad + plen; - }
- aopdata.assoc_size = 16; - aopdata.in_bytes = g_pktlen; - aopdata.out_bytes = g_pktlen; - aopdata.iv_bytes = pdata->ivsize; - aopdata.priv = NULL; - aopdata.out_buf_bytes = g_pktlen * 2; + ctx = wcrypto_create_aead_ctx(queue, &aead_setup);
- aopdata.in = res_in[0]; - aopdata.out = res_out[0]; - aopdata.iv = res_iv[0]; - usleep(SEND_USLEEP); - while(1) { - if (get_run_state() == 0) - break; - - ret = wcrypto_do_aead(ctx, &aopdata, tag); - if (ret == -WD_EBUSY) { - usleep(SEND_USLEEP * try_cnt); - try_cnt++; - if (try_cnt > MAX_TRY_CNT) { - SEC_TST_PRT("Test aead send fail %d times!\n", MAX_TRY_CNT); - try_cnt = 0; - } - continue; - } + if (!ctx) { + SEC_TST_PRT("wd create aead ctx fail!\n"); + return NULL; + }
- count++; - try_cnt = 0; - i = count % MAX_POOL_LENTH; - aopdata.in = res_in[i]; - aopdata.out = res_out[i]; - aopdata.iv = res_iv[i]; - } + ret = wcrypto_set_aead_ckey(ctx, (__u8*)priv_key, (__u16)pdata->keysize); + if (ret) { + SEC_TST_PRT("wd aead set key fail!\n"); wcrypto_del_aead_ctx(ctx); + return NULL; + }
- break; - case DIGEST_TYPE: - digest_setup.alg = pdata->alg; - digest_setup.mode = pdata->mode; - digest_setup.br.alloc = (void *)wd_alloc_blk; - digest_setup.br.free = (void *)wd_free_blk; - digest_setup.br.iova_map = (void *)wd_blk_iova_map; - digest_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; - digest_setup.br.get_bufsize = (void *)wd_blksize; - digest_setup.br.usr = pool; - - ctx = wcrypto_create_digest_ctx(queue, &digest_setup); - if (!ctx) { - SEC_TST_PRT("wd create digest ctx fail!\n"); - return NULL; - } + authsize = 16; //set defaut size + ret = wcrypto_aead_setauthsize(ctx, authsize); + if (ret) { + SEC_TST_PRT("set authsize fail!\n"); + wcrypto_del_aead_ctx(ctx); + return NULL; + } + + if (queue->capa.priv.direction == 0) { + aopdata.op_type = WCRYPTO_CIPHER_ENCRYPTION_DIGEST; + aopdata.out_bytes = g_pktlen + 32; // aad + plen + authsize; + } else { + aopdata.op_type = WCRYPTO_CIPHER_DECRYPTION_DIGEST; + aopdata.out_bytes = g_pktlen + 16; // aad + plen; + }
- if (digest_setup.mode == WCRYPTO_DIGEST_HMAC) { - ret = wcrypto_set_digest_key(ctx, (__u8*)priv_key, - (__u16)pdata->keysize); - if (ret) { - SEC_TST_PRT("wd digest set key fail!\n"); - wcrypto_del_digest_ctx(ctx); - return NULL; + aopdata.assoc_size = 16; + aopdata.in_bytes = g_pktlen; + aopdata.out_bytes = g_pktlen; + aopdata.iv_bytes = pdata->ivsize; + aopdata.priv = NULL; + aopdata.out_buf_bytes = g_pktlen * 2; + + aopdata.in = res_in[0]; + aopdata.out = res_out[0]; + aopdata.iv = res_iv[0]; + usleep(SEND_USLEEP); + while(1) { + if (get_run_state() == 0) + break; + + ret = wcrypto_do_aead(ctx, &aopdata, tag); + if (ret == -WD_EBUSY) { + usleep(SEND_USLEEP * try_cnt); + try_cnt++; + if (try_cnt > MAX_TRY_CNT) { + SEC_TST_PRT("Test aead send fail %d times!\n", MAX_TRY_CNT); + try_cnt = 0; } + continue; }
- dopdata.in_bytes = g_pktlen; - dopdata.out_bytes = 16; - dopdata.has_next = 0; - dopdata.priv = NULL; + count++; + try_cnt = 0; + i = count % MAX_POOL_LENTH; + aopdata.in = res_in[i]; + aopdata.out = res_out[i]; + aopdata.iv = res_iv[i]; + } + + wcrypto_del_aead_ctx(ctx);
- dopdata.in = res_in[0]; - dopdata.out = res_out[0]; - usleep(SEND_USLEEP); - while(1) { - if (get_run_state() == 0) - break; - - ret = wcrypto_do_digest(ctx, &dopdata, (void *)tag); - if (ret == -WD_EBUSY) { - usleep(SEND_USLEEP * try_cnt); - try_cnt++; - if (try_cnt > MAX_TRY_CNT) { - SEC_TST_PRT("Test digest send fail %d times!\n", MAX_TRY_CNT); - try_cnt = 0; - } - continue; - } + add_recv_data(count, g_pktlen); + + return NULL; +} + +static void *sec_wd_digest_sync(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + struct wcrypto_digest_ctx_setup digest_setup = {0}; + struct wcrypto_digest_op_data dopdata; + char priv_key[MAX_IVK_LENTH]; + struct thread_bd_res *bd_res; + struct wd_queue *queue; + void *ctx = NULL; + void *tag = NULL; + void **res_in; + void **res_out; + u32 count = 0; + int try_cnt = 0; + int ret, i; + void *pool; + + if (pdata->td_id > g_thread_num) + return NULL; + + bd_res = &g_thread_queue.bd_res[pdata->td_id]; + queue = bd_res->queue; + pool = bd_res->pool; + res_in = bd_res->in; + res_out = bd_res->out; + + memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH); + + digest_setup.alg = pdata->alg; + digest_setup.mode = pdata->mode; + digest_setup.br.alloc = (void *)wd_alloc_blk; + digest_setup.br.free = (void *)wd_free_blk; + digest_setup.br.iova_map = (void *)wd_blk_iova_map; + digest_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; + digest_setup.br.get_bufsize = (void *)wd_blksize; + digest_setup.br.usr = pool; + + ctx = wcrypto_create_digest_ctx(queue, &digest_setup); + if (!ctx) { + SEC_TST_PRT("wd create digest ctx fail!\n"); + return NULL; + }
- count++; - try_cnt = 0; - i = count % MAX_POOL_LENTH; - dopdata.in = res_in[i]; - dopdata.out = res_out[i]; + if (digest_setup.mode == WCRYPTO_DIGEST_HMAC) { + ret = wcrypto_set_digest_key(ctx, (__u8*)priv_key, + (__u16)pdata->keysize); + if (ret) { + SEC_TST_PRT("wd digest set key fail!\n"); + wcrypto_del_digest_ctx(ctx); + return NULL; } - wcrypto_del_digest_ctx(ctx); - break; }
+ dopdata.in_bytes = g_pktlen; + dopdata.out_bytes = 16; + dopdata.has_next = 0; + dopdata.priv = NULL; + dopdata.in = res_in[0]; + dopdata.out = res_out[0]; + usleep(SEND_USLEEP); + while(1) { + if (get_run_state() == 0) + break; + + ret = wcrypto_do_digest(ctx, &dopdata, (void *)tag); + if (ret == -WD_EBUSY) { + usleep(SEND_USLEEP * try_cnt); + try_cnt++; + if (try_cnt > MAX_TRY_CNT) { + SEC_TST_PRT("Test digest send fail %d times!\n", MAX_TRY_CNT); + try_cnt = 0; + } + continue; + } + + count++; + try_cnt = 0; + i = count % MAX_POOL_LENTH; + dopdata.in = res_in[i]; + dopdata.out = res_out[i]; + } + wcrypto_del_digest_ctx(ctx); + add_recv_data(count, g_pktlen);
return NULL; @@ -1057,6 +1207,8 @@ static void *sec_wd_sync_run(void *arg)
int sec_wd_sync_threads(struct acc_option *options) { + typedef void *(*sec_sync_run)(void *arg); + sec_sync_run wd_sec_sync_run = NULL; thread_data threads_args[THREADS_NUM]; thread_data threads_option; pthread_t tdid[THREADS_NUM]; @@ -1067,6 +1219,18 @@ int sec_wd_sync_threads(struct acc_option *options) if (ret) return ret;
+ switch (options->subtype) { + case CIPHER_TYPE: + wd_sec_sync_run = sec_wd_cipher_sync; + break; + case AEAD_TYPE: + wd_sec_sync_run = sec_wd_aead_sync; + break; + case DIGEST_TYPE: + wd_sec_sync_run = sec_wd_digest_sync; + break; + } + for (i = 0; i < g_thread_num; i++) { threads_args[i].subtype = threads_option.subtype; threads_args[i].alg = threads_option.alg; @@ -1075,7 +1239,7 @@ int sec_wd_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; - ret = pthread_create(&tdid[i], NULL, sec_wd_sync_run, &threads_args[i]); + ret = pthread_create(&tdid[i], NULL, wd_sec_sync_run, &threads_args[i]); if (ret) { SEC_TST_PRT("Create sync thread fail!\n"); goto sync_error; @@ -1098,6 +1262,8 @@ sync_error:
int sec_wd_async_threads(struct acc_option *options) { + typedef void *(*sec_async_run)(void *arg); + sec_async_run wd_sec_async_run = NULL; thread_data threads_args[THREADS_NUM]; thread_data threads_option; pthread_t tdid[THREADS_NUM]; @@ -1120,6 +1286,18 @@ int sec_wd_async_threads(struct acc_option *options) } }
+ switch (options->subtype) { + case CIPHER_TYPE: + wd_sec_async_run = sec_wd_cipher_async; + break; + case AEAD_TYPE: + wd_sec_async_run = sec_wd_aead_async; + break; + case DIGEST_TYPE: + wd_sec_async_run = sec_wd_digest_async; + break; + } + for (i = 0; i < g_thread_num; i++) { threads_args[i].subtype = threads_option.subtype; threads_args[i].alg = threads_option.alg; @@ -1128,7 +1306,7 @@ int sec_wd_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; - ret = pthread_create(&tdid[i], NULL, sec_wd_async_run, &threads_args[i]); + ret = pthread_create(&tdid[i], NULL, wd_sec_async_run, &threads_args[i]); if (ret) { SEC_TST_PRT("Create async thread fail!\n"); goto async_error;