DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] examples/vhost_blk: check protocol feature before get inflight info
@ 2021-02-02  9:10 Keiichi Watanabe
  2021-03-19  9:16 ` Maxime Coquelin
  0 siblings, 1 reply; 2+ messages in thread
From: Keiichi Watanabe @ 2021-02-02  9:10 UTC (permalink / raw)
  To: dev; +Cc: dgreid, chirantan, Keiichi Watanabe, Maxime Coquelin, Chenbo Xia

Avoid calling rte_vhost_get_vhost_ring_inflight() and
rte_vhost_get_vring_base_from_inflight() when
VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD is not set.

Signed-off-by: Keiichi Watanabe <keiichiw@chromium.org>
---
 examples/vhost_blk/vhost_blk.c | 22 +++++++++++++++++-----
 lib/librte_vhost/rte_vhost.h   | 13 +++++++++++++
 lib/librte_vhost/vhost.c       | 14 ++++++++++++++
 3 files changed, 44 insertions(+), 5 deletions(-)

diff --git a/examples/vhost_blk/vhost_blk.c b/examples/vhost_blk/vhost_blk.c
index 7ea60863d..9f3e157a0 100644
--- a/examples/vhost_blk/vhost_blk.c
+++ b/examples/vhost_blk/vhost_blk.c
@@ -603,10 +603,10 @@ new_device(int vid)
 	struct vhost_blk_ctrlr *ctrlr;
 	struct vhost_blk_queue *vq;
 	char path[PATH_MAX];
-	uint64_t features;
+	uint64_t features, protocol_features;
 	pthread_t tid;
 	int i, ret;
-	bool packed_ring;
+	bool packed_ring, inflight_shmfd;
 
 	ret = rte_vhost_get_ifname(vid, path, PATH_MAX);
 	if (ret) {
@@ -631,6 +631,15 @@ new_device(int vid)
 	}
 	packed_ring = !!(features & (1ULL << VIRTIO_F_RING_PACKED));
 
+	ret = rte_vhost_get_negotiated_protocol_features(
+		vid, &protocol_features);
+	if (ret) {
+		fprintf(stderr,
+			"Failed to get the negotiated protocol features\n");
+		return -1;
+	}
+	inflight_shmfd = !!(features & (1ULL << VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD));
+
 	/* Disable Notifications and init last idx */
 	for (i = 0; i < NUM_OF_BLK_QUEUES; i++) {
 		vq = &ctrlr->queues[i];
@@ -641,10 +650,13 @@ new_device(int vid)
 		assert(rte_vhost_get_vring_base(ctrlr->vid, i,
 					       &vq->last_avail_idx,
 					       &vq->last_used_idx) == 0);
-		assert(rte_vhost_get_vhost_ring_inflight(ctrlr->vid, i,
-						&vq->inflight_ring) == 0);
 
-		if (packed_ring) {
+		if (inflight_shmfd)
+			assert(rte_vhost_get_vhost_ring_inflight(
+				       ctrlr->vid, i,
+				       &vq->inflight_ring) == 0);
+
+		if (packed_ring && inflight_shmfd) {
 			/* for the reconnection */
 			assert(rte_vhost_get_vring_base_from_inflight(
 				ctrlr->vid, i,
diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h
index 010f16086..2744374af 100644
--- a/lib/librte_vhost/rte_vhost.h
+++ b/lib/librte_vhost/rte_vhost.h
@@ -567,6 +567,19 @@ rte_vhost_driver_get_queue_num(const char *path, uint32_t *queue_num);
  */
 int rte_vhost_get_negotiated_features(int vid, uint64_t *features);
 
+/**
+ * Get the protocol feature bits after negotiation
+ *
+ * @param vid
+ *  Vhost device ID
+ * @param protocol_features
+ *  A pointer to store the queried protocol feature bits
+ * @return
+ *  0 on success, -1 on failure
+ */
+int rte_vhost_get_negotiated_protocol_features(int vid,
+		uint64_t *protocol_features);
+
 /* Register callbacks. */
 int rte_vhost_driver_callback_register(const char *path,
 	struct vhost_device_ops const * const ops);
diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c
index efb136edd..61189ce93 100644
--- a/lib/librte_vhost/vhost.c
+++ b/lib/librte_vhost/vhost.c
@@ -868,6 +868,20 @@ rte_vhost_get_negotiated_features(int vid, uint64_t *features)
 	return 0;
 }
 
+int
+rte_vhost_get_negotiated_protocol_features(int vid,
+					   uint64_t *protocol_features)
+{
+	struct virtio_net *dev;
+
+	dev = get_device(vid);
+	if (dev == NULL || protocol_features == NULL)
+		return -1;
+
+	*protocol_features = dev->protocol_features;
+	return 0;
+}
+
 int
 rte_vhost_get_mem_table(int vid, struct rte_vhost_memory **mem)
 {
-- 
2.30.0.365.g02bc693789-goog


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

* Re: [dpdk-dev] [PATCH] examples/vhost_blk: check protocol feature before get inflight info
  2021-02-02  9:10 [dpdk-dev] [PATCH] examples/vhost_blk: check protocol feature before get inflight info Keiichi Watanabe
@ 2021-03-19  9:16 ` Maxime Coquelin
  0 siblings, 0 replies; 2+ messages in thread
