DPDK patches and discussions
 help / color / mirror / Atom feed
From: Maxime Coquelin <maxime.coquelin@redhat.com>
To: tiwei.bie@intel.com, zhihong.wang@intel.com,
	jfreimann@redhat.com, dev@dpdk.org
Cc: mst@redhat.com, jasowang@redhat.com, wexu@redhat.com,
	Maxime Coquelin <maxime.coquelin@redhat.com>
Subject: [dpdk-dev] [PATCH v5 14/15] vhost: add notification for packed ring
Date: Fri, 22 Jun 2018 15:43:26 +0200	[thread overview]
Message-ID: <20180622134327.18973-15-maxime.coquelin@redhat.com> (raw)
In-Reply-To: <20180622134327.18973-1-maxime.coquelin@redhat.com>

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 lib/librte_vhost/vhost.c         | 55 +++++++++++++++++++++++++++----
 lib/librte_vhost/vhost.h         | 71 ++++++++++++++++++++++++++++++++++++----
 lib/librte_vhost/vhost_user.c    | 29 +++++++++++++---
 lib/librte_vhost/virtio-packed.h | 11 +++++++
 lib/librte_vhost/virtio_net.c    | 12 +++----
 5 files changed, 154 insertions(+), 24 deletions(-)

diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c
index 7cbf1eded..c26162542 100644
--- a/lib/librte_vhost/vhost.c
+++ b/lib/librte_vhost/vhost.c
@@ -595,7 +595,11 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx)
 	if (!vq)
 		return -1;
 
-	vhost_vring_call(dev, vq);
+	if (vq_is_packed(dev))
+		vhost_vring_call_packed(dev, vq);
+	else
+		vhost_vring_call_split(dev, vq);
+
 	return 0;
 }
 
@@ -616,20 +620,59 @@ rte_vhost_avail_entries(int vid, uint16_t queue_id)
 	return *(volatile uint16_t *)&vq->avail->idx - vq->last_used_idx;
 }
 
+static inline int
+vhost_enable_notify_split(struct vhost_virtqueue *vq, int enable)
+{
+	if (enable)
+		vq->used->flags &= ~VRING_USED_F_NO_NOTIFY;
+	else
+		vq->used->flags |= VRING_USED_F_NO_NOTIFY;
+
+	return 0;
+}
+
+static inline int
+vhost_enable_notify_packed(struct virtio_net *dev,
+		struct vhost_virtqueue *vq, int enable)
+{
+	uint16_t flags;
+
+	if (!enable) {
+		vq->device_event->desc_event_flags = RING_EVENT_FLAGS_DISABLE;
+		return 0;
+	}
+
+	flags = RING_EVENT_FLAGS_DISABLE;
+	if (dev->features & (1ULL << VIRTIO_RING_F_EVENT_IDX)) {
+		flags = RING_EVENT_FLAGS_DESC;
+		vq->device_event->desc_event_off_wrap = vq->last_avail_idx |
+			vq->avail_wrap_counter << 15;
+	}
+
+	rte_smp_wmb();
+
+	vq->device_event->desc_event_flags = flags;
+
+	rte_smp_wmb();
+
+	return 0;
+}
+
 int
 rte_vhost_enable_guest_notification(int vid, uint16_t queue_id, int enable)
 {
 	struct virtio_net *dev = get_device(vid);
+	struct vhost_virtqueue *vq;
 
 	if (!dev)
 		return -1;
 
-	if (enable)
-		dev->virtqueue[queue_id]->used->flags &=
-			~VRING_USED_F_NO_NOTIFY;
+	vq = dev->virtqueue[queue_id];
+
+	if (vq_is_packed(dev))
+		return vhost_enable_notify_packed(dev, vq, enable);
 	else
-		dev->virtqueue[queue_id]->used->flags |= VRING_USED_F_NO_NOTIFY;
-	return 0;
+		return vhost_enable_notify_split(vq, enable);
 }
 
 void
diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h
index 5dcb61c71..99db688a8 100644
--- a/lib/librte_vhost/vhost.h
+++ b/lib/librte_vhost/vhost.h
@@ -21,6 +21,7 @@
 
 #include "rte_vhost.h"
 #include "rte_vdpa.h"
