All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] virtio_ring: remove unnecessary to_vvq call in vring hot path
@ 2022-06-22  9:09 Deming Wang
  0 siblings, 0 replies; 6+ messages in thread
From: Deming Wang @ 2022-06-22  9:09 UTC (permalink / raw)
  To: mst, jasowang; +Cc: virtualization, linux-kernel, Deming Wang

It passes '_vq' to virtqueue_detach_unused_buf_packed(),
which still calls to_vvq to get 'vq', let's directly
pass 'vq'. It can avoid unnecessary call of to_vvq in hot path.

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

diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 13a7348cedff..905d003f6849 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -1593,9 +1593,8 @@ static bool virtqueue_enable_cb_delayed_packed(struct virtqueue *_vq)
 	return true;
 }
 
-static void *virtqueue_detach_unused_buf_packed(struct virtqueue *_vq)
+static void *virtqueue_detach_unused_buf_packed(struct vring_virtqueue *vq)
 {
-	struct vring_virtqueue *vq = to_vvq(_vq);
 	unsigned int i;
 	void *buf;
 
@@ -2115,7 +2114,7 @@ void *virtqueue_detach_unused_buf(struct virtqueue *_vq)
 {
 	struct vring_virtqueue *vq = to_vvq(_vq);
 
-	return vq->packed_ring ? virtqueue_detach_unused_buf_packed(_vq) :
+	return vq->packed_ring ? virtqueue_detach_unused_buf_packed(vq) :
 				 virtqueue_detach_unused_buf_split(_vq);
 }
 EXPORT_SYMBOL_GPL(virtqueue_detach_unused_buf);
-- 
2.27.0


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

* [PATCH] virtio_ring: remove unnecessary to_vvq call in vring hot path
@ 2022-06-22  8:51 Deming Wang
  0 siblings, 0 replies; 6+ messages in thread
From: Deming Wang @ 2022-06-22  8:51 UTC (permalink / raw)
  To: mst, jasowang; +Cc: virtualization, linux-kernel, Deming Wang

It passes '_vq' to virtqueue_enable_cb_delayed_packed(), which
still calls to_vvq to get 'vq', let's directly pass
to_vvq to gunnecessary call of to_vvq in hot path.

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

diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 13a7348cedff..4d41d5a90816 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -1534,9 +1534,8 @@ static bool virtqueue_poll_packed(struct virtqueue *_vq, u16 off_wrap)
 	return is_used_desc_packed(vq, used_idx, wrap_counter);
 }
 
-static bool virtqueue_enable_cb_delayed_packed(struct virtqueue *_vq)
+static bool virtqueue_enable_cb_delayed_packed(struct vring_virtqueue *vq)
 {
-	struct vring_virtqueue *vq = to_vvq(_vq);
 	u16 used_idx, wrap_counter;
 	u16 bufs;
 
@@ -2098,7 +2097,7 @@ bool virtqueue_enable_cb_delayed(struct virtqueue *_vq)
 	if (vq->event_triggered)
 		vq->event_triggered = false;
 
-	return vq->packed_ring ? virtqueue_enable_cb_delayed_packed(_vq) :
+	return vq->packed_ring ? virtqueue_enable_cb_delayed_packed(vq) :
 				 virtqueue_enable_cb_delayed_split(_vq);
 }
 EXPORT_SYMBOL_GPL(virtqueue_enable_cb_delayed);
-- 
2.27.0


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

* Re: [PATCH] virtio_ring: remove unnecessary to_vvq call in vring hot path
  2022-03-28  9:05   ` Stefano Garzarella
  (?)
@ 2022-03-28  9:13   ` Xianting Tian
  -1 siblings, 0 replies; 6+ messages in thread
From: Xianting Tian @ 2022-03-28  9:13 UTC (permalink / raw)
  To: Stefano Garzarella; +Cc: mst, jasowang, virtualization, linux-kernel

在 2022/3/28 下午5:05, Stefano Garzarella 写道:

