linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next V2 0/3] basic in order support for vhost_net
@ 2019-01-09  8:05 Jason Wang
  2019-01-09  8:05 ` [PATCH net-next V2 1/3] virtio: introduce in order feature bit Jason Wang
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Jason Wang @ 2019-01-09  8:05 UTC (permalink / raw)
  To: mst, jasowang; +Cc: kvm, virtualization, netdev, linux-kernel

Hi:

This series implement basic in order feature support for
vhost_net. This feature requires both driver and device to use
descriptors in order which can simplify the implementation and
optimizaton for both side. The series also implement a simple
optimization that avoid read available ring. Test shows 10%
performance improvement at most.

More optimizations could be done on top.

Changes from V1:
- no code changes
- add result of SMAP off

Jason Wang (3):
  virtio: introduce in order feature bit
  vhost_net: support in order feature
  vhost: don't touch avail ring if in_order is negotiated

 drivers/vhost/net.c                |  6 ++++--
 drivers/vhost/vhost.c              | 19 ++++++++++++-------
 include/uapi/linux/virtio_config.h |  6 ++++++
 3 files changed, 22 insertions(+), 9 deletions(-)

-- 
2.17.1


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

* [PATCH net-next V2 1/3] virtio: introduce in order feature bit
  2019-01-09  8:05 [PATCH net-next V2 0/3] basic in order support for vhost_net Jason Wang
@ 2019-01-09  8:05 ` Jason Wang
  2019-01-09 14:27   ` Michael S. Tsirkin
  2019-01-09  8:05 ` [PATCH net-next V2 2/3] vhost_net: support in order feature Jason Wang
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Jason Wang @ 2019-01-09  8:05 UTC (permalink / raw)
  To: mst, jasowang; +Cc: kvm, virtualization, netdev, linux-kernel

Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 include/uapi/linux/virtio_config.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/include/uapi/linux/virtio_config.h b/include/uapi/linux/virtio_config.h
index 1196e1c1d4f6..2698e069ed9e 100644
--- a/include/uapi/linux/virtio_config.h
+++ b/include/uapi/linux/virtio_config.h
@@ -78,6 +78,12 @@
 /* This feature indicates support for the packed virtqueue layout. */
 #define VIRTIO_F_RING_PACKED		34
 
+/*
+ * Device uses buffers in the same order in which they have been
+ * available.
+ */
+#define VIRTIO_F_IN_ORDER		35
+
 /*
  * Does the device support Single Root I/O Virtualization?
  */
-- 
2.17.1


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

* [PATCH net-next V2 2/3] vhost_net: support in order feature
  2019-01-09  8:05 [PATCH net-next V2 0/3] basic in order support for vhost_net Jason Wang
  2019-01-09  8:05 ` [PATCH net-next V2 1/3] virtio: introduce in order feature bit Jason Wang
@ 2019-01-09  8:05 ` Jason Wang
  2019-01-09  8:05 ` [PATCH net-next V2 3/3] vhost: don't touch avail ring if in_order is negotiated Jason Wang
  2019-01-09 12:19 ` [PATCH net-next V2 0/3] basic in order support for vhost_net Jason Wang
  3 siblings, 0 replies; 6+ messages in thread
From: Jason Wang @ 2019-01-09  8:05 UTC (permalink / raw)
  To: mst, jasowang; +Cc: kvm, virtualization, netdev, linux-kernel

