All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] virtio_ring: remove unnecessary variables in virtqueue_add_packed
@ 2022-10-06  8:06 Liu Song
  0 siblings, 0 replies; only message in thread
From: Liu Song @ 2022-10-06  8:06 UTC (permalink / raw)
  To: mst, jasowang; +Cc: virtualization, linux-kernel

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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-10-06  8:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-06  8:06 [RFC PATCH] virtio_ring: remove unnecessary variables in virtqueue_add_packed Liu Song

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.