From: Wenkai Lin linwenkai6@hisilicon.com
When packet length is small, it use software compute, so there is no need to init ctx, optimize it. before: len: 16 64 256 speed: 32213.72k 131927.84k 629974.20k after: len: 16 64 256 speed: 1771017.00k 5464413.82k 629608.35k
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com Signed-off-by: JiangShui Yang yangjiangshui@h-partners.com --- src/uadk_cipher.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-)
diff --git a/src/uadk_cipher.c b/src/uadk_cipher.c index dce6d1e..0ae945f 100644 --- a/src/uadk_cipher.c +++ b/src/uadk_cipher.c @@ -636,13 +636,6 @@ static int do_cipher_sync(struct cipher_priv_ctx *priv) return 0; }
- /* - * If the length of the input data does not reach to hardware computing threshold, - * directly switch to soft cipher. - */ - if (priv->req.in_bytes <= priv->switch_threshold) - return 0; - ret = wd_do_cipher_sync(priv->sess, &priv->req); if (ret) return 0; @@ -801,28 +794,29 @@ static int uadk_e_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, priv->req.dst = out; priv->req.out_buf_bytes = inlen;
- uadk_e_ctx_init(ctx, priv); - ret = async_setup_async_event_notification(&op); if (!ret) { fprintf(stderr, "failed to setup async event notification.\n"); return 0; }
+ /* + * If the length of the input data does not reach to hardware computing threshold, + * directly switch to soft cipher. + */ + if (priv->req.in_bytes <= priv->switch_threshold) { + ret = 0; + goto sync_err; + } + + uadk_e_ctx_init(ctx, priv); + if (!op.job) { /* Synchronous, only the synchronous mode supports soft computing */ ret = do_cipher_sync(priv); if (!ret) goto sync_err; } else { - /* - * If the length of the input data - * does not reach to hardware computing threshold, - * directly switch to soft cipher. - */ - if (priv->req.in_bytes <= priv->switch_threshold) - goto sync_err; - ret = do_cipher_async(priv, &op); if (!ret) goto out_notify;