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 6214F4C9F for ; Thu, 6 Sep 2018 20:20:48 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 05D2940676C0; Thu, 6 Sep 2018 18:20:48 +0000 (UTC) Received: from localhost (ovpn-116-129.ams2.redhat.com [10.36.116.129]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D8E472166BA2; Thu, 6 Sep 2018 18:20:43 +0000 (UTC) From: Jens Freimann To: dev@dpdk.org Cc: tiwei.bie@intel.com, maxime.coquelin@redhat.com Date: Thu, 6 Sep 2018 19:19:47 +0100 Message-Id: <20180906181947.20646-12-jfreimann@redhat.com> In-Reply-To: <20180906181947.20646-1-jfreimann@redhat.com> References: <20180906181947.20646-1-jfreimann@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 06 Sep 2018 18:20:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 06 Sep 2018 18:20:48 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jfreimann@redhat.com' RCPT:'' Subject: [dpdk-dev] [PATCH v5 11/11] net/virtio: add support for event suppression 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, 06 Sep 2018 18:20:48 -0000 Signed-off-by: Jens Freimann --- drivers/net/virtio/virtio_ethdev.c | 2 +- drivers/net/virtio/virtio_rxtx.c | 15 +++++- drivers/net/virtio/virtqueue.h | 77 ++++++++++++++++++++++++++++-- 3 files changed, 89 insertions(+), 5 deletions(-) diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index f2e515838..4249e52c7 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -730,7 +730,7 @@ virtio_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id) struct virtnet_rx *rxvq = dev->data->rx_queues[queue_id]; struct virtqueue *vq = rxvq->vq; - virtqueue_enable_intr(vq); + virtqueue_enable_intr(vq, 0, 0); return 0; } diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c index 577786b7e..5dee3f12b 100644 --- a/drivers/net/virtio/virtio_rxtx.c +++ b/drivers/net/virtio/virtio_rxtx.c @@ -137,6 +137,10 @@ virtio_xmit_pkts_packed(void *tx_queue, struct rte_mbuf **tx_pkts, vq->vq_descx[head_idx].ndescs = descs_used; idx = update_pq_avail_index(vq); + if (unlikely(virtqueue_kick_prepare_packed(vq))) { + virtqueue_notify(vq); + PMD_RX_LOG(DEBUG, "Notified"); + } } txvq->stats.packets += i; @@ -1193,6 +1197,10 @@ virtio_recv_pkts_packed(void *rx_queue, struct rte_mbuf **rx_pkts, } rxvq->stats.packets += nb_rx; + if (nb_rx > 0 && unlikely(virtqueue_kick_prepare_packed(vq))) { + virtqueue_notify(vq); + PMD_RX_LOG(DEBUG, "Notified"); + } return nb_rx; } @@ -1648,8 +1656,13 @@ virtio_recv_mergeable_pkts(void *rx_queue, rxvq->stats.packets += nb_rx; - if (vtpci_packed_queue(vq->hw)) + if (vtpci_packed_queue(vq->hw)) { + if (unlikely(virtqueue_kick_prepare(vq))) { + virtqueue_notify(vq); + PMD_RX_LOG(DEBUG, "Notified"); + } return nb_rx; + } /* Allocate new mbuf for the used descriptor */ while (likely(!virtqueue_full(vq))) { diff --git a/drivers/net/virtio/virtqueue.h b/drivers/net/virtio/virtqueue.h index 735066486..9d3e322a2 100644 --- a/drivers/net/virtio/virtqueue.h +++ b/drivers/net/virtio/virtqueue.h @@ -176,6 +176,8 @@ struct virtqueue { uint16_t vq_free_cnt; /**< num of desc available */ uint16_t vq_avail_idx; /**< sync until needed */ uint16_t vq_free_thresh; /**< free threshold */ + uint16_t vq_signalled_avail; + int vq_signalled_avail_valid; void *vq_ring_virt_mem; /**< linear address of vring*/ unsigned int vq_ring_size; @@ -292,16 +294,37 @@ vring_desc_init(struct vring_desc *dp, uint16_t n) static inline void virtqueue_disable_intr(struct virtqueue *vq) { - vq->vq_ring.avail->flags |= VRING_AVAIL_F_NO_INTERRUPT; + if (vtpci_packed_queue(vq->hw) && vtpci_with_feature(vq->hw, + VIRTIO_RING_F_EVENT_IDX)) + vq->vq_ring.device_event->desc_event_flags = + RING_EVENT_FLAGS_DISABLE; + else + vq->vq_ring.avail->flags |= VRING_AVAIL_F_NO_INTERRUPT; } /** * Tell the backend to interrupt us. */ static inline void -virtqueue_enable_intr(struct virtqueue *vq) +virtqueue_enable_intr(struct virtqueue *vq, uint16_t off, uint16_t wrap_counter) { - vq->vq_ring.avail->flags &= (~VRING_AVAIL_F_NO_INTERRUPT); + uint16_t *flags = &vq->vq_ring.device_event->desc_event_flags; + uint16_t *event_off_wrap = + &vq->vq_ring.device_event->desc_event_off_wrap; + if (vtpci_packed_queue(vq->hw)) { + *flags = 0; + *event_off_wrap = 0; + if (*event_off_wrap & RING_EVENT_FLAGS_DESC) { + *event_off_wrap = off | 0x7FFF; + *event_off_wrap |= wrap_counter << 15; + *flags |= RING_EVENT_FLAGS_DESC; + } else { + *event_off_wrap = 0; + } + *flags |= RING_EVENT_FLAGS_ENABLE; + } else { + vq->vq_ring.avail->flags &= (~VRING_AVAIL_F_NO_INTERRUPT); + } } /** @@ -363,12 +386,60 @@ vq_update_avail_ring(struct virtqueue *vq, uint16_t desc_idx) vq->vq_avail_idx++; } +static int vhost_idx_diff(struct virtqueue *vq, uint16_t old, uint16_t new) +{ + if (new > old) + return new - old; + return (new + vq->vq_nentries - old); +} + +static int vring_packed_need_event(struct virtqueue *vq, + uint16_t event_off, uint16_t new, + uint16_t old) +{ + return (uint16_t)(vhost_idx_diff(vq, new, event_off) - 1) < + (uint16_t)vhost_idx_diff(vq, new, old); +} + + static inline int virtqueue_kick_prepare(struct virtqueue *vq) { return !(vq->vq_ring.used->flags & VRING_USED_F_NO_NOTIFY); } +static inline int +virtqueue_kick_prepare_packed(struct virtqueue *vq) +{ + uint16_t notify_offset, flags, wrap; + uint16_t old, new; + int v; + + if (vtpci_packed_queue(vq->hw)) { + flags = vq->vq_ring.device_event->desc_event_flags; + if (!(flags & RING_EVENT_FLAGS_DESC)) + return flags & RING_EVENT_FLAGS_ENABLE; + virtio_rmb(); + notify_offset = vq->vq_ring.device_event->desc_event_off_wrap; + wrap = notify_offset & 0x1; + notify_offset >>= 1; + + old = vq->vq_signalled_avail; + v = vq->vq_signalled_avail_valid; + new = vq->vq_avail_idx; + vq->vq_signalled_avail = vq->vq_avail_idx; + vq->vq_signalled_avail_valid = 1; + + if (unlikely(!v)) + return 0; + + return (vring_packed_need_event(vq, new, old, notify_offset) && + wrap == vq->vq_ring.avail_wrap_counter); + } else { + return !(vq->vq_ring.used->flags & VRING_USED_F_NO_NOTIFY); + } +} + static inline void virtqueue_notify(struct virtqueue *vq) { -- 2.17.1