mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Liu Song <liusong@linux.alibaba.com>
To: mst@redhat.com, jasowang@redhat.com
Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org
Subject: [RFC PATCH] virtio_ring: remove unnecessary variables in virtqueue_add_packed
Date: Thu,  6 Oct 2022 16:06:20 +0800	[thread overview]
Message-ID: <1665043580-10009-1-git-send-email-liusong@linux.alibaba.com> (raw)

From: Liu Song <liusong@linux.alibaba.com>

Unlike "virtqueue_add_split", "descs_used" will only be equal
to "total_sg" in the context of "virtqueue_add_packed", so it
can be removed to reduce unnecessary operations.

Signed-off-by: Liu Song <liusong@linux.alibaba.com>
---
 drivers/virtio/virtio_ring.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 2e7689b..2f5b900 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -1353,7 +1353,7 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq,
 	struct vring_virtqueue *vq = to_vvq(_vq);
 	struct vring_packed_desc *desc;
 	struct scatterlist *sg;
-	unsigned int i, n, c, descs_used, err_idx;
+	unsigned int i, n, c, err_idx;
 	__le16 head_flags, flags;
 	u16 head, id, prev, curr, avail_used_flags;
 	int err;
@@ -1390,11 +1390,10 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq,
 
 	desc = vq->packed.vring.desc;
 	i = head;
-	descs_used = total_sg;
 
-	if (unlikely(vq->vq.num_free < descs_used)) {
+	if (unlikely(vq->vq.num_free < total_sg)) {
 		pr_debug("Can't add buf len %i - avail = %i\n",
-			 descs_used, vq->vq.num_free);
+			 total_sg, vq->vq.num_free);
 		END_USE(vq);
 		return -ENOSPC;
 	}
@@ -1445,14 +1444,14 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq,
 		vq->packed.avail_wrap_counter ^= 1;
 
 	/* We're using some buffers from the free list. */
-	vq->vq.num_free -= descs_used;
+	vq->vq.num_free -= total_sg;
 
 	/* Update free pointer */
 	vq->packed.next_avail_idx = i;
 	vq->free_head = curr;
 
 	/* Store token. */
-	vq->packed.desc_state[id].num = descs_used;
+	vq->packed.desc_state[id].num = total_sg;
 	vq->packed.desc_state[id].data = data;
 	vq->packed.desc_state[id].indir_desc = ctx;
 	vq->packed.desc_state[id].last = prev;
@@ -1464,7 +1463,7 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq,
 	 */
 	virtio_wmb(vq->weak_barriers);
 	vq->packed.vring.desc[head].flags = head_flags;
-	vq->num_added += descs_used;
+	vq->num_added += total_sg;
 
 	pr_debug("Added buffer head %i to %p\n", head, vq);
 	END_USE(vq);
-- 
1.8.3.1


                 reply	other threads:[~2022-10-06  8:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1665043580-10009-1-git-send-email-liusong@linux.alibaba.com \
    --to=liusong@linux.alibaba.com \
    --cc=jasowang@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@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

all inboxes | Powered by JetHome®