This makes vhost_net to support in order feature. This is as simple as
use datacopy path when it was negotiated. An alternative is not to
advertise in order when zerocopy is enabled which tends to be
suboptimal consider zerocopy may suffer from e.g HOL issues.

Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 drivers/vhost/net.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index 36f3d0f49e60..0870f51a1c76 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -74,7 +74,8 @@ enum {
 	VHOST_NET_FEATURES = VHOST_FEATURES |
 			 (1ULL << VHOST_NET_F_VIRTIO_NET_HDR) |
 			 (1ULL << VIRTIO_NET_F_MRG_RXBUF) |
-			 (1ULL << VIRTIO_F_IOMMU_PLATFORM)
+			 (1ULL << VIRTIO_F_IOMMU_PLATFORM) |
+	                 (1ULL << VIRTIO_F_IN_ORDER)
 };
 
 enum {
@@ -977,7 +978,8 @@ static void handle_tx(struct vhost_net *net)
 	vhost_disable_notify(&net->dev, vq);
 	vhost_net_disable_vq(net, vq);
 
-	if (vhost_sock_zcopy(sock))
+	if (vhost_sock_zcopy(sock) &&
+	    !vhost_has_feature(vq, VIRTIO_F_IN_ORDER))
 		handle_tx_zerocopy(net, sock);
 	else
 		handle_tx_copy(net, sock);
-- 
2.17.1


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

* [PATCH net-next V2 3/3] vhost: don't touch avail ring if in_order is negotiated
  2019-01-09  8:05 [PATCH net-next V2 0/3] basic in order support for vhost_net Jason Wang
  2019-01-09  8:05 ` [PATCH net-next V2 1/3] virtio: introduce in order feature bit Jason Wang
  2019-01-09  8:05 ` [PATCH net-next V2 2/3] vhost_net: support in order feature Jason Wang
@ 2019-01-09  8:05 ` Jason Wang
  2019-01-09 12:19 ` [PATCH net-next V2 0/3] basic in order support for vhost_net Jason Wang
  3 siblings, 0 replies; 6+ messages in thread
From: Jason Wang @ 2019-01-09  8:05 UTC (permalink / raw)
  To: mst, jasowang; +Cc: kvm, virtualization, netdev, linux-kernel

Device use descriptors table in order, so there's no need to read
index from available ring. This eliminate the cache contention on
available ring completely.

Virito-user + vhost_kernel + XDP_DROP on 2.60GHz Broadwell

            Before /After
SMAP on:  4.8Mpps   5.3Mpps(+10%)
SMAP off: 6.6Mpps   7.0Mpps(+6%)

Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 drivers/vhost/vhost.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 55e5aa662ad5..ab0d05262235 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -2012,6 +2012,7 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,
 	__virtio16 avail_idx;
 	__virtio16 ring_head;
 	int ret, access;
+	bool in_order = vhost_has_feature(vq, VIRTIO_F_IN_ORDER);
 
 	/* Check it isn't doing very strange things with descriptor numbers. */
 	last_avail_idx = vq->last_avail_idx;
@@ -2044,15 +2045,19 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,
 
 	/* Grab the next descriptor number they're advertising, and increment
 	 * the index we've seen. */
-	if (unlikely(vhost_get_avail(vq, ring_head,
-		     &vq->avail->ring[last_avail_idx & (vq->num - 1)]))) {
-		vq_err(vq, "Failed to read head: idx %d address %p\n",
-		       last_avail_idx,
-		       &vq->avail->ring[last_avail_idx % vq->num]);
-		return -EFAULT;
+	if (!in_order) {
+		if (unlikely(vhost_get_avail(vq, ring_head,
+		    &vq->avail->ring[last_avail_idx & (vq->num - 1)]))) {
+			vq_err(vq, "Failed to read head: idx %d address %p\n",
+				last_avail_idx,
+				&vq->avail->ring[last_avail_idx % vq->num]);
+			return -EFAULT;
+		}
+		head = vhost16_to_cpu(vq, ring_head);
+	} else {
+		head = last_avail_idx & (vq->num - 1);
 	}
 
-	head = vhost16_to_cpu(vq, ring_head);
 
 	/* If their number is silly, that's an error. */
 	if (unlikely(head >= vq->num)) {
-- 
2.17.1


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

* Re: [PATCH net-next V2 0/3] basic in order support for vhost_net
  2019-01-09  8:05 [PATCH net-next V2 0/3] basic in order support for vhost_net Jason Wang
                   ` (2 preceding siblings ...)
  2019-01-09  8:05 ` [PATCH net-next V2 3/3] vhost: don't touch avail ring if in_order is negotiated Jason Wang
@ 2019-01-09 12:19 ` Jason Wang
  3 siblings, 0 replies; 6+ messages in thread
From: Jason Wang @ 2019-01-09 12:19 UTC (permalink / raw)
  To: mst; +Cc: kvm, virtualization, netdev, linux-kernel


On 2019/1/9 下午4:05, Jason Wang wrote:
> Hi:
>
> This series implement basic in order feature support for
> vhost_net. This feature requires both driver and device to use
> descriptors in order which can simplify the implementation and
> optimizaton for both side. The series also implement a simple
> optimization that avoid read available ring. Test shows 10%
> performance improvement at most.
>
> More optimizations could be done on top.
>
> Changes from V1:
> - no code changes
> - add result of SMAP off


Just notice the patch works only for some specific case e.g a buffer 
only contain one descriptor. Will respin.

Thanks


>
> Jason Wang (3):
>    virtio: introduce in order feature bit
>    vhost_net: support in order feature
>    vhost: don't touch avail ring if in_order is negotiated
>
>   drivers/vhost/net.c                |  6 ++++--
>   drivers/vhost/vhost.c              | 19 ++++++++++++-------
>   include/uapi/linux/virtio_config.h |  6 ++++++
>   3 files changed, 22 insertions(+), 9 deletions(-)
>

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

* Re: [PATCH net-next V2 1/3] virtio: introduce in order feature bit
  2019-01-09  8:05 ` [PATCH net-next V2 1/3] virtio: introduce in order feature bit Jason Wang
@ 2019-01-09 14:27   ` Michael S. Tsirkin
  0 siblings, 0 replies; 6+ messages in thread
From: Michael S. Tsirkin @ 2019-01-09 14:27 UTC (permalink / raw)
  To: Jason Wang; +Cc: kvm, virtualization, netdev, linux-kernel

On Wed, Jan 09, 2019 at 04:05:28PM +0800, Jason Wang wrote:
> Signed-off-by: Jason Wang <jasowang@redhat.com>
> ---
>  include/uapi/linux/virtio_config.h | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/include/uapi/linux/virtio_config.h b/include/uapi/linux/virtio_config.h
> index 1196e1c1d4f6..2698e069ed9e 100644
> --- a/include/uapi/linux/virtio_config.h
> +++ b/include/uapi/linux/virtio_config.h
> @@ -78,6 +78,12 @@
>  /* This feature indicates support for the packed virtqueue layout. */
>  #define VIRTIO_F_RING_PACKED		34
>  
> +/*
> + * Device uses buffers in the same order in which they have been
> + * available.

been *made* available

> + */
> +#define VIRTIO_F_IN_ORDER		35
> +
>  /*
>   * Does the device support Single Root I/O Virtualization?
>   */
> -- 
> 2.17.1

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

end of thread, other threads:[~2019-01-09 14:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-09  8:05 [PATCH net-next V2 0/3] basic in order support for vhost_net Jason Wang
2019-01-09  8:05 ` [PATCH net-next V2 1/3] virtio: introduce in order feature bit Jason Wang
2019-01-09 14:27   ` Michael S. Tsirkin
2019-01-09  8:05 ` [PATCH net-next V2 2/3] vhost_net: support in order feature Jason Wang
2019-01-09  8:05 ` [PATCH net-next V2 3/3] vhost: don't touch avail ring if in_order is negotiated Jason Wang
2019-01-09 12:19 ` [PATCH net-next V2 0/3] basic in order support for vhost_net Jason Wang

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