2022-10-06 08:26:14

by Liu Song

[permalink] [raw]
Subject: [RFC PATCH] virtio_ring: remove unnecessary variables in virtqueue_add_packed

From: Liu Song <[email protected]>

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 <[email protected]>
---
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