From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 122DEA32A1 for ; Thu, 24 Oct 2019 10:28:51 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 520D61E54B; Thu, 24 Oct 2019 10:28:44 +0200 (CEST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id 39A5F1E535 for ; Thu, 24 Oct 2019 10:28:40 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Oct 2019 01:28:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,224,1569308400"; d="scan'208";a="228431057" Received: from npg-dpdk-virtual-marvin-dev.sh.intel.com ([10.67.119.142]) by fmsmga002.fm.intel.com with ESMTP; 24 Oct 2019 01:28:36 -0700 From: Marvin Liu To: maxime.coquelin@redhat.com, tiwei.bie@intel.com, zhihong.wang@intel.com, stephen@networkplumber.org, gavin.hu@arm.com Cc: dev@dpdk.org, Marvin Liu Date: Fri, 25 Oct 2019 00:08:20 +0800 Message-Id: <20191024160832.14543-2-yong.liu@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191024160832.14543-1-yong.liu@intel.com> References: <20191021220813.55236-1-yong.liu@intel.com> <20191024160832.14543-1-yong.liu@intel.com> Subject: [dpdk-dev] [PATCH v9 01/13] vhost: add packed ring indexes increasing function 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 enqueuing or dequeuing, the virtqueue's local available and used indexes are increased. Signed-off-by: Marvin Liu Reviewed-by: Maxime Coquelin --- lib/librte_vhost/vhost.h | 20 ++++++++++++++++++++ lib/librte_vhost/virtio_net.c | 18 +++--------------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h index c76d40115..02b3c91ff 100644 --- a/lib/librte_vhost/vhost.h +++ b/lib/librte_vhost/vhost.h @@ -367,6 +367,26 @@ desc_is_avail(struct vring_packed_desc *desc, bool wrap_counter) wrap_counter != !!(flags & VRING_DESC_F_USED); } +static inline void +vq_inc_last_used_packed(struct vhost_virtqueue *vq, uint16_t num) +{ + vq->last_used_idx += num; + if (vq->last_used_idx >= vq->size) { + vq->used_wrap_counter ^= 1; + vq->last_used_idx -= vq->size; + } +} + +static inline void +vq_inc_last_avail_packed(struct vhost_virtqueue *vq, uint16_t num) +{ + vq->last_avail_idx += num; + if (vq->last_avail_idx >= vq->size) { + vq->avail_wrap_counter ^= 1; + vq->last_avail_idx -= vq->size; + } +} + void __vhost_log_cache_write(struct virtio_net *dev, struct vhost_virtqueue *vq, uint64_t addr, uint64_t len); diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c index 66f0c7206..070d62bc0 100644 --- a/lib/librte_vhost/virtio_net.c +++ b/lib/librte_vhost/virtio_net.c @@ -138,11 +138,7 @@ flush_shadow_used_ring_packed(struct virtio_net *dev, head_flags = flags; } - vq->last_used_idx += vq->shadow_used_packed[i].count; - if (vq->last_used_idx >= vq->size) { - vq->used_wrap_counter ^= 1; - vq->last_used_idx -= vq->size; - } + vq_inc_last_used_packed(vq, vq->shadow_used_packed[i].count); } __atomic_store_n(&vq->desc_packed[head_idx].flags, head_flags, @@ -865,11 +861,7 @@ virtio_dev_rx_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, break; } - vq->last_avail_idx += nr_descs; - if (vq->last_avail_idx >= vq->size) { - vq->last_avail_idx -= vq->size; - vq->avail_wrap_counter ^= 1; - } + vq_inc_last_avail_packed(vq, nr_descs); } do_data_copy_enqueue(dev, vq); @@ -1585,11 +1577,7 @@ virtio_dev_tx_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, TAILQ_INSERT_TAIL(&vq->zmbuf_list, zmbuf, next); } - vq->last_avail_idx += desc_count; - if (vq->last_avail_idx >= vq->size) { - vq->last_avail_idx -= vq->size; - vq->avail_wrap_counter ^= 1; - } + vq_inc_last_avail_packed(vq, desc_count); } if (likely(dev->dequeue_zero_copy == 0)) { -- 2.17.1