+#include "virtio-packed.h"
 
 /* Used to indicate that the device is running on a data core */
 #define VIRTIO_DEV_RUNNING 1
@@ -95,8 +96,14 @@ struct vhost_virtqueue {
 		struct vring_desc	*desc;
 		struct vring_desc_packed   *desc_packed;
 	};
-	struct vring_avail	*avail;
-	struct vring_used	*used;
+	union {
+		struct vring_avail	*avail;
+		struct vring_packed_desc_event *driver_event;
+	};
+	union {
+		struct vring_used	*used;
+		struct vring_packed_desc_event *device_event;
+	};
 	uint32_t		size;
 
 	uint16_t		last_avail_idx;
@@ -614,7 +621,7 @@ vhost_need_event(uint16_t event_idx, uint16_t new_idx, uint16_t old)
 }
 
 static __rte_always_inline void
-vhost_vring_call(struct virtio_net *dev, struct vhost_virtqueue *vq)
+vhost_vring_call_split(struct virtio_net *dev, struct vhost_virtqueue *vq)
 {
 	/* Flush used->idx update before we read avail->flags. */
 	rte_mb();
@@ -625,11 +632,11 @@ vhost_vring_call(struct virtio_net *dev, struct vhost_virtqueue *vq)
 		uint16_t new = vq->last_used_idx;
 
 		VHOST_LOG_DEBUG(VHOST_DATA, "%s: used_event_idx=%d, old=%d, new=%d\n",
-			__func__,
-			vhost_used_event(vq),
-			old, new);
+				__func__,
+				vhost_used_event(vq),
+				old, new);
 		if (vhost_need_event(vhost_used_event(vq), new, old)
-			&& (vq->callfd >= 0)) {
+				&& (vq->callfd >= 0)) {
 			vq->signalled_used = vq->last_used_idx;
 			eventfd_write(vq->callfd, (eventfd_t) 1);
 		}
@@ -641,4 +648,54 @@ vhost_vring_call(struct virtio_net *dev, struct vhost_virtqueue *vq)
 	}
 }
 
+static __rte_always_inline void
+vhost_vring_call_packed(struct virtio_net *dev, struct vhost_virtqueue *vq)
+{
+	uint16_t old, new, off, off_wrap, wrap;
+	bool kick = false;
+
+
+	/*  Flush used desc update. */
+	rte_smp_mb();
+
+	if (!(dev->features & (1ULL << VIRTIO_RING_F_EVENT_IDX))) {
+		if (vq->driver_event->desc_event_flags !=
+				RING_EVENT_FLAGS_DISABLE)
+			kick = true;
+		goto kick;
+	}
+
+	old = vq->signalled_used;
+	new = vq->last_used_idx;
+	vq->signalled_used = new;
+
+	if (vq->driver_event->desc_event_flags != RING_EVENT_FLAGS_DESC) {
+		if (vq->driver_event->desc_event_flags !=
+				RING_EVENT_FLAGS_DISABLE)
+			kick = true;
+		goto kick;
+	}
+
+	rte_smp_rmb();
+
+	off_wrap = vq->driver_event->desc_event_off_wrap;
+	off = off_wrap & ~(1 << 15);
+	wrap = vq->used_wrap_counter;
+
+	if (new < old) {
+		new += vq->size;
+		wrap ^= 1;
+	}
+
+	if (wrap != off_wrap >> 15)
+		off += vq->size;
+
+	if (vhost_need_event(off, new, old))
+		kick = true;
+
+kick:
+	if (kick)
+		eventfd_write(vq->callfd, (eventfd_t)1);
+}
+
 #endif /* _VHOST_NET_CDEV_H_ */
diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c
index a08d99314..c74924564 100644
--- a/lib/librte_vhost/vhost_user.c
+++ b/lib/librte_vhost/vhost_user.c
@@ -509,9 +509,6 @@ translate_ring_addresses(struct virtio_net *dev, int vq_index)
 		len = sizeof(struct vring_desc_packed) * vq->size;
 		vq->desc_packed = (struct vring_desc_packed *) ring_addr_to_vva
 			(dev, vq, addr->desc_user_addr, &len);
-		vq->desc = NULL;
-		vq->avail = NULL;
-		vq->used = NULL;
 		vq->log_guest_addr = 0;
 		if (vq->desc_packed == 0 ||
 				len != sizeof(struct vring_desc_packed) *
@@ -526,6 +523,30 @@ translate_ring_addresses(struct virtio_net *dev, int vq_index)
 		vq = dev->virtqueue[vq_index];
 		addr = &vq->ring_addrs;
 
+		len = sizeof(struct vring_packed_desc_event);
+		vq->driver_event = (struct vring_packed_desc_event *)
+					(uintptr_t)ring_addr_to_vva(dev,
+					vq, addr->avail_user_addr, &len);
+		if (vq->driver_event == 0 ||
+				len != sizeof(struct vring_packed_desc_event)) {
+			RTE_LOG(DEBUG, VHOST_CONFIG,
+				"(%d) failed to find driver area address.\n",
+				dev->vid);
+			return dev;
+		}
+
+		len = sizeof(struct vring_packed_desc_event);
+		vq->device_event = (struct vring_packed_desc_event *)
+					(uintptr_t)ring_addr_to_vva(dev,
+					vq, addr->used_user_addr, &len);
+		if (vq->device_event == 0 ||
+				len != sizeof(struct vring_packed_desc_event)) {
+			RTE_LOG(DEBUG, VHOST_CONFIG,
+				"(%d) failed to find device area address.\n",
+				dev->vid);
+			return dev;
+		}
+
 		return dev;
 	}
 
@@ -542,8 +563,6 @@ translate_ring_addresses(struct virtio_net *dev, int vq_index)
 			dev->vid);
 		return dev;
 	}
-	vq->desc_packed = NULL;
-
 	dev = numa_realloc(dev, vq_index);
 	vq = dev->virtqueue[vq_index];
 	addr = &vq->ring_addrs;
diff --git a/lib/librte_vhost/virtio-packed.h b/lib/librte_vhost/virtio-packed.h
index 21fe5045b..f271249d8 100644
--- a/lib/librte_vhost/virtio-packed.h
+++ b/lib/librte_vhost/virtio-packed.h
@@ -19,6 +19,17 @@ struct vring_desc_packed {
 	uint16_t flags;
 };
 
+#define RING_EVENT_FLAGS_ENABLE 0x0
+#define RING_EVENT_FLAGS_DISABLE 0x1
+#define RING_EVENT_FLAGS_DESC 0x2
+#define RING_EVENT_FLAGS_MASK 0xFFFC
+#define RING_EVENT_WRAP_MASK 0x8000
+#define RING_EVENT_OFF_MASK 0x7FFF
+
+struct vring_packed_desc_event {
+	uint16_t desc_event_off_wrap;
+	uint16_t desc_event_flags;
+};
 
 static inline int
 desc_is_avail(struct vring_desc_packed *desc, uint16_t wrap_counter)
diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c
index b9f49175c..9e8c9969b 100644
--- a/lib/librte_vhost/virtio_net.c
+++ b/lib/librte_vhost/virtio_net.c
@@ -822,7 +822,7 @@ virtio_dev_rx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
 
 	if (likely(vq->shadow_used_idx)) {
 		flush_shadow_used_ring_split(dev, vq);
-		vhost_vring_call(dev, vq);
+		vhost_vring_call_split(dev, vq);
 	}
 
 	return pkt_idx;
@@ -875,7 +875,7 @@ virtio_dev_rx_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,
 
 	if (likely(vq->shadow_used_idx)) {
 		flush_shadow_used_ring_packed(dev, vq);
-		vhost_vring_call(dev, vq);
+		vhost_vring_call_packed(dev, vq);
 	}
 
 	return pkt_idx;
@@ -1358,7 +1358,7 @@ virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
 		}
 
 		flush_shadow_used_ring_split(dev, vq);
-		vhost_vring_call(dev, vq);
+		vhost_vring_call_split(dev, vq);
 	}
 
 	rte_prefetch0(&vq->avail->ring[vq->last_avail_idx & (vq->size - 1)]);
@@ -1437,7 +1437,7 @@ virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
 		if (unlikely(i < count))
 			vq->shadow_used_idx = i;
 		flush_shadow_used_ring_split(dev, vq);