> On Thu, Mar 24, 2022 at 03:33:40PM +0800, Xianting Tian wrote:
>> It passes '_vq' to virtqueue_use_indirect(), which still calls
>> to_vvq to get 'vq', let's directly pass 'vq'. It can avoid
>> unnecessary call of to_vvq in hot path.
>
> It seems reasonable to me.
>
>>
>> Other tiny optimization:
>> Add unlikely to "if (vq->vq.num_free < descs_used).
>
> Better to do this change in another patch.
Thanks for the reply, I will send the patchset, which contains the two 
patches, soon.
>
> Thanks,
> Stefano
>
>>
>> Signed-off-by: Xianting Tian <xianting.tian@linux.alibaba.com>
>> ---
>> drivers/virtio/virtio_ring.c | 10 ++++------
>> 1 file changed, 4 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
>> index 962f1477b1fa..ab6d5f0cb579 100644
>> --- a/drivers/virtio/virtio_ring.c
>> +++ b/drivers/virtio/virtio_ring.c
>> @@ -205,11 +205,9 @@ struct vring_virtqueue {
>>
>> #define to_vvq(_vq) container_of(_vq, struct vring_virtqueue, vq)
>>
>> -static inline bool virtqueue_use_indirect(struct virtqueue *_vq,
>> +static inline bool virtqueue_use_indirect(struct vring_virtqueue *vq,
>>                       unsigned int total_sg)
>> {
>> -    struct vring_virtqueue *vq = to_vvq(_vq);
>> -
>>     /*
>>      * If the host supports indirect descriptor tables, and we have 
>> multiple
>>      * buffers, then go indirect. FIXME: tune this threshold
>> @@ -507,7 +505,7 @@ static inline int virtqueue_add_split(struct 
>> virtqueue *_vq,
>>
>>     head = vq->free_head;
>>
>> -    if (virtqueue_use_indirect(_vq, total_sg))
>> +    if (virtqueue_use_indirect(vq, total_sg))
>>         desc = alloc_indirect_split(_vq, total_sg, gfp);
>>     else {
>>         desc = NULL;
>> @@ -527,7 +525,7 @@ static inline int virtqueue_add_split(struct 
>> virtqueue *_vq,
>>         descs_used = total_sg;
>>     }
>>
>> -    if (vq->vq.num_free < descs_used) {
>> +    if (unlikely(vq->vq.num_free < descs_used)) {
>>         pr_debug("Can't add buf len %i - avail = %i\n",
>>              descs_used, vq->vq.num_free);
>>         /* FIXME: for historical reasons, we force a notify here if
>> @@ -1194,7 +1192,7 @@ static inline int virtqueue_add_packed(struct 
>> virtqueue *_vq,
>>
>>     BUG_ON(total_sg == 0);
>>
>> -    if (virtqueue_use_indirect(_vq, total_sg)) {
>> +    if (virtqueue_use_indirect(vq, total_sg)) {
>>         err = virtqueue_add_indirect_packed(vq, sgs, total_sg, out_sgs,
>>                             in_sgs, data, gfp);
>>         if (err != -ENOMEM) {
>> -- 
>> 2.17.1
>>

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

* Re: [PATCH] virtio_ring: remove unnecessary to_vvq call in vring hot path
  2022-03-24  7:33 Xianting Tian
@ 2022-03-28  9:05   ` Stefano Garzarella
  0 siblings, 0 replies; 6+ messages in thread
From: Stefano Garzarella @ 2022-03-28  9:05 UTC (permalink / raw)
  To: Xianting Tian; +Cc: mst, jasowang, virtualization, linux-kernel

On Thu, Mar 24, 2022 at 03:33:40PM +0800, Xianting Tian wrote:
>It passes '_vq' to virtqueue_use_indirect(), which still calls
>to_vvq to get 'vq', let's directly pass 'vq'. It can avoid
>unnecessary call of to_vvq in hot path.

It seems reasonable to me.

>
>Other tiny optimization:
>Add unlikely to "if (vq->vq.num_free < descs_used).

Better to do this change in another patch.

Thanks,
Stefano

>
>Signed-off-by: Xianting Tian <xianting.tian@linux.alibaba.com>
>---
> drivers/virtio/virtio_ring.c | 10 ++++------
> 1 file changed, 4 insertions(+), 6 deletions(-)
>
>diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
>index 962f1477b1fa..ab6d5f0cb579 100644
>--- a/drivers/virtio/virtio_ring.c
>+++ b/drivers/virtio/virtio_ring.c
>@@ -205,11 +205,9 @@ struct vring_virtqueue {
>
> #define to_vvq(_vq) container_of(_vq, struct vring_virtqueue, vq)
>
>-static inline bool virtqueue_use_indirect(struct virtqueue *_vq,
>+static inline bool virtqueue_use_indirect(struct vring_virtqueue *vq,
> 					  unsigned int total_sg)
> {
>-	struct vring_virtqueue *vq = to_vvq(_vq);
>-
> 	/*
> 	 * If the host supports indirect descriptor tables, and we have multiple
> 	 * buffers, then go indirect. FIXME: tune this threshold
>@@ -507,7 +505,7 @@ static inline int virtqueue_add_split(struct virtqueue *_vq,
>
> 	head = vq->free_head;
>
>-	if (virtqueue_use_indirect(_vq, total_sg))
>+	if (virtqueue_use_indirect(vq, total_sg))
> 		desc = alloc_indirect_split(_vq, total_sg, gfp);
> 	else {
> 		desc = NULL;
>@@ -527,7 +525,7 @@ static inline int virtqueue_add_split(struct virtqueue *_vq,
> 		descs_used = total_sg;
> 	}
>
>-	if (vq->vq.num_free < descs_used) {
>+	if (unlikely(vq->vq.num_free < descs_used)) {
> 		pr_debug("Can't add buf len %i - avail = %i\n",
> 			 descs_used, vq->vq.num_free);
> 		/* FIXME: for historical reasons, we force a notify here if
>@@ -1194,7 +1192,7 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq,
>
> 	BUG_ON(total_sg == 0);
>
>-	if (virtqueue_use_indirect(_vq, total_sg)) {
>+	if (virtqueue_use_indirect(vq, total_sg)) {
> 		err = virtqueue_add_indirect_packed(vq, sgs, total_sg, out_sgs,
> 						    in_sgs, data, gfp);
> 		if (err != -ENOMEM) {
>-- 
>2.17.1
>


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

* Re: [PATCH] virtio_ring: remove unnecessary to_vvq call in vring hot path
@ 2022-03-28  9:05   ` Stefano Garzarella
  0 siblings, 0 replies; 6+ messages in thread
From: Stefano Garzarella @ 2022-03-28  9:05 UTC (permalink / raw)
  To: Xianting Tian; +Cc: virtualization, linux-kernel, mst

On Thu, Mar 24, 2022 at 03:33:40PM +0800, Xianting Tian wrote:
>It passes '_vq' to virtqueue_use_indirect(), which still calls
>to_vvq to get 'vq', let's directly pass 'vq'. It can avoid
>unnecessary call of to_vvq in hot path.

It seems reasonable to me.

>
>Other tiny optimization:
>Add unlikely to "if (vq->vq.num_free < descs_used).

Better to do this change in another patch.

Thanks,
Stefano

>
>Signed-off-by: Xianting Tian <xianting.tian@linux.alibaba.com>
>---
> drivers/virtio/virtio_ring.c | 10 ++++------
> 1 file changed, 4 insertions(+), 6 deletions(-)
>
>diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
>index 962f1477b1fa..ab6d5f0cb579 100644
>--- a/drivers/virtio/virtio_ring.c
>+++ b/drivers/virtio/virtio_ring.c
>@@ -205,11 +205,9 @@ struct vring_virtqueue {
>
> #define to_vvq(_vq) container_of(_vq, struct vring_virtqueue, vq)
>
>-static inline bool virtqueue_use_indirect(struct virtqueue *_vq,
>+static inline bool virtqueue_use_indirect(struct vring_virtqueue *vq,
> 					  unsigned int total_sg)
> {
>-	struct vring_virtqueue *vq = to_vvq(_vq);
>-
> 	/*
> 	 * If the host supports indirect descriptor tables, and we have multiple
> 	 * buffers, then go indirect. FIXME: tune this threshold
>@@ -507,7 +505,7 @@ static inline int virtqueue_add_split(struct virtqueue *_vq,
>
> 	head = vq->free_head;
>
>-	if (virtqueue_use_indirect(_vq, total_sg))
>+	if (virtqueue_use_indirect(vq, total_sg))
> 		desc = alloc_indirect_split(_vq, total_sg, gfp);
> 	else {
> 		desc = NULL;
>@@ -527,7 +525,7 @@ static inline int virtqueue_add_split(struct virtqueue *_vq,
> 		descs_used = total_sg;
> 	}
>
>-	if (vq->vq.num_free < descs_used) {
>+	if (unlikely(vq->vq.num_free < descs_used)) {
> 		pr_debug("Can't add buf len %i - avail = %i\n",
> 			 descs_used, vq->vq.num_free);
> 		/* FIXME: for historical reasons, we force a notify here if
>@@ -1194,7 +1192,7 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq,
>
> 	BUG_ON(total_sg == 0);
>
>-	if (virtqueue_use_indirect(_vq, total_sg)) {
>+	if (virtqueue_use_indirect(vq, total_sg)) {
> 		err = virtqueue_add_indirect_packed(vq, sgs, total_sg, out_sgs,
> 						    in_sgs, data, gfp);
> 		if (err != -ENOMEM) {
>-- 
>2.17.1
>

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

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

* [PATCH] virtio_ring: remove unnecessary to_vvq call in vring hot path
@ 2022-03-24  7:33 Xianting Tian
  2022-03-28  9:05   ` Stefano Garzarella
  0 siblings, 1 reply; 6+ messages in thread
From: Xianting Tian @ 2022-03-24  7:33 UTC (permalink / raw)
  To: mst, jasowang; +Cc: virtualization, linux-kernel, Xianting Tian

It passes '_vq' to virtqueue_use_indirect(), which still calls
to_vvq to get 'vq', let's directly pass 'vq'. It can avoid
unnecessary call of to_vvq in hot path.

Other tiny optimization:
Add unlikely to "if (vq->vq.num_free < descs_used).

Signed-off-by: Xianting Tian <xianting.tian@linux.alibaba.com>
---
 drivers/virtio/virtio_ring.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 962f1477b1fa..ab6d5f0cb579 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -205,11 +205,9 @@ struct vring_virtqueue {
 
 #define to_vvq(_vq) container_of(_vq, struct vring_virtqueue, vq)
 
-static inline bool virtqueue_use_indirect(struct virtqueue *_vq,
+static inline bool virtqueue_use_indirect(struct vring_virtqueue *vq,
 					  unsigned int total_sg)
 {
-	struct vring_virtqueue *vq = to_vvq(_vq);
-
 	/*
 	 * If the host supports indirect descriptor tables, and we have multiple
 	 * buffers, then go indirect. FIXME: tune this threshold
@@ -507,7 +505,7 @@ static inline int virtqueue_add_split(struct virtqueue *_vq,
 
 	head = vq->free_head;
 
-	if (virtqueue_use_indirect(_vq, total_sg))
+	if (virtqueue_use_indirect(vq, total_sg))
 		desc = alloc_indirect_split(_vq, total_sg, gfp);
 	else {
 		desc = NULL;
@@ -527,7 +525,7 @@ static inline int virtqueue_add_split(struct virtqueue *_vq,
 		descs_used = total_sg;
 	}
 
-	if (vq->vq.num_free < descs_used) {
+	if (unlikely(vq->vq.num_free < descs_used)) {
 		pr_debug("Can't add buf len %i - avail = %i\n",
 			 descs_used, vq->vq.num_free);
 		/* FIXME: for historical reasons, we force a notify here if
@@ -1194,7 +1192,7 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq,
 
 	BUG_ON(total_sg == 0);
 
-	if (virtqueue_use_indirect(_vq, total_sg)) {
+	if (virtqueue_use_indirect(vq, total_sg)) {
 		err = virtqueue_add_indirect_packed(vq, sgs, total_sg, out_sgs,
 						    in_sgs, data, gfp);
 		if (err != -ENOMEM) {
-- 
2.17.1


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

end of thread, other threads:[~2022-06-22  9:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-22  9:09 [PATCH] virtio_ring: remove unnecessary to_vvq call in vring hot path Deming Wang
  -- strict thread matches above, loose matches on Subject: below --
2022-06-22  8:51 Deming Wang
2022-03-24  7:33 Xianting Tian
2022-03-28  9:05 ` Stefano Garzarella
2022-03-28  9:05   ` Stefano Garzarella
2022-03-28  9:13   ` Xianting Tian

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.