Skip to content

Commit be9c336

Browse files
visitorckwherbertx
authored andcommitted
crypto: hisilicon/zip - Optimize performance by replacing rw_lock with spinlock
The req_lock is currently implemented as a rw_lock, but there are no instances where read_lock() is called. This means that the lock is effectively only used by writers, making it functionally equivalent to a simple spinlock. As stated in Documentation/locking/spinlocks.rst: "Reader-writer locks require more atomic memory operations than simple spinlocks. Unless the reader critical section is long, you are better off just using spinlocks." Since the rw_lock in this case incurs additional atomic memory operations without any benefit from reader-writer locking, it is more efficient to replace it with a spinlock. This patch implements that replacement to optimize the driver's performance. Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 407f8cf commit be9c336

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

drivers/crypto/hisilicon/zip/zip_crypto.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct hisi_zip_req {
5454
struct hisi_zip_req_q {
5555
struct hisi_zip_req *q;
5656
unsigned long *req_bitmap;
57-
rwlock_t req_lock;
57+
spinlock_t req_lock;
5858
u16 size;
5959
};
6060

@@ -116,17 +116,17 @@ static struct hisi_zip_req *hisi_zip_create_req(struct hisi_zip_qp_ctx *qp_ctx,
116116
struct hisi_zip_req *req_cache;
117117
int req_id;
118118

119-
write_lock(&req_q->req_lock);
119+
spin_lock(&req_q->req_lock);
120120

121121
req_id = find_first_zero_bit(req_q->req_bitmap, req_q->size);
122122
if (req_id >= req_q->size) {
123-
write_unlock(&req_q->req_lock);
123+
spin_unlock(&req_q->req_lock);
124124
dev_dbg(&qp_ctx->qp->qm->pdev->dev, "req cache is full!\n");
125125
return ERR_PTR(-EAGAIN);
126126
}
127127
set_bit(req_id, req_q->req_bitmap);
128128

129-
write_unlock(&req_q->req_lock);
129+
spin_unlock(&req_q->req_lock);
130130

131131
req_cache = q + req_id;
132132
req_cache->req_id = req_id;
@@ -140,9 +140,9 @@ static void hisi_zip_remove_req(struct hisi_zip_qp_ctx *qp_ctx,
140140
{
141141
struct hisi_zip_req_q *req_q = &qp_ctx->req_q;
142142

143-
write_lock(&req_q->req_lock);
143+
spin_lock(&req_q->req_lock);
144144
clear_bit(req->req_id, req_q->req_bitmap);
145-
write_unlock(&req_q->req_lock);
145+
spin_unlock(&req_q->req_lock);
146146
}
147147

148148
static void hisi_zip_fill_addr(struct hisi_zip_sqe *sqe, struct hisi_zip_req *req)
@@ -456,7 +456,7 @@ static int hisi_zip_create_req_q(struct hisi_zip_ctx *ctx)
456456

457457
goto err_free_comp_q;
458458
}
459-
rwlock_init(&req_q->req_lock);
459+
spin_lock_init(&req_q->req_lock);
460460

461461
req_q->q = kcalloc(req_q->size, sizeof(struct hisi_zip_req),
462462
GFP_KERNEL);

0 commit comments

Comments
 (0)