From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by dpdk.org (Postfix) with ESMTP id 2D1E11CB35 for ; Thu, 5 Apr 2018 12:11:51 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C44CF406FA03; Thu, 5 Apr 2018 10:11:50 +0000 (UTC) Received: from localhost (dhcp-192-241.str.redhat.com [10.33.192.241]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 75C712024CA4; Thu, 5 Apr 2018 10:11:50 +0000 (UTC) From: Jens Freimann To: dev@dpdk.org Cc: tiwei.bie@intel.com, yliu@fridaylinux.org, maxime.coquelin@redhat.com, mst@redhat.com Date: Thu, 5 Apr 2018 12:10:31 +0200 Message-Id: <20180405101031.26468-22-jfreimann@redhat.com> In-Reply-To: <20180405101031.26468-1-jfreimann@redhat.com> References: <20180405101031.26468-1-jfreimann@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 05 Apr 2018 10:11:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 05 Apr 2018 10:11:50 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jfreimann@redhat.com' RCPT:'' Subject: [dpdk-dev] [PATCH v3 21/21] vhost: add event suppression for packed queues X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Apr 2018 10:11:51 -0000 Signed-off-by: Jens Freimann --- 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