From patchwork Mon Jul 8 17:13:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marvin Liu X-Patchwork-Id: 56219 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 770851BDF2; Mon, 8 Jul 2019 11:30:16 +0200 (CEST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 70A711B9A6 for ; Mon, 8 Jul 2019 11:30:02 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Jul 2019 02:30:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,466,1557212400"; d="scan'208";a="155821719" Received: from npg-dpdk-virtual-marvin-dev.sh.intel.com ([10.67.119.142]) by orsmga007.jf.intel.com with ESMTP; 08 Jul 2019 02:29:59 -0700 From: Marvin Liu To: tiwei.bie@intel.com, maxime.coquelin@redhat.com, dev@dpdk.org Cc: Marvin Liu Date: Tue, 9 Jul 2019 01:13:19 +0800 Message-Id: <20190708171320.38802-13-yong.liu@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190708171320.38802-1-yong.liu@intel.com> References: <20190708171320.38802-1-yong.liu@intel.com> Subject: [dpdk-dev] [RFC PATCH 12/13] support inorder in vhost dequeue path 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" When inorder feature bit is negotiated, just update first used descriptor with last descriptor index. It can reflect all used descriptors. Signed-off-by: Marvin Liu diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c index 0f9292eb0..6bcf565f0 100644 --- a/lib/librte_vhost/virtio_net.c +++ b/lib/librte_vhost/virtio_net.c @@ -31,6 +31,12 @@ rxvq_is_mergeable(struct virtio_net *dev) return dev->features & (1ULL << VIRTIO_NET_F_MRG_RXBUF); } +static __rte_always_inline bool +virtio_net_is_inorder(struct virtio_net *dev) +{ + return dev->features & (1ULL << VIRTIO_F_IN_ORDER); +} + static bool is_valid_virt_queue_idx(uint32_t idx, int is_tx, uint32_t nr_vring) { @@ -158,6 +164,35 @@ flush_shadow_used_ring_packed(struct virtio_net *dev, vhost_log_cache_sync(dev, vq); } +static __rte_always_inline void +flush_dequeue_shadow_used_packed_inorder(struct virtio_net *dev, + struct vhost_virtqueue *vq) +{ + uint16_t head_idx = vq->dequeue_shadow_head; + uint16_t head_flags = 0; + struct vring_used_elem_packed *last_elem; + + last_elem = &vq->shadow_used_packed[vq->shadow_used_idx - 1]; + vq->desc_packed[head_idx].id = last_elem->id + last_elem->count - 1; + + if (vq->shadow_used_packed[0].used_wrap_counter) + head_flags = VIRTIO_TX_FLAG_PACKED; + else + head_flags = VIRTIO_TX_WRAP_FLAG_PACKED; + + rte_smp_wmb(); + + vq->desc_packed[head_idx].flags = head_flags; + + vhost_log_cache_used_vring(dev, vq, + head_idx * + sizeof(struct vring_packed_desc), + sizeof(struct vring_packed_desc)); + + vq->shadow_used_idx = 0; + vhost_log_cache_sync(dev, vq); +} + static __rte_always_inline void flush_enqueue_used_packed(struct virtio_net *dev, struct vhost_virtqueue *vq) @@ -269,6 +304,34 @@ flush_dequeue_shadow_used_packed(struct virtio_net *dev, vhost_log_cache_sync(dev, vq); } +static __rte_always_inline void +flush_used_fast_packed_inorder(struct virtio_net *dev, + struct vhost_virtqueue *vq, uint64_t len, + uint64_t len1, uint64_t len2, uint64_t len3, + uint16_t id, uint16_t flags) +{ + vq->desc_packed[vq->last_used_idx].id = id; + vq->desc_packed[vq->last_used_idx].len = len; + vq->desc_packed[vq->last_used_idx + 1].len = len1; + vq->desc_packed[vq->last_used_idx + 2].len = len2; + vq->desc_packed[vq->last_used_idx + 3].len = len3; + + rte_smp_wmb(); + vq->desc_packed[vq->last_used_idx].flags = flags; + + vhost_log_cache_used_vring(dev, vq, + vq->last_used_idx * + sizeof(struct vring_packed_desc), + RTE_CACHE_LINE_SIZE); + vhost_log_cache_sync(dev, vq); + + vq->last_used_idx += PACKED_DESC_PER_CACHELINE; + if (vq->last_used_idx >= vq->size) { + vq->used_wrap_counter ^= 1; + vq->last_used_idx -= vq->size; + } +} + /* flags are same when flushing used ring in fast path */ static __rte_always_inline void flush_used_fast_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, @@ -320,8 +383,12 @@ flush_dequeue_fast_used_packed(struct virtio_net *dev, flags = VIRTIO_TX_FLAG_PACKED; else flags = VIRTIO_TX_WRAP_FLAG_PACKED; - - flush_used_fast_packed(dev, vq, 0, 0, 0, 0, id, id1, id2, id3, flags); + if (virtio_net_is_inorder(dev)) + flush_used_fast_packed_inorder(dev, vq, 0, 0, 0, 0, id3, + flags); + else + flush_used_fast_packed(dev, vq, 0, 0, 0, 0, id, id1, id2, id3, + flags); } static __rte_always_inline void @@ -451,7 +518,10 @@ flush_dequeue_shadow_used(struct virtio_net *dev, struct vhost_virtqueue *vq) shadow_count += vq->last_used_idx & 0x3; if ((uint16_t)shadow_count >= (vq->size >> 1)) { do_data_copy_dequeue(vq); - flush_dequeue_shadow_used_packed(dev, vq); + if (virtio_net_is_inorder(dev)) + flush_dequeue_shadow_used_packed_inorder(dev, vq); + else + flush_dequeue_shadow_used_packed(dev, vq); vhost_vring_call_packed(dev, vq); } }