Skip to contentSkip to conversation

provide thread unsafe async registration functions

PATCH Superseded Jiayu Hu 4 participants 49 messages May 28, 2021 – Jul 21, 2021

lore
Share & tools
lore

Jiayu Hu

author
#0 lore raw

cover provide thread unsafe async registration functions

Lock protection is needed during the vhost notifies the application of device readiness, so the first patch is to add lock protection. After performing locking, existed async vhost registration functions will cause deadlock, as they acquire lock too. So the second patch is to provide unsafe registration functions to support calling within vhost callback functions.

Jiayu Hu (2):
vhost: fix lock on device readiness notification
vhost: add thread unsafe async registration functions

 doc/guides/prog_guide/vhost_lib.rst |  12 +++
 lib/vhost/rte_vhost_async.h         |  42 ++++++++++
 lib/vhost/version.map               |   4 +
 lib/vhost/vhost.c                   | 161 +++++++++++++++++++++++++++---------
 lib/vhost/vhost_user.c              |   5 +-
 5 files changed, 180 insertions(+), 44 deletions(-)
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH 1/2 vhost: fix lock on device readiness notification

The vhost notifies the application of device readiness via vhost_user_notify_queue_state(), but calling this function is not protected by the lock. This patch is to make this function call lock protected.

Fixes d0fcc38f5fa4 ("vhost: improve device readiness notifications")
---
 lib/vhost/vhost_user.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
lib/vhost/vhost_user.c +2 -3
index 8f0eba6..dabce26 100644
@@ -2915,9 +2915,6 @@ vhost_user_msg_handler(int vid, int fd)
 		}
 	}
 
-	if (unlock_required)
-		vhost_user_unlock_all_queue_pairs(dev);
-
 	/* If message was not handled at this stage, treat it as an error */
 	if (!handled) {
 		VHOST_LOG_CONFIG(ERR,
@@ -2952,6 +2949,8 @@ vhost_user_msg_handler(int vid, int fd)
 		}
 	}
 
+	if (unlock_required)
+		vhost_user_unlock_all_queue_pairs(dev);
 
 	if (!virtio_is_ready(dev))
 		goto out;
Signature · 1 line
2.7.4
Reviewed-by on v1 1/2
#2 lore raw

Re: [dpdk-dev] [PATCH 1/2] vhost: fix lock on device readiness notification

Quoted 28 lines · Jiayu Hu

The vhost notifies the application of device readiness via vhost_user_notify_queue_state(), but calling this function is not protected by the lock. This patch is to make this function call lock protected.

Fixes d0fcc38f5fa4 ("vhost: improve device readiness notifications")
---
 lib/vhost/vhost_user.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
lib/vhost/vhost_user.c +0 -3
index 8f0eba6..dabce26 100644
@@ -2915,9 +2915,6 @@ vhost_user_msg_handler(int vid, int fd)
 		}
 	}
 
-	if (unlock_required)
-		vhost_user_unlock_all_queue_pairs(dev);
-
 	/* If message was not handled at this stage, treat it as an error */
 	if (!handled) {
 		VHOST_LOG_CONFIG(ERR,

lib/vhost/vhost_user.c vhost_user_msg_handler(int vid, int fd) · line 2956

Quoted 8 lines
lib/vhost/vhost_user.c +2 -0
@@ -2952,6 +2949,8 @@ vhost_user_msg_handler(int vid, int fd)
 		}
 	}
 
+	if (unlock_required)
+		vhost_user_unlock_all_queue_pairs(dev);
 
 	if (!virtio_is_ready(dev))
 		goto out;

Thanks,
Maxime

author
#3 lore raw

v2 cover provide thread unsafe async registration functions

In reply to Jiayu Hu

Lock protection is needed during the vhost notifies the application of device readiness, so the first patch adds lock protection. In addition, the second patch reworks async feature structure to improve readability. After performing locking, existed async vhost registration functions will cause deadlock, as they acquire lock too. The last patch provides thread unsafe registration functions to support calling within vhost callback functions.

v2:
* rework async feature structure
* fix typo in commit log

Jiayu Hu (3):
vhost: fix lock on device readiness notification
vhost: rework async feature struct
vhost: add thread unsafe async registeration functions

 doc/guides/prog_guide/vhost_lib.rst |  12 +++
 examples/vhost/main.c               |   4 +-
 lib/vhost/rte_vhost_async.h         |  63 +++++++++++----
 lib/vhost/version.map               |   4 +
 lib/vhost/vhost.c                   | 157 ++++++++++++++++++++++++++----------
 lib/vhost/vhost_user.c              |   5 +-
 6 files changed, 183 insertions(+), 62 deletions(-)
Signature · 1 line
2.7.4
author
#4 lore raw

PATCH v2 1/3 vhost: fix lock on device readiness notification

The vhost notifies the application of device readiness via vhost_user_notify_queue_state(), but calling this function is not protected by the lock. This patch is to make this function call lock protected.

Fixes d0fcc38f5fa4 ("vhost: improve device readiness notifications")
---
 lib/vhost/vhost_user.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
lib/vhost/vhost_user.c +2 -3
index 031c578..31300e1 100644
@@ -2995,9 +2995,6 @@ vhost_user_msg_handler(int vid, int fd)
 		}
 	}
 
-	if (unlock_required)
-		vhost_user_unlock_all_queue_pairs(dev);
-
 	/* If message was not handled at this stage, treat it as an error */
 	if (!handled) {
 		VHOST_LOG_CONFIG(ERR,
@@ -3032,6 +3029,8 @@ vhost_user_msg_handler(int vid, int fd)
 		}
 	}
 
+	if (unlock_required)
+		vhost_user_unlock_all_queue_pairs(dev);
 
 	if (!virtio_is_ready(dev))
 		goto out;
Signature · 1 line
2.7.4
author
#5 lore raw

v3 cover provide thread unsafe async registration functions

Lock protection is needed during the vhost notifies the application of device readiness, so the first patch adds lock protection. In addition, the second patch reworks async feature structure to improve readability. After performing locking, existed async vhost registration functions will cause deadlock, as they acquire lock too. The last patch provides thread unsafe registration functions to support calling within vhost callback functions.

v3:
* rename and use enum to define async device features
* change padding fields to 8 bytes
v2:
* rework async feature structure
* fix typo in commit log

Jiayu Hu (3):
vhost: fix lock on device readiness notification
vhost: rework async configuration struct
vhost: add thread unsafe async registeration functions

 doc/guides/prog_guide/vhost_lib.rst |  31 +++++--
 examples/vhost/main.c               |   8 +-
 lib/vhost/rte_vhost_async.h         |  74 ++++++++++++----
 lib/vhost/version.map               |   4 +
 lib/vhost/vhost.c                   | 165 +++++++++++++++++++++++++++---------
 lib/vhost/vhost_user.c              |   5 +-
 6 files changed, 213 insertions(+), 74 deletions(-)
Signature · 1 line
2.7.4
author
#6 lore raw

PATCH v3 1/3 vhost: fix lock on device readiness notification

The vhost notifies the application of device readiness via vhost_user_notify_queue_state(), but calling this function is not protected by the lock. This patch is to make this function call lock protected.

Fixes d0fcc38f5fa4 ("vhost: improve device readiness notifications")
---
 lib/vhost/vhost_user.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
lib/vhost/vhost_user.c +2 -3
index 031c578..31300e1 100644
@@ -2995,9 +2995,6 @@ vhost_user_msg_handler(int vid, int fd)
 		}
 	}
 
-	if (unlock_required)
-		vhost_user_unlock_all_queue_pairs(dev);
-
 	/* If message was not handled at this stage, treat it as an error */
 	if (!handled) {
 		VHOST_LOG_CONFIG(ERR,
@@ -3032,6 +3029,8 @@ vhost_user_msg_handler(int vid, int fd)
 		}
 	}
 
+	if (unlock_required)
+		vhost_user_unlock_all_queue_pairs(dev);
 
 	if (!virtio_is_ready(dev))
 		goto out;
Signature · 1 line
2.7.4
author
#7 lore raw

v4 cover provide thread unsafe async registration functions

Lock protection is needed during the vhost notifies the application of device readiness, so the first patch adds lock protection. In addition, the second patch reworks async feature structure to improve readability. After performing locking, existed async vhost registration functions will cause deadlock, as they acquire lock too. The last patch provides thread unsafe registration functions to support calling within vhost callback functions.

v4:
* remove brace {} in single statement block v3:
* rename and use enum to define async device features
* change padding fields to 8 bytes
v2:
* rework async feature structure
* fix typo in commit log

Jiayu Hu (3):
vhost: fix lock on device readiness notification
vhost: rework async configuration struct
vhost: add thread unsafe async registeration functions

 doc/guides/prog_guide/vhost_lib.rst |  31 +++++--
 examples/vhost/main.c               |   8 +-
 lib/vhost/rte_vhost_async.h         |  74 ++++++++++++-----
 lib/vhost/version.map               |   4 +
 lib/vhost/vhost.c                   | 157 ++++++++++++++++++++++++++----------
 lib/vhost/vhost_user.c              |   5 +-
 6 files changed, 205 insertions(+), 74 deletions(-)
Signature · 1 line
2.7.4
author
#8 lore raw

PATCH v4 1/3 vhost: fix lock on device readiness notification

The vhost notifies the application of device readiness via vhost_user_notify_queue_state(), but calling this function is not protected by the lock. This patch is to make this function call lock protected.

Fixes d0fcc38f5fa4 ("vhost: improve device readiness notifications")
---
 lib/vhost/vhost_user.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
lib/vhost/vhost_user.c +2 -3
index 031c578..31300e1 100644
@@ -2995,9 +2995,6 @@ vhost_user_msg_handler(int vid, int fd)
 		}
 	}
 
-	if (unlock_required)
-		vhost_user_unlock_all_queue_pairs(dev);
-
 	/* If message was not handled at this stage, treat it as an error */
 	if (!handled) {
 		VHOST_LOG_CONFIG(ERR,
@@ -3032,6 +3029,8 @@ vhost_user_msg_handler(int vid, int fd)
 		}
 	}
 
+	if (unlock_required)
+		vhost_user_unlock_all_queue_pairs(dev);
 
 	if (!virtio_is_ready(dev))
 		goto out;
Signature · 1 line
2.7.4
author
#9 lore raw

v5 cover provide thread unsafe async registration functions

Lock protection is needed during the vhost notifies the application of device readiness, so the first patch adds lock protection. In addition, the second patch reworks async feature structure to improve readability. After performing locking, existed async vhost registration functions will cause deadlock, as they acquire lock too. The last patch provides thread unsafe registration functions to support calling within vhost callback functions.

v5:
* improve coding style
* update commit log, doc and comments
* remove useless field async_inorder
* change async_threshold from uint16_t to uint32_t v4:
* remove brace {} in single statement block v3:
* rename and use enum to define async device features
* change padding fields to 8 bytes
v2:
* rework async feature structure
* fix typo in commit log

Jiayu Hu (3):
vhost: fix lock on device readiness notification
vhost: rework async configuration structure
vhost: add thread unsafe async registeration functions

 doc/guides/prog_guide/vhost_lib.rst |  35 ++++++--
 examples/vhost/main.c               |   8 +-
 lib/vhost/rte_vhost_async.h         |  86 ++++++++++++++-----
 lib/vhost/version.map               |   4 +
 lib/vhost/vhost.c                   | 162 ++++++++++++++++++++++++++----------
 lib/vhost/vhost.h                   |   3 +-
 lib/vhost/vhost_user.c              |   5 +-
 7 files changed, 219 insertions(+), 84 deletions(-)
Signature · 1 line
2.7.4
author
#10 lore raw

PATCH v5 1/3 vhost: fix lock on device readiness notification

The vhost notifies the application of device readiness via vhost_user_notify_queue_state(), but calling this function is not protected by the lock. This patch is to make this function call lock protected.

Fixes d0fcc38f5fa4 ("vhost: improve device readiness notifications")
---
 lib/vhost/vhost_user.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
lib/vhost/vhost_user.c +2 -3
index 031c578..31300e1 100644
@@ -2995,9 +2995,6 @@ vhost_user_msg_handler(int vid, int fd)
 		}
 	}
 
-	if (unlock_required)
-		vhost_user_unlock_all_queue_pairs(dev);
-
 	/* If message was not handled at this stage, treat it as an error */
 	if (!handled) {
 		VHOST_LOG_CONFIG(ERR,
@@ -3032,6 +3029,8 @@ vhost_user_msg_handler(int vid, int fd)
 		}
 	}
 
+	if (unlock_required)
+		vhost_user_unlock_all_queue_pairs(dev);
 
 	if (!virtio_is_ready(dev))
 		goto out;
Signature · 1 line
2.7.4
author
#11 lore raw

v6 cover provide thread unsafe async registration functions

Lock protection is needed during the vhost notifies the application of device readiness, so the first patch adds lock protection. In addition, the second patch reworks async feature structure to improve readability. After performing locking, existed async vhost registration functions will cause deadlock, as they acquire lock too. The last patch provides thread unsafe registration functions to support calling within vhost callback functions.

v6:
* remove RTE_VHOST_ASYNC_FEATURE_UNKNOWN
* add blank lines in doc
v5:
* improve coding style
* update commit log, doc and comments
* remove useless field async_inorder
* change async_threshold from uint16_t to uint32_t v4:
* remove brace {} in single statement block v3:
* rename and use enum to define async device features
* change padding fields to 8 bytes
v2:
* rework async feature structure
* fix typo in commit log

Jiayu Hu (3):
vhost: fix lock on device readiness notification
vhost: rework async configuration structure
vhost: add thread unsafe async registeration functions

 doc/guides/prog_guide/vhost_lib.rst |  37 ++++++--
 examples/vhost/main.c               |   8 +-
 lib/vhost/rte_vhost_async.h         |  85 ++++++++++++++-----
 lib/vhost/version.map               |   4 +
 lib/vhost/vhost.c                   | 162 ++++++++++++++++++++++++++----------
 lib/vhost/vhost.h                   |   3 +-
 lib/vhost/vhost_user.c              |   5 +-
 7 files changed, 220 insertions(+), 84 deletions(-)
Signature · 1 line
2.7.4
author
#12 lore raw

PATCH v6 1/3 vhost: fix lock on device readiness notification

The vhost notifies the application of device readiness via vhost_user_notify_queue_state(), but calling this function is not protected by the lock. This patch is to make this function call lock protected.

Fixes d0fcc38f5fa4 ("vhost: improve device readiness notifications")
---
 lib/vhost/vhost_user.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
lib/vhost/vhost_user.c +2 -3
index 031c578..31300e1 100644
@@ -2995,9 +2995,6 @@ vhost_user_msg_handler(int vid, int fd)
 		}
 	}
 
-	if (unlock_required)
-		vhost_user_unlock_all_queue_pairs(dev);
-
 	/* If message was not handled at this stage, treat it as an error */
 	if (!handled) {
 		VHOST_LOG_CONFIG(ERR,
@@ -3032,6 +3029,8 @@ vhost_user_msg_handler(int vid, int fd)
 		}
 	}
 
+	if (unlock_required)
+		vhost_user_unlock_all_queue_pairs(dev);
 
 	if (!virtio_is_ready(dev))
 		goto out;
Signature · 1 line
2.7.4
author
#13 lore raw

PATCH v6 2/3 vhost: rework async configuration structure

In reply to Jiayu Hu

This patch reworks the async configuration structure to improve code readability. In addition, add preserved padding fields on the structure for future usage.

---
 doc/guides/prog_guide/vhost_lib.rst | 21 ++++++++++--------
 examples/vhost/main.c               |  8 +++----
 lib/vhost/rte_vhost_async.h         | 44 ++++++++++++++++++-------------------
 lib/vhost/vhost.c                   | 19 +++++++---------
 lib/vhost/vhost.h                   |  3 +--
 5 files changed, 46 insertions(+), 49 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +12 -9
index d18fb98..2a61b85 100644
@@ -218,26 +218,29 @@ The following is an overview of some key Vhost API functions:
 
   Enable or disable zero copy feature of the vhost crypto backend.
 
-* ``rte_vhost_async_channel_register(vid, queue_id, features, ops)``
+* ``rte_vhost_async_channel_register(vid, queue_id, config, ops)``
 
-  Register a vhost queue with async copy device channel after vring
-  is enabled. Following device ``features`` must be specified together
+  Register an async copy device channel for a vhost queue after vring
+  is enabled. Following device ``config`` must be specified together
   with the registration:
 
-  * ``async_inorder``
+  * ``features``
 
-    Async copy device can guarantee the ordering of copy completion
-    sequence. Copies are completed in the same order with that at
-    the submission time.
+    This field is used to specify async copy device features.
 
-    Currently, only ``async_inorder`` capable device is supported by vhost.
+    ``RTE_VHOST_ASYNC_INORDER`` represents the async copy device can
+    guarantee the order of copy completion is the same as the order
+    of copy submission.
+
+    Currently, only ``RTE_VHOST_ASYNC_INORDER`` capable device is
+    supported by vhost.
 
   * ``async_threshold``
 
     The copy length (in bytes) below which CPU copy will be used even if
     applications call async vhost APIs to enqueue/dequeue data.
 
-    Typical value is 512~1024 depending on the async device capability.
+    Typical value is 256~1024 depending on the async device capability.
 
   Applications must provide following ``ops`` callbacks for vhost lib to
   work with the async copy devices:
examples/vhost/main.c +4 -4
index d2179ea..9cd855a 100644
@@ -1468,7 +1468,7 @@ new_device(int vid)
 		vid, vdev->coreid);
 
 	if (async_vhost_driver) {
-		struct rte_vhost_async_features f;
+		struct rte_vhost_async_config config = {0};
 		struct rte_vhost_async_channel_ops channel_ops;
 
 		if (dma_type != NULL && strncmp(dma_type, "ioat", 4) == 0) {
@@ -1476,11 +1476,11 @@ new_device(int vid)
 			channel_ops.check_completed_copies =
 				ioat_check_completed_copies_cb;
 
-			f.async_inorder = 1;
-			f.async_threshold = 256;
+			config.features = RTE_VHOST_ASYNC_INORDER;
+			config.async_threshold = 256;
 
 			return rte_vhost_async_channel_register(vid, VIRTIO_RXQ,
-				f.intval, &channel_ops);
+				config, &channel_ops);
 		}
 	}
 
lib/vhost/rte_vhost_async.h +21 -23

70 lines not on this page · raw message

lib/vhost/vhost.c +8 -11
index 53a470f..908758e 100644
@@ -1619,19 +1619,17 @@ int rte_vhost_extern_callback_register(int vid,
 	return 0;
 }
 
