From: Jens Freimann <jfreimann@redhat.com>
To: dev@dpdk.org
Cc: tiwei.bie@intel.com, yliu@fridaylinux.org,
maxime.coquelin@redhat.com, mst@redhat.com
Subject: [dpdk-dev] [PATCH v3 21/21] vhost: add event suppression for packed queues
Date: Thu, 5 Apr 2018 12:10:31 +0200 [thread overview]
Message-ID: <20180405101031.26468-22-jfreimann@redhat.com> (raw)
In-Reply-To: <20180405101031.26468-1-jfreimann@redhat.com>
Signed-off-by: Jens Freimann <jfreimann@redhat.com>
---
lib/librte_vhost/vhost.c | 17 +++++++++---
lib/librte_vhost/vhost.h | 62 ++++++++++++++++++++++++++++++++++++-------
lib/librte_vhost/vhost_user.c | 19 +++++++++++++
lib/librte_vhost/virtio_net.c | 1 +
4 files changed, 86 insertions(+), 13 deletions(-)
diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c
index 3c633e71e..b0fc1c1ac 100644
--- a/lib/librte_vhost/vhost.c
+++ b/lib/librte_vhost/vhost.c
@@ -577,11 +577,21 @@ 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 == NULL)
return -1;
- if (dev->features & (1ULL << VIRTIO_F_RING_PACKED))
- return -1;
+
+ vq = dev->virtqueue[queue_id];
+ if (!vq->enabled)
+ return 0;
+
+ if (dev->features & (1ULL << VIRTIO_F_RING_PACKED)) {
+ if (!enable) {
+ vq->driver_event->desc_event_flags |= RING_EVENT_FLAGS_DISABLE;
+ } else
+ vq->driver_event->desc_event_flags |= RING_EVENT_FLAGS_ENABLE;
+ }
if (enable) {
RTE_LOG(ERR, VHOST_CONFIG,
@@ -589,7 +599,8 @@ rte_vhost_enable_guest_notification(int vid, uint16_t queue_id, int enable)
return -1;
}
- dev->virtqueue[queue_id]->used->flags = VRING_USED_F_NO_NOTIFY;
+ if (!(dev->features & (1ULL << VIRTIO_F_RING_PACKED)))
+ dev->virtqueue[queue_id]->used->flags = VRING_USED_F_NO_NOTIFY;
return 0;
}
diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h
index a0b61b7b0..77eeed8c9 100644
--- a/lib/librte_vhost/vhost.h
+++ b/lib/librte_vhost/vhost.h
@@ -69,14 +69,31 @@ struct batch_copy_elem {
uint64_t log_addr;
};
+#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;
+};
+
/**
* Structure contains variables relevant to RX/TX virtqueues.
*/
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;
@@ -211,7 +228,6 @@ struct vhost_msg {
(1ULL << VIRTIO_NET_F_MTU) | \
(1ULL << VIRTIO_F_IOMMU_PLATFORM))
-
struct guest_page {
uint64_t guest_phys_addr;
uint64_t host_phys_addr;
@@ -427,6 +443,11 @@ 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)
{
+ uint16_t off_wrap, wrap = 0;
+ uint16_t event_flags;
+ uint16_t event_idx = 0;
+ int do_kick = 0;
+
/* Flush used->idx update before we read avail->flags. */
rte_mb();
@@ -434,22 +455,43 @@ vhost_vring_call(struct virtio_net *dev, struct vhost_virtqueue *vq)
if (dev->features & (1ULL << VIRTIO_RING_F_EVENT_IDX)) {
uint16_t old = vq->signalled_used;
uint16_t new = vq->last_used_idx;
+ if (dev->features & (1ULL << VIRTIO_F_RING_PACKED)) {
+ event_flags = vq->driver_event->desc_event_flags &
+ RING_EVENT_FLAGS_MASK;
+ if (!(event_flags & RING_EVENT_FLAGS_DESC))
+ do_kick = event_flags & RING_EVENT_FLAGS_ENABLE ? 1 : 0;
+ else {
+ off_wrap = vq->driver_event->desc_event_off_wrap;
+ wrap = off_wrap & RING_EVENT_WRAP_MASK;
+ event_idx = off_wrap & RING_EVENT_OFF_MASK;
+ }
+ if (vhost_need_event(event_idx, new, old)
+ && (vq->callfd >= 0) && (wrap == vq->used_wrap_counter)) {
+ vq->signalled_used = vq->last_used_idx;
+ do_kick = 1;
+ }
+ } else {
+ event_idx = vhost_used_event(vq);
+ if (vhost_need_event(event_idx, new, old)
+ && (vq->callfd >= 0)) {
+ vq->signalled_used = vq->last_used_idx;
+ do_kick = 1;
+ }
+ }
VHOST_LOG_DEBUG(VHOST_DATA, "%s: used_event_idx=%d, old=%d, new=%d\n",
__func__,
- vhost_used_event(vq),
+ event_idx,
old, new);
- if (vhost_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);
+ do_kick = 1;
}
+
+ if (do_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 183893e46..6b8fd1474 100644
--- a/lib/librte_vhost/vhost_user.c
+++ b/lib/librte_vhost/vhost_user.c
@@ -39,6 +39,7 @@
#include "iotlb.h"
#include "vhost.h"
#include "vhost_user.h"
+#include "virtio-1.1.h"
#define VIRTIO_MIN_MTU 68
#define VIRTIO_MAX_MTU 65535
@@ -476,6 +477,24 @@ translate_ring_addresses(struct virtio_net *dev, int vq_index)
vq->avail = NULL;
vq->used = NULL;
vq->log_guest_addr = 0;
+ vq->driver_event = (struct vring_packed_desc_event *)(uintptr_t)ring_addr_to_vva(dev,
+ vq, addr->avail_user_addr, sizeof(struct vring_packed_desc_event));
+ if (vq->driver_event == 0) {
+ RTE_LOG(DEBUG, VHOST_CONFIG,
+ "(%d) failed to find driver area address.\n",
+ dev->vid);
+ return dev;
+ }
+
+ vq->device_event = (struct vring_packed_desc_event *)(uintptr_t)ring_addr_to_vva(dev,
+ vq, addr->used_user_addr, sizeof(struct vring_packed_desc_event));
+ if (vq->device_event == 0) {
+ RTE_LOG(DEBUG, VHOST_CONFIG,
+ "(%d) failed to find device area address.\n",
+ dev->vid);
+ return dev;
+ }
+
if (vq->last_used_idx != 0) {
RTE_LOG(WARNING, VHOST_CONFIG,
diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c
index b82c24081..d3c09c8ba 100644
--- a/lib/librte_vhost/virtio_net.c
+++ b/lib/librte_vhost/virtio_net.c
@@ -770,6 +770,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
if ((i & (vq->size - 1)) == 0)
toggle_wrap_counter(vq);
set_desc_used(vq, &descs[i & (vq->size - 1)]);
+ vhost_vring_call(dev, vq);
}
}
--
2.14.3
prev parent reply other threads:[~2018-04-05 10:11 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-05 10:10 [dpdk-dev] [PATCH v3 00/21] implement packed virtqueues Jens Freimann
2018-04-05 10:10 ` [dpdk-dev] [PATCH v3 01/21] net/virtio: by default disable " Jens Freimann
2018-04-05 13:42 ` Maxime Coquelin
2018-04-05 14:19 ` Jens Freimann
2018-04-05 10:10 ` [dpdk-dev] [PATCH v3 02/21] net/virtio: vring init for packed queues Jens Freimann
2018-04-05 14:15 ` Maxime Coquelin
2018-04-05 14:24 ` Jens Freimann
2018-04-05 14:22 ` Tiwei Bie
2018-04-05 15:16 ` Jens Freimann
2018-04-05 10:10 ` [dpdk-dev] [PATCH v3 03/21] net/virtio: add virtio 1.1 defines Jens Freimann
2018-04-05 14:16 ` Maxime Coquelin
2018-04-05 14:27 ` Tiwei Bie
2018-04-05 14:33 ` Jens Freimann
2018-04-05 10:10 ` [dpdk-dev] [PATCH v3 04/21] net/virtio: add packed virtqueue helpers Jens Freimann
2018-04-05 14:27 ` Maxime Coquelin
2018-04-05 14:34 ` Jens Freimann
2018-04-05 14:40 ` Tiwei Bie
2018-04-05 15:14 ` Jens Freimann
2018-04-05 10:10 ` [dpdk-dev] [PATCH v3 05/21] net/virtio: dump packed virtqueue data Jens Freimann
2018-04-05 14:29 ` Maxime Coquelin
2018-04-08 3:53 ` Tiwei Bie
2018-04-05 10:10 ` [dpdk-dev] [PATCH v3 06/21] net/virtio-user: add option to use packed queues Jens Freimann
2018-04-05 14:35 ` Maxime Coquelin
2018-04-05 10:10 ` [dpdk-dev] [PATCH v3 07/21] net/virtio: implement transmit path for " Jens Freimann
2018-04-06 7:56 ` Maxime Coquelin
2018-04-06 8:10 ` Jens Freimann
2018-04-08 4:51 ` Tiwei Bie
2018-04-09 6:20 ` Jens Freimann
2018-04-05 10:10 ` [dpdk-dev] [PATCH v3 08/21] net/virtio: implement receive " Jens Freimann
2018-04-06 7:51 ` Maxime Coquelin
2018-04-06 8:12 ` Jens Freimann
2018-04-05 10:10 ` [dpdk-dev] [PATCH v3 09/21] vhost: disable packed virtqueues by default Jens Freimann
2018-04-05 10:10 ` [dpdk-dev] [PATCH v3 10/21] vhost: turn of indirect descriptors for packed virtqueues Jens Freimann
2018-04-06 8:12 ` Maxime Coquelin
2018-04-05 10:10 ` [dpdk-dev] [PATCH v3 11/21] vhost: add virtio 1.1 defines Jens Freimann
2018-04-06 8:15 ` Maxime Coquelin
2018-04-05 10:10 ` [dpdk-dev] [PATCH v3 12/21] vhost: vring address setup for packed queues Jens Freimann
2018-04-06 8:19 ` Maxime Coquelin
2018-04-06 8:23 ` Jens Freimann
2018-04-05 10:10 ` [dpdk-dev] [PATCH v3 13/21] vhost: add helpers for packed virtqueues Jens Freimann
2018-04-06 9:20 ` Maxime Coquelin
2018-04-06 9:21 ` Jens Freimann
2018-04-05 10:10 ` [dpdk-dev] [PATCH v3 14/21] vhost: dequeue for packed queues Jens Freimann
2018-04-06 9:30 ` Maxime Coquelin
2018-04-06 10:07 ` Jens Freimann
2018-04-05 10:10 ` [dpdk-dev] [PATCH v3 15/21] vhost: packed queue enqueue path Jens Freimann
2018-04-06 9:36 ` Maxime Coquelin
2018-04-06 12:17 ` Jens Freimann
2018-04-05 10:10 ` [dpdk-dev] [PATCH v3 16/21] vhost: enable packed virtqueues Jens Freimann
2018-04-05 10:10 ` [dpdk-dev] [PATCH v3 17/21] net/virtio: disable ctrl virtqueue for packed rings Jens Freimann
2018-04-06 9:38 ` Maxime Coquelin
2018-04-06 9:43 ` Jens Freimann
2018-04-06 9:48 ` Maxime Coquelin
2018-04-05 10:10 ` [dpdk-dev] [PATCH v3 18/21] net/virtio: add support for mergeable buffers with packed virtqueues Jens Freimann
2018-04-06 10:05 ` Maxime Coquelin
2018-04-08 6:02 ` Tiwei Bie
2018-04-05 10:10 ` [dpdk-dev] [PATCH v3 19/21] vhost: support mergeable rx buffers with packed queues Jens Freimann
2018-04-06 13:04 ` Maxime Coquelin
2018-04-06 14:07 ` Jens Freimann
2018-04-05 10:10 ` [dpdk-dev] [PATCH v3 20/21] net/virtio: add support for event suppression Jens Freimann
2018-04-06 13:50 ` Maxime Coquelin
2018-04-06 14:09 ` Jens Freimann
2018-04-08 6:07 ` Tiwei Bie
2018-04-09 6:09 ` Jens Freimann
2018-04-05 10:10 ` Jens Freimann [this message]
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=20180405101031.26468-22-jfreimann@redhat.com \
--to=jfreimann@redhat.com \
--cc=dev@dpdk.org \
--cc=maxime.coquelin@redhat.com \
--cc=mst@redhat.com \
--cc=tiwei.bie@intel.com \
--cc=yliu@fridaylinux.org \
/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).