[dpdk-dev] [PATCH v1 14/14] vhost: check whether disable software pre-fetch

Marvin Liu yong.liu at intel.com
Thu Sep 5 18:14:21 CEST 2019


Disable software pre-fetch actions on Skylake and Cascadelake platforms.
Hardware can fetch needed data for vhost, additional software pre-fetch
will have impact on performance.

Signed-off-by: Marvin Liu <yong.liu at intel.com>

diff --git a/lib/librte_vhost/Makefile b/lib/librte_vhost/Makefile
index 8623e91c0..1d1423bdc 100644
--- a/lib/librte_vhost/Makefile
+++ b/lib/librte_vhost/Makefile
@@ -16,6 +16,12 @@ CFLAGS += -I vhost_user
 CFLAGS += -fno-strict-aliasing
 LDLIBS += -lpthread
 
+AVX512_SUPPORT=$(shell $(CC) -march=native -dM -E - </dev/null |grep AVX512F)
+
+ifneq ($(AVX512_SUPPORT),)
+CFLAGS += -DDISABLE_SWPREFETCH
+endif
+
 ifeq ($(CONFIG_RTE_LIBRTE_VHOST_NUMA),y)
 LDLIBS += -lnuma
 endif
diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c
index 554617292..7d9a8eda0 100644
--- a/lib/librte_vhost/virtio_net.c
+++ b/lib/librte_vhost/virtio_net.c
@@ -489,7 +489,9 @@ map_one_desc(struct virtio_net *dev, struct vhost_virtqueue *vq,
 		if (unlikely(!desc_addr))
 			return -1;
 
+#ifndef DISABLE_SWPREFETCH
 		rte_prefetch0((void *)(uintptr_t)desc_addr);
+#endif
 
 		buf_vec[vec_id].buf_iova = desc_iova;
 		buf_vec[vec_id].buf_addr = desc_addr;
@@ -1011,7 +1013,9 @@ virtio_dev_rx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	 */
 	rte_smp_rmb();
 
+#ifndef DISABLE_SWPREFETCH
 	rte_prefetch0(&vq->avail->ring[vq->last_avail_idx & (vq->size - 1)]);
+#endif
 
 	for (pkt_idx = 0; pkt_idx < count; pkt_idx++) {
 		uint32_t pkt_len = pkts[pkt_idx]->pkt_len + dev->vhost_hlen;
@@ -1110,10 +1114,12 @@ virtio_dev_rx_burst_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,
 		(len3 != descs[avail_idx + 3].len)))
 		return -1;
 
+#ifndef DISABLE_SWPREFETCH
 	rte_prefetch0((void *)(uintptr_t)desc_addr);
 	rte_prefetch0((void *)(uintptr_t)desc_addr1);
 	rte_prefetch0((void *)(uintptr_t)desc_addr2);
 	rte_prefetch0((void *)(uintptr_t)desc_addr3);
+#endif
 
 	hdr = (struct virtio_net_hdr_mrg_rxbuf *)(uintptr_t)desc_addr;
 	hdr1 = (struct virtio_net_hdr_mrg_rxbuf *)(uintptr_t)desc_addr1;
@@ -1687,7 +1693,9 @@ virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	 */
 	rte_smp_rmb();
 
+#ifndef DISABLE_SWPREFETCH
 	rte_prefetch0(&vq->avail->ring[vq->last_avail_idx & (vq->size - 1)]);
+#endif
 
 	VHOST_LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->vid, __func__);
 
@@ -1872,10 +1880,12 @@ virtio_dev_tx_burst_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	if (ret)
 		return ret;
 
+#ifndef DISABLE_SWPREFETCH
 	rte_prefetch0((void *)(uintptr_t)desc_addr[0]);
 	rte_prefetch0((void *)(uintptr_t)desc_addr[1]);
 	rte_prefetch0((void *)(uintptr_t)desc_addr[2]);
 	rte_prefetch0((void *)(uintptr_t)desc_addr[3]);
+#endif
 
 	rte_memcpy(rte_pktmbuf_mtod_offset(pkts[0], void *, 0),
 		(void *)(uintptr_t)(desc_addr[0] + buf_offset),
-- 
2.17.1



More information about the dev mailing list