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 5D5DDA0613 for ; Mon, 23 Sep 2019 07:49:16 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 1CB114CE4; Mon, 23 Sep 2019 07:49:15 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id 1BF314C9D for ; Mon, 23 Sep 2019 07:49:13 +0200 (CEST) X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Sep 2019 22:49:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,539,1559545200"; d="scan'208";a="203054954" Received: from dpdk-virtio-tbie-2.sh.intel.com (HELO ___) ([10.67.104.73]) by fmsmga001.fm.intel.com with ESMTP; 22 Sep 2019 22:49:11 -0700 Date: Mon, 23 Sep 2019 13:46:25 +0800 From: Tiwei Bie To: Marvin Liu Cc: maxime.coquelin@redhat.com, zhihong.wang@intel.com, dev@dpdk.org Message-ID: <20190923054625.GA554@___> References: <20190905161421.55981-2-yong.liu@intel.com> <20190919163643.24130-1-yong.liu@intel.com> <20190919163643.24130-4-yong.liu@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20190919163643.24130-4-yong.liu@intel.com> User-Agent: Mutt/1.9.4 (2018-02-28) Subject: Re: [dpdk-dev] [PATCH v2 03/16] vhost: add burst enqueue function for packed ring 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" On Fri, Sep 20, 2019 at 12:36:30AM +0800, Marvin Liu wrote: > Burst enqueue function will first check whether descriptors are cache > aligned. It will also check prerequisites in the beginning. Burst > enqueue function not support chained mbufs, single packet enqueue > function will handle it. > > Signed-off-by: Marvin Liu > > diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h > index 5074226f0..67889c80a 100644 > --- a/lib/librte_vhost/vhost.h > +++ b/lib/librte_vhost/vhost.h > @@ -39,6 +39,9 @@ > > #define VHOST_LOG_CACHE_NR 32 > > +#define PACKED_DESCS_BURST (RTE_CACHE_LINE_SIZE / \ > + sizeof(struct vring_packed_desc)) > + > #ifdef SUPPORT_GCC_UNROLL_PRAGMA > #define PRAGMA_PARAM "GCC unroll 4" > #endif > @@ -57,6 +60,8 @@ > #define UNROLL_PRAGMA(param) do {} while(0); > #endif > > +#define PACKED_BURST_MASK (PACKED_DESCS_BURST - 1) It's better to have consistent names, e.g. something like: PACKED_BATCH_SIZE PACKED_BATCH_MASK instead of PACKED_DESCS_BURST PACKED_BURST_MASK Besides, please also put above two defines together. > + > /** > * Structure contains buffer address, length and descriptor index > * from vring to do scatter RX. > diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c > index 2b5c47145..c664b27c5 100644 > --- a/lib/librte_vhost/virtio_net.c > +++ b/lib/librte_vhost/virtio_net.c > @@ -895,6 +895,84 @@ virtio_dev_rx_split(struct virtio_net *dev, struct vhost_virtqueue *vq, > return pkt_idx; > } > > +static __rte_unused __rte_always_inline int > +virtio_dev_rx_burst_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, > + struct rte_mbuf **pkts) > +{ > + bool wrap_counter = vq->avail_wrap_counter; > + struct vring_packed_desc *descs = vq->desc_packed; > + uint16_t avail_idx = vq->last_avail_idx; > + > + uint64_t desc_addrs[PACKED_DESCS_BURST]; > + struct virtio_net_hdr_mrg_rxbuf *hdrs[PACKED_DESCS_BURST]; > + uint32_t buf_offset = dev->vhost_hlen; > + uint64_t lens[PACKED_DESCS_BURST]; > + > + uint16_t i; > + > + if (unlikely(avail_idx & PACKED_BURST_MASK)) > + return -1; We also need to check (avail_idx + PACKED_DESCS_BURST) <= vq->size before accessing descs[avail_idx + i] in the following code. > + > + UNROLL_PRAGMA(PRAGMA_PARAM) > + for (i = 0; i < PACKED_DESCS_BURST; i++) { > + if (unlikely(pkts[i]->next != NULL)) > + return -1; > + if (unlikely(!desc_is_avail(&descs[avail_idx + i], > + wrap_counter))) > + return -1; > + } > + > + rte_smp_rmb(); > + > + UNROLL_PRAGMA(PRAGMA_PARAM) > + for (i = 0; i < PACKED_DESCS_BURST; i++) > + lens[i] = descs[avail_idx + i].len; > + > + UNROLL_PRAGMA(PRAGMA_PARAM) > + for (i = 0; i < PACKED_DESCS_BURST; i++) { > + if (unlikely(pkts[i]->pkt_len > (lens[i] - buf_offset))) > + return -1; > + } > + > + UNROLL_PRAGMA(PRAGMA_PARAM) > + for (i = 0; i < PACKED_DESCS_BURST; i++) > + desc_addrs[i] = vhost_iova_to_vva(dev, vq, > + descs[avail_idx + i].addr, > + &lens[i], > + VHOST_ACCESS_RW); > + UNROLL_PRAGMA(PRAGMA_PARAM) > + for (i = 0; i < PACKED_DESCS_BURST; i++) { > + if (unlikely(lens[i] != descs[avail_idx + i].len)) > + return -1; > + } > + > + UNROLL_PRAGMA(PRAGMA_PARAM) > + for (i = 0; i < PACKED_DESCS_BURST; i++) { > + rte_prefetch0((void *)(uintptr_t)desc_addrs[i]); > + hdrs[i] = (struct virtio_net_hdr_mrg_rxbuf *)desc_addrs[i]; > + lens[i] = pkts[i]->pkt_len + dev->vhost_hlen; > + } > + > + UNROLL_PRAGMA(PRAGMA_PARAM) > + for (i = 0; i < PACKED_DESCS_BURST; i++) > + virtio_enqueue_offload(pkts[i], &hdrs[i]->hdr); > + > + vq->last_avail_idx += PACKED_DESCS_BURST; > + if (vq->last_avail_idx >= vq->size) { > + vq->last_avail_idx -= vq->size; > + vq->avail_wrap_counter ^= 1; > + } > + > + UNROLL_PRAGMA(PRAGMA_PARAM) > + for (i = 0; i < PACKED_DESCS_BURST; i++) { > + rte_memcpy((void *)(uintptr_t)(desc_addrs[i] + buf_offset), > + rte_pktmbuf_mtod_offset(pkts[i], void *, 0), > + pkts[i]->pkt_len); > + } > + > + return 0; > +} > + > static __rte_unused int16_t > virtio_dev_rx_single_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, > struct rte_mbuf *pkt) > -- > 2.17.1 >