Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp377488ybl; Thu, 9 Jan 2020 23:54:33 -0800 (PST) X-Google-Smtp-Source: APXvYqzrUNUBqVJKJq/NLBWGEZ1PJuw4VP02c0CjtG8zAmT5qoyhoi9PGxLGgHf3CcO+TMV6iWA9 X-Received: by 2002:a9d:6396:: with SMTP id w22mr1560556otk.364.1578642873816; Thu, 09 Jan 2020 23:54:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578642873; cv=none; d=google.com; s=arc-20160816; b=LpjkfNjn1U7uPXdkEA5fKjxMYumOhncl9R/7cIKsH85mIypfoKjY4VnM2c+0VlMhcb 4F7p8iwl2Fh0GKTv2kYYztWTCALQ6HZ/MU0f1YDiHqmXB/HywnVYcJbvhCUsB+ulUF3m reVQvkq5lYVtf+pWFvvFEgHtfaqnXYE08VjfgK9gPRO9ZtPABR984XYHxoxn/48TQp2U DQU3LMf4e0JKMbMqw9c5NsDhN36FGELOZyLnmHzcJ4QBnxKSRSCMZYLpi0sQLQRQx3tW r7CRlT0A8eAkIDoyLCWJjoncNzz6C9q+0dFWdKJWEkLpRmld6uX2NbqZpkIR2EZllT/P D3eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=fKxaWoCX8ckh4kyE4gMQEhUm7zhk4UxSplNrDT14C/E=; b=ubYcpLdRq2Dhuk6CWKhrWeaFhJWqHNW46EENEaiEjAKZLh/K1j4ztaTOBFveT+wdHk ytfOFXNMgPaheUMbgu4EcyZDc4KsTepx65zZDN9gO3+33BjMI39DhuKiKWUZCP5vyJ8R eH99Bs6DS+aQgpEerm0QL1fPNMUxoLyTFZRiFRJp8eaQqI3nUwCexP3JwYFvpTMrsyKN LIVe4gLt0LexKpW1yPtSqTBSZp4t9Kb2MOW8v8BLyhdRXp38nA/jRGDxXYzy0I8bDsla ZKmbWP0dqLKAEIeCcb4+R6ev0rHCCRp0v1rzXK++SJkOAa0eYXniMIasszAU7um6A2Ch LyWA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i5si635157oif.211.2020.01.09.23.53.59; Thu, 09 Jan 2020 23:54:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726636AbgAJHx5 (ORCPT + 99 others); Fri, 10 Jan 2020 02:53:57 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:42540 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726549AbgAJHxz (ORCPT ); Fri, 10 Jan 2020 02:53:55 -0500 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 20C8C25F27279EA81904; Fri, 10 Jan 2020 15:53:52 +0800 (CST) Received: from localhost.localdomain (10.67.165.24) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.439.0; Fri, 10 Jan 2020 15:53:44 +0800 From: Zaibo Xu To: , CC: , , , , , , , , , , Subject: [PATCH 7/9] crypto: hisilicon - Add branch prediction macro Date: Fri, 10 Jan 2020 15:49:56 +0800 Message-ID: <1578642598-8584-8-git-send-email-xuzaibo@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1578642598-8584-1-git-send-email-xuzaibo@huawei.com> References: <1578642598-8584-1-git-send-email-xuzaibo@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.165.24] X-CFilter-Loop: Reflected Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org After adding branch prediction for skcipher hot path, a little bit income of performance is gotten. Signed-off-by: Zaibo Xu --- drivers/crypto/hisilicon/sec2/sec_crypto.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/crypto/hisilicon/sec2/sec_crypto.c b/drivers/crypto/hisilicon/sec2/sec_crypto.c index 568c174..521bab8 100644 --- a/drivers/crypto/hisilicon/sec2/sec_crypto.c +++ b/drivers/crypto/hisilicon/sec2/sec_crypto.c @@ -69,7 +69,7 @@ static int sec_alloc_req_id(struct sec_req *req, struct sec_qp_ctx *qp_ctx) req_id = idr_alloc_cyclic(&qp_ctx->req_idr, NULL, 0, QM_Q_DEPTH, GFP_ATOMIC); mutex_unlock(&qp_ctx->req_lock); - if (req_id < 0) { + if (unlikely(req_id < 0)) { dev_err(SEC_CTX_DEV(req->ctx), "alloc req id fail!\n"); return req_id; } @@ -84,7 +84,7 @@ static void sec_free_req_id(struct sec_req *req) struct sec_qp_ctx *qp_ctx = req->qp_ctx; int req_id = req->req_id; - if (req_id < 0 || req_id >= QM_Q_DEPTH) { + if (unlikely(req_id < 0 || req_id >= QM_Q_DEPTH)) { dev_err(SEC_CTX_DEV(req->ctx), "free request id invalid!\n"); return; } @@ -108,7 +108,7 @@ static void sec_req_cb(struct hisi_qp *qp, void *resp) u8 type; type = bd->type_cipher_auth & SEC_TYPE_MASK; - if (type != SEC_BD_TYPE2) { + if (unlikely(type != SEC_BD_TYPE2)) { pr_err("err bd type [%d]\n", type); return; } @@ -144,7 +144,7 @@ static int sec_bd_send(struct sec_ctx *ctx, struct sec_req *req) mutex_unlock(&qp_ctx->req_lock); atomic64_inc(&ctx->sec->debug.dfx.send_cnt); - if (ret == -EBUSY) + if (unlikely(ret == -EBUSY)) return -ENOBUFS; if (!ret) { @@ -526,13 +526,13 @@ static int sec_request_transfer(struct sec_ctx *ctx, struct sec_req *req) int ret; ret = ctx->req_op->buf_map(ctx, req); - if (ret) + if (unlikely(ret)) return ret; ctx->req_op->do_transfer(ctx, req); ret = ctx->req_op->bd_fill(ctx, req); - if (ret) + if (unlikely(ret)) goto unmap_req_buf; return ret; @@ -617,7 +617,7 @@ static void sec_update_iv(struct sec_req *req) sz = sg_pcopy_to_buffer(sgl, sg_nents(sgl), sk_req->iv, iv_size, sk_req->cryptlen - iv_size); - if (sz != iv_size) + if (unlikely(sz != iv_size)) dev_err(SEC_CTX_DEV(req->ctx), "copy output iv error!\n"); } @@ -659,7 +659,7 @@ static int sec_request_init(struct sec_ctx *ctx, struct sec_req *req) qp_ctx = &ctx->qp_ctx[queue_id]; req->req_id = sec_alloc_req_id(req, qp_ctx); - if (req->req_id < 0) { + if (unlikely(req->req_id < 0)) { sec_free_queue_id(ctx, req); return req->req_id; } @@ -677,11 +677,11 @@ static int sec_process(struct sec_ctx *ctx, struct sec_req *req) int ret; ret = sec_request_init(ctx, req); - if (ret) + if (unlikely(ret)) return ret; ret = sec_request_transfer(ctx, req); - if (ret) + if (unlikely(ret)) goto err_uninit_req; /* Output IV as decrypto */ @@ -689,7 +689,7 @@ static int sec_process(struct sec_ctx *ctx, struct sec_req *req) sec_update_iv(req); ret = ctx->req_op->bd_send(ctx, req); - if (ret != -EBUSY && ret != -EINPROGRESS) { + if (unlikely(ret != -EBUSY && ret != -EINPROGRESS)) { dev_err_ratelimited(SEC_CTX_DEV(ctx), "send sec request failed!\n"); goto err_send_req; } @@ -740,19 +740,19 @@ static int sec_skcipher_param_check(struct sec_ctx *ctx, struct sec_req *sreq) struct device *dev = SEC_CTX_DEV(ctx); u8 c_alg = ctx->c_ctx.c_alg; - if (!sk_req->src || !sk_req->dst) { + if (unlikely(!sk_req->src || !sk_req->dst)) { dev_err(dev, "skcipher input param error!\n"); return -EINVAL; } sreq->c_req.c_len = sk_req->cryptlen; if (c_alg == SEC_CALG_3DES) { - if (sk_req->cryptlen & (DES3_EDE_BLOCK_SIZE - 1)) { + if (unlikely(sk_req->cryptlen & (DES3_EDE_BLOCK_SIZE - 1))) { dev_err(dev, "skcipher 3des input length error!\n"); return -EINVAL; } return 0; } else if (c_alg == SEC_CALG_AES || c_alg == SEC_CALG_SM4) { - if (sk_req->cryptlen & (AES_BLOCK_SIZE - 1)) { + if (unlikely(sk_req->cryptlen & (AES_BLOCK_SIZE - 1))) { dev_err(dev, "skcipher aes input length error!\n"); return -EINVAL; } -- 2.8.1