From: Stefan Hajnoczi <stefanha@redhat.com>
To: virtualization@lists.linux-foundation.org
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
Christoph Hellwig <hch@lst.de>, Jason Wang <jasowang@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>, Jens Axboe <axboe@kernel.dk>,
slp@redhat.com, sgarzare@redhat.com,
"Michael S. Tsirkin" <mst@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [PATCH 2/3] virtio_blk: avoid repeating vblk->vqs[qid]
Date: Thu, 20 May 2021 15:13:04 +0100 [thread overview]
Message-ID: <20210520141305.355961-3-stefanha@redhat.com> (raw)
In-Reply-To: <20210520141305.355961-1-stefanha@redhat.com>
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@redhat.com>
---
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
next prev parent reply other threads:[~2021-05-20 14:14 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-20 14:13 [PATCH 0/3] virtio_blk: blk-mq io_poll support Stefan Hajnoczi
2021-05-20 14:13 ` [PATCH 1/3] virtio: add virtioqueue_more_used() Stefan Hajnoczi
2021-05-25 2:23 ` Jason Wang
2021-05-25 8:48 ` Stefan Hajnoczi
2021-05-20 14:13 ` Stefan Hajnoczi [this message]
2021-05-25 2:25 ` [PATCH 2/3] virtio_blk: avoid repeating vblk->vqs[qid] Jason Wang
2021-05-20 14:13 ` [PATCH 3/3] virtio_blk: implement blk_mq_ops->poll() Stefan Hajnoczi
2021-05-24 14:59 ` Christoph Hellwig
2021-05-25 7:22 ` Paolo Bonzini
2021-05-25 7:38 ` Ming Lei
2021-05-25 8:06 ` Paolo Bonzini
2021-05-25 13:20 ` Stefan Hajnoczi
2021-05-25 13:19 ` Stefan Hajnoczi
2021-05-25 3:21 ` Jason Wang
2021-05-25 8:59 ` Stefan Hajnoczi
2021-05-27 5:48 ` Jason Wang
2021-06-03 15:24 ` Stefan Hajnoczi
2021-05-27 2:44 ` Ming Lei
2021-06-03 15:12 ` Stefan Hajnoczi
2021-06-03 15:30 ` [PATCH 0/3] virtio_blk: blk-mq io_poll support Stefan Hajnoczi
2021-06-16 7:43 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210520141305.355961-3-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=jasowang@redhat.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=sgarzare@redhat.com \
--cc=slp@redhat.com \
--cc=virtualization@lists.linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).