virtio_ring: Optimize duplicate judgment codes for virtqueue_add_split
PATCH 1/1 virtio_ring: Optimize duplicate judgment codes for virtqueue_add_split
We combine repeated judgments about indirect in one place
Signed-off-by Deming Wang <[email protected]>
--- drivers/virtio/virtio_ring.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
drivers/virtio/virtio_ring.c +6 -10
@@ -582,23 +582,19 @@ static inline int virtqueue_add_split(struct virtqueue *_vq, total_sg * sizeof(struct vring_desc),VRING_DESC_F_INDIRECT , false); + vq->free_head = vq->split.desc_extra[head].next; + vq->split.desc_state[head].indir_desc = desc; + }else { +/* Update free pointer */ + vq->free_head = i; + vq->split.desc_state[head].indir_desc = ctx; }/* We're using some buffers from the free list. */ vq->vq.num_free -= descs_used; -/* Update free pointer */ -if (indirect) - vq->free_head = vq->split.desc_extra[head].next; -else - vq->free_head = i; -/* Store token and indirect buffer state. */ vq->split.desc_state[head].data = data; -if (indirect) - vq->split.desc_state[head].indir_desc = desc; -else - vq->split.desc_state[head].indir_desc = ctx;/* Put entry in available array (but don't update avail->idx until they * do sync). */
Signature · 1 line
2.27.0
Michael S. Tsirkin
maintainerQuoted 3 lines · Deming Wang
We combine repeated judgments about indirect in one place
Signed-off-by Deming Wang <[email protected]>
Point being? The patch makes the code kind of confusing. What do we gain in return?
Quoted 40 lines
--- drivers/virtio/virtio_ring.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)drivers/virtio/virtio_ring.c +6
-10@@ -582,23 +582,19 @@ static inline int virtqueue_add_split(struct virtqueue *_vq, total_sg * sizeof(struct vring_desc),VRING_DESC_F_INDIRECT , false); + vq->free_head = vq->split.desc_extra[head].next; + vq->split.desc_state[head].indir_desc = desc; + }else { +/* Update free pointer */ + vq->free_head = i; + vq->split.desc_state[head].indir_desc = ctx; }/* We're using some buffers from the free list. */ vq->vq.num_free -= descs_used; -/* Update free pointer */ -if (indirect) - vq->free_head = vq->split.desc_extra[head].next; -else - vq->free_head = i; -/* Store token and indirect buffer state. */ vq->split.desc_state[head].data = data; -if (indirect) - vq->split.desc_state[head].indir_desc = desc; -else - vq->split.desc_state[head].indir_desc = ctx;/* Put entry in available array (but don't update avail->idx until they * do sync). */ Signature · 1 line
2.27.0
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization