vectorize virtio packed ring datapath
Subsystems (2)
Re: [dpdk-dev] [PATCH v10 6/9] net/virtio: add vectorized packed ring Rx path
In reply to Marvin LiuQuoted 528 lines · Marvin Liu
Optimize packed ring Rx path with SIMD instructions. Solution of optimization is pretty like vhost, is that split path into batch and single functions. Batch function is further optimized by AVX512 instructions. Also pad desc extra structure to 16 bytes aligned, thus four elements will be saved in one batch.
Signed-off-by Marvin Liu <[email protected]>drivers/net/virtio/Makefile +35
-0@@ -36,6 +36,41 @@ else ifneq ($(filter y,$(CONFIG_RTE_ARCH_ARM) $(CONFIG_RTE_ARCH_ARM64)),) SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_rxtx_simple_neon.c endif +ifneq ($(FORCE_DISABLE_AVX512), y) + CC_AVX512_SUPPORT=\ + $(shell $(CC) -march=native -dM -E - </dev/null 2>&1 | \ + sed '/./{H;$$!d} ; x ; /AVX512F/!d; /AVX512BW/!d; /AVX512VL/!d' | \ + grep -q AVX512 && echo 1) +endif + +ifeq ($(CC_AVX512_SUPPORT), 1) +CFLAGS += -DCC_AVX512_SUPPORT +SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_rxtx_packed_avx.c + +ifeq ($(RTE_TOOLCHAIN), gcc) +ifeq ($(shell test $(GCC_VERSION) -ge 83 && echo 1), 1) +CFLAGS += -DVIRTIO_GCC_UNROLL_PRAGMA +endif +endif + +ifeq ($(RTE_TOOLCHAIN), clang) +ifeq ($(shell test $(CLANG_MAJOR_VERSION)$(CLANG_MINOR_VERSION) -ge 37 && echo 1), 1) +CFLAGS += -DVIRTIO_CLANG_UNROLL_PRAGMA +endif +endif + +ifeq ($(RTE_TOOLCHAIN), icc) +ifeq ($(shell test $(ICC_MAJOR_VERSION) -ge 16 && echo 1), 1) +CFLAGS += -DVIRTIO_ICC_UNROLL_PRAGMA +endif +endif + +CFLAGS_virtio_rxtx_packed_avx.o += -mavx512f -mavx512bw -mavx512vl +ifeq ($(shell test $(GCC_VERSION) -ge 100 && echo 1), 1) +CFLAGS_virtio_rxtx_packed_avx.o += -Wno-zero-length-bounds +endif +endif + ifeq ($(CONFIG_RTE_VIRTIO_USER),y) SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_user/vhost_user.c SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_user/vhost_kernel.cdrivers/net/virtio/meson.build +14
-0@@ -9,6 +9,20 @@ sources += files('virtio_ethdev.c', deps += ['kvargs', 'bus_pci'] if arch_subdir == 'x86' + if '-mno-avx512f' not in machine_args + if cc.has_argument('-mavx512f') and cc.has_argument('-mavx512vl') and cc.has_argument('-mavx512bw') + cflags += ['-mavx512f', '-mavx512bw', '-mavx512vl'] + cflags += ['-DCC_AVX512_SUPPORT'] + if (toolchain == 'gcc' and cc.version().version_compare('>=8.3.0')) + cflags += '-DVHOST_GCC_UNROLL_PRAGMA' + elif (toolchain == 'clang' and cc.version().version_compare('>=3.7.0')) + cflags += '-DVHOST_CLANG_UNROLL_PRAGMA' + elif (toolchain == 'icc' and cc.version().version_compare('>=16.0.0')) + cflags += '-DVHOST_ICC_UNROLL_PRAGMA' + endif + sources += files('virtio_rxtx_packed_avx.c') + endif + endif sources += files('virtio_rxtx_simple_sse.c') elif arch_subdir == 'ppc' sources += files('virtio_rxtx_simple_altivec.c')drivers/net/virtio/virtio_ethdev.h +3
-0@@ -105,6 +105,9 @@ uint16_t virtio_xmit_pkts_inorder(void *tx_queue, struct rte_mbuf **tx_pkts,uint16_t virtio_recv_pkts_vec (void *rx_queue,struct rte_mbuf **rx_pkts,uint16_t nb_pkts); +uint16_t virtio_recv_pkts_packed_vec (void *rx_queue,struct rte_mbuf **rx_pkts, +uint16_t nb_pkts); +int eth_virtio_dev_init (struct rte_eth_dev *eth_dev);void virtio_interrupt_handler (void *param);drivers/net/virtio/virtio_rxtx.c +8
-0@@ -2030,3 +2030,11 @@ virtio_xmit_pkts_inorder(void *tx_queue,return nb_tx; } + +__rte_weak uint16_t +virtio_recv_pkts_packed_vec(void *rx_queue __rte_unused, + struct rte_mbuf **rx_pkts __rte_unused, + uint16_t nb_pkts __rte_unused) +{ +return 0 ; +}drivers/net/virtio/virtio_rxtx_packed_avx.c new file +374
-0@@ -0,0 +1,374 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2010-2020 Intel Corporation +*/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include <rte_net.h> + +#include "virtio_logs.h" +#include "virtio_ethdev.h" +#include "virtio_pci.h" +#include "virtqueue.h" + +#define BYTE_SIZE 8 +/* flag bits offset in packed ring desc higher 64bits */ +#define FLAGS_BITS_OFFSET ((offsetof(struct vring_packed_desc, flags) - \ + offsetof(struct vring_packed_desc, len)) * BYTE_SIZE) + +#define PACKED_FLAGS_MASK ((0ULL | VRING_PACKED_DESC_F_AVAIL_USED) << \ + FLAGS_BITS_OFFSET) + +#define PACKED_BATCH_SIZE (RTE_CACHE_LINE_SIZE / \ + sizeof(struct vring_packed_desc)) +#define PACKED_BATCH_MASK (PACKED_BATCH_SIZE - 1) + +#ifdef VIRTIO_GCC_UNROLL_PRAGMA +#define virtio_for_each_try_unroll (iter, val, size) _Pragma("GCC unroll 4") \ + for (iter = val; iter < size; iter++) +#endif + +#ifdef VIRTIO_CLANG_UNROLL_PRAGMA +#define virtio_for_each_try_unroll (iter, val, size) _Pragma("unroll 4") \ + for (iter = val; iter < size; iter++) +#endif + +#ifdef VIRTIO_ICC_UNROLL_PRAGMA +#define virtio_for_each_try_unroll (iter, val, size) _Pragma("unroll (4)") \ + for (iter = val; iter < size; iter++) +#endif + +#ifndef virtio_for_each_try_unroll +#define virtio_for_each_try_unroll (iter, val, num) \ + for (iter = val; iter < num; iter++) +#endif + +static inline void +virtio_update_batch_stats (struct virtnet_stats *stats, +uint16_t pkt_len1, +uint16_t pkt_len2, +uint16_t pkt_len3, +uint16_t pkt_len4) +{ + stats->bytes += pkt_len1; + stats->bytes += pkt_len2; + stats->bytes += pkt_len3; + stats->bytes += pkt_len4; +} + +/* Optionally fill offload information in structure */ +static inline int +virtio_vec_rx_offload (struct rte_mbuf *m,struct virtio_net_hdr *hdr) +{ +struct rte_net_hdr_lens hdr_lens; +uint32_t hdrlen, ptype; +int l4_supported =0 ; + +/* nothing to do */ +if (hdr->flags ==0 ) +return 0 ; + +/* GSO not support in vec path, skip check */ + m->ol_flags |=PKT_RX_IP_CKSUM_UNKNOWN ; + + ptype =rte_net_get_ptype (m, &hdr_lens,RTE_PTYPE_ALL_MASK ); + m->packet_type = ptype; +if ((ptype &RTE_PTYPE_L4_MASK ) ==RTE_PTYPE_L4_TCP || + (ptype &RTE_PTYPE_L4_MASK ) ==RTE_PTYPE_L4_UDP || + (ptype &RTE_PTYPE_L4_MASK ) ==RTE_PTYPE_L4_SCTP ) + l4_supported =1 ; + +if (hdr->flags &VIRTIO_NET_HDR_F_NEEDS_CSUM ) { + hdrlen = hdr_lens.l2_len + hdr_lens.l3_len + hdr_lens.l4_len; +if (hdr->csum_start <= hdrlen && l4_supported) { + m->ol_flags |=PKT_RX_L4_CKSUM_NONE ; + }else { +/* Unknown proto or tunnel, do sw cksum. We can assume +* the cksum field is in the first segment since the +* buffers we provided to the host are large enough. +* In case of SCTP, this will be wrong since it's a CRC +* but there's nothing we can do. +*/ +uint16_t csum =0 , off; + +rte_raw_cksum_mbuf (m, hdr->csum_start, +rte_pktmbuf_pkt_len (m) - hdr->csum_start, + &csum); +if (likely (csum !=0xffff )) + csum = ~csum; + off = hdr->csum_offset + hdr->csum_start; +if (rte_pktmbuf_data_len (m) >= off +1 ) + *rte_pktmbuf_mtod_offset(m, uint16_t *, + off) = csum; + } + }else if (hdr->flags &VIRTIO_NET_HDR_F_DATA_VALID && l4_supported) { + m->ol_flags |=PKT_RX_L4_CKSUM_GOOD ; + } + +return 0 ; +} + +static inline uint16_t +virtqueue_dequeue_batch_packed_vec (struct virtnet_rx *rxvq, +struct rte_mbuf **rx_pkts) +{ +struct virtqueue *vq = rxvq->vq; +struct virtio_hw *hw = vq->hw; +uint16_t hdr_size = hw->vtnet_hdr_size; +uint64_t addrs[PACKED_BATCH_SIZE ]; +uint16_t id = vq->vq_used_cons_idx; +uint8_t desc_stats; +uint16_t i; +void *desc_addr; + +if (id &PACKED_BATCH_MASK ) +return -1 ; + +if (unlikely ((id +PACKED_BATCH_SIZE ) > vq->vq_nentries)) +return -1 ; + +/* only care avail/used bits */ +__m512i v_mask =_mm512_maskz_set1_epi64 (0xaa ,PACKED_FLAGS_MASK ); + desc_addr = &vq->vq_packed.ring.desc[id]; + +__m512i v_desc =_mm512_loadu_si512 (desc_addr); +__m512i v_flag =_mm512_and_epi64 (v_desc, v_mask); + +__m512i v_used_flag =_mm512_setzero_si512 (); +if (vq->vq_packed.used_wrap_counter) + v_used_flag =_mm512_maskz_set1_epi64 (0xaa ,PACKED_FLAGS_MASK ); + +/* Check all descs are used */ + desc_stats =_mm512_cmpneq_epu64_mask (v_flag, v_used_flag); +if (desc_stats) +return -1 ; + +virtio_for_each_try_unroll (i,0 ,PACKED_BATCH_SIZE ) { + rx_pkts[i] = (struct rte_mbuf *)vq->vq_descx[id + i].cookie; +rte_packet_prefetch (rte_pktmbuf_mtod(rx_pkts [i],void *)); + + addrs[i] = (uint64_t )rx_pkts[i]->rx_descriptor_fields1; + } + +/* +* load len from desc, store into mbuf pkt_len and data_len +* len limiated by l6bit buf_len, pkt_len[16:31] can be ignored +*/ +const __mmask16 mask =0x6 |0x6 <<4 |0x6 <<8 |0x6 <<12 ; +__m512i values =_mm512_maskz_shuffle_epi32 (mask, v_desc,0xAA ); + +/* reduce hdr_len from pkt_len and data_len */ +__m512i mbuf_len_offset =_mm512_maskz_set1_epi32 (mask, + (uint32_t )-hdr_size); + +__m512i v_value =_mm512_add_epi32 (values, mbuf_len_offset); + +/* assert offset of data_len */ +RTE_BUILD_BUG_ON (offsetof(struct rte_mbuf , data_len) != + offsetof(struct rte_mbuf , rx_descriptor_fields1) +8 ); + +__m512i v_index =_mm512_set_epi64 (addrs[3 ] +8 , addrs[3 ], + addrs[2 ] +8 , addrs[2 ], + addrs[1 ] +8 , addrs[1 ], + addrs[0 ] +8 , addrs[0 ]); +/* batch store into mbufs */ +_mm512_i64scatter_epi64 (0 , v_index, v_value,1 ); + +if (hw->has_rx_offload) { +virtio_for_each_try_unroll (i,0 ,PACKED_BATCH_SIZE ) { +char *addr = (char *)rx_pkts[i]->buf_addr + +RTE_PKTMBUF_HEADROOM - hdr_size; +virtio_vec_rx_offload (rx_pkts[i], + (struct virtio_net_hdr *)addr); + } + } + +virtio_update_batch_stats (&rxvq->stats, rx_pkts[0 ]->pkt_len, + rx_pkts[1 ]->pkt_len, rx_pkts[2 ]->pkt_len, + rx_pkts[3 ]->pkt_len); + + vq->vq_free_cnt +=PACKED_BATCH_SIZE ; + + vq->vq_used_cons_idx +=PACKED_BATCH_SIZE ; +if (vq->vq_used_cons_idx >= vq->vq_nentries) { + vq->vq_used_cons_idx -= vq->vq_nentries; + vq->vq_packed.used_wrap_counter ^=1 ; + } + +return 0 ; +} + +static uint16_t +virtqueue_dequeue_single_packed_vec (struct virtnet_rx *rxvq, +struct rte_mbuf **rx_pkts) +{ +uint16_t used_idx, id; +uint32_t len; +struct virtqueue *vq = rxvq->vq; +struct virtio_hw *hw = vq->hw; +uint32_t hdr_size = hw->vtnet_hdr_size; +struct virtio_net_hdr *hdr; +struct vring_packed_desc *desc; +struct rte_mbuf *cookie; + + desc = vq->vq_packed.ring.desc; + used_idx = vq->vq_used_cons_idx; +if (!desc_is_used (&desc[used_idx], vq)) +return -1 ; + + len = desc[used_idx].len; + id = desc[used_idx].id; + cookie = (struct rte_mbuf *)vq->vq_descx[id].cookie; +if (unlikely (cookie ==NULL )) { +PMD_DRV_LOG (ERR ,"vring descriptor with no mbuf cookie at %u" , + vq->vq_used_cons_idx); +return -1 ; + } +rte_prefetch0 (cookie); +rte_packet_prefetch (rte_pktmbuf_mtod(cookie ,void *)); + + cookie->data_off =RTE_PKTMBUF_HEADROOM ; + cookie->ol_flags =0 ; + cookie->pkt_len = (uint32_t )(len - hdr_size); + cookie->data_len = (uint32_t )(len - hdr_size); + + hdr = (struct virtio_net_hdr *)((char *)cookie->buf_addr + +RTE_PKTMBUF_HEADROOM - hdr_size); +if (hw->has_rx_offload) +virtio_vec_rx_offload (cookie, hdr); + + *rx_pkts = cookie; + + rxvq->stats.bytes += cookie->pkt_len; + + vq->vq_free_cnt++; + vq->vq_used_cons_idx++; +if (vq->vq_used_cons_idx >= vq->vq_nentries) { + vq->vq_used_cons_idx -= vq->vq_nentries; + vq->vq_packed.used_wrap_counter ^=1 ; + } + +return 0 ; +} + +static inline void +virtio_recv_refill_packed_vec (struct virtnet_rx *rxvq, +struct rte_mbuf **cookie, +uint16_t num) +{ +struct virtqueue *vq = rxvq->vq; +struct vring_packed_desc *start_dp = vq->vq_packed.ring.desc; +uint16_t flags = vq->vq_packed.cached_flags; +struct virtio_hw *hw = vq->hw; +struct vq_desc_extra *dxp; +uint16_t idx, i; +uint16_t batch_num, total_num =0 ; +uint16_t head_idx = vq->vq_avail_idx; +uint16_t head_flag = vq->vq_packed.cached_flags; +uint64_t addr; + +do { + idx = vq->vq_avail_idx; + + batch_num =PACKED_BATCH_SIZE ; +if (unlikely ((idx +PACKED_BATCH_SIZE ) > vq->vq_nentries)) + batch_num = vq->vq_nentries - idx; +if (unlikely ((total_num + batch_num) > num)) + batch_num = num - total_num; + +virtio_for_each_try_unroll (i,0 , batch_num) { + dxp = &vq->vq_descx[idx + i]; + dxp->cookie = (void *)cookie[total_num + i]; + + addr =VIRTIO_MBUF_ADDR (cookie[total_num + i], vq) + +RTE_PKTMBUF_HEADROOM - hw->vtnet_hdr_size; + start_dp[idx + i].addr = addr; + start_dp[idx + i].len = cookie[total_num + i]->buf_len + -RTE_PKTMBUF_HEADROOM + hw->vtnet_hdr_size; +if (total_num || i) { +virtqueue_store_flags_packed (&start_dp[idx + i], + flags, hw->weak_barriers); + } + } + + vq->vq_avail_idx += batch_num; +if (vq->vq_avail_idx >= vq->vq_nentries) { + vq->vq_avail_idx -= vq->vq_nentries; + vq->vq_packed.cached_flags ^= +VRING_PACKED_DESC_F_AVAIL_USED ; + flags = vq->vq_packed.cached_flags; + } + total_num += batch_num; + }while (total_num < num); + +virtqueue_store_flags_packed (&start_dp[head_idx], head_flag, + hw->weak_barriers); + vq->vq_free_cnt = (uint16_t )(vq->vq_free_cnt - num); +} + +uint16_t +virtio_recv_pkts_packed_vec (void *rx_queue, +struct rte_mbuf **rx_pkts, +uint16_t nb_pkts) +{ +struct virtnet_rx *rxvq = rx_queue; +struct virtqueue *vq = rxvq->vq; +struct virtio_hw *hw = vq->hw; +uint16_t num, nb_rx =0 ; +uint32_t nb_enqueued =0 ; +uint16_t free_cnt = vq->vq_free_thresh; + +if (unlikely (hw->started ==0 )) +return nb_rx; + + num =RTE_MIN (VIRTIO_MBUF_BURST_SZ , nb_pkts); +if (likely (num >PACKED_BATCH_SIZE )) + num = num - ((vq->vq_used_cons_idx + num) %PACKED_BATCH_SIZE ); + +while (num) { +if (!virtqueue_dequeue_batch_packed_vec (rxvq, + &rx_pkts[nb_rx])) { + nb_rx +=PACKED_BATCH_SIZE ; + num -=PACKED_BATCH_SIZE ; +continue ; + } +if (!virtqueue_dequeue_single_packed_vec (rxvq, + &rx_pkts[nb_rx])) { + nb_rx++; + num--; +continue ; + } +break ; + }; + +PMD_RX_LOG (DEBUG ,"dequeue:%d" , num); + + rxvq->stats.packets += nb_rx; + +if (likely (vq->vq_free_cnt >= free_cnt)) { +struct rte_mbuf *new_pkts[free_cnt]; +if (likely (rte_pktmbuf_alloc_bulk (rxvq->mpool, new_pkts, + free_cnt) ==0 )) { +virtio_recv_refill_packed_vec (rxvq, new_pkts, + free_cnt); + nb_enqueued += free_cnt; + }else { +struct rte_eth_dev *dev = + &rte_eth_devices[rxvq->port_id]; + dev->data->rx_mbuf_alloc_failed += free_cnt; + } + } + +if (likely (nb_enqueued)) { +if (unlikely (virtqueue_kick_prepare_packed (vq))) { +virtqueue_notify (vq); +PMD_RX_LOG (DEBUG ,"Notified" ); + } + } + +return nb_rx; +}drivers/net/virtio/virtio_user_ethdev.c +14
-2@@ -528,6 +528,7 @@ virtio_user_eth_dev_alloc(struct rte_vdev_device *vdev) hw->use_msix =1 ; hw->modern =0 ; hw->use_vec_rx =0 ; + hw->use_vec_tx =0 ; hw->use_inorder_rx =0 ; hw->use_inorder_tx =0 ; hw->virtio_user_dev = dev;@@ -739,8 +740,19 @@ virtio_user_pmd_probe(struct rte_vdev_device *dev) goto end; } -if (vectorized) - hw->use_vec_rx =1 ; +if (vectorized) { +if (packed_vq) { +#if defined(CC_AVX512_SUPPORT ) + hw->use_vec_rx =1 ; + hw->use_vec_tx =1 ; +#else +PMD_INIT_LOG (INFO , +"building environment do not support packed ring vectorized" ); +#endif + }else { + hw->use_vec_rx =1 ; + } + }rte_eth_dev_probing_finish (eth_dev); ret =0 ;drivers/net/virtio/virtqueue.h +0
-0
drivers/net/virtio/virtqueue.h struct vq_desc_extra { · line 243
Quoted 6 lines
drivers/net/virtio/virtqueue.h +2
-1@@ -239,7 +239,8 @@ struct vq_desc_extra {void *cookie;uint16_t ndescs;uint16_t next; -}; +uint8_t padding[4 ]; +} __rte_packed __rte_aligned(16);
Can't this introduce a performance impact for the non-vectorized case? I think of worse cache liens utilization.
For example with a burst of 32 descriptors with 32B cachelines, before it would take 14 cachelines, after 16. So for each burst, one could face 2 extra cache misses.
If you could run non-vectorized benchamrks with and without that patch, I would be grateful.
Thanks,
Maxime
Re: [dpdk-dev] [PATCH v10 6/9] net/virtio: add vectorized packed ring Rx path
Quoted 580 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Monday, April 27, 2020 7:21 PM
To: Liu, Yong <[email protected]>; Ye, Xiaolong <[email protected]>; Wang, Zhihong <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v10 6/9] net/virtio: add vectorized packed ring Rx pathdrivers/net/virtio/Makefile else ifneq ($(filter y,$(CONFIG_RTE_ARCH_ARM)
Quoted 13 lines · Marvin Liu
Optimize packed ring Rx path with SIMD instructions. Solution of optimization is pretty like vhost, is that split path into batch and single functions. Batch function is further optimized by AVX512 instructions. Also pad desc extra structure to 16 bytes aligned, thus four elements will be saved in one batch.
Signed-off-by Marvin Liu <[email protected]>drivers/net/virtio/Makefile +0
-0@@ -36,6 +36,41 @@ else ifneq ($(filter y,$(CONFIG_RTE_ARCH_ARM)$(CONFIG_RTE_ARCH_ARM64)),)
Quoted 12 lines
drivers/net/virtio/Makefile +9
-0SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_rxtx_simple_neon.c endif +ifneq ($(FORCE_DISABLE_AVX512), y) + CC_AVX512_SUPPORT=\ + $(shell $(CC) -march=native -dM -E - </dev/null 2>&1 | \ + sed '/./{H;$$!d} ; x ; /AVX512F/!d; /AVX512BW/!d; /AVX512VL/!d' | \ + grep -q AVX512 && echo 1) +endif + +ifeq ($(CC_AVX512_SUPPORT), 1) +CFLAGS += -DCC_AVX512_SUPPORTdrivers/net/virtio/Makefile else ifneq ($(filter y,$(CONFIG_RTE_ARCH_ARM) $(CONFIG_RTE_ARCH_ARM64)),)
Quoted 10 lines
drivers/net/virtio/Makefile +10
-0+SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_rxtx_packed_avx.c + +ifeq ($(RTE_TOOLCHAIN), gcc) +ifeq ($(shell test $(GCC_VERSION) -ge 83 && echo 1), 1) +CFLAGS += -DVIRTIO_GCC_UNROLL_PRAGMA +endif +endif + +ifeq ($(RTE_TOOLCHAIN), clang) +ifeq ($(shell test $(CLANG_MAJOR_VERSION)$(CLANG_MINOR_VERSION) -ge 37 && echo 1), 1)
Quoted 24 lines
drivers/net/virtio/Makefile +16
-0+CFLAGS += -DVIRTIO_CLANG_UNROLL_PRAGMA +endif +endif + +ifeq ($(RTE_TOOLCHAIN), icc) +ifeq ($(shell test $(ICC_MAJOR_VERSION) -ge 16 && echo 1), 1) +CFLAGS += -DVIRTIO_ICC_UNROLL_PRAGMA +endif +endif + +CFLAGS_virtio_rxtx_packed_avx.o += -mavx512f -mavx512bw -mavx512vl +ifeq ($(shell test $(GCC_VERSION) -ge 100 && echo 1), 1) +CFLAGS_virtio_rxtx_packed_avx.o += -Wno-zero-length-bounds +endif +endif + ifeq ($(CONFIG_RTE_VIRTIO_USER),y) SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_user/vhost_user.c SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_user/vhost_kernel.cdrivers/net/virtio/meson.build +0
-0drivers/net/virtio/meson.build sources += files('virtio_ethdev.c', · line 13
Quoted 5 lines
drivers/net/virtio/meson.build +2
-0@@ -9,6 +9,20 @@ sources += files('virtio_ethdev.c', deps += ['kvargs', 'bus_pci'] if arch_subdir == 'x86' + if '-mno-avx512f' not in machine_args + if cc.has_argument('-mavx512f') and cc.has_argument('-mavx512vl') and
cc.has_argument('-mavx512bw')drivers/net/virtio/meson.build sources += files('virtio_ethdev.c',
Quoted 3 lines
drivers/net/virtio/meson.build +3
-0+ cflags += ['-mavx512f', '-mavx512bw', '-mavx512vl'] + cflags += ['-DCC_AVX512_SUPPORT'] + if (toolchain == 'gcc' andcc.version().version_compare('>=8.3.0'))
drivers/net/virtio/meson.build sources += files('virtio_ethdev.c', · line 18
Quoted 2 lines
drivers/net/virtio/meson.build +2
-0+ cflags += '-DVHOST_GCC_UNROLL_PRAGMA' + elif (toolchain == 'clang' andcc.version().version_compare('>=3.7.0'))
drivers/net/virtio/meson.build sources += files('virtio_ethdev.c', · line 19
Quoted 1 line
drivers/net/virtio/meson.build +1
-0+ cflags += '-
DVHOST_CLANG_UNROLL_PRAGMA'drivers/net/virtio/meson.build sources += files('virtio_ethdev.c', · line 20
Quoted 1 line
drivers/net/virtio/meson.build +1
-0+ elif (toolchain == 'icc' andcc.version().version_compare('>=16.0.0'))
Review
Quoted 9 lines
drivers/net/virtio/meson.build +5
-0+ cflags += '-DVHOST_ICC_UNROLL_PRAGMA' + endif + sources += files('virtio_rxtx_packed_avx.c') + endif + endif sources += files('virtio_rxtx_simple_sse.c') elif arch_subdir == 'ppc' sources += files('virtio_rxtx_simple_altivec.c')(quoted diff) +0
-0
b/drivers/net/virtio/virtio_ethdev.hdrivers/net/virtio/virtio_ethdev.h uint16_t virtio_xmit_pkts_inorder(void *tx_queue,
Quoted 4 lines
index
febaf17a8..5c112cac7100644drivers/net/virtio/virtio_ethdev.h +0
-0@@ -105,6 +105,9 @@ uint16_t virtio_xmit_pkts_inorder(void *tx_queue,struct
rte_mbuf**tx_pkts,drivers/net/virtio/virtio_ethdev.h uint16_t virtio_xmit_pkts_inorder(void *tx_queue, struct rte_mbuf **tx_pkts,
Quoted 4 lines
drivers/net/virtio/virtio_ethdev.h +1
-0uint16_t virtio_recv_pkts_vec (void *rx_queue,struct rte_mbuf **rx_pkts,uint16_t nb_pkts); +uint16_t virtio_recv_pkts_packed_vec(void *rx_queue, struct rte_mbuf**rx_pkts,
Review
Quoted 22 lines
drivers/net/virtio/virtio_ethdev.h +2
-0+ uint16_t nb_pkts); +int eth_virtio_dev_init (struct rte_eth_dev *eth_dev);void virtio_interrupt_handler (void *param);drivers/net/virtio/virtio_rxtx.c +8
-0@@ -2030,3 +2030,11 @@ virtio_xmit_pkts_inorder(void *tx_queue,return nb_tx; } + +__rte_weak uint16_t +virtio_recv_pkts_packed_vec(void *rx_queue __rte_unused, + struct rte_mbuf **rx_pkts __rte_unused, + uint16_t nb_pkts __rte_unused) +{ +return 0 ; +}(quoted diff) +0
-0
b/drivers/net/virtio/virtio_rxtx_packed_avx.cQuoted 18 lines
new file mode 100644
index 000000000..8a7b459ebdrivers/net/virtio/virtio_rxtx_packed_avx.c new file +13
-0@@ -0,0 +1,374 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2010-2020 Intel Corporation +*/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include <rte_net.h> + +#include "virtio_logs.h" drivers/net/virtio/virtio_rxtx_packed_avx.c line 23
Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +10
-0+#include "virtio_ethdev.h" +#include "virtio_pci.h" +#include "virtqueue.h" + +#define BYTE_SIZE 8 +/* flag bits offset in packed ring desc higher 64bits */ +#define FLAGS_BITS_OFFSET ((offsetof(struct vring_packed_desc, flags) - \ + offsetof(struct vring_packed_desc, len)) * BYTE_SIZE) + +#define PACKED_FLAGS_MASK ((0ULL |
VRING_PACKED_DESC_F_AVAIL_USED) << \drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 8 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +8
-0+ FLAGS_BITS_OFFSET) + +#define PACKED_BATCH_SIZE (RTE_CACHE_LINE_SIZE / \ + sizeof(struct vring_packed_desc)) +#define PACKED_BATCH_MASK (PACKED_BATCH_SIZE - 1) + +#ifdef VIRTIO_GCC_UNROLL_PRAGMA +#define virtio_for_each_try_unroll (iter, val, size) _Pragma("GCC unroll 4")\
Quoted 49 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +49
-0+ for (iter = val; iter < size; iter++) +#endif + +#ifdef VIRTIO_CLANG_UNROLL_PRAGMA +#define virtio_for_each_try_unroll (iter, val, size) _Pragma("unroll 4") \ + for (iter = val; iter < size; iter++) +#endif + +#ifdef VIRTIO_ICC_UNROLL_PRAGMA +#define virtio_for_each_try_unroll (iter, val, size) _Pragma("unroll (4)") \ + for (iter = val; iter < size; iter++) +#endif + +#ifndef virtio_for_each_try_unroll +#define virtio_for_each_try_unroll (iter, val, num) \ + for (iter = val; iter < num; iter++) +#endif + +static inline void +virtio_update_batch_stats (struct virtnet_stats *stats, +uint16_t pkt_len1, +uint16_t pkt_len2, +uint16_t pkt_len3, +uint16_t pkt_len4) +{ + stats->bytes += pkt_len1; + stats->bytes += pkt_len2; + stats->bytes += pkt_len3; + stats->bytes += pkt_len4; +} + +/* Optionally fill offload information in structure */ +static inline int +virtio_vec_rx_offload (struct rte_mbuf *m,struct virtio_net_hdr *hdr) +{ +struct rte_net_hdr_lens hdr_lens; +uint32_t hdrlen, ptype; +int l4_supported =0 ; + +/* nothing to do */ +if (hdr->flags ==0 ) +return 0 ; + +/* GSO not support in vec path, skip check */ + m->ol_flags |=PKT_RX_IP_CKSUM_UNKNOWN ; + + ptype =rte_net_get_ptype (m, &hdr_lens,RTE_PTYPE_ALL_MASK ); + m->packet_type = ptype; + if ((ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_TCP ||drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +10
-0+ (ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_UDP || + (ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_SCTP) + l4_supported =1 ; + +if (hdr->flags &VIRTIO_NET_HDR_F_NEEDS_CSUM ) { + hdrlen = hdr_lens.l2_len + hdr_lens.l3_len + hdr_lens.l4_len; +if (hdr->csum_start <= hdrlen && l4_supported) { + m->ol_flags |=PKT_RX_L4_CKSUM_NONE ; + }else { +/* Unknown proto or tunnel, do sw cksum. We can assume
Quoted 8 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +8
-0+* the cksum field is in the first segment since the +* buffers we provided to the host are large enough. +* In case of SCTP, this will be wrong since it's a CRC +* but there's nothing we can do. +*/ +uint16_t csum =0 , off; + + rte_raw_cksum_mbuf(m, hdr->csum_start,drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +10
-0+rte_pktmbuf_pkt_len (m) - hdr->csum_start, + &csum); +if (likely (csum !=0xffff )) + csum = ~csum; + off = hdr->csum_offset + hdr->csum_start; +if (rte_pktmbuf_data_len (m) >= off +1 ) + *rte_pktmbuf_mtod_offset(m, uint16_t *, + off) = csum; + } + } else if (hdr->flags & VIRTIO_NET_HDR_F_DATA_VALID &&
l4_supported) {Quoted 17 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +17
-0+ m->ol_flags |=PKT_RX_L4_CKSUM_GOOD ; + } + +return 0 ; +} + +static inline uint16_t +virtqueue_dequeue_batch_packed_vec (struct virtnet_rx *rxvq, +struct rte_mbuf **rx_pkts) +{ +struct virtqueue *vq = rxvq->vq; +struct virtio_hw *hw = vq->hw; +uint16_t hdr_size = hw->vtnet_hdr_size; +uint64_t addrs[PACKED_BATCH_SIZE ]; +uint16_t id = vq->vq_used_cons_idx; +uint8_t desc_stats; +uint16_t i;drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +10
-0+void *desc_addr; + +if (id &PACKED_BATCH_MASK ) +return -1 ; + +if (unlikely ((id +PACKED_BATCH_SIZE ) > vq->vq_nentries)) +return -1 ; + +/* only care avail/used bits */ + __m512i v_mask = _mm512_maskz_set1_epi64(0xaa,
PACKED_FLAGS_MASK);drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 8 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +8
-0+ desc_addr = &vq->vq_packed.ring.desc[id]; + +__m512i v_desc =_mm512_loadu_si512 (desc_addr); +__m512i v_flag =_mm512_and_epi64 (v_desc, v_mask); + +__m512i v_used_flag =_mm512_setzero_si512 (); +if (vq->vq_packed.used_wrap_counter) + v_used_flag = _mm512_maskz_set1_epi64(0xaa,
PACKED_FLAGS_MASK);Quoted 9 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +9
-0+ +/* Check all descs are used */ + desc_stats =_mm512_cmpneq_epu64_mask (v_flag, v_used_flag); +if (desc_stats) +return -1 ; + +virtio_for_each_try_unroll (i,0 ,PACKED_BATCH_SIZE ) { + rx_pkts[i] = (struct rte_mbuf *)vq->vq_descx[id + i].cookie; +rte_packet_prefetch (rte_pktmbuf_mtod(rx_pkts [i],void *));drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +10
-0+ + addrs[i] = (uint64_t )rx_pkts[i]->rx_descriptor_fields1; + } + +/* +* load len from desc, store into mbuf pkt_len and data_len +* len limiated by l6bit buf_len, pkt_len[16:31] can be ignored +*/ +const __mmask16 mask =0x6 |0x6 <<4 |0x6 <<8 |0x6 <<12 ; + __m512i values = _mm512_maskz_shuffle_epi32(mask, v_desc,
0xAA);Quoted 55 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +55
-0+ +/* reduce hdr_len from pkt_len and data_len */ +__m512i mbuf_len_offset =_mm512_maskz_set1_epi32 (mask, + (uint32_t )-hdr_size); + +__m512i v_value =_mm512_add_epi32 (values, mbuf_len_offset); + +/* assert offset of data_len */ +RTE_BUILD_BUG_ON (offsetof(struct rte_mbuf , data_len) != + offsetof(struct rte_mbuf , rx_descriptor_fields1) +8 ); + +__m512i v_index =_mm512_set_epi64 (addrs[3 ] +8 , addrs[3 ], + addrs[2 ] +8 , addrs[2 ], + addrs[1 ] +8 , addrs[1 ], + addrs[0 ] +8 , addrs[0 ]); +/* batch store into mbufs */ +_mm512_i64scatter_epi64 (0 , v_index, v_value,1 ); + +if (hw->has_rx_offload) { +virtio_for_each_try_unroll (i,0 ,PACKED_BATCH_SIZE ) { +char *addr = (char *)rx_pkts[i]->buf_addr + +RTE_PKTMBUF_HEADROOM - hdr_size; +virtio_vec_rx_offload (rx_pkts[i], + (struct virtio_net_hdr *)addr); + } + } + +virtio_update_batch_stats (&rxvq->stats, rx_pkts[0 ]->pkt_len, + rx_pkts[1 ]->pkt_len, rx_pkts[2 ]->pkt_len, + rx_pkts[3 ]->pkt_len); + + vq->vq_free_cnt +=PACKED_BATCH_SIZE ; + + vq->vq_used_cons_idx +=PACKED_BATCH_SIZE ; +if (vq->vq_used_cons_idx >= vq->vq_nentries) { + vq->vq_used_cons_idx -= vq->vq_nentries; + vq->vq_packed.used_wrap_counter ^=1 ; + } + +return 0 ; +} + +static uint16_t +virtqueue_dequeue_single_packed_vec (struct virtnet_rx *rxvq, +struct rte_mbuf **rx_pkts) +{ +uint16_t used_idx, id; +uint32_t len; +struct virtqueue *vq = rxvq->vq; +struct virtio_hw *hw = vq->hw; +uint32_t hdr_size = hw->vtnet_hdr_size; +struct virtio_net_hdr *hdr; +struct vring_packed_desc *desc; +struct rte_mbuf *cookie; +drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +10
-0+ desc = vq->vq_packed.ring.desc; + used_idx = vq->vq_used_cons_idx; +if (!desc_is_used (&desc[used_idx], vq)) +return -1 ; + + len = desc[used_idx].len; + id = desc[used_idx].id; + cookie = (struct rte_mbuf *)vq->vq_descx[id].cookie; +if (unlikely (cookie ==NULL )) { + PMD_DRV_LOG(ERR, "vring descriptor with no mbuf cookieat %u",
drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 13 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +13
-0+ vq->vq_used_cons_idx); +return -1 ; + } +rte_prefetch0 (cookie); +rte_packet_prefetch (rte_pktmbuf_mtod(cookie ,void *)); + + cookie->data_off =RTE_PKTMBUF_HEADROOM ; + cookie->ol_flags =0 ; + cookie->pkt_len = (uint32_t )(len - hdr_size); + cookie->data_len = (uint32_t )(len - hdr_size); + + hdr = (struct virtio_net_hdr *)((char *)cookie->buf_addr + + RTE_PKTMBUF_HEADROOM -
hdr_size);Quoted 37 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +37
-0+if (hw->has_rx_offload) +virtio_vec_rx_offload (cookie, hdr); + + *rx_pkts = cookie; + + rxvq->stats.bytes += cookie->pkt_len; + + vq->vq_free_cnt++; + vq->vq_used_cons_idx++; +if (vq->vq_used_cons_idx >= vq->vq_nentries) { + vq->vq_used_cons_idx -= vq->vq_nentries; + vq->vq_packed.used_wrap_counter ^=1 ; + } + +return 0 ; +} + +static inline void +virtio_recv_refill_packed_vec (struct virtnet_rx *rxvq, +struct rte_mbuf **cookie, +uint16_t num) +{ +struct virtqueue *vq = rxvq->vq; +struct vring_packed_desc *start_dp = vq->vq_packed.ring.desc; +uint16_t flags = vq->vq_packed.cached_flags; +struct virtio_hw *hw = vq->hw; +struct vq_desc_extra *dxp; +uint16_t idx, i; +uint16_t batch_num, total_num =0 ; +uint16_t head_idx = vq->vq_avail_idx; +uint16_t head_flag = vq->vq_packed.cached_flags; +uint64_t addr; + + do { + idx = vq->vq_avail_idx; + + batch_num = PACKED_BATCH_SIZE;drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +10
-0+if (unlikely ((idx +PACKED_BATCH_SIZE ) > vq->vq_nentries)) + batch_num = vq->vq_nentries - idx; +if (unlikely ((total_num + batch_num) > num)) + batch_num = num - total_num; + +virtio_for_each_try_unroll (i,0 , batch_num) { + dxp = &vq->vq_descx[idx + i]; + dxp->cookie = (void *)cookie[total_num + i]; + + addr = VIRTIO_MBUF_ADDR(cookie[total_num + i],vq) +
drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 8 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +1
-0+ RTE_PKTMBUF_HEADROOM - hw-
vtnet_hdr_size;drivers/net/virtio/virtio_rxtx_packed_avx.c new file +3
-0+ start_dp[idx + i].addr = addr; + start_dp[idx + i].len = cookie[total_num + i]->buf_len + - RTE_PKTMBUF_HEADROOM + hw-
vtnet_hdr_size;drivers/net/virtio/virtio_rxtx_packed_avx.c new file +2
-0+ if (total_num || i) { + virtqueue_store_flags_packed(&start_dp[idx+ i],
Quoted 27 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +27
-0+ flags, hw->weak_barriers); + } + } + + vq->vq_avail_idx += batch_num; +if (vq->vq_avail_idx >= vq->vq_nentries) { + vq->vq_avail_idx -= vq->vq_nentries; + vq->vq_packed.cached_flags ^= +VRING_PACKED_DESC_F_AVAIL_USED ; + flags = vq->vq_packed.cached_flags; + } + total_num += batch_num; + }while (total_num < num); + +virtqueue_store_flags_packed (&start_dp[head_idx], head_flag, + hw->weak_barriers); + vq->vq_free_cnt = (uint16_t )(vq->vq_free_cnt - num); +} + +uint16_t +virtio_recv_pkts_packed_vec (void *rx_queue, +struct rte_mbuf **rx_pkts, +uint16_t nb_pkts) +{ +struct virtnet_rx *rxvq = rx_queue; +struct virtqueue *vq = rxvq->vq; +struct virtio_hw *hw = vq->hw;drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +10
-0+uint16_t num, nb_rx =0 ; +uint32_t nb_enqueued =0 ; +uint16_t free_cnt = vq->vq_free_thresh; + +if (unlikely (hw->started ==0 )) +return nb_rx; + + num =RTE_MIN (VIRTIO_MBUF_BURST_SZ , nb_pkts); +if (likely (num >PACKED_BATCH_SIZE )) + num = num - ((vq->vq_used_cons_idx + num) %
PACKED_BATCH_SIZE);Review
Quoted 45 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +44
-0+ +while (num) { +if (!virtqueue_dequeue_batch_packed_vec (rxvq, + &rx_pkts[nb_rx])) { + nb_rx +=PACKED_BATCH_SIZE ; + num -=PACKED_BATCH_SIZE ; +continue ; + } +if (!virtqueue_dequeue_single_packed_vec (rxvq, + &rx_pkts[nb_rx])) { + nb_rx++; + num--; +continue ; + } +break ; + }; + +PMD_RX_LOG (DEBUG ,"dequeue:%d" , num); + + rxvq->stats.packets += nb_rx; + +if (likely (vq->vq_free_cnt >= free_cnt)) { +struct rte_mbuf *new_pkts[free_cnt]; +if (likely (rte_pktmbuf_alloc_bulk (rxvq->mpool, new_pkts, + free_cnt) ==0 )) { +virtio_recv_refill_packed_vec (rxvq, new_pkts, + free_cnt); + nb_enqueued += free_cnt; + }else { +struct rte_eth_dev *dev = + &rte_eth_devices[rxvq->port_id]; + dev->data->rx_mbuf_alloc_failed += free_cnt; + } + } + +if (likely (nb_enqueued)) { +if (unlikely (virtqueue_kick_prepare_packed (vq))) { +virtqueue_notify (vq); +PMD_RX_LOG (DEBUG ,"Notified" ); + } + } + +return nb_rx; +}(quoted diff) +0
-0
b/drivers/net/virtio/virtio_user_ethdev.cdrivers/net/virtio/virtio_user_ethdev.c virtio_user_eth_dev_alloc(struct rte_vdev_device
Quoted 4 lines
index
40ad786cc..c54698ad1100644drivers/net/virtio/virtio_user_ethdev.c +0
-0@@ -528,6 +528,7 @@ virtio_user_eth_dev_alloc(struct rte_vdev_device*vdev)
drivers/net/virtio/virtio_user_ethdev.c virtio_user_pmd_probe(struct rte_vdev_device
Quoted 8 lines
drivers/net/virtio/virtio_user_ethdev.c +1
-0hw->use_msix =1 ; hw->modern =0 ; hw->use_vec_rx =0 ; + hw->use_vec_tx =0 ; hw->use_inorder_rx =0 ; hw->use_inorder_tx =0 ; hw->virtio_user_dev = dev;@@ -739,8 +740,19 @@ virtio_user_pmd_probe(struct rte_vdev_device*dev)
drivers/net/virtio/virtio_user_ethdev.c virtio_user_pmd_probe(struct rte_vdev_device *dev)
Quoted 13 lines
drivers/net/virtio/virtio_user_ethdev.c +8
-2goto end; } -if (vectorized) - hw->use_vec_rx =1 ; +if (vectorized) { +if (packed_vq) { +#if defined(CC_AVX512_SUPPORT ) + hw->use_vec_rx =1 ; + hw->use_vec_tx =1 ; +#else + PMD_INIT_LOG(INFO, + "building environment do not support packedring vectorized");
Quoted 13 lines
drivers/net/virtio/virtio_user_ethdev.c +5
-0+#endif + }else { + hw->use_vec_rx =1 ; + } + }rte_eth_dev_probing_finish (eth_dev); ret =0 ;drivers/net/virtio/virtqueue.h +0
-0drivers/net/virtio/virtqueue.h struct vq_desc_extra { · line 243
Quoted 6 lines
drivers/net/virtio/virtqueue.h +2
-1@@ -239,7 +239,8 @@ struct vq_desc_extra {void *cookie;uint16_t ndescs;uint16_t next; -}; +uint8_t padding[4 ]; +} __rte_packed __rte_aligned(16);Can't this introduce a performance impact for the non-vectorized case? I think of worse cache liens utilization.
Quoted 7 lines
For example with a burst of 32 descriptors with 32B cachelines, before it would take 14 cachelines, after 16. So for each burst, one could face 2 extra cache misses.
If you could run non-vectorized benchamrks with and without that patch, I would be grateful.
Maxime,
Thanks for point it out, it will add extra cache miss in datapath. And its impact on performance is around 1% in loopback case. While benefit of vectorized path will be more than that number.
Thanks,
Marvin
Quoted 4 lines
Reviewed-by Maxime Coquelin <[email protected]>Thanks,
Maxime
Re: [dpdk-dev] [PATCH v10 6/9] net/virtio: add vectorized packed ring Rx path
Quoted 584 lines · Yong
Quoted 584 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Monday, April 27, 2020 7:21 PM
To: Liu, Yong <[email protected]>; Ye, Xiaolong <[email protected]>; Wang, Zhihong <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v10 6/9] net/virtio: add vectorized packed ring Rx pathdrivers/net/virtio/Makefile else ifneq ($(filter y,$(CONFIG_RTE_ARCH_ARM)
Quoted 13 lines · Marvin Liu
Optimize packed ring Rx path with SIMD instructions. Solution of optimization is pretty like vhost, is that split path into batch and single functions. Batch function is further optimized by AVX512 instructions. Also pad desc extra structure to 16 bytes aligned, thus four elements will be saved in one batch.
Signed-off-by Marvin Liu <[email protected]>drivers/net/virtio/Makefile +0
-0@@ -36,6 +36,41 @@ else ifneq ($(filter y,$(CONFIG_RTE_ARCH_ARM)$(CONFIG_RTE_ARCH_ARM64)),)
Quoted 12 lines
drivers/net/virtio/Makefile +9
-0SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_rxtx_simple_neon.c endif +ifneq ($(FORCE_DISABLE_AVX512), y) + CC_AVX512_SUPPORT=\ + $(shell $(CC) -march=native -dM -E - </dev/null 2>&1 | \ + sed '/./{H;$$!d} ; x ; /AVX512F/!d; /AVX512BW/!d; /AVX512VL/!d' | \ + grep -q AVX512 && echo 1) +endif + +ifeq ($(CC_AVX512_SUPPORT), 1) +CFLAGS += -DCC_AVX512_SUPPORTdrivers/net/virtio/Makefile else ifneq ($(filter y,$(CONFIG_RTE_ARCH_ARM) $(CONFIG_RTE_ARCH_ARM64)),)
Quoted 10 lines
drivers/net/virtio/Makefile +10
-0+SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_rxtx_packed_avx.c + +ifeq ($(RTE_TOOLCHAIN), gcc) +ifeq ($(shell test $(GCC_VERSION) -ge 83 && echo 1), 1) +CFLAGS += -DVIRTIO_GCC_UNROLL_PRAGMA +endif +endif + +ifeq ($(RTE_TOOLCHAIN), clang) +ifeq ($(shell test $(CLANG_MAJOR_VERSION)$(CLANG_MINOR_VERSION) -ge 37 && echo 1), 1)
Quoted 24 lines
drivers/net/virtio/Makefile +16
-0+CFLAGS += -DVIRTIO_CLANG_UNROLL_PRAGMA +endif +endif + +ifeq ($(RTE_TOOLCHAIN), icc) +ifeq ($(shell test $(ICC_MAJOR_VERSION) -ge 16 && echo 1), 1) +CFLAGS += -DVIRTIO_ICC_UNROLL_PRAGMA +endif +endif + +CFLAGS_virtio_rxtx_packed_avx.o += -mavx512f -mavx512bw -mavx512vl +ifeq ($(shell test $(GCC_VERSION) -ge 100 && echo 1), 1) +CFLAGS_virtio_rxtx_packed_avx.o += -Wno-zero-length-bounds +endif +endif + ifeq ($(CONFIG_RTE_VIRTIO_USER),y) SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_user/vhost_user.c SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_user/vhost_kernel.cdrivers/net/virtio/meson.build +0
-0drivers/net/virtio/meson.build sources += files('virtio_ethdev.c', · line 13
Quoted 5 lines
drivers/net/virtio/meson.build +2
-0@@ -9,6 +9,20 @@ sources += files('virtio_ethdev.c', deps += ['kvargs', 'bus_pci'] if arch_subdir == 'x86' + if '-mno-avx512f' not in machine_args + if cc.has_argument('-mavx512f') and cc.has_argument('-mavx512vl') and
cc.has_argument('-mavx512bw')drivers/net/virtio/meson.build sources += files('virtio_ethdev.c',
Quoted 3 lines
drivers/net/virtio/meson.build +3
-0+ cflags += ['-mavx512f', '-mavx512bw', '-mavx512vl'] + cflags += ['-DCC_AVX512_SUPPORT'] + if (toolchain == 'gcc' andcc.version().version_compare('>=8.3.0'))
drivers/net/virtio/meson.build sources += files('virtio_ethdev.c', · line 18
Quoted 2 lines
drivers/net/virtio/meson.build +2
-0+ cflags += '-DVHOST_GCC_UNROLL_PRAGMA' + elif (toolchain == 'clang' andcc.version().version_compare('>=3.7.0'))
drivers/net/virtio/meson.build sources += files('virtio_ethdev.c', · line 19
Quoted 1 line
drivers/net/virtio/meson.build +1
-0+ cflags += '-
DVHOST_CLANG_UNROLL_PRAGMA'drivers/net/virtio/meson.build sources += files('virtio_ethdev.c', · line 20
Quoted 1 line
drivers/net/virtio/meson.build +1
-0+ elif (toolchain == 'icc' andcc.version().version_compare('>=16.0.0'))
Review
Quoted 9 lines
drivers/net/virtio/meson.build +5
-0+ cflags += '-DVHOST_ICC_UNROLL_PRAGMA' + endif + sources += files('virtio_rxtx_packed_avx.c') + endif + endif sources += files('virtio_rxtx_simple_sse.c') elif arch_subdir == 'ppc' sources += files('virtio_rxtx_simple_altivec.c')(quoted diff) +0
-0
b/drivers/net/virtio/virtio_ethdev.hdrivers/net/virtio/virtio_ethdev.h uint16_t virtio_xmit_pkts_inorder(void *tx_queue,
Quoted 4 lines
index
febaf17a8..5c112cac7100644drivers/net/virtio/virtio_ethdev.h +0
-0@@ -105,6 +105,9 @@ uint16_t virtio_xmit_pkts_inorder(void *tx_queue,struct
rte_mbuf**tx_pkts,drivers/net/virtio/virtio_ethdev.h uint16_t virtio_xmit_pkts_inorder(void *tx_queue, struct rte_mbuf **tx_pkts,
Quoted 4 lines
drivers/net/virtio/virtio_ethdev.h +1
-0uint16_t virtio_recv_pkts_vec (void *rx_queue,struct rte_mbuf **rx_pkts,uint16_t nb_pkts); +uint16_t virtio_recv_pkts_packed_vec(void *rx_queue, struct rte_mbuf**rx_pkts,
Review
Quoted 22 lines
drivers/net/virtio/virtio_ethdev.h +2
-0+ uint16_t nb_pkts); +int eth_virtio_dev_init (struct rte_eth_dev *eth_dev);void virtio_interrupt_handler (void *param);drivers/net/virtio/virtio_rxtx.c +8
-0@@ -2030,3 +2030,11 @@ virtio_xmit_pkts_inorder(void *tx_queue,return nb_tx; } + +__rte_weak uint16_t +virtio_recv_pkts_packed_vec(void *rx_queue __rte_unused, + struct rte_mbuf **rx_pkts __rte_unused, + uint16_t nb_pkts __rte_unused) +{ +return 0 ; +}(quoted diff) +0
-0
b/drivers/net/virtio/virtio_rxtx_packed_avx.cQuoted 18 lines
new file mode 100644
index 000000000..8a7b459ebdrivers/net/virtio/virtio_rxtx_packed_avx.c new file +13
-0@@ -0,0 +1,374 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2010-2020 Intel Corporation +*/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include <rte_net.h> + +#include "virtio_logs.h" drivers/net/virtio/virtio_rxtx_packed_avx.c line 23
Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +10
-0+#include "virtio_ethdev.h" +#include "virtio_pci.h" +#include "virtqueue.h" + +#define BYTE_SIZE 8 +/* flag bits offset in packed ring desc higher 64bits */ +#define FLAGS_BITS_OFFSET ((offsetof(struct vring_packed_desc, flags) - \ + offsetof(struct vring_packed_desc, len)) * BYTE_SIZE) + +#define PACKED_FLAGS_MASK ((0ULL |
VRING_PACKED_DESC_F_AVAIL_USED) << \drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 8 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +8
-0+ FLAGS_BITS_OFFSET) + +#define PACKED_BATCH_SIZE (RTE_CACHE_LINE_SIZE / \ + sizeof(struct vring_packed_desc)) +#define PACKED_BATCH_MASK (PACKED_BATCH_SIZE - 1) + +#ifdef VIRTIO_GCC_UNROLL_PRAGMA +#define virtio_for_each_try_unroll (iter, val, size) _Pragma("GCC unroll 4")\
Quoted 49 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +49
-0+ for (iter = val; iter < size; iter++) +#endif + +#ifdef VIRTIO_CLANG_UNROLL_PRAGMA +#define virtio_for_each_try_unroll (iter, val, size) _Pragma("unroll 4") \ + for (iter = val; iter < size; iter++) +#endif + +#ifdef VIRTIO_ICC_UNROLL_PRAGMA +#define virtio_for_each_try_unroll (iter, val, size) _Pragma("unroll (4)") \ + for (iter = val; iter < size; iter++) +#endif + +#ifndef virtio_for_each_try_unroll +#define virtio_for_each_try_unroll (iter, val, num) \ + for (iter = val; iter < num; iter++) +#endif + +static inline void +virtio_update_batch_stats (struct virtnet_stats *stats, +uint16_t pkt_len1, +uint16_t pkt_len2, +uint16_t pkt_len3, +uint16_t pkt_len4) +{ + stats->bytes += pkt_len1; + stats->bytes += pkt_len2; + stats->bytes += pkt_len3; + stats->bytes += pkt_len4; +} + +/* Optionally fill offload information in structure */ +static inline int +virtio_vec_rx_offload (struct rte_mbuf *m,struct virtio_net_hdr *hdr) +{ +struct rte_net_hdr_lens hdr_lens; +uint32_t hdrlen, ptype; +int l4_supported =0 ; + +/* nothing to do */ +if (hdr->flags ==0 ) +return 0 ; + +/* GSO not support in vec path, skip check */ + m->ol_flags |=PKT_RX_IP_CKSUM_UNKNOWN ; + + ptype =rte_net_get_ptype (m, &hdr_lens,RTE_PTYPE_ALL_MASK ); + m->packet_type = ptype; + if ((ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_TCP ||drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +10
-0+ (ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_UDP || + (ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_SCTP) + l4_supported =1 ; + +if (hdr->flags &VIRTIO_NET_HDR_F_NEEDS_CSUM ) { + hdrlen = hdr_lens.l2_len + hdr_lens.l3_len + hdr_lens.l4_len; +if (hdr->csum_start <= hdrlen && l4_supported) { + m->ol_flags |=PKT_RX_L4_CKSUM_NONE ; + }else { +/* Unknown proto or tunnel, do sw cksum. We can assume
Quoted 8 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +8
-0+* the cksum field is in the first segment since the +* buffers we provided to the host are large enough. +* In case of SCTP, this will be wrong since it's a CRC +* but there's nothing we can do. +*/ +uint16_t csum =0 , off; + + rte_raw_cksum_mbuf(m, hdr->csum_start,drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +10
-0+rte_pktmbuf_pkt_len (m) - hdr->csum_start, + &csum); +if (likely (csum !=0xffff )) + csum = ~csum; + off = hdr->csum_offset + hdr->csum_start; +if (rte_pktmbuf_data_len (m) >= off +1 ) + *rte_pktmbuf_mtod_offset(m, uint16_t *, + off) = csum; + } + } else if (hdr->flags & VIRTIO_NET_HDR_F_DATA_VALID &&
l4_supported) {Quoted 17 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +17
-0+ m->ol_flags |=PKT_RX_L4_CKSUM_GOOD ; + } + +return 0 ; +} + +static inline uint16_t +virtqueue_dequeue_batch_packed_vec (struct virtnet_rx *rxvq, +struct rte_mbuf **rx_pkts) +{ +struct virtqueue *vq = rxvq->vq; +struct virtio_hw *hw = vq->hw; +uint16_t hdr_size = hw->vtnet_hdr_size; +uint64_t addrs[PACKED_BATCH_SIZE ]; +uint16_t id = vq->vq_used_cons_idx; +uint8_t desc_stats; +uint16_t i;drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +10
-0+void *desc_addr; + +if (id &PACKED_BATCH_MASK ) +return -1 ; + +if (unlikely ((id +PACKED_BATCH_SIZE ) > vq->vq_nentries)) +return -1 ; + +/* only care avail/used bits */ + __m512i v_mask = _mm512_maskz_set1_epi64(0xaa,
PACKED_FLAGS_MASK);drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 8 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +8
-0+ desc_addr = &vq->vq_packed.ring.desc[id]; + +__m512i v_desc =_mm512_loadu_si512 (desc_addr); +__m512i v_flag =_mm512_and_epi64 (v_desc, v_mask); + +__m512i v_used_flag =_mm512_setzero_si512 (); +if (vq->vq_packed.used_wrap_counter) + v_used_flag = _mm512_maskz_set1_epi64(0xaa,
PACKED_FLAGS_MASK);Quoted 9 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +9
-0+ +/* Check all descs are used */ + desc_stats =_mm512_cmpneq_epu64_mask (v_flag, v_used_flag); +if (desc_stats) +return -1 ; + +virtio_for_each_try_unroll (i,0 ,PACKED_BATCH_SIZE ) { + rx_pkts[i] = (struct rte_mbuf *)vq->vq_descx[id + i].cookie; +rte_packet_prefetch (rte_pktmbuf_mtod(rx_pkts [i],void *));drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +10
-0+ + addrs[i] = (uint64_t )rx_pkts[i]->rx_descriptor_fields1; + } + +/* +* load len from desc, store into mbuf pkt_len and data_len +* len limiated by l6bit buf_len, pkt_len[16:31] can be ignored +*/ +const __mmask16 mask =0x6 |0x6 <<4 |0x6 <<8 |0x6 <<12 ; + __m512i values = _mm512_maskz_shuffle_epi32(mask, v_desc,
0xAA);Quoted 55 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +55
-0+ +/* reduce hdr_len from pkt_len and data_len */ +__m512i mbuf_len_offset =_mm512_maskz_set1_epi32 (mask, + (uint32_t )-hdr_size); + +__m512i v_value =_mm512_add_epi32 (values, mbuf_len_offset); + +/* assert offset of data_len */ +RTE_BUILD_BUG_ON (offsetof(struct rte_mbuf , data_len) != + offsetof(struct rte_mbuf , rx_descriptor_fields1) +8 ); + +__m512i v_index =_mm512_set_epi64 (addrs[3 ] +8 , addrs[3 ], + addrs[2 ] +8 , addrs[2 ], + addrs[1 ] +8 , addrs[1 ], + addrs[0 ] +8 , addrs[0 ]); +/* batch store into mbufs */ +_mm512_i64scatter_epi64 (0 , v_index, v_value,1 ); + +if (hw->has_rx_offload) { +virtio_for_each_try_unroll (i,0 ,PACKED_BATCH_SIZE ) { +char *addr = (char *)rx_pkts[i]->buf_addr + +RTE_PKTMBUF_HEADROOM - hdr_size; +virtio_vec_rx_offload (rx_pkts[i], + (struct virtio_net_hdr *)addr); + } + } + +virtio_update_batch_stats (&rxvq->stats, rx_pkts[0 ]->pkt_len, + rx_pkts[1 ]->pkt_len, rx_pkts[2 ]->pkt_len, + rx_pkts[3 ]->pkt_len); + + vq->vq_free_cnt +=PACKED_BATCH_SIZE ; + + vq->vq_used_cons_idx +=PACKED_BATCH_SIZE ; +if (vq->vq_used_cons_idx >= vq->vq_nentries) { + vq->vq_used_cons_idx -= vq->vq_nentries; + vq->vq_packed.used_wrap_counter ^=1 ; + } + +return 0 ; +} + +static uint16_t +virtqueue_dequeue_single_packed_vec (struct virtnet_rx *rxvq, +struct rte_mbuf **rx_pkts) +{ +uint16_t used_idx, id; +uint32_t len; +struct virtqueue *vq = rxvq->vq; +struct virtio_hw *hw = vq->hw; +uint32_t hdr_size = hw->vtnet_hdr_size; +struct virtio_net_hdr *hdr; +struct vring_packed_desc *desc; +struct rte_mbuf *cookie; +drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +10
-0+ desc = vq->vq_packed.ring.desc; + used_idx = vq->vq_used_cons_idx; +if (!desc_is_used (&desc[used_idx], vq)) +return -1 ; + + len = desc[used_idx].len; + id = desc[used_idx].id; + cookie = (struct rte_mbuf *)vq->vq_descx[id].cookie; +if (unlikely (cookie ==NULL )) { + PMD_DRV_LOG(ERR, "vring descriptor with no mbuf cookieat %u",
drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 13 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +13
-0+ vq->vq_used_cons_idx); +return -1 ; + } +rte_prefetch0 (cookie); +rte_packet_prefetch (rte_pktmbuf_mtod(cookie ,void *)); + + cookie->data_off =RTE_PKTMBUF_HEADROOM ; + cookie->ol_flags =0 ; + cookie->pkt_len = (uint32_t )(len - hdr_size); + cookie->data_len = (uint32_t )(len - hdr_size); + + hdr = (struct virtio_net_hdr *)((char *)cookie->buf_addr + + RTE_PKTMBUF_HEADROOM -
hdr_size);Quoted 37 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +37
-0+if (hw->has_rx_offload) +virtio_vec_rx_offload (cookie, hdr); + + *rx_pkts = cookie; + + rxvq->stats.bytes += cookie->pkt_len; + + vq->vq_free_cnt++; + vq->vq_used_cons_idx++; +if (vq->vq_used_cons_idx >= vq->vq_nentries) { + vq->vq_used_cons_idx -= vq->vq_nentries; + vq->vq_packed.used_wrap_counter ^=1 ; + } + +return 0 ; +} + +static inline void +virtio_recv_refill_packed_vec (struct virtnet_rx *rxvq, +struct rte_mbuf **cookie, +uint16_t num) +{ +struct virtqueue *vq = rxvq->vq; +struct vring_packed_desc *start_dp = vq->vq_packed.ring.desc; +uint16_t flags = vq->vq_packed.cached_flags; +struct virtio_hw *hw = vq->hw; +struct vq_desc_extra *dxp; +uint16_t idx, i; +uint16_t batch_num, total_num =0 ; +uint16_t head_idx = vq->vq_avail_idx; +uint16_t head_flag = vq->vq_packed.cached_flags; +uint64_t addr; + + do { + idx = vq->vq_avail_idx; + + batch_num = PACKED_BATCH_SIZE;drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +10
-0+if (unlikely ((idx +PACKED_BATCH_SIZE ) > vq->vq_nentries)) + batch_num = vq->vq_nentries - idx; +if (unlikely ((total_num + batch_num) > num)) + batch_num = num - total_num; + +virtio_for_each_try_unroll (i,0 , batch_num) { + dxp = &vq->vq_descx[idx + i]; + dxp->cookie = (void *)cookie[total_num + i]; + + addr = VIRTIO_MBUF_ADDR(cookie[total_num + i],vq) +
drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 8 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +1
-0+ RTE_PKTMBUF_HEADROOM - hw-
vtnet_hdr_size;drivers/net/virtio/virtio_rxtx_packed_avx.c new file +3
-0+ start_dp[idx + i].addr = addr; + start_dp[idx + i].len = cookie[total_num + i]->buf_len + - RTE_PKTMBUF_HEADROOM + hw-
vtnet_hdr_size;drivers/net/virtio/virtio_rxtx_packed_avx.c new file +2
-0+ if (total_num || i) { + virtqueue_store_flags_packed(&start_dp[idx+ i],
Quoted 27 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +27
-0+ flags, hw->weak_barriers); + } + } + + vq->vq_avail_idx += batch_num; +if (vq->vq_avail_idx >= vq->vq_nentries) { + vq->vq_avail_idx -= vq->vq_nentries; + vq->vq_packed.cached_flags ^= +VRING_PACKED_DESC_F_AVAIL_USED ; + flags = vq->vq_packed.cached_flags; + } + total_num += batch_num; + }while (total_num < num); + +virtqueue_store_flags_packed (&start_dp[head_idx], head_flag, + hw->weak_barriers); + vq->vq_free_cnt = (uint16_t )(vq->vq_free_cnt - num); +} + +uint16_t +virtio_recv_pkts_packed_vec (void *rx_queue, +struct rte_mbuf **rx_pkts, +uint16_t nb_pkts) +{ +struct virtnet_rx *rxvq = rx_queue; +struct virtqueue *vq = rxvq->vq; +struct virtio_hw *hw = vq->hw;drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +10
-0+uint16_t num, nb_rx =0 ; +uint32_t nb_enqueued =0 ; +uint16_t free_cnt = vq->vq_free_thresh; + +if (unlikely (hw->started ==0 )) +return nb_rx; + + num =RTE_MIN (VIRTIO_MBUF_BURST_SZ , nb_pkts); +if (likely (num >PACKED_BATCH_SIZE )) + num = num - ((vq->vq_used_cons_idx + num) %
PACKED_BATCH_SIZE);Review
Quoted 45 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +44
-0+ +while (num) { +if (!virtqueue_dequeue_batch_packed_vec (rxvq, + &rx_pkts[nb_rx])) { + nb_rx +=PACKED_BATCH_SIZE ; + num -=PACKED_BATCH_SIZE ; +continue ; + } +if (!virtqueue_dequeue_single_packed_vec (rxvq, + &rx_pkts[nb_rx])) { + nb_rx++; + num--; +continue ; + } +break ; + }; + +PMD_RX_LOG (DEBUG ,"dequeue:%d" , num); + + rxvq->stats.packets += nb_rx; + +if (likely (vq->vq_free_cnt >= free_cnt)) { +struct rte_mbuf *new_pkts[free_cnt]; +if (likely (rte_pktmbuf_alloc_bulk (rxvq->mpool, new_pkts, + free_cnt) ==0 )) { +virtio_recv_refill_packed_vec (rxvq, new_pkts, + free_cnt); + nb_enqueued += free_cnt; + }else { +struct rte_eth_dev *dev = + &rte_eth_devices[rxvq->port_id]; + dev->data->rx_mbuf_alloc_failed += free_cnt; + } + } + +if (likely (nb_enqueued)) { +if (unlikely (virtqueue_kick_prepare_packed (vq))) { +virtqueue_notify (vq); +PMD_RX_LOG (DEBUG ,"Notified" ); + } + } + +return nb_rx; +}(quoted diff) +0
-0
b/drivers/net/virtio/virtio_user_ethdev.cdrivers/net/virtio/virtio_user_ethdev.c virtio_user_eth_dev_alloc(struct rte_vdev_device
Quoted 4 lines
index
40ad786cc..c54698ad1100644drivers/net/virtio/virtio_user_ethdev.c +0
-0@@ -528,6 +528,7 @@ virtio_user_eth_dev_alloc(struct rte_vdev_device*vdev)
drivers/net/virtio/virtio_user_ethdev.c virtio_user_pmd_probe(struct rte_vdev_device
Quoted 8 lines
drivers/net/virtio/virtio_user_ethdev.c +1
-0hw->use_msix =1 ; hw->modern =0 ; hw->use_vec_rx =0 ; + hw->use_vec_tx =0 ; hw->use_inorder_rx =0 ; hw->use_inorder_tx =0 ; hw->virtio_user_dev = dev;@@ -739,8 +740,19 @@ virtio_user_pmd_probe(struct rte_vdev_device*dev)
drivers/net/virtio/virtio_user_ethdev.c virtio_user_pmd_probe(struct rte_vdev_device *dev)
Quoted 13 lines
drivers/net/virtio/virtio_user_ethdev.c +8
-2goto end; } -if (vectorized) - hw->use_vec_rx =1 ; +if (vectorized) { +if (packed_vq) { +#if defined(CC_AVX512_SUPPORT ) + hw->use_vec_rx =1 ; + hw->use_vec_tx =1 ; +#else + PMD_INIT_LOG(INFO, + "building environment do not support packedring vectorized");
Quoted 13 lines
drivers/net/virtio/virtio_user_ethdev.c +5
-0+#endif + }else { + hw->use_vec_rx =1 ; + } + }rte_eth_dev_probing_finish (eth_dev); ret =0 ;drivers/net/virtio/virtqueue.h +0
-0drivers/net/virtio/virtqueue.h struct vq_desc_extra { · line 243
Quoted 6 lines
drivers/net/virtio/virtqueue.h +2
-1@@ -239,7 +239,8 @@ struct vq_desc_extra {void *cookie;uint16_t ndescs;uint16_t next; -}; +uint8_t padding[4 ]; +} __rte_packed __rte_aligned(16);Can't this introduce a performance impact for the non-vectorized case? I think of worse cache liens utilization.
For example with a burst of 32 descriptors with 32B cachelines, before it would take 14 cachelines, after 16. So for each burst, one could face 2 extra cache misses.
Quoted 7 lines
Quoted 3 lines
If you could run non-vectorized benchamrks with and without that patch, I would be grateful.
Maxime,
Thanks for point it out, it will add extra cache miss in datapath. And its impact on performance is around 1% in loopback case.
Ok, thanks for doing the test. I'll try to run some PVP benchmarks on my side because when doing IO loopback, the cache pressure is much less important.
Quoted 1 line
While benefit of vectorized path will be more than that number.
Ok, but I disagree for two reasons:
1. You have to keep in mind than non-vectorized is the default and
encouraged mode to use. Indeed, it takes a lot of shortcuts like not checking header length (so no error stats), etc...
2. It's like saying it's OK it degrades by 5% on $CPU_VENDOR_A because
the gain is 20% on $CPU_VENDOR_B.
In the case we see more degradation in real-world scenario, you might want to consider using ifdefs to avoid adding padding in the non- vectorized case, like you did to differentiate Virtio PMD to Virtio-user PMD in patch 7.
Thanks,
Maxime
Quoted 8 lines
Thanks,
MarvinQuoted 4 lines
Reviewed-by Maxime Coquelin <[email protected]>Thanks,
Maxime
Re: [dpdk-dev] [PATCH v10 6/9] net/virtio: add vectorized packed ring Rx path
Quoted 626 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Tuesday, April 28, 2020 4:44 PM
To: Liu, Yong <[email protected]>; Ye, Xiaolong <[email protected]>; Wang, Zhihong <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v10 6/9] net/virtio: add vectorized packed ring Rx pathQuoted 6 lines · Yong
Quoted 6 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Monday, April 27, 2020 7:21 PM
To: Liu, Yong <[email protected]>; Ye, XiaolongQuoted 3 lines
Quoted 3 lines
Wang, Zhihong <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v10 6/9] net/virtio: add vectorized packed ring Rxpath
Quoted 12 lines
Quoted 12 lines · Marvin Liu
Quoted 8 lines
Optimize packed ring Rx path with SIMD instructions. Solution of optimization is pretty like vhost, is that split path into batch and single functions. Batch function is further optimized by AVX512 instructions. Also pad desc extra structure to 16 bytes aligned, thus four elements will be saved in one batch.
Signed-off-by Marvin Liu <[email protected]>Quoted 7 lines
Quoted 7 lines
drivers/net/virtio/Makefile else ifneq ($(filter y,$(CONFIG_RTE_ARCH_ARM)
Quoted 5 lines
drivers/net/virtio/Makefile +0
-0@@ -36,6 +36,41 @@ else ifneq ($(filter y,$(CONFIG_RTE_ARCH_ARM)$(CONFIG_RTE_ARCH_ARM64)),)
Quoted 1 line
drivers/net/virtio/Makefile +0
-0SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) +=
virtio_rxtx_simple_neon.cQuoted 13 lines
Quoted 13 lines
Quoted 13 lines
drivers/net/virtio/Makefile +11
-0endif +ifneq ($(FORCE_DISABLE_AVX512), y) + CC_AVX512_SUPPORT=\ + $(shell $(CC) -march=native -dM -E - </dev/null 2>&1 | \ + sed '/./{H;$$!d} ; x ; /AVX512F/!d; /AVX512BW/!d; /AVX512VL/!d' | \ + grep -q AVX512 && echo 1) +endif + +ifeq ($(CC_AVX512_SUPPORT), 1) +CFLAGS += -DCC_AVX512_SUPPORT +SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_rxtx_packed_avx.c +Quoted 8 lines
Quoted 8 lines
drivers/net/virtio/Makefile else ifneq ($(filter y,$(CONFIG_RTE_ARCH_ARM) $(CONFIG_RTE_ARCH_ARM64)),)
Quoted 8 lines
drivers/net/virtio/Makefile +8
-0+ifeq ($(RTE_TOOLCHAIN), gcc) +ifeq ($(shell test $(GCC_VERSION) -ge 83 && echo 1), 1) +CFLAGS += -DVIRTIO_GCC_UNROLL_PRAGMA +endif +endif + +ifeq ($(RTE_TOOLCHAIN), clang) +ifeq ($(shell test$(CLANG_MAJOR_VERSION)$(CLANG_MINOR_VERSION) -
Quoted 12 lines
Quoted 12 lines
ge 37 && echo 1), 1)
drivers/net/virtio/Makefile else ifneq ($(filter y,$(CONFIG_RTE_ARCH_ARM) $(CONFIG_RTE_ARCH_ARM64)),)
Quoted 11 lines
drivers/net/virtio/Makefile +11
-0+CFLAGS += -DVIRTIO_CLANG_UNROLL_PRAGMA +endif +endif + +ifeq ($(RTE_TOOLCHAIN), icc) +ifeq ($(shell test $(ICC_MAJOR_VERSION) -ge 16 && echo 1), 1) +CFLAGS += -DVIRTIO_ICC_UNROLL_PRAGMA +endif +endif + +CFLAGS_virtio_rxtx_packed_avx.o += -mavx512f -mavx512bw -mavx512vl
Quoted 8 lines
Quoted 8 lines
drivers/net/virtio/Makefile else ifneq ($(filter y,$(CONFIG_RTE_ARCH_ARM) $(CONFIG_RTE_ARCH_ARM64)),)
Quoted 8 lines
drivers/net/virtio/Makefile +5
-0+ifeq ($(shell test $(GCC_VERSION) -ge 100 && echo 1), 1) +CFLAGS_virtio_rxtx_packed_avx.o += -Wno-zero-length-bounds +endif +endif + ifeq ($(CONFIG_RTE_VIRTIO_USER),y) SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_user/vhost_user.c SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) +=
virtio_user/vhost_kernel.cQuoted 1 line
Quoted 1 line
Review
Quoted 1 line
(quoted diff) +0
-0b/drivers/net/virtio/meson.build
Quoted 31 lines
Quoted 31 lines
drivers/net/virtio/meson.build sources += files('virtio_ethdev.c', · line 13
Quoted 9 lines
index
15150eea1..8e68c3039100644drivers/net/virtio/meson.build +2
-0@@ -9,6 +9,20 @@ sources += files('virtio_ethdev.c', deps += ['kvargs', 'bus_pci'] if arch_subdir == 'x86' + if '-mno-avx512f' not in machine_args + if cc.has_argument('-mavx512f') and cc.has_argument('-mavx512vl') and
cc.has_argument('-mavx512bw')drivers/net/virtio/meson.build sources += files('virtio_ethdev.c',
Quoted 3 lines
drivers/net/virtio/meson.build +3
-0+ cflags += ['-mavx512f', '-mavx512bw', '-mavx512vl'] + cflags += ['-DCC_AVX512_SUPPORT'] + if (toolchain == 'gcc' andcc.version().version_compare('>=8.3.0'))
drivers/net/virtio/meson.build sources += files('virtio_ethdev.c', · line 18
Quoted 2 lines
drivers/net/virtio/meson.build +2
-0+ cflags += '-DVHOST_GCC_UNROLL_PRAGMA' + elif (toolchain == 'clang' andcc.version().version_compare('>=3.7.0'))
drivers/net/virtio/meson.build sources += files('virtio_ethdev.c', · line 19
Quoted 1 line
drivers/net/virtio/meson.build +1
-0+ cflags += '-
DVHOST_CLANG_UNROLL_PRAGMA'drivers/net/virtio/meson.build sources += files('virtio_ethdev.c', · line 20
Quoted 1 line
drivers/net/virtio/meson.build +1
-0+ elif (toolchain == 'icc' andcc.version().version_compare('>=16.0.0'))
Review
Quoted 9 lines
drivers/net/virtio/meson.build +5
-0+ cflags += '-DVHOST_ICC_UNROLL_PRAGMA' + endif + sources += files('virtio_rxtx_packed_avx.c') + endif + endif sources += files('virtio_rxtx_simple_sse.c') elif arch_subdir == 'ppc' sources += files('virtio_rxtx_simple_altivec.c')(quoted diff) +0
-0
b/drivers/net/virtio/virtio_ethdev.hQuoted 4 lines
Quoted 4 lines
drivers/net/virtio/virtio_ethdev.h uint16_t virtio_xmit_pkts_inorder(void
Quoted 4 lines
index
febaf17a8..5c112cac7100644drivers/net/virtio/virtio_ethdev.h +0
-0@@ -105,6 +105,9 @@ uint16_t virtio_xmit_pkts_inorder(void
*tx_queue,Quoted 2 lines
Quoted 2 lines
struct
rte_mbuf**tx_pkts,Quoted 1 line
drivers/net/virtio/virtio_ethdev.h +0
-0uint16_t virtio_recv_pkts_vec(void *rx_queue, struct rte_mbuf**rx_pkts,
Quoted 10 lines
Quoted 10 lines
drivers/net/virtio/virtio_ethdev.h uint16_t virtio_xmit_pkts_inorder(void *tx_queue, struct rte_mbuf **tx_pkts,
Quoted 3 lines
drivers/net/virtio/virtio_ethdev.h +1
-0uint16_t nb_pkts); +uint16_t virtio_recv_pkts_packed_vec(void *rx_queue, struct rte_mbuf**rx_pkts,
Review
Quoted 6 lines
drivers/net/virtio/virtio_ethdev.h +2
-0+ uint16_t nb_pkts); +int eth_virtio_dev_init (struct rte_eth_dev *eth_dev);void virtio_interrupt_handler (void *param);(quoted diff) +0
-0
b/drivers/net/virtio/virtio_rxtx.cQuoted 34 lines
Quoted 34 lines
Review
Quoted 16 lines
index
a549991aa..534562cca100644drivers/net/virtio/virtio_rxtx.c +8
-0@@ -2030,3 +2030,11 @@ virtio_xmit_pkts_inorder(void *tx_queue,return nb_tx; } + +__rte_weak uint16_t +virtio_recv_pkts_packed_vec(void *rx_queue __rte_unused, + struct rte_mbuf **rx_pkts __rte_unused, + uint16_t nb_pkts __rte_unused) +{ +return 0 ; +}(quoted diff) +0
-0
b/drivers/net/virtio/virtio_rxtx_packed_avx.cQuoted 17 lines
new file mode 100644
index 000000000..8a7b459ebdrivers/net/virtio/virtio_rxtx_packed_avx.c new file +12
-0@@ -0,0 +1,374 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2010-2020 Intel Corporation +*/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include <rte_net.h> +Quoted 8 lines
Quoted 8 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 8 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +8
-0+#include "virtio_logs.h" +#include "virtio_ethdev.h" +#include "virtio_pci.h" +#include "virtqueue.h" + +#define BYTE_SIZE 8 +/* flag bits offset in packed ring desc higher 64bits */ +#define FLAGS_BITS_OFFSET ((offsetof(struct vring_packed_desc, flags)- \
Quoted 4 lines
Quoted 4 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 3 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +3
-0+ offsetof(struct vring_packed_desc, len)) * BYTE_SIZE) + +#define PACKED_FLAGS_MASK ((0ULL |
VRING_PACKED_DESC_F_AVAIL_USED) << \Quoted 8 lines
Quoted 8 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 8 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +8
-0+ FLAGS_BITS_OFFSET) + +#define PACKED_BATCH_SIZE (RTE_CACHE_LINE_SIZE / \ + sizeof(struct vring_packed_desc)) +#define PACKED_BATCH_MASK (PACKED_BATCH_SIZE - 1) + +#ifdef VIRTIO_GCC_UNROLL_PRAGMA +#define virtio_for_each_try_unroll (iter, val, size) _Pragma("GCC unroll4")
Quoted 11 lines
Quoted 11 lines
\
drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +10
-0+ for (iter = val; iter < size; iter++) +#endif + +#ifdef VIRTIO_CLANG_UNROLL_PRAGMA +#define virtio_for_each_try_unroll (iter, val, size) _Pragma("unroll 4") \ + for (iter = val; iter < size; iter++) +#endif + +#ifdef VIRTIO_ICC_UNROLL_PRAGMA +#define virtio_for_each_try_unroll (iter, val, size) _Pragma("unroll (4)")\
Quoted 348 lines
Quoted 254 lines
Quoted 39 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +39
-0+ for (iter = val; iter < size; iter++) +#endif + +#ifndef virtio_for_each_try_unroll +#define virtio_for_each_try_unroll (iter, val, num) \ + for (iter = val; iter < num; iter++) +#endif + +static inline void +virtio_update_batch_stats (struct virtnet_stats *stats, +uint16_t pkt_len1, +uint16_t pkt_len2, +uint16_t pkt_len3, +uint16_t pkt_len4) +{ + stats->bytes += pkt_len1; + stats->bytes += pkt_len2; + stats->bytes += pkt_len3; + stats->bytes += pkt_len4; +} + +/* Optionally fill offload information in structure */ +static inline int +virtio_vec_rx_offload (struct rte_mbuf *m,struct virtio_net_hdr *hdr) +{ +struct rte_net_hdr_lens hdr_lens; +uint32_t hdrlen, ptype; +int l4_supported =0 ; + +/* nothing to do */ +if (hdr->flags ==0 ) +return 0 ; + +/* GSO not support in vec path, skip check */ + m->ol_flags |=PKT_RX_IP_CKSUM_UNKNOWN ; + + ptype =rte_net_get_ptype (m, &hdr_lens,RTE_PTYPE_ALL_MASK ); + m->packet_type = ptype; + if ((ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_TCP ||drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +10
-0+ (ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_UDP || + (ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_SCTP) + l4_supported =1 ; + +if (hdr->flags &VIRTIO_NET_HDR_F_NEEDS_CSUM ) { + hdrlen = hdr_lens.l2_len + hdr_lens.l3_len + hdr_lens.l4_len; +if (hdr->csum_start <= hdrlen && l4_supported) { + m->ol_flags |=PKT_RX_L4_CKSUM_NONE ; + }else { +/* Unknown proto or tunnel, do sw cksum. We can assume
Quoted 8 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +8
-0+* the cksum field is in the first segment since the +* buffers we provided to the host are large enough. +* In case of SCTP, this will be wrong since it's a CRC +* but there's nothing we can do. +*/ +uint16_t csum =0 , off; + + rte_raw_cksum_mbuf(m, hdr->csum_start,drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +10
-0+rte_pktmbuf_pkt_len (m) - hdr->csum_start, + &csum); +if (likely (csum !=0xffff )) + csum = ~csum; + off = hdr->csum_offset + hdr->csum_start; +if (rte_pktmbuf_data_len (m) >= off +1 ) + *rte_pktmbuf_mtod_offset(m, uint16_t *, + off) = csum; + } + } else if (hdr->flags & VIRTIO_NET_HDR_F_DATA_VALID &&
l4_supported) {Quoted 17 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +17
-0+ m->ol_flags |=PKT_RX_L4_CKSUM_GOOD ; + } + +return 0 ; +} + +static inline uint16_t +virtqueue_dequeue_batch_packed_vec (struct virtnet_rx *rxvq, +struct rte_mbuf **rx_pkts) +{ +struct virtqueue *vq = rxvq->vq; +struct virtio_hw *hw = vq->hw; +uint16_t hdr_size = hw->vtnet_hdr_size; +uint64_t addrs[PACKED_BATCH_SIZE ]; +uint16_t id = vq->vq_used_cons_idx; +uint8_t desc_stats; +uint16_t i;drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +10
-0+void *desc_addr; + +if (id &PACKED_BATCH_MASK ) +return -1 ; + +if (unlikely ((id +PACKED_BATCH_SIZE ) > vq->vq_nentries)) +return -1 ; + +/* only care avail/used bits */ + __m512i v_mask = _mm512_maskz_set1_epi64(0xaa,
PACKED_FLAGS_MASK);drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 8 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +8
-0+ desc_addr = &vq->vq_packed.ring.desc[id]; + +__m512i v_desc =_mm512_loadu_si512 (desc_addr); +__m512i v_flag =_mm512_and_epi64 (v_desc, v_mask); + +__m512i v_used_flag =_mm512_setzero_si512 (); +if (vq->vq_packed.used_wrap_counter) + v_used_flag = _mm512_maskz_set1_epi64(0xaa,
PACKED_FLAGS_MASK);Quoted 9 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +9
-0+ +/* Check all descs are used */ + desc_stats =_mm512_cmpneq_epu64_mask (v_flag, v_used_flag); +if (desc_stats) +return -1 ; + +virtio_for_each_try_unroll (i,0 ,PACKED_BATCH_SIZE ) { + rx_pkts[i] = (struct rte_mbuf *)vq->vq_descx[id + i].cookie; +rte_packet_prefetch (rte_pktmbuf_mtod(rx_pkts [i],void *));drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +10
-0+ + addrs[i] = (uint64_t )rx_pkts[i]->rx_descriptor_fields1; + } + +/* +* load len from desc, store into mbuf pkt_len and data_len +* len limiated by l6bit buf_len, pkt_len[16:31] can be ignored +*/ +const __mmask16 mask =0x6 |0x6 <<4 |0x6 <<8 |0x6 <<12 ; + __m512i values = _mm512_maskz_shuffle_epi32(mask, v_desc,
0xAA);Quoted 55 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +55
-0+ +/* reduce hdr_len from pkt_len and data_len */ +__m512i mbuf_len_offset =_mm512_maskz_set1_epi32 (mask, + (uint32_t )-hdr_size); + +__m512i v_value =_mm512_add_epi32 (values, mbuf_len_offset); + +/* assert offset of data_len */ +RTE_BUILD_BUG_ON (offsetof(struct rte_mbuf , data_len) != + offsetof(struct rte_mbuf , rx_descriptor_fields1) +8 ); + +__m512i v_index =_mm512_set_epi64 (addrs[3 ] +8 , addrs[3 ], + addrs[2 ] +8 , addrs[2 ], + addrs[1 ] +8 , addrs[1 ], + addrs[0 ] +8 , addrs[0 ]); +/* batch store into mbufs */ +_mm512_i64scatter_epi64 (0 , v_index, v_value,1 ); + +if (hw->has_rx_offload) { +virtio_for_each_try_unroll (i,0 ,PACKED_BATCH_SIZE ) { +char *addr = (char *)rx_pkts[i]->buf_addr + +RTE_PKTMBUF_HEADROOM - hdr_size; +virtio_vec_rx_offload (rx_pkts[i], + (struct virtio_net_hdr *)addr); + } + } + +virtio_update_batch_stats (&rxvq->stats, rx_pkts[0 ]->pkt_len, + rx_pkts[1 ]->pkt_len, rx_pkts[2 ]->pkt_len, + rx_pkts[3 ]->pkt_len); + + vq->vq_free_cnt +=PACKED_BATCH_SIZE ; + + vq->vq_used_cons_idx +=PACKED_BATCH_SIZE ; +if (vq->vq_used_cons_idx >= vq->vq_nentries) { + vq->vq_used_cons_idx -= vq->vq_nentries; + vq->vq_packed.used_wrap_counter ^=1 ; + } + +return 0 ; +} + +static uint16_t +virtqueue_dequeue_single_packed_vec (struct virtnet_rx *rxvq, +struct rte_mbuf **rx_pkts) +{ +uint16_t used_idx, id; +uint32_t len; +struct virtqueue *vq = rxvq->vq; +struct virtio_hw *hw = vq->hw; +uint32_t hdr_size = hw->vtnet_hdr_size; +struct virtio_net_hdr *hdr; +struct vring_packed_desc *desc; +struct rte_mbuf *cookie; +drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +10
-0+ desc = vq->vq_packed.ring.desc; + used_idx = vq->vq_used_cons_idx; +if (!desc_is_used (&desc[used_idx], vq)) +return -1 ; + + len = desc[used_idx].len; + id = desc[used_idx].id; + cookie = (struct rte_mbuf *)vq->vq_descx[id].cookie; +if (unlikely (cookie ==NULL )) { + PMD_DRV_LOG(ERR, "vring descriptor with no mbuf cookieat %u",
drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 13 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +13
-0+ vq->vq_used_cons_idx); +return -1 ; + } +rte_prefetch0 (cookie); +rte_packet_prefetch (rte_pktmbuf_mtod(cookie ,void *)); + + cookie->data_off =RTE_PKTMBUF_HEADROOM ; + cookie->ol_flags =0 ; + cookie->pkt_len = (uint32_t )(len - hdr_size); + cookie->data_len = (uint32_t )(len - hdr_size); + + hdr = (struct virtio_net_hdr *)((char *)cookie->buf_addr + + RTE_PKTMBUF_HEADROOM -
hdr_size);Quoted 37 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +37
-0+if (hw->has_rx_offload) +virtio_vec_rx_offload (cookie, hdr); + + *rx_pkts = cookie; + + rxvq->stats.bytes += cookie->pkt_len; + + vq->vq_free_cnt++; + vq->vq_used_cons_idx++; +if (vq->vq_used_cons_idx >= vq->vq_nentries) { + vq->vq_used_cons_idx -= vq->vq_nentries; + vq->vq_packed.used_wrap_counter ^=1 ; + } + +return 0 ; +} + +static inline void +virtio_recv_refill_packed_vec (struct virtnet_rx *rxvq, +struct rte_mbuf **cookie, +uint16_t num) +{ +struct virtqueue *vq = rxvq->vq; +struct vring_packed_desc *start_dp = vq->vq_packed.ring.desc; +uint16_t flags = vq->vq_packed.cached_flags; +struct virtio_hw *hw = vq->hw; +struct vq_desc_extra *dxp; +uint16_t idx, i; +uint16_t batch_num, total_num =0 ; +uint16_t head_idx = vq->vq_avail_idx; +uint16_t head_flag = vq->vq_packed.cached_flags; +uint64_t addr; + + do { + idx = vq->vq_avail_idx; + + batch_num = PACKED_BATCH_SIZE;drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +10
-0+if (unlikely ((idx +PACKED_BATCH_SIZE ) > vq->vq_nentries)) + batch_num = vq->vq_nentries - idx; +if (unlikely ((total_num + batch_num) > num)) + batch_num = num - total_num; + +virtio_for_each_try_unroll (i,0 , batch_num) { + dxp = &vq->vq_descx[idx + i]; + dxp->cookie = (void *)cookie[total_num + i]; + + addr = VIRTIO_MBUF_ADDR(cookie[total_num + i],vq) +
Quoted 4 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 4 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +1
-0+ RTE_PKTMBUF_HEADROOM - hw-
vtnet_hdr_size;drivers/net/virtio/virtio_rxtx_packed_avx.c new file +2
-0+ start_dp[idx + i].addr = addr; + start_dp[idx + i].len = cookie[total_num + i]-
buf_lenQuoted 89 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 4 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +1
-0+ - RTE_PKTMBUF_HEADROOM + hw-
vtnet_hdr_size;drivers/net/virtio/virtio_rxtx_packed_avx.c new file +2
-0+ if (total_num || i) { + virtqueue_store_flags_packed(&start_dp[idx+ i],
Quoted 27 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +27
-0+ flags, hw->weak_barriers); + } + } + + vq->vq_avail_idx += batch_num; +if (vq->vq_avail_idx >= vq->vq_nentries) { + vq->vq_avail_idx -= vq->vq_nentries; + vq->vq_packed.cached_flags ^= +VRING_PACKED_DESC_F_AVAIL_USED ; + flags = vq->vq_packed.cached_flags; + } + total_num += batch_num; + }while (total_num < num); + +virtqueue_store_flags_packed (&start_dp[head_idx], head_flag, + hw->weak_barriers); + vq->vq_free_cnt = (uint16_t )(vq->vq_free_cnt - num); +} + +uint16_t +virtio_recv_pkts_packed_vec (void *rx_queue, +struct rte_mbuf **rx_pkts, +uint16_t nb_pkts) +{ +struct virtnet_rx *rxvq = rx_queue; +struct virtqueue *vq = rxvq->vq; +struct virtio_hw *hw = vq->hw;drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +10
-0+uint16_t num, nb_rx =0 ; +uint32_t nb_enqueued =0 ; +uint16_t free_cnt = vq->vq_free_thresh; + +if (unlikely (hw->started ==0 )) +return nb_rx; + + num =RTE_MIN (VIRTIO_MBUF_BURST_SZ , nb_pkts); +if (likely (num >PACKED_BATCH_SIZE )) + num = num - ((vq->vq_used_cons_idx + num) %
PACKED_BATCH_SIZE);Review
Quoted 45 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +44
-0+ +while (num) { +if (!virtqueue_dequeue_batch_packed_vec (rxvq, + &rx_pkts[nb_rx])) { + nb_rx +=PACKED_BATCH_SIZE ; + num -=PACKED_BATCH_SIZE ; +continue ; + } +if (!virtqueue_dequeue_single_packed_vec (rxvq, + &rx_pkts[nb_rx])) { + nb_rx++; + num--; +continue ; + } +break ; + }; + +PMD_RX_LOG (DEBUG ,"dequeue:%d" , num); + + rxvq->stats.packets += nb_rx; + +if (likely (vq->vq_free_cnt >= free_cnt)) { +struct rte_mbuf *new_pkts[free_cnt]; +if (likely (rte_pktmbuf_alloc_bulk (rxvq->mpool, new_pkts, + free_cnt) ==0 )) { +virtio_recv_refill_packed_vec (rxvq, new_pkts, + free_cnt); + nb_enqueued += free_cnt; + }else { +struct rte_eth_dev *dev = + &rte_eth_devices[rxvq->port_id]; + dev->data->rx_mbuf_alloc_failed += free_cnt; + } + } + +if (likely (nb_enqueued)) { +if (unlikely (virtqueue_kick_prepare_packed (vq))) { +virtqueue_notify (vq); +PMD_RX_LOG (DEBUG ,"Notified" ); + } + } + +return nb_rx; +}(quoted diff) +0
-0
b/drivers/net/virtio/virtio_user_ethdev.cQuoted 4 lines
Quoted 4 lines
drivers/net/virtio/virtio_user_ethdev.c virtio_user_eth_dev_alloc(struct
Quoted 4 lines
index
40ad786cc..c54698ad1100644drivers/net/virtio/virtio_user_ethdev.c +0
-0@@ -528,6 +528,7 @@ virtio_user_eth_dev_alloc(struct
rte_vdev_deviceQuoted 13 lines
Quoted 13 lines
*vdev)
drivers/net/virtio/virtio_user_ethdev.c virtio_user_pmd_probe(struct rte_vdev_device
Quoted 8 lines
drivers/net/virtio/virtio_user_ethdev.c +1
-0hw->use_msix =1 ; hw->modern =0 ; hw->use_vec_rx =0 ; + hw->use_vec_tx =0 ; hw->use_inorder_rx =0 ; hw->use_inorder_tx =0 ; hw->virtio_user_dev = dev;@@ -739,8 +740,19 @@ virtio_user_pmd_probe(struct rte_vdev_device*dev)
Quoted 3 lines
drivers/net/virtio/virtio_user_ethdev.c +0
-0goto end; }Quoted 10 lines
Quoted 10 lines
drivers/net/virtio/virtio_user_ethdev.c virtio_user_pmd_probe(struct rte_vdev_device *dev)
Quoted 10 lines
drivers/net/virtio/virtio_user_ethdev.c +8
-2-if (vectorized) - hw->use_vec_rx =1 ; +if (vectorized) { +if (packed_vq) { +#if defined(CC_AVX512_SUPPORT ) + hw->use_vec_rx =1 ; + hw->use_vec_tx =1 ; +#else + PMD_INIT_LOG(INFO, + "building environment do not supportpacked
Quoted 10 lines
Quoted 10 lines
ring vectorized");
Review
Quoted 9 lines
drivers/net/virtio/virtio_user_ethdev.c +5
-0+#endif + }else { + hw->use_vec_rx =1 ; + } + }rte_eth_dev_probing_finish (eth_dev); ret =0 ;(quoted diff) +0
-0
b/drivers/net/virtio/virtqueue.hQuoted 18 lines
Quoted 18 lines
drivers/net/virtio/virtqueue.h struct vq_desc_extra { · line 243
Quoted 10 lines
index
ca1c10499..ce0340743100644drivers/net/virtio/virtqueue.h +2
-1@@ -239,7 +239,8 @@ struct vq_desc_extra {void *cookie;uint16_t ndescs;uint16_t next; -}; +uint8_t padding[4 ]; +} __rte_packed __rte_aligned(16);Can't this introduce a performance impact for the non-vectorized case? I think of worse cache liens utilization.
For example with a burst of 32 descriptors with 32B cachelines, before it would take 14 cachelines, after 16. So for each burst, one could face 2 extra cache misses.
Quoted 7 lines
Quoted 3 lines
If you could run non-vectorized benchamrks with and without that patch, I would be grateful.
Maxime,
Thanks for point it out, it will add extra cache miss in datapath. And its impact on performance is around 1% in loopback case.Ok, thanks for doing the test. I'll try to run some PVP benchmarks on my side because when doing IO loopback, the cache pressure is much less important.
Quoted 7 lines
Quoted 1 line
While benefit of vectorized path will be more than that number.
Ok, but I disagree for two reasons:
1. You have to keep in mind than non-vectorized is the default and
encouraged mode to use. Indeed, it takes a lot of shortcuts like not checking header length (so no error stats), etc...
Ok, I will keep non-vectorized same as before.
Quoted 8 lines
2. It's like saying it's OK it degrades by 5% on $CPU_VENDOR_A because
the gain is 20% on $CPU_VENDOR_B.In the case we see more degradation in real-world scenario, you might want to consider using ifdefs to avoid adding padding in the non- vectorized case, like you did to differentiate Virtio PMD to Virtio-user PMD in patch 7.
Maxime,
The performance difference is so slight, so I ignored for it look like a sampling error.
It maybe not suitable to add new configuration for such setting which only used inside driver.
Virtio driver can check whether virtqueue is using vectorized path when initialization, will use padded structure if it is.
I have added some tested code and now performance came back. Since code has changed in initialization process, it need some time for regression check.
Regards,
Marvin
Quoted 11 lines
Thanks,
MaximeQuoted 8 lines
Thanks,
MarvinQuoted 4 lines
Reviewed-by Maxime Coquelin <[email protected]>Thanks,
Maxime
Re: [dpdk-dev] [PATCH v10 6/9] net/virtio: add vectorized packed ring Rx path
Quoted 18 lines · Yong
Quoted 7 lines
Quoted 3 lines
Maxime,
Thanks for point it out, it will add extra cache miss in datapath. And its impact on performance is around 1% in loopback case.Ok, thanks for doing the test. I'll try to run some PVP benchmarks on my side because when doing IO loopback, the cache pressure is much less important.
Quoted 6 lines
Quoted 1 line
While benefit of vectorized path will be more than that number.
Ok, but I disagree for two reasons:
1. You have to keep in mind than non-vectorized is the default and
encouraged mode to use. Indeed, it takes a lot of shortcuts like not checking header length (so no error stats), etc...Ok, I will keep non-vectorized same as before.
Quoted 3 lines
2. It's like saying it's OK it degrades by 5% on $CPU_VENDOR_A because
the gain is 20% on $CPU_VENDOR_B.
Quoted 7 lines
Quoted 5 lines
In the case we see more degradation in real-world scenario, you might want to consider using ifdefs to avoid adding padding in the non- vectorized case, like you did to differentiate Virtio PMD to Virtio-user PMD in patch 7.
Maxime,
The performance difference is so slight, so I ignored for it look like a sampling error.
Agree for IO loopback, but it adds one more cache line access per burst, which might be see in some real-life use cases.
Quoted 1 line
It maybe not suitable to add new configuration for such setting which only used inside driver.
Wait, the Virtio-user #ifdef is based on the defconfig options? How can it work since both Virtio PMD and Virtio-user PMD can be selected at the same time?
I thought it was a define set before the headers inclusion and unset afterwards, but I didn't checked carefully.
Quoted 2 lines
Virtio driver can check whether virtqueue is using vectorized path when initialization, will use padded structure if it is.
I have added some tested code and now performance came back. Since code has changed in initialization process, it need some time for regression check.
Ok, works for me.
I am investigating a linkage issue with your series, which does not happen systematically (see below, it happens also with clang). David pointed me to some Intel patches removing the usage if __rte_weak, could it be related?
gcc -o app/test/dpdk-test
'app/test/3062f5d@@dpdk-test@exe/commands.c.o' 'app/test/3062f5d@@dpdk-test@exe/packet_burst_generator.c.o' 'app/test/3062f5d@@dpdk-test@exe/test.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_acl.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_alarm.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_atomic.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_barrier.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_bpf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_byteorder.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_cmdline.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_cmdline_cirbuf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_cmdline_etheraddr.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_cmdline_ipaddr.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_cmdline_lib.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_cmdline_num.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_cmdline_portlist.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_cmdline_string.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_common.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_cpuflags.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_crc.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_cryptodev.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_cryptodev_asym.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_cryptodev_blockcipher.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_cryptodev_security_pdcp.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_cycles.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_debug.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_distributor.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_distributor_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_eal_flags.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_eal_fs.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_efd.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_efd_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_errno.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_event_crypto_adapter.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_event_eth_rx_adapter.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_event_ring.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_event_timer_adapter.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_eventdev.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_external_mem.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_fbarray.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_fib.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_fib_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_fib6.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_fib6_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_func_reentrancy.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_flow_classify.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_hash.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_hash_functions.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_hash_multiwriter.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_hash_readwrite.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_hash_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_hash_readwrite_lf_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_interrupts.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_ipfrag.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_ipsec.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_ipsec_sad.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_kni.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_kvargs.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_link_bonding.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_link_bonding_rssconf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_logs.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_lpm.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_lpm6.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_lpm6_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_lpm_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_malloc.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_mbuf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_member.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_member_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_memcpy.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_memcpy_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_memory.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_mempool.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_mempool_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_memzone.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_meter.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_metrics.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_mcslock.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_mp_secondary.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_per_lcore.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_pmd_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_power.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_power_cpufreq.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_power_kvm_vm.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_prefetch.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_rand_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_rawdev.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_rcu_qsbr.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_rcu_qsbr_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_reciprocal_division.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_reciprocal_division_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_red.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_reorder.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_rib.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_rib6.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_ring.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_ring_mpmc_stress.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_ring_hts_stress.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_ring_peek_stress.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_ring_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_ring_rts_stress.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_ring_stress.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_rwlock.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_sched.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_security.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_service_cores.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_spinlock.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_stack.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_stack_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_string_fns.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_table.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_table_acl.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_table_combined.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_table_pipeline.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_table_ports.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_table_tables.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_tailq.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_thash.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_timer.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_timer_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_timer_racecond.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_timer_secondary.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_ticketlock.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_trace.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_trace_register.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_trace_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_version.c.o' 'app/test/3062f5d@@dpdk-test@exe/virtual_pmd.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_pmd_ring_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_pmd_ring.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_event_eth_tx_adapter.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_bitratestats.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_latencystats.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_link_bonding_mode4.c.o' 'app/test/3062f5d@@dpdk-test@exe/sample_packet_forward.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_pdump.c.o' -Wl,--no-undefined -Wl,--as-needed -Wl,-O1 -Wl,--whole-archive -Wl,--start-group drivers/librte_common_cpt.a drivers/librte_common_dpaax.a drivers/librte_common_iavf.a drivers/librte_common_octeontx.a drivers/librte_common_octeontx2.a drivers/librte_bus_dpaa.a drivers/librte_bus_fslmc.a drivers/librte_bus_ifpga.adrivers/librte_bus_pci.a drivers/librte_bus_vdev.adrivers/librte_bus_vmbus.a drivers/librte_mempool_bucket.a drivers/librte_mempool_dpaa.a drivers/librte_mempool_dpaa2.a drivers/librte_mempool_octeontx.a drivers/librte_mempool_octeontx2.a drivers/librte_mempool_ring.a drivers/librte_mempool_stack.a drivers/librte_pmd_af_packet.a drivers/librte_pmd_ark.a drivers/librte_pmd_atlantic.a drivers/librte_pmd_avp.a drivers/librte_pmd_axgbe.a drivers/librte_pmd_bond.adrivers/librte_pmd_bnxt.a drivers/librte_pmd_cxgbe.adrivers/librte_pmd_dpaa.a drivers/librte_pmd_dpaa2.adrivers/librte_pmd_e1000.a drivers/librte_pmd_ena.adrivers/librte_pmd_enetc.a drivers/librte_pmd_enic.a drivers/librte_pmd_failsafe.a drivers/librte_pmd_fm10k.a drivers/librte_pmd_i40e.a drivers/librte_pmd_hinic.adrivers/librte_pmd_hns3.a drivers/librte_pmd_iavf.adrivers/librte_pmd_ice.a drivers/librte_pmd_igc.adrivers/librte_pmd_ixgbe.a drivers/librte_pmd_kni.a drivers/librte_pmd_liquidio.a drivers/librte_pmd_memif.a drivers/librte_pmd_netvsc.a drivers/librte_pmd_nfp.adrivers/librte_pmd_null.a drivers/librte_pmd_octeontx.a drivers/librte_pmd_octeontx2.a drivers/librte_pmd_pfe.a drivers/librte_pmd_qede.a drivers/librte_pmd_ring.adrivers/librte_pmd_sfc.a drivers/librte_pmd_softnic.adrivers/librte_pmd_tap.a drivers/librte_pmd_thunderx.a drivers/librte_pmd_vdev_netvsc.a drivers/librte_pmd_vhost.a drivers/librte_pmd_virtio.a drivers/librte_pmd_vmxnet3.a drivers/librte_rawdev_dpaa2_cmdif.a drivers/librte_rawdev_dpaa2_qdma.a drivers/librte_rawdev_ioat.a drivers/librte_rawdev_ntb.a drivers/librte_rawdev_octeontx2_dma.adrivers/librte_rawdev_octeontx2_ep.a drivers/librte_rawdev_skeleton.a drivers/librte_pmd_caam_jr.a drivers/librte_pmd_dpaa_sec.a drivers/librte_pmd_dpaa2_sec.a drivers/librte_pmd_nitrox.a drivers/librte_pmd_null_crypto.a drivers/librte_pmd_octeontx_crypto.a drivers/librte_pmd_octeontx2_crypto.adrivers/librte_pmd_crypto_scheduler.a drivers/librte_pmd_virtio_crypto.a drivers/librte_pmd_octeontx_compress.a drivers/librte_pmd_qat.a drivers/librte_pmd_ifc.a drivers/librte_pmd_dpaa_event.a drivers/librte_pmd_dpaa2_event.a drivers/librte_pmd_octeontx2_event.a drivers/librte_pmd_opdl_event.a drivers/librte_pmd_skeleton_event.a drivers/librte_pmd_sw_event.a drivers/librte_pmd_dsw_event.a drivers/librte_pmd_octeontx_event.a drivers/librte_pmd_bbdev_null.a drivers/librte_pmd_bbdev_turbo_sw.adrivers/librte_pmd_bbdev_fpga_lte_fec.adrivers/librte_pmd_bbdev_fpga_5gnr_fec.a -Wl,--no-whole-archive -Wl,--no-as-needed -pthread -lm -ldl -lnuma lib/librte_acl.alib/librte_eal.a lib/librte_kvargs.a lib/librte_bitratestats.a lib/librte_ethdev.a lib/librte_net.a lib/librte_mbuf.alib/librte_mempool.a lib/librte_ring.a lib/librte_meter.alib/librte_metrics.a lib/librte_bpf.a lib/librte_cfgfile.alib/librte_cmdline.a lib/librte_cryptodev.a lib/librte_distributor.a lib/librte_efd.a lib/librte_hash.a lib/librte_eventdev.alib/librte_timer.a lib/librte_fib.a lib/librte_rib.alib/librte_flow_classify.a lib/librte_table.a lib/librte_port.a lib/librte_sched.a lib/librte_ip_frag.a lib/librte_kni.alib/librte_pci.a lib/librte_lpm.a lib/librte_ipsec.alib/librte_security.a lib/librte_latencystats.a lib/librte_member.a lib/librte_pipeline.a lib/librte_rawdev.a lib/librte_rcu.alib/librte_reorder.a lib/librte_stack.a lib/librte_power.alib/librte_pdump.a lib/librte_gso.a lib/librte_vhost.alib/librte_compressdev.a lib/librte_bbdev.a -Wl,--end-group '-Wl,-rpath,$ORIGIN/../../lib:$ORIGIN/../../drivers' -Wl,-rpath-link,/tmp/dpdk_build/meson_buildir_gcc/lib:/tmp/dpdk_build/meson_buildir_gcc/drivers drivers/librte_pmd_virtio.a(net_virtio_virtio_ethdev.c.o): In function `set_rxtx_funcs':
virtio_ethdev.c:(.text.unlikely+0x6f): undefined reference to `virtio_xmit_pkts_packed_vec'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
Quoted 3 lines
Regards,
Marvin
Re: [dpdk-dev] [PATCH v10 6/9] net/virtio: add vectorized packed ring Rx path
Quoted 45 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Tuesday, April 28, 2020 9:46 PM
To: Liu, Yong <[email protected]>; Ye, Xiaolong <[email protected]>; Wang, Zhihong <[email protected]>
Cc: [email protected]; Honnappa Nagarahalli <[email protected]>; [email protected]
Subject: Re: [PATCH v10 6/9] net/virtio: add vectorized packed ring Rx pathQuoted 18 lines · Yong
Quoted 7 lines
Quoted 3 lines
Maxime,
Thanks for point it out, it will add extra cache miss in datapath. And its impact on performance is around 1% in loopback case.Ok, thanks for doing the test. I'll try to run some PVP benchmarks on my side because when doing IO loopback, the cache pressure is much less important.
Quoted 6 lines
Quoted 1 line
While benefit of vectorized path will be more than that number.
Ok, but I disagree for two reasons:
1. You have to keep in mind than non-vectorized is the default and
encouraged mode to use. Indeed, it takes a lot of shortcuts like not checking header length (so no error stats), etc...Ok, I will keep non-vectorized same as before.
Quoted 3 lines
2. It's like saying it's OK it degrades by 5% on $CPU_VENDOR_A because
the gain is 20% on $CPU_VENDOR_B.Quoted 7 lines
Quoted 5 lines
In the case we see more degradation in real-world scenario, you might want to consider using ifdefs to avoid adding padding in the non- vectorized case, like you did to differentiate Virtio PMD to Virtio-user PMD in patch 7.
Maxime,
The performance difference is so slight, so I ignored for it look like asampling error.
Agree for IO loopback, but it adds one more cache line access per burst, which might be see in some real-life use cases.
Quoted 1 line
It maybe not suitable to add new configuration for such setting which
Quoted 9 lines
only used inside driver.
Wait, the Virtio-user #ifdef is based on the defconfig options? How can it work since both Virtio PMD and Virtio-user PMD can be selected at the same time?
I thought it was a define set before the headers inclusion and unset afterwards, but I didn't checked carefully.
Maxime,
The difference between virtio PMD and Virtio-user PMD addresses is handled by vq->offset.
When virtio PMD is running, offset will be set to buf_iova. vq->offset = offsetof(struct rte_mbuf, buf_iova);
When virtio_user PMD is running, offset will be set to buf_addr. vq->offset = offsetof(struct rte_mbuf, buf_addr);
Quoted 6 lines
Quoted 1 line
Virtio driver can check whether virtqueue is using vectorized path when
initialization, will use padded structure if it is.
Quoted 1 line
I have added some tested code and now performance came back. Since
code has changed in initialization process, it need some time for regression check.
Quoted 7 lines
Ok, works for me.
I am investigating a linkage issue with your series, which does not happen systematically (see below, it happens also with clang). David pointed me to some Intel patches removing the usage if
__rte_weak, could it be related?
I checked David's patch, it only changed i40e driver. Meanwhile attribute __rte_weak should still be in virtio_rxtx.c. I will follow David's patch, eliminate the usage of weak attribute.
Quoted 217 lines
gcc -o app/test/dpdk-test '
app/test/3062f5d@@dpdk-test@exe/commands.c.o' 'app/test/3062f5d@@dpdk-test@exe/packet_burst_generator.c.o' 'app/test/3062f5d@@dpdk-test@exe/test.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_acl.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_alarm.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_atomic.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_barrier.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_bpf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_byteorder.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_cmdline.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_cmdline_cirbuf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_cmdline_etheraddr.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_cmdline_ipaddr.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_cmdline_lib.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_cmdline_num.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_cmdline_portlist.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_cmdline_string.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_common.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_cpuflags.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_crc.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_cryptodev.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_cryptodev_asym.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_cryptodev_blockcipher.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_cryptodev_security_pdcp.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_cycles.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_debug.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_distributor.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_distributor_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_eal_flags.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_eal_fs.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_efd.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_efd_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_errno.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_event_crypto_adapter.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_event_eth_rx_adapter.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_event_ring.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_event_timer_adapter.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_eventdev.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_external_mem.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_fbarray.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_fib.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_fib_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_fib6.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_fib6_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_func_reentrancy.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_flow_classify.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_hash.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_hash_functions.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_hash_multiwriter.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_hash_readwrite.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_hash_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_hash_readwrite_lf_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_interrupts.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_ipfrag.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_ipsec.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_ipsec_sad.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_kni.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_kvargs.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_link_bonding.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_link_bonding_rssconf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_logs.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_lpm.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_lpm6.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_lpm6_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_lpm_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_malloc.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_mbuf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_member.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_member_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_memcpy.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_memcpy_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_memory.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_mempool.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_mempool_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_memzone.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_meter.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_metrics.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_mcslock.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_mp_secondary.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_per_lcore.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_pmd_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_power.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_power_cpufreq.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_power_kvm_vm.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_prefetch.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_rand_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_rawdev.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_rcu_qsbr.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_rcu_qsbr_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_reciprocal_division.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_reciprocal_division_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_red.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_reorder.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_rib.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_rib6.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_ring.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_ring_mpmc_stress.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_ring_hts_stress.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_ring_peek_stress.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_ring_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_ring_rts_stress.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_ring_stress.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_rwlock.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_sched.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_security.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_service_cores.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_spinlock.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_stack.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_stack_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_string_fns.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_table.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_table_acl.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_table_combined.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_table_pipeline.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_table_ports.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_table_tables.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_tailq.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_thash.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_timer.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_timer_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_timer_racecond.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_timer_secondary.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_ticketlock.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_trace.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_trace_register.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_trace_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_version.c.o' 'app/test/3062f5d@@dpdk-test@exe/virtual_pmd.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_pmd_ring_perf.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_pmd_ring.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_event_eth_tx_adapter.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_bitratestats.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_latencystats.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_link_bonding_mode4.c.o' 'app/test/3062f5d@@dpdk-test@exe/sample_packet_forward.c.o' 'app/test/3062f5d@@dpdk-test@exe/test_pdump.c.o' -Wl,--no-undefined -Wl,--as-needed -Wl,-O1 -Wl,--whole-archive -Wl,--start-groupdrivers/librte_common_cpt.adrivers/librte_common_dpaax.adrivers/librte_common_iavf.adrivers/librte_common_octeontx.adrivers/librte_common_octeontx2.adrivers/librte_bus_dpaa.adrivers/librte_bus_fslmc.adrivers/librte_bus_ifpga.adrivers/librte_bus_pci.adrivers/librte_bus_vdev.adrivers/librte_bus_vmbus.adrivers/librte_mempool_bucket.adrivers/librte_mempool_dpaa.adrivers/librte_mempool_dpaa2.adrivers/librte_mempool_octeontx.adrivers/librte_mempool_octeontx2.adrivers/librte_mempool_ring.adrivers/librte_mempool_stack.adrivers/librte_pmd_af_packet.adrivers/librte_pmd_ark.adrivers/librte_pmd_atlantic.adrivers/librte_pmd_avp.adrivers/librte_pmd_axgbe.adrivers/librte_pmd_bond.adrivers/librte_pmd_bnxt.adrivers/librte_pmd_cxgbe.adrivers/librte_pmd_dpaa.adrivers/librte_pmd_dpaa2.adrivers/librte_pmd_e1000.adrivers/librte_pmd_ena.adrivers/librte_pmd_enetc.adrivers/librte_pmd_enic.adrivers/librte_pmd_failsafe.adrivers/librte_pmd_fm10k.adrivers/librte_pmd_i40e.adrivers/librte_pmd_hinic.adrivers/librte_pmd_hns3.adrivers/librte_pmd_iavf.adrivers/librte_pmd_ice.adrivers/librte_pmd_igc.adrivers/librte_pmd_ixgbe.adrivers/librte_pmd_kni.adrivers/librte_pmd_liquidio.adrivers/librte_pmd_memif.adrivers/librte_pmd_netvsc.adrivers/librte_pmd_nfp.adrivers/librte_pmd_null.adrivers/librte_pmd_octeontx.adrivers/librte_pmd_octeontx2.adrivers/librte_pmd_pfe.adrivers/librte_pmd_qede.adrivers/librte_pmd_ring.adrivers/librte_pmd_sfc.adrivers/librte_pmd_softnic.adrivers/librte_pmd_tap.adrivers/librte_pmd_thunderx.adrivers/librte_pmd_vdev_netvsc.adrivers/librte_pmd_vhost.adrivers/librte_pmd_virtio.adrivers/librte_pmd_vmxnet3.adrivers/librte_rawdev_dpaa2_cmdif.adrivers/librte_rawdev_dpaa2_qdma.adrivers/librte_rawdev_ioat.adrivers/librte_rawdev_ntb.adrivers/librte_rawdev_octeontx2_dma.adrivers/librte_rawdev_octeontx2_ep.adrivers/librte_rawdev_skeleton.adrivers/librte_pmd_caam_jr.adrivers/librte_pmd_dpaa_sec.adrivers/librte_pmd_dpaa2_sec.adrivers/librte_pmd_nitrox.adrivers/librte_pmd_null_crypto.adrivers/librte_pmd_octeontx_crypto.adrivers/librte_pmd_octeontx2_crypto.adrivers/librte_pmd_crypto_scheduler.adrivers/librte_pmd_virtio_crypto.adrivers/librte_pmd_octeontx_compress.adrivers/librte_pmd_qat.adrivers/librte_pmd_ifc.adrivers/librte_pmd_dpaa_event.adrivers/librte_pmd_dpaa2_event.adrivers/librte_pmd_octeontx2_event.adrivers/librte_pmd_opdl_event.adrivers/librte_pmd_skeleton_event.adrivers/librte_pmd_sw_event.adrivers/librte_pmd_dsw_event.adrivers/librte_pmd_octeontx_event.adrivers/librte_pmd_bbdev_null.adrivers/librte_pmd_bbdev_turbo_sw.adrivers/librte_pmd_bbdev_fpga_lte_fec.adrivers/librte_pmd_bbdev_fpga_5gnr_fec.a-Wl,--no-whole-archive -Wl,--no-as-needed -pthread -lm -ldl -lnumalib/librte_acl.alib/librte_eal.alib/librte_kvargs.alib/librte_bitratestats.alib/librte_ethdev.alib/librte_net.alib/librte_mbuf.alib/librte_mempool.alib/librte_ring.alib/librte_meter.alib/librte_metrics.alib/librte_bpf.alib/librte_cfgfile.alib/librte_cmdline.alib/librte_cryptodev.alib/librte_distributor.alib/librte_efd.alib/librte_hash.alib/librte_eventdev.alib/librte_timer.alib/librte_fib.alib/librte_rib.alib/librte_flow_classify.alib/librte_table.alib/librte_port.alib/librte_sched.alib/librte_ip_frag.alib/librte_kni.alib/librte_pci.alib/librte_lpm.alib/librte_ipsec.alib/librte_security.alib/librte_latencystats.alib/librte_member.alib/librte_pipeline.alib/librte_rawdev.alib/librte_rcu.alib/librte_reorder.alib/librte_stack.alib/librte_power.alib/librte_pdump.alib/librte_gso.alib/librte_vhost.alib/librte_compressdev.alib/librte_bbdev.a-Wl,--end-group '-Wl,-rpath,$ORIGIN/../../lib:$ORIGIN/../../drivers' -Wl,-rpath- link,/tmp/dpdk_build/meson_buildir_gcc/lib:/tmp/dpdk_build/meson_buil dir_gcc/drivers drivers/librte_pmd_virtio.a(net_virtio_virtio_ethdev.c.o): In function `set_rxtx_funcs':
virtio_ethdev.c:(.text.unlikely+0x6f): undefined reference to `virtio_xmit_pkts_packed_vec'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.Quoted 3 lines
Regards,
Marvin
Re: [dpdk-dev] [PATCH v10 6/9] net/virtio: add vectorized packed ring Rx path
Quoted 55 lines · Yong
Quoted 45 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Tuesday, April 28, 2020 9:46 PM
To: Liu, Yong <[email protected]>; Ye, Xiaolong <[email protected]>; Wang, Zhihong <[email protected]>
Cc: [email protected]; Honnappa Nagarahalli <[email protected]>; [email protected]
Subject: Re: [PATCH v10 6/9] net/virtio: add vectorized packed ring Rx pathQuoted 18 lines · Yong
Quoted 7 lines
Quoted 3 lines
Maxime,
Thanks for point it out, it will add extra cache miss in datapath. And its impact on performance is around 1% in loopback case.Ok, thanks for doing the test. I'll try to run some PVP benchmarks on my side because when doing IO loopback, the cache pressure is much less important.
Quoted 6 lines
Quoted 1 line
While benefit of vectorized path will be more than that number.
Ok, but I disagree for two reasons:
1. You have to keep in mind than non-vectorized is the default and
encouraged mode to use. Indeed, it takes a lot of shortcuts like not checking header length (so no error stats), etc...Ok, I will keep non-vectorized same as before.
Quoted 3 lines
2. It's like saying it's OK it degrades by 5% on $CPU_VENDOR_A because
the gain is 20% on $CPU_VENDOR_B.Quoted 7 lines
Quoted 5 lines
In the case we see more degradation in real-world scenario, you might want to consider using ifdefs to avoid adding padding in the non- vectorized case, like you did to differentiate Virtio PMD to Virtio-user PMD in patch 7.
Maxime,
The performance difference is so slight, so I ignored for it look like asampling error.
Agree for IO loopback, but it adds one more cache line access per burst, which might be see in some real-life use cases.
Quoted 1 line
It maybe not suitable to add new configuration for such setting which
Quoted 9 lines
only used inside driver.
Wait, the Virtio-user #ifdef is based on the defconfig options? How can it work since both Virtio PMD and Virtio-user PMD can be selected at the same time?
I thought it was a define set before the headers inclusion and unset afterwards, but I didn't checked carefully.
Quoted 8 lines
Maxime,
The difference between virtio PMD and Virtio-user PMD addresses is handled byvq->offset.When virtio PMD is running, offset will be set to
buf_iova.vq->offset=offsetof(struct rte_mbuf, buf_iova);When
virtio_userPMD is running, offset will be set tobuf_addr.vq->offset=offsetof(struct rte_mbuf, buf_addr);
Ok, but below is a build time check:
+#ifdef RTE_VIRTIO_USER
+ __m128i flag_offset = _mm_set_epi64x(flags_temp, (uint64_t)vq->offset);
+#else
+ __m128i flag_offset = _mm_set_epi64x(flags_temp, 0);
+#endif
So how can it work for a single build for both Virtio and Virtio-user?
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Virtio driver can check whether virtqueue is using vectorized path when
initialization, will use padded structure if it is.
Quoted 1 line
I have added some tested code and now performance came back. Since
code has changed in initialization process, it need some time for regression check.
Ok, works for me.
Quoted 8 lines
Quoted 5 lines
I am investigating a linkage issue with your series, which does not happen systematically (see below, it happens also with clang). David pointed me to some Intel patches removing the usage if
__rte_weak, could it be related?I checked David's patch, it only changed i40e driver. Meanwhile attribute
__rte_weakshould still be invirtio_rxtx.c. I will follow David's patch, eliminate the usage of weak attribute.
Yeah, I meant below issue could be linked to __rte_weak, not that i40e patch was the cause of this problem.
Re: [dpdk-dev] [PATCH v10 6/9] net/virtio: add vectorized packed ring Rx path
Quoted 91 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Tuesday, April 28, 2020 10:50 PM
To: Liu, Yong <[email protected]>; Ye, Xiaolong <[email protected]>; Wang, Zhihong <[email protected]>
Cc: [email protected]; Honnappa Nagarahalli <[email protected]>; [email protected]
Subject: Re: [PATCH v10 6/9] net/virtio: add vectorized packed ring Rx pathQuoted 6 lines · Yong
Quoted 6 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Tuesday, April 28, 2020 9:46 PM
To: Liu, Yong <[email protected]>; Ye, XiaolongQuoted 4 lines
Quoted 4 lines
Wang, Zhihong <[email protected]>
Cc: [email protected]; Honnappa Nagarahalli <[email protected]>; [email protected]
Subject: Re: [PATCH v10 6/9] net/virtio: add vectorized packed ring Rxpath
Quoted 12 lines
Quoted 12 lines · Yong
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Maxime,
Thanks for point it out, it will add extra cache miss in datapath. And its impact on performance is around 1% in loopback case.Ok, thanks for doing the test. I'll try to run some PVP benchmarks on my side because when doing IO loopback, the cache pressure is much less important.
Quoted 1 line
While benefit of vectorized path will be more than that number.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Ok, but I disagree for two reasons:
1. You have to keep in mind than non-vectorized is the default and
encouraged mode to use. Indeed, it takes a lot of shortcuts like not checking header length (so no error stats), etc...Ok, I will keep non-vectorized same as before.
Quoted 1 line
2. It's like saying it's OK it degrades by 5% on $CPU_VENDOR_A
because
Quoted 21 lines
Quoted 21 lines
Quoted 9 lines
Quoted 7 lines
the gain is 20% on $CPU_VENDOR_B.
In the case we see more degradation in real-world scenario, you might want to consider using ifdefs to avoid adding padding in the non- vectorized case, like you did to differentiate Virtio PMD to Virtio-user PMD in patch 7.
Maxime,
The performance difference is so slight, so I ignored for it look like asampling error.
Agree for IO loopback, but it adds one more cache line access per burst, which might be see in some real-life use cases.
Quoted 1 line
It maybe not suitable to add new configuration for such setting which
only used inside driver.
Wait, the Virtio-user #ifdef is based on the defconfig options? How can it work since both Virtio PMD and Virtio-user PMD can be selected at the same time?
Quoted 6 lines
Quoted 3 lines
I thought it was a define set before the headers inclusion and unset afterwards, but I didn't checked carefully.
Maxime,
The difference between virtio PMD and Virtio-user PMD addresses ishandled by
vq->offset.Quoted 6 lines
When virtio PMD is running, offset will be set to
buf_iova.vq->offset=offsetof(struct rte_mbuf, buf_iova);When
virtio_userPMD is running, offset will be set tobuf_addr.vq->offset=offsetof(struct rte_mbuf, buf_addr);Ok, but below is a build time check:
(quoted diff) +2
-0+#ifdef RTE_VIRTIO_USER + __m128i flag_offset = _mm_set_epi64x(flags_temp, (uint64_t)vq-Quoted 1 line
offset);
(quoted diff) +3
-0+#else + __m128i flag_offset = _mm_set_epi64x(flags_temp, 0); +#endif
Quoted 2 lines
So how can it work for a single build for both Virtio and Virtio-user?
Sorry, here is an implementation error. vq->offset should be used in descs_base for getting the iova address. It will work the same as VIRTIO_MBUF_ADDR macro.
Quoted 15 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Virtio driver can check whether virtqueue is using vectorized path when
initialization, will use padded structure if it is.
Quoted 1 line
I have added some tested code and now performance came back. Since
code has changed in initialization process, it need some time for
regression
Quoted 10 lines
Quoted 9 lines
check.
Ok, works for me.
I am investigating a linkage issue with your series, which does not happen systematically (see below, it happens also with clang). David pointed me to some Intel patches removing the usage if
__rte_weak, could it be related?
Quoted 7 lines
Quoted 1 line
I checked David's patch, it only changed i40e driver. Meanwhile attribute
__rte_weakshould still be invirtio_rxtx.c.Quoted 1 line
I will follow David's patch, eliminate the usage of weak attribute.
Yeah, I meant below issue could be linked to
__rte_weak, not that i40e patch was the cause of this problem.
Maxime,
I haven't seen any build issue related to __rte_weak both with gcc and clang.
Thanks,
Marvin
Re: [dpdk-dev] [PATCH v10 6/9] net/virtio: add vectorized packed ring Rx path
Quoted 114 lines · Yong
Quoted 91 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Tuesday, April 28, 2020 10:50 PM
To: Liu, Yong <[email protected]>; Ye, Xiaolong <[email protected]>; Wang, Zhihong <[email protected]>
Cc: [email protected]; Honnappa Nagarahalli <[email protected]>; [email protected]
Subject: Re: [PATCH v10 6/9] net/virtio: add vectorized packed ring Rx pathQuoted 6 lines · Yong
Quoted 6 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Tuesday, April 28, 2020 9:46 PM
To: Liu, Yong <[email protected]>; Ye, XiaolongQuoted 4 lines
Quoted 4 lines
Wang, Zhihong <[email protected]>
Cc: [email protected]; Honnappa Nagarahalli <[email protected]>; [email protected]
Subject: Re: [PATCH v10 6/9] net/virtio: add vectorized packed ring Rxpath
Quoted 12 lines
Quoted 12 lines · Yong
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Maxime,
Thanks for point it out, it will add extra cache miss in datapath. And its impact on performance is around 1% in loopback case.Ok, thanks for doing the test. I'll try to run some PVP benchmarks on my side because when doing IO loopback, the cache pressure is much less important.
Quoted 1 line
While benefit of vectorized path will be more than that number.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Ok, but I disagree for two reasons:
1. You have to keep in mind than non-vectorized is the default and
encouraged mode to use. Indeed, it takes a lot of shortcuts like not checking header length (so no error stats), etc...Ok, I will keep non-vectorized same as before.
Quoted 1 line
2. It's like saying it's OK it degrades by 5% on $CPU_VENDOR_A
because
Quoted 21 lines
Quoted 21 lines
Quoted 9 lines
Quoted 7 lines
the gain is 20% on $CPU_VENDOR_B.
In the case we see more degradation in real-world scenario, you might want to consider using ifdefs to avoid adding padding in the non- vectorized case, like you did to differentiate Virtio PMD to Virtio-user PMD in patch 7.
Maxime,
The performance difference is so slight, so I ignored for it look like asampling error.
Agree for IO loopback, but it adds one more cache line access per burst, which might be see in some real-life use cases.
Quoted 1 line
It maybe not suitable to add new configuration for such setting which
only used inside driver.
Wait, the Virtio-user #ifdef is based on the defconfig options? How can it work since both Virtio PMD and Virtio-user PMD can be selected at the same time?
Quoted 6 lines
Quoted 3 lines
I thought it was a define set before the headers inclusion and unset afterwards, but I didn't checked carefully.
Maxime,
The difference between virtio PMD and Virtio-user PMD addresses ishandled by
vq->offset.Quoted 6 lines
When virtio PMD is running, offset will be set to
buf_iova.vq->offset=offsetof(struct rte_mbuf, buf_iova);When
virtio_userPMD is running, offset will be set tobuf_addr.vq->offset=offsetof(struct rte_mbuf, buf_addr);Ok, but below is a build time check:
(quoted diff) +2
-0+#ifdef RTE_VIRTIO_USER + __m128i flag_offset = _mm_set_epi64x(flags_temp, (uint64_t)vq-Quoted 1 line
offset);
(quoted diff) +3
-0+#else + __m128i flag_offset = _mm_set_epi64x(flags_temp, 0); +#endifQuoted 2 lines
So how can it work for a single build for both Virtio and Virtio-user?
Sorry, here is an implementation error.
vq->offsetshould be used indescs_basefor getting the iova address. It will work the same asVIRTIO_MBUF_ADDRmacro.Quoted 17 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Virtio driver can check whether virtqueue is using vectorized path when
initialization, will use padded structure if it is.
Quoted 1 line
I have added some tested code and now performance came back. Since
code has changed in initialization process, it need some time for
regression
Quoted 11 lines
Quoted 9 lines
check.
Ok, works for me.
I am investigating a linkage issue with your series, which does not happen systematically (see below, it happens also with clang). David pointed me to some Intel patches removing the usage if
__rte_weak, could it be related?I checked David's patch, it only changed i40e driver. Meanwhile attribute
__rte_weakshould still be invirtio_rxtx.c.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
I will follow David's patch, eliminate the usage of weak attribute.
Yeah, I meant below issue could be linked to
__rte_weak, not that i40e patch was the cause of this problem.Maxime,
I haven't seen any build issue related to__rte_weakboth with gcc and clang.
Note that this build (which does not fail systematically) is when using binutils 2.30, which cause AVX512 support to be disabled.
Quoted 3 lines
Thanks,
Marvin
Re: [dpdk-dev] [PATCH v10 6/9] net/virtio: add vectorized packed ring Rx path
Quoted 146 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Tuesday, April 28, 2020 11:40 PM
To: Liu, Yong <[email protected]>; Ye, Xiaolong <[email protected]>; Wang, Zhihong <[email protected]>
Cc: [email protected]; Honnappa Nagarahalli <[email protected]>; [email protected]
Subject: Re: [PATCH v10 6/9] net/virtio: add vectorized packed ring Rx pathQuoted 6 lines · Yong
Quoted 6 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Tuesday, April 28, 2020 10:50 PM
To: Liu, Yong <[email protected]>; Ye, XiaolongQuoted 4 lines
Quoted 4 lines
Wang, Zhihong <[email protected]>
Cc: [email protected]; Honnappa Nagarahalli <[email protected]>; [email protected]
Subject: Re: [PATCH v10 6/9] net/virtio: add vectorized packed ring Rxpath
Quoted 33 lines
Quoted 33 lines · Yong
Quoted 6 lines
Quoted 6 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Tuesday, April 28, 2020 9:46 PM
To: Liu, Yong <[email protected]>; Ye, XiaolongQuoted 4 lines
Quoted 4 lines
Wang, Zhihong <[email protected]>
Cc: [email protected]; Honnappa Nagarahalli <[email protected]>; [email protected]
Subject: Re: [PATCH v10 6/9] net/virtio: add vectorized packed ring Rxpath
Quoted 17 lines
Quoted 17 lines · Yong
Quoted 13 lines
Quoted 13 lines
Quoted 3 lines
Maxime,
Thanks for point it out, it will add extra cache miss in datapath. And its impact on performance is around 1% in loopback case.Ok, thanks for doing the test. I'll try to run some PVP benchmarks on my side because when doing IO loopback, the cache pressure is much less important.
Quoted 1 line
While benefit of vectorized path will be more than that number.
Ok, but I disagree for two reasons:
1. You have to keep in mind than non-vectorized is the default and
encouraged mode to use. Indeed, it takes a lot of shortcuts like not checking header length (so no error stats), etc...Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Ok, I will keep non-vectorized same as before.
Quoted 1 line
2. It's like saying it's OK it degrades by 5% on $CPU_VENDOR_A
because
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
the gain is 20% on $CPU_VENDOR_B.
In the case we see more degradation in real-world scenario, you
might
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
want to consider using ifdefs to avoid adding padding in the non- vectorized case, like you did to differentiate Virtio PMD to Virtio-
user
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
PMD in patch 7.
Maxime,
The performance difference is so slight, so I ignored for it look like asampling error.
Agree for IO loopback, but it adds one more cache line access per
burst,
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
which might be see in some real-life use cases.
Quoted 1 line
It maybe not suitable to add new configuration for such setting
which
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
only used inside driver.
Wait, the Virtio-user #ifdef is based on the defconfig options? How
can
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
it work since both Virtio PMD and Virtio-user PMD can be selected at
the
Quoted 21 lines
Quoted 21 lines
Quoted 8 lines
Quoted 5 lines
same time?
I thought it was a define set before the headers inclusion and unset afterwards, but I didn't checked carefully.
Maxime,
The difference between virtio PMD and Virtio-user PMD addresses ishandled by
vq->offset.Quoted 6 lines
When virtio PMD is running, offset will be set to
buf_iova.vq->offset=offsetof(struct rte_mbuf, buf_iova);When
virtio_userPMD is running, offset will be set tobuf_addr.vq->offset=offsetof(struct rte_mbuf, buf_addr);Ok, but below is a build time check:
(quoted diff) +2
-0+#ifdef RTE_VIRTIO_USER + __m128i flag_offset = _mm_set_epi64x(flags_temp, (uint64_t)vq-Quoted 1 line
offset);
Quoted 8 lines
Quoted 6 lines
(quoted diff) +3
-0+#else + __m128i flag_offset = _mm_set_epi64x(flags_temp, 0); +#endifSo how can it work for a single build for both Virtio and Virtio-user?
Sorry, here is an implementation error.
vq->offsetshould be used in
descs_basefor getting the iova address.Quoted 3 lines
It will work the same as
VIRTIO_MBUF_ADDRmacro.Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Virtio driver can check whether virtqueue is using vectorized path
when
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
initialization, will use padded structure if it is.
Quoted 1 line
I have added some tested code and now performance came back.
Since
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
code has changed in initialization process, it need some time for
regression
Quoted 4 lines
Quoted 4 lines
check.
Ok, works for me.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
I am investigating a linkage issue with your series, which does not happen systematically (see below, it happens also with clang). David pointed me to some Intel patches removing the usage if
__rte_weak, could it be related?I checked David's patch, it only changed i40e driver. Meanwhile
attribute
Quoted 7 lines
Quoted 6 lines
__rte_weakshould still be invirtio_rxtx.c.Quoted 1 line
I will follow David's patch, eliminate the usage of weak attribute.
Yeah, I meant below issue could be linked to
__rte_weak, not that i40e patch was the cause of this problem.
Quoted 7 lines
Quoted 2 lines
Maxime,
I haven't seen any build issue related to__rte_weakboth with gcc andclang.
Note that this build (which does not fail systematically) is when using binutils 2.30, which cause AVX512 support to be disabled.
Just change to binutils 2.30, AVX512 code will be skipped as expected in meson build. Could you please supply more information, I will try to reproduce it.
Quoted 3 lines
Quoted 3 lines
Thanks,
Marvin
Re: [dpdk-dev] [PATCH v10 6/9] net/virtio: add vectorized packed ring Rx path
In reply to Liu, YongQuoted 664 lines
-----Original Message-----
From: Liu, Yong
Sent: Tuesday, April 28, 2020 9:01 PM
To: 'Maxime Coquelin' <[email protected]>; Ye, Xiaolong <[email protected]>; Wang, Zhihong <[email protected]>
Cc: [email protected]
Subject: RE: [PATCH v10 6/9] net/virtio: add vectorized packed ring Rx pathQuoted 7 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Tuesday, April 28, 2020 4:44 PM
To: Liu, Yong <[email protected]>; Ye, Xiaolong <[email protected]>; Wang, Zhihong <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v10 6/9] net/virtio: add vectorized packed ring Rxpath
Quoted 37 lines · Yong
Quoted 6 lines
Quoted 6 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Monday, April 27, 2020 7:21 PM
To: Liu, Yong <[email protected]>; Ye, XiaolongQuoted 3 lines
Quoted 3 lines
Wang, Zhihong <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v10 6/9] net/virtio: add vectorized packed ring Rxpath
Quoted 12 lines
Quoted 12 lines · Marvin Liu
Quoted 8 lines
Optimize packed ring Rx path with SIMD instructions. Solution of optimization is pretty like vhost, is that split path into batch and single functions. Batch function is further optimized by AVX512 instructions. Also pad desc extra structure to 16 bytes aligned, thus four elements will be saved in one batch.
Signed-off-by Marvin Liu <[email protected]>Quoted 7 lines
Quoted 7 lines
drivers/net/virtio/Makefile else ifneq ($(filter y,$(CONFIG_RTE_ARCH_ARM)
Quoted 5 lines
drivers/net/virtio/Makefile +0
-0@@ -36,6 +36,41 @@ else ifneq ($(filter y,$(CONFIG_RTE_ARCH_ARM)$(CONFIG_RTE_ARCH_ARM64)),)
Quoted 1 line
drivers/net/virtio/Makefile +0
-0SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) +=
virtio_rxtx_simple_neon.cQuoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/virtio/Makefile +0
-0endifQuoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/net/virtio/Makefile else ifneq ($(filter y,$(CONFIG_RTE_ARCH_ARM) $(CONFIG_RTE_ARCH_ARM64)),)
Quoted 10 lines
drivers/net/virtio/Makefile +10
-0+ifneq ($(FORCE_DISABLE_AVX512), y) + CC_AVX512_SUPPORT=\ + $(shell $(CC) -march=native -dM -E - </dev/null 2>&1 | \ + sed '/./{H;$$!d} ; x ; /AVX512F/!d; /AVX512BW/!d; /AVX512VL/!d' | \ + grep -q AVX512 && echo 1) +endif + +ifeq ($(CC_AVX512_SUPPORT), 1) +CFLAGS += -DCC_AVX512_SUPPORT +SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) +=
virtio_rxtx_packed_avx.cQuoted 23 lines
Quoted 9 lines
Quoted 9 lines
drivers/net/virtio/Makefile else ifneq ($(filter y,$(CONFIG_RTE_ARCH_ARM) $(CONFIG_RTE_ARCH_ARM64)),)
Quoted 9 lines
drivers/net/virtio/Makefile +9
-0+ +ifeq ($(RTE_TOOLCHAIN), gcc) +ifeq ($(shell test $(GCC_VERSION) -ge 83 && echo 1), 1) +CFLAGS += -DVIRTIO_GCC_UNROLL_PRAGMA +endif +endif + +ifeq ($(RTE_TOOLCHAIN), clang) +ifeq ($(shell test$(CLANG_MAJOR_VERSION)$(CLANG_MINOR_VERSION) -
Quoted 12 lines
Quoted 12 lines
ge 37 && echo 1), 1)
drivers/net/virtio/Makefile else ifneq ($(filter y,$(CONFIG_RTE_ARCH_ARM) $(CONFIG_RTE_ARCH_ARM64)),)
Quoted 11 lines
drivers/net/virtio/Makefile +11
-0+CFLAGS += -DVIRTIO_CLANG_UNROLL_PRAGMA +endif +endif + +ifeq ($(RTE_TOOLCHAIN), icc) +ifeq ($(shell test $(ICC_MAJOR_VERSION) -ge 16 && echo 1), 1) +CFLAGS += -DVIRTIO_ICC_UNROLL_PRAGMA +endif +endif + +CFLAGS_virtio_rxtx_packed_avx.o += -mavx512f -mavx512bw -mavx512vl
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/net/virtio/Makefile else ifneq ($(filter y,$(CONFIG_RTE_ARCH_ARM) $(CONFIG_RTE_ARCH_ARM64)),)
Quoted 7 lines
drivers/net/virtio/Makefile +5
-0+ifeq ($(shell test $(GCC_VERSION) -ge 100 && echo 1), 1) +CFLAGS_virtio_rxtx_packed_avx.o += -Wno-zero-length-bounds +endif +endif + ifeq ($(CONFIG_RTE_VIRTIO_USER),y) SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) +=
virtio_user/vhost_user.cQuoted 35 lines
Quoted 1 line
Quoted 1 line
drivers/net/virtio/Makefile else ifneq ($(filter y,$(CONFIG_RTE_ARCH_ARM) · line 76
Quoted 1 line
drivers/net/virtio/Makefile +0
-0SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) +=
virtio_user/vhost_kernel.cQuoted 1 line
Quoted 1 line
Review
Quoted 1 line
(quoted diff) +0
-0b/drivers/net/virtio/meson.build
Quoted 31 lines
Quoted 31 lines
drivers/net/virtio/meson.build sources += files('virtio_ethdev.c', · line 13
Quoted 9 lines
index
15150eea1..8e68c3039100644drivers/net/virtio/meson.build +2
-0@@ -9,6 +9,20 @@ sources += files('virtio_ethdev.c', deps += ['kvargs', 'bus_pci'] if arch_subdir == 'x86' + if '-mno-avx512f' not in machine_args + if cc.has_argument('-mavx512f') and cc.has_argument('-mavx512vl') and
cc.has_argument('-mavx512bw')drivers/net/virtio/meson.build sources += files('virtio_ethdev.c',
Quoted 3 lines
drivers/net/virtio/meson.build +3
-0+ cflags += ['-mavx512f', '-mavx512bw', '-mavx512vl'] + cflags += ['-DCC_AVX512_SUPPORT'] + if (toolchain == 'gcc' andcc.version().version_compare('>=8.3.0'))
drivers/net/virtio/meson.build sources += files('virtio_ethdev.c', · line 18
Quoted 2 lines
drivers/net/virtio/meson.build +2
-0+ cflags += '-DVHOST_GCC_UNROLL_PRAGMA' + elif (toolchain == 'clang' andcc.version().version_compare('>=3.7.0'))
drivers/net/virtio/meson.build sources += files('virtio_ethdev.c', · line 19
Quoted 1 line
drivers/net/virtio/meson.build +1
-0+ cflags += '-
DVHOST_CLANG_UNROLL_PRAGMA'drivers/net/virtio/meson.build sources += files('virtio_ethdev.c', · line 20
Quoted 1 line
drivers/net/virtio/meson.build +1
-0+ elif (toolchain == 'icc' andcc.version().version_compare('>=16.0.0'))
Review
Quoted 9 lines
drivers/net/virtio/meson.build +5
-0+ cflags += '-DVHOST_ICC_UNROLL_PRAGMA' + endif + sources += files('virtio_rxtx_packed_avx.c') + endif + endif sources += files('virtio_rxtx_simple_sse.c') elif arch_subdir == 'ppc' sources += files('virtio_rxtx_simple_altivec.c')(quoted diff) +0
-0
b/drivers/net/virtio/virtio_ethdev.hQuoted 11 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/virtio/virtio_ethdev.h uint16_t virtio_xmit_pkts_inorder(void
Quoted 4 lines
index
febaf17a8..5c112cac7100644drivers/net/virtio/virtio_ethdev.h +0
-0@@ -105,6 +105,9 @@ uint16_t virtio_xmit_pkts_inorder(void
*tx_queue,Quoted 2 lines
Quoted 2 lines
struct
rte_mbuf**tx_pkts,Quoted 1 line
drivers/net/virtio/virtio_ethdev.h +0
-0uint16_t virtio_recv_pkts_vec(void *rx_queue, struct rte_mbuf**rx_pkts,
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/net/virtio/virtio_ethdev.h +1
-0uint16_t nb_pkts); +uint16_t virtio_recv_pkts_packed_vec(void *rx_queue, struct
rte_mbufQuoted 42 lines
Quoted 7 lines
Quoted 7 lines
**rx_pkts,
Review
Quoted 6 lines
drivers/net/virtio/virtio_ethdev.h +2
-0+ uint16_t nb_pkts); +int eth_virtio_dev_init (struct rte_eth_dev *eth_dev);void virtio_interrupt_handler (void *param);(quoted diff) +0
-0
b/drivers/net/virtio/virtio_rxtx.cQuoted 34 lines
Quoted 34 lines
Review
Quoted 16 lines
index
a549991aa..534562cca100644drivers/net/virtio/virtio_rxtx.c +8
-0@@ -2030,3 +2030,11 @@ virtio_xmit_pkts_inorder(void *tx_queue,return nb_tx; } + +__rte_weak uint16_t +virtio_recv_pkts_packed_vec(void *rx_queue __rte_unused, + struct rte_mbuf **rx_pkts __rte_unused, + uint16_t nb_pkts __rte_unused) +{ +return 0 ; +}(quoted diff) +0
-0
b/drivers/net/virtio/virtio_rxtx_packed_avx.cQuoted 17 lines
new file mode 100644
index 000000000..8a7b459ebdrivers/net/virtio/virtio_rxtx_packed_avx.c new file +12
-0@@ -0,0 +1,374 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2010-2020 Intel Corporation +*/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include <rte_net.h> +Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 8 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +8
-0+#include "virtio_logs.h" +#include "virtio_ethdev.h" +#include "virtio_pci.h" +#include "virtqueue.h" + +#define BYTE_SIZE 8 +/* flag bits offset in packed ring desc higher 64bits */ +#define FLAGS_BITS_OFFSET ((offsetof(struct vring_packed_desc,flags)
Quoted 5 lines
- \
Quoted 4 lines
Quoted 4 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 3 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +3
-0+ offsetof(struct vring_packed_desc, len)) * BYTE_SIZE) + +#define PACKED_FLAGS_MASK ((0ULL |
VRING_PACKED_DESC_F_AVAIL_USED) << \Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 8 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +8
-0+ FLAGS_BITS_OFFSET) + +#define PACKED_BATCH_SIZE (RTE_CACHE_LINE_SIZE / \ + sizeof(struct vring_packed_desc)) +#define PACKED_BATCH_MASK (PACKED_BATCH_SIZE - 1) + +#ifdef VIRTIO_GCC_UNROLL_PRAGMA +#define virtio_for_each_try_unroll (iter, val, size) _Pragma("GCCunroll
Quoted 7 lines
4")
Quoted 6 lines
Quoted 6 lines
\
drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 5 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +5
-0+ for (iter = val; iter < size; iter++) +#endif + +#ifdef VIRTIO_CLANG_UNROLL_PRAGMA +#define virtio_for_each_try_unroll (iter, val, size) _Pragma("unroll 4")\
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 5 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +5
-0+ for (iter = val; iter < size; iter++) +#endif + +#ifdef VIRTIO_ICC_UNROLL_PRAGMA +#define virtio_for_each_try_unroll (iter, val, size) _Pragma("unroll(4)")
Quoted 355 lines
\
Quoted 348 lines
Quoted 254 lines
Quoted 39 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +39
-0+ for (iter = val; iter < size; iter++) +#endif + +#ifndef virtio_for_each_try_unroll +#define virtio_for_each_try_unroll (iter, val, num) \ + for (iter = val; iter < num; iter++) +#endif + +static inline void +virtio_update_batch_stats (struct virtnet_stats *stats, +uint16_t pkt_len1, +uint16_t pkt_len2, +uint16_t pkt_len3, +uint16_t pkt_len4) +{ + stats->bytes += pkt_len1; + stats->bytes += pkt_len2; + stats->bytes += pkt_len3; + stats->bytes += pkt_len4; +} + +/* Optionally fill offload information in structure */ +static inline int +virtio_vec_rx_offload (struct rte_mbuf *m,struct virtio_net_hdr *hdr) +{ +struct rte_net_hdr_lens hdr_lens; +uint32_t hdrlen, ptype; +int l4_supported =0 ; + +/* nothing to do */ +if (hdr->flags ==0 ) +return 0 ; + +/* GSO not support in vec path, skip check */ + m->ol_flags |=PKT_RX_IP_CKSUM_UNKNOWN ; + + ptype =rte_net_get_ptype (m, &hdr_lens,RTE_PTYPE_ALL_MASK ); + m->packet_type = ptype; + if ((ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_TCP ||drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +10
-0+ (ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_UDP || + (ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_SCTP) + l4_supported =1 ; + +if (hdr->flags &VIRTIO_NET_HDR_F_NEEDS_CSUM ) { + hdrlen = hdr_lens.l2_len + hdr_lens.l3_len + hdr_lens.l4_len; +if (hdr->csum_start <= hdrlen && l4_supported) { + m->ol_flags |=PKT_RX_L4_CKSUM_NONE ; + }else { +/* Unknown proto or tunnel, do sw cksum. We can assume
Quoted 8 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +8
-0+* the cksum field is in the first segment since the +* buffers we provided to the host are large enough. +* In case of SCTP, this will be wrong since it's a CRC +* but there's nothing we can do. +*/ +uint16_t csum =0 , off; + + rte_raw_cksum_mbuf(m, hdr->csum_start,drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +10
-0+rte_pktmbuf_pkt_len (m) - hdr->csum_start, + &csum); +if (likely (csum !=0xffff )) + csum = ~csum; + off = hdr->csum_offset + hdr->csum_start; +if (rte_pktmbuf_data_len (m) >= off +1 ) + *rte_pktmbuf_mtod_offset(m, uint16_t *, + off) = csum; + } + } else if (hdr->flags & VIRTIO_NET_HDR_F_DATA_VALID &&
l4_supported) {Quoted 17 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +17
-0+ m->ol_flags |=PKT_RX_L4_CKSUM_GOOD ; + } + +return 0 ; +} + +static inline uint16_t +virtqueue_dequeue_batch_packed_vec (struct virtnet_rx *rxvq, +struct rte_mbuf **rx_pkts) +{ +struct virtqueue *vq = rxvq->vq; +struct virtio_hw *hw = vq->hw; +uint16_t hdr_size = hw->vtnet_hdr_size; +uint64_t addrs[PACKED_BATCH_SIZE ]; +uint16_t id = vq->vq_used_cons_idx; +uint8_t desc_stats; +uint16_t i;drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +10
-0+void *desc_addr; + +if (id &PACKED_BATCH_MASK ) +return -1 ; + +if (unlikely ((id +PACKED_BATCH_SIZE ) > vq->vq_nentries)) +return -1 ; + +/* only care avail/used bits */ + __m512i v_mask = _mm512_maskz_set1_epi64(0xaa,
PACKED_FLAGS_MASK);drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 8 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +8
-0+ desc_addr = &vq->vq_packed.ring.desc[id]; + +__m512i v_desc =_mm512_loadu_si512 (desc_addr); +__m512i v_flag =_mm512_and_epi64 (v_desc, v_mask); + +__m512i v_used_flag =_mm512_setzero_si512 (); +if (vq->vq_packed.used_wrap_counter) + v_used_flag = _mm512_maskz_set1_epi64(0xaa,
PACKED_FLAGS_MASK);Quoted 9 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +9
-0+ +/* Check all descs are used */ + desc_stats =_mm512_cmpneq_epu64_mask (v_flag, v_used_flag); +if (desc_stats) +return -1 ; + +virtio_for_each_try_unroll (i,0 ,PACKED_BATCH_SIZE ) { + rx_pkts[i] = (struct rte_mbuf *)vq->vq_descx[id + i].cookie; +rte_packet_prefetch (rte_pktmbuf_mtod(rx_pkts [i],void *));drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +10
-0+ + addrs[i] = (uint64_t )rx_pkts[i]->rx_descriptor_fields1; + } + +/* +* load len from desc, store into mbuf pkt_len and data_len +* len limiated by l6bit buf_len, pkt_len[16:31] can be ignored +*/ +const __mmask16 mask =0x6 |0x6 <<4 |0x6 <<8 |0x6 <<12 ; + __m512i values = _mm512_maskz_shuffle_epi32(mask, v_desc,
0xAA);Quoted 55 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +55
-0+ +/* reduce hdr_len from pkt_len and data_len */ +__m512i mbuf_len_offset =_mm512_maskz_set1_epi32 (mask, + (uint32_t )-hdr_size); + +__m512i v_value =_mm512_add_epi32 (values, mbuf_len_offset); + +/* assert offset of data_len */ +RTE_BUILD_BUG_ON (offsetof(struct rte_mbuf , data_len) != + offsetof(struct rte_mbuf , rx_descriptor_fields1) +8 ); + +__m512i v_index =_mm512_set_epi64 (addrs[3 ] +8 , addrs[3 ], + addrs[2 ] +8 , addrs[2 ], + addrs[1 ] +8 , addrs[1 ], + addrs[0 ] +8 , addrs[0 ]); +/* batch store into mbufs */ +_mm512_i64scatter_epi64 (0 , v_index, v_value,1 ); + +if (hw->has_rx_offload) { +virtio_for_each_try_unroll (i,0 ,PACKED_BATCH_SIZE ) { +char *addr = (char *)rx_pkts[i]->buf_addr + +RTE_PKTMBUF_HEADROOM - hdr_size; +virtio_vec_rx_offload (rx_pkts[i], + (struct virtio_net_hdr *)addr); + } + } + +virtio_update_batch_stats (&rxvq->stats, rx_pkts[0 ]->pkt_len, + rx_pkts[1 ]->pkt_len, rx_pkts[2 ]->pkt_len, + rx_pkts[3 ]->pkt_len); + + vq->vq_free_cnt +=PACKED_BATCH_SIZE ; + + vq->vq_used_cons_idx +=PACKED_BATCH_SIZE ; +if (vq->vq_used_cons_idx >= vq->vq_nentries) { + vq->vq_used_cons_idx -= vq->vq_nentries; + vq->vq_packed.used_wrap_counter ^=1 ; + } + +return 0 ; +} + +static uint16_t +virtqueue_dequeue_single_packed_vec (struct virtnet_rx *rxvq, +struct rte_mbuf **rx_pkts) +{ +uint16_t used_idx, id; +uint32_t len; +struct virtqueue *vq = rxvq->vq; +struct virtio_hw *hw = vq->hw; +uint32_t hdr_size = hw->vtnet_hdr_size; +struct virtio_net_hdr *hdr; +struct vring_packed_desc *desc; +struct rte_mbuf *cookie; +drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +10
-0+ desc = vq->vq_packed.ring.desc; + used_idx = vq->vq_used_cons_idx; +if (!desc_is_used (&desc[used_idx], vq)) +return -1 ; + + len = desc[used_idx].len; + id = desc[used_idx].id; + cookie = (struct rte_mbuf *)vq->vq_descx[id].cookie; +if (unlikely (cookie ==NULL )) { + PMD_DRV_LOG(ERR, "vring descriptor with no mbuf cookieat %u",
drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 13 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +13
-0+ vq->vq_used_cons_idx); +return -1 ; + } +rte_prefetch0 (cookie); +rte_packet_prefetch (rte_pktmbuf_mtod(cookie ,void *)); + + cookie->data_off =RTE_PKTMBUF_HEADROOM ; + cookie->ol_flags =0 ; + cookie->pkt_len = (uint32_t )(len - hdr_size); + cookie->data_len = (uint32_t )(len - hdr_size); + + hdr = (struct virtio_net_hdr *)((char *)cookie->buf_addr + + RTE_PKTMBUF_HEADROOM -
hdr_size);Quoted 37 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +37
-0+if (hw->has_rx_offload) +virtio_vec_rx_offload (cookie, hdr); + + *rx_pkts = cookie; + + rxvq->stats.bytes += cookie->pkt_len; + + vq->vq_free_cnt++; + vq->vq_used_cons_idx++; +if (vq->vq_used_cons_idx >= vq->vq_nentries) { + vq->vq_used_cons_idx -= vq->vq_nentries; + vq->vq_packed.used_wrap_counter ^=1 ; + } + +return 0 ; +} + +static inline void +virtio_recv_refill_packed_vec (struct virtnet_rx *rxvq, +struct rte_mbuf **cookie, +uint16_t num) +{ +struct virtqueue *vq = rxvq->vq; +struct vring_packed_desc *start_dp = vq->vq_packed.ring.desc; +uint16_t flags = vq->vq_packed.cached_flags; +struct virtio_hw *hw = vq->hw; +struct vq_desc_extra *dxp; +uint16_t idx, i; +uint16_t batch_num, total_num =0 ; +uint16_t head_idx = vq->vq_avail_idx; +uint16_t head_flag = vq->vq_packed.cached_flags; +uint64_t addr; + + do { + idx = vq->vq_avail_idx; + + batch_num = PACKED_BATCH_SIZE;drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +10
-0+if (unlikely ((idx +PACKED_BATCH_SIZE ) > vq->vq_nentries)) + batch_num = vq->vq_nentries - idx; +if (unlikely ((total_num + batch_num) > num)) + batch_num = num - total_num; + +virtio_for_each_try_unroll (i,0 , batch_num) { + dxp = &vq->vq_descx[idx + i]; + dxp->cookie = (void *)cookie[total_num + i]; + + addr = VIRTIO_MBUF_ADDR(cookie[total_num + i],vq) +
Quoted 4 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 4 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +1
-0+ RTE_PKTMBUF_HEADROOM - hw-
vtnet_hdr_size;drivers/net/virtio/virtio_rxtx_packed_avx.c new file +2
-0+ start_dp[idx + i].addr = addr; + start_dp[idx + i].len = cookie[total_num + i]-
buf_lenQuoted 89 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 4 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +1
-0+ - RTE_PKTMBUF_HEADROOM + hw-
vtnet_hdr_size;drivers/net/virtio/virtio_rxtx_packed_avx.c new file +2
-0+ if (total_num || i) { + virtqueue_store_flags_packed(&start_dp[idx+ i],
Quoted 27 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +27
-0+ flags, hw->weak_barriers); + } + } + + vq->vq_avail_idx += batch_num; +if (vq->vq_avail_idx >= vq->vq_nentries) { + vq->vq_avail_idx -= vq->vq_nentries; + vq->vq_packed.cached_flags ^= +VRING_PACKED_DESC_F_AVAIL_USED ; + flags = vq->vq_packed.cached_flags; + } + total_num += batch_num; + }while (total_num < num); + +virtqueue_store_flags_packed (&start_dp[head_idx], head_flag, + hw->weak_barriers); + vq->vq_free_cnt = (uint16_t )(vq->vq_free_cnt - num); +} + +uint16_t +virtio_recv_pkts_packed_vec (void *rx_queue, +struct rte_mbuf **rx_pkts, +uint16_t nb_pkts) +{ +struct virtnet_rx *rxvq = rx_queue; +struct virtqueue *vq = rxvq->vq; +struct virtio_hw *hw = vq->hw;drivers/net/virtio/virtio_rxtx_packed_avx.c
Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +10
-0+uint16_t num, nb_rx =0 ; +uint32_t nb_enqueued =0 ; +uint16_t free_cnt = vq->vq_free_thresh; + +if (unlikely (hw->started ==0 )) +return nb_rx; + + num =RTE_MIN (VIRTIO_MBUF_BURST_SZ , nb_pkts); +if (likely (num >PACKED_BATCH_SIZE )) + num = num - ((vq->vq_used_cons_idx + num) %
PACKED_BATCH_SIZE);Review
Quoted 45 lines
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +44
-0+ +while (num) { +if (!virtqueue_dequeue_batch_packed_vec (rxvq, + &rx_pkts[nb_rx])) { + nb_rx +=PACKED_BATCH_SIZE ; + num -=PACKED_BATCH_SIZE ; +continue ; + } +if (!virtqueue_dequeue_single_packed_vec (rxvq, + &rx_pkts[nb_rx])) { + nb_rx++; + num--; +continue ; + } +break ; + }; + +PMD_RX_LOG (DEBUG ,"dequeue:%d" , num); + + rxvq->stats.packets += nb_rx; + +if (likely (vq->vq_free_cnt >= free_cnt)) { +struct rte_mbuf *new_pkts[free_cnt]; +if (likely (rte_pktmbuf_alloc_bulk (rxvq->mpool, new_pkts, + free_cnt) ==0 )) { +virtio_recv_refill_packed_vec (rxvq, new_pkts, + free_cnt); + nb_enqueued += free_cnt; + }else { +struct rte_eth_dev *dev = + &rte_eth_devices[rxvq->port_id]; + dev->data->rx_mbuf_alloc_failed += free_cnt; + } + } + +if (likely (nb_enqueued)) { +if (unlikely (virtqueue_kick_prepare_packed (vq))) { +virtqueue_notify (vq); +PMD_RX_LOG (DEBUG ,"Notified" ); + } + } + +return nb_rx; +}(quoted diff) +0
-0
b/drivers/net/virtio/virtio_user_ethdev.cQuoted 4 lines
Quoted 4 lines
drivers/net/virtio/virtio_user_ethdev.c virtio_user_eth_dev_alloc(struct
Quoted 4 lines
index
40ad786cc..c54698ad1100644drivers/net/virtio/virtio_user_ethdev.c +0
-0@@ -528,6 +528,7 @@ virtio_user_eth_dev_alloc(struct
rte_vdev_deviceQuoted 1 line
Quoted 1 line
*vdev)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/net/virtio/virtio_user_ethdev.c virtio_user_pmd_probe(struct
Quoted 8 lines
drivers/net/virtio/virtio_user_ethdev.c +1
-0hw->use_msix =1 ; hw->modern =0 ; hw->use_vec_rx =0 ; + hw->use_vec_tx =0 ; hw->use_inorder_rx =0 ; hw->use_inorder_tx =0 ; hw->virtio_user_dev = dev;@@ -739,8 +740,19 @@ virtio_user_pmd_probe(struct
rte_vdev_deviceQuoted 22 lines
Quoted 4 lines
Quoted 4 lines
*dev)
Quoted 3 lines
drivers/net/virtio/virtio_user_ethdev.c +0
-0goto end; }Quoted 10 lines
Quoted 10 lines
drivers/net/virtio/virtio_user_ethdev.c virtio_user_pmd_probe(struct rte_vdev_device *dev)
Quoted 10 lines
drivers/net/virtio/virtio_user_ethdev.c +8
-2-if (vectorized) - hw->use_vec_rx =1 ; +if (vectorized) { +if (packed_vq) { +#if defined(CC_AVX512_SUPPORT ) + hw->use_vec_rx =1 ; + hw->use_vec_tx =1 ; +#else + PMD_INIT_LOG(INFO, + "building environment do not supportpacked
Quoted 7 lines
Quoted 7 lines
ring vectorized");
Quoted 6 lines
drivers/net/virtio/virtio_user_ethdev.c +5
-0+#endif + }else { + hw->use_vec_rx =1 ; + } + }Quoted 23 lines
Quoted 3 lines
Quoted 3 lines
Review
Quoted 3 lines
drivers/net/virtio/virtio_user_ethdev.c +0
-0rte_eth_dev_probing_finish (eth_dev); ret =0 ;(quoted diff) +0
-0
b/drivers/net/virtio/virtqueue.hQuoted 19 lines
Quoted 19 lines
drivers/net/virtio/virtqueue.h struct vq_desc_extra { · line 243
Quoted 10 lines
index
ca1c10499..ce0340743100644drivers/net/virtio/virtqueue.h +2
-1@@ -239,7 +239,8 @@ struct vq_desc_extra {void *cookie;uint16_t ndescs;uint16_t next; -}; +uint8_t padding[4 ]; +} __rte_packed __rte_aligned(16);Can't this introduce a performance impact for the non-vectorized case? I think of worse cache liens utilization.
For example with a burst of 32 descriptors with 32B cachelines, before it would take 14 cachelines, after 16. So for each burst, one could face 2 extra cache misses.
If you could run non-vectorized benchamrks with and without that
patch,
Quoted 11 lines
Quoted 6 lines
Quoted 2 lines
I would be grateful.
Maxime,
Thanks for point it out, it will add extra cache miss in datapath. And its impact on performance is around 1% in loopback case.Ok, thanks for doing the test. I'll try to run some PVP benchmarks on my side because when doing IO loopback, the cache pressure is much less important.
Quoted 7 lines
Quoted 1 line
While benefit of vectorized path will be more than that number.
Ok, but I disagree for two reasons:
1. You have to keep in mind than non-vectorized is the default and
encouraged mode to use. Indeed, it takes a lot of shortcuts like not checking header length (so no error stats), etc...Ok, I will keep non-vectorized same as before.
Quoted 8 lines
2. It's like saying it's OK it degrades by 5% on $CPU_VENDOR_A because
the gain is 20% on $CPU_VENDOR_B.In the case we see more degradation in real-world scenario, you might want to consider using ifdefs to avoid adding padding in the non- vectorized case, like you did to differentiate Virtio PMD to Virtio-user PMD in patch 7.
Quoted 11 lines
Maxime,
The performance difference is so slight, so I ignored for it look like a sampling error.
It maybe not suitable to add new configuration for such setting which only used inside driver.
Virtio driver can check whether virtqueue is using vectorized path when initialization, will use padded structure if it is.
I have added some tested code and now performance came back. Since code has changed in initialization process, it need some time for regression check.
+ one more update.
Batch store with padding structure won't have benefit based on the latest code. It may due to addition load/store cost can't be hidden by saved cpu cycles. Will moved padding structure and make things clear as before.
Quoted 14 lines
Regards,
MarvinQuoted 11 lines
Thanks,
MaximeQuoted 8 lines
Thanks,
MarvinQuoted 4 lines
Reviewed-by Maxime Coquelin <[email protected]>Thanks,
Maxime
PATCH v10 7/9 net/virtio: add vectorized packed ring Tx path
In reply to Marvin LiuOptimize packed ring Tx path like Rx path. Split Tx path into batch and single Tx functions. Batch function is further optimized by AVX512 instructions.
drivers/net/virtio/virtio_ethdev.h +3 -0
@@ -108,6 +108,9 @@ uint16_t virtio_recv_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,uint16_t virtio_recv_pkts_packed_vec (void *rx_queue,struct rte_mbuf **rx_pkts,uint16_t nb_pkts); +uint16_t virtio_xmit_pkts_packed_vec (void *tx_queue,struct rte_mbuf **tx_pkts, +uint16_t nb_pkts); +int eth_virtio_dev_init (struct rte_eth_dev *eth_dev);void virtio_interrupt_handler (void *param);
drivers/net/virtio/virtio_rxtx.c +8 -0
@@ -2038,3 +2038,11 @@ virtio_recv_pkts_packed_vec(void *rx_queue __rte_unused, {return 0 ; } + +__rte_weak uint16_t +virtio_xmit_pkts_packed_vec(void *tx_queue __rte_unused, + struct rte_mbuf **tx_pkts __rte_unused, + uint16_t nb_pkts __rte_unused) +{ +return 0 ; +}
drivers/net/virtio/virtio_rxtx_packed_avx.c +249 -0
261 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [dpdk-dev] [PATCH v10 7/9] net/virtio: add vectorized packed ring Tx path
Quoted 6 lines · Marvin Liu
Optimize packed ring Tx path like Rx path. Split Tx path into batch and single Tx functions. Batch function is further optimized by AVX512 instructions.
Signed-off-by Marvin Liu <[email protected]>
Thanks,
Maxime
PATCH v10 8/9 net/virtio: add election for vectorized path
In reply to Marvin LiuRewrite vectorized path selection logic. Default setting comes from vectorized devarg, then checks each criteria.
Packed ring vectorized path need:
AVX512F and required extensions are supported by compiler and host VERSION_1 and IN_ORDER features are negotiated mergeable feature is not negotiated
LRO offloading is disabled
Split ring vectorized rx path need:
mergeable and IN_ORDER features are not negotiated LRO, chksum and vlan strip offloadings are disabled
drivers/net/virtio/virtio_ethdev.c +74 -26
@@ -1523,9 +1523,12 @@ set_rxtx_funcs(struct rte_eth_dev *eth_dev)if (vtpci_packed_queue (hw)) {PMD_INIT_LOG (INFO ,"virtio: using packed ring %s Tx path on port %u" , - hw->use_inorder_tx ?"inorder" :"standard" , + hw->use_vec_tx ?"vectorized" :"standard" , eth_dev->data->port_id); - eth_dev->tx_pkt_burst = virtio_xmit_pkts_packed; +if (hw->use_vec_tx) + eth_dev->tx_pkt_burst = virtio_xmit_pkts_packed_vec; +else + eth_dev->tx_pkt_burst = virtio_xmit_pkts_packed; }else {if (hw->use_inorder_tx) { PMD_INIT_LOG(INFO, "virtio: using inorder Tx path on port %u",
@@ -1539,7 +1542,13 @@ set_rxtx_funcs(struct rte_eth_dev *eth_dev) }if (vtpci_packed_queue (hw)) { -if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) { +if (hw->use_vec_rx) { +PMD_INIT_LOG (INFO , +"virtio: using packed ring vectorized Rx path on port %u" , + eth_dev->data->port_id); + eth_dev->rx_pkt_burst = + &virtio_recv_pkts_packed_vec; + }else if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) {PMD_INIT_LOG (INFO ,"virtio: using packed ring mergeable buffer Rx path on port %u" , eth_dev->data->port_id);
@@ -1952,8 +1961,17 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev) goto err_virtio_init;if (vectorized) { -if (!vtpci_packed_queue (hw)) +if (!vtpci_packed_queue (hw)) { + hw->use_vec_rx =1 ; + }else { +#if !defined(CC_AVX512_SUPPORT ) +PMD_DRV_LOG (INFO , +"building environment do not support packed ring vectorized" ); +#else hw->use_vec_rx =1 ; + hw->use_vec_tx =1 ; +#endif + } } hw->opened = true;
@@ -2102,8 +2120,8 @@ virtio_dev_devargs_parse(struct rte_devargs *devargs, int *vdpa,if (vectorized &&rte_kvargs_count (kvlist,VIRTIO_ARG_VECTORIZED ) ==1 ) { ret =rte_kvargs_process (kvlist, -VIRTIO_ARG_VECTORIZED , - vectorized_check_handler, vectorized); +VIRTIO_ARG_VECTORIZED , + vectorized_check_handler, vectorized);if (ret <0 ) {PMD_INIT_LOG (ERR ,"Failed to parse %s" ,VIRTIO_ARG_VECTORIZED );
@@ -2288,31 +2306,61 @@ virtio_dev_configure(struct rte_eth_dev *dev)return -EBUSY ; } -if (vtpci_with_feature (hw,VIRTIO_F_IN_ORDER )) { - hw->use_inorder_tx =1 ; - hw->use_inorder_rx =1 ; - hw->use_vec_rx =0 ; - } -if (vtpci_packed_queue (hw)) { - hw->use_vec_rx =0 ; - hw->use_inorder_rx =0 ; - } +if ((hw->use_vec_rx || hw->use_vec_tx) && + (!rte_cpu_get_flag_enabled (RTE_CPUFLAG_AVX512F ) || + !vtpci_with_feature (hw,VIRTIO_F_IN_ORDER ) || + !vtpci_with_feature (hw,VIRTIO_F_VERSION_1 ))) { +PMD_DRV_LOG (INFO , +"disabled packed ring vectorized path for requirements not met" ); + hw->use_vec_rx =0 ; + hw->use_vec_tx =0 ; + } +if (hw->use_vec_rx) { +if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) { +PMD_DRV_LOG (INFO , +"disabled packed ring vectorized rx for mrg_rxbuf enabled" ); + hw->use_vec_rx =0 ; + } + +if (rx_offloads &DEV_RX_OFFLOAD_TCP_LRO ) { +PMD_DRV_LOG (INFO , +"disabled packed ring vectorized rx for TCP_LRO enabled" ); + hw->use_vec_rx =0 ; + } + } + }else { +if (vtpci_with_feature (hw,VIRTIO_F_IN_ORDER )) { + hw->use_inorder_tx =1 ; + hw->use_inorder_rx =1 ; + hw->use_vec_rx =0 ; + } + +if (hw->use_vec_rx) {#if definedRTE_ARCH_ARM64 || definedRTE_ARCH_ARM -if (!rte_cpu_get_flag_enabled (RTE_CPUFLAG_NEON )) { - hw->use_vec_rx =0 ; - } +if (!rte_cpu_get_flag_enabled (RTE_CPUFLAG_NEON )) { +PMD_DRV_LOG (INFO , +"disabled split ring vectorized path for requirement not met" ); + hw->use_vec_rx =0 ; + }#endif -if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) { - hw->use_vec_rx =0 ; - } +if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) { +PMD_DRV_LOG (INFO , +"disabled split ring vectorized rx for mrg_rxbuf enabled" ); + hw->use_vec_rx =0 ; + } -if (rx_offloads & (DEV_RX_OFFLOAD_UDP_CKSUM | -DEV_RX_OFFLOAD_TCP_CKSUM | -DEV_RX_OFFLOAD_TCP_LRO | -DEV_RX_OFFLOAD_VLAN_STRIP )) - hw->use_vec_rx =0 ; +if (rx_offloads & (DEV_RX_OFFLOAD_UDP_CKSUM | +DEV_RX_OFFLOAD_TCP_CKSUM | +DEV_RX_OFFLOAD_TCP_LRO | +DEV_RX_OFFLOAD_VLAN_STRIP )) { +PMD_DRV_LOG (INFO , +"disabled split ring vectorized rx for offloading enabled" ); + hw->use_vec_rx =0 ; + } + } + }return 0 ; }
Signature · 1 line
2.17.1
PATCH v10 9/9 doc: add packed vectorized path
In reply to Marvin LiuDocument packed virtqueue vectorized path selection logic in virtio net PMD.
doc/guides/nics/virtio.rst +25 -14
@@ -482,6 +482,13 @@ according to below configuration: both negotiated, this path will be selected. #. Packed virtqueue in-order non-mergeable path: If in-order feature is negotiated and Rx mergeable is not negotiated, this path will be selected. +#. Packed virtqueue vectorized Rx path: If building and running environment support + AVX512 && in-order feature is negotiated && Rx mergeable is not negotiated && + TCP_LRO Rx offloading is disabled && vectorized option enabled, + this path will be selected. +#. Packed virtqueue vectorized Tx path: If building and running environment support + AVX512 && in-order feature is negotiated && vectorized option enabled, + this path will be selected. Rx/Tx callbacks of each Virtio path ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -504,6 +511,8 @@ are shown in below table: Packed virtqueue non-meregable path virtio_recv_pkts_packed virtio_xmit_pkts_packed Packed virtqueue in-order mergeable path virtio_recv_mergeable_pkts_packed virtio_xmit_pkts_packed Packed virtqueue in-order non-mergeable path virtio_recv_pkts_packed virtio_xmit_pkts_packed + Packed virtqueue vectorized Rx path virtio_recv_pkts_packed_vec virtio_xmit_pkts_packed + Packed virtqueue vectorized Tx path virtio_recv_pkts_packed virtio_xmit_pkts_packed_vec ============================================ ================================= ======================== Virtio paths Support Status from Release to Release
@@ -521,20 +530,22 @@ All virtio paths support status are shown in below table: .. table:: Virtio Paths and Releases - ============================================ ============= ============= ============= - Virtio paths 16.11 ~ 18.05 18.08 ~ 18.11 19.02 ~ 19.11 - ============================================ ============= ============= ============= - Split virtqueue mergeable path Y Y Y - Split virtqueue non-mergeable path Y Y Y - Split virtqueue vectorized Rx path Y Y Y - Split virtqueue simple Tx path Y N N - Split virtqueue in-order mergeable path Y Y - Split virtqueue in-order non-mergeable path Y Y - Packed virtqueue mergeable path Y - Packed virtqueue non-mergeable path Y - Packed virtqueue in-order mergeable path Y - Packed virtqueue in-order non-mergeable path Y - ============================================ ============= ============= ============= + ============================================ ============= ============= ============= ======= + Virtio paths 16.11 ~ 18.05 18.08 ~ 18.11 19.02 ~ 19.11 20.05 ~ + ============================================ ============= ============= ============= ======= + Split virtqueue mergeable path Y Y Y Y + Split virtqueue non-mergeable path Y Y Y Y + Split virtqueue vectorized Rx path Y Y Y Y + Split virtqueue simple Tx path Y N N N + Split virtqueue in-order mergeable path Y Y Y + Split virtqueue in-order non-mergeable path Y Y Y + Packed virtqueue mergeable path Y Y + Packed virtqueue non-mergeable path Y Y + Packed virtqueue in-order mergeable path Y Y + Packed virtqueue in-order non-mergeable path Y Y + Packed virtqueue vectorized Rx path Y + Packed virtqueue vectorized Tx path Y + ============================================ ============= ============= ============= ======= QEMU Support Status ~~~~~~~~~~~~~~~~~~~
Signature · 1 line
2.17.1
v11 cover add packed ring vectorized path
In reply to Marvin LiuThis patch set introduced vectorized path for packed ring.
The size of packed ring descriptor is 16Bytes. Four batched descriptors are just placed into one cacheline. AVX512 instructions can well handle this kind of data. Packed ring TX path can fully transformed into vectorized path. Packed ring Rx path can be vectorized when requirements met(LRO and mergeable disabled).
New option RTE_LIBRTE_VIRTIO_INC_VECTOR will be introduced in this patch set. This option will unify split and packed ring vectorized path default setting. Meanwhile user can specify whether enable vectorized path at runtime by 'vectorized' parameter of virtio user vdev.
v11:
* fix i686 build warnings
* fix typo in doc
v10:
* reuse packed ring xmit cleanup
v9:
* replace RTE_LIBRTE_VIRTIO_INC_VECTOR with vectorized devarg
* reorder patch sequence
v8:
* fix meson build error on ubuntu16.04 and suse15
v7:
* default vectorization is disabled
* compilation time check dependency on rte_mbuf structure
* offsets are calcuated when compiling
* remove useless barrier as descs are batched store&load
* vindex of scatter is directly set
* some comments updates
* enable vectorized path in meson build
v6:
* fix issue when size not power of 2
v5:
* remove cpuflags definition as required extensions always come with AVX512F on x86_64
* inorder actions should depend on feature bit
* check ring type in rx queue setup
* rewrite some commit logs
* fix some checkpatch warnings
v4:
* rename 'packed_vec' to 'vectorized', also used in split ring
* add RTE_LIBRTE_VIRTIO_INC_VECTOR config for virtio ethdev
* check required AVX512 extensions cpuflags
* combine split and packed ring datapath selection logic
* remove limitation that size must power of two
* clear 12Bytes virtio_net_hdr
v3:
* remove virtio_net_hdr array for better performance
* disable 'packed_vec' by default
v2:
* more function blocks replaced by vector instructions
* clean virtio_net_hdr by vector instruction
* allow header room size change
* add 'packed_vec' option in virtio_user vdev
* fix build not check whether AVX512 enabled
* doc update
Marvin Liu (9):
net/virtio: add Rx free threshold setting net/virtio: inorder should depend on feature bit net/virtio: add vectorized devarg net/virtio-user: add vectorized devarg net/virtio: reuse packed ring functions net/virtio: add vectorized packed ring Rx path net/virtio: add vectorized packed ring Tx path net/virtio: add election for vectorized path
doc: add packed vectorized path
doc/guides/nics/virtio.rst | 52 +- drivers/net/virtio/Makefile | 35 ++ drivers/net/virtio/meson.build | 14 + drivers/net/virtio/virtio_ethdev.c | 137 ++++- drivers/net/virtio/virtio_ethdev.h | 6 + drivers/net/virtio/virtio_pci.h | 3 +- drivers/net/virtio/virtio_rxtx.c | 349 ++--------- drivers/net/virtio/virtio_rxtx_packed_avx.c | 623 ++++++++++++++++++++ drivers/net/virtio/virtio_user_ethdev.c | 32 +- drivers/net/virtio/virtqueue.c | 7 +- drivers/net/virtio/virtqueue.h | 307 +++++++++- 11 files changed, 1210 insertions(+), 355 deletions(-) create mode 100644 drivers/net/virtio/virtio_rxtx_packed_avx.c
Signature · 1 line
2.17.1
PATCH v11 1/9 net/virtio: add Rx free threshold setting
Introduce free threshold setting in Rx queue, its default value is 32. Limit the threshold size to multiple of four as only vectorized packed Rx function will utilize it. Virtio driver will rearm Rx queue when more than rx_free_thresh descs were dequeued.
drivers/net/virtio/virtio_rxtx.c +23 -0
@@ -936,6 +936,7 @@ virtio_dev_rx_queue_setup(struct rte_eth_dev *dev,struct virtio_hw *hw = dev->data->dev_private;struct virtqueue *vq = hw->vqs[vtpci_queue_idx];struct virtnet_rx *rxvq; +uint16_t rx_free_thresh;PMD_INIT_FUNC_TRACE ();
@@ -944,6 +945,28 @@ virtio_dev_rx_queue_setup(struct rte_eth_dev *dev,return -EINVAL ; } + rx_free_thresh = rx_conf->rx_free_thresh; +if (rx_free_thresh ==0 ) + rx_free_thresh = +RTE_MIN (vq->vq_nentries /4 ,DEFAULT_RX_FREE_THRESH ); + +if (rx_free_thresh &0x3 ) { +RTE_LOG (ERR ,PMD ,"rx_free_thresh must be multiples of four." +" (rx_free_thresh=%u port=%u queue=%u)\n" , + rx_free_thresh, dev->data->port_id, queue_idx); +return -EINVAL ; + } + +if (rx_free_thresh >= vq->vq_nentries) { +RTE_LOG (ERR ,PMD ,"rx_free_thresh must be less than the " +"number of RX entries (%u)." +" (rx_free_thresh=%u port=%u queue=%u)\n" , + vq->vq_nentries, + rx_free_thresh, dev->data->port_id, queue_idx); +return -EINVAL ; + } + vq->vq_free_thresh = rx_free_thresh; +if (nb_desc ==0 || nb_desc > vq->vq_nentries) nb_desc = vq->vq_nentries; vq->vq_free_cnt =RTE_MIN (vq->vq_free_cnt, nb_desc);
drivers/net/virtio/virtqueue.h +2 -0
@@ -18,6 +18,8 @@struct rte_mbuf ; +#define DEFAULT_RX_FREE_THRESH 32 +/* * Per virtio_ring.h in Linux. * For virtio_pci on SMP, we don't need to order with respect to MMIO
Signature · 1 line
2.17.1
PATCH v11 2/9 net/virtio: inorder should depend on feature bit
In reply to Marvin LiuRing initialization is different when inorder feature negotiated. This action should dependent on negotiated feature bits.
drivers/net/virtio/virtio_rxtx.c +4 -3
@@ -989,6 +989,7 @@ virtio_dev_rx_queue_setup_finish(struct rte_eth_dev *dev, uint16_t queue_idx)struct rte_mbuf *m;uint16_t desc_idx;int error, nbufs, i; +bool in_order =vtpci_with_feature (hw,VIRTIO_F_IN_ORDER );PMD_INIT_FUNC_TRACE ();
@@ -1018,7 +1019,7 @@ virtio_dev_rx_queue_setup_finish(struct rte_eth_dev *dev, uint16_t queue_idx)virtio_rxq_rearm_vec (rxvq); nbufs +=RTE_VIRTIO_VPMD_RX_REARM_THRESH ; } - }else if (hw->use_inorder_rx) { + }else if (!vtpci_packed_queue (vq->hw) && in_order) {if ((!virtqueue_full (vq))) {uint16_t free_cnt = vq->vq_free_cnt;struct rte_mbuf *pkts[free_cnt];
@@ -1133,7 +1134,7 @@ virtio_dev_tx_queue_setup_finish(struct rte_eth_dev *dev,PMD_INIT_FUNC_TRACE ();if (!vtpci_packed_queue (hw)) { -if (hw->use_inorder_tx) +if (vtpci_with_feature (hw,VIRTIO_F_IN_ORDER )) vq->vq_split.ring.desc[vq->vq_nentries -1 ].next =0 ; }
@@ -2046,7 +2047,7 @@ virtio_xmit_pkts_packed(void *tx_queue, struct rte_mbuf **tx_pkts,struct virtio_hw *hw = vq->hw;uint16_t hdr_size = hw->vtnet_hdr_size;uint16_t nb_tx =0 ; -bool in_order = hw->use_inorder_tx; +bool in_order =vtpci_with_feature (hw,VIRTIO_F_IN_ORDER );if (unlikely (hw->started ==0 && tx_pkts != hw->inject_pkts))return nb_tx;
Signature · 1 line
2.17.1
PATCH v11 3/9 net/virtio: add vectorized devarg
In reply to Marvin LiuPreviously, virtio split ring vectorized path was enabled by default. This is not suitable for everyone because that path dose not follow virtio spec. Add new devarg for virtio vectorized path selection. By default vectorized path is disabled.
doc/guides/nics/virtio.rst +7 -0
@@ -363,6 +363,13 @@ Below devargs are supported by the PCI virtio driver: rte_eth_link_get_nowait function. (Default: 10000 (10G)) +#. ``vectorized``: + + It is used to specify whether virtio device perfers to use vectorized path. + Afterwards, dependencies of vectorized path will be checked in path + election. + (Default: 0 (disabled)) + Below devargs are supported by the virtio-user vdev: #. ``path``:
drivers/net/virtio/virtio_ethdev.c +42 -13
138 lines not on this page · raw message
drivers/net/virtio/virtio_pci.h +2 -1
@@ -253,7 +253,8 @@ struct virtio_hw {uint8_t vlan_strip;uint8_t use_msix;uint8_t modern; -uint8_t use_simple_rx; +uint8_t use_vec_rx; +uint8_t use_vec_tx;uint8_t use_inorder_rx;uint8_t use_inorder_tx;uint8_t weak_barriers;
drivers/net/virtio/virtio_rxtx.c +2 -2
@@ -996,7 +996,7 @@ virtio_dev_rx_queue_setup_finish(struct rte_eth_dev *dev, uint16_t queue_idx)/* Allocate blank mbufs for the each rx descriptor */ nbufs =0 ; -if (hw->use_simple_rx) { +if (hw->use_vec_rx && !vtpci_packed_queue (hw)) {for (desc_idx =0 ; desc_idx < vq->vq_nentries; desc_idx++) { vq->vq_split.ring.avail->ring[desc_idx] = desc_idx;
@@ -1014,7 +1014,7 @@ virtio_dev_rx_queue_setup_finish(struct rte_eth_dev *dev, uint16_t queue_idx) &rxvq->fake_mbuf; } -if (hw->use_simple_rx) { +if (hw->use_vec_rx && !vtpci_packed_queue (hw)) {while (vq->vq_free_cnt >=RTE_VIRTIO_VPMD_RX_REARM_THRESH ) {virtio_rxq_rearm_vec (rxvq); nbufs +=RTE_VIRTIO_VPMD_RX_REARM_THRESH ;
drivers/net/virtio/virtio_user_ethdev.c +1 -1
@@ -525,7 +525,7 @@ virtio_user_eth_dev_alloc(struct rte_vdev_device *vdev)*/ hw->use_msix =1 ; hw->modern =0 ; - hw->use_simple_rx =0 ; + hw->use_vec_rx =0 ; hw->use_inorder_rx =0 ; hw->use_inorder_tx =0 ; hw->virtio_user_dev = dev;
drivers/net/virtio/virtqueue.c +4 -3
@@ -32,7 +32,8 @@ virtqueue_detach_unused(struct virtqueue *vq) end = (vq->vq_avail_idx + vq->vq_free_cnt) & (vq->vq_nentries -1 );for (idx =0 ; idx < vq->vq_nentries; idx++) { -if (hw->use_simple_rx && type ==VTNET_RQ ) { +if (hw->use_vec_rx && !vtpci_packed_queue (hw) && + type ==VTNET_RQ ) {if (start <= end && idx >= start && idx < end)continue ;if (start > end && (idx >= start || idx < end))
@@ -97,7 +98,7 @@ virtqueue_rxvq_flush_split(struct virtqueue *vq)for (i =0 ; i < nb_used; i++) { used_idx = vq->vq_used_cons_idx & (vq->vq_nentries -1 ); uep = &vq->vq_split.ring.used->ring[used_idx]; -if (hw->use_simple_rx) { +if (hw->use_vec_rx) { desc_idx = used_idx;rte_pktmbuf_free (vq->sw_ring[desc_idx]); vq->vq_free_cnt++;
@@ -121,7 +122,7 @@ virtqueue_rxvq_flush_split(struct virtqueue *vq) vq->vq_used_cons_idx++; } -if (hw->use_simple_rx) { +if (hw->use_vec_rx) {while (vq->vq_free_cnt >=RTE_VIRTIO_VPMD_RX_REARM_THRESH ) {virtio_rxq_rearm_vec (rxq);if (virtqueue_kick_prepare (vq))
Signature · 1 line
2.17.1
PATCH v11 4/9 net/virtio-user: add vectorized devarg
In reply to Marvin LiuAdd new devarg for virtio user device vectorized path selection. By default vectorized path is disabled.
doc/guides/nics/virtio.rst +6 -0
@@ -424,6 +424,12 @@ Below devargs are supported by the virtio-user vdev: rte_eth_link_get_nowait function. (Default: 10000 (10G)) +#. ``vectorized``: + + It is used to specify whether virtio device perfers to use vectorized path. + Afterwards, dependencies of vectorized path will be checked in path + election. + (Default: 0 (disabled)) Virtio paths Selection and Usage --------------------------------
drivers/net/virtio/virtio_user_ethdev.c +17 -1
@@ -452,6 +452,8 @@ static const char *valid_args[] = {VIRTIO_USER_ARG_PACKED_VQ , #define VIRTIO_USER_ARG_SPEED "speed"VIRTIO_USER_ARG_SPEED , +#define VIRTIO_USER_ARG_VECTORIZED "vectorized" +VIRTIO_USER_ARG_VECTORIZED , NULL };
@@ -559,6 +561,7 @@ virtio_user_pmd_probe(struct rte_vdev_device *dev)uint64_t mrg_rxbuf =1 ;uint64_t in_order =1 ;uint64_t packed_vq =0 ; +uint64_t vectorized =0 ;char *path =NULL ;char *ifname =NULL ;char *mac_addr =NULL ;
@@ -675,6 +678,15 @@ virtio_user_pmd_probe(struct rte_vdev_device *dev) } } +if (rte_kvargs_count (kvlist,VIRTIO_USER_ARG_VECTORIZED ) ==1 ) { +if (rte_kvargs_process (kvlist,VIRTIO_USER_ARG_VECTORIZED , + &get_integer_arg, &vectorized) <0 ) { +PMD_INIT_LOG (ERR ,"error to parse %s" , +VIRTIO_USER_ARG_VECTORIZED ); + goto end; + } + } +if (queues >1 && cq ==0 ) {PMD_INIT_LOG (ERR ,"multi-q requires ctrl-q" ); goto end;
@@ -727,6 +739,9 @@ virtio_user_pmd_probe(struct rte_vdev_device *dev) goto end; } +if (vectorized) + hw->use_vec_rx =1 ; +rte_eth_dev_probing_finish (eth_dev); ret =0 ;
@@ -785,4 +800,5 @@ RTE_PMD_REGISTER_PARAM_STRING(net_virtio_user,"mrg_rxbuf=<0|1> " "in_order=<0|1> " "packed_vq=<0|1> " - "speed=<int>"); +"speed=<int> " + "vectorized=<0|1>");
Signature · 1 line
2.17.1
PATCH v11 5/9 net/virtio: reuse packed ring functions
In reply to Marvin LiuMove offload, xmit cleanup and packed xmit enqueue function to header file. These functions will be reused by packed ring vectorized path.
drivers/net/virtio/virtio_rxtx.c +0 -299
@@ -89,23 +89,6 @@ vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx) dp->next =VQ_RING_DESC_CHAIN_END ; } -static void -vq_ring_free_id_packed (struct virtqueue *vq,uint16_t id) -{ -struct vq_desc_extra *dxp; - - dxp = &vq->vq_descx[id]; - vq->vq_free_cnt += dxp->ndescs; - -if (vq->vq_desc_tail_idx ==VQ_RING_DESC_CHAIN_END ) - vq->vq_desc_head_idx = id; -else - vq->vq_descx[vq->vq_desc_tail_idx].next = id; - - vq->vq_desc_tail_idx = id; - dxp->next =VQ_RING_DESC_CHAIN_END ; -} -void virtio_update_packet_stats (struct virtnet_stats *stats,struct rte_mbuf *mbuf) {
@@ -264,130 +247,6 @@ virtqueue_dequeue_rx_inorder(struct virtqueue *vq,return i; } -#ifndef DEFAULT_TX_FREE_THRESH -#define DEFAULT_TX_FREE_THRESH 32 -#endif - -static void -virtio_xmit_cleanup_inorder_packed (struct virtqueue *vq,int num) -{ -uint16_t used_idx, id, curr_id, free_cnt =0 ; -uint16_t size = vq->vq_nentries; -struct vring_packed_desc *desc = vq->vq_packed.ring.desc; -struct vq_desc_extra *dxp; - - used_idx = vq->vq_used_cons_idx; -/* desc_is_used has a load-acquire or rte_cio_rmb inside -* and wait for used desc in virtqueue. -*/ -while (num >0 &&desc_is_used (&desc[used_idx], vq)) { - id = desc[used_idx].id; -do { - curr_id = used_idx; - dxp = &vq->vq_descx[used_idx]; - used_idx += dxp->ndescs; - free_cnt += dxp->ndescs; - num -= dxp->ndescs; -if (used_idx >= size) { - used_idx -= size; - vq->vq_packed.used_wrap_counter ^=1 ; - } -if (dxp->cookie !=NULL ) { -rte_pktmbuf_free (dxp->cookie); - dxp->cookie =NULL ; - } - }while (curr_id != id); - } - vq->vq_used_cons_idx = used_idx; - vq->vq_free_cnt += free_cnt; -} - -static void -virtio_xmit_cleanup_normal_packed (struct virtqueue *vq,int num) -{ -uint16_t used_idx, id; -uint16_t size = vq->vq_nentries; -struct vring_packed_desc *desc = vq->vq_packed.ring.desc; -struct vq_desc_extra *dxp; - - used_idx = vq->vq_used_cons_idx; -/* desc_is_used has a load-acquire or rte_cio_rmb inside -* and wait for used desc in virtqueue. -*/ -while (num-- &&desc_is_used (&desc[used_idx], vq)) { - id = desc[used_idx].id; - dxp = &vq->vq_descx[id]; - vq->vq_used_cons_idx += dxp->ndescs; -if (vq->vq_used_cons_idx >= size) { - vq->vq_used_cons_idx -= size; - vq->vq_packed.used_wrap_counter ^=1 ; - } -vq_ring_free_id_packed (vq, id); -if (dxp->cookie !=NULL ) { -rte_pktmbuf_free (dxp->cookie); - dxp->cookie =NULL ; - } - used_idx = vq->vq_used_cons_idx; - } -} - -/* Cleanup from completed transmits. */ -static inline void -virtio_xmit_cleanup_packed (struct virtqueue *vq,int num,int in_order) -{ -if (in_order) -virtio_xmit_cleanup_inorder_packed (vq, num); -else -virtio_xmit_cleanup_normal_packed (vq, num); -} - -static void -virtio_xmit_cleanup (struct virtqueue *vq,uint16_t num) -{ -uint16_t i, used_idx, desc_idx; -for (i =0 ; i < num; i++) { -struct vring_used_elem *uep; -struct vq_desc_extra *dxp; - - used_idx = (uint16_t )(vq->vq_used_cons_idx & (vq->vq_nentries -1 )); - uep = &vq->vq_split.ring.used->ring[used_idx]; - - desc_idx = (uint16_t ) uep->id; - dxp = &vq->vq_descx[desc_idx]; - vq->vq_used_cons_idx++; -vq_ring_free_chain (vq, desc_idx); - -if (dxp->cookie !=NULL ) { -rte_pktmbuf_free (dxp->cookie); - dxp->cookie =NULL ; - } - } -} - -/* Cleanup from completed inorder transmits. */ -static __rte_always_inline void -virtio_xmit_cleanup_inorder (struct virtqueue *vq,uint16_t num) -{ -uint16_t i, idx = vq->vq_used_cons_idx; -int16_t free_cnt =0 ; -struct vq_desc_extra *dxp =NULL ; - -if (unlikely (num ==0 )) -return ; - -for (i =0 ; i < num; i++) { - dxp = &vq->vq_descx[idx++ & (vq->vq_nentries -1 )]; - free_cnt += dxp->ndescs; -if (dxp->cookie !=NULL ) { -rte_pktmbuf_free (dxp->cookie); - dxp->cookie =NULL ; - } - } - - vq->vq_free_cnt += free_cnt; - vq->vq_used_cons_idx = idx; -} - static inline int virtqueue_enqueue_refill_inorder(struct virtqueue *vq, struct rte_mbuf **cookies,
@@ -562,68 +421,7 @@ virtio_tso_fix_cksum(struct rte_mbuf *m) } -/* avoid write operation when necessary, to lessen cache issues */ -#define ASSIGN_UNLESS_EQUAL (var, val) do { \ - if ((var) != (val)) \ - (var) = (val); \ -} while (0) - -#define virtqueue_clear_net_hdr (_hdr) do { \ - ASSIGN_UNLESS_EQUAL((_hdr)->csum_start, 0); \ - ASSIGN_UNLESS_EQUAL((_hdr)->csum_offset, 0); \ - ASSIGN_UNLESS_EQUAL((_hdr)->flags, 0); \ - ASSIGN_UNLESS_EQUAL((_hdr)->gso_type, 0); \ - ASSIGN_UNLESS_EQUAL((_hdr)->gso_size, 0); \ - ASSIGN_UNLESS_EQUAL((_hdr)->hdr_len, 0); \ -} while (0) - -static inline void -virtqueue_xmit_offload (struct virtio_net_hdr *hdr, -struct rte_mbuf *cookie, -bool offload) -{ -if (offload) { -if (cookie->ol_flags &PKT_TX_TCP_SEG ) - cookie->ol_flags |=PKT_TX_TCP_CKSUM ; - -switch (cookie->ol_flags &PKT_TX_L4_MASK ) { -case PKT_TX_UDP_CKSUM : - hdr->csum_start = cookie->l2_len + cookie->l3_len; - hdr->csum_offset = offsetof(struct rte_udp_hdr , - dgram_cksum); - hdr->flags =VIRTIO_NET_HDR_F_NEEDS_CSUM ; -break ; - -case PKT_TX_TCP_CKSUM : - hdr->csum_start = cookie->l2_len + cookie->l3_len; - hdr->csum_offset = offsetof(struct rte_tcp_hdr , cksum); - hdr->flags =VIRTIO_NET_HDR_F_NEEDS_CSUM ; -break ; - -default : -ASSIGN_UNLESS_EQUAL (hdr->csum_start,0 ); -ASSIGN_UNLESS_EQUAL (hdr->csum_offset,0 ); -ASSIGN_UNLESS_EQUAL (hdr->flags,0 ); -break ; - } -/* TCP Segmentation Offload */ -if (cookie->ol_flags &PKT_TX_TCP_SEG ) { - hdr->gso_type = (cookie->ol_flags &PKT_TX_IPV6 ) ? -VIRTIO_NET_HDR_GSO_TCPV6 : -VIRTIO_NET_HDR_GSO_TCPV4 ; - hdr->gso_size = cookie->tso_segsz; - hdr->hdr_len = - cookie->l2_len + - cookie->l3_len + - cookie->l4_len; - }else { -ASSIGN_UNLESS_EQUAL (hdr->gso_type,0 ); -ASSIGN_UNLESS_EQUAL (hdr->gso_size,0 ); -ASSIGN_UNLESS_EQUAL (hdr->hdr_len,0 ); - } - } -} static inline void virtqueue_enqueue_xmit_inorder(struct virtnet_tx *txvq,
@@ -725,102 +523,6 @@ virtqueue_enqueue_xmit_packed_fast(struct virtnet_tx *txvq,virtqueue_store_flags_packed (dp, flags, vq->hw->weak_barriers); } -static inline void -virtqueue_enqueue_xmit_packed (struct virtnet_tx *txvq,struct rte_mbuf *cookie, -uint16_t needed,int can_push,int in_order) -{ -struct virtio_tx_region *txr = txvq->virtio_net_hdr_mz->addr; -struct vq_desc_extra *dxp; -struct virtqueue *vq = txvq->vq; -struct vring_packed_desc *start_dp, *head_dp; -uint16_t idx, id, head_idx, head_flags; -int16_t head_size = vq->hw->vtnet_hdr_size; -struct virtio_net_hdr *hdr; -uint16_t prev; -bool prepend_header = false; - - id = in_order ? vq->vq_avail_idx : vq->vq_desc_head_idx; - - dxp = &vq->vq_descx[id]; - dxp->ndescs = needed; - dxp->cookie = cookie; - - head_idx = vq->vq_avail_idx; - idx = head_idx; - prev = head_idx; - start_dp = vq->vq_packed.ring.desc; - - head_dp = &vq->vq_packed.ring.desc[idx]; - head_flags = cookie->next ?VRING_DESC_F_NEXT :0 ; - head_flags |= vq->vq_packed.cached_flags; - -if (can_push) { -/* prepend cannot fail, checked by caller */ - hdr = rte_pktmbuf_mtod_offset(cookie, struct virtio_net_hdr *, - -head_size); - prepend_header = true; - -/* if offload disabled, it is not zeroed below, do it now */ -if (!vq->hw->has_tx_offload) -virtqueue_clear_net_hdr (hdr); - }else { -/* setup first tx ring slot to point to header -* stored in reserved region. -*/ - start_dp[idx].addr = txvq->virtio_net_hdr_mem + -RTE_PTR_DIFF (&txr[idx].tx_hdr, txr); - start_dp[idx].len = vq->hw->vtnet_hdr_size; - hdr = (struct virtio_net_hdr *)&txr[idx].tx_hdr; - idx++; -if (idx >= vq->vq_nentries) { - idx -= vq->vq_nentries; - vq->vq_packed.cached_flags ^= -VRING_PACKED_DESC_F_AVAIL_USED ; - } - } - -virtqueue_xmit_offload (hdr, cookie, vq->hw->has_tx_offload); - -do { -uint16_t flags; - - start_dp[idx].addr =VIRTIO_MBUF_DATA_DMA_ADDR (cookie, vq); - start_dp[idx].len = cookie->data_len; -if (prepend_header) { - start_dp[idx].addr -= head_size; - start_dp[idx].len += head_size; - prepend_header = false; - } - -if (likely (idx != head_idx)) { - flags = cookie->next ?VRING_DESC_F_NEXT :0 ; - flags |= vq->vq_packed.cached_flags; - start_dp[idx].flags = flags; - } - prev = idx; - idx++; -if (idx >= vq->vq_nentries) { - idx -= vq->vq_nentries; - vq->vq_packed.cached_flags ^= -VRING_PACKED_DESC_F_AVAIL_USED ; - } - }while ((cookie = cookie->next) !=NULL ); - - start_dp[prev].id = id; - - vq->vq_free_cnt = (uint16_t )(vq->vq_free_cnt - needed); - vq->vq_avail_idx = idx; - -if (!in_order) { - vq->vq_desc_head_idx = dxp->next; -if (vq->vq_desc_head_idx ==VQ_RING_DESC_CHAIN_END ) - vq->vq_desc_tail_idx =VQ_RING_DESC_CHAIN_END ; - } - -virtqueue_store_flags_packed (head_dp, head_flags, - vq->hw->weak_barriers); -} - static inline void virtqueue_enqueue_xmit(struct virtnet_tx *txvq, struct rte_mbuf *cookie, uint16_t needed, int use_indirect, int can_push,
@@ -1246,7 +948,6 @@ virtio_rx_offload(struct rte_mbuf *m, struct virtio_net_hdr *hdr)return 0 ; } -#define VIRTIO_MBUF_BURST_SZ 64#define DESC_PER_CACHELINE (RTE_CACHE_LINE_SIZE / sizeof(struct vring_desc))uint16_t virtio_recv_pkts (void *rx_queue,struct rte_mbuf **rx_pkts,uint16_t nb_pkts)
drivers/net/virtio/virtqueue.h +302 -0
320 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v11 6/9 net/virtio: add vectorized packed ring Rx path
In reply to Marvin LiuOptimize packed ring Rx path with SIMD instructions. Solution of optimization is pretty like vhost, is that split path into batch and single functions. Batch function is further optimized by AVX512 instructions. Also pad desc extra structure to 16 bytes aligned, thus four elements will be saved in one batch.
drivers/net/virtio/Makefile +35 -0
@@ -36,6 +36,41 @@ else ifneq ($(filter y,$(CONFIG_RTE_ARCH_ARM) $(CONFIG_RTE_ARCH_ARM64)),) SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_rxtx_simple_neon.c endif +ifneq ($(FORCE_DISABLE_AVX512), y) + CC_AVX512_SUPPORT=\ + $(shell $(CC) -march=native -dM -E - </dev/null 2>&1 | \ + sed '/./{H;$$!d} ; x ; /AVX512F/!d; /AVX512BW/!d; /AVX512VL/!d' | \ + grep -q AVX512 && echo 1) +endif + +ifeq ($(CC_AVX512_SUPPORT), 1) +CFLAGS += -DCC_AVX512_SUPPORT +SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_rxtx_packed_avx.c + +ifeq ($(RTE_TOOLCHAIN), gcc) +ifeq ($(shell test $(GCC_VERSION) -ge 83 && echo 1), 1) +CFLAGS += -DVIRTIO_GCC_UNROLL_PRAGMA +endif +endif + +ifeq ($(RTE_TOOLCHAIN), clang) +ifeq ($(shell test $(CLANG_MAJOR_VERSION)$(CLANG_MINOR_VERSION) -ge 37 && echo 1), 1) +CFLAGS += -DVIRTIO_CLANG_UNROLL_PRAGMA +endif +endif + +ifeq ($(RTE_TOOLCHAIN), icc) +ifeq ($(shell test $(ICC_MAJOR_VERSION) -ge 16 && echo 1), 1) +CFLAGS += -DVIRTIO_ICC_UNROLL_PRAGMA +endif +endif + +CFLAGS_virtio_rxtx_packed_avx.o += -mavx512f -mavx512bw -mavx512vl +ifeq ($(shell test $(GCC_VERSION) -ge 100 && echo 1), 1) +CFLAGS_virtio_rxtx_packed_avx.o += -Wno-zero-length-bounds +endif +endif + ifeq ($(CONFIG_RTE_VIRTIO_USER),y) SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_user/vhost_user.c SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_user/vhost_kernel.c
drivers/net/virtio/meson.build +14 -0
@@ -9,6 +9,20 @@ sources += files('virtio_ethdev.c', deps += ['kvargs', 'bus_pci'] if arch_subdir == 'x86' + if '-mno-avx512f' not in machine_args + if cc.has_argument('-mavx512f') and cc.has_argument('-mavx512vl') and cc.has_argument('-mavx512bw') + cflags += ['-mavx512f', '-mavx512bw', '-mavx512vl'] + cflags += ['-DCC_AVX512_SUPPORT'] + if (toolchain == 'gcc' and cc.version().version_compare('>=8.3.0')) + cflags += '-DVHOST_GCC_UNROLL_PRAGMA' + elif (toolchain == 'clang' and cc.version().version_compare('>=3.7.0')) + cflags += '-DVHOST_CLANG_UNROLL_PRAGMA' + elif (toolchain == 'icc' and cc.version().version_compare('>=16.0.0')) + cflags += '-DVHOST_ICC_UNROLL_PRAGMA' + endif + sources += files('virtio_rxtx_packed_avx.c') + endif + endif sources += files('virtio_rxtx_simple_sse.c') elif arch_subdir == 'ppc' sources += files('virtio_rxtx_simple_altivec.c')
drivers/net/virtio/virtio_ethdev.h +3 -0
@@ -105,6 +105,9 @@ uint16_t virtio_xmit_pkts_inorder(void *tx_queue, struct rte_mbuf **tx_pkts,uint16_t virtio_recv_pkts_vec (void *rx_queue,struct rte_mbuf **rx_pkts,uint16_t nb_pkts); +uint16_t virtio_recv_pkts_packed_vec (void *rx_queue,struct rte_mbuf **rx_pkts, +uint16_t nb_pkts); +int eth_virtio_dev_init (struct rte_eth_dev *eth_dev);void virtio_interrupt_handler (void *param);
drivers/net/virtio/virtio_rxtx.c +8 -0
@@ -2030,3 +2030,11 @@ virtio_xmit_pkts_inorder(void *tx_queue,return nb_tx; } + +__rte_weak uint16_t +virtio_recv_pkts_packed_vec(void *rx_queue __rte_unused, + struct rte_mbuf **rx_pkts __rte_unused, + uint16_t nb_pkts __rte_unused) +{ +return 0 ; +}
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +374 -0
374 lines not on this page · raw message
drivers/net/virtio/virtio_user_ethdev.c +14 -2
@@ -528,6 +528,7 @@ virtio_user_eth_dev_alloc(struct rte_vdev_device *vdev) hw->use_msix =1 ; hw->modern =0 ; hw->use_vec_rx =0 ; + hw->use_vec_tx =0 ; hw->use_inorder_rx =0 ; hw->use_inorder_tx =0 ; hw->virtio_user_dev = dev;
@@ -739,8 +740,19 @@ virtio_user_pmd_probe(struct rte_vdev_device *dev) goto end; } -if (vectorized) - hw->use_vec_rx =1 ; +if (vectorized) { +if (packed_vq) { +#if defined(CC_AVX512_SUPPORT ) + hw->use_vec_rx =1 ; + hw->use_vec_tx =1 ; +#else +PMD_INIT_LOG (INFO , +"building environment do not support packed ring vectorized" ); +#endif + }else { + hw->use_vec_rx =1 ; + } + }rte_eth_dev_probing_finish (eth_dev); ret =0 ;
drivers/net/virtio/virtqueue.h +2 -1
@@ -239,7 +239,8 @@ struct vq_desc_extra {void *cookie;uint16_t ndescs;uint16_t next; -}; +uint8_t padding[4 ]; +} __rte_packed __rte_aligned(16);struct virtqueue {struct virtio_hw *hw;/**< virtio_hw structure pointer. */
Signature · 1 line
2.17.1
Re: [dpdk-dev] [PATCH v11 6/9] net/virtio: add vectorized packed ring Rx path
Quoted 8 lines · Marvin Liu
Optimize packed ring Rx path with SIMD instructions. Solution of optimization is pretty like vhost, is that split path into batch and single functions. Batch function is further optimized by AVX512 instructions. Also pad desc extra structure to 16 bytes aligned, thus four elements will be saved in one batch.
Signed-off-by Marvin Liu <[email protected]>Reviewed-by Maxime Coquelin <[email protected]>
<...>
Quoted 8 lines
drivers/net/virtio/meson.build +4
-0@@ -9,6 +9,20 @@ sources += files('virtio_ethdev.c', deps += ['kvargs', 'bus_pci'] if arch_subdir == 'x86' + if '-mno-avx512f' not in machine_args + if cc.has_argument('-mavx512f') and cc.has_argument('-mavx512vl') and cc.has_argument('-mavx512bw') + cflags += ['-mavx512f', '-mavx512bw', '-mavx512vl'] + cflags += ['-DCC_AVX512_SUPPORT']
drivers/net/virtio/meson.build sources += files('virtio_ethdev.c', · line 25
Quoted 10 lines
drivers/net/virtio/meson.build +10
-0+ if (toolchain == 'gcc' and cc.version().version_compare('>=8.3.0')) + cflags += '-DVHOST_GCC_UNROLL_PRAGMA' + elif (toolchain == 'clang' and cc.version().version_compare('>=3.7.0')) + cflags += '-DVHOST_CLANG_UNROLL_PRAGMA' + elif (toolchain == 'icc' and cc.version().version_compare('>=16.0.0')) + cflags += '-DVHOST_ICC_UNROLL_PRAGMA' + endif + sources += files('virtio_rxtx_packed_avx.c') + endif + endif
This is giving following error in Travis build [1], it is seems this usage is supported since meson 0.49 [2] and Travis has 0.47 [3], also DPDK supports version 0.47.1+ [4].
Can you please check for meson v0.47 version way of doing same thing?
[1]drivers/net/virtio/meson.build:12:19: ERROR: Expecting eol got not.
if '-mno-avx512f' not in machine_args
^[2]
https://mesonbuild.com/Syntax.html#dictionaries
Since 0.49.0, you can check if a dictionary contains a key like this:
if 'foo' not in my_dict
# This condition is false
endif
[3]
The Meson build system
Version: 0.47.1
[4]doc/guides/linux_gsg/sys_reqs.rst
* Meson (version 0.47.1+) and ninja
Re: [dpdk-dev] [PATCH v11 6/9] net/virtio: add vectorized packed ring Rx path
Quoted 35 lines · Ferruh Yigit
Quoted 8 lines · Marvin Liu
Optimize packed ring Rx path with SIMD instructions. Solution of optimization is pretty like vhost, is that split path into batch and single functions. Batch function is further optimized by AVX512 instructions. Also pad desc extra structure to 16 bytes aligned, thus four elements will be saved in one batch.
Signed-off-by Marvin Liu <[email protected]>Reviewed-by Maxime Coquelin <[email protected]><...>
Quoted 8 lines
drivers/net/virtio/meson.build +4
-0@@ -9,6 +9,20 @@ sources += files('virtio_ethdev.c', deps += ['kvargs', 'bus_pci'] if arch_subdir == 'x86' + if '-mno-avx512f' not in machine_args + if cc.has_argument('-mavx512f') and cc.has_argument('-mavx512vl') and cc.has_argument('-mavx512bw') + cflags += ['-mavx512f', '-mavx512bw', '-mavx512vl'] + cflags += ['-DCC_AVX512_SUPPORT']drivers/net/virtio/meson.build sources += files('virtio_ethdev.c', · line 25
Quoted 10 lines
drivers/net/virtio/meson.build +10
-0+ if (toolchain == 'gcc' and cc.version().version_compare('>=8.3.0')) + cflags += '-DVHOST_GCC_UNROLL_PRAGMA' + elif (toolchain == 'clang' and cc.version().version_compare('>=3.7.0')) + cflags += '-DVHOST_CLANG_UNROLL_PRAGMA' + elif (toolchain == 'icc' and cc.version().version_compare('>=16.0.0')) + cflags += '-DVHOST_ICC_UNROLL_PRAGMA' + endif + sources += files('virtio_rxtx_packed_avx.c') + endif + endifThis is giving following error in Travis build [1], it is seems this usage is supported since meson 0.49 [2] and Travis has 0.47 [3], also DPDK supports version 0.47.1+ [4].
Quoted 3 lines
Can you please check for meson v0.47 version way of doing same thing?
<arrayname>.contains() is probably what you want.
/Bruce
Re: [dpdk-dev] [PATCH v11 6/9] net/virtio: add vectorized packed ring Rx path
Quoted 36 lines · Bruce Richardson
Quoted 35 lines · Ferruh Yigit
Quoted 8 lines · Marvin Liu
Optimize packed ring Rx path with SIMD instructions. Solution of optimization is pretty like vhost, is that split path into batch and single functions. Batch function is further optimized by AVX512 instructions. Also pad desc extra structure to 16 bytes aligned, thus four elements will be saved in one batch.
Signed-off-by Marvin Liu <[email protected]>Reviewed-by Maxime Coquelin <[email protected]><...>
Quoted 8 lines
drivers/net/virtio/meson.build +4
-0@@ -9,6 +9,20 @@ sources += files('virtio_ethdev.c', deps += ['kvargs', 'bus_pci'] if arch_subdir == 'x86' + if '-mno-avx512f' not in machine_args + if cc.has_argument('-mavx512f') and cc.has_argument('-mavx512vl') and cc.has_argument('-mavx512bw') + cflags += ['-mavx512f', '-mavx512bw', '-mavx512vl'] + cflags += ['-DCC_AVX512_SUPPORT']drivers/net/virtio/meson.build sources += files('virtio_ethdev.c', · line 25
Quoted 10 lines
drivers/net/virtio/meson.build +10
-0+ if (toolchain == 'gcc' and cc.version().version_compare('>=8.3.0')) + cflags += '-DVHOST_GCC_UNROLL_PRAGMA' + elif (toolchain == 'clang' and cc.version().version_compare('>=3.7.0')) + cflags += '-DVHOST_CLANG_UNROLL_PRAGMA' + elif (toolchain == 'icc' and cc.version().version_compare('>=16.0.0')) + cflags += '-DVHOST_ICC_UNROLL_PRAGMA' + endif + sources += files('virtio_rxtx_packed_avx.c') + endif + endifThis is giving following error in Travis build [1], it is seems this usage is supported since meson 0.49 [2] and Travis has 0.47 [3], also DPDK supports version 0.47.1+ [4].
Quoted 5 lines
Quoted 3 lines
Can you please check for meson v0.47 version way of doing same thing?
<arrayname>.contains() is probably what you want.
Thanks Bruce,
I will update in the next-net as following [1].
@Marvin can you please double check it on the next-net?
[1]
- if '-mno-avx512f' not in machine_args
+ if not machine_args.contains('-mno-avx512f')
PATCH v11 7/9 net/virtio: add vectorized packed ring Tx path
In reply to Marvin LiuOptimize packed ring Tx path like Rx path. Split Tx path into batch and single Tx functions. Batch function is further optimized by AVX512 instructions.
drivers/net/virtio/virtio_ethdev.h +3 -0
@@ -108,6 +108,9 @@ uint16_t virtio_recv_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,uint16_t virtio_recv_pkts_packed_vec (void *rx_queue,struct rte_mbuf **rx_pkts,uint16_t nb_pkts); +uint16_t virtio_xmit_pkts_packed_vec (void *tx_queue,struct rte_mbuf **tx_pkts, +uint16_t nb_pkts); +int eth_virtio_dev_init (struct rte_eth_dev *eth_dev);void virtio_interrupt_handler (void *param);
drivers/net/virtio/virtio_rxtx.c +8 -0
@@ -2038,3 +2038,11 @@ virtio_recv_pkts_packed_vec(void *rx_queue __rte_unused, {return 0 ; } + +__rte_weak uint16_t +virtio_xmit_pkts_packed_vec(void *tx_queue __rte_unused, + struct rte_mbuf **tx_pkts __rte_unused, + uint16_t nb_pkts __rte_unused) +{ +return 0 ; +}
drivers/net/virtio/virtio_rxtx_packed_avx.c +249 -0
261 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v11 8/9 net/virtio: add election for vectorized path
In reply to Marvin LiuRewrite vectorized path selection logic. Default setting comes from vectorized devarg, then checks each criteria.
Packed ring vectorized path need:
AVX512F and required extensions are supported by compiler and host VERSION_1 and IN_ORDER features are negotiated mergeable feature is not negotiated
LRO offloading is disabled
Split ring vectorized rx path need:
mergeable and IN_ORDER features are not negotiated LRO, chksum and vlan strip offloadings are disabled
drivers/net/virtio/virtio_ethdev.c +72 -24
@@ -1523,9 +1523,12 @@ set_rxtx_funcs(struct rte_eth_dev *eth_dev)if (vtpci_packed_queue (hw)) {PMD_INIT_LOG (INFO ,"virtio: using packed ring %s Tx path on port %u" , - hw->use_inorder_tx ?"inorder" :"standard" , + hw->use_vec_tx ?"vectorized" :"standard" , eth_dev->data->port_id); - eth_dev->tx_pkt_burst = virtio_xmit_pkts_packed; +if (hw->use_vec_tx) + eth_dev->tx_pkt_burst = virtio_xmit_pkts_packed_vec; +else + eth_dev->tx_pkt_burst = virtio_xmit_pkts_packed; }else {if (hw->use_inorder_tx) { PMD_INIT_LOG(INFO, "virtio: using inorder Tx path on port %u",
@@ -1539,7 +1542,13 @@ set_rxtx_funcs(struct rte_eth_dev *eth_dev) }if (vtpci_packed_queue (hw)) { -if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) { +if (hw->use_vec_rx) { +PMD_INIT_LOG (INFO , +"virtio: using packed ring vectorized Rx path on port %u" , + eth_dev->data->port_id); + eth_dev->rx_pkt_burst = + &virtio_recv_pkts_packed_vec; + }else if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) {PMD_INIT_LOG (INFO ,"virtio: using packed ring mergeable buffer Rx path on port %u" , eth_dev->data->port_id);
@@ -1952,8 +1961,17 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev) goto err_virtio_init;if (vectorized) { -if (!vtpci_packed_queue (hw)) +if (!vtpci_packed_queue (hw)) { + hw->use_vec_rx =1 ; + }else { +#if !defined(CC_AVX512_SUPPORT ) +PMD_DRV_LOG (INFO , +"building environment do not support packed ring vectorized" ); +#else hw->use_vec_rx =1 ; + hw->use_vec_tx =1 ; +#endif + } } hw->opened = true;
@@ -2288,31 +2306,61 @@ virtio_dev_configure(struct rte_eth_dev *dev)return -EBUSY ; } -if (vtpci_with_feature (hw,VIRTIO_F_IN_ORDER )) { - hw->use_inorder_tx =1 ; - hw->use_inorder_rx =1 ; - hw->use_vec_rx =0 ; - } -if (vtpci_packed_queue (hw)) { - hw->use_vec_rx =0 ; - hw->use_inorder_rx =0 ; - } +if ((hw->use_vec_rx || hw->use_vec_tx) && + (!rte_cpu_get_flag_enabled (RTE_CPUFLAG_AVX512F ) || + !vtpci_with_feature (hw,VIRTIO_F_IN_ORDER ) || + !vtpci_with_feature (hw,VIRTIO_F_VERSION_1 ))) { +PMD_DRV_LOG (INFO , +"disabled packed ring vectorized path for requirements not met" ); + hw->use_vec_rx =0 ; + hw->use_vec_tx =0 ; + } +if (hw->use_vec_rx) { +if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) { +PMD_DRV_LOG (INFO , +"disabled packed ring vectorized rx for mrg_rxbuf enabled" ); + hw->use_vec_rx =0 ; + } + +if (rx_offloads &DEV_RX_OFFLOAD_TCP_LRO ) { +PMD_DRV_LOG (INFO , +"disabled packed ring vectorized rx for TCP_LRO enabled" ); + hw->use_vec_rx =0 ; + } + } + }else { +if (vtpci_with_feature (hw,VIRTIO_F_IN_ORDER )) { + hw->use_inorder_tx =1 ; + hw->use_inorder_rx =1 ; + hw->use_vec_rx =0 ; + } + +if (hw->use_vec_rx) {#if definedRTE_ARCH_ARM64 || definedRTE_ARCH_ARM -if (!rte_cpu_get_flag_enabled (RTE_CPUFLAG_NEON )) { - hw->use_vec_rx =0 ; - } +if (!rte_cpu_get_flag_enabled (RTE_CPUFLAG_NEON )) { +PMD_DRV_LOG (INFO , +"disabled split ring vectorized path for requirement not met" ); + hw->use_vec_rx =0 ; + }#endif -if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) { - hw->use_vec_rx =0 ; - } +if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) { +PMD_DRV_LOG (INFO , +"disabled split ring vectorized rx for mrg_rxbuf enabled" ); + hw->use_vec_rx =0 ; + } -if (rx_offloads & (DEV_RX_OFFLOAD_UDP_CKSUM | -DEV_RX_OFFLOAD_TCP_CKSUM | -DEV_RX_OFFLOAD_TCP_LRO | -DEV_RX_OFFLOAD_VLAN_STRIP )) - hw->use_vec_rx =0 ; +if (rx_offloads & (DEV_RX_OFFLOAD_UDP_CKSUM | +DEV_RX_OFFLOAD_TCP_CKSUM | +DEV_RX_OFFLOAD_TCP_LRO | +DEV_RX_OFFLOAD_VLAN_STRIP )) { +PMD_DRV_LOG (INFO , +"disabled split ring vectorized rx for offloading enabled" ); + hw->use_vec_rx =0 ; + } + } + }return 0 ; }
Signature · 1 line
2.17.1
PATCH v11 9/9 doc: add packed vectorized path
In reply to Marvin LiuDocument packed virtqueue vectorized path selection logic in virtio net PMD.
doc/guides/nics/virtio.rst +25 -14
@@ -482,6 +482,13 @@ according to below configuration: both negotiated, this path will be selected. #. Packed virtqueue in-order non-mergeable path: If in-order feature is negotiated and Rx mergeable is not negotiated, this path will be selected. +#. Packed virtqueue vectorized Rx path: If building and running environment support + AVX512 && in-order feature is negotiated && Rx mergeable is not negotiated && + TCP_LRO Rx offloading is disabled && vectorized option enabled, + this path will be selected. +#. Packed virtqueue vectorized Tx path: If building and running environment support + AVX512 && in-order feature is negotiated && vectorized option enabled, + this path will be selected. Rx/Tx callbacks of each Virtio path ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -504,6 +511,8 @@ are shown in below table: Packed virtqueue non-meregable path virtio_recv_pkts_packed virtio_xmit_pkts_packed Packed virtqueue in-order mergeable path virtio_recv_mergeable_pkts_packed virtio_xmit_pkts_packed Packed virtqueue in-order non-mergeable path virtio_recv_pkts_packed virtio_xmit_pkts_packed + Packed virtqueue vectorized Rx path virtio_recv_pkts_packed_vec virtio_xmit_pkts_packed + Packed virtqueue vectorized Tx path virtio_recv_pkts_packed virtio_xmit_pkts_packed_vec ============================================ ================================= ======================== Virtio paths Support Status from Release to Release
@@ -521,20 +530,22 @@ All virtio paths support status are shown in below table: .. table:: Virtio Paths and Releases - ============================================ ============= ============= ============= - Virtio paths 16.11 ~ 18.05 18.08 ~ 18.11 19.02 ~ 19.11 - ============================================ ============= ============= ============= - Split virtqueue mergeable path Y Y Y - Split virtqueue non-mergeable path Y Y Y - Split virtqueue vectorized Rx path Y Y Y - Split virtqueue simple Tx path Y N N - Split virtqueue in-order mergeable path Y Y - Split virtqueue in-order non-mergeable path Y Y - Packed virtqueue mergeable path Y - Packed virtqueue non-mergeable path Y - Packed virtqueue in-order mergeable path Y - Packed virtqueue in-order non-mergeable path Y - ============================================ ============= ============= ============= + ============================================ ============= ============= ============= ======= + Virtio paths 16.11 ~ 18.05 18.08 ~ 18.11 19.02 ~ 19.11 20.05 ~ + ============================================ ============= ============= ============= ======= + Split virtqueue mergeable path Y Y Y Y + Split virtqueue non-mergeable path Y Y Y Y + Split virtqueue vectorized Rx path Y Y Y Y + Split virtqueue simple Tx path Y N N N + Split virtqueue in-order mergeable path Y Y Y + Split virtqueue in-order non-mergeable path Y Y Y + Packed virtqueue mergeable path Y Y + Packed virtqueue non-mergeable path Y Y + Packed virtqueue in-order mergeable path Y Y + Packed virtqueue in-order non-mergeable path Y Y + Packed virtqueue vectorized Rx path Y + Packed virtqueue vectorized Tx path Y + ============================================ ============= ============= ============= ======= QEMU Support Status ~~~~~~~~~~~~~~~~~~~
Signature · 1 line
2.17.1
v12 cover add packed ring vectorized path
In reply to Marvin LiuThis patch set introduced vectorized path for packed ring.
The size of packed ring descriptor is 16Bytes. Four batched descriptors are just placed into one cacheline. AVX512 instructions can well handle this kind of data. Packed ring TX path can fully transformed into vectorized path. Packed ring Rx path can be vectorized when requirements met(LRO and mergeable disabled).
New device parameter "vectorized" will be introduced in this patch set. This parameter will be workable for both virtio device and virtio user vdev. It will also unify split and packed ring vectorized path default setting. Path election logic will check dependencies of vectorized path. Packed ring vectorized path is dependent on building/running environment and features like IN_ORDER and VERSION_1 enabled, MRG and LRO disabled. If vectorized path is not supported, will fallback to normal path.
v12:
* eliminate weak symbols in data path
* remove desc extra padding which can impact normal path
* fix enqueue address invalid
v11:
* fix i686 build warnings
* fix typo in doc
v10:
* reuse packed ring xmit cleanup
v9:
* replace RTE_LIBRTE_VIRTIO_INC_VECTOR with vectorized devarg
* reorder patch sequence
v8:
* fix meson build error on ubuntu16.04 and suse15
v7:
* default vectorization is disabled
* compilation time check dependency on rte_mbuf structure
* offsets are calcuated when compiling
* remove useless barrier as descs are batched store&load
* vindex of scatter is directly set
* some comments updates
* enable vectorized path in meson build
v6:
* fix issue when size not power of 2
v5:
* remove cpuflags definition as required extensions always come with AVX512F on x86_64
* inorder actions should depend on feature bit
* check ring type in rx queue setup
* rewrite some commit logs
* fix some checkpatch warnings
v4:
* rename 'packed_vec' to 'vectorized', also used in split ring
* add RTE_LIBRTE_VIRTIO_INC_VECTOR config for virtio ethdev
* check required AVX512 extensions cpuflags
* combine split and packed ring datapath selection logic
* remove limitation that size must power of two
* clear 12Bytes virtio_net_hdr
v3:
* remove virtio_net_hdr array for better performance
* disable 'packed_vec' by default
v2:
* more function blocks replaced by vector instructions
* clean virtio_net_hdr by vector instruction
* allow header room size change
* add 'packed_vec' option in virtio_user vdev
* fix build not check whether AVX512 enabled
* doc update
Marvin Liu (9):
net/virtio: add Rx free threshold setting net/virtio: inorder should depend on feature bit net/virtio: add vectorized devarg net/virtio-user: add vectorized devarg net/virtio: reuse packed ring functions net/virtio: add vectorized packed ring Rx path net/virtio: add vectorized packed ring Tx path net/virtio: add election for vectorized path
doc: add packed vectorized path
doc/guides/nics/virtio.rst | 52 +- drivers/net/virtio/Makefile | 35 ++ drivers/net/virtio/meson.build | 14 + drivers/net/virtio/virtio_ethdev.c | 142 ++++- drivers/net/virtio/virtio_ethdev.h | 6 + drivers/net/virtio/virtio_pci.h | 3 +- drivers/net/virtio/virtio_rxtx.c | 351 ++--------- drivers/net/virtio/virtio_rxtx_packed_avx.c | 607 ++++++++++++++++++++ drivers/net/virtio/virtio_user_ethdev.c | 32 +- drivers/net/virtio/virtqueue.c | 7 +- drivers/net/virtio/virtqueue.h | 304 ++++++++++ 11 files changed, 1199 insertions(+), 354 deletions(-) create mode 100644 drivers/net/virtio/virtio_rxtx_packed_avx.c
Signature · 1 line
2.17.1
PATCH v12 1/9 net/virtio: add Rx free threshold setting
Introduce free threshold setting in Rx queue, its default value is 32. Limit the threshold size to multiple of four as only vectorized packed Rx function will utilize it. Virtio driver will rearm Rx queue when more than rx_free_thresh descs were dequeued.
drivers/net/virtio/virtio_rxtx.c +23 -0
@@ -936,6 +936,7 @@ virtio_dev_rx_queue_setup(struct rte_eth_dev *dev,struct virtio_hw *hw = dev->data->dev_private;struct virtqueue *vq = hw->vqs[vtpci_queue_idx];struct virtnet_rx *rxvq; +uint16_t rx_free_thresh;PMD_INIT_FUNC_TRACE ();
@@ -944,6 +945,28 @@ virtio_dev_rx_queue_setup(struct rte_eth_dev *dev,return -EINVAL ; } + rx_free_thresh = rx_conf->rx_free_thresh; +if (rx_free_thresh ==0 ) + rx_free_thresh = +RTE_MIN (vq->vq_nentries /4 ,DEFAULT_RX_FREE_THRESH ); + +if (rx_free_thresh &0x3 ) { +RTE_LOG (ERR ,PMD ,"rx_free_thresh must be multiples of four." +" (rx_free_thresh=%u port=%u queue=%u)\n" , + rx_free_thresh, dev->data->port_id, queue_idx); +return -EINVAL ; + } + +if (rx_free_thresh >= vq->vq_nentries) { +RTE_LOG (ERR ,PMD ,"rx_free_thresh must be less than the " +"number of RX entries (%u)." +" (rx_free_thresh=%u port=%u queue=%u)\n" , + vq->vq_nentries, + rx_free_thresh, dev->data->port_id, queue_idx); +return -EINVAL ; + } + vq->vq_free_thresh = rx_free_thresh; +if (nb_desc ==0 || nb_desc > vq->vq_nentries) nb_desc = vq->vq_nentries; vq->vq_free_cnt =RTE_MIN (vq->vq_free_cnt, nb_desc);
drivers/net/virtio/virtqueue.h +2 -0
@@ -18,6 +18,8 @@struct rte_mbuf ; +#define DEFAULT_RX_FREE_THRESH 32 +/* * Per virtio_ring.h in Linux. * For virtio_pci on SMP, we don't need to order with respect to MMIO
Signature · 1 line
2.17.1
PATCH v12 2/9 net/virtio: inorder should depend on feature bit
In reply to Marvin LiuRing initialization is different when inorder feature negotiated. This action should dependent on negotiated feature bits.
drivers/net/virtio/virtio_rxtx.c +4 -3
@@ -989,6 +989,7 @@ virtio_dev_rx_queue_setup_finish(struct rte_eth_dev *dev, uint16_t queue_idx)struct rte_mbuf *m;uint16_t desc_idx;int error, nbufs, i; +bool in_order =vtpci_with_feature (hw,VIRTIO_F_IN_ORDER );PMD_INIT_FUNC_TRACE ();
@@ -1018,7 +1019,7 @@ virtio_dev_rx_queue_setup_finish(struct rte_eth_dev *dev, uint16_t queue_idx)virtio_rxq_rearm_vec (rxvq); nbufs +=RTE_VIRTIO_VPMD_RX_REARM_THRESH ; } - }else if (hw->use_inorder_rx) { + }else if (!vtpci_packed_queue (vq->hw) && in_order) {if ((!virtqueue_full (vq))) {uint16_t free_cnt = vq->vq_free_cnt;struct rte_mbuf *pkts[free_cnt];
@@ -1133,7 +1134,7 @@ virtio_dev_tx_queue_setup_finish(struct rte_eth_dev *dev,PMD_INIT_FUNC_TRACE ();if (!vtpci_packed_queue (hw)) { -if (hw->use_inorder_tx) +if (vtpci_with_feature (hw,VIRTIO_F_IN_ORDER )) vq->vq_split.ring.desc[vq->vq_nentries -1 ].next =0 ; }
@@ -2046,7 +2047,7 @@ virtio_xmit_pkts_packed(void *tx_queue, struct rte_mbuf **tx_pkts,struct virtio_hw *hw = vq->hw;uint16_t hdr_size = hw->vtnet_hdr_size;uint16_t nb_tx =0 ; -bool in_order = hw->use_inorder_tx; +bool in_order =vtpci_with_feature (hw,VIRTIO_F_IN_ORDER );if (unlikely (hw->started ==0 && tx_pkts != hw->inject_pkts))return nb_tx;
Signature · 1 line
2.17.1
PATCH v12 3/9 net/virtio: add vectorized devarg
In reply to Marvin LiuPreviously, virtio split ring vectorized path was enabled by default. This is not suitable for everyone because that path dose not follow virtio spec. Add new devarg for virtio vectorized path selection. By default vectorized path is disabled.
doc/guides/nics/virtio.rst +7 -0
@@ -363,6 +363,13 @@ Below devargs are supported by the PCI virtio driver: rte_eth_link_get_nowait function. (Default: 10000 (10G)) +#. ``vectorized``: + + It is used to specify whether virtio device perfers to use vectorized path. + Afterwards, dependencies of vectorized path will be checked in path + election. + (Default: 0 (disabled)) + Below devargs are supported by the virtio-user vdev: #. ``path``:
drivers/net/virtio/virtio_ethdev.c +42 -13
138 lines not on this page · raw message
drivers/net/virtio/virtio_pci.h +2 -1
@@ -253,7 +253,8 @@ struct virtio_hw {uint8_t vlan_strip;uint8_t use_msix;uint8_t modern; -uint8_t use_simple_rx; +uint8_t use_vec_rx; +uint8_t use_vec_tx;uint8_t use_inorder_rx;uint8_t use_inorder_tx;uint8_t weak_barriers;
drivers/net/virtio/virtio_rxtx.c +2 -2
@@ -996,7 +996,7 @@ virtio_dev_rx_queue_setup_finish(struct rte_eth_dev *dev, uint16_t queue_idx)/* Allocate blank mbufs for the each rx descriptor */ nbufs =0 ; -if (hw->use_simple_rx) { +if (hw->use_vec_rx && !vtpci_packed_queue (hw)) {for (desc_idx =0 ; desc_idx < vq->vq_nentries; desc_idx++) { vq->vq_split.ring.avail->ring[desc_idx] = desc_idx;
@@ -1014,7 +1014,7 @@ virtio_dev_rx_queue_setup_finish(struct rte_eth_dev *dev, uint16_t queue_idx) &rxvq->fake_mbuf; } -if (hw->use_simple_rx) { +if (hw->use_vec_rx && !vtpci_packed_queue (hw)) {while (vq->vq_free_cnt >=RTE_VIRTIO_VPMD_RX_REARM_THRESH ) {virtio_rxq_rearm_vec (rxvq); nbufs +=RTE_VIRTIO_VPMD_RX_REARM_THRESH ;
drivers/net/virtio/virtio_user_ethdev.c +1 -1
@@ -525,7 +525,7 @@ virtio_user_eth_dev_alloc(struct rte_vdev_device *vdev)*/ hw->use_msix =1 ; hw->modern =0 ; - hw->use_simple_rx =0 ; + hw->use_vec_rx =0 ; hw->use_inorder_rx =0 ; hw->use_inorder_tx =0 ; hw->virtio_user_dev = dev;
drivers/net/virtio/virtqueue.c +4 -3
@@ -32,7 +32,8 @@ virtqueue_detach_unused(struct virtqueue *vq) end = (vq->vq_avail_idx + vq->vq_free_cnt) & (vq->vq_nentries -1 );for (idx =0 ; idx < vq->vq_nentries; idx++) { -if (hw->use_simple_rx && type ==VTNET_RQ ) { +if (hw->use_vec_rx && !vtpci_packed_queue (hw) && + type ==VTNET_RQ ) {if (start <= end && idx >= start && idx < end)continue ;if (start > end && (idx >= start || idx < end))
@@ -97,7 +98,7 @@ virtqueue_rxvq_flush_split(struct virtqueue *vq)for (i =0 ; i < nb_used; i++) { used_idx = vq->vq_used_cons_idx & (vq->vq_nentries -1 ); uep = &vq->vq_split.ring.used->ring[used_idx]; -if (hw->use_simple_rx) { +if (hw->use_vec_rx) { desc_idx = used_idx;rte_pktmbuf_free (vq->sw_ring[desc_idx]); vq->vq_free_cnt++;
@@ -121,7 +122,7 @@ virtqueue_rxvq_flush_split(struct virtqueue *vq) vq->vq_used_cons_idx++; } -if (hw->use_simple_rx) { +if (hw->use_vec_rx) {while (vq->vq_free_cnt >=RTE_VIRTIO_VPMD_RX_REARM_THRESH ) {virtio_rxq_rearm_vec (rxq);if (virtqueue_kick_prepare (vq))
Signature · 1 line
2.17.1
PATCH v12 4/9 net/virtio-user: add vectorized devarg
In reply to Marvin LiuAdd new devarg for virtio user device vectorized path selection. By default vectorized path is disabled.
doc/guides/nics/virtio.rst +6 -0
@@ -424,6 +424,12 @@ Below devargs are supported by the virtio-user vdev: rte_eth_link_get_nowait function. (Default: 10000 (10G)) +#. ``vectorized``: + + It is used to specify whether virtio device perfers to use vectorized path. + Afterwards, dependencies of vectorized path will be checked in path + election. + (Default: 0 (disabled)) Virtio paths Selection and Usage --------------------------------
drivers/net/virtio/virtio_user_ethdev.c +17 -1
@@ -452,6 +452,8 @@ static const char *valid_args[] = {VIRTIO_USER_ARG_PACKED_VQ , #define VIRTIO_USER_ARG_SPEED "speed"VIRTIO_USER_ARG_SPEED , +#define VIRTIO_USER_ARG_VECTORIZED "vectorized" +VIRTIO_USER_ARG_VECTORIZED , NULL };
@@ -559,6 +561,7 @@ virtio_user_pmd_probe(struct rte_vdev_device *dev)uint64_t mrg_rxbuf =1 ;uint64_t in_order =1 ;uint64_t packed_vq =0 ; +uint64_t vectorized =0 ;char *path =NULL ;char *ifname =NULL ;char *mac_addr =NULL ;
@@ -675,6 +678,15 @@ virtio_user_pmd_probe(struct rte_vdev_device *dev) } } +if (rte_kvargs_count (kvlist,VIRTIO_USER_ARG_VECTORIZED ) ==1 ) { +if (rte_kvargs_process (kvlist,VIRTIO_USER_ARG_VECTORIZED , + &get_integer_arg, &vectorized) <0 ) { +PMD_INIT_LOG (ERR ,"error to parse %s" , +VIRTIO_USER_ARG_VECTORIZED ); + goto end; + } + } +if (queues >1 && cq ==0 ) {PMD_INIT_LOG (ERR ,"multi-q requires ctrl-q" ); goto end;
@@ -727,6 +739,9 @@ virtio_user_pmd_probe(struct rte_vdev_device *dev) goto end; } +if (vectorized) + hw->use_vec_rx =1 ; +rte_eth_dev_probing_finish (eth_dev); ret =0 ;
@@ -785,4 +800,5 @@ RTE_PMD_REGISTER_PARAM_STRING(net_virtio_user,"mrg_rxbuf=<0|1> " "in_order=<0|1> " "packed_vq=<0|1> " - "speed=<int>"); +"speed=<int> " + "vectorized=<0|1>");
Signature · 1 line
2.17.1
PATCH v12 5/9 net/virtio: reuse packed ring functions
In reply to Marvin LiuMove offload, xmit cleanup and packed xmit enqueue function to header file. These functions will be reused by packed ring vectorized path.
drivers/net/virtio/virtio_rxtx.c +0 -299
@@ -89,23 +89,6 @@ vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx) dp->next =VQ_RING_DESC_CHAIN_END ; } -static void -vq_ring_free_id_packed (struct virtqueue *vq,uint16_t id) -{ -struct vq_desc_extra *dxp; - - dxp = &vq->vq_descx[id]; - vq->vq_free_cnt += dxp->ndescs; - -if (vq->vq_desc_tail_idx ==VQ_RING_DESC_CHAIN_END ) - vq->vq_desc_head_idx = id; -else - vq->vq_descx[vq->vq_desc_tail_idx].next = id; - - vq->vq_desc_tail_idx = id; - dxp->next =VQ_RING_DESC_CHAIN_END ; -} -void virtio_update_packet_stats (struct virtnet_stats *stats,struct rte_mbuf *mbuf) {
@@ -264,130 +247,6 @@ virtqueue_dequeue_rx_inorder(struct virtqueue *vq,return i; } -#ifndef DEFAULT_TX_FREE_THRESH -#define DEFAULT_TX_FREE_THRESH 32 -#endif - -static void -virtio_xmit_cleanup_inorder_packed (struct virtqueue *vq,int num) -{ -uint16_t used_idx, id, curr_id, free_cnt =0 ; -uint16_t size = vq->vq_nentries; -struct vring_packed_desc *desc = vq->vq_packed.ring.desc; -struct vq_desc_extra *dxp; - - used_idx = vq->vq_used_cons_idx; -/* desc_is_used has a load-acquire or rte_cio_rmb inside -* and wait for used desc in virtqueue. -*/ -while (num >0 &&desc_is_used (&desc[used_idx], vq)) { - id = desc[used_idx].id; -do { - curr_id = used_idx; - dxp = &vq->vq_descx[used_idx]; - used_idx += dxp->ndescs; - free_cnt += dxp->ndescs; - num -= dxp->ndescs; -if (used_idx >= size) { - used_idx -= size; - vq->vq_packed.used_wrap_counter ^=1 ; - } -if (dxp->cookie !=NULL ) { -rte_pktmbuf_free (dxp->cookie); - dxp->cookie =NULL ; - } - }while (curr_id != id); - } - vq->vq_used_cons_idx = used_idx; - vq->vq_free_cnt += free_cnt; -} - -static void -virtio_xmit_cleanup_normal_packed (struct virtqueue *vq,int num) -{ -uint16_t used_idx, id; -uint16_t size = vq->vq_nentries; -struct vring_packed_desc *desc = vq->vq_packed.ring.desc; -struct vq_desc_extra *dxp; - - used_idx = vq->vq_used_cons_idx; -/* desc_is_used has a load-acquire or rte_cio_rmb inside -* and wait for used desc in virtqueue. -*/ -while (num-- &&desc_is_used (&desc[used_idx], vq)) { - id = desc[used_idx].id; - dxp = &vq->vq_descx[id]; - vq->vq_used_cons_idx += dxp->ndescs; -if (vq->vq_used_cons_idx >= size) { - vq->vq_used_cons_idx -= size; - vq->vq_packed.used_wrap_counter ^=1 ; - } -vq_ring_free_id_packed (vq, id); -if (dxp->cookie !=NULL ) { -rte_pktmbuf_free (dxp->cookie); - dxp->cookie =NULL ; - } - used_idx = vq->vq_used_cons_idx; - } -} - -/* Cleanup from completed transmits. */ -static inline void -virtio_xmit_cleanup_packed (struct virtqueue *vq,int num,int in_order) -{ -if (in_order) -virtio_xmit_cleanup_inorder_packed (vq, num); -else -virtio_xmit_cleanup_normal_packed (vq, num); -} - -static void -virtio_xmit_cleanup (struct virtqueue *vq,uint16_t num) -{ -uint16_t i, used_idx, desc_idx; -for (i =0 ; i < num; i++) { -struct vring_used_elem *uep; -struct vq_desc_extra *dxp; - - used_idx = (uint16_t )(vq->vq_used_cons_idx & (vq->vq_nentries -1 )); - uep = &vq->vq_split.ring.used->ring[used_idx]; - - desc_idx = (uint16_t ) uep->id; - dxp = &vq->vq_descx[desc_idx]; - vq->vq_used_cons_idx++; -vq_ring_free_chain (vq, desc_idx); - -if (dxp->cookie !=NULL ) { -rte_pktmbuf_free (dxp->cookie); - dxp->cookie =NULL ; - } - } -} - -/* Cleanup from completed inorder transmits. */ -static __rte_always_inline void -virtio_xmit_cleanup_inorder (struct virtqueue *vq,uint16_t num) -{ -uint16_t i, idx = vq->vq_used_cons_idx; -int16_t free_cnt =0 ; -struct vq_desc_extra *dxp =NULL ; - -if (unlikely (num ==0 )) -return ; - -for (i =0 ; i < num; i++) { - dxp = &vq->vq_descx[idx++ & (vq->vq_nentries -1 )]; - free_cnt += dxp->ndescs; -if (dxp->cookie !=NULL ) { -rte_pktmbuf_free (dxp->cookie); - dxp->cookie =NULL ; - } - } - - vq->vq_free_cnt += free_cnt; - vq->vq_used_cons_idx = idx; -} - static inline int virtqueue_enqueue_refill_inorder(struct virtqueue *vq, struct rte_mbuf **cookies,
@@ -562,68 +421,7 @@ virtio_tso_fix_cksum(struct rte_mbuf *m) } -/* avoid write operation when necessary, to lessen cache issues */ -#define ASSIGN_UNLESS_EQUAL (var, val) do { \ - if ((var) != (val)) \ - (var) = (val); \ -} while (0) - -#define virtqueue_clear_net_hdr (_hdr) do { \ - ASSIGN_UNLESS_EQUAL((_hdr)->csum_start, 0); \ - ASSIGN_UNLESS_EQUAL((_hdr)->csum_offset, 0); \ - ASSIGN_UNLESS_EQUAL((_hdr)->flags, 0); \ - ASSIGN_UNLESS_EQUAL((_hdr)->gso_type, 0); \ - ASSIGN_UNLESS_EQUAL((_hdr)->gso_size, 0); \ - ASSIGN_UNLESS_EQUAL((_hdr)->hdr_len, 0); \ -} while (0) - -static inline void -virtqueue_xmit_offload (struct virtio_net_hdr *hdr, -struct rte_mbuf *cookie, -bool offload) -{ -if (offload) { -if (cookie->ol_flags &PKT_TX_TCP_SEG ) - cookie->ol_flags |=PKT_TX_TCP_CKSUM ; - -switch (cookie->ol_flags &PKT_TX_L4_MASK ) { -case PKT_TX_UDP_CKSUM : - hdr->csum_start = cookie->l2_len + cookie->l3_len; - hdr->csum_offset = offsetof(struct rte_udp_hdr , - dgram_cksum); - hdr->flags =VIRTIO_NET_HDR_F_NEEDS_CSUM ; -break ; - -case PKT_TX_TCP_CKSUM : - hdr->csum_start = cookie->l2_len + cookie->l3_len; - hdr->csum_offset = offsetof(struct rte_tcp_hdr , cksum); - hdr->flags =VIRTIO_NET_HDR_F_NEEDS_CSUM ; -break ; - -default : -ASSIGN_UNLESS_EQUAL (hdr->csum_start,0 ); -ASSIGN_UNLESS_EQUAL (hdr->csum_offset,0 ); -ASSIGN_UNLESS_EQUAL (hdr->flags,0 ); -break ; - } -/* TCP Segmentation Offload */ -if (cookie->ol_flags &PKT_TX_TCP_SEG ) { - hdr->gso_type = (cookie->ol_flags &PKT_TX_IPV6 ) ? -VIRTIO_NET_HDR_GSO_TCPV6 : -VIRTIO_NET_HDR_GSO_TCPV4 ; - hdr->gso_size = cookie->tso_segsz; - hdr->hdr_len = - cookie->l2_len + - cookie->l3_len + - cookie->l4_len; - }else { -ASSIGN_UNLESS_EQUAL (hdr->gso_type,0 ); -ASSIGN_UNLESS_EQUAL (hdr->gso_size,0 ); -ASSIGN_UNLESS_EQUAL (hdr->hdr_len,0 ); - } - } -} static inline void virtqueue_enqueue_xmit_inorder(struct virtnet_tx *txvq,
@@ -725,102 +523,6 @@ virtqueue_enqueue_xmit_packed_fast(struct virtnet_tx *txvq,virtqueue_store_flags_packed (dp, flags, vq->hw->weak_barriers); } -static inline void -virtqueue_enqueue_xmit_packed (struct virtnet_tx *txvq,struct rte_mbuf *cookie, -uint16_t needed,int can_push,int in_order) -{ -struct virtio_tx_region *txr = txvq->virtio_net_hdr_mz->addr; -struct vq_desc_extra *dxp; -struct virtqueue *vq = txvq->vq; -struct vring_packed_desc *start_dp, *head_dp; -uint16_t idx, id, head_idx, head_flags; -int16_t head_size = vq->hw->vtnet_hdr_size; -struct virtio_net_hdr *hdr; -uint16_t prev; -bool prepend_header = false; - - id = in_order ? vq->vq_avail_idx : vq->vq_desc_head_idx; - - dxp = &vq->vq_descx[id]; - dxp->ndescs = needed; - dxp->cookie = cookie; - - head_idx = vq->vq_avail_idx; - idx = head_idx; - prev = head_idx; - start_dp = vq->vq_packed.ring.desc; - - head_dp = &vq->vq_packed.ring.desc[idx]; - head_flags = cookie->next ?VRING_DESC_F_NEXT :0 ; - head_flags |= vq->vq_packed.cached_flags; - -if (can_push) { -/* prepend cannot fail, checked by caller */ - hdr = rte_pktmbuf_mtod_offset(cookie, struct virtio_net_hdr *, - -head_size); - prepend_header = true; - -/* if offload disabled, it is not zeroed below, do it now */ -if (!vq->hw->has_tx_offload) -virtqueue_clear_net_hdr (hdr); - }else { -/* setup first tx ring slot to point to header -* stored in reserved region. -*/ - start_dp[idx].addr = txvq->virtio_net_hdr_mem + -RTE_PTR_DIFF (&txr[idx].tx_hdr, txr); - start_dp[idx].len = vq->hw->vtnet_hdr_size; - hdr = (struct virtio_net_hdr *)&txr[idx].tx_hdr; - idx++; -if (idx >= vq->vq_nentries) { - idx -= vq->vq_nentries; - vq->vq_packed.cached_flags ^= -VRING_PACKED_DESC_F_AVAIL_USED ; - } - } - -virtqueue_xmit_offload (hdr, cookie, vq->hw->has_tx_offload); - -do { -uint16_t flags; - - start_dp[idx].addr =VIRTIO_MBUF_DATA_DMA_ADDR (cookie, vq); - start_dp[idx].len = cookie->data_len; -if (prepend_header) { - start_dp[idx].addr -= head_size; - start_dp[idx].len += head_size; - prepend_header = false; - } - -if (likely (idx != head_idx)) { - flags = cookie->next ?VRING_DESC_F_NEXT :0 ; - flags |= vq->vq_packed.cached_flags; - start_dp[idx].flags = flags; - } - prev = idx; - idx++; -if (idx >= vq->vq_nentries) { - idx -= vq->vq_nentries; - vq->vq_packed.cached_flags ^= -VRING_PACKED_DESC_F_AVAIL_USED ; - } - }while ((cookie = cookie->next) !=NULL ); - - start_dp[prev].id = id; - - vq->vq_free_cnt = (uint16_t )(vq->vq_free_cnt - needed); - vq->vq_avail_idx = idx; - -if (!in_order) { - vq->vq_desc_head_idx = dxp->next; -if (vq->vq_desc_head_idx ==VQ_RING_DESC_CHAIN_END ) - vq->vq_desc_tail_idx =VQ_RING_DESC_CHAIN_END ; - } - -virtqueue_store_flags_packed (head_dp, head_flags, - vq->hw->weak_barriers); -} - static inline void virtqueue_enqueue_xmit(struct virtnet_tx *txvq, struct rte_mbuf *cookie, uint16_t needed, int use_indirect, int can_push,
@@ -1246,7 +948,6 @@ virtio_rx_offload(struct rte_mbuf *m, struct virtio_net_hdr *hdr)return 0 ; } -#define VIRTIO_MBUF_BURST_SZ 64#define DESC_PER_CACHELINE (RTE_CACHE_LINE_SIZE / sizeof(struct vring_desc))uint16_t virtio_recv_pkts (void *rx_queue,struct rte_mbuf **rx_pkts,uint16_t nb_pkts)
drivers/net/virtio/virtqueue.h +302 -0
320 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v12 6/9 net/virtio: add vectorized packed ring Rx path
In reply to Marvin LiuOptimize packed ring Rx path with SIMD instructions. Solution of optimization is pretty like vhost, is that split path into batch and single functions. Batch function is further optimized by AVX512 instructions.
drivers/net/virtio/Makefile +35 -0
@@ -36,6 +36,41 @@ else ifneq ($(filter y,$(CONFIG_RTE_ARCH_ARM) $(CONFIG_RTE_ARCH_ARM64)),) SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_rxtx_simple_neon.c endif +ifneq ($(FORCE_DISABLE_AVX512), y) + CC_AVX512_SUPPORT=\ + $(shell $(CC) -march=native -dM -E - </dev/null 2>&1 | \ + sed '/./{H;$$!d} ; x ; /AVX512F/!d; /AVX512BW/!d; /AVX512VL/!d' | \ + grep -q AVX512 && echo 1) +endif + +ifeq ($(CC_AVX512_SUPPORT), 1) +CFLAGS += -DCC_AVX512_SUPPORT +SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_rxtx_packed_avx.c + +ifeq ($(RTE_TOOLCHAIN), gcc) +ifeq ($(shell test $(GCC_VERSION) -ge 83 && echo 1), 1) +CFLAGS += -DVIRTIO_GCC_UNROLL_PRAGMA +endif +endif + +ifeq ($(RTE_TOOLCHAIN), clang) +ifeq ($(shell test $(CLANG_MAJOR_VERSION)$(CLANG_MINOR_VERSION) -ge 37 && echo 1), 1) +CFLAGS += -DVIRTIO_CLANG_UNROLL_PRAGMA +endif +endif + +ifeq ($(RTE_TOOLCHAIN), icc) +ifeq ($(shell test $(ICC_MAJOR_VERSION) -ge 16 && echo 1), 1) +CFLAGS += -DVIRTIO_ICC_UNROLL_PRAGMA +endif +endif + +CFLAGS_virtio_rxtx_packed_avx.o += -mavx512f -mavx512bw -mavx512vl +ifeq ($(shell test $(GCC_VERSION) -ge 100 && echo 1), 1) +CFLAGS_virtio_rxtx_packed_avx.o += -Wno-zero-length-bounds +endif +endif + ifeq ($(CONFIG_RTE_VIRTIO_USER),y) SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_user/vhost_user.c SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_user/vhost_kernel.c
drivers/net/virtio/meson.build +14 -0
@@ -9,6 +9,20 @@ sources += files('virtio_ethdev.c', deps += ['kvargs', 'bus_pci'] if arch_subdir == 'x86' + if '-mno-avx512f' not in machine_args + if cc.has_argument('-mavx512f') and cc.has_argument('-mavx512vl') and cc.has_argument('-mavx512bw') + cflags += ['-mavx512f', '-mavx512bw', '-mavx512vl'] + cflags += ['-DCC_AVX512_SUPPORT'] + if (toolchain == 'gcc' and cc.version().version_compare('>=8.3.0')) + cflags += '-DVHOST_GCC_UNROLL_PRAGMA' + elif (toolchain == 'clang' and cc.version().version_compare('>=3.7.0')) + cflags += '-DVHOST_CLANG_UNROLL_PRAGMA' + elif (toolchain == 'icc' and cc.version().version_compare('>=16.0.0')) + cflags += '-DVHOST_ICC_UNROLL_PRAGMA' + endif + sources += files('virtio_rxtx_packed_avx.c') + endif + endif sources += files('virtio_rxtx_simple_sse.c') elif arch_subdir == 'ppc' sources += files('virtio_rxtx_simple_altivec.c')
drivers/net/virtio/virtio_ethdev.h +3 -0
@@ -105,6 +105,9 @@ uint16_t virtio_xmit_pkts_inorder(void *tx_queue, struct rte_mbuf **tx_pkts,uint16_t virtio_recv_pkts_vec (void *rx_queue,struct rte_mbuf **rx_pkts,uint16_t nb_pkts); +uint16_t virtio_recv_pkts_packed_vec (void *rx_queue,struct rte_mbuf **rx_pkts, +uint16_t nb_pkts); +int eth_virtio_dev_init (struct rte_eth_dev *eth_dev);void virtio_interrupt_handler (void *param);
drivers/net/virtio/virtio_rxtx.c +10 -0
@@ -2030,3 +2030,13 @@ virtio_xmit_pkts_inorder(void *tx_queue,return nb_tx; } + +#ifndef CC_AVX512_SUPPORT +uint16_t +virtio_recv_pkts_packed_vec(void *rx_queue __rte_unused, + struct rte_mbuf **rx_pkts __rte_unused, + uint16_t nb_pkts __rte_unused) +{ +return 0 ; +} +#endif /* ifndef CC_AVX512_SUPPORT */
drivers/net/virtio/virtio_rxtx_packed_avx.c new file +374 -0
374 lines not on this page · raw message
drivers/net/virtio/virtio_user_ethdev.c +14 -2
@@ -528,6 +528,7 @@ virtio_user_eth_dev_alloc(struct rte_vdev_device *vdev) hw->use_msix =1 ; hw->modern =0 ; hw->use_vec_rx =0 ; + hw->use_vec_tx =0 ; hw->use_inorder_rx =0 ; hw->use_inorder_tx =0 ; hw->virtio_user_dev = dev;
@@ -739,8 +740,19 @@ virtio_user_pmd_probe(struct rte_vdev_device *dev) goto end; } -if (vectorized) - hw->use_vec_rx =1 ; +if (vectorized) { +if (packed_vq) { +#if defined(CC_AVX512_SUPPORT ) + hw->use_vec_rx =1 ; + hw->use_vec_tx =1 ; +#else +PMD_INIT_LOG (INFO , +"building environment do not support packed ring vectorized" ); +#endif + }else { + hw->use_vec_rx =1 ; + } + }rte_eth_dev_probing_finish (eth_dev); ret =0 ;
Signature · 1 line
2.17.1
PATCH v12 7/9 net/virtio: add vectorized packed ring Tx path
In reply to Marvin LiuOptimize packed ring Tx path like Rx path. Split Tx path into batch and single Tx functions. Batch function is further optimized by AVX512 instructions.
drivers/net/virtio/virtio_ethdev.h +3 -0
@@ -108,6 +108,9 @@ uint16_t virtio_recv_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,uint16_t virtio_recv_pkts_packed_vec (void *rx_queue,struct rte_mbuf **rx_pkts,uint16_t nb_pkts); +uint16_t virtio_xmit_pkts_packed_vec (void *tx_queue,struct rte_mbuf **tx_pkts, +uint16_t nb_pkts); +int eth_virtio_dev_init (struct rte_eth_dev *eth_dev);void virtio_interrupt_handler (void *param);
drivers/net/virtio/virtio_rxtx.c +8 -0
@@ -2039,4 +2039,12 @@ virtio_recv_pkts_packed_vec(void *rx_queue __rte_unused, {return 0 ; } + +uint16_t +virtio_xmit_pkts_packed_vec(void *tx_queue __rte_unused, + struct rte_mbuf **tx_pkts __rte_unused, + uint16_t nb_pkts __rte_unused) +{ +return 0 ; +}#endif /* ifndef CC_AVX512_SUPPORT */
drivers/net/virtio/virtio_rxtx_packed_avx.c +233 -0
245 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v12 8/9 net/virtio: add election for vectorized path
In reply to Marvin LiuRewrite vectorized path selection logic. Default setting comes from vectorized devarg, then checks each criteria.
Packed ring vectorized path need:
AVX512F and required extensions are supported by compiler and host VERSION_1 and IN_ORDER features are negotiated mergeable feature is not negotiated
LRO offloading is disabled
Split ring vectorized rx path need:
mergeable and IN_ORDER features are not negotiated LRO, chksum and vlan strip offloadings are disabled
drivers/net/virtio/virtio_ethdev.c +76 -23
@@ -1523,9 +1523,12 @@ set_rxtx_funcs(struct rte_eth_dev *eth_dev)if (vtpci_packed_queue (hw)) {PMD_INIT_LOG (INFO ,"virtio: using packed ring %s Tx path on port %u" , - hw->use_inorder_tx ?"inorder" :"standard" , + hw->use_vec_tx ?"vectorized" :"standard" , eth_dev->data->port_id); - eth_dev->tx_pkt_burst = virtio_xmit_pkts_packed; +if (hw->use_vec_tx) + eth_dev->tx_pkt_burst = virtio_xmit_pkts_packed_vec; +else + eth_dev->tx_pkt_burst = virtio_xmit_pkts_packed; }else {if (hw->use_inorder_tx) { PMD_INIT_LOG(INFO, "virtio: using inorder Tx path on port %u",
@@ -1539,7 +1542,13 @@ set_rxtx_funcs(struct rte_eth_dev *eth_dev) }if (vtpci_packed_queue (hw)) { -if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) { +if (hw->use_vec_rx) { +PMD_INIT_LOG (INFO , +"virtio: using packed ring vectorized Rx path on port %u" , + eth_dev->data->port_id); + eth_dev->rx_pkt_burst = + &virtio_recv_pkts_packed_vec; + }else if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) {PMD_INIT_LOG (INFO ,"virtio: using packed ring mergeable buffer Rx path on port %u" , eth_dev->data->port_id);
@@ -1952,8 +1961,17 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev) goto err_virtio_init;if (vectorized) { -if (!vtpci_packed_queue (hw)) +if (!vtpci_packed_queue (hw)) { + hw->use_vec_rx =1 ; + }else { +#if !defined(CC_AVX512_SUPPORT ) +PMD_DRV_LOG (INFO , +"building environment do not support packed ring vectorized" ); +#else hw->use_vec_rx =1 ; + hw->use_vec_tx =1 ; +#endif + } } hw->opened = true;
@@ -2288,31 +2306,66 @@ virtio_dev_configure(struct rte_eth_dev *dev)return -EBUSY ; } -if (vtpci_with_feature (hw,VIRTIO_F_IN_ORDER )) { - hw->use_inorder_tx =1 ; - hw->use_inorder_rx =1 ; - hw->use_vec_rx =0 ; - } -if (vtpci_packed_queue (hw)) { +#if defined(RTE_ARCH_X86_64 ) && defined(CC_AVX512_SUPPORT ) +if ((hw->use_vec_rx || hw->use_vec_tx) && + (!rte_cpu_get_flag_enabled (RTE_CPUFLAG_AVX512F ) || + !vtpci_with_feature (hw,VIRTIO_F_IN_ORDER ) || + !vtpci_with_feature (hw,VIRTIO_F_VERSION_1 ))) { +PMD_DRV_LOG (INFO , +"disabled packed ring vectorized path for requirements not met" ); + hw->use_vec_rx =0 ; + hw->use_vec_tx =0 ; + } +#else hw->use_vec_rx =0 ; - hw->use_inorder_rx =0 ; - } + hw->use_vec_tx =0 ; +#endif + +if (hw->use_vec_rx) { +if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) { +PMD_DRV_LOG (INFO , +"disabled packed ring vectorized rx for mrg_rxbuf enabled" ); + hw->use_vec_rx =0 ; + } +if (rx_offloads &DEV_RX_OFFLOAD_TCP_LRO ) { +PMD_DRV_LOG (INFO , +"disabled packed ring vectorized rx for TCP_LRO enabled" ); + hw->use_vec_rx =0 ; + } + } + }else { +if (vtpci_with_feature (hw,VIRTIO_F_IN_ORDER )) { + hw->use_inorder_tx =1 ; + hw->use_inorder_rx =1 ; + hw->use_vec_rx =0 ; + } + +if (hw->use_vec_rx) {#if definedRTE_ARCH_ARM64 || definedRTE_ARCH_ARM -if (!rte_cpu_get_flag_enabled (RTE_CPUFLAG_NEON )) { - hw->use_vec_rx =0 ; - } +if (!rte_cpu_get_flag_enabled (RTE_CPUFLAG_NEON )) { +PMD_DRV_LOG (INFO , +"disabled split ring vectorized path for requirement not met" ); + hw->use_vec_rx =0 ; + }#endif -if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) { - hw->use_vec_rx =0 ; - } +if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) { +PMD_DRV_LOG (INFO , +"disabled split ring vectorized rx for mrg_rxbuf enabled" ); + hw->use_vec_rx =0 ; + } -if (rx_offloads & (DEV_RX_OFFLOAD_UDP_CKSUM | -DEV_RX_OFFLOAD_TCP_CKSUM | -DEV_RX_OFFLOAD_TCP_LRO | -DEV_RX_OFFLOAD_VLAN_STRIP )) - hw->use_vec_rx =0 ; +if (rx_offloads & (DEV_RX_OFFLOAD_UDP_CKSUM | +DEV_RX_OFFLOAD_TCP_CKSUM | +DEV_RX_OFFLOAD_TCP_LRO | +DEV_RX_OFFLOAD_VLAN_STRIP )) { +PMD_DRV_LOG (INFO , +"disabled split ring vectorized rx for offloading enabled" ); + hw->use_vec_rx =0 ; + } + } + }return 0 ; }
Signature · 1 line
2.17.1
PATCH v12 9/9 doc: add packed vectorized path
In reply to Marvin LiuDocument packed virtqueue vectorized path selection logic in virtio net PMD.
doc/guides/nics/virtio.rst +25 -14
@@ -482,6 +482,13 @@ according to below configuration: both negotiated, this path will be selected. #. Packed virtqueue in-order non-mergeable path: If in-order feature is negotiated and Rx mergeable is not negotiated, this path will be selected. +#. Packed virtqueue vectorized Rx path: If building and running environment support + AVX512 && in-order feature is negotiated && Rx mergeable is not negotiated && + TCP_LRO Rx offloading is disabled && vectorized option enabled, + this path will be selected. +#. Packed virtqueue vectorized Tx path: If building and running environment support + AVX512 && in-order feature is negotiated && vectorized option enabled, + this path will be selected. Rx/Tx callbacks of each Virtio path ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -504,6 +511,8 @@ are shown in below table: Packed virtqueue non-meregable path virtio_recv_pkts_packed virtio_xmit_pkts_packed Packed virtqueue in-order mergeable path virtio_recv_mergeable_pkts_packed virtio_xmit_pkts_packed Packed virtqueue in-order non-mergeable path virtio_recv_pkts_packed virtio_xmit_pkts_packed + Packed virtqueue vectorized Rx path virtio_recv_pkts_packed_vec virtio_xmit_pkts_packed + Packed virtqueue vectorized Tx path virtio_recv_pkts_packed virtio_xmit_pkts_packed_vec ============================================ ================================= ======================== Virtio paths Support Status from Release to Release
@@ -521,20 +530,22 @@ All virtio paths support status are shown in below table: .. table:: Virtio Paths and Releases - ============================================ ============= ============= ============= - Virtio paths 16.11 ~ 18.05 18.08 ~ 18.11 19.02 ~ 19.11 - ============================================ ============= ============= ============= - Split virtqueue mergeable path Y Y Y - Split virtqueue non-mergeable path Y Y Y - Split virtqueue vectorized Rx path Y Y Y - Split virtqueue simple Tx path Y N N - Split virtqueue in-order mergeable path Y Y - Split virtqueue in-order non-mergeable path Y Y - Packed virtqueue mergeable path Y - Packed virtqueue non-mergeable path Y - Packed virtqueue in-order mergeable path Y - Packed virtqueue in-order non-mergeable path Y - ============================================ ============= ============= ============= + ============================================ ============= ============= ============= ======= + Virtio paths 16.11 ~ 18.05 18.08 ~ 18.11 19.02 ~ 19.11 20.05 ~ + ============================================ ============= ============= ============= ======= + Split virtqueue mergeable path Y Y Y Y + Split virtqueue non-mergeable path Y Y Y Y + Split virtqueue vectorized Rx path Y Y Y Y + Split virtqueue simple Tx path Y N N N + Split virtqueue in-order mergeable path Y Y Y + Split virtqueue in-order non-mergeable path Y Y Y + Packed virtqueue mergeable path Y Y + Packed virtqueue non-mergeable path Y Y + Packed virtqueue in-order mergeable path Y Y + Packed virtqueue in-order non-mergeable path Y Y + Packed virtqueue vectorized Rx path Y + Packed virtqueue vectorized Tx path Y + ============================================ ============= ============= ============= ======= QEMU Support Status ~~~~~~~~~~~~~~~~~~~
Signature · 1 line
2.17.1
Maxime Coquelin
AppliedRe: [dpdk-dev] [PATCH v12 0/9] add packed ring vectorized path
In reply to Marvin LiuQuoted 88 lines · Marvin Liu
This patch set introduced vectorized path for packed ring.
The size of packed ring descriptor is 16Bytes. Four batched descriptors are just placed into one cacheline. AVX512 instructions can well handle this kind of data. Packed ring TX path can fully transformed into vectorized path. Packed ring Rx path can be vectorized when requirements met(LRO and mergeable disabled).
New device parameter "vectorized" will be introduced in this patch set. This parameter will be workable for both virtio device and virtio user vdev. It will also unify split and packed ring vectorized path default setting. Path election logic will check dependencies of vectorized path. Packed ring vectorized path is dependent on building/running environment and features like
IN_ORDERandVERSION_1enabled, MRG and LRO disabled. If vectorized path is not supported, will fallback to normal path.v12:
* eliminate weak symbols in data path
* remove desc extra padding which can impact normal path
* fix enqueue address invalidv11:
* fix i686 build warnings
* fix typo in docv10:
* reuse packed ring xmit cleanupv9:
* replaceRTE_LIBRTE_VIRTIO_INC_VECTORwith vectorized devarg
* reorder patch sequencev8:
* fix meson build error on ubuntu16.04 and suse15v7:
* default vectorization is disabled
* compilation time check dependency onrte_mbufstructure
* offsets are calcuated when compiling
* remove useless barrier as descs are batched store&load
* vindex of scatter is directly set
* some comments updates
* enable vectorized path in meson buildv6:
* fix issue when size not power of 2v5:
* remove cpuflags definition as required extensions always come with AVX512F onx86_64
* inorder actions should depend on feature bit
* check ring type in rx queue setup
* rewrite some commit logs
* fix some checkpatch warningsv4:
* rename 'packed_vec' to 'vectorized', also used in split ring
* addRTE_LIBRTE_VIRTIO_INC_VECTORconfig for virtio ethdev
* check required AVX512 extensions cpuflags
* combine split and packed ring datapath selection logic
* remove limitation that size must power of two
* clear 12Bytesvirtio_net_hdrv3:
* removevirtio_net_hdrarray for better performance
* disable 'packed_vec' by defaultv2:
* more function blocks replaced by vector instructions
* cleanvirtio_net_hdrby vector instruction
* allow header room size change
* add 'packed_vec' option invirtio_uservdev
* fix build not check whether AVX512 enabled
* doc updateTested-by Wang, Yinan <[email protected]>Marvin Liu (9):
net/virtio: add Rx free threshold setting net/virtio: inorder should depend on feature bit net/virtio: add vectorized devargnet/virtio-user: add vectorized devarg net/virtio: reuse packed ring functions net/virtio: add vectorized packed ring Rx path net/virtio: add vectorized packed ring Tx path net/virtio: add election for vectorized path
doc: add packed vectorized path
Quoted 14 lines
doc/guides/nics/virtio.rst | 52 +- drivers/net/virtio/Makefile | 35 ++ drivers/net/virtio/meson.build | 14 + drivers/net/virtio/virtio_ethdev.c | 142 ++++- drivers/net/virtio/virtio_ethdev.h | 6 + drivers/net/virtio/virtio_pci.h | 3 +- drivers/net/virtio/virtio_rxtx.c | 351 ++--------- drivers/net/virtio/virtio_rxtx_packed_avx.c | 607 ++++++++++++++++++++ drivers/net/virtio/virtio_user_ethdev.c | 32 +- drivers/net/virtio/virtqueue.c | 7 +- drivers/net/virtio/virtqueue.h | 304 ++++++++++ 11 files changed, 1199 insertions(+), 354 deletions(-) create mode 100644 drivers/net/virtio/virtio_rxtx_packed_avx.c
Applied to dpdk-next-virtio/master,
Thanks,
Maxime