-int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
-					uint32_t features,
-					struct rte_vhost_async_channel_ops *ops)
+int
+rte_vhost_async_channel_register(int vid, uint16_t queue_id,
+		struct rte_vhost_async_config config,
+		struct rte_vhost_async_channel_ops *ops)
 {
 	struct vhost_virtqueue *vq;
 	struct virtio_net *dev = get_device(vid);
-	struct rte_vhost_async_features f;
 
 	if (dev == NULL || ops == NULL)
 		return -1;
 
-	f.intval = features;
-
 	if (queue_id >= VHOST_MAX_VRING)
 		return -1;
 
@@ -1640,7 +1638,7 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
 	if (unlikely(vq == NULL || !dev->async_copy))
 		return -1;
 
-	if (unlikely(!f.async_inorder)) {
+	if (unlikely(!(config.features & RTE_VHOST_ASYNC_INORDER))) {
 		VHOST_LOG_CONFIG(ERR,
 			"async copy is not supported on non-inorder mode "
 			"(vid %d, qid: %d)\n", vid, queue_id);
@@ -1719,9 +1717,7 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
 
 	vq->async_ops.check_completed_copies = ops->check_completed_copies;
 	vq->async_ops.transfer_data = ops->transfer_data;
-
-	vq->async_inorder = f.async_inorder;
-	vq->async_threshold = f.async_threshold;
+	vq->async_threshold = config.async_threshold;
 
 	vq->async_registered = true;
 
@@ -1731,7 +1727,8 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
 	return 0;
 }
 
-int rte_vhost_async_channel_unregister(int vid, uint16_t queue_id)
+int
+rte_vhost_async_channel_unregister(int vid, uint16_t queue_id)
 {
 	struct vhost_virtqueue *vq;
 	struct virtio_net *dev = get_device(vid);
lib/vhost/vhost.h +1 -2
index 8ffe387..d98ca8a 100644
@@ -218,9 +218,8 @@ struct vhost_virtqueue {
 	};
 
 	/* vq async features */
-	bool		async_inorder;
 	bool		async_registered;
-	uint16_t	async_threshold;
+	uint32_t	async_threshold;
 
 	int			notif_enable;
 #define VIRTIO_UNINITIALIZED_NOTIF	(-1)
Signature · 1 line
2.7.4
Reviewed-by on v6 2/3
#14 lore raw

Re: [dpdk-dev] [PATCH v6 2/3] vhost: rework async configuration structure

Quoted 6 lines · Jiayu Hu

This patch reworks the async configuration structure to improve code readability. In addition, add preserved padding fields on the structure for future usage.

Quoted 7 lines
---
 doc/guides/prog_guide/vhost_lib.rst | 21 ++++++++++--------
 examples/vhost/main.c               |  8 +++----
 lib/vhost/rte_vhost_async.h         | 44 ++++++++++++++++++-------------------
 lib/vhost/vhost.c                   | 19 +++++++---------
 lib/vhost/vhost.h                   |  3 +--
 5 files changed, 46 insertions(+), 49 deletions(-)

Please see one comment below:

Quoted 84 lines
doc/guides/prog_guide/vhost_lib.rst +12 -9
index d18fb98..2a61b85 100644
@@ -218,26 +218,29 @@ The following is an overview of some key Vhost API functions:
 
   Enable or disable zero copy feature of the vhost crypto backend.
 
-* ``rte_vhost_async_channel_register(vid, queue_id, features, ops)``
+* ``rte_vhost_async_channel_register(vid, queue_id, config, ops)``
 
-  Register a vhost queue with async copy device channel after vring
-  is enabled. Following device ``features`` must be specified together
+  Register an async copy device channel for a vhost queue after vring
+  is enabled. Following device ``config`` must be specified together
   with the registration:
 
-  * ``async_inorder``
+  * ``features``
 
-    Async copy device can guarantee the ordering of copy completion
-    sequence. Copies are completed in the same order with that at
-    the submission time.
+    This field is used to specify async copy device features.
 
-    Currently, only ``async_inorder`` capable device is supported by vhost.
+    ``RTE_VHOST_ASYNC_INORDER`` represents the async copy device can
+    guarantee the order of copy completion is the same as the order
+    of copy submission.
+
+    Currently, only ``RTE_VHOST_ASYNC_INORDER`` capable device is
+    supported by vhost.
 
   * ``async_threshold``
 
     The copy length (in bytes) below which CPU copy will be used even if
     applications call async vhost APIs to enqueue/dequeue data.
 
-    Typical value is 512~1024 depending on the async device capability.
+    Typical value is 256~1024 depending on the async device capability.
 
   Applications must provide following ``ops`` callbacks for vhost lib to
   work with the async copy devices:
examples/vhost/main.c +4 -4
index d2179ea..9cd855a 100644
@@ -1468,7 +1468,7 @@ new_device(int vid)
 		vid, vdev->coreid);
 
 	if (async_vhost_driver) {
-		struct rte_vhost_async_features f;
+		struct rte_vhost_async_config config = {0};
 		struct rte_vhost_async_channel_ops channel_ops;
 
 		if (dma_type != NULL && strncmp(dma_type, "ioat", 4) == 0) {
@@ -1476,11 +1476,11 @@ new_device(int vid)
 			channel_ops.check_completed_copies =
 				ioat_check_completed_copies_cb;
 
-			f.async_inorder = 1;
-			f.async_threshold = 256;
+			config.features = RTE_VHOST_ASYNC_INORDER;
+			config.async_threshold = 256;
 
 			return rte_vhost_async_channel_register(vid, VIRTIO_RXQ,
-				f.intval, &channel_ops);
+				config, &channel_ops);
 		}
 	}
 
lib/vhost/rte_vhost_async.h +1 -3
index 6faa31f..ef8c1a2 100644
@@ -93,49 +93,47 @@ struct async_inflight_info {
 };
 
 /**
- *  dma channel feature bit definition
+ *  async channel features
  */
-struct rte_vhost_async_features {
-	union {

lib/vhost/rte_vhost_async.h struct async_inflight_info { · line 99

Quoted 10 lines
lib/vhost/rte_vhost_async.h +2 -8
-		uint32_t intval;
-		struct {
-			uint32_t async_inorder:1;
-			uint32_t resvd_0:15;
-			uint32_t async_threshold:12;
-			uint32_t resvd_1:4;
-		};
-	};
+enum {
+	RTE_VHOST_ASYNC_INORDER = 1U << 0,

I think I understand the point of this flag, but the naming is misleading. The code later on fails registration if the "INORDER" flag is not passed, but the code behaves in the opposite, it does not support Virtio INORDER mode as soon as a threashold is used.

Why do we need the DMA to write the descriptors buffers in order? My understanding is that it is an optimization in order to ease the DMA completion handling. So we are requiring DMA to be in-order, but on the other hand we cannot guarantee the Virtio ring to be handled in order, moving the complexity (and potential performance cost) to the guest.

Quoted 126 lines
lib/vhost/rte_vhost_async.h +18 -12
 };
 
 /**
- * register an async channel for vhost
+ *  async channel configuration
+ */
+struct rte_vhost_async_config {
+	uint32_t async_threshold;
+	uint32_t features;
+	uint32_t rsvd[2];
+};
+
+/**
+ * Register an async channel for a vhost queue
  *
  * @param vid
  *  vhost device id async channel to be attached to
  * @param queue_id
  *  vhost queue id async channel to be attached to
- * @param features
- *  DMA channel feature bit
- *    b0       : DMA supports inorder data transfer
- *    b1  - b15: reserved
- *    b16 - b27: Packet length threshold for DMA transfer
- *    b28 - b31: reserved
+ * @param config
+ *  Async channel configuration structure
  * @param ops
- *  DMA operation callbacks
+ *  Async channel operation callbacks
  * @return
  *  0 on success, -1 on failures
  */
 __rte_experimental
 int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
-	uint32_t features, struct rte_vhost_async_channel_ops *ops);
+	struct rte_vhost_async_config config,
+	struct rte_vhost_async_channel_ops *ops);
 
 /**
- * unregister a dma channel for vhost
+ * Unregister an async channel for a vhost queue
  *
  * @param vid
- *  vhost device id DMA channel to be detached
+ *  vhost device id async channel to be detached from
  * @param queue_id
- *  vhost queue id DMA channel to be detached
+ *  vhost queue id async channel to be detached from
  * @return
  *  0 on success, -1 on failures
  */
lib/vhost/vhost.c +8 -11
index 53a470f..908758e 100644
@@ -1619,19 +1619,17 @@ int rte_vhost_extern_callback_register(int vid,
 	return 0;
 }
 
-int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
-					uint32_t features,
-					struct rte_vhost_async_channel_ops *ops)
+int
+rte_vhost_async_channel_register(int vid, uint16_t queue_id,
+		struct rte_vhost_async_config config,
+		struct rte_vhost_async_channel_ops *ops)
 {
 	struct vhost_virtqueue *vq;
 	struct virtio_net *dev = get_device(vid);
-	struct rte_vhost_async_features f;
 
 	if (dev == NULL || ops == NULL)
 		return -1;
 
-	f.intval = features;
-
 	if (queue_id >= VHOST_MAX_VRING)
 		return -1;
 
@@ -1640,7 +1638,7 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
 	if (unlikely(vq == NULL || !dev->async_copy))
 		return -1;
 
-	if (unlikely(!f.async_inorder)) {
+	if (unlikely(!(config.features & RTE_VHOST_ASYNC_INORDER))) {
 		VHOST_LOG_CONFIG(ERR,
 			"async copy is not supported on non-inorder mode "
 			"(vid %d, qid: %d)\n", vid, queue_id);
@@ -1719,9 +1717,7 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
 
 	vq->async_ops.check_completed_copies = ops->check_completed_copies;
 	vq->async_ops.transfer_data = ops->transfer_data;
-
-	vq->async_inorder = f.async_inorder;
-	vq->async_threshold = f.async_threshold;
+	vq->async_threshold = config.async_threshold;
 
 	vq->async_registered = true;
 
@@ -1731,7 +1727,8 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
 	return 0;
 }
 
-int rte_vhost_async_channel_unregister(int vid, uint16_t queue_id)
+int
+rte_vhost_async_channel_unregister(int vid, uint16_t queue_id)
 {
 	struct vhost_virtqueue *vq;
 	struct virtio_net *dev = get_device(vid);
lib/vhost/vhost.h +1 -2
index 8ffe387..d98ca8a 100644
@@ -218,9 +218,8 @@ struct vhost_virtqueue {
 	};
 
 	/* vq async features */
-	bool		async_inorder;
 	bool		async_registered;
-	uint16_t	async_threshold;
+	uint32_t	async_threshold;
 
 	int			notif_enable;
 #define VIRTIO_UNINITIALIZED_NOTIF	(-1)
author
#15 lore raw

Re: [dpdk-dev] [PATCH v6 2/3] vhost: rework async configuration structure

Quoted 136 lines

-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Tuesday, July 20, 2021 3:18 PM
To: Hu, Jiayu <[email protected]>; [email protected]
Cc: Xia, Chenbo <[email protected]>
Subject: Re: [PATCH v6 2/3] vhost: rework async configuration structure

Quoted 6 lines · Jiayu Hu

This patch reworks the async configuration structure to improve code readability. In addition, add preserved padding fields on the structure for future usage.

Quoted 7 lines
---
 doc/guides/prog_guide/vhost_lib.rst | 21 ++++++++++--------
 examples/vhost/main.c               |  8 +++----
 lib/vhost/rte_vhost_async.h         | 44 ++++++++++++++++++-------------------
 lib/vhost/vhost.c                   | 19 +++++++---------
 lib/vhost/vhost.h                   |  3 +--
 5 files changed, 46 insertions(+), 49 deletions(-)

Please see one comment below:

doc/guides/prog_guide/vhost_lib.rst The following is an overview of some key Vhost

Quoted 6 lines
doc/guides/prog_guide/vhost_lib.rst +0 -0
index d18fb98..2a61b85 100644
@@ -218,26 +218,29 @@ The following is an overview of some key Vhost

API functions:

Quoted 44 lines
doc/guides/prog_guide/vhost_lib.rst +1 -3
   Enable or disable zero copy feature of the vhost crypto backend.
 
-* ``rte_vhost_async_channel_register(vid, queue_id, features, ops)``
+* ``rte_vhost_async_channel_register(vid, queue_id, config, ops)``
 
-  Register a vhost queue with async copy device channel after vring
-  is enabled. Following device ``features`` must be specified

together

doc/guides/prog_guide/vhost_lib.rst +11 -6
+  Register an async copy device channel for a vhost queue after vring
+ is enabled. Following device ``config`` must be specified together
   with the registration:
 
-  * ``async_inorder``
+  * ``features``
 
-    Async copy device can guarantee the ordering of copy completion
-    sequence. Copies are completed in the same order with that at
-    the submission time.
+    This field is used to specify async copy device features.
 
-    Currently, only ``async_inorder`` capable device is supported by vhost.
+    ``RTE_VHOST_ASYNC_INORDER`` represents the async copy device can
+    guarantee the order of copy completion is the same as the order
+    of copy submission.
+
+    Currently, only ``RTE_VHOST_ASYNC_INORDER`` capable device is
+    supported by vhost.
 
   * ``async_threshold``
 
     The copy length (in bytes) below which CPU copy will be used even if
     applications call async vhost APIs to enqueue/dequeue data.
 
-    Typical value is 512~1024 depending on the async device capability.
+    Typical value is 256~1024 depending on the async device capability.
 
   Applications must provide following ``ops`` callbacks for vhost lib to
   work with the async copy devices:
examples/vhost/main.c index renamed from examples/vhost/main.c +0 -0

d2179ea..9cd855a 100644

examples/vhost/main.c new_device(int vid) · line 1474

Quoted 8 lines
examples/vhost/main.c +1 -1
@@ -1468,7 +1468,7 @@ new_device(int vid)
 		vid, vdev->coreid);
 
 	if (async_vhost_driver) {
-		struct rte_vhost_async_features f;
+		struct rte_vhost_async_config config = {0};
 		struct rte_vhost_async_channel_ops channel_ops;
 
 		if (dma_type != NULL && strncmp(dma_type, "ioat", 4) == 0)

{ @@

examples/vhost/main.c new_device(int vid)

Quoted 10 lines

-1476,11 +1476,11 @@ new_device(int vid)

examples/vhost/main.c +2 -2
 			channel_ops.check_completed_copies =
 				ioat_check_completed_copies_cb;
 
-			f.async_inorder = 1;
-			f.async_threshold = 256;
+			config.features = RTE_VHOST_ASYNC_INORDER;
+			config.async_threshold = 256;
 
 			return rte_vhost_async_channel_register(vid,

VIRTIO_RXQ,

Quoted 17 lines
examples/vhost/main.c +1 -1
-				f.intval, &channel_ops);
+				config, &channel_ops);
 		}
 	}
lib/vhost/rte_vhost_async.h +1 -3
index 6faa31f..ef8c1a2 100644
@@ -93,49 +93,47 @@ struct async_inflight_info {  };
 
 /**
- *  dma channel feature bit definition
+ *  async channel features
  */
-struct rte_vhost_async_features {
-	union {

lib/vhost/rte_vhost_async.h struct async_inflight_info { }; · line 98

Quoted 10 lines
lib/vhost/rte_vhost_async.h +2 -8
-		uint32_t intval;
-		struct {
-			uint32_t async_inorder:1;
-			uint32_t resvd_0:15;
-			uint32_t async_threshold:12;
-			uint32_t resvd_1:4;
-		};
-	};
+enum {
+	RTE_VHOST_ASYNC_INORDER = 1U << 0,

I think I understand the point of this flag, but the naming is misleading. The code later on fails registration if the "INORDER" flag is not passed, but the code behaves in the opposite, it does not support Virtio INORDER mode as soon as a threashold is used.

Quoted 5 lines

Why do we need the DMA to write the descriptors buffers in order? My understanding is that it is an optimization in order to ease the DMA completion handling. So we are requiring DMA to be in-order, but on the other hand we cannot guarantee the Virtio ring to be handled in order, moving the complexity (and potential performance cost) to the guest.

Yes, the reason of requiring dma in-order is to simply vhost for higher performance. Another reason is that in some cases, where a vring only uses one DMA channel, the dma device guarantees the ordering already, so dma callback is in-ordered. For other apps, who want the most complex vring and dma channel mapping, i.e., multiple vring use multiple dma, the order is better to be implemented by itself, i.e., dma callback functions.

If we assume vring and dma channel mapping is M:N, the vhost lib implementation is going to be more complex. But in my opinion, the mapping relationship of vring and dma channel is per app specific. Implementing M:N inside vhost will sacrifice performance for the simplest use case.

Right, the name is misleading, and virtio INORDER mode doesn't work if setting threshold. But we'd better consider a tradeoff between dma efficiency and out-of-order impacts. I will measure the performance with removing threshold supporting in the code, and let's discuss with some data.

Thanks,
Jiayu

Quoted 131 lines
Quoted 58 lines
lib/vhost/rte_vhost_async.h +18 -12
 };
 
 /**
- * register an async channel for vhost
+ *  async channel configuration
+ */
+struct rte_vhost_async_config {
+	uint32_t async_threshold;
+	uint32_t features;
+	uint32_t rsvd[2];
+};
+
+/**
+ * Register an async channel for a vhost queue
  *
  * @param vid
  *  vhost device id async channel to be attached to
  * @param queue_id
  *  vhost queue id async channel to be attached to
- * @param features
- *  DMA channel feature bit
- *    b0       : DMA supports inorder data transfer
- *    b1  - b15: reserved
- *    b16 - b27: Packet length threshold for DMA transfer
- *    b28 - b31: reserved
+ * @param config
+ *  Async channel configuration structure
  * @param ops
- *  DMA operation callbacks
+ *  Async channel operation callbacks
  * @return
  *  0 on success, -1 on failures
  */
 __rte_experimental
 int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
-	uint32_t features, struct rte_vhost_async_channel_ops *ops);
+	struct rte_vhost_async_config config,
+	struct rte_vhost_async_channel_ops *ops);
 
 /**
- * unregister a dma channel for vhost
+ * Unregister an async channel for a vhost queue
  *
  * @param vid
- *  vhost device id DMA channel to be detached
+ *  vhost device id async channel to be detached from
  * @param queue_id
- *  vhost queue id DMA channel to be detached
+ *  vhost queue id async channel to be detached from
  * @return
  *  0 on success, -1 on failures
  */
lib/vhost/vhost.c index renamed from lib/vhost/vhost.c +0 -0

53a470f..908758e 100644

lib/vhost/vhost.c int rte_vhost_extern_callback_register(int vid, · line 1624

Quoted 6 lines
lib/vhost/vhost.c +0 -3
@@ -1619,19 +1619,17 @@ int rte_vhost_extern_callback_register(int vid,
 	return 0;
 }
 
-int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
-					uint32_t features,
-					struct rte_vhost_async_channel_ops

*ops)

