mirror of
https://github.com/torvalds/linux.git
synced 2024-12-05 10:32:35 +00:00
crypto: hisilicon/zip - optimization for performance
1.Remove some useless steps during doing requests. 2.Adjust the possibility of branch prediction. Signed-off-by: Yang Shen <shenyang39@huawei.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
parent
5a4c293666
commit
4f33604527
@ -183,7 +183,7 @@ static int add_comp_head(struct scatterlist *dst, u8 req_type)
|
||||
int ret;
|
||||
|
||||
ret = sg_copy_from_buffer(dst, sg_nents(dst), head, head_size);
|
||||
if (ret != head_size) {
|
||||
if (unlikely(ret != head_size)) {
|
||||
pr_err("the head size of buffer is wrong (%d)!\n", ret);
|
||||
return -ENOMEM;
|
||||
}
|
||||
@ -193,11 +193,11 @@ static int add_comp_head(struct scatterlist *dst, u8 req_type)
|
||||
|
||||
static int get_comp_head_size(struct acomp_req *acomp_req, u8 req_type)
|
||||
{
|
||||
if (!acomp_req->src || !acomp_req->slen)
|
||||
if (unlikely(!acomp_req->src || !acomp_req->slen))
|
||||
return -EINVAL;
|
||||
|
||||
if (req_type == HZIP_ALG_TYPE_GZIP &&
|
||||
acomp_req->slen < GZIP_HEAD_FEXTRA_SHIFT)
|
||||
if (unlikely(req_type == HZIP_ALG_TYPE_GZIP &&
|
||||
acomp_req->slen < GZIP_HEAD_FEXTRA_SHIFT))
|
||||
return -EINVAL;
|
||||
|
||||
switch (req_type) {
|
||||
@ -230,6 +230,8 @@ static struct hisi_zip_req *hisi_zip_create_req(struct acomp_req *req,
|
||||
}
|
||||
set_bit(req_id, req_q->req_bitmap);
|
||||
|
||||
write_unlock(&req_q->req_lock);
|
||||
|
||||
req_cache = q + req_id;
|
||||
req_cache->req_id = req_id;
|
||||
req_cache->req = req;
|
||||
@ -242,8 +244,6 @@ static struct hisi_zip_req *hisi_zip_create_req(struct acomp_req *req,
|
||||
req_cache->dskip = 0;
|
||||
}
|
||||
|
||||
write_unlock(&req_q->req_lock);
|
||||
|
||||
return req_cache;
|
||||
}
|
||||
|
||||
@ -254,7 +254,6 @@ static void hisi_zip_remove_req(struct hisi_zip_qp_ctx *qp_ctx,
|
||||
|
||||
write_lock(&req_q->req_lock);
|
||||
clear_bit(req->req_id, req_q->req_bitmap);
|
||||
memset(req, 0, sizeof(struct hisi_zip_req));
|
||||
write_unlock(&req_q->req_lock);
|
||||
}
|
||||
|
||||
@ -339,7 +338,7 @@ static int hisi_zip_do_work(struct hisi_zip_req *req,
|
||||
struct hisi_zip_sqe zip_sqe;
|
||||
int ret;
|
||||
|
||||
if (!a_req->src || !a_req->slen || !a_req->dst || !a_req->dlen)
|
||||
if (unlikely(!a_req->src || !a_req->slen || !a_req->dst || !a_req->dlen))
|
||||
return -EINVAL;
|
||||
|
||||
req->hw_src = hisi_acc_sg_buf_map_to_hw_sgl(dev, a_req->src, pool,
|
||||
@ -365,7 +364,7 @@ static int hisi_zip_do_work(struct hisi_zip_req *req,
|
||||
/* send command to start a task */
|
||||
atomic64_inc(&dfx->send_cnt);
|
||||
ret = hisi_qp_send(qp, &zip_sqe);
|
||||
if (ret < 0) {
|
||||
if (unlikely(ret < 0)) {
|
||||
atomic64_inc(&dfx->send_busy_cnt);
|
||||
ret = -EAGAIN;
|
||||
dev_dbg_ratelimited(dev, "failed to send request!\n");
|
||||
@ -417,7 +416,7 @@ static void hisi_zip_acomp_cb(struct hisi_qp *qp, void *data)
|
||||
|
||||
atomic64_inc(&dfx->recv_cnt);
|
||||
status = ops->get_status(sqe);
|
||||
if (status != 0 && status != HZIP_NC_ERR) {
|
||||
if (unlikely(status != 0 && status != HZIP_NC_ERR)) {
|
||||
dev_err(dev, "%scompress fail in qp%u: %u, output: %u\n",
|
||||
(qp->alg_type == 0) ? "" : "de", qp->qp_id, status,
|
||||
sqe->produced);
|
||||
@ -450,7 +449,7 @@ static int hisi_zip_acompress(struct acomp_req *acomp_req)
|
||||
|
||||
/* let's output compression head now */
|
||||
head_size = add_comp_head(acomp_req->dst, qp_ctx->qp->req_type);
|
||||
if (head_size < 0) {
|
||||
if (unlikely(head_size < 0)) {
|
||||
dev_err_ratelimited(dev, "failed to add comp head (%d)!\n",
|
||||
head_size);
|
||||
return head_size;
|
||||
@ -461,7 +460,7 @@ static int hisi_zip_acompress(struct acomp_req *acomp_req)
|
||||
return PTR_ERR(req);
|
||||
|
||||
ret = hisi_zip_do_work(req, qp_ctx);
|
||||
if (ret != -EINPROGRESS) {
|
||||
if (unlikely(ret != -EINPROGRESS)) {
|
||||
dev_info_ratelimited(dev, "failed to do compress (%d)!\n", ret);
|
||||
hisi_zip_remove_req(qp_ctx, req);
|
||||
}
|
||||
@ -478,7 +477,7 @@ static int hisi_zip_adecompress(struct acomp_req *acomp_req)
|
||||
int head_size, ret;
|
||||
|
||||
head_size = get_comp_head_size(acomp_req, qp_ctx->qp->req_type);
|
||||
if (head_size < 0) {
|
||||
if (unlikely(head_size < 0)) {
|
||||
dev_err_ratelimited(dev, "failed to get comp head size (%d)!\n",
|
||||
head_size);
|
||||
return head_size;
|
||||
@ -489,7 +488,7 @@ static int hisi_zip_adecompress(struct acomp_req *acomp_req)
|
||||
return PTR_ERR(req);
|
||||
|
||||
ret = hisi_zip_do_work(req, qp_ctx);
|
||||
if (ret != -EINPROGRESS) {
|
||||
if (unlikely(ret != -EINPROGRESS)) {
|
||||
dev_info_ratelimited(dev, "failed to do decompress (%d)!\n",
|
||||
ret);
|
||||
hisi_zip_remove_req(qp_ctx, req);
|
||||
|
Loading…
Reference in New Issue
Block a user