-		vhost_vring_call(dev, vq);
+		vhost_vring_call_split(dev, vq);
 	}
 
 	return i;
@@ -1475,7 +1475,7 @@ virtio_dev_tx_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,
 		}
 
 		flush_shadow_used_ring_packed(dev, vq);
-		vhost_vring_call(dev, vq);
+		vhost_vring_call_packed(dev, vq);
 	}
 
 	VHOST_LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->vid, __func__);
@@ -1553,7 +1553,7 @@ virtio_dev_tx_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,
 		if (unlikely(i < count))
 			vq->shadow_used_idx = i;
 		flush_shadow_used_ring_packed(dev, vq);
-		vhost_vring_call(dev, vq);
+		vhost_vring_call_packed(dev, vq);
 	}
 
 	return i;
-- 
2.14.4

  parent reply	other threads:[~2018-06-22 13:44 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-22 13:43 [dpdk-dev] [PATCH v5 00/15] Vhost: add support to packed ring layout Maxime Coquelin
2018-06-22 13:43 ` [dpdk-dev] [PATCH v5 01/15] vhost: add virtio packed virtqueue defines Maxime Coquelin
2018-06-29 15:47   ` Tiwei Bie
2018-06-29 16:20     ` Maxime Coquelin
2018-06-22 13:43 ` [dpdk-dev] [PATCH v5 02/15] vhost: add helpers for packed virtqueues Maxime Coquelin
2018-06-29 15:51   ` Tiwei Bie
2018-06-29 16:21     ` Maxime Coquelin
2018-06-22 13:43 ` [dpdk-dev] [PATCH v5 03/15] vhost: vring address setup for packed queues Maxime Coquelin
2018-06-29 15:59   ` Tiwei Bie
2018-06-29 16:34     ` Maxime Coquelin
2018-06-30  2:18       ` Tiwei Bie
2018-07-01  9:58     ` Maxime Coquelin
2018-06-22 13:43 ` [dpdk-dev] [PATCH v5 04/15] vhost: clear shadow used table index at flush time Maxime Coquelin
2018-06-22 13:43 ` [dpdk-dev] [PATCH v5 05/15] vhost: make indirect desc table copy desc type agnostic Maxime Coquelin
2018-06-22 13:43 ` [dpdk-dev] [PATCH v5 06/15] vhost: clear batch copy index at copy time Maxime Coquelin
2018-06-22 13:43 ` [dpdk-dev] [PATCH v5 07/15] vhost: extract split ring handling from Rx and Tx functions Maxime Coquelin
2018-06-22 13:43 ` [dpdk-dev] [PATCH v5 08/15] vhost: append shadow used ring function names with split Maxime Coquelin
2018-06-22 13:43 ` [dpdk-dev] [PATCH v5 09/15] vhost: add shadow used ring support for packed rings Maxime Coquelin
2018-06-29 16:08   ` Tiwei Bie
2018-06-22 13:43 ` [dpdk-dev] [PATCH v5 10/15] vhost: create descriptor mapping function Maxime Coquelin
2018-06-22 13:43 ` [dpdk-dev] [PATCH v5 11/15] vhost: add vector filling support for packed ring Maxime Coquelin
2018-06-22 13:43 ` [dpdk-dev] [PATCH v5 12/15] vhost: add Rx " Maxime Coquelin
2018-06-22 13:43 ` [dpdk-dev] [PATCH v5 13/15] vhost: add Tx " Maxime Coquelin
2018-06-22 13:43 ` Maxime Coquelin [this message]
2018-06-29 16:22   ` [dpdk-dev] [PATCH v5 14/15] vhost: add notification " Tiwei Bie
2018-06-22 13:43 ` [dpdk-dev] [PATCH v5 15/15] vhost: advertize packed ring layout support Maxime Coquelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180622134327.18973-15-maxime.coquelin@redhat.com \
    --to=maxime.coquelin@redhat.com \
    --cc=dev@dpdk.org \
    --cc=jasowang@redhat.com \
    --cc=jfreimann@redhat.com \
    --cc=mst@redhat.com \
    --cc=tiwei.bie@intel.com \
    --cc=wexu@redhat.com \
    --cc=zhihong.wang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).