From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 894F45AA1 for ; Thu, 18 Aug 2016 15:41:16 +0200 (CEST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP; 18 Aug 2016 06:41:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,539,1464678000"; d="scan'208";a="750443122" Received: from unknown (HELO dpdk5.sh.intel.com) ([10.239.129.118]) by FMSMGA003.fm.intel.com with ESMTP; 18 Aug 2016 06:41:15 -0700 From: Zhihong Wang To: dev@dpdk.org Cc: maxime.coquelin@redhat.com, yuanhan.liu@linux.intel.com, Zhihong Wang Date: Thu, 18 Aug 2016 02:33:11 -0400 Message-Id: <1471501991-37257-7-git-send-email-zhihong.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1471501991-37257-1-git-send-email-zhihong.wang@intel.com> References: <1471319402-112998-1-git-send-email-zhihong.wang@intel.com> <1471501991-37257-1-git-send-email-zhihong.wang@intel.com> Subject: [dpdk-dev] [PATCH v2 6/6] vhost: optimize cache access X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Aug 2016 13:41:18 -0000 This patch reorders the code to delay virtio header write to optimize cache access efficiency for cases where the mrg_rxbuf feature is turned on. It reduces CPU pipeline stall cycles significantly. Signed-off-by: Zhihong Wang --- lib/librte_vhost/vhost_rxtx.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c index 60d63d3..15f7f9c 100644 --- a/lib/librte_vhost/vhost_rxtx.c +++ b/lib/librte_vhost/vhost_rxtx.c @@ -154,6 +154,7 @@ enqueue_packet(struct virtio_net *dev, struct vhost_virtqueue *vq, uint32_t mbuf_len = 0; uint32_t mbuf_len_left = 0; uint32_t copy_len = 0; + uint32_t copy_virtio_hdr = 0; uint32_t extra_buffers = 0; /* start with the first mbuf of the packet */ @@ -168,18 +169,17 @@ enqueue_packet(struct virtio_net *dev, struct vhost_virtqueue *vq, if (unlikely(!desc_host_write_addr)) goto error; - /* handle virtio header */ + /* + * handle virtio header, the actual write operation + * is delayed for cache optimization. + */ virtio_hdr = (struct virtio_net_hdr_mrg_rxbuf *) (uintptr_t)desc_host_write_addr; - memset((void *)(uintptr_t)&(virtio_hdr->hdr), - 0, dev->vhost_hlen); - virtio_enqueue_offload(mbuf, &(virtio_hdr->hdr)); + copy_virtio_hdr = 1; vhost_log_write(dev, desc->addr, dev->vhost_hlen); desc_write_offset = dev->vhost_hlen; desc_chain_len = desc_write_offset; desc_host_write_addr += desc_write_offset; - if (is_mrg_rxbuf) - virtio_hdr->num_buffers = 1; /* start copy from mbuf to desc */ while (1) { @@ -233,9 +233,18 @@ enqueue_packet(struct virtio_net *dev, struct vhost_virtqueue *vq, goto rollback; } - /* copy mbuf data */ + /* copy virtio header and mbuf data */ copy_len = RTE_MIN(desc->len - desc_write_offset, mbuf_len_left); + if (copy_virtio_hdr) { + copy_virtio_hdr = 0; + memset((void *)(uintptr_t)&(virtio_hdr->hdr), + 0, dev->vhost_hlen); + virtio_enqueue_offload(mbuf, &(virtio_hdr->hdr)); + if (is_mrg_rxbuf) + virtio_hdr->num_buffers = extra_buffers + 1; + } + rte_memcpy((void *)(uintptr_t)desc_host_write_addr, rte_pktmbuf_mtod_offset(mbuf, void *, mbuf_len - mbuf_len_left), -- 2.7.4