Skip to contentSkip to conversation

enable AVX2 for IDPF single queue

PATCH Superseded Wenzhuo Lu 2 participants 7 messages Dec 7, 2023 – Jan 9, 2024

Subsystems (2)
lore
Share & tools
lore

Wenzhuo Lu

author
#0 lore raw

cover enable AVX2 for IDPF single queue

In case some CPUs don't support AVX512. Enable AVX2 for them to get better per-core performance.

Wenzhuo Lu (2):
common/idpf: enable AVX2 for single queue Rx
common/idpf: enable AVX2 for single queue Tx

 doc/guides/rel_notes/release_24_03.rst      |   3 +
 drivers/common/idpf/idpf_common_device.h    |   2 +
 drivers/common/idpf/idpf_common_rxtx.h      |   8 +
 drivers/common/idpf/idpf_common_rxtx_avx2.c | 834 ++++++++++++++++++++
 drivers/common/idpf/meson.build             |  16 +
 drivers/common/idpf/version.map             |   2 +
 drivers/net/idpf/idpf_rxtx.c                |  26 +
 7 files changed, 891 insertions(+)
 create mode 100644 drivers/common/idpf/idpf_common_rxtx_avx2.c
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH 1/2 common/idpf: enable AVX2 for single queue Rx

In case some CPUs don't support AVX512. Enable AVX2 for them to get better per-core performance.

---
 drivers/common/idpf/idpf_common_device.h    |   1 +
 drivers/common/idpf/idpf_common_rxtx.h      |   4 +
 drivers/common/idpf/idpf_common_rxtx_avx2.c | 609 ++++++++++++++++++++
 drivers/common/idpf/meson.build             |  16 +
 drivers/common/idpf/version.map             |   1 +
 drivers/net/idpf/idpf_rxtx.c                |  12 +
 6 files changed, 643 insertions(+)
 create mode 100644 drivers/common/idpf/idpf_common_rxtx_avx2.c
drivers/common/idpf/idpf_common_device.h +1 -0
index f767ea7cec..afe3d48798 100644
@@ -114,6 +114,7 @@ struct idpf_vport {
 
 	bool rx_vec_allowed;
 	bool tx_vec_allowed;
+	bool rx_use_avx2;
 	bool rx_use_avx512;
 	bool tx_use_avx512;
 
drivers/common/idpf/idpf_common_rxtx.h +4 -0
index b49b1ed737..4d64063718 100644
@@ -302,5 +302,9 @@ uint16_t idpf_dp_splitq_xmit_pkts_avx512(void *tx_queue, struct rte_mbuf **tx_pk
 __rte_internal
 uint16_t idpf_dp_singleq_recv_scatter_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
 			  uint16_t nb_pkts);
+__rte_internal
+uint16_t idpf_dp_singleq_recv_pkts_avx2(void *rx_queue,
+					struct rte_mbuf **rx_pkts,
+					uint16_t nb_pkts);
 
 #endif /* _IDPF_COMMON_RXTX_H_ */
drivers/common/idpf/idpf_common_rxtx_avx2.c new file +609 -0

609 lines not on this page · raw message

drivers/common/idpf/meson.build +16 -0
index 80c8906f80..6ab1c8175d 100644
@@ -16,6 +16,22 @@ sources = files(
 )
 
 if arch_subdir == 'x86'
+    # compile AVX2 version if either:
+    # a. we have AVX supported in minimum instruction set baseline
+    # b. it's not minimum instruction set, but supported by compiler
+    if cc.get_define('__AVX2__', args: machine_args) != ''
+        cflags += ['-DCC_AVX2_SUPPORT']
+        sources += files('idpf_common_rxtx_avx2.c')
+    elif cc.has_argument('-mavx2')
+        cflags += ['-DCC_AVX2_SUPPORT']
+        idpf_avx2_lib = static_library('idpf_avx2_lib',
+                'idpf_common_rxtx_avx2.c',
+                dependencies: [static_rte_ethdev, static_rte_kvargs, static_rte_hash],
+                include_directories: includes,
+                c_args: [cflags, '-mavx2'])
+        objs += idpf_avx2_lib.extract_objects('idpf_common_rxtx_avx2.c')
+    endif
+
     idpf_avx512_cpu_support = (
         cc.get_define('__AVX512F__', args: machine_args) != '' and
         cc.get_define('__AVX512BW__', args: machine_args) != '' and
drivers/common/idpf/version.map +1 -0
index 0729f6b912..4510aae6b3 100644
@@ -14,6 +14,7 @@ INTERNAL {
 	idpf_dp_splitq_recv_pkts_avx512;
 	idpf_dp_splitq_xmit_pkts;
 	idpf_dp_splitq_xmit_pkts_avx512;
+	idpf_dp_singleq_recv_pkts_avx2;
 
 	idpf_qc_rx_thresh_check;
 	idpf_qc_rx_queue_release;
drivers/net/idpf/idpf_rxtx.c +12 -0
index 64f2235580..b155c9ccd1 100644
@@ -772,6 +772,11 @@ idpf_set_rx_function(struct rte_eth_dev *dev)
 	    rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128) {
 		vport->rx_vec_allowed = true;
 
+		if ((rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2) == 1 ||
+		     rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512F) == 1) &&
+		    rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_256)
+			vport->rx_use_avx2 = true;
+
 		if (rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_512)
 #ifdef CC_AVX512_SUPPORT
 			if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512F) == 1 &&
@@ -823,6 +828,13 @@ idpf_set_rx_function(struct rte_eth_dev *dev)
 				return;
 			}
 #endif /* CC_AVX512_SUPPORT */
+			if (vport->rx_use_avx2) {
+				PMD_DRV_LOG(NOTICE,
+					    "Using Single AVX2 Vector Rx (port %d).",
+					    dev->data->port_id);
+				dev->rx_pkt_burst = idpf_dp_singleq_recv_pkts_avx2;
+				return;
+			}
 		}
 
 		if (dev->data->scattered_rx) {
Signature · 1 line
2.25.1
author
#2 lore raw

PATCH 2/2 common/idpf: enable AVX2 for single queue Tx

In reply to Wenzhuo Lu

In case some CPUs don't support AVX512. Enable AVX2 for them to get better per-core performance.

---
 doc/guides/rel_notes/release_24_03.rst      |   3 +
 drivers/common/idpf/idpf_common_device.h    |   1 +
 drivers/common/idpf/idpf_common_rxtx.h      |   4 +
 drivers/common/idpf/idpf_common_rxtx_avx2.c | 225 ++++++++++++++++++++
 drivers/common/idpf/version.map             |   1 +
 drivers/net/idpf/idpf_rxtx.c                |  14 ++
 6 files changed, 248 insertions(+)
doc/guides/rel_notes/release_24_03.rst +3 -0
index e9c9717706..08c8ee07c3 100644
@@ -55,6 +55,9 @@ New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+   * **Added support of vector instructions on IDPF.**
+
+     Added support of AVX2 instructions in IDPF single queue RX and TX path.
 
 Removed Items
 -------------
drivers/common/idpf/idpf_common_device.h +1 -0
index afe3d48798..60f8cab53a 100644
@@ -115,6 +115,7 @@ struct idpf_vport {
 	bool rx_vec_allowed;
 	bool tx_vec_allowed;
 	bool rx_use_avx2;
+	bool tx_use_avx2;
 	bool rx_use_avx512;
 	bool tx_use_avx512;
 
drivers/common/idpf/idpf_common_rxtx.h +4 -0
index 4d64063718..a92d328313 100644
@@ -306,5 +306,9 @@ __rte_internal
 uint16_t idpf_dp_singleq_recv_pkts_avx2(void *rx_queue,
 					struct rte_mbuf **rx_pkts,
 					uint16_t nb_pkts);
+__rte_internal
+uint16_t idpf_dp_singleq_xmit_pkts_avx2(void *tx_queue,
+					struct rte_mbuf **tx_pkts,
+					uint16_t nb_pkts);
 
 #endif /* _IDPF_COMMON_RXTX_H_ */
drivers/common/idpf/idpf_common_rxtx_avx2.c +225 -0

228 lines not on this page · raw message

drivers/common/idpf/version.map +1 -0
index 4510aae6b3..eadcb9a2cf 100644
@@ -15,6 +15,7 @@ INTERNAL {
 	idpf_dp_splitq_xmit_pkts;
 	idpf_dp_splitq_xmit_pkts_avx512;
 	idpf_dp_singleq_recv_pkts_avx2;
+	idpf_dp_singleq_xmit_pkts_avx2;
 
 	idpf_qc_rx_thresh_check;
 	idpf_qc_rx_queue_release;
drivers/net/idpf/idpf_rxtx.c +14 -0
index b155c9ccd1..45c791515d 100644
@@ -884,6 +884,12 @@ idpf_set_tx_function(struct rte_eth_dev *dev)
 	if (idpf_tx_vec_dev_check_default(dev) == IDPF_VECTOR_PATH &&
 	    rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128) {
 		vport->tx_vec_allowed = true;
+
+		if ((rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2) == 1 ||
+		     rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512F) == 1) &&
+		    rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_256)
+			vport->tx_use_avx2 = true;
+
 		if (rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_512)
 #ifdef CC_AVX512_SUPPORT
 		{
@@ -943,6 +949,14 @@ idpf_set_tx_function(struct rte_eth_dev *dev)
 				return;
 			}
 #endif /* CC_AVX512_SUPPORT */
+			if (vport->tx_use_avx2) {
+				PMD_DRV_LOG(NOTICE,
+					    "Using Single AVX2 Vector Tx (port %d).",
+					    dev->data->port_id);
+				dev->tx_pkt_burst = idpf_dp_singleq_xmit_pkts_avx2;
+				dev->tx_pkt_prepare = idpf_dp_prep_pkts;
+				return;
+			}
 		}
 		PMD_DRV_LOG(NOTICE,
 			    "Using Single Scalar Tx (port %d).",
Signature · 1 line
2.25.1
Tested-by on v1 2/2
#3 lore raw

RE: [PATCH 2/2] common/idpf: enable AVX2 for single queue Tx

Quoted 7 lines

-----Original Message-----
From: Wenzhuo Lu <[email protected]>
Sent: Thursday, December 7, 2023 2:35 PM
To: [email protected]
Cc: Lu, Wenzhuo <[email protected]>
Subject: [PATCH 2/2] common/idpf: enable AVX2 for single queue Tx

Quoted 5 lines

In case some CPUs don't support AVX512. Enable AVX2 for them to get better per-core performance.

---

Verified idpf single queue + AVX2 in functional regression test, tested pass.

author
#4 lore raw

v2 cover enable AVX2 for IDPF single queue

In reply to Wenzhuo Lu

In case some CPUs don't support AVX512. Enable AVX2 for them to get better per-core performance.

---
v2:
- Removed unused code.

*** BLURB HERE ***

Wenzhuo Lu (2):
common/idpf: enable AVX2 for single queue Rx
common/idpf: enable AVX2 for single queue Tx

 doc/guides/rel_notes/release_24_03.rst      |   3 +
 drivers/common/idpf/idpf_common_device.h    |   2 +
 drivers/common/idpf/idpf_common_rxtx.h      |   8 +
 drivers/common/idpf/idpf_common_rxtx_avx2.c | 815 ++++++++++++++++++++
 drivers/common/idpf/meson.build             |  16 +
 drivers/common/idpf/version.map             |   2 +
 drivers/net/idpf/idpf_rxtx.c                |  26 +
 7 files changed, 872 insertions(+)
 create mode 100644 drivers/common/idpf/idpf_common_rxtx_avx2.c
Signature · 1 line
2.25.1
author
#5 lore raw

PATCH v2 1/2 common/idpf: enable AVX2 for single queue Rx

In case some CPUs don't support AVX512. Enable AVX2 for them to get better per-core performance.

---
 drivers/common/idpf/idpf_common_device.h    |   1 +
 drivers/common/idpf/idpf_common_rxtx.h      |   4 +
 drivers/common/idpf/idpf_common_rxtx_avx2.c | 590 ++++++++++++++++++++
 drivers/common/idpf/meson.build             |  16 +
 drivers/common/idpf/version.map             |   1 +
 drivers/net/idpf/idpf_rxtx.c                |  12 +
 6 files changed, 624 insertions(+)
 create mode 100644 drivers/common/idpf/idpf_common_rxtx_avx2.c
drivers/common/idpf/idpf_common_device.h +1 -0
index f767ea7cec..afe3d48798 100644
@@ -114,6 +114,7 @@ struct idpf_vport {
 
 	bool rx_vec_allowed;
 	bool tx_vec_allowed;
+	bool rx_use_avx2;
 	bool rx_use_avx512;
 	bool tx_use_avx512;
 
drivers/common/idpf/idpf_common_rxtx.h +4 -0
index b49b1ed737..4d64063718 100644
@@ -302,5 +302,9 @@ uint16_t idpf_dp_splitq_xmit_pkts_avx512(void *tx_queue, struct rte_mbuf **tx_pk
 __rte_internal
 uint16_t idpf_dp_singleq_recv_scatter_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
 			  uint16_t nb_pkts);
+__rte_internal
+uint16_t idpf_dp_singleq_recv_pkts_avx2(void *rx_queue,
+					struct rte_mbuf **rx_pkts,
+					uint16_t nb_pkts);
 
 #endif /* _IDPF_COMMON_RXTX_H_ */
drivers/common/idpf/idpf_common_rxtx_avx2.c new file +590 -0

590 lines not on this page · raw message

drivers/common/idpf/meson.build +16 -0
index 80c8906f80..6ab1c8175d 100644
@@ -16,6 +16,22 @@ sources = files(
 )
 
 if arch_subdir == 'x86'
+    # compile AVX2 version if either:
+    # a. we have AVX supported in minimum instruction set baseline
+    # b. it's not minimum instruction set, but supported by compiler
+    if cc.get_define('__AVX2__', args: machine_args) != ''
+        cflags += ['-DCC_AVX2_SUPPORT']
+        sources += files('idpf_common_rxtx_avx2.c')
+    elif cc.has_argument('-mavx2')
+        cflags += ['-DCC_AVX2_SUPPORT']
+        idpf_avx2_lib = static_library('idpf_avx2_lib',
+                'idpf_common_rxtx_avx2.c',
+                dependencies: [static_rte_ethdev, static_rte_kvargs, static_rte_hash],
+                include_directories: includes,
+                c_args: [cflags, '-mavx2'])
+        objs += idpf_avx2_lib.extract_objects('idpf_common_rxtx_avx2.c')
+    endif
+
     idpf_avx512_cpu_support = (
         cc.get_define('__AVX512F__', args: machine_args) != '' and
         cc.get_define('__AVX512BW__', args: machine_args) != '' and
drivers/common/idpf/version.map +1 -0
index 0729f6b912..4510aae6b3 100644
@@ -14,6 +14,7 @@ INTERNAL {
 	idpf_dp_splitq_recv_pkts_avx512;
 	idpf_dp_splitq_xmit_pkts;
 	idpf_dp_splitq_xmit_pkts_avx512;
+	idpf_dp_singleq_recv_pkts_avx2;
 
 	idpf_qc_rx_thresh_check;
 	idpf_qc_rx_queue_release;
drivers/net/idpf/idpf_rxtx.c +12 -0
index 64f2235580..b155c9ccd1 100644
@@ -772,6 +772,11 @@ idpf_set_rx_function(struct rte_eth_dev *dev)
 	    rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128) {
 		vport->rx_vec_allowed = true;
 
+		if ((rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2) == 1 ||
+		     rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512F) == 1) &&
+		    rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_256)
+			vport->rx_use_avx2 = true;
+
 		if (rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_512)
 #ifdef CC_AVX512_SUPPORT
 			if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512F) == 1 &&
@@ -823,6 +828,13 @@ idpf_set_rx_function(struct rte_eth_dev *dev)
 				return;
 			}
 #endif /* CC_AVX512_SUPPORT */
+			if (vport->rx_use_avx2) {
+				PMD_DRV_LOG(NOTICE,
+					    "Using Single AVX2 Vector Rx (port %d).",
+					    dev->data->port_id);
+				dev->rx_pkt_burst = idpf_dp_singleq_recv_pkts_avx2;
+				return;
+			}
 		}
 
 		if (dev->data->scattered_rx) {
Signature · 1 line
2.25.1
author
#6 lore raw

PATCH v2 2/2 common/idpf: enable AVX2 for single queue Tx

In reply to Wenzhuo Lu

In case some CPUs don't support AVX512. Enable AVX2 for them to get better per-core performance.

---
 doc/guides/rel_notes/release_24_03.rst      |   3 +
 drivers/common/idpf/idpf_common_device.h    |   1 +
 drivers/common/idpf/idpf_common_rxtx.h      |   4 +
 drivers/common/idpf/idpf_common_rxtx_avx2.c | 225 ++++++++++++++++++++
 drivers/common/idpf/version.map             |   1 +
 drivers/net/idpf/idpf_rxtx.c                |  14 ++
 6 files changed, 248 insertions(+)
doc/guides/rel_notes/release_24_03.rst +3 -0
index e9c9717706..08c8ee07c3 100644
@@ -55,6 +55,9 @@ New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+   * **Added support of vector instructions on IDPF.**
+
+     Added support of AVX2 instructions in IDPF single queue RX and TX path.
 
 Removed Items
 -------------
drivers/common/idpf/idpf_common_device.h +1 -0
index afe3d48798..60f8cab53a 100644
@@ -115,6 +115,7 @@ struct idpf_vport {
 	bool rx_vec_allowed;
 	bool tx_vec_allowed;
 	bool rx_use_avx2;
+	bool tx_use_avx2;
 	bool rx_use_avx512;
 	bool tx_use_avx512;
 
drivers/common/idpf/idpf_common_rxtx.h +4 -0
index 4d64063718..a92d328313 100644
@@ -306,5 +306,9 @@ __rte_internal
 uint16_t idpf_dp_singleq_recv_pkts_avx2(void *rx_queue,
 					struct rte_mbuf **rx_pkts,
 					uint16_t nb_pkts);
+__rte_internal
+uint16_t idpf_dp_singleq_xmit_pkts_avx2(void *tx_queue,
+					struct rte_mbuf **tx_pkts,
+					uint16_t nb_pkts);
 
 #endif /* _IDPF_COMMON_RXTX_H_ */
drivers/common/idpf/idpf_common_rxtx_avx2.c +225 -0

228 lines not on this page · raw message

drivers/common/idpf/version.map +1 -0
index 4510aae6b3..eadcb9a2cf 100644
@@ -15,6 +15,7 @@ INTERNAL {
 	idpf_dp_splitq_xmit_pkts;
 	idpf_dp_splitq_xmit_pkts_avx512;
 	idpf_dp_singleq_recv_pkts_avx2;
+	idpf_dp_singleq_xmit_pkts_avx2;
 
 	idpf_qc_rx_thresh_check;
 	idpf_qc_rx_queue_release;
drivers/net/idpf/idpf_rxtx.c +14 -0
index b155c9ccd1..45c791515d 100644
@@ -884,6 +884,12 @@ idpf_set_tx_function(struct rte_eth_dev *dev)
 	if (idpf_tx_vec_dev_check_default(dev) == IDPF_VECTOR_PATH &&
 	    rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128) {
 		vport->tx_vec_allowed = true;
+
+		if ((rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2) == 1 ||
+		     rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512F) == 1) &&
+		    rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_256)
+			vport->tx_use_avx2 = true;
+
 		if (rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_512)
 #ifdef CC_AVX512_SUPPORT
 		{
@@ -943,6 +949,14 @@ idpf_set_tx_function(struct rte_eth_dev *dev)
 				return;
 			}
 #endif /* CC_AVX512_SUPPORT */
+			if (vport->tx_use_avx2) {
+				PMD_DRV_LOG(NOTICE,
+					    "Using Single AVX2 Vector Tx (port %d).",
+					    dev->data->port_id);
+				dev->tx_pkt_burst = idpf_dp_singleq_xmit_pkts_avx2;
+				dev->tx_pkt_prepare = idpf_dp_prep_pkts;
+				return;
+			}
 		}
 		PMD_DRV_LOG(NOTICE,
 			    "Using Single Scalar Tx (port %d).",
Signature · 1 line
2.25.1