lib/vhost/vhost.c int rte_vhost_async_channel_register(int vid,

Quoted 18 lines
lib/vhost/vhost.c +4 -3
+int
+rte_vhost_async_channel_register(int vid, uint16_t queue_id,
+		struct rte_vhost_async_config config,
+		struct rte_vhost_async_channel_ops *ops)
 {
 	struct vhost_virtqueue *vq;
 	struct virtio_net *dev = get_device(vid);
-	struct rte_vhost_async_features f;
 
 	if (dev == NULL || ops == NULL)
 		return -1;
 
-	f.intval = features;
-
 	if (queue_id >= VHOST_MAX_VRING)
 		return -1;
 
@@ -1640,7 +1638,7 @@ int rte_vhost_async_channel_register(int vid,

uint16_t queue_id,

lib/vhost/vhost.c int rte_vhost_async_channel_register(int vid, uint16_t queue_id,

Quoted 8 lines
lib/vhost/vhost.c +1 -1
 	if (unlikely(vq == NULL || !dev->async_copy))
 		return -1;
 
-	if (unlikely(!f.async_inorder)) {
+	if (unlikely(!(config.features & RTE_VHOST_ASYNC_INORDER))) {
 		VHOST_LOG_CONFIG(ERR,
 			"async copy is not supported on non-inorder mode "
 			"(vid %d, qid: %d)\n", vid, queue_id); @@ -1719,9

+1717,7 @@ int

lib/vhost/vhost.c int rte_vhost_async_channel_register(int vid,

Quoted 13 lines

rte_vhost_async_channel_register(int vid, uint16_t queue_id,

vq->async_ops.check_completed_copies = ops-
check_completed_copies;

lib/vhost/vhost.c +1 -3
 	vq->async_ops.transfer_data = ops->transfer_data;
-
-	vq->async_inorder = f.async_inorder;
-	vq->async_threshold = f.async_threshold;
+	vq->async_threshold = config.async_threshold;
 
 	vq->async_registered = true;
@@ -1731,7 +1727,8 @@ int rte_vhost_async_channel_register(int vid,

uint16_t queue_id,

Quoted 24 lines
lib/vhost/vhost.c +2 -1
 	return 0;
 }
 
-int rte_vhost_async_channel_unregister(int vid, uint16_t queue_id)
+int
+rte_vhost_async_channel_unregister(int vid, uint16_t queue_id)
 {
 	struct vhost_virtqueue *vq;
 	struct virtio_net *dev = get_device(vid); diff --git

a/lib/vhost/vhost.h b/lib/vhost/vhost.h index 8ffe387..d98ca8a 100644

lib/vhost/vhost.h +1 -2
@@ -218,9 +218,8 @@ struct vhost_virtqueue {
 	};
 
 	/* vq async features */
-	bool		async_inorder;
 	bool		async_registered;
-	uint16_t	async_threshold;
+	uint32_t	async_threshold;
 
 	int			notif_enable;
 #define VIRTIO_UNINITIALIZED_NOTIF	(-1)
author
#16 lore raw

PATCH v6 3/3 vhost: add thread unsafe async registeration functions

In reply to Jiayu Hu

This patch adds thread unsafe version for async register and unregister functions.

---
 doc/guides/prog_guide/vhost_lib.rst |  16 ++++
 lib/vhost/rte_vhost_async.h         |  41 ++++++++++
 lib/vhost/version.map               |   4 +
 lib/vhost/vhost.c                   | 149 +++++++++++++++++++++++++++---------
 4 files changed, 175 insertions(+), 35 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +16 -0
index 2a61b85..462393d 100644
@@ -256,6 +256,14 @@ The following is an overview of some key Vhost API functions:
     vhost invokes this function to get the copy data completed by async
     devices.
 
+* ``rte_vhost_async_channel_register_thread_unsafe(vid, queue_id, config, ops)``
+
+  Register an async copy device channel for a vhost queue without
+  performing any locking.
+
+  This function is only safe to call in vhost callback functions
+  (i.e., struct vhost_device_ops).
+
 * ``rte_vhost_async_channel_unregister(vid, queue_id)``
 
   Unregister the async copy device channel from a vhost queue.
@@ -268,6 +276,14 @@ The following is an overview of some key Vhost API functions:
   devices for all vhost queues in destroy_device(), when a
   virtio device is paused or shut down.
 
+* ``rte_vhost_async_channel_unregister_thread_unsafe(vid, queue_id)``
+
+  Unregister the async copy device channel for a vhost queue without
+  performing any locking.
+
+  This function is only safe to call in vhost callback functions
+  (i.e., struct vhost_device_ops).
+
 * ``rte_vhost_submit_enqueue_burst(vid, queue_id, pkts, count, comp_pkts, comp_count)``
 
   Submit an enqueue request to transmit ``count`` packets from host to guest
lib/vhost/rte_vhost_async.h +41 -0

47 lines not on this page · raw message

lib/vhost/version.map +4 -0
index 9103a23..2363db8 100644
@@ -79,4 +79,8 @@ EXPERIMENTAL {
 
 	# added in 21.05
 	rte_vhost_get_negotiated_protocol_features;
+
+	# added in 21.08
+	rte_vhost_async_channel_register_thread_unsafe;
+	rte_vhost_async_channel_unregister_thread_unsafe;
 };
lib/vhost/vhost.c +114 -35

207 lines not on this page · raw message

Signature · 1 line
2.7.4
Reviewed-by on v6 3/3
#17 lore raw

Re: [dpdk-dev] [PATCH v6 3/3] vhost: add thread unsafe async registeration functions

Quoted 12 lines · Jiayu Hu

This patch adds thread unsafe version for async register and unregister functions.

---
 doc/guides/prog_guide/vhost_lib.rst |  16 ++++
 lib/vhost/rte_vhost_async.h         |  41 ++++++++++
 lib/vhost/version.map               |   4 +
 lib/vhost/vhost.c                   | 149 +++++++++++++++++++++++++++---------
 4 files changed, 175 insertions(+), 35 deletions(-)

Thanks,
Maxime

#18 lore raw
In reply to Jiayu Hu
Quoted 48 lines

-----Original Message-----
From: Hu, Jiayu <[email protected]>
Sent: Monday, July 19, 2021 11:01 PM
To: [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Hu, Jiayu <[email protected]>
Subject: [PATCH v6 0/3] provide thread unsafe async registration functions

Lock protection is needed during the vhost notifies the application of device readiness, so the first patch adds lock protection. In addition, the second patch reworks async feature structure to improve readability. After performing locking, existed async vhost registration functions will cause deadlock, as they acquire lock too. The last patch provides thread unsafe registration functions to support calling within vhost callback functions.

v6:
* remove RTE_VHOST_ASYNC_FEATURE_UNKNOWN
* add blank lines in doc
v5:
* improve coding style
* update commit log, doc and comments
* remove useless field async_inorder
* change async_threshold from uint16_t to uint32_t v4:
* remove brace {} in single statement block v3:
* rename and use enum to define async device features
* change padding fields to 8 bytes
v2:
* rework async feature structure
* fix typo in commit log

Jiayu Hu (3):
vhost: fix lock on device readiness notification
vhost: rework async configuration structure
vhost: add thread unsafe async registeration functions

 doc/guides/prog_guide/vhost_lib.rst |  37 ++++++--
 examples/vhost/main.c               |   8 +-
 lib/vhost/rte_vhost_async.h         |  85 ++++++++++++++-----
 lib/vhost/version.map               |   4 +
 lib/vhost/vhost.c                   | 162 ++++++++++++++++++++++++++---------
-
 lib/vhost/vhost.h                   |   3 +-
 lib/vhost/vhost_user.c              |   5 +-
 7 files changed, 220 insertions(+), 84 deletions(-)
Quoted 2 lines

--
2.7.4

Series applied to next-virtio/main. Thanks

author
#19 lore raw

PATCH v5 2/3 vhost: rework async configuration structure

In reply to Jiayu Hu

This patch reworks the async configuration structure to improve code readability. In addition, add preserved padding fields on the structure for future usage.

---
 doc/guides/prog_guide/vhost_lib.rst | 21 +++++++++--------
 examples/vhost/main.c               |  8 +++----
 lib/vhost/rte_vhost_async.h         | 45 ++++++++++++++++++-------------------
 lib/vhost/vhost.c                   | 19 +++++++---------
 lib/vhost/vhost.h                   |  3 +--
 5 files changed, 47 insertions(+), 49 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +12 -9
index d18fb98..2a61b85 100644
@@ -218,26 +218,29 @@ The following is an overview of some key Vhost API functions:
 
   Enable or disable zero copy feature of the vhost crypto backend.
 
-* ``rte_vhost_async_channel_register(vid, queue_id, features, ops)``
+* ``rte_vhost_async_channel_register(vid, queue_id, config, ops)``
 
-  Register a vhost queue with async copy device channel after vring
-  is enabled. Following device ``features`` must be specified together
+  Register an async copy device channel for a vhost queue after vring
+  is enabled. Following device ``config`` must be specified together
   with the registration:
 
-  * ``async_inorder``
+  * ``features``
 
-    Async copy device can guarantee the ordering of copy completion
-    sequence. Copies are completed in the same order with that at
-    the submission time.
+    This field is used to specify async copy device features.
 
-    Currently, only ``async_inorder`` capable device is supported by vhost.
+    ``RTE_VHOST_ASYNC_INORDER`` represents the async copy device can
+    guarantee the order of copy completion is the same as the order
+    of copy submission.
+
+    Currently, only ``RTE_VHOST_ASYNC_INORDER`` capable device is
+    supported by vhost.
 
   * ``async_threshold``
 
     The copy length (in bytes) below which CPU copy will be used even if
     applications call async vhost APIs to enqueue/dequeue data.
 
-    Typical value is 512~1024 depending on the async device capability.
+    Typical value is 256~1024 depending on the async device capability.
 
   Applications must provide following ``ops`` callbacks for vhost lib to
   work with the async copy devices:
examples/vhost/main.c +4 -4
index d2179ea..9cd855a 100644
@@ -1468,7 +1468,7 @@ new_device(int vid)
 		vid, vdev->coreid);
 
 	if (async_vhost_driver) {
-		struct rte_vhost_async_features f;
+		struct rte_vhost_async_config config = {0};
 		struct rte_vhost_async_channel_ops channel_ops;
 
 		if (dma_type != NULL && strncmp(dma_type, "ioat", 4) == 0) {
@@ -1476,11 +1476,11 @@ new_device(int vid)
 			channel_ops.check_completed_copies =
 				ioat_check_completed_copies_cb;
 
-			f.async_inorder = 1;
-			f.async_threshold = 256;
+			config.features = RTE_VHOST_ASYNC_INORDER;
+			config.async_threshold = 256;
 
 			return rte_vhost_async_channel_register(vid, VIRTIO_RXQ,
-				f.intval, &channel_ops);
+				config, &channel_ops);
 		}
 	}
 
lib/vhost/rte_vhost_async.h +22 -23

71 lines not on this page · raw message

lib/vhost/vhost.c +8 -11
index 53a470f..908758e 100644
@@ -1619,19 +1619,17 @@ int rte_vhost_extern_callback_register(int vid,
 	return 0;
 }
 
-int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
-					uint32_t features,
-					struct rte_vhost_async_channel_ops *ops)
+int
+rte_vhost_async_channel_register(int vid, uint16_t queue_id,
+		struct rte_vhost_async_config config,
+		struct rte_vhost_async_channel_ops *ops)
 {
 	struct vhost_virtqueue *vq;
 	struct virtio_net *dev = get_device(vid);
-	struct rte_vhost_async_features f;
 
 	if (dev == NULL || ops == NULL)
 		return -1;
 
-	f.intval = features;
-
 	if (queue_id >= VHOST_MAX_VRING)
 		return -1;
 
@@ -1640,7 +1638,7 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
 	if (unlikely(vq == NULL || !dev->async_copy))
 		return -1;
 
-	if (unlikely(!f.async_inorder)) {
+	if (unlikely(!(config.features & RTE_VHOST_ASYNC_INORDER))) {
 		VHOST_LOG_CONFIG(ERR,
 			"async copy is not supported on non-inorder mode "
 			"(vid %d, qid: %d)\n", vid, queue_id);
@@ -1719,9 +1717,7 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
 
 	vq->async_ops.check_completed_copies = ops->check_completed_copies;
 	vq->async_ops.transfer_data = ops->transfer_data;
-
-	vq->async_inorder = f.async_inorder;
-	vq->async_threshold = f.async_threshold;
+	vq->async_threshold = config.async_threshold;
 
 	vq->async_registered = true;
 
@@ -1731,7 +1727,8 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
 	return 0;
 }
 
-int rte_vhost_async_channel_unregister(int vid, uint16_t queue_id)
+int
+rte_vhost_async_channel_unregister(int vid, uint16_t queue_id)
 {
 	struct vhost_virtqueue *vq;
 	struct virtio_net *dev = get_device(vid);
lib/vhost/vhost.h +1 -2
index 8ffe387..d98ca8a 100644
@@ -218,9 +218,8 @@ struct vhost_virtqueue {
 	};
 
 	/* vq async features */
-	bool		async_inorder;
 	bool		async_registered;
-	uint16_t	async_threshold;
+	uint32_t	async_threshold;
 
 	int			notif_enable;
 #define VIRTIO_UNINITIALIZED_NOTIF	(-1)
Signature · 1 line
2.7.4
Reviewed-by on v5 2/3
#20 lore raw

Re: [dpdk-dev] [PATCH v5 2/3] vhost: rework async configuration structure

Quoted 22 lines

-----Original Message-----
From: Hu, Jiayu <[email protected]>
Sent: Saturday, July 17, 2021 3:51 AM
To: [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Hu, Jiayu <[email protected]>
Subject: [PATCH v5 2/3] vhost: rework async configuration structure

This patch reworks the async configuration structure to improve code readability. In addition, add preserved padding fields on the structure for future usage.

---
 doc/guides/prog_guide/vhost_lib.rst | 21 +++++++++--------
 examples/vhost/main.c               |  8 +++----
 lib/vhost/rte_vhost_async.h         | 45 ++++++++++++++++++------------------
-
 lib/vhost/vhost.c                   | 19 +++++++---------
 lib/vhost/vhost.h                   |  3 +--
 5 files changed, 47 insertions(+), 49 deletions(-)
Quoted 2 lines

--
2.7.4

#21 lore raw

Re: [dpdk-dev] [PATCH v5 2/3] vhost: rework async configuration structure

In reply to Jiayu Hu
Quoted 97 lines · Jiayu Hu

This patch reworks the async configuration structure to improve code readability. In addition, add preserved padding fields on the structure for future usage.

---
 doc/guides/prog_guide/vhost_lib.rst | 21 +++++++++--------
 examples/vhost/main.c               |  8 +++----
 lib/vhost/rte_vhost_async.h         | 45 ++++++++++++++++++-------------------
 lib/vhost/vhost.c                   | 19 +++++++---------
 lib/vhost/vhost.h                   |  3 +--
 5 files changed, 47 insertions(+), 49 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +12 -9
index d18fb98..2a61b85 100644
@@ -218,26 +218,29 @@ The following is an overview of some key Vhost API functions:
 
   Enable or disable zero copy feature of the vhost crypto backend.
 
-* ``rte_vhost_async_channel_register(vid, queue_id, features, ops)``
+* ``rte_vhost_async_channel_register(vid, queue_id, config, ops)``
 
-  Register a vhost queue with async copy device channel after vring
-  is enabled. Following device ``features`` must be specified together
+  Register an async copy device channel for a vhost queue after vring
+  is enabled. Following device ``config`` must be specified together
   with the registration:
 
-  * ``async_inorder``
+  * ``features``
 
-    Async copy device can guarantee the ordering of copy completion
-    sequence. Copies are completed in the same order with that at
-    the submission time.
+    This field is used to specify async copy device features.
 
-    Currently, only ``async_inorder`` capable device is supported by vhost.
+    ``RTE_VHOST_ASYNC_INORDER`` represents the async copy device can
+    guarantee the order of copy completion is the same as the order
+    of copy submission.
+
+    Currently, only ``RTE_VHOST_ASYNC_INORDER`` capable device is
+    supported by vhost.
 
   * ``async_threshold``
 
     The copy length (in bytes) below which CPU copy will be used even if
     applications call async vhost APIs to enqueue/dequeue data.
 
-    Typical value is 512~1024 depending on the async device capability.
+    Typical value is 256~1024 depending on the async device capability.
 
   Applications must provide following ``ops`` callbacks for vhost lib to
   work with the async copy devices:
examples/vhost/main.c +4 -4
index d2179ea..9cd855a 100644
@@ -1468,7 +1468,7 @@ new_device(int vid)
 		vid, vdev->coreid);
 
 	if (async_vhost_driver) {
-		struct rte_vhost_async_features f;
+		struct rte_vhost_async_config config = {0};
 		struct rte_vhost_async_channel_ops channel_ops;
 
 		if (dma_type != NULL && strncmp(dma_type, "ioat", 4) == 0) {
@@ -1476,11 +1476,11 @@ new_device(int vid)
 			channel_ops.check_completed_copies =
 				ioat_check_completed_copies_cb;
 
-			f.async_inorder = 1;
-			f.async_threshold = 256;
+			config.features = RTE_VHOST_ASYNC_INORDER;
+			config.async_threshold = 256;
 
 			return rte_vhost_async_channel_register(vid, VIRTIO_RXQ,
-				f.intval, &channel_ops);
+				config, &channel_ops);
 		}
 	}
 
lib/vhost/rte_vhost_async.h +1 -3
index 6faa31f..52b1727 100644
@@ -93,49 +93,48 @@ struct async_inflight_info {
 };
 
 /**
- *  dma channel feature bit definition
+ *  async channel features
  */
-struct rte_vhost_async_features {
-	union {

lib/vhost/rte_vhost_async.h struct async_inflight_info { · line 99

Quoted 10 lines
lib/vhost/rte_vhost_async.h +2 -8
-		uint32_t intval;
-		struct {
-			uint32_t async_inorder:1;
-			uint32_t resvd_0:15;
-			uint32_t async_threshold:12;
-			uint32_t resvd_1:4;
-		};
-	};
+enum {
+	RTE_VHOST_ASYNC_FEATURE_UNKNOWN = 0U,

Please remove this entry, it has no meaning.

Quoted 127 lines
lib/vhost/rte_vhost_async.h +19 -12
+	RTE_VHOST_ASYNC_INORDER = 1U << 0,
 };
 
 /**
- * register an async channel for vhost
+ *  async channel configuration
+ */
+struct rte_vhost_async_config {
+	uint32_t async_threshold;
+	uint32_t features;
+	uint32_t rsvd[2];
+};
+
+/**
+ * Register an async channel for a vhost queue
  *
  * @param vid
  *  vhost device id async channel to be attached to
  * @param queue_id
  *  vhost queue id async channel to be attached to
- * @param features
- *  DMA channel feature bit
- *    b0       : DMA supports inorder data transfer
- *    b1  - b15: reserved
- *    b16 - b27: Packet length threshold for DMA transfer
- *    b28 - b31: reserved
+ * @param config
+ *  Async channel configuration structure
  * @param ops
- *  DMA operation callbacks
+ *  Async channel operation callbacks
  * @return
  *  0 on success, -1 on failures
  */
 __rte_experimental
 int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
-	uint32_t features, struct rte_vhost_async_channel_ops *ops);
+	struct rte_vhost_async_config config,
+	struct rte_vhost_async_channel_ops *ops);
 
 /**
- * unregister a dma channel for vhost
+ * Unregister an async channel for a vhost queue
  *
  * @param vid
- *  vhost device id DMA channel to be detached
+ *  vhost device id async channel to be detached from
  * @param queue_id
- *  vhost queue id DMA channel to be detached
+ *  vhost queue id async channel to be detached from
  * @return
  *  0 on success, -1 on failures
  */
lib/vhost/vhost.c +8 -11
index 53a470f..908758e 100644
@@ -1619,19 +1619,17 @@ int rte_vhost_extern_callback_register(int vid,
 	return 0;
 }
 
-int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
-					uint32_t features,
-					struct rte_vhost_async_channel_ops *ops)
+int
+rte_vhost_async_channel_register(int vid, uint16_t queue_id,
+		struct rte_vhost_async_config config,
+		struct rte_vhost_async_channel_ops *ops)
 {
 	struct vhost_virtqueue *vq;
 	struct virtio_net *dev = get_device(vid);
-	struct rte_vhost_async_features f;
 
 	if (dev == NULL || ops == NULL)
 		return -1;
 
-	f.intval = features;
-
 	if (queue_id >= VHOST_MAX_VRING)
 		return -1;
 
@@ -1640,7 +1638,7 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
 	if (unlikely(vq == NULL || !dev->async_copy))
 		return -1;
 
-	if (unlikely(!f.async_inorder)) {
+	if (unlikely(!(config.features & RTE_VHOST_ASYNC_INORDER))) {
 		VHOST_LOG_CONFIG(ERR,
 			"async copy is not supported on non-inorder mode "
 			"(vid %d, qid: %d)\n", vid, queue_id);
@@ -1719,9 +1717,7 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
 
 	vq->async_ops.check_completed_copies = ops->check_completed_copies;
 	vq->async_ops.transfer_data = ops->transfer_data;
-
-	vq->async_inorder = f.async_inorder;
-	vq->async_threshold = f.async_threshold;
+	vq->async_threshold = config.async_threshold;
 
 	vq->async_registered = true;
 
@@ -1731,7 +1727,8 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
 	return 0;
 }
 
-int rte_vhost_async_channel_unregister(int vid, uint16_t queue_id)
+int
+rte_vhost_async_channel_unregister(int vid, uint16_t queue_id)
 {
 	struct vhost_virtqueue *vq;
 	struct virtio_net *dev = get_device(vid);
lib/vhost/vhost.h +1 -2
index 8ffe387..d98ca8a 100644
@@ -218,9 +218,8 @@ struct vhost_virtqueue {
 	};
 
 	/* vq async features */
-	bool		async_inorder;
 	bool		async_registered;
-	uint16_t	async_threshold;
+	uint32_t	async_threshold;
 
 	int			notif_enable;
 #define VIRTIO_UNINITIALIZED_NOTIF	(-1)
author
#22 lore raw

PATCH v5 3/3 vhost: add thread unsafe async registeration functions

In reply to Jiayu Hu

This patch adds thread unsafe version for async register and unregister functions.

---
 doc/guides/prog_guide/vhost_lib.rst |  14 ++++
 lib/vhost/rte_vhost_async.h         |  41 ++++++++++
 lib/vhost/version.map               |   4 +
 lib/vhost/vhost.c                   | 149 +++++++++++++++++++++++++++---------
 4 files changed, 173 insertions(+), 35 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +14 -0
index 2a61b85..c8638db 100644
@@ -256,6 +256,13 @@ The following is an overview of some key Vhost API functions:
     vhost invokes this function to get the copy data completed by async
     devices.
 
+* ``rte_vhost_async_channel_register_thread_unsafe(vid, queue_id, config, ops)``
+  Register an async copy device channel for a vhost queue without
+  performing any locking.
+
+  This function is only safe to call in vhost callback functions
+  (i.e., struct vhost_device_ops).
+
 * ``rte_vhost_async_channel_unregister(vid, queue_id)``
 
   Unregister the async copy device channel from a vhost queue.
@@ -268,6 +275,13 @@ The following is an overview of some key Vhost API functions:
   devices for all vhost queues in destroy_device(), when a
   virtio device is paused or shut down.
 
+* ``rte_vhost_async_channel_unregister_thread_unsafe(vid, queue_id)``
+  Unregister the async copy device channel for a vhost queue without
+  performing any locking.
+
+  This function is only safe to call in vhost callback functions
+  (i.e., struct vhost_device_ops).
+
 * ``rte_vhost_submit_enqueue_burst(vid, queue_id, pkts, count, comp_pkts, comp_count)``
 
   Submit an enqueue request to transmit ``count`` packets from host to guest
lib/vhost/rte_vhost_async.h +41 -0

47 lines not on this page · raw message

lib/vhost/version.map +4 -0
index 9103a23..2363db8 100644
@@ -79,4 +79,8 @@ EXPERIMENTAL {
 
 	# added in 21.05
 	rte_vhost_get_negotiated_protocol_features;
+
+	# added in 21.08
+	rte_vhost_async_channel_register_thread_unsafe;
+	rte_vhost_async_channel_unregister_thread_unsafe;
 };
lib/vhost/vhost.c +114 -35

207 lines not on this page · raw message

Signature · 1 line
2.7.4
Reviewed-by on v5 3/3
#23 lore raw

Re: [dpdk-dev] [PATCH v5 3/3] vhost: add thread unsafe async registeration functions

Hi Jiayu,

Quoted 46 lines

-----Original Message-----
From: Hu, Jiayu <[email protected]>
Sent: Saturday, July 17, 2021 3:51 AM
To: [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Hu, Jiayu <[email protected]>
Subject: [PATCH v5 3/3] vhost: add thread unsafe async registeration functions

This patch adds thread unsafe version for async register and unregister functions.

---
 doc/guides/prog_guide/vhost_lib.rst |  14 ++++
 lib/vhost/rte_vhost_async.h         |  41 ++++++++++
 lib/vhost/version.map               |   4 +
 lib/vhost/vhost.c                   | 149 +++++++++++++++++++++++++++--------
(quoted diff) +0 -1
-
 4 files changed, 173 insertions(+), 35 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +0 -0
index 2a61b85..c8638db 100644
@@ -256,6 +256,13 @@ The following is an overview of some key Vhost API

functions:
vhost invokes this function to get the copy data completed by async devices.

+* ``rte_vhost_async_channel_register_thread_unsafe(vid, queue_id, config, ops)``

doc/guides/prog_guide/vhost_lib.rst +6 -0
+  Register an async copy device channel for a vhost queue without
+  performing any locking.
+
+  This function is only safe to call in vhost callback functions
+  (i.e., struct vhost_device_ops).
+
 * ``rte_vhost_async_channel_unregister(vid, queue_id)``
 
   Unregister the async copy device channel from a vhost queue.
@@ -268,6 +275,13 @@ The following is an overview of some key Vhost API

functions:
devices for all vhost queues in destroy_device(), when a virtio device is paused or shut down.

Quoted 1 line

+* ``rte_vhost_async_channel_unregister_thread_unsafe(vid, queue_id)``

We should add a blank line between API name and its description. I will add them when applying.

With above fixed:

author
#24 lore raw

PATCH v4 2/3 vhost: rework async configuration struct

In reply to Jiayu Hu

This patch reworks the async configuration structure to improve code readability. In addition, add preserved padding fields on the structure for future usage.

---
 doc/guides/prog_guide/vhost_lib.rst | 19 +++++++++++--------
 examples/vhost/main.c               |  8 ++++----
 lib/vhost/rte_vhost_async.h         | 35 +++++++++++++++++------------------
 lib/vhost/vhost.c                   | 13 +++++--------
 4 files changed, 37 insertions(+), 38 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +11 -8
index d18fb98..affdc57 100644
@@ -218,26 +218,29 @@ The following is an overview of some key Vhost API functions:
 
   Enable or disable zero copy feature of the vhost crypto backend.
 
-* ``rte_vhost_async_channel_register(vid, queue_id, features, ops)``
+* ``rte_vhost_async_channel_register(vid, queue_id, config, ops)``
 
   Register a vhost queue with async copy device channel after vring
-  is enabled. Following device ``features`` must be specified together
+  is enabled. Following device ``config`` must be specified together
   with the registration:
 
-  * ``async_inorder``
+  * ``features``
 
-    Async copy device can guarantee the ordering of copy completion
-    sequence. Copies are completed in the same order with that at
-    the submission time.
+    This field is used to specify async copy device features.
 
-    Currently, only ``async_inorder`` capable device is supported by vhost.
+    ``RTE_VHOST_ASYNC_INORDER`` represents the async copy device can
+    guarantee the order of copy completion is the same as the order
+    of copy submission.
+
+    Currently, only ``RTE_VHOST_ASYNC_INORDER`` capable device is
+    supported by vhost.
 
   * ``async_threshold``
 
     The copy length (in bytes) below which CPU copy will be used even if
     applications call async vhost APIs to enqueue/dequeue data.
 
-    Typical value is 512~1024 depending on the async device capability.
+    Typical value is 256~1024 depending on the async device capability.
 
   Applications must provide following ``ops`` callbacks for vhost lib to
   work with the async copy devices:
examples/vhost/main.c +4 -4
index d2179ea..9cd855a 100644
@@ -1468,7 +1468,7 @@ new_device(int vid)
 		vid, vdev->coreid);
 
 	if (async_vhost_driver) {
-		struct rte_vhost_async_features f;
+		struct rte_vhost_async_config config = {0};
 		struct rte_vhost_async_channel_ops channel_ops;
 
 		if (dma_type != NULL && strncmp(dma_type, "ioat", 4) == 0) {
@@ -1476,11 +1476,11 @@ new_device(int vid)
 			channel_ops.check_completed_copies =
 				ioat_check_completed_copies_cb;
 
-			f.async_inorder = 1;
-			f.async_threshold = 256;
+			config.features = RTE_VHOST_ASYNC_INORDER;
+			config.async_threshold = 256;
 
 			return rte_vhost_async_channel_register(vid, VIRTIO_RXQ,
-				f.intval, &channel_ops);
+				config, &channel_ops);
 		}
 	}
 
lib/vhost/rte_vhost_async.h +17 -18
index 6faa31f..c93490d 100644
@@ -93,18 +93,20 @@ struct async_inflight_info {
 };
 
 /**
- *  dma channel feature bit definition
+ *  dma channel features
  */
-struct rte_vhost_async_features {
-	union {
-		uint32_t intval;
-		struct {
-			uint32_t async_inorder:1;
-			uint32_t resvd_0:15;
-			uint32_t async_threshold:12;
-			uint32_t resvd_1:4;
-		};
-	};
+enum {
+	RTE_VHOST_ASYNC_FEATURE_UNKNOWN = 0U,
+	RTE_VHOST_ASYNC_INORDER = 1U << 0,
+};
+
+/**
+ *  dma channel configuration
+ */
+struct rte_vhost_async_config {
+	uint32_t async_threshold;
+	uint32_t features;
+	uint32_t resvd[2];
 };
 
 /**
@@ -114,12 +116,8 @@ struct rte_vhost_async_features {
  *  vhost device id async channel to be attached to
  * @param queue_id
  *  vhost queue id async channel to be attached to
- * @param features
- *  DMA channel feature bit
- *    b0       : DMA supports inorder data transfer
- *    b1  - b15: reserved
- *    b16 - b27: Packet length threshold for DMA transfer
- *    b28 - b31: reserved
+ * @param config
+ *  DMA channel configuration structure
  * @param ops
  *  DMA operation callbacks
  * @return
@@ -127,7 +125,8 @@ struct rte_vhost_async_features {
  */
 __rte_experimental
 int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
-	uint32_t features, struct rte_vhost_async_channel_ops *ops);
+	struct rte_vhost_async_config config,
+	struct rte_vhost_async_channel_ops *ops);
 
 /**
  * unregister a dma channel for vhost
lib/vhost/vhost.c +5 -8
index 53a470f..a20f05a 100644
@@ -1620,18 +1620,15 @@ int rte_vhost_extern_callback_register(int vid,
 }
 
 int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
-					uint32_t features,
-					struct rte_vhost_async_channel_ops *ops)
+		struct rte_vhost_async_config config,
+		struct rte_vhost_async_channel_ops *ops)
 {
 	struct vhost_virtqueue *vq;
 	struct virtio_net *dev = get_device(vid);
-	struct rte_vhost_async_features f;
 
 	if (dev == NULL || ops == NULL)
 		return -1;
 
-	f.intval = features;
-
 	if (queue_id >= VHOST_MAX_VRING)
 		return -1;
 
@@ -1640,7 +1637,7 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
 	if (unlikely(vq == NULL || !dev->async_copy))
 		return -1;
 
-	if (unlikely(!f.async_inorder)) {
+	if (unlikely(!(config.features & RTE_VHOST_ASYNC_INORDER))) {
 		VHOST_LOG_CONFIG(ERR,
 			"async copy is not supported on non-inorder mode "
 			"(vid %d, qid: %d)\n", vid, queue_id);
@@ -1720,8 +1717,8 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
 	vq->async_ops.check_completed_copies = ops->check_completed_copies;
 	vq->async_ops.transfer_data = ops->transfer_data;
 
-	vq->async_inorder = f.async_inorder;
-	vq->async_threshold = f.async_threshold;
+	vq->async_inorder = true;
+	vq->async_threshold = config.async_threshold;
 
 	vq->async_registered = true;
 
Signature · 1 line
2.7.4
#25 lore raw

Re: [dpdk-dev] [PATCH v4 2/3] vhost: rework async configuration struct

Hi Jiayu,

Quoted 7 lines

-----Original Message-----
From: Hu, Jiayu <[email protected]>
Sent: Tuesday, July 13, 2021 3:46 PM
To: [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Hu, Jiayu <[email protected]>
Subject: [PATCH v4 2/3] vhost: rework async configuration struct

Struct -> structure

Quoted 23 lines

This patch reworks the async configuration structure to improve code readability. In addition, add preserved padding fields on the structure for future usage.

---
 doc/guides/prog_guide/vhost_lib.rst | 19 +++++++++++--------
 examples/vhost/main.c               |  8 ++++----
 lib/vhost/rte_vhost_async.h         | 35 +++++++++++++++++------------------
 lib/vhost/vhost.c                   | 13 +++++--------
 4 files changed, 37 insertions(+), 38 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +0 -0
index d18fb98..affdc57 100644
@@ -218,26 +218,29 @@ The following is an overview of some key Vhost API

functions:

Enable or disable zero copy feature of the vhost crypto backend.

doc/guides/prog_guide/vhost_lib.rst The following is an overview of some key Vhost API functions: · line 223

Quoted 4 lines
doc/guides/prog_guide/vhost_lib.rst +1 -1
-* ``rte_vhost_async_channel_register(vid, queue_id, features, ops)``
+* ``rte_vhost_async_channel_register(vid, queue_id, config, ops)``
 
   Register a vhost queue with async copy device channel after vring

Not related to this patch. But maybe 'Register an async copy device channel for a vhost queue' is better?

Quoted 44 lines
doc/guides/prog_guide/vhost_lib.rst +10 -7
-  is enabled. Following device ``features`` must be specified together
+  is enabled. Following device ``config`` must be specified together
   with the registration:
 
-  * ``async_inorder``
+  * ``features``
 
-    Async copy device can guarantee the ordering of copy completion
-    sequence. Copies are completed in the same order with that at
-    the submission time.
+    This field is used to specify async copy device features.
 
-    Currently, only ``async_inorder`` capable device is supported by vhost.
+    ``RTE_VHOST_ASYNC_INORDER`` represents the async copy device can
+    guarantee the order of copy completion is the same as the order
+    of copy submission.
+
+    Currently, only ``RTE_VHOST_ASYNC_INORDER`` capable device is
+    supported by vhost.
 
   * ``async_threshold``
 
     The copy length (in bytes) below which CPU copy will be used even if
     applications call async vhost APIs to enqueue/dequeue data.
 
-    Typical value is 512~1024 depending on the async device capability.
+    Typical value is 256~1024 depending on the async device capability.
 
   Applications must provide following ``ops`` callbacks for vhost lib to
   work with the async copy devices:
examples/vhost/main.c +1 -1
index d2179ea..9cd855a 100644
@@ -1468,7 +1468,7 @@ new_device(int vid)
 		vid, vdev->coreid);
 
 	if (async_vhost_driver) {
-		struct rte_vhost_async_features f;
+		struct rte_vhost_async_config config = {0};
 		struct rte_vhost_async_channel_ops channel_ops;
 
 		if (dma_type != NULL && strncmp(dma_type, "ioat", 4) == 0) {

examples/vhost/main.c new_device(int vid) · line 1480

Quoted 7 lines
examples/vhost/main.c +2 -2
@@ -1476,11 +1476,11 @@ new_device(int vid)
 			channel_ops.check_completed_copies =
 				ioat_check_completed_copies_cb;
 
-			f.async_inorder = 1;
-			f.async_threshold = 256;
+			config.features = RTE_VHOST_ASYNC_INORDER;
+			config.async_threshold = 256;

This is ok as for now we are using ioat API. But I guess there should be a more user-friendly way to know the value. I mean, no users want to do complicated tests for his platform to know the value. Maybe there could be some auto-test in specific driver to show the value to user?

It's off-topic for this patch. But thinking about it should be good.

Quoted 12 lines
examples/vhost/main.c +1 -1
 			return rte_vhost_async_channel_register(vid, VIRTIO_RXQ,
-				f.intval, &channel_ops);
+				config, &channel_ops);
 		}
 	}
 
lib/vhost/rte_vhost_async.h +0 -0
index 6faa31f..c93490d 100644

lib/vhost/rte_vhost_async.h struct async_inflight_info { · line 96

Quoted 5 lines
lib/vhost/rte_vhost_async.h +1 -1
@@ -93,18 +93,20 @@ struct async_inflight_info {
 };
 
 /**
- *  dma channel feature bit definition
+ *  dma channel features

Let's use 'async channel' which is also the name for API. It's always good to use one term for one thing.

Quoted 8 lines
lib/vhost/rte_vhost_async.h +0 -7
  */
-struct rte_vhost_async_features {
-	union {
-		uint32_t intval;
-		struct {
-			uint32_t async_inorder:1;
-			uint32_t resvd_0:15;
-			uint32_t async_threshold:12;

lib/vhost/rte_vhost_async.h struct async_inflight_info { · line 104

Quoted 10 lines
lib/vhost/rte_vhost_async.h +7 -3
-			uint32_t resvd_1:4;
-		};
-	};
+enum {
+	RTE_VHOST_ASYNC_FEATURE_UNKNOWN = 0U,
+	RTE_VHOST_ASYNC_INORDER = 1U << 0,
+};
+
+/**
+ *  dma channel configuration

Ditto

lib/vhost/rte_vhost_async.h struct async_inflight_info { · line 109

Quoted 5 lines
lib/vhost/rte_vhost_async.h +5 -0
+ */
+struct rte_vhost_async_config {
+	uint32_t async_threshold;
+	uint32_t features;
+	uint32_t resvd[2];

Generally we use 'rsvd' for the word 'reserved'.

Quoted 5 lines
lib/vhost/rte_vhost_async.h +0 -0
 };
 
 /**
@@ -114,12 +116,8 @@ struct rte_vhost_async_features {
  *  vhost device id async channel to be attached to

lib/vhost/rte_vhost_async.h struct rte_vhost_async_features { · line 120

Quoted 10 lines
lib/vhost/rte_vhost_async.h +2 -6
  * @param queue_id
  *  vhost queue id async channel to be attached to
- * @param features
- *  DMA channel feature bit
- *    b0       : DMA supports inorder data transfer
- *    b1  - b15: reserved
- *    b16 - b27: Packet length threshold for DMA transfer
- *    b28 - b31: reserved
+ * @param config
+ *  DMA channel configuration structure

DMA -> async

Quoted 49 lines
lib/vhost/rte_vhost_async.h +2 -1
  * @param ops
  *  DMA operation callbacks
  * @return
@@ -127,7 +125,8 @@ struct rte_vhost_async_features {
  */
 __rte_experimental
 int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
-	uint32_t features, struct rte_vhost_async_channel_ops *ops);
+	struct rte_vhost_async_config config,
+	struct rte_vhost_async_channel_ops *ops);
 
 /**
  * unregister a dma channel for vhost
lib/vhost/vhost.c +3 -6
index 53a470f..a20f05a 100644
@@ -1620,18 +1620,15 @@ int rte_vhost_extern_callback_register(int vid,
 }
 
 int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
-					uint32_t features,
-					struct rte_vhost_async_channel_ops *ops)
+		struct rte_vhost_async_config config,
+		struct rte_vhost_async_channel_ops *ops)
 {
 	struct vhost_virtqueue *vq;
 	struct virtio_net *dev = get_device(vid);
-	struct rte_vhost_async_features f;
 
 	if (dev == NULL || ops == NULL)
 		return -1;
 
-	f.intval = features;
-
 	if (queue_id >= VHOST_MAX_VRING)
 		return -1;
 
@@ -1640,7 +1637,7 @@ int rte_vhost_async_channel_register(int vid, uint16_t
 queue_id,
 	if (unlikely(vq == NULL || !dev->async_copy))
 		return -1;
 
-	if (unlikely(!f.async_inorder)) {
+	if (unlikely(!(config.features & RTE_VHOST_ASYNC_INORDER))) {
 		VHOST_LOG_CONFIG(ERR,
 			"async copy is not supported on non-inorder mode "
lib/vhost/vhost.c +0 -0
 			"(vid %d, qid: %d)\n", vid, queue_id);

lib/vhost/vhost.c int rte_vhost_async_channel_register(int vid, uint16_t · line 1721

Quoted 7 lines
lib/vhost/vhost.c +1 -2
@@ -1720,8 +1717,8 @@ int rte_vhost_async_channel_register(int vid, uint16_t
 queue_id,
 	vq->async_ops.check_completed_copies = ops->check_completed_copies;
 	vq->async_ops.transfer_data = ops->transfer_data;
 
-	vq->async_inorder = f.async_inorder;
-	vq->async_threshold = f.async_threshold;
+	vq->async_inorder = true;

Do we still need this? It's never used.

lib/vhost/vhost.c int rte_vhost_async_channel_register(int vid, uint16_t queue_id, · line 1721

Quoted 1 line
lib/vhost/vhost.c +1 -0
+	vq->async_threshold = config.async_threshold;

vq->async_threshold is uint16_t and config.async_threshold is uint32_t. They should be the same.

Thanks,
Chenbo

Quoted 5 lines
lib/vhost/vhost.c +0 -1
 	vq->async_registered = true;
 
--

2.7.4

author
#26 lore raw

Re: [dpdk-dev] [PATCH v4 2/3] vhost: rework async configuration struct

Thanks Chenbo for your comments.

Replies are inline.

Quoted 100 lines

-----Original Message-----
From: Xia, Chenbo <[email protected]>
Sent: Friday, July 16, 2021 2:03 PM
To: Hu, Jiayu <[email protected]>; [email protected]
Cc: [email protected]
Subject: RE: [PATCH v4 2/3] vhost: rework async configuration struct

Hi Jiayu,

Quoted 7 lines

-----Original Message-----
From: Hu, Jiayu <[email protected]>
Sent: Tuesday, July 13, 2021 3:46 PM
To: [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Hu, Jiayu <[email protected]>
Subject: [PATCH v4 2/3] vhost: rework async configuration struct

Struct -> structure

Quoted 24 lines

This patch reworks the async configuration structure to improve code readability. In addition, add preserved padding fields on the structure for future usage.

---
 doc/guides/prog_guide/vhost_lib.rst | 19 +++++++++++--------
 examples/vhost/main.c               |  8 ++++----
 lib/vhost/rte_vhost_async.h         | 35 +++++++++++++++++------------------
 lib/vhost/vhost.c                   | 13 +++++--------
 4 files changed, 37 insertions(+), 38 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +0 -0
index d18fb98..affdc57 100644
@@ -218,26 +218,29 @@ The following is an overview of some key Vhost

API
functions:

Enable or disable zero copy feature of the vhost crypto backend.

doc/guides/prog_guide/vhost_lib.rst The following is an overview of some key Vhost API functions: · line 223

Quoted 4 lines
doc/guides/prog_guide/vhost_lib.rst +1 -1
-* ``rte_vhost_async_channel_register(vid, queue_id, features, ops)``
+* ``rte_vhost_async_channel_register(vid, queue_id, config, ops)``
 
   Register a vhost queue with async copy device channel after vring

Not related to this patch. But maybe 'Register an async copy device channel for a vhost queue' is better?

Quoted 36 lines

- is enabled. Following device ``features`` must be specified together

doc/guides/prog_guide/vhost_lib.rst +10 -6
+  is enabled. Following device ``config`` must be specified together
   with the registration:
 
-  * ``async_inorder``
+  * ``features``
 
-    Async copy device can guarantee the ordering of copy completion
-    sequence. Copies are completed in the same order with that at
-    the submission time.
+    This field is used to specify async copy device features.
 
-    Currently, only ``async_inorder`` capable device is supported by vhost.
+    ``RTE_VHOST_ASYNC_INORDER`` represents the async copy device can
+    guarantee the order of copy completion is the same as the order
+    of copy submission.
+
+    Currently, only ``RTE_VHOST_ASYNC_INORDER`` capable device is
+    supported by vhost.
 
   * ``async_threshold``
 
     The copy length (in bytes) below which CPU copy will be used even if
     applications call async vhost APIs to enqueue/dequeue data.
 
-    Typical value is 512~1024 depending on the async device capability.
+    Typical value is 256~1024 depending on the async device capability.
 
   Applications must provide following ``ops`` callbacks for vhost lib to
   work with the async copy devices:
examples/vhost/main.c index renamed from examples/vhost/main.c +0 -0

d2179ea..9cd855a 100644

examples/vhost/main.c new_device(int vid) · line 1474

Quoted 8 lines
examples/vhost/main.c +1 -1
@@ -1468,7 +1468,7 @@ new_device(int vid)
 		vid, vdev->coreid);
 
 	if (async_vhost_driver) {
-		struct rte_vhost_async_features f;
+		struct rte_vhost_async_config config = {0};
 		struct rte_vhost_async_channel_ops channel_ops;
 
 		if (dma_type != NULL && strncmp(dma_type, "ioat", 4) == 0)

{ @@

Quoted 4 lines

-1476,11 +1476,11 @@ new_device(int vid)

examples/vhost/main.c +0 -0
 			channel_ops.check_completed_copies =
 				ioat_check_completed_copies_cb;
Quoted 9 lines

examples/vhost/main.c new_device(int vid) · line 1480

Quoted 4 lines
examples/vhost/main.c +2 -2
-			f.async_inorder = 1;
-			f.async_threshold = 256;
+			config.features = RTE_VHOST_ASYNC_INORDER;
+			config.async_threshold = 256;

This is ok as for now we are using ioat API. But I guess there should be a more user-friendly way to know the value. I mean, no users want to do complicated tests for his platform to know the value. Maybe there could be some auto-test in specific driver to show the value to user?

It's hard in a way, as it's not only related to platform, but also application logics. So I think better to keep it as an input from users, before we have a good idea 😊

Quoted 17 lines

It's off-topic for this patch. But thinking about it should be good.

Quoted 2 lines

return rte_vhost_async_channel_register(vid,

VIRTIO_RXQ,

Quoted 11 lines
examples/vhost/main.c +1 -1
-				f.intval, &channel_ops);
+				config, &channel_ops);
 		}
 	}
lib/vhost/rte_vhost_async.h +0 -0
index 6faa31f..c93490d 100644
@@ -93,18 +93,20 @@ struct async_inflight_info {  };
 
Quoted 6 lines

lib/vhost/rte_vhost_async.h struct async_inflight_info { · line 96

Quoted 3 lines
lib/vhost/rte_vhost_async.h +1 -1
 /**
- *  dma channel feature bit definition
+ *  dma channel features

Let's use 'async channel' which is also the name for API. It's always good to use one term for one thing.

Sure, I will fix that.

Quoted 102 lines
Quoted 9 lines
lib/vhost/rte_vhost_async.h +0 -7
  */
-struct rte_vhost_async_features {
-	union {
-		uint32_t intval;
-		struct {
-			uint32_t async_inorder:1;
-			uint32_t resvd_0:15;
-			uint32_t async_threshold:12;

lib/vhost/rte_vhost_async.h struct async_inflight_info { · line 104

Quoted 10 lines
lib/vhost/rte_vhost_async.h +7 -3
-			uint32_t resvd_1:4;
-		};
-	};
+enum {
+	RTE_VHOST_ASYNC_FEATURE_UNKNOWN = 0U,
+	RTE_VHOST_ASYNC_INORDER = 1U << 0,
+};
+
+/**
+ *  dma channel configuration

Ditto

lib/vhost/rte_vhost_async.h struct async_inflight_info { · line 109

Quoted 5 lines
lib/vhost/rte_vhost_async.h +5 -0
+ */
+struct rte_vhost_async_config {
+	uint32_t async_threshold;
+	uint32_t features;
+	uint32_t resvd[2];

Generally we use 'rsvd' for the word 'reserved'.

Quoted 5 lines
lib/vhost/rte_vhost_async.h +0 -0
 };
 
 /**
@@ -114,12 +116,8 @@ struct rte_vhost_async_features {
  *  vhost device id async channel to be attached to

lib/vhost/rte_vhost_async.h struct rte_vhost_async_features { · line 120

Quoted 10 lines
lib/vhost/rte_vhost_async.h +2 -6
  * @param queue_id
  *  vhost queue id async channel to be attached to
- * @param features
- *  DMA channel feature bit
- *    b0       : DMA supports inorder data transfer
- *    b1  - b15: reserved
- *    b16 - b27: Packet length threshold for DMA transfer
- *    b28 - b31: reserved
+ * @param config
+ *  DMA channel configuration structure

DMA -> async

Quoted 17 lines
lib/vhost/rte_vhost_async.h +2 -1
  * @param ops
  *  DMA operation callbacks
  * @return
@@ -127,7 +125,8 @@ struct rte_vhost_async_features {
  */
 __rte_experimental
 int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
-	uint32_t features, struct rte_vhost_async_channel_ops *ops);
+	struct rte_vhost_async_config config,
+	struct rte_vhost_async_channel_ops *ops);
 
 /**
  * unregister a dma channel for vhost diff --git a/lib/vhost/vhost.c

b/lib/vhost/vhost.c index 53a470f..a20f05a 100644

lib/vhost/vhost.c int rte_vhost_extern_callback_register(int · line 1624

Quoted 5 lines
lib/vhost/vhost.c +0 -2
@@ -1620,18 +1620,15 @@ int rte_vhost_extern_callback_register(int
 vid,  }
 
 int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
-					uint32_t features,
-					struct rte_vhost_async_channel_ops

*ops)

Quoted 24 lines
lib/vhost/vhost.c +3 -4
+		struct rte_vhost_async_config config,
+		struct rte_vhost_async_channel_ops *ops)
 {
 	struct vhost_virtqueue *vq;
 	struct virtio_net *dev = get_device(vid);
-	struct rte_vhost_async_features f;
 
 	if (dev == NULL || ops == NULL)
 		return -1;
 
-	f.intval = features;
-
 	if (queue_id >= VHOST_MAX_VRING)
 		return -1;
 
@@ -1640,7 +1637,7 @@ int rte_vhost_async_channel_register(int vid,
 uint16_t queue_id,
 	if (unlikely(vq == NULL || !dev->async_copy))
 		return -1;
 
-	if (unlikely(!f.async_inorder)) {
+	if (unlikely(!(config.features & RTE_VHOST_ASYNC_INORDER))) {
 		VHOST_LOG_CONFIG(ERR,
 			"async copy is not supported on non-inorder mode "
Quoted 1 line

"(vid %d, qid: %d)\n", vid, queue_id); @@ -1720,8

+1717,8 @@ int

Quoted 5 lines

rte_vhost_async_channel_register(int vid, uint16_t queue_id,
vq->async_ops.check_completed_copies = ops-
check_completed_copies;
vq->async_ops.transfer_data = ops->transfer_data;

Quoted 5 lines

lib/vhost/vhost.c int rte_vhost_async_channel_register(int vid, uint16_t queue_id, · line 1720

Quoted 3 lines
lib/vhost/vhost.c +1 -2
-	vq->async_inorder = f.async_inorder;
-	vq->async_threshold = f.async_threshold;
+	vq->async_inorder = true;

Do we still need this? It's never used.

I think we need to keep it, as we may support out-of-order channel in future.

Quoted 5 lines

lib/vhost/vhost.c int rte_vhost_async_channel_register(int vid, uint16_t queue_id, · line 1721

Quoted 2 lines
lib/vhost/vhost.c +1 -0
+	vq->async_threshold = config.async_threshold;

vq->async_threshold is uint16_t and config.async_threshold is uint32_t. They should be the same.

I will change vq->async_threshold to uint32_t.

Thanks,
Jiayu

Quoted 10 lines

Thanks,
Chenbo

Quoted 5 lines

vq->async_registered = true;

--
2.7.4

#27 lore raw

Re: [dpdk-dev] [PATCH v4 2/3] vhost: rework async configuration struct

Hi Jiayu,

Quoted 44 lines

-----Original Message-----
From: Hu, Jiayu <[email protected]>
Sent: Friday, July 16, 2021 2:18 PM
To: Xia, Chenbo <[email protected]>; [email protected]
Cc: [email protected]
Subject: RE: [PATCH v4 2/3] vhost: rework async configuration struct

Thanks Chenbo for your comments.

Replies are inline.

Quoted 17 lines

-----Original Message-----
From: Xia, Chenbo <[email protected]>
Sent: Friday, July 16, 2021 2:03 PM
To: Hu, Jiayu <[email protected]>; [email protected]
Cc: [email protected]
Subject: RE: [PATCH v4 2/3] vhost: rework async configuration struct

Hi Jiayu,

Quoted 7 lines

-----Original Message-----
From: Hu, Jiayu <[email protected]>
Sent: Tuesday, July 13, 2021 3:46 PM
To: [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Hu, Jiayu <[email protected]>
Subject: [PATCH v4 2/3] vhost: rework async configuration struct

Quoted 12 lines

Struct -> structure

Quoted 10 lines

This patch reworks the async configuration structure to improve code readability. In addition, add preserved padding fields on the structure for future usage.

---
 doc/guides/prog_guide/vhost_lib.rst | 19 +++++++++++--------
 examples/vhost/main.c               |  8 ++++----
 lib/vhost/rte_vhost_async.h         | 35 +++++++++++++++++---------------

---

Quoted 3 lines
Quoted 3 lines
 lib/vhost/vhost.c                   | 13 +++++--------
 4 files changed, 37 insertions(+), 38 deletions(-)

[snip]

Quoted 7 lines
Quoted 5 lines

lib/vhost/vhost.c int rte_vhost_async_channel_register(int vid, uint16_t queue_id, · line 1720

Quoted 3 lines
lib/vhost/vhost.c +1 -2
-vq->async_inorder = f.async_inorder;
-vq->async_threshold = f.async_threshold;
+vq->async_inorder = true;

Do we still need this? It's never used.

I think we need to keep it, as we may support out-of-order channel in future.

We don't like to define things when it's not needed currently. If in future, the definition should also be made in future :P. Just leave the definition to future patch.

Thanks,
Chenbo

Quoted 22 lines
Quoted 6 lines
Quoted 3 lines

+vq->async_threshold = config.async_threshold;

vq->async_threshold is uint16_t and config.async_threshold is uint32_t. They should be the same.

I will change vq->async_threshold to uint32_t.

Thanks,
Jiayu

Quoted 10 lines

Thanks,
Chenbo

Quoted 5 lines

vq->async_registered = true;

--
2.7.4

author
#28 lore raw

Re: [dpdk-dev] [PATCH v4 2/3] vhost: rework async configuration struct

Quoted 16 lines

-----Original Message-----
From: Xia, Chenbo <[email protected]>
Sent: Friday, July 16, 2021 2:28 PM
To: Hu, Jiayu <[email protected]>; [email protected]
Cc: [email protected]
Subject: RE: [PATCH v4 2/3] vhost: rework async configuration struct

Quoted 6 lines
Quoted 5 lines

Review

Quoted 3 lines
(quoted diff) +1 -2
-vq->async_inorder = f.async_inorder; async_threshold =
-vq->f.async_threshold;
+vq->async_inorder = true;

Do we still need this? It's never used.

Quoted 6 lines
Quoted 1 line

I think we need to keep it, as we may support out-of-order channel in

future.

We don't like to define things when it's not needed currently. If in future, the definition should also be made in future :P. Just leave the definition to future patch.

Fair. I will delete vq->async_inorder field.

Thanks,
Jiayu

Quoted 27 lines

Thanks,
Chenbo

Quoted 22 lines
Quoted 6 lines
Quoted 3 lines

+vq->async_threshold = config.async_threshold;

vq->async_threshold is uint16_t and config.async_threshold is uint32_t. They should be the same.

I will change vq->async_threshold to uint32_t.

Thanks,
Jiayu

Quoted 10 lines

Thanks,
Chenbo

Quoted 5 lines

vq->async_registered = true;

--
2.7.4

author
#29 lore raw

PATCH v4 3/3 vhost: add thread unsafe async registeration functions

In reply to Jiayu Hu

This patch adds thread unsafe version for async register and unregister functions.

---
 doc/guides/prog_guide/vhost_lib.rst |  12 +++
 lib/vhost/rte_vhost_async.h         |  39 ++++++++++
 lib/vhost/version.map               |   4 +
 lib/vhost/vhost.c                   | 146 +++++++++++++++++++++++++++---------
 4 files changed, 167 insertions(+), 34 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +12 -0
index affdc57..ffe09a3 100644
@@ -256,6 +256,12 @@ The following is an overview of some key Vhost API functions:
     vhost invokes this function to get the copy data completed by async
     devices.
 
+* ``rte_vhost_async_channel_register_thread_unsafe(vid, queue_id, config, ops)``
+  Register a vhost queue with async copy device channel without
+  performing any locking.
+
+  This function is only safe to call from within vhost callback functions.
+
 * ``rte_vhost_async_channel_unregister(vid, queue_id)``
 
   Unregister the async copy device channel from a vhost queue.
@@ -268,6 +274,12 @@ The following is an overview of some key Vhost API functions:
   devices for all vhost queues in destroy_device(), when a
   virtio device is paused or shut down.
 
+* ``rte_vhost_async_channel_unregister_thread_unsafe(vid, queue_id)``
+  Unregister the async copy device channel from a vhost queue without
+  performing any locking.
+
+  This function is only safe to call from within vhost callback functions.
+
 * ``rte_vhost_submit_enqueue_burst(vid, queue_id, pkts, count, comp_pkts, comp_count)``
 
   Submit an enqueue request to transmit ``count`` packets from host to guest
lib/vhost/rte_vhost_async.h +39 -0
index c93490d..e4d20a3 100644
@@ -142,6 +142,45 @@ __rte_experimental
 int rte_vhost_async_channel_unregister(int vid, uint16_t queue_id);
 
 /**
+ * register an async channel for vhost without performing any locking
+ *
+ * @note This function does not perform any locking, and is only safe to call
+ *       from within vhost callback functions.
+ *
+ * @param vid
+ *  vhost device id async channel to be attached to
+ * @param queue_id
+ *  vhost queue id async channel to be attached to
+ * @param config
+ *  DMA channel configuration
+ * @param ops
+ *  DMA operation callbacks
+ * @return
+ *  0 on success, -1 on failures
+ */
+__rte_experimental
+int rte_vhost_async_channel_register_thread_unsafe(int vid, uint16_t queue_id,
+	struct rte_vhost_async_config config,
+	struct rte_vhost_async_channel_ops *ops);
+
+/**
+ * unregister a dma channel for vhost without performing any lock
+ *
+ * @note This function does not perform any locking, and is only safe to call
+ *       from within vhost callback functions.
+ *
+ * @param vid
+ *  vhost device id DMA channel to be detached
+ * @param queue_id
+ *  vhost queue id DMA channel to be detached
+ * @return
+ *  0 on success, -1 on failures
+ */
+__rte_experimental
+int rte_vhost_async_channel_unregister_thread_unsafe(int vid,
+		uint16_t queue_id);
+
+/**
  * This function submits enqueue data to async engine. Successfully
  * enqueued packets can be transfer completed or being occupied by DMA
  * engines, when this API returns. Transfer completed packets are returned
lib/vhost/version.map +4 -0
index 9103a23..2363db8 100644
@@ -79,4 +79,8 @@ EXPERIMENTAL {
 
 	# added in 21.05
 	rte_vhost_get_negotiated_protocol_features;
+
+	# added in 21.08
+	rte_vhost_async_channel_register_thread_unsafe;
+	rte_vhost_async_channel_unregister_thread_unsafe;
 };
lib/vhost/vhost.c +112 -34

204 lines not on this page · raw message

Signature · 1 line
2.7.4
#30 lore raw

Re: [dpdk-dev] [PATCH v4 3/3] vhost: add thread unsafe async registeration functions

Hi Jiayu,

Quoted 30 lines

-----Original Message-----
From: Hu, Jiayu <[email protected]>
Sent: Tuesday, July 13, 2021 3:46 PM
To: [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Hu, Jiayu <[email protected]>
Subject: [PATCH v4 3/3] vhost: add thread unsafe async registeration functions

This patch adds thread unsafe version for async register and unregister functions.

---
 doc/guides/prog_guide/vhost_lib.rst |  12 +++
 lib/vhost/rte_vhost_async.h         |  39 ++++++++++
 lib/vhost/version.map               |   4 +
 lib/vhost/vhost.c                   | 146 +++++++++++++++++++++++++++--------
(quoted diff) +0 -1
-
 4 files changed, 167 insertions(+), 34 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +0 -0
index affdc57..ffe09a3 100644
@@ -256,6 +256,12 @@ The following is an overview of some key Vhost API

functions:
vhost invokes this function to get the copy data completed by async devices.

Quoted 3 lines

+* ``rte_vhost_async_channel_register_thread_unsafe(vid, queue_id, config, ops)``
+ Register a vhost queue with async copy device channel without

'Register an async copy device channel for a vhost queue' sounds better

doc/guides/prog_guide/vhost_lib.rst The following is an overview of some key Vhost API functions: · line 263

Quoted 3 lines
doc/guides/prog_guide/vhost_lib.rst +3 -0
+  performing any locking.
+
+  This function is only safe to call from within vhost callback functions.

call in vhost callback functions?

doc/guides/prog_guide/vhost_lib.rst The following is an overview of some key Vhost API functions: · line 278

Quoted 11 lines
doc/guides/prog_guide/vhost_lib.rst +1 -0
+
 * ``rte_vhost_async_channel_unregister(vid, queue_id)``
 
   Unregister the async copy device channel from a vhost queue.
@@ -268,6 +274,12 @@ The following is an overview of some key Vhost API

functions:
devices for all vhost queues in destroy_device(), when a virtio device is paused or shut down.

doc/guides/prog_guide/vhost_lib.rst +2 -0
+* ``rte_vhost_async_channel_unregister_thread_unsafe(vid, queue_id)``
+  Unregister the async copy device channel from a vhost queue without

for a vhost queue?

doc/guides/prog_guide/vhost_lib.rst The following is an overview of some key Vhost API functions: · line 263

Quoted 3 lines
doc/guides/prog_guide/vhost_lib.rst +3 -0
+  performing any locking.
+
+  This function is only safe to call from within vhost callback functions.

Call in vhost callback functions?

And let's make it clearer. Add this: (i.e., struct vhost_device_ops)

Quoted 10 lines

+
* ``rte_vhost_submit_enqueue_burst(vid, queue_id, pkts, count, comp_pkts,
comp_count)``

Submit an enqueue request to transmit ``count`` packets from host to guest

lib/vhost/rte_vhost_async.h +0 -0
index c93490d..e4d20a3 100644

lib/vhost/rte_vhost_async.h __rte_experimental · line 145

Quoted 4 lines
lib/vhost/rte_vhost_async.h +1 -0
@@ -142,6 +142,45 @@ __rte_experimental
 int rte_vhost_async_channel_unregister(int vid, uint16_t queue_id);
 
 /**
+ * register an async channel for vhost without performing any locking

register -> Register

for vhost -> for a vhost queue

lib/vhost/rte_vhost_async.h __rte_experimental · line 148

Quoted 3 lines
lib/vhost/rte_vhost_async.h +3 -0
+ *
+ * @note This function does not perform any locking, and is only safe to call
+ *       from within vhost callback functions.

From within -> in ?

lib/vhost/rte_vhost_async.h __rte_experimental · line 155

Quoted 7 lines
lib/vhost/rte_vhost_async.h +7 -0
+ *
+ * @param vid
+ *  vhost device id async channel to be attached to
+ * @param queue_id
+ *  vhost queue id async channel to be attached to
+ * @param config
+ *  DMA channel configuration

DMA -> async?

lib/vhost/rte_vhost_async.h __rte_experimental · line 157

Quoted 2 lines
lib/vhost/rte_vhost_async.h +2 -0
+ * @param ops
+ *  DMA operation callbacks

Async channel operation callbacks?

lib/vhost/rte_vhost_async.h __rte_experimental · line 162

Quoted 5 lines
lib/vhost/rte_vhost_async.h +5 -0
+ * @return
+ *  0 on success, -1 on failures
+ */
+__rte_experimental
+int rte_vhost_async_channel_register_thread_unsafe(int vid, uint16_t queue_id,

According to DPDK coding style. Return value should not be in the same line of the function name. Just make a new line for it. Please check other functions like unregister.

lib/vhost/rte_vhost_async.h __rte_experimental · line 167

Quoted 5 lines
lib/vhost/rte_vhost_async.h +5 -0
+	struct rte_vhost_async_config config,
+	struct rte_vhost_async_channel_ops *ops);
+
+/**
+ * unregister a dma channel for vhost without performing any lock

Unregister an async channel for a vhost queue

lib/vhost/rte_vhost_async.h __rte_experimental · line 148

Quoted 3 lines
lib/vhost/rte_vhost_async.h +3 -0
+ *
+ * @note This function does not perform any locking, and is only safe to call
+ *       from within vhost callback functions.

in vhost callback functions

lib/vhost/rte_vhost_async.h __rte_experimental · line 173

Quoted 3 lines
lib/vhost/rte_vhost_async.h +3 -0
+ *
+ * @param vid
+ *  vhost device id DMA channel to be detached

Vhost device id Async channel to be detached from

lib/vhost/rte_vhost_async.h __rte_experimental · line 175

Quoted 2 lines
lib/vhost/rte_vhost_async.h +2 -0
+ * @param queue_id
+ *  vhost queue id DMA channel to be detached

Ditto

Quoted 5 lines
lib/vhost/rte_vhost_async.h +3 -1
+ * @return
+ *  0 on success, -1 on failures
+ */
--

2.7.4

author
#31 lore raw

PATCH v3 2/3 vhost: rework async configuration struct

In reply to Jiayu Hu

This patch reworks the async configuration structure to improve code readability. In addition, add preserved padding fields on the structure for future usage.

---
 doc/guides/prog_guide/vhost_lib.rst | 19 +++++++++++--------
 examples/vhost/main.c               |  8 ++++----
 lib/vhost/rte_vhost_async.h         | 35 +++++++++++++++++------------------
 lib/vhost/vhost.c                   | 13 +++++--------
 4 files changed, 37 insertions(+), 38 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +11 -8
index d18fb98..affdc57 100644
@@ -218,26 +218,29 @@ The following is an overview of some key Vhost API functions:
 
   Enable or disable zero copy feature of the vhost crypto backend.
 
-* ``rte_vhost_async_channel_register(vid, queue_id, features, ops)``
+* ``rte_vhost_async_channel_register(vid, queue_id, config, ops)``
 
   Register a vhost queue with async copy device channel after vring
-  is enabled. Following device ``features`` must be specified together
+  is enabled. Following device ``config`` must be specified together
   with the registration:
 
-  * ``async_inorder``
+  * ``features``
 
-    Async copy device can guarantee the ordering of copy completion
-    sequence. Copies are completed in the same order with that at
-    the submission time.
+    This field is used to specify async copy device features.
 
-    Currently, only ``async_inorder`` capable device is supported by vhost.
+    ``RTE_VHOST_ASYNC_INORDER`` represents the async copy device can
+    guarantee the order of copy completion is the same as the order
+    of copy submission.
+
+    Currently, only ``RTE_VHOST_ASYNC_INORDER`` capable device is
+    supported by vhost.
 
   * ``async_threshold``
 
     The copy length (in bytes) below which CPU copy will be used even if
     applications call async vhost APIs to enqueue/dequeue data.
 
-    Typical value is 512~1024 depending on the async device capability.
+    Typical value is 256~1024 depending on the async device capability.
 
   Applications must provide following ``ops`` callbacks for vhost lib to
   work with the async copy devices:
examples/vhost/main.c +4 -4
index d2179ea..9cd855a 100644
@@ -1468,7 +1468,7 @@ new_device(int vid)
 		vid, vdev->coreid);
 
 	if (async_vhost_driver) {
-		struct rte_vhost_async_features f;
+		struct rte_vhost_async_config config = {0};
 		struct rte_vhost_async_channel_ops channel_ops;
 
 		if (dma_type != NULL && strncmp(dma_type, "ioat", 4) == 0) {
@@ -1476,11 +1476,11 @@ new_device(int vid)
 			channel_ops.check_completed_copies =
 				ioat_check_completed_copies_cb;
 
-			f.async_inorder = 1;
-			f.async_threshold = 256;
+			config.features = RTE_VHOST_ASYNC_INORDER;
+			config.async_threshold = 256;
 
 			return rte_vhost_async_channel_register(vid, VIRTIO_RXQ,
-				f.intval, &channel_ops);
+				config, &channel_ops);
 		}
 	}
 
lib/vhost/rte_vhost_async.h +17 -18
index 6faa31f..c93490d 100644
@@ -93,18 +93,20 @@ struct async_inflight_info {
 };
 
 /**
- *  dma channel feature bit definition
+ *  dma channel features
  */
-struct rte_vhost_async_features {
-	union {
-		uint32_t intval;
-		struct {
-			uint32_t async_inorder:1;
-			uint32_t resvd_0:15;
-			uint32_t async_threshold:12;
-			uint32_t resvd_1:4;
-		};
-	};
+enum {
+	RTE_VHOST_ASYNC_FEATURE_UNKNOWN = 0U,
+	RTE_VHOST_ASYNC_INORDER = 1U << 0,
+};
+
+/**
+ *  dma channel configuration
+ */
+struct rte_vhost_async_config {
+	uint32_t async_threshold;
+	uint32_t features;
+	uint32_t resvd[2];
 };
 
 /**
@@ -114,12 +116,8 @@ struct rte_vhost_async_features {
  *  vhost device id async channel to be attached to
  * @param queue_id
  *  vhost queue id async channel to be attached to
- * @param features
- *  DMA channel feature bit
- *    b0       : DMA supports inorder data transfer
- *    b1  - b15: reserved
- *    b16 - b27: Packet length threshold for DMA transfer
- *    b28 - b31: reserved
+ * @param config
+ *  DMA channel configuration structure
  * @param ops
  *  DMA operation callbacks
  * @return
@@ -127,7 +125,8 @@ struct rte_vhost_async_features {
  */
 __rte_experimental
 int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
-	uint32_t features, struct rte_vhost_async_channel_ops *ops);
+	struct rte_vhost_async_config config,
+	struct rte_vhost_async_channel_ops *ops);
 
 /**
  * unregister a dma channel for vhost
lib/vhost/vhost.c +5 -8
index 53a470f..a20f05a 100644
@@ -1620,18 +1620,15 @@ int rte_vhost_extern_callback_register(int vid,
 }
 
 int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
-					uint32_t features,
-					struct rte_vhost_async_channel_ops *ops)
+		struct rte_vhost_async_config config,
+		struct rte_vhost_async_channel_ops *ops)
 {
 	struct vhost_virtqueue *vq;
 	struct virtio_net *dev = get_device(vid);
-	struct rte_vhost_async_features f;
 
 	if (dev == NULL || ops == NULL)
 		return -1;
 
-	f.intval = features;
-
 	if (queue_id >= VHOST_MAX_VRING)
 		return -1;
 
@@ -1640,7 +1637,7 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
 	if (unlikely(vq == NULL || !dev->async_copy))
 		return -1;
 
-	if (unlikely(!f.async_inorder)) {
+	if (unlikely(!(config.features & RTE_VHOST_ASYNC_INORDER))) {
 		VHOST_LOG_CONFIG(ERR,
 			"async copy is not supported on non-inorder mode "
 			"(vid %d, qid: %d)\n", vid, queue_id);
@@ -1720,8 +1717,8 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
 	vq->async_ops.check_completed_copies = ops->check_completed_copies;
 	vq->async_ops.transfer_data = ops->transfer_data;
 
-	vq->async_inorder = f.async_inorder;
-	vq->async_threshold = f.async_threshold;
+	vq->async_inorder = true;
+	vq->async_threshold = config.async_threshold;
 
 	vq->async_registered = true;
 
Signature · 1 line
2.7.4
author
#32 lore raw

PATCH v3 3/3 vhost: add thread unsafe async registeration functions

In reply to Jiayu Hu

This patch adds thread unsafe version for async register and unregister functions.

---
 doc/guides/prog_guide/vhost_lib.rst |  12 +++
 lib/vhost/rte_vhost_async.h         |  39 +++++++++
 lib/vhost/version.map               |   4 +
 lib/vhost/vhost.c                   | 154 ++++++++++++++++++++++++++++--------
 4 files changed, 175 insertions(+), 34 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +12 -0
index affdc57..ffe09a3 100644
@@ -256,6 +256,12 @@ The following is an overview of some key Vhost API functions:
     vhost invokes this function to get the copy data completed by async
     devices.
 
+* ``rte_vhost_async_channel_register_thread_unsafe(vid, queue_id, config, ops)``
+  Register a vhost queue with async copy device channel without
+  performing any locking.
+
+  This function is only safe to call from within vhost callback functions.
+
 * ``rte_vhost_async_channel_unregister(vid, queue_id)``
 
   Unregister the async copy device channel from a vhost queue.
@@ -268,6 +274,12 @@ The following is an overview of some key Vhost API functions:
   devices for all vhost queues in destroy_device(), when a
   virtio device is paused or shut down.
 
+* ``rte_vhost_async_channel_unregister_thread_unsafe(vid, queue_id)``
+  Unregister the async copy device channel from a vhost queue without
+  performing any locking.
+
+  This function is only safe to call from within vhost callback functions.
+
 * ``rte_vhost_submit_enqueue_burst(vid, queue_id, pkts, count, comp_pkts, comp_count)``
 
   Submit an enqueue request to transmit ``count`` packets from host to guest
lib/vhost/rte_vhost_async.h +39 -0
index c93490d..e4d20a3 100644
@@ -142,6 +142,45 @@ __rte_experimental
 int rte_vhost_async_channel_unregister(int vid, uint16_t queue_id);
 
 /**
+ * register an async channel for vhost without performing any locking
+ *
+ * @note This function does not perform any locking, and is only safe to call
+ *       from within vhost callback functions.
+ *
+ * @param vid
+ *  vhost device id async channel to be attached to
+ * @param queue_id
+ *  vhost queue id async channel to be attached to
+ * @param config
+ *  DMA channel configuration
+ * @param ops
+ *  DMA operation callbacks
+ * @return
+ *  0 on success, -1 on failures
+ */
+__rte_experimental
+int rte_vhost_async_channel_register_thread_unsafe(int vid, uint16_t queue_id,
+	struct rte_vhost_async_config config,
+	struct rte_vhost_async_channel_ops *ops);
+
+/**
+ * unregister a dma channel for vhost without performing any lock
+ *
+ * @note This function does not perform any locking, and is only safe to call
+ *       from within vhost callback functions.
+ *
+ * @param vid
+ *  vhost device id DMA channel to be detached
+ * @param queue_id
+ *  vhost queue id DMA channel to be detached
+ * @return
+ *  0 on success, -1 on failures
+ */
+__rte_experimental
+int rte_vhost_async_channel_unregister_thread_unsafe(int vid,
+		uint16_t queue_id);
+
+/**
  * This function submits enqueue data to async engine. Successfully
  * enqueued packets can be transfer completed or being occupied by DMA
  * engines, when this API returns. Transfer completed packets are returned
lib/vhost/version.map +4 -0
index 9103a23..2363db8 100644
@@ -79,4 +79,8 @@ EXPERIMENTAL {
 
 	# added in 21.05
 	rte_vhost_get_negotiated_protocol_features;
+
+	# added in 21.08
+	rte_vhost_async_channel_register_thread_unsafe;
+	rte_vhost_async_channel_unregister_thread_unsafe;
 };
lib/vhost/vhost.c +120 -34

212 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#33 lore raw

PATCH v2 2/3 vhost: rework async feature struct

In reply to Jiayu Hu

No need to use bitfields in the structure rte_vhost_async_features. This patch reworks the structure to improve code readability. In addition, add preserved padding fields on the structure for future usage.

---
 examples/vhost/main.c       |  4 ++--
 lib/vhost/rte_vhost_async.h | 24 ++++++++----------------
 lib/vhost/vhost.c           | 13 +++++--------
 3 files changed, 15 insertions(+), 26 deletions(-)
examples/vhost/main.c +2 -2
index d2179ea..ec1a5b4 100644
@@ -1468,7 +1468,7 @@ new_device(int vid)
 		vid, vdev->coreid);
 
 	if (async_vhost_driver) {
-		struct rte_vhost_async_features f;
+		struct rte_vhost_async_features f = {0};
 		struct rte_vhost_async_channel_ops channel_ops;
 
 		if (dma_type != NULL && strncmp(dma_type, "ioat", 4) == 0) {
@@ -1480,7 +1480,7 @@ new_device(int vid)
 			f.async_threshold = 256;
 
 			return rte_vhost_async_channel_register(vid, VIRTIO_RXQ,
-				f.intval, &channel_ops);
+				f, &channel_ops);
 		}
 	}
 
lib/vhost/rte_vhost_async.h +8 -16
index 6faa31f..12c6962 100644
@@ -93,18 +93,13 @@ struct async_inflight_info {
 };
 
 /**
- *  dma channel feature bit definition
+ *  dma channel features
  */
 struct rte_vhost_async_features {
-	union {
-		uint32_t intval;
-		struct {
-			uint32_t async_inorder:1;
-			uint32_t resvd_0:15;
-			uint32_t async_threshold:12;
-			uint32_t resvd_1:4;
-		};
-	};
+	uint32_t async_threshold;
+	uint32_t resvd_0[13];
+	uint8_t async_inorder;
+	uint8_t resvd_1[7];
 };
 
 /**
@@ -115,11 +110,7 @@ struct rte_vhost_async_features {
  * @param queue_id
  *  vhost queue id async channel to be attached to
  * @param features
- *  DMA channel feature bit
- *    b0       : DMA supports inorder data transfer
- *    b1  - b15: reserved
- *    b16 - b27: Packet length threshold for DMA transfer
- *    b28 - b31: reserved
+ *  DMA channel feature structure
  * @param ops
  *  DMA operation callbacks
  * @return
@@ -127,7 +118,8 @@ struct rte_vhost_async_features {
  */
 __rte_experimental
 int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
-	uint32_t features, struct rte_vhost_async_channel_ops *ops);
+	struct rte_vhost_async_features features,
+	struct rte_vhost_async_channel_ops *ops);
 
 /**
  * unregister a dma channel for vhost
lib/vhost/vhost.c +5 -8
index 53a470f..835aad8 100644
@@ -1620,18 +1620,15 @@ int rte_vhost_extern_callback_register(int vid,
 }
 
 int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
-					uint32_t features,
-					struct rte_vhost_async_channel_ops *ops)
+		struct rte_vhost_async_features features,
+		struct rte_vhost_async_channel_ops *ops)
 {
 	struct vhost_virtqueue *vq;
 	struct virtio_net *dev = get_device(vid);
-	struct rte_vhost_async_features f;
 
 	if (dev == NULL || ops == NULL)
 		return -1;
 
-	f.intval = features;
-
 	if (queue_id >= VHOST_MAX_VRING)
 		return -1;
 
@@ -1640,7 +1637,7 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
 	if (unlikely(vq == NULL || !dev->async_copy))
 		return -1;
 
-	if (unlikely(!f.async_inorder)) {
+	if (unlikely(!features.async_inorder)) {
 		VHOST_LOG_CONFIG(ERR,
 			"async copy is not supported on non-inorder mode "
 			"(vid %d, qid: %d)\n", vid, queue_id);
@@ -1720,8 +1717,8 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
 	vq->async_ops.check_completed_copies = ops->check_completed_copies;
 	vq->async_ops.transfer_data = ops->transfer_data;
 
-	vq->async_inorder = f.async_inorder;
-	vq->async_threshold = f.async_threshold;
+	vq->async_inorder = features.async_inorder;
+	vq->async_threshold = features.async_threshold;
 
 	vq->async_registered = true;
 
Signature · 1 line
2.7.4
#34 lore raw

Re: [dpdk-dev] [PATCH v2 2/3] vhost: rework async feature struct

Hi Jiayu,

Quoted 39 lines · Jiayu Hu

No need to use bitfields in the structure rte_vhost_async_features. This patch reworks the structure to improve code readability. In addition, add preserved padding fields on the structure for future usage.

---
 examples/vhost/main.c       |  4 ++--
 lib/vhost/rte_vhost_async.h | 24 ++++++++----------------
 lib/vhost/vhost.c           | 13 +++++--------
 3 files changed, 15 insertions(+), 26 deletions(-)
examples/vhost/main.c +2 -2
index d2179ea..ec1a5b4 100644
@@ -1468,7 +1468,7 @@ new_device(int vid)
 		vid, vdev->coreid);
 
 	if (async_vhost_driver) {
-		struct rte_vhost_async_features f;
+		struct rte_vhost_async_features f = {0};
 		struct rte_vhost_async_channel_ops channel_ops;
 
 		if (dma_type != NULL && strncmp(dma_type, "ioat", 4) == 0) {
@@ -1480,7 +1480,7 @@ new_device(int vid)
 			f.async_threshold = 256;
 
 			return rte_vhost_async_channel_register(vid, VIRTIO_RXQ,
-				f.intval, &channel_ops);
+				f, &channel_ops);
 		}
 	}
 
lib/vhost/rte_vhost_async.h +0 -0
index 6faa31f..12c6962 100644

lib/vhost/rte_vhost_async.h struct async_inflight_info { · line 98

Quoted 7 lines
lib/vhost/rte_vhost_async.h +1 -1
@@ -93,18 +93,13 @@ struct async_inflight_info {
 };
 
 /**
- *  dma channel feature bit definition
+ *  dma channel features
  */
 struct rte_vhost_async_features {

Give the struct also contains config/tuning stuff, I don't think rte_vhost_async_features is a good name, maybe rte_vhost_async_config?

Quoted 4 lines
lib/vhost/rte_vhost_async.h +0 -4
-	union {
-		uint32_t intval;
-		struct {
-			uint32_t async_inorder:1;

lib/vhost/rte_vhost_async.h struct async_inflight_info {

Quoted 10 lines
lib/vhost/rte_vhost_async.h +2 -5
-			uint32_t resvd_0:15;
-			uint32_t async_threshold:12;
-			uint32_t resvd_1:4;
-		};
-	};
+	uint32_t async_threshold;
 
 
 
+	uint32_t resvd_0[13];

That's a lot of padding! I hope the application won't have to use that much to configure the async feature one day :)

lib/vhost/rte_vhost_async.h struct async_inflight_info { · line 101

Quoted 1 line
lib/vhost/rte_vhost_async.h +1 -0
+	uint8_t async_inorder;

I would prefer a uint32_t features bitfield for consistency with Vhost library, with enums for the features definition.

Quoted 73 lines
lib/vhost/rte_vhost_async.h +1 -0
+	uint8_t resvd_1[7];

};

/**

lib/vhost/rte_vhost_async.h +3 -6
@@ -115,11 +110,7 @@ struct rte_vhost_async_features {
  * @param queue_id
  *  vhost queue id async channel to be attached to
  * @param features
- *  DMA channel feature bit
- *    b0       : DMA supports inorder data transfer
- *    b1  - b15: reserved
- *    b16 - b27: Packet length threshold for DMA transfer
- *    b28 - b31: reserved
+ *  DMA channel feature structure
  * @param ops
  *  DMA operation callbacks
  * @return
@@ -127,7 +118,8 @@ struct rte_vhost_async_features {
  */
 __rte_experimental
 int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
-	uint32_t features, struct rte_vhost_async_channel_ops *ops);
+	struct rte_vhost_async_features features,
+	struct rte_vhost_async_channel_ops *ops);
 
 /**
  * unregister a dma channel for vhost
lib/vhost/vhost.c +5 -8
index 53a470f..835aad8 100644
@@ -1620,18 +1620,15 @@ int rte_vhost_extern_callback_register(int vid,
 }
 
 int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
-					uint32_t features,
-					struct rte_vhost_async_channel_ops *ops)
+		struct rte_vhost_async_features features,
+		struct rte_vhost_async_channel_ops *ops)
 {
 	struct vhost_virtqueue *vq;
 	struct virtio_net *dev = get_device(vid);
-	struct rte_vhost_async_features f;
 
 	if (dev == NULL || ops == NULL)
 		return -1;
 
-	f.intval = features;
-
 	if (queue_id >= VHOST_MAX_VRING)
 		return -1;
 
@@ -1640,7 +1637,7 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
 	if (unlikely(vq == NULL || !dev->async_copy))
 		return -1;
 
-	if (unlikely(!f.async_inorder)) {
+	if (unlikely(!features.async_inorder)) {
 		VHOST_LOG_CONFIG(ERR,
 			"async copy is not supported on non-inorder mode "
 			"(vid %d, qid: %d)\n", vid, queue_id);
@@ -1720,8 +1717,8 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
 	vq->async_ops.check_completed_copies = ops->check_completed_copies;
 	vq->async_ops.transfer_data = ops->transfer_data;
 
-	vq->async_inorder = f.async_inorder;
-	vq->async_threshold = f.async_threshold;
+	vq->async_inorder = features.async_inorder;
+	vq->async_threshold = features.async_threshold;
 
 	vq->async_registered = true;
 
author
#35 lore raw

PATCH v2 3/3 vhost: add thread unsafe async registeration functions

In reply to Jiayu Hu

This patch adds thread unsafe version for async register and unregister functions.

---
 doc/guides/prog_guide/vhost_lib.rst |  12 +++
 lib/vhost/rte_vhost_async.h         |  39 +++++++++
 lib/vhost/version.map               |   4 +
 lib/vhost/vhost.c                   | 154 +++++++++++++++++++++++++++---------
 4 files changed, 171 insertions(+), 38 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +12 -0
index d18fb98..6b2745f 100644
@@ -253,6 +253,12 @@ The following is an overview of some key Vhost API functions:
     vhost invokes this function to get the copy data completed by async
     devices.
 
+* ``rte_vhost_async_channel_register_thread_unsafe(vid, queue_id, features, ops)``
+  Register a vhost queue with async copy device channel without
+  performing any locking.
+
+  This function is only safe to call from within vhost callback functions.
+
 * ``rte_vhost_async_channel_unregister(vid, queue_id)``
 
   Unregister the async copy device channel from a vhost queue.
@@ -265,6 +271,12 @@ The following is an overview of some key Vhost API functions:
   devices for all vhost queues in destroy_device(), when a
   virtio device is paused or shut down.
 
+* ``rte_vhost_async_channel_unregister_thread_unsafe(vid, queue_id)``
+  Unregister the async copy device channel from a vhost queue without
+  performing any locking.
+
+  This function is only safe to call from within vhost callback functions.
+
 * ``rte_vhost_submit_enqueue_burst(vid, queue_id, pkts, count, comp_pkts, comp_count)``
 
   Submit an enqueue request to transmit ``count`` packets from host to guest
lib/vhost/rte_vhost_async.h +39 -0
index 12c6962..6a93fcd 100644
@@ -135,6 +135,45 @@ __rte_experimental
 int rte_vhost_async_channel_unregister(int vid, uint16_t queue_id);
 
 /**
+ * register an async channel for vhost without performing any locking
+ *
+ * @note This function does not perform any locking, and is only safe to call
+ *       from within vhost callback functions.
+ *
+ * @param vid
+ *  vhost device id async channel to be attached to
+ * @param queue_id
+ *  vhost queue id async channel to be attached to
+ * @param features
+ *  DMA channel feature structure
+ * @param ops
+ *  DMA operation callbacks
+ * @return
+ *  0 on success, -1 on failures
+ */
+__rte_experimental
+int rte_vhost_async_channel_register_thread_unsafe(int vid, uint16_t queue_id,
+	struct rte_vhost_async_features features,
+	struct rte_vhost_async_channel_ops *ops);
+
+/**
+ * unregister a dma channel for vhost without performing any lock
+ *
+ * @note This function does not perform any locking, and is only safe to call
+ *       from within vhost callback functions.
+ *
+ * @param vid
+ *  vhost device id DMA channel to be detached
+ * @param queue_id
+ *  vhost queue id DMA channel to be detached
+ * @return
+ *  0 on success, -1 on failures
+ */
+__rte_experimental
+int rte_vhost_async_channel_unregister_thread_unsafe(int vid,
+		uint16_t queue_id);
+
+/**
  * This function submits enqueue data to async engine. Successfully
  * enqueued packets can be transfer completed or being occupied by DMA
  * engines, when this API returns. Transfer completed packets are returned
lib/vhost/version.map +4 -0
index 9103a23..2363db8 100644
@@ -79,4 +79,8 @@ EXPERIMENTAL {
 
 	# added in 21.05
 	rte_vhost_get_negotiated_protocol_features;
+
+	# added in 21.08
+	rte_vhost_async_channel_register_thread_unsafe;
+	rte_vhost_async_channel_unregister_thread_unsafe;
 };
lib/vhost/vhost.c +116 -38

213 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#36 lore raw

PATCH 2/2 vhost: add thread unsafe async registration functions

In reply to Jiayu Hu

This patch is to add thread unsafe version for async register and unregister functions.

---
 doc/guides/prog_guide/vhost_lib.rst |  12 +++
 lib/vhost/rte_vhost_async.h         |  42 ++++++++++
 lib/vhost/version.map               |   4 +
 lib/vhost/vhost.c                   | 161 +++++++++++++++++++++++++++---------
 4 files changed, 178 insertions(+), 41 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +12 -0
index d18fb98..6b2745f 100644
@@ -253,6 +253,12 @@ The following is an overview of some key Vhost API functions:
     vhost invokes this function to get the copy data completed by async
     devices.
 
+* ``rte_vhost_async_channel_register_thread_unsafe(vid, queue_id, features, ops)``
+  Register a vhost queue with async copy device channel without
+  performing any locking.
+
+  This function is only safe to call from within vhost callback functions.
+
 * ``rte_vhost_async_channel_unregister(vid, queue_id)``
 
   Unregister the async copy device channel from a vhost queue.
@@ -265,6 +271,12 @@ The following is an overview of some key Vhost API functions:
   devices for all vhost queues in destroy_device(), when a
   virtio device is paused or shut down.
 
+* ``rte_vhost_async_channel_unregister_thread_unsafe(vid, queue_id)``
+  Unregister the async copy device channel from a vhost queue without
+  performing any locking.
+
+  This function is only safe to call from within vhost callback functions.
+
 * ``rte_vhost_submit_enqueue_burst(vid, queue_id, pkts, count, comp_pkts, comp_count)``
 
   Submit an enqueue request to transmit ``count`` packets from host to guest
lib/vhost/rte_vhost_async.h +42 -0

48 lines not on this page · raw message

lib/vhost/version.map +4 -0
index 9103a23..2363db8 100644
@@ -79,4 +79,8 @@ EXPERIMENTAL {
 
 	# added in 21.05
 	rte_vhost_get_negotiated_protocol_features;
+
+	# added in 21.08
+	rte_vhost_async_channel_register_thread_unsafe;
+	rte_vhost_async_channel_unregister_thread_unsafe;
 };
lib/vhost/vhost.c +120 -41

221 lines not on this page · raw message

Signature · 1 line
2.7.4
#37 lore raw

Re: [dpdk-dev] [PATCH 2/2] vhost: add thread unsafe async registration functions

Quoted 1 line · Jiayu Hu

This patch is to add thread unsafe version for async register and

s/is to add/adds/

Quoted 15 lines

unregister functions.

---
 doc/guides/prog_guide/vhost_lib.rst |  12 +++
 lib/vhost/rte_vhost_async.h         |  42 ++++++++++
 lib/vhost/version.map               |   4 +
 lib/vhost/vhost.c                   | 161 +++++++++++++++++++++++++++---------
 4 files changed, 178 insertions(+), 41 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +0 -0
index d18fb98..6b2745f 100644

doc/guides/prog_guide/vhost_lib.rst The following is an overview of some key Vhost API functions: · line 260

Quoted 8 lines
doc/guides/prog_guide/vhost_lib.rst +5 -0
@@ -253,6 +253,12 @@ The following is an overview of some key Vhost API functions:
     vhost invokes this function to get the copy data completed by async
     devices.
 
+* ``rte_vhost_async_channel_register_thread_unsafe(vid, queue_id, features, ops)``
+  Register a vhost queue with async copy device channel without
+  performing any locking.
+
+  This function is only safe to call from within vhost callback functions.

I'm not sure with this, AFAICS .new_device() is called without the lock held, so is that safe? Since .new_device() is the first time the app gets required device info to use the Vhost API, that might not be an issue, though.

author
#38 lore raw

Re: [dpdk-dev] [PATCH 2/2] vhost: add thread unsafe async registration functions

Quoted 38 lines

-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Friday, July 2, 2021 3:41 PM
To: Hu, Jiayu <[email protected]>; [email protected]
Cc: Xia, Chenbo <[email protected]>; Wang, Yinan <[email protected]>
Subject: Re: [PATCH 2/2] vhost: add thread unsafe async registration functions

Quoted 1 line · Jiayu Hu

This patch is to add thread unsafe version for async register and

s/is to add/adds/

doc/guides/prog_guide/vhost_lib.rst The following is an overview of some key Vhost

Quoted 16 lines

unregister functions.

---
 doc/guides/prog_guide/vhost_lib.rst |  12 +++
 lib/vhost/rte_vhost_async.h         |  42 ++++++++++
 lib/vhost/version.map               |   4 +
 lib/vhost/vhost.c                   | 161 +++++++++++++++++++++++++++---------
 4 files changed, 178 insertions(+), 41 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +0 -0
index d18fb98..6b2745f 100644
@@ -253,6 +253,12 @@ The following is an overview of some key Vhost

API functions:

Quoted 3 lines
doc/guides/prog_guide/vhost_lib.rst +0 -0
     vhost invokes this function to get the copy data completed by async
     devices.
 
Quoted 10 lines

doc/guides/prog_guide/vhost_lib.rst The following is an overview of some key Vhost API functions: · line 260

Quoted 6 lines
doc/guides/prog_guide/vhost_lib.rst +6 -0
+* ``rte_vhost_async_channel_register_thread_unsafe(vid, queue_id,
+features, ops)``
+  Register a vhost queue with async copy device channel without
+  performing any locking.
+
+  This function is only safe to call from within vhost callback functions.

I'm not sure with this, AFAICS .new_device() is called without the lock held, so is that safe? Since .new_device() is the first time the app gets required device info to use the Vhost API, that might not be an issue, though.

I think so. Although new_device() is called without lock, no data plane threads can operate vrings if device is not created.

Thanks,
Jiayu

#39 lore raw

Re: [dpdk-dev] [PATCH 2/2] vhost: add thread unsafe async registration functions

In reply to Jiayu Hu
Quoted 224 lines · Jiayu Hu

This patch is to add thread unsafe version for async register and unregister functions.

---
 doc/guides/prog_guide/vhost_lib.rst |  12 +++
 lib/vhost/rte_vhost_async.h         |  42 ++++++++++
 lib/vhost/version.map               |   4 +
 lib/vhost/vhost.c                   | 161 +++++++++++++++++++++++++++---------
 4 files changed, 178 insertions(+), 41 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +12 -0
index d18fb98..6b2745f 100644
@@ -253,6 +253,12 @@ The following is an overview of some key Vhost API functions:
     vhost invokes this function to get the copy data completed by async
     devices.
 
+* ``rte_vhost_async_channel_register_thread_unsafe(vid, queue_id, features, ops)``
+  Register a vhost queue with async copy device channel without
+  performing any locking.
+
+  This function is only safe to call from within vhost callback functions.
+
 * ``rte_vhost_async_channel_unregister(vid, queue_id)``
 
   Unregister the async copy device channel from a vhost queue.
@@ -265,6 +271,12 @@ The following is an overview of some key Vhost API functions:
   devices for all vhost queues in destroy_device(), when a
   virtio device is paused or shut down.
 
+* ``rte_vhost_async_channel_unregister_thread_unsafe(vid, queue_id)``
+  Unregister the async copy device channel from a vhost queue without
+  performing any locking.
+
+  This function is only safe to call from within vhost callback functions.
+
 * ``rte_vhost_submit_enqueue_burst(vid, queue_id, pkts, count, comp_pkts, comp_count)``
 
   Submit an enqueue request to transmit ``count`` packets from host to guest
lib/vhost/rte_vhost_async.h +42 -0
index 6faa31f..d054b5f 100644
@@ -143,6 +143,48 @@ __rte_experimental
 int rte_vhost_async_channel_unregister(int vid, uint16_t queue_id);
 
 /**
+ * register an async channel for vhost without performing any locking
+ *
+ * @note This function does not perform any locking, and is only safe to call
+ *       from within vhost callback functions.
+ *
+ * @param vid
+ *  vhost device id async channel to be attached to
+ * @param queue_id
+ *  vhost queue id async channel to be attached to
+ * @param features
+ *  DMA channel feature bit
+ *    b0       : DMA supports inorder data transfer
+ *    b1  - b15: reserved
+ *    b16 - b27: Packet length threshold for DMA transfer
+ *    b28 - b31: reserved
+ * @param ops
+ *  DMA operation callbacks
+ * @return
+ *  0 on success, -1 on failures
+ */
+__rte_experimental
+int rte_vhost_async_channel_register_thread_unsafe(int vid, uint16_t queue_id,
+	uint32_t features, struct rte_vhost_async_channel_ops *ops);
+
+/**
+ * unregister a dma channel for vhost without performing any lock
+ *
+ * @note This function does not perform any locking, and is only safe to call
+ *       from within vhost callback functions.
+ *
+ * @param vid
+ *  vhost device id DMA channel to be detached
+ * @param queue_id
+ *  vhost queue id DMA channel to be detached
+ * @return
+ *  0 on success, -1 on failures
+ */
+__rte_experimental
+int rte_vhost_async_channel_unregister_thread_unsafe(int vid,
+		uint16_t queue_id);
+
+/**
  * This function submits enqueue data to async engine. Successfully
  * enqueued packets can be transfer completed or being occupied by DMA
  * engines, when this API returns. Transfer completed packets are returned
lib/vhost/version.map +4 -0
index 9103a23..2363db8 100644
@@ -79,4 +79,8 @@ EXPERIMENTAL {
 
 	# added in 21.05
 	rte_vhost_get_negotiated_protocol_features;
+
+	# added in 21.08
+	rte_vhost_async_channel_register_thread_unsafe;
+	rte_vhost_async_channel_unregister_thread_unsafe;
 };
lib/vhost/vhost.c +17 -40
index c96f633..025e150 100644
@@ -1609,46 +1609,20 @@ int rte_vhost_extern_callback_register(int vid,
 	return 0;
 }
 
-int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
-					uint32_t features,
-					struct rte_vhost_async_channel_ops *ops)
+static __rte_always_inline int
+async_channel_register(int vid, uint16_t queue_id,
+		struct rte_vhost_async_features f,
+		struct rte_vhost_async_channel_ops *ops)
 {
-	struct vhost_virtqueue *vq;
 	struct virtio_net *dev = get_device(vid);
-	struct rte_vhost_async_features f;
+	struct vhost_virtqueue *vq = dev->virtqueue[queue_id];
 	int node;
 
-	if (dev == NULL || ops == NULL)
-		return -1;
-
-	f.intval = features;
-
-	if (queue_id >= VHOST_MAX_VRING)
-		return -1;
-
-	vq = dev->virtqueue[queue_id];
-
-	if (unlikely(vq == NULL || !dev->async_copy))
-		return -1;
-
-	if (unlikely(!f.async_inorder)) {
-		VHOST_LOG_CONFIG(ERR,
-			"async copy is not supported on non-inorder mode "
-			"(vid %d, qid: %d)\n", vid, queue_id);
-		return -1;
-	}
-
-	if (unlikely(ops->check_completed_copies == NULL ||
-		ops->transfer_data == NULL))
-		return -1;
-
-	rte_spinlock_lock(&vq->access_lock);
-
 	if (unlikely(vq->async_registered)) {
 		VHOST_LOG_CONFIG(ERR,
 			"async register failed: channel already registered "
 			"(vid %d, qid: %d)\n", vid, queue_id);
-		goto reg_out;
+		return -1;
 	}
 
 #ifdef RTE_LIBRTE_VHOST_NUMA
@@ -1670,7 +1644,7 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
 		VHOST_LOG_CONFIG(ERR,
 			"async register failed: cannot allocate memory for async_pkts_info "
 			"(vid %d, qid: %d)\n", vid, queue_id);
-		goto reg_out;
+		return -1;
 	}
 
 	vq->it_pool = rte_malloc_socket(NULL,
@@ -1681,7 +1655,7 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
 		VHOST_LOG_CONFIG(ERR,
 			"async register failed: cannot allocate memory for it_pool "
 			"(vid %d, qid: %d)\n", vid, queue_id);
-		goto reg_out;
+		return -1;
 	}
 
 	vq->vec_pool = rte_malloc_socket(NULL,
@@ -1692,7 +1666,7 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
 		VHOST_LOG_CONFIG(ERR,
 			"async register failed: cannot allocate memory for vec_pool "
 			"(vid %d, qid: %d)\n", vid, queue_id);
-		goto reg_out;
+		return -1;
 	}
 
 	if (vq_is_packed(dev)) {
@@ -1704,7 +1678,7 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
 			VHOST_LOG_CONFIG(ERR,
 				"async register failed: cannot allocate memory for async buffers "
 				"(vid %d, qid: %d)\n", vid, queue_id);
-			goto reg_out;
+			return -1;
 		}
 	} else {
 		vq->async_descs_split = rte_malloc_socket(NULL,
@@ -1715,22 +1689,92 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
 			VHOST_LOG_CONFIG(ERR,
 				"async register failed: cannot allocate memory for async descs "
 				"(vid %d, qid: %d)\n", vid, queue_id);
-			goto reg_out;
+			return -1;
 		}
 	}
 
 	vq->async_ops.check_completed_copies = ops->check_completed_copies;
 	vq->async_ops.transfer_data = ops->transfer_data;
-
 	vq->async_inorder = f.async_inorder;
 	vq->async_threshold = f.async_threshold;
-
 	vq->async_registered = true;
 
-reg_out:
+	return 0;
+}
+
+int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
+					uint32_t features,
+					struct rte_vhost_async_channel_ops *ops)

lib/vhost/vhost.c int rte_vhost_async_channel_register(int vid, uint16_t queue_id, · line 1717

Quoted 10 lines
lib/vhost/vhost.c +10 -0
+{
+	struct vhost_virtqueue *vq;
+	struct virtio_net *dev = get_device(vid);
+	struct rte_vhost_async_features f;
+	int ret;
+
+	if (dev == NULL || ops == NULL)
+		return -1;
+
+	f.intval = features;

Not directly related to this patch set, but could you please rework struct rte_vhost_async_features? There is no point to pack the flags and threshold values.

Also, the prototype should just pass the struct directly, or add different fields for the threshold and the features.

Quoted 106 lines
lib/vhost/vhost.c +93 -1
+
+	if (queue_id >= VHOST_MAX_VRING)
+		return -1;
+
+	vq = dev->virtqueue[queue_id];
+
+	if (unlikely(vq == NULL || !dev->async_copy))
+		return -1;
+
+	if (unlikely(!f.async_inorder)) {
+		VHOST_LOG_CONFIG(ERR,
+			"async copy is not supported on non-inorder mode "
+			"(vid %d, qid: %d)\n", vid, queue_id);
+		return -1;
+	}
+
+	if (unlikely(ops->check_completed_copies == NULL ||
+		ops->transfer_data == NULL))
+		return -1;
+
+	rte_spinlock_lock(&vq->access_lock);
+	ret = async_channel_register(vid, queue_id, f, ops);
 	rte_spinlock_unlock(&vq->access_lock);
 
-	return 0;
+	return ret;
+}
+
+int rte_vhost_async_channel_register_thread_unsafe(int vid, uint16_t queue_id,
+					uint32_t features,
+					struct rte_vhost_async_channel_ops *ops)
+{
+	struct vhost_virtqueue *vq;
+	struct virtio_net *dev = get_device(vid);
+	struct rte_vhost_async_features f;
+
+	if (dev == NULL || ops == NULL)
+		return -1;
+
+	f.intval = features;
+
+	if (queue_id >= VHOST_MAX_VRING)
+		return -1;
+
+	vq = dev->virtqueue[queue_id];
+
+	if (unlikely(vq == NULL || !dev->async_copy))
+		return -1;
+
+	if (unlikely(!f.async_inorder)) {
+		VHOST_LOG_CONFIG(ERR,
+			"async copy is not supported on non-inorder mode "
+			"(vid %d, qid: %d)\n", vid, queue_id);
+		return -1;
+	}
+
+	if (unlikely(ops->check_completed_copies == NULL ||
+		ops->transfer_data == NULL))
+		return -1;
+
+	return async_channel_register(vid, queue_id, f, ops);
 }
 
 int rte_vhost_async_channel_unregister(int vid, uint16_t queue_id)
@@ -1780,5 +1824,40 @@ int rte_vhost_async_channel_unregister(int vid, uint16_t queue_id)
 	return ret;
 }
 
+int rte_vhost_async_channel_unregister_thread_unsafe(int vid,
+		uint16_t queue_id)
+{
+	struct vhost_virtqueue *vq;
+	struct virtio_net *dev = get_device(vid);
+
+	if (dev == NULL)
+		return -1;
+
+	if (queue_id >= VHOST_MAX_VRING)
+		return -1;
+
+	vq = dev->virtqueue[queue_id];
+
+	if (vq == NULL)
+		return -1;
+
+	if (!vq->async_registered)
+		return 0;
+
+	if (vq->async_pkts_inflight_n) {
+		VHOST_LOG_CONFIG(ERR, "Failed to unregister async channel. "
+			"async inflight packets must be completed before unregistration.\n");
+		return -1;
+	}
+
+	vhost_free_async_mem(vq);
+
+	vq->async_ops.transfer_data = NULL;
+	vq->async_ops.check_completed_copies = NULL;
+	vq->async_registered = false;
+
+	return 0;
+}
+
 RTE_LOG_REGISTER_SUFFIX(vhost_config_log_level, config, INFO);
 RTE_LOG_REGISTER_SUFFIX(vhost_data_log_level, data, WARNING);
author
#40 lore raw

Re: [dpdk-dev] [PATCH 2/2] vhost: add thread unsafe async registration functions

Quoted 166 lines

-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Monday, July 5, 2021 4:59 PM
To: Hu, Jiayu <[email protected]>; [email protected]
Cc: Xia, Chenbo <[email protected]>; Wang, Yinan <[email protected]>
Subject: Re: [PATCH 2/2] vhost: add thread unsafe async registration functions

Quoted 16 lines · Jiayu Hu

This patch is to add thread unsafe version for async register and unregister functions.

---
 doc/guides/prog_guide/vhost_lib.rst |  12 +++
 lib/vhost/rte_vhost_async.h         |  42 ++++++++++
 lib/vhost/version.map               |   4 +
 lib/vhost/vhost.c                   | 161 +++++++++++++++++++++++++++---------
 4 files changed, 178 insertions(+), 41 deletions(-)
lib/vhost/vhost.c index renamed from lib/vhost/vhost.c +0 -0

c96f633..025e150 100644

lib/vhost/vhost.c int rte_vhost_extern_callback_register(int vid, · line 1614

Quoted 6 lines
lib/vhost/vhost.c +0 -3
@@ -1609,46 +1609,20 @@ int rte_vhost_extern_callback_register(int vid,
 	return 0;
 }
 
-int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
-					uint32_t features,
-					struct rte_vhost_async_channel_ops

*ops)

lib/vhost/vhost.c int rte_vhost_async_channel_register(int vid,

Quoted 47 lines
lib/vhost/vhost.c +6 -29
+static __rte_always_inline int
+async_channel_register(int vid, uint16_t queue_id,
+		struct rte_vhost_async_features f,
+		struct rte_vhost_async_channel_ops *ops)
 {
-	struct vhost_virtqueue *vq;
 	struct virtio_net *dev = get_device(vid);
-	struct rte_vhost_async_features f;
+	struct vhost_virtqueue *vq = dev->virtqueue[queue_id];
 	int node;
 
-	if (dev == NULL || ops == NULL)
-		return -1;
-
-	f.intval = features;
-
-	if (queue_id >= VHOST_MAX_VRING)
-		return -1;
-
-	vq = dev->virtqueue[queue_id];
-
-	if (unlikely(vq == NULL || !dev->async_copy))
-		return -1;
-
-	if (unlikely(!f.async_inorder)) {
-		VHOST_LOG_CONFIG(ERR,
-			"async copy is not supported on non-inorder mode "
-			"(vid %d, qid: %d)\n", vid, queue_id);
-		return -1;
-	}
-
-	if (unlikely(ops->check_completed_copies == NULL ||
-		ops->transfer_data == NULL))
-		return -1;
-
-	rte_spinlock_lock(&vq->access_lock);
-
 	if (unlikely(vq->async_registered)) {
 		VHOST_LOG_CONFIG(ERR,
 			"async register failed: channel already registered "
 			"(vid %d, qid: %d)\n", vid, queue_id);
-		goto reg_out;
+		return -1;
 	}
 
 #ifdef RTE_LIBRTE_VHOST_NUMA
@@ -1670,7 +1644,7 @@ int rte_vhost_async_channel_register(int vid,

uint16_t queue_id,

lib/vhost/vhost.c int rte_vhost_async_channel_register(int vid, · line 1645

Quoted 2 lines
lib/vhost/vhost.c +0 -0
 		VHOST_LOG_CONFIG(ERR,
 			"async register failed: cannot allocate memory for

async_pkts_info "

lib/vhost/vhost.c

Quoted 9 lines
lib/vhost/vhost.c +1 -1
 			"(vid %d, qid: %d)\n", vid, queue_id);
-		goto reg_out;
+		return -1;
 	}
 
 	vq->it_pool = rte_malloc_socket(NULL, @@ -1681,7 +1655,7 @@ int

rte_vhost_async_channel_register(int vid, uint16_t queue_id,

lib/vhost/vhost.c +0 -0
 		VHOST_LOG_CONFIG(ERR,
 			"async register failed: cannot allocate memory for

it_pool "

lib/vhost/vhost.c int rte_vhost_extern_callback_register(int vid,

Quoted 6 lines
lib/vhost/vhost.c +1 -1
 			"(vid %d, qid: %d)\n", vid, queue_id);
-		goto reg_out;
+		return -1;
 	}
 
 	vq->vec_pool = rte_malloc_socket(NULL, @@ -1692,7 +1666,7 @@

int

lib/vhost/vhost.c

Quoted 3 lines

rte_vhost_async_channel_register(int vid, uint16_t queue_id,

lib/vhost/vhost.c +0 -0
 		VHOST_LOG_CONFIG(ERR,
 			"async register failed: cannot allocate memory for

vec_pool "

lib/vhost/vhost.c int rte_vhost_async_channel_register(int vid,

Quoted 7 lines
lib/vhost/vhost.c +1 -1
 			"(vid %d, qid: %d)\n", vid, queue_id);
-		goto reg_out;
+		return -1;
 	}
 
 	if (vq_is_packed(dev)) {
@@ -1704,7 +1678,7 @@ int rte_vhost_async_channel_register(int vid,

uint16_t queue_id,

lib/vhost/vhost.c int rte_vhost_async_channel_register(int vid, · line 1679

Quoted 2 lines
lib/vhost/vhost.c +0 -0
 			VHOST_LOG_CONFIG(ERR,
 				"async register failed: cannot allocate

memory for async buffers "

lib/vhost/vhost.c int rte_vhost_async_channel_register(int vid, uint16_t queue_id,

Quoted 6 lines
lib/vhost/vhost.c +1 -1
 				"(vid %d, qid: %d)\n", vid, queue_id);
-			goto reg_out;
+			return -1;
 		}
 	} else {
 		vq->async_descs_split = rte_malloc_socket(NULL, @@ -

1715,22

Quoted 1 line

+1689,92 @@ int rte_vhost_async_channel_register(int vid, uint16_t

queue_id,

lib/vhost/vhost.c

Quoted 2 lines
lib/vhost/vhost.c +0 -0
 			VHOST_LOG_CONFIG(ERR,
 				"async register failed: cannot allocate

memory for async descs "

Quoted 12 lines
lib/vhost/vhost.c +1 -1
 				"(vid %d, qid: %d)\n", vid, queue_id);
-			goto reg_out;
+			return -1;
 		}
 	}
 
 	vq->async_ops.check_completed_copies = ops-

check_completed_copies;

lib/vhost/vhost.c +0 -1
 	vq->async_ops.transfer_data = ops->transfer_data;
-
 	vq->async_inorder = f.async_inorder;
 	vq->async_threshold = f.async_threshold;

lib/vhost/vhost.c int rte_vhost_async_channel_register(int vid, uint16_t queue_id,

Quoted 10 lines
lib/vhost/vhost.c +6 -2
-
 	vq->async_registered = true;
 
-reg_out:
+	return 0;
+}
+
+int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
+					uint32_t features,
+					struct rte_vhost_async_channel_ops

*ops) {

lib/vhost/vhost.c int rte_vhost_async_channel_register(int vid, uint16_t queue_id, · line 1717

Quoted 9 lines
lib/vhost/vhost.c +9 -0
+	struct vhost_virtqueue *vq;
+	struct virtio_net *dev = get_device(vid);
+	struct rte_vhost_async_features f;
+	int ret;
+
+	if (dev == NULL || ops == NULL)
+		return -1;
+
+	f.intval = features;

Not directly related to this patch set, but could you please rework struct rte_vhost_async_features? There is no point to pack the flags and threshold values.

Quoted 3 lines

Also, the prototype should just pass the struct directly, or add different fields for the threshold and the features.

Will rework the structure in v2.

Thanks,
Jiayu

#41 lore raw
In reply to Jiayu Hu
Quoted 18 lines · Jiayu Hu

Lock protection is needed during the vhost notifies the application of device readiness, so the first patch is to add lock protection. After performing locking, existed async vhost registration functions will cause deadlock, as they acquire lock too. So the second patch is to provide unsafe registration functions to support calling within vhost callback functions.

Jiayu Hu (2):
vhost: fix lock on device readiness notification
vhost: add thread unsafe async registration functions

 doc/guides/prog_guide/vhost_lib.rst |  12 +++
 lib/vhost/rte_vhost_async.h         |  42 ++++++++++
 lib/vhost/version.map               |   4 +
 lib/vhost/vhost.c                   | 161 +++++++++++++++++++++++++++---------
 lib/vhost/vhost_user.c              |   5 +-
 5 files changed, 180 insertions(+), 44 deletions(-)
#42 lore raw
In reply to Jiayu Hu

Sorry, for previous blank reply.

Quoted 6 lines · Jiayu Hu

Lock protection is needed during the vhost notifies the application of device readiness, so the first patch is to add lock protection. After performing locking, existed async vhost registration functions will cause deadlock, as they acquire lock too. So the second patch is to provide unsafe registration functions to support calling within vhost callback functions.

I agree the callback should be always protected, and in that case having a new thread-unsafe API makes sense for async registration.

Regarding backport, I'm not sure what we should do.

Backporting new API is a no-go, but with only backporting patch 1 async feature will be always broken on 20.11 LTS, right?

What do you think?

Thanks,
Maxime

Quoted 11 lines

Jiayu Hu (2):
vhost: fix lock on device readiness notification
vhost: add thread unsafe async registration functions

 doc/guides/prog_guide/vhost_lib.rst |  12 +++
 lib/vhost/rte_vhost_async.h         |  42 ++++++++++
 lib/vhost/version.map               |   4 +
 lib/vhost/vhost.c                   | 161 +++++++++++++++++++++++++++---------
 lib/vhost/vhost_user.c              |   5 +-
 5 files changed, 180 insertions(+), 44 deletions(-)
author
#43 lore raw

Hi Maxime,

Quoted 18 lines

-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Friday, June 4, 2021 3:25 PM
To: Hu, Jiayu <[email protected]>; [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Wang, Yinan <[email protected]>
Subject: Re: [PATCH 0/2] provide thread unsafe async registration functions

Sorry, for previous blank reply.

Quoted 6 lines · Jiayu Hu

Lock protection is needed during the vhost notifies the application of device readiness, so the first patch is to add lock protection. After performing locking, existed async vhost registration functions will cause deadlock, as they acquire lock too. So the second patch is to provide unsafe registration functions to support calling within vhost callback functions.

Quoted 7 lines

I agree the callback should be always protected, and in that case having a new thread-unsafe API makes sense for async registration.

Regarding backport, I'm not sure what we should do.

Backporting new API is a no-go, but with only backporting patch 1 async feature will be always broken on 20.11 LTS, right?

Yes, if only backporting this fix patch to 20.11 LTS, it may break apps who call async registration functions inside vhost callbacks.

How about making this patch not a fix, but a new feature?

Thanks,
Jiayu

Quoted 17 lines

What do you think?

Thanks,
Maxime

Quoted 11 lines

Jiayu Hu (2):
vhost: fix lock on device readiness notification
vhost: add thread unsafe async registration functions

 doc/guides/prog_guide/vhost_lib.rst |  12 +++
 lib/vhost/rte_vhost_async.h         |  42 ++++++++++
 lib/vhost/version.map               |   4 +
 lib/vhost/vhost.c                   | 161 +++++++++++++++++++++++++++---------
 lib/vhost/vhost_user.c              |   5 +-
 5 files changed, 180 insertions(+), 44 deletions(-)
#44 lore raw

Hi Jiayu,

Quoted 25 lines · Jiayu

Hi Maxime,

Quoted 23 lines

-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Friday, June 4, 2021 3:25 PM
To: Hu, Jiayu <[email protected]>; [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Wang, Yinan <[email protected]>
Subject: Re: [PATCH 0/2] provide thread unsafe async registration functions

Sorry, for previous blank reply.

Quoted 6 lines · Jiayu Hu

Lock protection is needed during the vhost notifies the application of device readiness, so the first patch is to add lock protection. After performing locking, existed async vhost registration functions will cause deadlock, as they acquire lock too. So the second patch is to provide unsafe registration functions to support calling within vhost callback functions.

I agree the callback should be always protected, and in that case having a new thread-unsafe API makes sense for async registration.

Regarding backport, I'm not sure what we should do.

Quoted 7 lines
Quoted 2 lines

Backporting new API is a no-go, but with only backporting patch 1 async feature will be always broken on 20.11 LTS, right?

Yes, if only backporting this fix patch to 20.11 LTS, it may break apps who call async registration functions inside vhost callbacks.

How about making this patch not a fix, but a new feature?

Async will be still broken in v20.11 in this case.
Maybe the better thing would be to remove async support in v20.11, as its support was quite limited in that release anyway. Does that make sense?

Thanks,
Maxime

Quoted 20 lines

Thanks,
Jiayu

Quoted 17 lines

What do you think?

Thanks,
Maxime

Quoted 11 lines

Jiayu Hu (2):
vhost: fix lock on device readiness notification
vhost: add thread unsafe async registration functions

 doc/guides/prog_guide/vhost_lib.rst |  12 +++
 lib/vhost/rte_vhost_async.h         |  42 ++++++++++
 lib/vhost/version.map               |   4 +
 lib/vhost/vhost.c                   | 161 +++++++++++++++++++++++++++---------
 lib/vhost/vhost_user.c              |   5 +-
 5 files changed, 180 insertions(+), 44 deletions(-)
author
#45 lore raw
Quoted 44 lines

-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Monday, June 7, 2021 9:20 PM
To: Hu, Jiayu <[email protected]>; [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Wang, Yinan <[email protected]>
Subject: Re: [PATCH 0/2] provide thread unsafe async registration functions

Hi Jiayu,

Quoted 9 lines · Jiayu

Hi Maxime,

Quoted 7 lines

-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Friday, June 4, 2021 3:25 PM
To: Hu, Jiayu <[email protected]>; [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Wang, Yinan <[email protected]>
Subject: Re: [PATCH 0/2] provide thread unsafe async registration

functions

Quoted 14 lines
Quoted 14 lines

Sorry, for previous blank reply.

Quoted 6 lines · Jiayu Hu

Lock protection is needed during the vhost notifies the application of device readiness, so the first patch is to add lock protection. After performing locking, existed async vhost registration functions will cause deadlock, as they acquire lock too. So the second patch is to provide unsafe registration functions to support calling within vhost callback functions.

I agree the callback should be always protected, and in that case having a new thread-unsafe API makes sense for async registration.

Quoted 6 lines
Quoted 4 lines

Regarding backport, I'm not sure what we should do.

Backporting new API is a no-go, but with only backporting patch 1 async feature will be always broken on 20.11 LTS, right?

Yes, if only backporting this fix patch to 20.11 LTS, it may break apps who

call

Quoted 8 lines
Quoted 3 lines

async registration functions inside vhost callbacks.

How about making this patch not a fix, but a new feature?

Async will be still broken in v20.11 in this case.
Maybe the better thing would be to remove async support in v20.11, as its support was quite limited in that release anyway. Does that make sense?

OK, that makes sense to me.

Thanks,
Jiayu

Quoted 25 lines

Thanks,
Maxime

Quoted 16 lines

Thanks,
Jiayu

Quoted 14 lines

What do you think?

Thanks,
Maxime

Quoted 8 lines

Jiayu Hu (2):
vhost: fix lock on device readiness notification
vhost: add thread unsafe async registration functions

 doc/guides/prog_guide/vhost_lib.rst |  12 +++
 lib/vhost/rte_vhost_async.h         |  42 ++++++++++
 lib/vhost/version.map               |   4 +
 lib/vhost/vhost.c                   | 161 +++++++++++++++++++++++++++--------

-

Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
 lib/vhost/vhost_user.c              |   5 +-
 5 files changed, 180 insertions(+), 44 deletions(-)
author
#46 lore raw
In reply to Maxime Coquelin

Hi Maxime,

Quoted 40 lines

-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Monday, June 7, 2021 9:20 PM
To: Hu, Jiayu <[email protected]>; [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Wang, Yinan <[email protected]>
Subject: Re: [PATCH 0/2] provide thread unsafe async registration functions

Hi Jiayu,

Quoted 29 lines · Jiayu

Hi Maxime,

Quoted 26 lines

-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Friday, June 4, 2021 3:25 PM
To: Hu, Jiayu <[email protected]>; [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Wang, Yinan <[email protected]>
Subject: Re: [PATCH 0/2] provide thread unsafe async registration functions

Sorry, for previous blank reply.

Quoted 6 lines · Jiayu Hu

Lock protection is needed during the vhost notifies the application of device readiness, so the first patch is to add lock protection. After performing locking, existed async vhost registration functions will cause deadlock, as they acquire lock too. So the second patch is to provide unsafe registration functions to support calling within vhost callback functions.

I agree the callback should be always protected, and in that case having a new thread-unsafe API makes sense for async registration.

Regarding backport, I'm not sure what we should do.

Backporting new API is a no-go, but with only backporting patch 1 async feature will be always broken on 20.11 LTS, right?

Quoted 8 lines
Quoted 4 lines

Yes, if only backporting this fix patch to 20.11 LTS, it may break apps who call async registration functions inside vhost callbacks.

How about making this patch not a fix, but a new feature?

Async will be still broken in v20.11 in this case.
Maybe the better thing would be to remove async support in v20.11, as its support was quite limited in that release anyway. Does that make sense?

The code of supporting async vhost are beyond 1000 lines. I am afraid that removing such more code in 20.11 LTS may get objected. Can we note async register/unregister only work in new_/destroy_device, and using them in other vhost callback functions will cause deadlock in 20.11 LTS instead? Does it make sense to you?

Thanks,
Jiayu

Quoted 11 lines

Thanks,
Maxime

Quoted 7 lines

Thanks,
Jiayu

Quoted 5 lines

What do you think?

Thanks,
Maxime

#47 lore raw

Hi Jiayu,

Quoted 51 lines · Jiayu

Hi Maxime,

Quoted 40 lines

-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Monday, June 7, 2021 9:20 PM
To: Hu, Jiayu <[email protected]>; [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Wang, Yinan <[email protected]>
Subject: Re: [PATCH 0/2] provide thread unsafe async registration functions

Hi Jiayu,

Quoted 29 lines · Jiayu

Hi Maxime,

Quoted 26 lines

-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Friday, June 4, 2021 3:25 PM
To: Hu, Jiayu <[email protected]>; [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Wang, Yinan <[email protected]>
Subject: Re: [PATCH 0/2] provide thread unsafe async registration functions

Sorry, for previous blank reply.

Quoted 6 lines · Jiayu Hu

Lock protection is needed during the vhost notifies the application of device readiness, so the first patch is to add lock protection. After performing locking, existed async vhost registration functions will cause deadlock, as they acquire lock too. So the second patch is to provide unsafe registration functions to support calling within vhost callback functions.

I agree the callback should be always protected, and in that case having a new thread-unsafe API makes sense for async registration.

Regarding backport, I'm not sure what we should do.

Backporting new API is a no-go, but with only backporting patch 1 async feature will be always broken on 20.11 LTS, right?

Quoted 8 lines
Quoted 4 lines

Yes, if only backporting this fix patch to 20.11 LTS, it may break apps who call async registration functions inside vhost callbacks.

How about making this patch not a fix, but a new feature?

Async will be still broken in v20.11 in this case.
Maybe the better thing would be to remove async support in v20.11, as its support was quite limited in that release anyway. Does that make sense?

Quoted 5 lines

The code of supporting async vhost are beyond 1000 lines. I am afraid that removing such more code in 20.11 LTS may get objected. Can we note async register/unregister only work in new_/destroy_device, and using them in other vhost callback functions will cause deadlock in 20.11 LTS instead? Does it make sense to you?

You are right, that removing 1L LoC in LTS might not be the best idea, since it will cause conflicts when doing backports later on.

Maybe the best way is to return -1 at async registration time, with logging an error?

Thanks,
Maxime

Quoted 14 lines

Thanks,
Jiayu

Quoted 11 lines

Thanks,
Maxime

Quoted 7 lines

Thanks,
Jiayu

Quoted 5 lines

What do you think?

Thanks,
Maxime

author
#48 lore raw
Quoted 73 lines

-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Thursday, July 1, 2021 11:43 PM
To: Hu, Jiayu <[email protected]>; Maxime Coquelin <[email protected]>; [email protected]
Cc: Xia, Chenbo <[email protected]>; Wang, Yinan <[email protected]>; David Marchand <[email protected]>
Subject: Re: [PATCH 0/2] provide thread unsafe async registration functions

Hi Jiayu,

Quoted 21 lines · Jiayu

Hi Maxime,

Quoted 19 lines

-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Monday, June 7, 2021 9:20 PM
To: Hu, Jiayu <[email protected]>; [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Wang, Yinan <[email protected]>
Subject: Re: [PATCH 0/2] provide thread unsafe async registration functions

Hi Jiayu,

Quoted 7 lines · Jiayu

Hi Maxime,

Quoted 5 lines

-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Friday, June 4, 2021 3:25 PM
To: Hu, Jiayu <[email protected]>; [email protected]
Cc: [email protected]; Xia, Chenbo

<[email protected]>;

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Wang, Yinan <[email protected]>
Subject: Re: [PATCH 0/2] provide thread unsafe async registration functions

Sorry, for previous blank reply.

Quoted 2 lines · Jiayu Hu

Lock protection is needed during the vhost notifies the application of device readiness, so the first patch is to add lock

protection.

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 4 lines

After performing locking, existed async vhost registration functions will cause deadlock, as they acquire lock too. So the second patch is to provide unsafe registration functions to support calling within vhost callback functions.

I agree the callback should be always protected, and in that case having a new thread-unsafe API makes sense for async registration.

Regarding backport, I'm not sure what we should do.

Backporting new API is a no-go, but with only backporting patch 1 async feature will be always broken on 20.11 LTS, right?

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

Yes, if only backporting this fix patch to 20.11 LTS, it may break apps who call async registration functions inside vhost callbacks.

How about making this patch not a fix, but a new feature?

Async will be still broken in v20.11 in this case.
Maybe the better thing would be to remove async support in v20.11, as its support was quite limited in that release anyway. Does that make

sense?

Quoted 5 lines

The code of supporting async vhost are beyond 1000 lines. I am afraid that removing such more code in 20.11 LTS may get objected. Can we note async register/unregister only work in new_/destroy_device, and using them in other vhost callback functions will cause deadlock in 20.11

Quoted 8 lines

LTS instead?

Quoted 1 line

Does it make sense to you?

You are right, that removing 1L LoC in LTS might not be the best idea, since it will cause conflicts when doing backports later on.

Maybe the best way is to return -1 at async registration time, with logging an error?

OK.

Thanks,
Jiayu

Quoted 18 lines

Thanks,
Maxime

Quoted 14 lines

Thanks,
Jiayu

Quoted 11 lines

Thanks,
Maxime

Quoted 7 lines

Thanks,
Jiayu

Quoted 5 lines

What do you think?

Thanks,
Maxime