DPDK patches and discussions
 help / color / mirror / Atom feed
* Re: [dpdk-dev] [PATCH v2] vhost: support virtqueue interrupt/notification suppression
  2017-11-28  9:48 [dpdk-dev] [PATCH v2] vhost: support virtqueue interrupt/notification suppression junjie.j.chen
@ 2017-11-28  2:46 ` Tiwei Bie
  0 siblings, 0 replies; 2+ messages in thread
From: Tiwei Bie @ 2017-11-28  2:46 UTC (permalink / raw)
  To: junjie.j.chen; +Cc: yliu, maxime.coquelin, jianfeng.tan, dev

Hi,

On Tue, Nov 28, 2017 at 04:48:26AM -0500, junjie.j.chen@intel.com wrote:
[...]
> @@ -195,6 +197,10 @@ struct vhost_msg {
>  
>  #define VHOST_USER_F_PROTOCOL_FEATURES	30
>  
> +#ifndef VIRTIO_F_EVENT_IDX
> + #define VIRTIO_F_EVENT_IDX 29
> +#endif
> +
>  /* Features supported by this builtin vhost-user net driver. */
>  #define VIRTIO_NET_SUPPORTED_FEATURES ((1ULL << VIRTIO_NET_F_MRG_RXBUF) | \
>  				(1ULL << VIRTIO_NET_F_CTRL_VQ) | \
> @@ -212,7 +218,8 @@ struct vhost_msg {
>  				(1ULL << VIRTIO_NET_F_GUEST_TSO6) | \
>  				(1ULL << VIRTIO_RING_F_INDIRECT_DESC) | \
>  				(1ULL << VIRTIO_NET_F_MTU) | \
> -				(1ULL << VIRTIO_F_IOMMU_PLATFORM))
> +				(1ULL << VIRTIO_F_IOMMU_PLATFORM) | \
> +				(1ULL << VIRTIO_F_EVENT_IDX))
>  

You can use VIRTIO_RING_F_EVENT_IDX directly. It has already
been defined by Linux. And you can add this new feature bit
after VIRTIO_RING_F_INDIRECT_DESC:

diff --git i/lib/librte_vhost/vhost.h w/lib/librte_vhost/vhost.h
index 2f36a034e..350ac3acc 100644
--- i/lib/librte_vhost/vhost.h
+++ w/lib/librte_vhost/vhost.h
@@ -211,6 +211,7 @@ struct vhost_msg {
 				(1ULL << VIRTIO_NET_F_GUEST_TSO4) | \
 				(1ULL << VIRTIO_NET_F_GUEST_TSO6) | \
 				(1ULL << VIRTIO_RING_F_INDIRECT_DESC) | \
+				(1ULL << VIRTIO_RING_F_EVENT_IDX) | \
 				(1ULL << VIRTIO_NET_F_MTU) | \
 				(1ULL << VIRTIO_F_IOMMU_PLATFORM))

Best regards,
Tiwei

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

* [dpdk-dev] [PATCH v2] vhost: support virtqueue interrupt/notification suppression
@ 2017-11-28  9:48 junjie.j.chen
  2017-11-28  2:46 ` Tiwei Bie
  0 siblings, 1 reply; 2+ messages in thread
From: junjie.j.chen @ 2017-11-28  9:48 UTC (permalink / raw)
  To: yliu, maxime.coquelin, tiwei.bie, jianfeng.tan, dev; +Cc: Junjie Chen

From: Junjie Chen <junjie.j.chen@intel.com>

The driver can suppress interrupt when VIRTIO_F_EVENT_IDX feature bit is
negotiated. The driver set vring flags to 0, and MAY use used_event in
available ring to advise device interrupt util reach an index specified
by used_event. The device ignore the lower bit of vring flags, and send
an interrupt when index reach used_event.

The device can suppress notification in a manner analogous to the ways
driver suppress interrupt. The device manipulates flags or avail_event in
the used ringin the same way the driver manipulates flags or used_event in
available ring.

This patch is to enable this feature in vhost.

Signed-off-by: Junjie Chen <junjie.j.chen@intel.com>
---
 lib/librte_vhost/Makefile     |  1 +
 lib/librte_vhost/vhost.h      |  9 ++++++-
 lib/librte_vhost/virtio_net.c | 56 +++++++++++++++++++++++++++++++------------
 3 files changed, 50 insertions(+), 16 deletions(-)

diff --git a/lib/librte_vhost/Makefile b/lib/librte_vhost/Makefile
index be182798a..85695d443 100644
--- a/lib/librte_vhost/Makefile
+++ b/lib/librte_vhost/Makefile
@@ -40,6 +40,7 @@ LIBABIVER := 4
 
 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3 -D_FILE_OFFSET_BITS=64
 CFLAGS += -I vhost_user
+CFLAGS += -fno-strict-aliasing
 LDLIBS += -lpthread
 
 ifeq ($(CONFIG_RTE_LIBRTE_VHOST_NUMA),y)
diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h
index 1cc81c17c..b0a955f64 100644
--- a/lib/librte_vhost/vhost.h
+++ b/lib/librte_vhost/vhost.h
@@ -103,6 +103,8 @@ struct vhost_virtqueue {
 
 	uint16_t		last_avail_idx;
 	uint16_t		last_used_idx;
+	/* Last used index we notify to front end. */
+	uint16_t		signalled_used;
 #define VIRTIO_INVALID_EVENTFD		(-1)
 #define VIRTIO_UNINITIALIZED_EVENTFD	(-2)
 
@@ -195,6 +197,10 @@ struct vhost_msg {
 
 #define VHOST_USER_F_PROTOCOL_FEATURES	30
 
+#ifndef VIRTIO_F_EVENT_IDX
+ #define VIRTIO_F_EVENT_IDX 29
+#endif
+
 /* Features supported by this builtin vhost-user net driver. */
 #define VIRTIO_NET_SUPPORTED_FEATURES ((1ULL << VIRTIO_NET_F_MRG_RXBUF) | \
 				(1ULL << VIRTIO_NET_F_CTRL_VQ) | \
@@ -212,7 +218,8 @@ struct vhost_msg {
 				(1ULL << VIRTIO_NET_F_GUEST_TSO6) | \
 				(1ULL << VIRTIO_RING_F_INDIRECT_DESC) | \
 				(1ULL << VIRTIO_NET_F_MTU) | \
-				(1ULL << VIRTIO_F_IOMMU_PLATFORM))
+				(1ULL << VIRTIO_F_IOMMU_PLATFORM) | \
+				(1ULL << VIRTIO_F_EVENT_IDX))
 
 
 struct guest_page {
diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c
index 6fee16e55..0c1d66d7c 100644
--- a/lib/librte_vhost/virtio_net.c
+++ b/lib/librte_vhost/virtio_net.c
@@ -52,6 +52,35 @@
 
 #define MAX_BATCH_LEN 256
 
+#define vhost_used_event(vr)  ((vr)->avail->ring[(vr)->size])
+#define vhost_avail_event(vr) \
+	(*(volatile uint16_t *)&(vr)->used->ring[(vr)->size])
+
+static __rte_always_inline void
+vhost_notify(struct virtio_net *dev,  struct vhost_virtqueue *vq)
+{
+	/* Don't notify guest if we don't reach index specified by guest. */
+	if (dev->features & (1ULL << VIRTIO_F_EVENT_IDX)) {
+		uint16_t old = vq->signalled_used;
+		uint16_t new = vq->last_used_idx;
+
+		LOG_DEBUG(VHOST_DATA, "%s: used_event_idx=%d, old=%d, new=%d\n",
+			__func__,
+			vhost_used_event(vq),
+			old, new);
+		if (vring_need_event(vhost_used_event(vq), new, old)
+			&& (vq->callfd >= 0)) {
+			vq->signalled_used = vq->last_used_idx;
+			eventfd_write(vq->callfd, (eventfd_t) 1);
+		}
+	} else {
+		/* Kick the guest if necessary. */
+		if (!(vq->avail->flags & VRING_AVAIL_F_NO_INTERRUPT)
+			&& (vq->callfd >= 0))
+			eventfd_write(vq->callfd, (eventfd_t)1);
+	}
+}
+
 static bool
 is_valid_virt_queue_idx(uint32_t idx, int is_tx, uint32_t nr_vring)
 {
@@ -410,11 +439,7 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 
 	/* flush used->idx update before we read avail->flags. */
 	rte_mb();
-
-	/* Kick the guest if necessary. */
-	if (!(vq->avail->flags & VRING_AVAIL_F_NO_INTERRUPT)
-			&& (vq->callfd >= 0))
-		eventfd_write(vq->callfd, (eventfd_t)1);
+	vhost_notify(dev, vq);
 out:
 	if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))
 		vhost_user_iotlb_rd_unlock(vq);
@@ -704,11 +729,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
 
 		/* flush used->idx update before we read avail->flags. */
 		rte_mb();
-
-		/* Kick the guest if necessary. */
-		if (!(vq->avail->flags & VRING_AVAIL_F_NO_INTERRUPT)
-				&& (vq->callfd >= 0))
-			eventfd_write(vq->callfd, (eventfd_t)1);
+		vhost_notify(dev, vq);
 	}
 
 out:
@@ -1106,11 +1127,7 @@ update_used_idx(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	vq->used->idx += count;
 	vhost_log_used_vring(dev, vq, offsetof(struct vring_used, idx),
 			sizeof(vq->used->idx));
-
-	/* Kick guest if required. */
-	if (!(vq->avail->flags & VRING_AVAIL_F_NO_INTERRUPT)
-			&& (vq->callfd >= 0))
-		eventfd_write(vq->callfd, (eventfd_t)1);
+	vhost_notify(dev, vq);
 }
 
 static __rte_always_inline struct zcopy_mbuf *
@@ -1352,6 +1369,15 @@ rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
 		update_used_idx(dev, vq, i);
 	}
 
+	/*
+	 * Update avail event index to last_avail_idx to expect
+	 * front end notify us after next buffer available.
+	 */
+	if (dev->features & (1ULL << VIRTIO_F_EVENT_IDX)) {
+		vhost_avail_event(vq) = vq->last_avail_idx;
+		rte_mb();
+	}
+
 out:
 	if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))
 		vhost_user_iotlb_rd_unlock(vq);
-- 
2.15.0

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

end of thread, other threads:[~2017-11-28  2:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-28  9:48 [dpdk-dev] [PATCH v2] vhost: support virtqueue interrupt/notification suppression junjie.j.chen
2017-11-28  2:46 ` Tiwei Bie

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).