[v3,2/8] vhost: refactor Virtio ready check

Message ID 20200706112452.1474533-3-amorenoz@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: Maxime Coquelin
Headers
Series vhost: improve Vhost/vDPA device init |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Adrian Moreno July 6, 2020, 11:24 a.m. UTC
From: Maxime Coquelin <maxime.coquelin@redhat.com>

This patch is a small refactoring, as preliminary work
for adding support to Virtio status support.

No functionnal change here.

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 lib/librte_vhost/vhost.c      |  1 +
 lib/librte_vhost/vhost_user.c | 33 +++++++++++++++++++++------------
 2 files changed, 22 insertions(+), 12 deletions(-)
  

Comments

Chenbo Xia July 7, 2020, 3:21 a.m. UTC | #1
> -----Original Message-----
> From: Adrian Moreno <amorenoz@redhat.com>
> Sent: Monday, July 6, 2020 7:25 PM
> To: dev@dpdk.org; Xia, Chenbo <chenbo.xia@intel.com>; Ye, Xiaolong
> <xiaolong.ye@intel.com>; shahafs@mellanox.com; matan@mellanox.com;
> maxime.coquelin@redhat.com; Wang, Xiao W <xiao.w.wang@intel.com>;
> viacheslavo@mellanox.com
> Cc: jasowang@redhat.com; lulu@redhat.com
> Subject: [PATCH v3 2/8] vhost: refactor Virtio ready check
> 
> From: Maxime Coquelin <maxime.coquelin@redhat.com>
> 
> This patch is a small refactoring, as preliminary work for adding support to Virtio
> status support.
> 
> No functionnal change here.
> 
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> ---
>  lib/librte_vhost/vhost.c      |  1 +
>  lib/librte_vhost/vhost_user.c | 33 +++++++++++++++++++++------------
>  2 files changed, 22 insertions(+), 12 deletions(-)
> 
> diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index
> 0d822d6a3..aa1424261 100644
> --- a/lib/librte_vhost/vhost.c
> +++ b/lib/librte_vhost/vhost.c
> @@ -710,6 +710,7 @@ vhost_enable_dequeue_zero_copy(int vid)
>  		return;
> 
>  	dev->dequeue_zero_copy = 1;
> +	VHOST_LOG_CONFIG(INFO, "dequeue zero copy is enabled\n");
>  }
> 
>  void
> diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index
> 5750dde6d..ff8b1752b 100644
> --- a/lib/librte_vhost/vhost_user.c
> +++ b/lib/librte_vhost/vhost_user.c
> @@ -1337,6 +1337,9 @@ virtio_is_ready(struct virtio_net *dev)
>  	struct vhost_virtqueue *vq;
>  	uint32_t i;
> 
> +	if (dev->flags & VIRTIO_DEV_READY)
> +		return 1;
> +
>  	if (dev->nr_vring < VIRTIO_DEV_NUM_VQS_TO_BE_READY)
>  		return 0;
> 
> @@ -1347,6 +1350,8 @@ virtio_is_ready(struct virtio_net *dev)
>  			return 0;
>  	}
> 
> +	dev->flags |= VIRTIO_DEV_READY;
> +
>  	if (!(dev->flags & VIRTIO_DEV_RUNNING))
>  		VHOST_LOG_CONFIG(INFO,
>  			"virtio is now ready for processing.\n"); @@ -2825,28
> +2830,32 @@ vhost_user_msg_handler(int vid, int fd)
>  	}
> 
> 
> -	if (!(dev->flags & VIRTIO_DEV_READY) && virtio_is_ready(dev)) {
> -		dev->flags |= VIRTIO_DEV_READY;
> +	if (!virtio_is_ready(dev))
> +		goto out;
> 
> -		if (!(dev->flags & VIRTIO_DEV_RUNNING)) {
> -			if (dev->dequeue_zero_copy) {
> -				VHOST_LOG_CONFIG(INFO,
> -						"dequeue zero copy is
> enabled\n");
> -			}
> +	/*
> +	 * Virtio is now ready. If not done already, it is time
> +	 * to notify the application it can process the rings and
> +	 * configure the vDPA device if present.
> +	 */
> 
> -			if (dev->notify_ops->new_device(dev->vid) == 0)
> -				dev->flags |= VIRTIO_DEV_RUNNING;
> -		}
> +	if (!(dev->flags & VIRTIO_DEV_RUNNING)) {
> +		if (dev->notify_ops->new_device(dev->vid) == 0)
> +			dev->flags |= VIRTIO_DEV_RUNNING;
>  	}
> 
>  	vdpa_dev = dev->vdpa_dev;
> -	if (vdpa_dev && virtio_is_ready(dev) &&
> -	    !(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED)) {
> +	if (!vdpa_dev)
> +		goto out;
> +
> +	if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED)) {
>  		if (vdpa_dev->ops->dev_conf)
>  			vdpa_dev->ops->dev_conf(dev->vid);
> +
>  		dev->flags |= VIRTIO_DEV_VDPA_CONFIGURED;
>  	}
> 
> +out:
>  	return 0;
>  }
> 
> --
> 2.26.2

Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
  

