2022-03-28 16:32:31

by Xianting Tian

[permalink] [raw]
Subject: [PATCH 1/2] virtio_ring: remove unnecessary to_vvq call in vring hot path

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.

Signed-off-by: Xianting Tian <[email protected]>
---
drivers/virtio/virtio_ring.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 962f1477b1fa..d597fc0874ec 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;
@@ -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


2022-03-28 21:38:41

by Xianting Tian

[permalink] [raw]
Subject: [PATCH 2/2] virtio_ring: add unlikely annotation for free descs check

The 'if (vq->vq.num_free < descs_used)' check will almost always be false.

Signed-off-by: Xianting Tian <[email protected]>
---
drivers/virtio/virtio_ring.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index d597fc0874ec..ab6d5f0cb579 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -525,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
--
2.17.1

2022-03-29 05:41:55

by Jason Wang

[permalink] [raw]
Subject: Re: [PATCH 2/2] virtio_ring: add unlikely annotation for free descs check

On Mon, Mar 28, 2022 at 6:58 PM Xianting Tian
<[email protected]> wrote:
>
> The 'if (vq->vq.num_free < descs_used)' check will almost always be false.
>
> Signed-off-by: Xianting Tian <[email protected]>

Acked-by: Jason Wang <[email protected]>

> ---
> drivers/virtio/virtio_ring.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> index d597fc0874ec..ab6d5f0cb579 100644
> --- a/drivers/virtio/virtio_ring.c
> +++ b/drivers/virtio/virtio_ring.c
> @@ -525,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
> --
> 2.17.1
>

2022-03-29 08:52:30

by Jason Wang

[permalink] [raw]
Subject: Re: [PATCH 1/2] virtio_ring: remove unnecessary to_vvq call in vring hot path

On Mon, Mar 28, 2022 at 6:58 PM Xianting Tian
<[email protected]> 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.
>
> Signed-off-by: Xianting Tian <[email protected]>

Acked-by: Jason Wang <[email protected]>

> ---
> drivers/virtio/virtio_ring.c | 8 +++-----
> 1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> index 962f1477b1fa..d597fc0874ec 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;
> @@ -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
>

2022-03-29 12:53:06

by Stefano Garzarella

[permalink] [raw]
Subject: Re: [PATCH 2/2] virtio_ring: add unlikely annotation for free descs check

On Mon, Mar 28, 2022 at 06:58:17PM +0800, Xianting Tian wrote:
>The 'if (vq->vq.num_free < descs_used)' check will almost always be false.
>
>Signed-off-by: Xianting Tian <[email protected]>
>---
> drivers/virtio/virtio_ring.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Stefano Garzarella <[email protected]>

>
>diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
>index d597fc0874ec..ab6d5f0cb579 100644
>--- a/drivers/virtio/virtio_ring.c
>+++ b/drivers/virtio/virtio_ring.c
>@@ -525,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
>--
>2.17.1
>

2022-03-30 12:09:26

by Stefano Garzarella

[permalink] [raw]
Subject: Re: [PATCH 1/2] virtio_ring: remove unnecessary to_vvq call in vring hot path

On Mon, Mar 28, 2022 at 06:58:16PM +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.
>
>Signed-off-by: Xianting Tian <[email protected]>
>---
> drivers/virtio/virtio_ring.c | 8 +++-----
> 1 file changed, 3 insertions(+), 5 deletions(-)

Reviewed-by: Stefano Garzarella <[email protected]>

>
>diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
>index 962f1477b1fa..d597fc0874ec 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;
>@@ -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
>

2022-04-05 00:54:01

by Michael S. Tsirkin

[permalink] [raw]
Subject: Re: [PATCH 2/2] virtio_ring: add unlikely annotation for free descs check

On Mon, Apr 04, 2022 at 11:11:16PM +0800, Xianting Tian wrote:
> I can't find it in next branch, will you apply this patch?

yes, thanks!

2022-04-05 01:06:37

by Xianting Tian

[permalink] [raw]
Subject: Re: [PATCH 2/2] virtio_ring: add unlikely annotation for free descs check

I can't find it in next branch, will you apply this patch?

在 2022/3/29 下午3:50, Stefano Garzarella 写道:
> On Mon, Mar 28, 2022 at 06:58:17PM +0800, Xianting Tian wrote:
>> The 'if (vq->vq.num_free < descs_used)' check will almost always be
>> false.
>>
>> Signed-off-by: Xianting Tian <[email protected]>
>> ---
>> drivers/virtio/virtio_ring.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> Reviewed-by: Stefano Garzarella <[email protected]>
>
>>
>> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
>> index d597fc0874ec..ab6d5f0cb579 100644
>> --- a/drivers/virtio/virtio_ring.c
>> +++ b/drivers/virtio/virtio_ring.c
>> @@ -525,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
>> --
>> 2.17.1
>>