public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] virtio_ring: Optimize duplicate judgment codes for virtqueue_add_split
@ 2022-06-20  8:06 Deming Wang
  2022-06-20  8:24 ` Michael S. Tsirkin
  0 siblings, 1 reply; 2+ messages in thread
From: Deming Wang @ 2022-06-20  8:06 UTC (permalink / raw)
  To: mst, jasowang; +Cc: virtualization, linux-kernel, Deming Wang

We combine repeated judgments about indirect in one place

Signed-off-by: Deming Wang <wangdeming@inspur.com>
---
 drivers/virtio/virtio_ring.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 13a7348cedff..331fa3cf5be7 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -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). */
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] virtio_ring: Optimize duplicate judgment codes for virtqueue_add_split
  2022-06-20  8:06 [PATCH] virtio_ring: Optimize duplicate judgment codes for virtqueue_add_split Deming Wang
@ 2022-06-20  8:24 ` Michael S. Tsirkin
  0 siblings, 0 replies; 2+ messages in thread
From: Michael S. Tsirkin @ 2022-06-20  8:24 UTC (permalink / raw)
  To: Deming Wang; +Cc: jasowang, virtualization, linux-kernel

On Mon, Jun 20, 2022 at 04:06:56AM -0400, Deming Wang wrote:
> We combine repeated judgments about indirect in one place
> 
> Signed-off-by: Deming Wang <wangdeming@inspur.com>


Point being? The patch makes the code kind of confusing.
What do we gain in return?

> ---
>  drivers/virtio/virtio_ring.c | 16 ++++++----------
>  1 file changed, 6 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> index 13a7348cedff..331fa3cf5be7 100644
> --- a/drivers/virtio/virtio_ring.c
> +++ b/drivers/virtio/virtio_ring.c
> @@ -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). */
> -- 
> 2.27.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-06-20  8:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-20  8:06 [PATCH] virtio_ring: Optimize duplicate judgment codes for virtqueue_add_split Deming Wang
2022-06-20  8:24 ` Michael S. Tsirkin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox