[PATCH 2/3] virtio_blk: avoid repeating vblk->vqs[qid]
From: Stefan Hajnoczi
Date: Thu May 20 2021 - 10:14:50 EST
struct virtio_blk_vq is accessed in many places. Introduce "vbq" local
variables to avoid repeating vblk->vqs[qid] throughout the code. The
patches that follow will add more accesses, making the payoff even
greater.
virtio_commit_rqs() calls the local variable "vq", which is easily
confused with struct virtqueue. Rename to "vbq" for clarity.
Signed-off-by: Stefan Hajnoczi <stefanha@xxxxxxxxxx>
---
drivers/block/virtio_blk.c | 34 +++++++++++++++++-----------------
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index b9fa3ef5b57c..fc0fb1dcd399 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -174,16 +174,16 @@ static inline void virtblk_request_done(struct request *req)
static void virtblk_done(struct virtqueue *vq)
{
struct virtio_blk *vblk = vq->vdev->priv;
+ struct virtio_blk_vq *vbq = &vblk->vqs[vq->index];
bool req_done = false;
- int qid = vq->index;
struct virtblk_req *vbr;
unsigned long flags;
unsigned int len;
- spin_lock_irqsave(&vblk->vqs[qid].lock, flags);
+ spin_lock_irqsave(&vbq->lock, flags);
do {
virtqueue_disable_cb(vq);
- while ((vbr = virtqueue_get_buf(vblk->vqs[qid].vq, &len)) != NULL) {
+ while ((vbr = virtqueue_get_buf(vq, &len)) != NULL) {
struct request *req = blk_mq_rq_from_pdu(vbr);
if (likely(!blk_should_fake_timeout(req->q)))
@@ -197,32 +197,32 @@ static void virtblk_done(struct virtqueue *vq)
/* In case queue is stopped waiting for more buffers. */
if (req_done)
blk_mq_start_stopped_hw_queues(vblk->disk->queue, true);
- spin_unlock_irqrestore(&vblk->vqs[qid].lock, flags);
+ spin_unlock_irqrestore(&vbq->lock, flags);
}
static void virtio_commit_rqs(struct blk_mq_hw_ctx *hctx)
{
struct virtio_blk *vblk = hctx->queue->queuedata;
- struct virtio_blk_vq *vq = &vblk->vqs[hctx->queue_num];
+ struct virtio_blk_vq *vbq = &vblk->vqs[hctx->queue_num];
bool kick;
- spin_lock_irq(&vq->lock);
- kick = virtqueue_kick_prepare(vq->vq);
- spin_unlock_irq(&vq->lock);
+ spin_lock_irq(&vbq->lock);
+ kick = virtqueue_kick_prepare(vbq->vq);
+ spin_unlock_irq(&vbq->lock);
if (kick)
- virtqueue_notify(vq->vq);
+ virtqueue_notify(vbq->vq);
}
static blk_status_t virtio_queue_rq(struct blk_mq_hw_ctx *hctx,
const struct blk_mq_queue_data *bd)
{
struct virtio_blk *vblk = hctx->queue->queuedata;
+ struct virtio_blk_vq *vbq = &vblk->vqs[hctx->queue_num];
struct request *req = bd->rq;
struct virtblk_req *vbr = blk_mq_rq_to_pdu(req);
unsigned long flags;
unsigned int num;
- int qid = hctx->queue_num;
int err;
bool notify = false;
bool unmap = false;
@@ -274,16 +274,16 @@ static blk_status_t virtio_queue_rq(struct blk_mq_hw_ctx *hctx,
vbr->out_hdr.type |= cpu_to_virtio32(vblk->vdev, VIRTIO_BLK_T_IN);
}
- spin_lock_irqsave(&vblk->vqs[qid].lock, flags);
- err = virtblk_add_req(vblk->vqs[qid].vq, vbr, vbr->sg, num);
+ spin_lock_irqsave(&vbq->lock, flags);
+ err = virtblk_add_req(vbq->vq, vbr, vbr->sg, num);
if (err) {
- virtqueue_kick(vblk->vqs[qid].vq);
+ virtqueue_kick(vbq->vq);
/* Don't stop the queue if -ENOMEM: we may have failed to
* bounce the buffer due to global resource outage.
*/
if (err == -ENOSPC)
blk_mq_stop_hw_queue(hctx);
- spin_unlock_irqrestore(&vblk->vqs[qid].lock, flags);
+ spin_unlock_irqrestore(&vbq->lock, flags);
switch (err) {
case -ENOSPC:
return BLK_STS_DEV_RESOURCE;
@@ -294,12 +294,12 @@ static blk_status_t virtio_queue_rq(struct blk_mq_hw_ctx *hctx,
}
}
- if (bd->last && virtqueue_kick_prepare(vblk->vqs[qid].vq))
+ if (bd->last && virtqueue_kick_prepare(vbq->vq))
notify = true;
- spin_unlock_irqrestore(&vblk->vqs[qid].lock, flags);
+ spin_unlock_irqrestore(&vbq->lock, flags);
if (notify)
- virtqueue_notify(vblk->vqs[qid].vq);
+ virtqueue_notify(vbq->vq);
return BLK_STS_OK;
}
--
2.31.1