Patch

diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c
index 0d822d6a3..aa1424261 100644
--- a/lib/librte_vhost/vhost.c
+++ b/lib/librte_vhost/vhost.c
@@ -710,6 +710,7 @@  vhost_enable_dequeue_zero_copy(int vid)
 		return;
 
 	dev->dequeue_zero_copy = 1;
+	VHOST_LOG_CONFIG(INFO, "dequeue zero copy is enabled\n");
 }
 
 void
diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c
index 5750dde6d..ff8b1752b 100644
--- a/lib/librte_vhost/vhost_user.c
+++ b/lib/librte_vhost/vhost_user.c
@@ -1337,6 +1337,9 @@  virtio_is_ready(struct virtio_net *dev)
 	struct vhost_virtqueue *vq;
 	uint32_t i;
 
+	if (dev->flags & VIRTIO_DEV_READY)
+		return 1;
+
 	if (dev->nr_vring < VIRTIO_DEV_NUM_VQS_TO_BE_READY)
 		return 0;
 
@@ -1347,6 +1350,8 @@  virtio_is_ready(struct virtio_net *dev)
 			return 0;
 	}
 
+	dev->flags |= VIRTIO_DEV_READY;
+
 	if (!(dev->flags & VIRTIO_DEV_RUNNING))
 		VHOST_LOG_CONFIG(INFO,
 			"virtio is now ready for processing.\n");
@@ -2825,28 +2830,32 @@  vhost_user_msg_handler(int vid, int fd)
 	}
 
 
-	if (!(dev->flags & VIRTIO_DEV_READY) && virtio_is_ready(dev)) {
-		dev->flags |= VIRTIO_DEV_READY;
+	if (!virtio_is_ready(dev))
+		goto out;
 
-		if (!(dev->flags & VIRTIO_DEV_RUNNING)) {
-			if (dev->dequeue_zero_copy) {
-				VHOST_LOG_CONFIG(INFO,
-						"dequeue zero copy is enabled\n");
-			}
+	/*
+	 * Virtio is now ready. If not done already, it is time
+	 * to notify the application it can process the rings and
+	 * configure the vDPA device if present.
+	 */
 
-			if (dev->notify_ops->new_device(dev->vid) == 0)
-				dev->flags |= VIRTIO_DEV_RUNNING;
-		}
+	if (!(dev->flags & VIRTIO_DEV_RUNNING)) {
+		if (dev->notify_ops->new_device(dev->vid) == 0)
+			dev->flags |= VIRTIO_DEV_RUNNING;
 	}
 
 	vdpa_dev = dev->vdpa_dev;
-	if (vdpa_dev && virtio_is_ready(dev) &&
-	    !(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED)) {
+	if (!vdpa_dev)
+		goto out;
+
+	if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED)) {
 		if (vdpa_dev->ops->dev_conf)
 			vdpa_dev->ops->dev_conf(dev->vid);
+
 		dev->flags |= VIRTIO_DEV_VDPA_CONFIGURED;
 	}
 
+out:
 	return 0;
 }