From: Maxime Coquelin @ 2021-03-19  9:16 UTC (permalink / raw)
  To: Keiichi Watanabe, dev; +Cc: dgreid, chirantan, Chenbo Xia

Hi Keiichi,

On 2/2/21 10:10 AM, Keiichi Watanabe wrote:
> Avoid calling rte_vhost_get_vhost_ring_inflight() and
> rte_vhost_get_vring_base_from_inflight() when
> VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD is not set.
> 
> Signed-off-by: Keiichi Watanabe <keiichiw@chromium.org>
> ---
>  examples/vhost_blk/vhost_blk.c | 22 +++++++++++++++++-----
>  lib/librte_vhost/rte_vhost.h   | 13 +++++++++++++
>  lib/librte_vhost/vhost.c       | 14 ++++++++++++++
>  3 files changed, 44 insertions(+), 5 deletions(-)
> 
> diff --git a/examples/vhost_blk/vhost_blk.c b/examples/vhost_blk/vhost_blk.c
> index 7ea60863d..9f3e157a0 100644
> --- a/examples/vhost_blk/vhost_blk.c
> +++ b/examples/vhost_blk/vhost_blk.c
> @@ -603,10 +603,10 @@ new_device(int vid)
>  	struct vhost_blk_ctrlr *ctrlr;
>  	struct vhost_blk_queue *vq;
>  	char path[PATH_MAX];
> -	uint64_t features;
> +	uint64_t features, protocol_features;
>  	pthread_t tid;
>  	int i, ret;
> -	bool packed_ring;
> +	bool packed_ring, inflight_shmfd;
>  
>  	ret = rte_vhost_get_ifname(vid, path, PATH_MAX);
>  	if (ret) {
> @@ -631,6 +631,15 @@ new_device(int vid)
>  	}
>  	packed_ring = !!(features & (1ULL << VIRTIO_F_RING_PACKED));
>  
> +	ret = rte_vhost_get_negotiated_protocol_features(
> +		vid, &protocol_features);
> +	if (ret) {
> +		fprintf(stderr,
> +			"Failed to get the negotiated protocol features\n");
> +		return -1;
> +	}
> +	inflight_shmfd = !!(features & (1ULL << VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD));
> +
>  	/* Disable Notifications and init last idx */
>  	for (i = 0; i < NUM_OF_BLK_QUEUES; i++) {
>  		vq = &ctrlr->queues[i];
> @@ -641,10 +650,13 @@ new_device(int vid)
>  		assert(rte_vhost_get_vring_base(ctrlr->vid, i,
>  					       &vq->last_avail_idx,
>  					       &vq->last_used_idx) == 0);
> -		assert(rte_vhost_get_vhost_ring_inflight(ctrlr->vid, i,
> -						&vq->inflight_ring) == 0);
>  
> -		if (packed_ring) {
> +		if (inflight_shmfd)
> +			assert(rte_vhost_get_vhost_ring_inflight(
> +				       ctrlr->vid, i,
> +				       &vq->inflight_ring) == 0);
> +
> +		if (packed_ring && inflight_shmfd) {
>  			/* for the reconnection */
>  			assert(rte_vhost_get_vring_base_from_inflight(
>  				ctrlr->vid, i,
> diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h
> index 010f16086..2744374af 100644
> --- a/lib/librte_vhost/rte_vhost.h
> +++ b/lib/librte_vhost/rte_vhost.h
> @@ -567,6 +567,19 @@ rte_vhost_driver_get_queue_num(const char *path, uint32_t *queue_num);
>   */
>  int rte_vhost_get_negotiated_features(int vid, uint64_t *features);
>  
> +/**
> + * Get the protocol feature bits after negotiation
> + *
> + * @param vid
> + *  Vhost device ID
> + * @param protocol_features
> + *  A pointer to store the queried protocol feature bits
> + * @return
> + *  0 on success, -1 on failure
> + */
> +int rte_vhost_get_negotiated_protocol_features(int vid,
> +		uint64_t *protocol_features);
> +
>  /* Register callbacks. */
>  int rte_vhost_driver_callback_register(const char *path,
>  	struct vhost_device_ops const * const ops);
> diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c
> index efb136edd..61189ce93 100644
> --- a/lib/librte_vhost/vhost.c
> +++ b/lib/librte_vhost/vhost.c
> @@ -868,6 +868,20 @@ rte_vhost_get_negotiated_features(int vid, uint64_t *features)
>  	return 0;
>  }
>  
> +int
> +rte_vhost_get_negotiated_protocol_features(int vid,
> +					   uint64_t *protocol_features)
> +{
> +	struct virtio_net *dev;
> +
> +	dev = get_device(vid);
> +	if (dev == NULL || protocol_features == NULL)
> +		return -1;
> +
> +	*protocol_features = dev->protocol_features;
> +	return 0;
> +}
> +
>  int
>  rte_vhost_get_mem_table(int vid, struct rte_vhost_memory **mem)
>  {
> 


The Vhost lib part should be in a dedicated patch and new API should be
added in its version.map as experimental.

Thanks,
Maxime


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

end of thread, other threads:[~2021-03-19  9:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-02  9:10 [dpdk-dev] [PATCH] examples/vhost_blk: check protocol feature before get inflight info Keiichi Watanabe
2021-03-19  9:16 ` Maxime Coquelin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).