Skip to contentSkip to conversation

Introduce AF_XDP PMD

PATCH Superseded Xiaolong Ye 17 participants 214 messages Mar 1, 2019 – Apr 25, 2019 Page 2 of 2

Subsystems (2)
lore
Share & tools
lore
#108 lore raw

PATCH v5 1/5 net/af_xdp: introduce AF XDP PMD driver

In reply to Xiaolong Ye

Add a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux. More info about AF_XDP, please refer to [1] [2].

This is the vanilla version PMD which just uses a raw buffer registered as the umem.

[1] https://fosdem.org/2018/schedule/event/af_xdp/
[2] https://lwn.net/Articles/745934/

---
 MAINTAINERS                                   |   6 +
 config/common_base                            |   5 +
 doc/guides/nics/af_xdp.rst                    |  45 +
 doc/guides/nics/features/af_xdp.ini           |  11 +
 doc/guides/nics/index.rst                     |   1 +
 doc/guides/rel_notes/release_19_05.rst        |   7 +
 drivers/net/Makefile                          |   1 +
 drivers/net/af_xdp/Makefile                   |  32 +
 drivers/net/af_xdp/meson.build                |  21 +
 drivers/net/af_xdp/rte_eth_af_xdp.c           | 931 ++++++++++++++++++
 drivers/net/af_xdp/rte_pmd_af_xdp_version.map |   3 +
 drivers/net/meson.build                       |   1 +
 mk/rte.app.mk                                 |   1 +
 13 files changed, 1065 insertions(+)
 create mode 100644 doc/guides/nics/af_xdp.rst
 create mode 100644 doc/guides/nics/features/af_xdp.ini
 create mode 100644 drivers/net/af_xdp/Makefile
 create mode 100644 drivers/net/af_xdp/meson.build
 create mode 100644 drivers/net/af_xdp/rte_eth_af_xdp.c
 create mode 100644 drivers/net/af_xdp/rte_pmd_af_xdp_version.map
MAINTAINERS +6 -0
index 452b8eb82..1cc54b439 100644
@@ -468,6 +468,12 @@ M: John W. Linville <[email protected]>
 F: drivers/net/af_packet/
 F: doc/guides/nics/features/afpacket.ini
 
+Linux AF_XDP
+M: Xiaolong Ye <[email protected]>
+M: Qi Zhang <[email protected]>
+F: drivers/net/af_xdp/
+F: doc/guides/nics/features/af_xdp.rst
+
 Amazon ENA
 M: Marcin Wojtas <[email protected]>
 M: Michal Krawczyk <[email protected]>
config/common_base +5 -0
index 0b09a9348..4044de205 100644
@@ -416,6 +416,11 @@ CONFIG_RTE_LIBRTE_VMXNET3_DEBUG_TX_FREE=n
 #
 CONFIG_RTE_LIBRTE_PMD_AF_PACKET=n
 
+#
+# Compile software PMD backed by AF_XDP sockets (Linux only)
+#
+CONFIG_RTE_LIBRTE_PMD_AF_XDP=n
+
 #
 # Compile link bonding PMD library
 #
doc/guides/nics/af_xdp.rst new file +45 -0

45 lines not on this page · raw message

doc/guides/nics/features/af_xdp.ini new file +11 -0
new file mode 100644
index 000000000..36953c2de
@@ -0,0 +1,11 @@
+;
+; Supported features of the 'af_xdp' network poll mode driver.
+;
+; Refer to default.ini for the full list of available PMD features.
+;
+[Features]
+Link status          = Y
+MTU update           = Y
+Promiscuous mode     = Y
+Stats per queue      = Y
+x86-64               = Y
doc/guides/nics/index.rst +1 -0
index 5c80e3baa..a4b80a3d0 100644
@@ -12,6 +12,7 @@ Network Interface Controller Drivers
     features
     build_and_test
     af_packet
+    af_xdp
     ark
     atlantic
     avp
doc/guides/rel_notes/release_19_05.rst +7 -0
index 61a2c7383..062facf89 100644
@@ -65,6 +65,13 @@ New Features
     process.
   * Added support for Rx packet types list in a secondary process.
 
+* **Added the AF_XDP PMD.**
+
+  Added a Linux-specific PMD driver for AF_XDP, it can create the AF_XDP socket
+  and bind it to a specific netdev queue, it allows a DPDK application to send
+  and receive raw packets through the socket which would bypass the kernel
+  network stack to achieve high performance packet processing.
+
 * **Updated Mellanox drivers.**
 
    New features and improvements were done in mlx4 and mlx5 PMDs:
drivers/net/Makefile +1 -0
index 502869a87..5d401b8c5 100644
@@ -9,6 +9,7 @@ ifeq ($(CONFIG_RTE_LIBRTE_THUNDERX_NICVF_PMD),d)
 endif
 
 DIRS-$(CONFIG_RTE_LIBRTE_PMD_AF_PACKET) += af_packet
+DIRS-$(CONFIG_RTE_LIBRTE_PMD_AF_XDP) += af_xdp
 DIRS-$(CONFIG_RTE_LIBRTE_ARK_PMD) += ark
 DIRS-$(CONFIG_RTE_LIBRTE_ATLANTIC_PMD) += atlantic
 DIRS-$(CONFIG_RTE_LIBRTE_AVP_PMD) += avp
drivers/net/af_xdp/Makefile new file +32 -0
new file mode 100644
index 000000000..db7d9aa57
@@ -0,0 +1,32 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2018 Intel Corporation
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+#
+# library name
+#
+LIB = librte_pmd_af_xdp.a
+
+EXPORT_MAP := rte_pmd_af_xdp_version.map
+
+LIBABIVER := 1
+
+CFLAGS += -O3
+
+# require kernel version >= v5.1-rc1
+CFLAGS += -I$(RTE_KERNELDIR)/tools/include
+CFLAGS += -I$(RTE_KERNELDIR)/tools/lib/bpf
+
+CFLAGS += $(WERROR_FLAGS)
+LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring
+LDLIBS += -lrte_ethdev -lrte_net -lrte_kvargs
+LDLIBS += -lrte_bus_vdev
+LDLIBS += -lbpf
+
+#
+# all source are stored in SRCS-y
+#
+SRCS-$(CONFIG_RTE_LIBRTE_PMD_AF_XDP) += rte_eth_af_xdp.c
+
+include $(RTE_SDK)/mk/rte.lib.mk
drivers/net/af_xdp/meson.build new file +21 -0
new file mode 100644
index 000000000..7e51169b4
@@ -0,0 +1,21 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2018 Intel Corporation
+
+if host_machine.system() != 'linux'
+	build = false
+endif
+
+bpf_dep = dependency('libbpf', required: false)
+if bpf_dep.found()
+	build = true
+else
+	bpf_dep = cc.find_library('libbpf', required: false)
+	if bpf_dep.found() and cc.has_header('xsk.h', dependencies: bpf_dep) and cc.has_header('linux/if_xdp.h')
+		build = true
+		pkgconfig_extra_libs += '-lbpf'
+	else
+		build = false
+	endif
+endif
+sources = files('rte_eth_af_xdp.c')
+ext_deps += bpf_dep
drivers/net/af_xdp/rte_eth_af_xdp.c new file +931 -0

931 lines not on this page · raw message

drivers/net/af_xdp/rte_pmd_af_xdp_version.map new file +3 -0
new file mode 100644
index 000000000..c6db030fe
@@ -0,0 +1,3 @@
+DPDK_19.05 {
+	local: *;
+};
drivers/net/meson.build +1 -0
index 3ecc78cee..1105e72d8 100644
@@ -2,6 +2,7 @@
 # Copyright(c) 2017 Intel Corporation
 
 drivers = ['af_packet',
+	'af_xdp',
 	'ark',
 	'atlantic',
 	'avp',
mk/rte.app.mk +1 -0
index 262132fc6..be0af73cc 100644
@@ -143,6 +143,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_DPAA2_MEMPOOL)  += -lrte_mempool_dpaa2
 endif
 
 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AF_PACKET)  += -lrte_pmd_af_packet
+_LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AF_XDP)     += -lrte_pmd_af_xdp -lelf -lbpf
 _LDLIBS-$(CONFIG_RTE_LIBRTE_ARK_PMD)        += -lrte_pmd_ark
 _LDLIBS-$(CONFIG_RTE_LIBRTE_ATLANTIC_PMD)   += -lrte_pmd_atlantic
 _LDLIBS-$(CONFIG_RTE_LIBRTE_AVP_PMD)        += -lrte_pmd_avp
Signature · 1 line
2.17.1
#109 lore raw

Re: [PATCH v5 1/5] net/af_xdp: introduce AF XDP PMD driver

drivers/net/af_xdp/rte_eth_af_xdp.c line 135

Quoted 4 lines · On Mon, 25 Mar 2019 14:03:56 +0800 Xiaolong Ye <[email protected]> wrote:
drivers/net/af_xdp/rte_eth_af_xdp.c new file +4 -0
+
+	ret = xsk_ring_prod__reserve(fq, reserve_size, &idx);
+	if (unlikely(!ret)) {
+		AF_XDP_LOG(ERR, "Failed to reserve enough fq descs.\n");

You defined AF_XDP_LOG to add a newline (similar to other drivers). But all the messages already have a newline.
This will cause log to be double spaced.

#110 lore raw

Re: [PATCH v5 1/5] net/af_xdp: introduce AF XDP PMD driver

Quoted 11 lines · Stephen Hemminger

drivers/net/af_xdp/rte_eth_af_xdp.c line 135

Quoted 4 lines · On Mon, 25 Mar 2019 14:03:56 +0800 Xiaolong Ye <[email protected]> wrote:
drivers/net/af_xdp/rte_eth_af_xdp.c new file +4 -0
+
+	ret = xsk_ring_prod__reserve(fq, reserve_size, &idx);
+	if (unlikely(!ret)) {
+		AF_XDP_LOG(ERR, "Failed to reserve enough fq descs.\n");

You defined AF_XDP_LOG to add a newline (similar to other drivers). But all the messages already have a newline.
This will cause log to be double spaced.

Thanks for the catch, I'll remove the newline in the definition.

#111 lore raw

PATCH v5 2/5 lib/mbuf: introduce helper to create mempool with flags

In reply to Xiaolong Ye

This allows applications to create mbuf mempool with specific flags such as MEMPOOL_F_NO_SPREAD if they want fixed size memory objects.

---
 lib/librte_mbuf/rte_mbuf.c           | 29 ++++++++++++++----
 lib/librte_mbuf/rte_mbuf.h           | 45 ++++++++++++++++++++++++++++
 lib/librte_mbuf/rte_mbuf_version.map |  1 +
 3 files changed, 70 insertions(+), 5 deletions(-)
lib/librte_mbuf/rte_mbuf.c +24 -5
index 21f6f7404..c1db9e298 100644
@@ -106,11 +106,10 @@ rte_pktmbuf_init(struct rte_mempool *mp,
 	m->next = NULL;
 }
 
-/* Helper to create a mbuf pool with given mempool ops name*/
-struct rte_mempool *
-rte_pktmbuf_pool_create_by_ops(const char *name, unsigned int n,
+static struct rte_mempool *
+rte_pktmbuf_pool_create_by_ops_with_flags(const char *name, unsigned int n,
 	unsigned int cache_size, uint16_t priv_size, uint16_t data_room_size,
-	int socket_id, const char *ops_name)
+	unsigned int flags, int socket_id, const char *ops_name)
 {
 	struct rte_mempool *mp;
 	struct rte_pktmbuf_pool_private mbp_priv;
@@ -130,7 +129,7 @@ rte_pktmbuf_pool_create_by_ops(const char *name, unsigned int n,
 	mbp_priv.mbuf_priv_size = priv_size;
 
 	mp = rte_mempool_create_empty(name, n, elt_size, cache_size,
-		 sizeof(struct rte_pktmbuf_pool_private), socket_id, 0);
+		 sizeof(struct rte_pktmbuf_pool_private), socket_id, flags);
 	if (mp == NULL)
 		return NULL;
 
@@ -157,6 +156,16 @@ rte_pktmbuf_pool_create_by_ops(const char *name, unsigned int n,
 	return mp;
 }
 
+/* Helper to create a mbuf pool with given mempool ops name*/
+struct rte_mempool *
+rte_pktmbuf_pool_create_by_ops(const char *name, unsigned int n,
+	unsigned int cache_size, uint16_t priv_size, uint16_t data_room_size,
+	int socket_id, const char *ops_name)
+{
+	return rte_pktmbuf_pool_create_by_ops_with_flags(name, n, cache_size,
+			 priv_size, data_room_size, 0, socket_id, ops_name);
+}
+
 /* helper to create a mbuf pool */
 struct rte_mempool *
 rte_pktmbuf_pool_create(const char *name, unsigned int n,
@@ -167,6 +176,16 @@ rte_pktmbuf_pool_create(const char *name, unsigned int n,
 			data_room_size, socket_id, NULL);
 }
 
+/* helper to create a mbuf pool with flags (e.g. NO_SPREAD) */
+struct rte_mempool * __rte_experimental
+rte_pktmbuf_pool_create_with_flags(const char *name, unsigned int n,
+	unsigned int cache_size, uint16_t priv_size, uint16_t data_room_size,
+	unsigned int flags, int socket_id)
+{
+	return rte_pktmbuf_pool_create_by_ops_with_flags(name, n, cache_size,
+			priv_size, data_room_size, flags, socket_id, NULL);
+}
+
 /* do some sanity checks on a mbuf: panic if it fails */
 void
 rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header)
lib/librte_mbuf/rte_mbuf.h +45 -0

51 lines not on this page · raw message

lib/librte_mbuf/rte_mbuf_version.map +1 -0
index 2662a37bf..2579538e0 100644
@@ -50,4 +50,5 @@ EXPERIMENTAL {
 	global:
 
 	rte_mbuf_check;
+	rte_pktmbuf_pool_create_with_flags;
 } DPDK_18.08;
Signature · 1 line
2.17.1
#112 lore raw

PATCH v5 3/5 lib/mempool: allow page size aligned mempool

In reply to Xiaolong Ye

Allow create a mempool with page size aligned base address.

---
 lib/librte_mempool/rte_mempool.c | 3 +++
 lib/librte_mempool/rte_mempool.h | 1 +
 2 files changed, 4 insertions(+)
lib/librte_mempool/rte_mempool.c +3 -0
index 683b216f9..171ba1057 100644
@@ -543,6 +543,9 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 		if (try_contig)
 			flags |= RTE_MEMZONE_IOVA_CONTIG;
 
+		if (mp->flags & MEMPOOL_F_PAGE_ALIGN)
+			align = RTE_MAX(align, (size_t)getpagesize());
+
 		mz = rte_memzone_reserve_aligned(mz_name, mem_size,
 				mp->socket_id, flags, align);
 
lib/librte_mempool/rte_mempool.h +1 -0
index 7c9cd9a2f..75553b36f 100644
@@ -264,6 +264,7 @@ struct rte_mempool {
 #define MEMPOOL_F_POOL_CREATED   0x0010 /**< Internal: pool is created. */
 #define MEMPOOL_F_NO_IOVA_CONTIG 0x0020 /**< Don't need IOVA contiguous objs. */
 #define MEMPOOL_F_NO_PHYS_CONTIG MEMPOOL_F_NO_IOVA_CONTIG /* deprecated */
+#define MEMPOOL_F_PAGE_ALIGN     0x0040 /**< Chunk's base address is page aligned */
 
 /**
  * @internal When debug is enabled, store some statistics.
Signature · 1 line
2.17.1
#113 lore raw

Re: [PATCH v5 3/5] lib/mempool: allow page size aligned mempool

Quoted 28 lines · Xiaolong Ye

Allow create a mempool with page size aligned base address.

---
  lib/librte_mempool/rte_mempool.c | 3 +++
  lib/librte_mempool/rte_mempool.h | 1 +
  2 files changed, 4 insertions(+)
lib/librte_mempool/rte_mempool.c +3 -0
index 683b216f9..171ba1057 100644
@@ -543,6 +543,9 @@ rte_mempool_populate_default(struct rte_mempool *mp)
  		if (try_contig)
  			flags |= RTE_MEMZONE_IOVA_CONTIG;
 
+		if (mp->flags & MEMPOOL_F_PAGE_ALIGN)
+			align = RTE_MAX(align, (size_t)getpagesize());
+
  		mz = rte_memzone_reserve_aligned(mz_name, mem_size,
  				mp->socket_id, flags, align);
 
lib/librte_mempool/rte_mempool.h +0 -0
index 7c9cd9a2f..75553b36f 100644

lib/librte_mempool/rte_mempool.h struct rte_mempool { · line 267

Quoted 4 lines
lib/librte_mempool/rte_mempool.h +1 -0
@@ -264,6 +264,7 @@ struct rte_mempool {
  #define MEMPOOL_F_POOL_CREATED   0x0010 /**< Internal: pool is created. */
  #define MEMPOOL_F_NO_IOVA_CONTIG 0x0020 /**< Don't need IOVA contiguous objs. */
  #define MEMPOOL_F_NO_PHYS_CONTIG MEMPOOL_F_NO_IOVA_CONTIG /* deprecated */
+#define MEMPOOL_F_PAGE_ALIGN     0x0040 /**< Chunk's base address is page aligned */

For me it sounds like mempool objects should be page aligned since MEMPOOL_F_NO_SPREAD, MEMPOOL_F_NO_CACHE_ALIGN and MEMPOOL_F_NO_IOVA_CONTIG say about object properties, not chunk.

Personally I doubt that the final goal is just having chunk page aligned.

Andrew.

#114 lore raw

Re: [PATCH v5 3/5] lib/mempool: allow page size aligned mempool

Quoted 36 lines · Andrew Rybchenko
Quoted 26 lines · Xiaolong Ye

Allow create a mempool with page size aligned base address.

---
  lib/librte_mempool/rte_mempool.c | 3 +++
  lib/librte_mempool/rte_mempool.h | 1 +
  2 files changed, 4 insertions(+)
lib/librte_mempool/rte_mempool.c +3 -0
index 683b216f9..171ba1057 100644
@@ -543,6 +543,9 @@ rte_mempool_populate_default(struct rte_mempool *mp)
  		if (try_contig)
  			flags |= RTE_MEMZONE_IOVA_CONTIG;
+		if (mp->flags & MEMPOOL_F_PAGE_ALIGN)
+			align = RTE_MAX(align, (size_t)getpagesize());
+
  		mz = rte_memzone_reserve_aligned(mz_name, mem_size,
  				mp->socket_id, flags, align);
lib/librte_mempool/rte_mempool.h +0 -0
index 7c9cd9a2f..75553b36f 100644

lib/librte_mempool/rte_mempool.h struct rte_mempool { · line 267

Quoted 4 lines
lib/librte_mempool/rte_mempool.h +1 -0
@@ -264,6 +264,7 @@ struct rte_mempool {
  #define MEMPOOL_F_POOL_CREATED   0x0010 /**< Internal: pool is created. */
  #define MEMPOOL_F_NO_IOVA_CONTIG 0x0020 /**< Don't need IOVA contiguous objs. */
  #define MEMPOOL_F_NO_PHYS_CONTIG MEMPOOL_F_NO_IOVA_CONTIG /* deprecated */
+#define MEMPOOL_F_PAGE_ALIGN     0x0040 /**< Chunk's base address is page aligned */

For me it sounds like mempool objects should be page aligned since MEMPOOL_F_NO_SPREAD, MEMPOOL_F_NO_CACHE_ALIGN and MEMPOOL_F_NO_IOVA_CONTIG say about object properties, not chunk.

Quoted 1 line

Personally I doubt that the final goal is just having chunk page aligned.

Hmm, how about naming it MEMPOOL_CHUNK_F_PAGE_ALIGN?

Thanks,
Xiaolong

Quoted 2 lines

Andrew.

#115 lore raw

PATCH v5 4/5 net/af_xdp: use mbuf mempool for buffer management

In reply to Xiaolong Ye

Now, af_xdp registered memory buffer is managed by rte_mempool. mbuf allocated from rte_mempool can be converted to xdp_desc's address and vice versa.

---
 drivers/net/af_xdp/rte_eth_af_xdp.c | 117 +++++++++++++++++-----------
 1 file changed, 72 insertions(+), 45 deletions(-)
drivers/net/af_xdp/rte_eth_af_xdp.c +72 -45
index 9f6ecace6..9a8e0f994 100644
@@ -48,7 +48,11 @@ static int af_xdp_logtype;
 
 #define ETH_AF_XDP_FRAME_SIZE		XSK_UMEM__DEFAULT_FRAME_SIZE
 #define ETH_AF_XDP_NUM_BUFFERS		4096
-#define ETH_AF_XDP_DATA_HEADROOM	0
+/* mempool hdrobj size (64 bytes) + sizeof(struct rte_mbuf) (128 bytes) */
+#define ETH_AF_XDP_MBUF_OVERHEAD	192
+/* data start from offset 320 (192 + 128) bytes */
+#define ETH_AF_XDP_DATA_HEADROOM				\
+	(ETH_AF_XDP_MBUF_OVERHEAD + RTE_PKTMBUF_HEADROOM)
 #define ETH_AF_XDP_DFLT_NUM_DESCS	XSK_RING_CONS__DEFAULT_NUM_DESCS
 #define ETH_AF_XDP_DFLT_QUEUE_IDX	0
 
@@ -61,7 +65,7 @@ struct xsk_umem_info {
 	struct xsk_ring_prod fq;
 	struct xsk_ring_cons cq;
 	struct xsk_umem *umem;
-	struct rte_ring *buf_ring;
+	struct rte_mempool *mb_pool;
 	void *buffer;
 };
 
@@ -123,10 +127,30 @@ static struct rte_eth_link pmd_link = {
 	.link_autoneg = ETH_LINK_AUTONEG
 };
 
+static inline struct rte_mbuf *
+addr_to_mbuf(struct xsk_umem_info *umem, uint64_t addr)
+{
+	uint64_t offset = (addr / ETH_AF_XDP_FRAME_SIZE *
+			ETH_AF_XDP_FRAME_SIZE);
+	struct rte_mbuf *mbuf = (struct rte_mbuf *)((uint64_t)umem->buffer +
+				    offset + ETH_AF_XDP_MBUF_OVERHEAD -
+				    sizeof(struct rte_mbuf));
+	mbuf->data_off = addr - offset - ETH_AF_XDP_MBUF_OVERHEAD;
+	return mbuf;
+}
+
+static inline uint64_t
+mbuf_to_addr(struct xsk_umem_info *umem, struct rte_mbuf *mbuf)
+{
+	return (uint64_t)mbuf->buf_addr + mbuf->data_off -
+		(uint64_t)umem->buffer;
+}
+
 static inline int
 reserve_fill_queue(struct xsk_umem_info *umem, int reserve_size)
 {
 	struct xsk_ring_prod *fq = &umem->fq;
+	struct rte_mbuf *mbuf;
 	uint32_t idx;
 	int i, ret;
 
@@ -138,13 +162,15 @@ reserve_fill_queue(struct xsk_umem_info *umem, int reserve_size)
 
 	for (i = 0; i < reserve_size; i++) {
 		__u64 *fq_addr;
-		void *addr = NULL;
-		if (rte_ring_dequeue(umem->buf_ring, &addr)) {
+		uint64_t addr;
+		mbuf = rte_pktmbuf_alloc(umem->mb_pool);
+		if (unlikely(mbuf == NULL)) {
 			i--;
 			break;
 		}
+		addr = mbuf_to_addr(umem, mbuf);
 		fq_addr = xsk_ring_prod__fill_addr(fq, idx++);
-		*fq_addr = (uint64_t)addr;
+		*fq_addr = addr;
 	}
 
 	xsk_ring_prod__submit(fq, i);
@@ -196,7 +222,7 @@ eth_af_xdp_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		rx_bytes += len;
 		bufs[count++] = mbufs[i];
 
-		rte_ring_enqueue(umem->buf_ring, (void *)addr);
+		rte_pktmbuf_free(addr_to_mbuf(umem, addr));
 	}
 
 	xsk_ring_cons__release(rx, rcvd);
@@ -219,7 +245,7 @@ static void pull_umem_cq(struct xsk_umem_info *umem, int size)
 	for (i = 0; i < n; i++) {
 		uint64_t addr;
 		addr = *xsk_ring_cons__comp_addr(cq, idx_cq++);
-		rte_ring_enqueue(umem->buf_ring, (void *)addr);
+		rte_pktmbuf_free(addr_to_mbuf(umem, addr));
 	}
 
 	xsk_ring_cons__release(cq, n);
@@ -248,7 +274,7 @@ eth_af_xdp_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	struct pkt_tx_queue *txq = queue;
 	struct xsk_umem_info *umem = txq->pair->umem;
 	struct rte_mbuf *mbuf;
-	void *addrs[ETH_AF_XDP_TX_BATCH_SIZE];
+	struct rte_mbuf *mbuf_to_tx;
 	unsigned long tx_bytes = 0;
 	int i, valid = 0;
 	uint32_t idx_tx;
@@ -257,11 +283,6 @@ eth_af_xdp_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 
 	pull_umem_cq(umem, nb_pkts);
 
-	nb_pkts = rte_ring_dequeue_bulk(umem->buf_ring, addrs,
-					nb_pkts, NULL);
-	if (nb_pkts == 0)
-		return 0;
-
 	if (xsk_ring_prod__reserve(&txq->tx, nb_pkts, &idx_tx) != nb_pkts) {
 		kick_tx(txq);
 		return 0;
@@ -275,7 +296,12 @@ eth_af_xdp_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		desc = xsk_ring_prod__tx_desc(&txq->tx, idx_tx + i);
 		mbuf = bufs[i];
 		if (mbuf->pkt_len <= buf_len) {
-			desc->addr = (uint64_t)addrs[valid];
+			mbuf_to_tx = rte_pktmbuf_alloc(umem->mb_pool);
+			if (unlikely(mbuf_to_tx == NULL)) {
+				rte_pktmbuf_free(mbuf);
+				continue;
+			}
+			desc->addr = mbuf_to_addr(umem, mbuf_to_tx);
 			desc->len = mbuf->pkt_len;
 			pkt = xsk_umem__get_data(umem->buffer,
 						 desc->addr);
@@ -291,10 +317,6 @@ eth_af_xdp_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 
 	kick_tx(txq);
 
-	if (valid < nb_pkts)
-		rte_ring_enqueue_bulk(umem->buf_ring, &addrs[valid],
-				 nb_pkts - valid, NULL);
-
 	txq->stats.err_pkts += nb_pkts - valid;
 	txq->stats.tx_pkts += valid;
 	txq->stats.tx_bytes += tx_bytes;
@@ -443,16 +465,29 @@ eth_link_update(struct rte_eth_dev *dev __rte_unused,
 
 static void xdp_umem_destroy(struct xsk_umem_info *umem)
 {
-	free(umem->buffer);
-	umem->buffer = NULL;
-
-	rte_ring_free(umem->buf_ring);
-	umem->buf_ring = NULL;
+	rte_mempool_free(umem->mb_pool);
+	umem->mb_pool = NULL;
 
 	rte_free(umem);
 	umem = NULL;
 }
 
+static inline uint64_t get_base_addr(struct rte_mempool *mp)
+{
+	struct rte_mempool_memhdr *memhdr;
+
+	memhdr = STAILQ_FIRST(&mp->mem_list);
+	return (uint64_t)(memhdr->addr);
+}
+
+static inline uint64_t get_len(struct rte_mempool *mp)
+{
+	struct rte_mempool_memhdr *memhdr;
+
+	memhdr = STAILQ_FIRST(&mp->mem_list);
+	return (uint64_t)(memhdr->len);
+}
+
 static struct xsk_umem_info *xdp_umem_configure(void)
 {
 	struct xsk_umem_info *umem;
@@ -461,9 +496,8 @@ static struct xsk_umem_info *xdp_umem_configure(void)
 		.comp_size = ETH_AF_XDP_DFLT_NUM_DESCS,
 		.frame_size = ETH_AF_XDP_FRAME_SIZE,
 		.frame_headroom = ETH_AF_XDP_DATA_HEADROOM };
-	void *bufs = NULL;
+	void *base_addr = NULL;
 	int ret;
-	uint64_t i;
 
 	umem = rte_zmalloc_socket("umem", sizeof(*umem), 0, rte_socket_id());
 	if (umem == NULL) {
@@ -471,26 +505,20 @@ static struct xsk_umem_info *xdp_umem_configure(void)
 		return NULL;
 	}
 
-	umem->buf_ring = rte_ring_create("af_xdp_ring",
-					 ETH_AF_XDP_NUM_BUFFERS,
-					 SOCKET_ID_ANY,
-					 0x0);
-	if (umem->buf_ring == NULL) {
-		AF_XDP_LOG(ERR, "Failed to create rte_ring\n");
+	umem->mb_pool = rte_pktmbuf_pool_create_with_flags("af_xdp_mempool",
+			ETH_AF_XDP_NUM_BUFFERS,
+			250, 0,
+			ETH_AF_XDP_FRAME_SIZE -
+			ETH_AF_XDP_MBUF_OVERHEAD,
+			MEMPOOL_F_NO_SPREAD | MEMPOOL_F_PAGE_ALIGN,
+			SOCKET_ID_ANY);
+	if (umem->mb_pool == NULL || umem->mb_pool->nb_mem_chunks != 1) {
+		AF_XDP_LOG(ERR, "Failed to create mempool\n");
 		goto err;
 	}
+	base_addr = (void *)get_base_addr(umem->mb_pool);
 
-	for (i = 0; i < ETH_AF_XDP_NUM_BUFFERS; i++)
-		rte_ring_enqueue(umem->buf_ring,
-				 (void *)(i * ETH_AF_XDP_FRAME_SIZE +
-					  ETH_AF_XDP_DATA_HEADROOM));
-
-	if (posix_memalign(&bufs, getpagesize(),
-			   ETH_AF_XDP_NUM_BUFFERS * ETH_AF_XDP_FRAME_SIZE)) {
-		AF_XDP_LOG(ERR, "Failed to allocate memory pool.\n");
-		goto err;
-	}
-	ret = xsk_umem__create(&umem->umem, bufs,
+	ret = xsk_umem__create(&umem->umem, base_addr,
 			       ETH_AF_XDP_NUM_BUFFERS * ETH_AF_XDP_FRAME_SIZE,
 			       &umem->fq, &umem->cq,
 			       &usr_config);
@@ -499,7 +527,7 @@ static struct xsk_umem_info *xdp_umem_configure(void)
 		AF_XDP_LOG(ERR, "Failed to create umem");
 		goto err;
 	}
-	umem->buffer = bufs;
+	umem->buffer = base_addr;
 
 	return umem;
 
@@ -903,10 +931,9 @@ rte_pmd_af_xdp_remove(struct rte_vdev_device *dev)
 
 	internals = eth_dev->data->dev_private;
 
-	rte_ring_free(internals->umem->buf_ring);
-	rte_free(internals->umem->buffer);
 	rte_free(internals->umem);
 
+	rte_mempool_free(internals->umem->mb_pool);
 	rte_eth_dev_release_port(eth_dev);
 
 
Signature · 1 line
2.17.1
#116 lore raw

PATCH v5 5/5 net/af_xdp: enable zero copy

In reply to Xiaolong Ye

Try to check if external mempool (from rx_queue_setup) is fit for af_xdp, if it is, it will be registered to af_xdp socket directly and there will be no packet data copy on Rx and Tx.

---
 drivers/net/af_xdp/rte_eth_af_xdp.c | 130 ++++++++++++++++++++--------
 1 file changed, 96 insertions(+), 34 deletions(-)
drivers/net/af_xdp/rte_eth_af_xdp.c +96 -34
index 9a8e0f994..e5e839d85 100644
@@ -67,6 +67,7 @@ struct xsk_umem_info {
 	struct xsk_umem *umem;
 	struct rte_mempool *mb_pool;
 	void *buffer;
+	uint8_t zc;
 };
 
 struct rx_stats {
@@ -85,6 +86,7 @@ struct pkt_rx_queue {
 
 	struct pkt_tx_queue *pair;
 	uint16_t queue_idx;
+	uint8_t zc;
 };
 
 struct tx_stats {
@@ -202,7 +204,9 @@ eth_af_xdp_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	if (xsk_prod_nb_free(fq, free_thresh) >= free_thresh)
 		(void)reserve_fill_queue(umem, ETH_AF_XDP_RX_BATCH_SIZE);
 
-	if (unlikely(rte_pktmbuf_alloc_bulk(rxq->mb_pool, mbufs, rcvd) != 0))
+	if (!rxq->zc &&
+		unlikely(rte_pktmbuf_alloc_bulk(rxq->mb_pool,
+				mbufs, rcvd) != 0))
 		return 0;
 
 	for (i = 0; i < rcvd; i++) {
@@ -216,13 +220,23 @@ eth_af_xdp_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		len = desc->len;
 		pkt = xsk_umem__get_data(rxq->umem->buffer, addr);
 
-		rte_memcpy(rte_pktmbuf_mtod(mbufs[i], void *), pkt, len);
-		rte_pktmbuf_pkt_len(mbufs[i]) = len;
-		rte_pktmbuf_data_len(mbufs[i]) = len;
-		rx_bytes += len;
-		bufs[count++] = mbufs[i];
-
-		rte_pktmbuf_free(addr_to_mbuf(umem, addr));
+		if (rxq->zc) {
+			struct rte_mbuf *mbuf;
+			mbuf = addr_to_mbuf(rxq->umem, addr);
+			rte_pktmbuf_pkt_len(mbuf) = len;
+			rte_pktmbuf_data_len(mbuf) = len;
+			rx_bytes += len;
+			bufs[count++] = mbuf;
+		} else {
+			rte_memcpy(rte_pktmbuf_mtod(mbufs[i], void *),
+					pkt, len);
+			rte_pktmbuf_pkt_len(mbufs[i]) = len;
+			rte_pktmbuf_data_len(mbufs[i]) = len;
+			rx_bytes += len;
+			bufs[count++] = mbufs[i];
+
+			rte_pktmbuf_free(addr_to_mbuf(umem, addr));
+		}
 	}
 
 	xsk_ring_cons__release(rx, rcvd);
@@ -295,22 +309,29 @@ eth_af_xdp_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 					- ETH_AF_XDP_DATA_HEADROOM;
 		desc = xsk_ring_prod__tx_desc(&txq->tx, idx_tx + i);
 		mbuf = bufs[i];
-		if (mbuf->pkt_len <= buf_len) {
-			mbuf_to_tx = rte_pktmbuf_alloc(umem->mb_pool);
-			if (unlikely(mbuf_to_tx == NULL)) {
-				rte_pktmbuf_free(mbuf);
-				continue;
-			}
-			desc->addr = mbuf_to_addr(umem, mbuf_to_tx);
+		if (txq->pair->zc && mbuf->pool == umem->mb_pool) {
+			desc->addr = mbuf_to_addr(umem, mbuf);
 			desc->len = mbuf->pkt_len;
-			pkt = xsk_umem__get_data(umem->buffer,
-						 desc->addr);
-			rte_memcpy(pkt, rte_pktmbuf_mtod(mbuf, void *),
-			       desc->len);
 			valid++;
 			tx_bytes += mbuf->pkt_len;
+		} else {
+			if (mbuf->pkt_len <= buf_len) {
+				mbuf_to_tx = rte_pktmbuf_alloc(umem->mb_pool);
+				if (unlikely(mbuf_to_tx == NULL)) {
+					rte_pktmbuf_free(mbuf);
+					continue;
+				}
+				desc->addr = mbuf_to_addr(umem, mbuf_to_tx);
+				desc->len = mbuf->pkt_len;
+				pkt = xsk_umem__get_data(umem->buffer,
+							 desc->addr);
+				memcpy(pkt, rte_pktmbuf_mtod(mbuf, void *),
+				       desc->len);
+				valid++;
+				tx_bytes += mbuf->pkt_len;
+			}
+			rte_pktmbuf_free(mbuf);
 		}
-		rte_pktmbuf_free(mbuf);
 	}
 
 	xsk_ring_prod__submit(&txq->tx, nb_pkts);
@@ -488,7 +509,7 @@ static inline uint64_t get_len(struct rte_mempool *mp)
 	return (uint64_t)(memhdr->len);
 }
 
-static struct xsk_umem_info *xdp_umem_configure(void)
+static struct xsk_umem_info *xdp_umem_configure(struct rte_mempool *mb_pool)
 {
 	struct xsk_umem_info *umem;
 	struct xsk_umem_config usr_config = {
@@ -505,16 +526,23 @@ static struct xsk_umem_info *xdp_umem_configure(void)
 		return NULL;
 	}
 
-	umem->mb_pool = rte_pktmbuf_pool_create_with_flags("af_xdp_mempool",
-			ETH_AF_XDP_NUM_BUFFERS,
-			250, 0,
-			ETH_AF_XDP_FRAME_SIZE -
-			ETH_AF_XDP_MBUF_OVERHEAD,
-			MEMPOOL_F_NO_SPREAD | MEMPOOL_F_PAGE_ALIGN,
-			SOCKET_ID_ANY);
-	if (umem->mb_pool == NULL || umem->mb_pool->nb_mem_chunks != 1) {
-		AF_XDP_LOG(ERR, "Failed to create mempool\n");
-		goto err;
+	if (!mb_pool) {
+		umem->mb_pool = rte_pktmbuf_pool_create_with_flags("af_xdp_mempool",
+				ETH_AF_XDP_NUM_BUFFERS,
+				250, 0,
+				ETH_AF_XDP_FRAME_SIZE -
+				ETH_AF_XDP_MBUF_OVERHEAD,
+				MEMPOOL_F_NO_SPREAD | MEMPOOL_F_PAGE_ALIGN,
+				SOCKET_ID_ANY);
+
+		if (umem->mb_pool == NULL ||
+				umem->mb_pool->nb_mem_chunks != 1) {
+			AF_XDP_LOG(ERR, "Failed to create mempool\n");
+			goto err;
+		}
+	} else {
+		umem->mb_pool = mb_pool;
+		umem->zc = 1;
 	}
 	base_addr = (void *)get_base_addr(umem->mb_pool);
 
@@ -536,16 +564,43 @@ static struct xsk_umem_info *xdp_umem_configure(void)
 	return NULL;
 }
 
+static uint8_t
+check_mempool_zc(struct rte_mempool *mp)
+{
+	RTE_ASSERT(mp);
+
+	/* must continues */
+	if (mp->nb_mem_chunks > 1)
+		return 0;
+
+	/* check header size */
+	if (mp->header_size != RTE_CACHE_LINE_SIZE)
+		return 0;
+
+	/* check base address */
+	if ((uint64_t)get_base_addr(mp) % getpagesize() != 0)
+		return 0;
+
+	/* check chunk size */
+	if ((mp->elt_size + mp->header_size + mp->trailer_size) %
+	    ETH_AF_XDP_FRAME_SIZE != 0)
+		return 0;
+
+	return 1;
+}
+
 static int
 xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
-	      int ring_size)
+	      int ring_size, struct rte_mempool *mb_pool)
 {
 	struct xsk_socket_config cfg;
 	struct pkt_tx_queue *txq = rxq->pair;
+	struct rte_mempool *mp;
 	int ret = 0;
 	int reserve_size;
 
-	rxq->umem = xdp_umem_configure();
+	mp = check_mempool_zc(mb_pool) ? mb_pool : NULL;
+	rxq->umem = xdp_umem_configure(mp);
 	if (rxq->umem == NULL)
 		return -ENOMEM;
 
@@ -622,7 +677,7 @@ eth_rx_queue_setup(struct rte_eth_dev *dev,
 
 	rxq->mb_pool = mb_pool;
 
-	if (xsk_configure(internals, rxq, nb_rx_desc)) {
+	if (xsk_configure(internals, rxq, nb_rx_desc, mb_pool)) {
 		AF_XDP_LOG(ERR, "Failed to configure xdp socket\n");
 		ret = -EINVAL;
 		goto err;
@@ -630,6 +685,13 @@ eth_rx_queue_setup(struct rte_eth_dev *dev,
 
 	internals->umem = rxq->umem;
 
+	if (mb_pool == internals->umem->mb_pool)
+		rxq->zc = internals->umem->zc;
+
+	if (rxq->zc)
+		AF_XDP_LOG(INFO,
+			"zero copy enabled on rx queue %d\n", rx_queue_id);
+
 	dev->data->rx_queues[rx_queue_id] = rxq;
 	return 0;
 
Signature · 1 line
2.17.1
#117 lore raw

v6 cover Introduce AF_XDP PMD

In reply to Xiaolong Ye

Overview
========

This patchset adds a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux, see below links [1] [2] for details of AF_XDP introduction:

AF_XDP roadmap
==============
- AF_XDP is included in upstream kernel since 4.18, and AF_XDP support in libbpf has been merged in v5.1-rc1.
- Now i40e and ixgbe drivers have supported zero copy mode.

Change logs
===========

V6:

- remove the newline in AF_XDP_LOG definition to avoid double new lines issue.
- rename MEMPOOL_F_PAGE_ALIGN to MEMPOOL_CHUNK_F_PAGE_ALIGN.

V5:

- disable AF_XDP pmd by default due to it requires kernel more recent than minimum kernel version supported by DPDK
- address other review comments of Maxime

V4:

- change vdev name to net_af_xdp
- adopt dynamic log type for all logging
- Fix other style issues raised by Stephen

V3:

- Fix all style issues pointed by Stephen, Mattias, David.
- Drop the testpmd change as we'll adopt Jerin's suggestion to add a new mempool driver to handle the application use of AF_XDP's zero copy feature.

V2:
- Fix a NULL pointer reference crash issue
- Fix txonly stop sending traffic in zc mode
- Refactor rte_mbuf.c to avoid ABI breakage.
- Fix multiple style issues pointed by Ferruh, David, Stephen, Luca.

changes vs RFC sent by Qi last Aug:

- Re-work base on AF_XDP's interface changes since the new libbpf has provided higher-level APIs that hide many of the details of the AP_XDP uapi. After the rework, it helps to reduce 300+ lines of code.

- multi-queues is not supported due to current libbpf doesn't support multi-sockets on a single umem.

- No extra steps to load xdp program manually, since the current behavior of libbpf would load a default xdp program when user calls xsk_socket__create. userspace application only needs to handle the cleanup.

How to try
==========

1. take the kernel >= v5.1-rc1, build kernel and replace your host kernel with it.

make sure you turn on XDP sockets when compiling

Networking support -->
Networking options -->
[ * ] XDP sockets

2. build libbpf in tools/lib/bpf, and copy the libbpf.a and libbpf.so to /usr/lib64

cd tools/lib/bpf
make

3. ethtool -L enp59s0f0 combined 1

4. extra step to build dpdk

explicitly enable AF_XDP pmd by adding below line to config/common_linux

CONFIG_RTE_LIBRTE_PMD_AF_XDP=y

5. start testpmd

   ./build/app/testpmd -c 0xc -n 4 --vdev net_af_xdp,iface=enp59s0f0,queue=0 -- -i --rxq=1 --txq=1

in this case, default xdp program will be loaded and linked to queue 0 of enp59s0f0, network traffics travel to queue 0 will be redirected to af_xdp socket.

Xiaolong Ye (5):
net/af_xdp: introduce AF XDP PMD driver lib/mbuf: introduce helper to create mempool with flags lib/mempool: allow page size aligned mempool net/af_xdp: use mbuf mempool for buffer management net/af_xdp: enable zero copy

 MAINTAINERS                                   |    6 +
 config/common_base                            |    5 +
 doc/guides/nics/af_xdp.rst                    |   45 +
 doc/guides/nics/features/af_xdp.ini           |   11 +
 doc/guides/nics/index.rst                     |    1 +
 doc/guides/rel_notes/release_19_05.rst        |    7 +
 drivers/net/Makefile                          |    1 +
 drivers/net/af_xdp/Makefile                   |   32 +
 drivers/net/af_xdp/meson.build                |   21 +
 drivers/net/af_xdp/rte_eth_af_xdp.c           | 1020 +++++++++++++++++
 drivers/net/af_xdp/rte_pmd_af_xdp_version.map |    3 +
 drivers/net/meson.build                       |    1 +
 lib/librte_mbuf/rte_mbuf.c                    |   29 +-
 lib/librte_mbuf/rte_mbuf.h                    |   45 +
 lib/librte_mbuf/rte_mbuf_version.map          |    1 +
 lib/librte_mempool/rte_mempool.c              |    3 +
 lib/librte_mempool/rte_mempool.h              |    1 +
 mk/rte.app.mk                                 |    1 +
 18 files changed, 1228 insertions(+), 5 deletions(-)
 create mode 100644 doc/guides/nics/af_xdp.rst
 create mode 100644 doc/guides/nics/features/af_xdp.ini
 create mode 100644 drivers/net/af_xdp/Makefile
 create mode 100644 drivers/net/af_xdp/meson.build
 create mode 100644 drivers/net/af_xdp/rte_eth_af_xdp.c
 create mode 100644 drivers/net/af_xdp/rte_pmd_af_xdp_version.map
Signature · 1 line
2.17.1
#118 lore raw

PATCH v6 1/5 net/af_xdp: introduce AF XDP PMD driver

Add a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux. More info about AF_XDP, please refer to [1] [2].

This is the vanilla version PMD which just uses a raw buffer registered as the umem.

[1] https://fosdem.org/2018/schedule/event/af_xdp/
[2] https://lwn.net/Articles/745934/

---
 MAINTAINERS                                   |   6 +
 config/common_base                            |   5 +
 doc/guides/nics/af_xdp.rst                    |  45 +
 doc/guides/nics/features/af_xdp.ini           |  11 +
 doc/guides/nics/index.rst                     |   1 +
 doc/guides/rel_notes/release_19_05.rst        |   7 +
 drivers/net/Makefile                          |   1 +
 drivers/net/af_xdp/Makefile                   |  32 +
 drivers/net/af_xdp/meson.build                |  21 +
 drivers/net/af_xdp/rte_eth_af_xdp.c           | 931 ++++++++++++++++++
 drivers/net/af_xdp/rte_pmd_af_xdp_version.map |   3 +
 drivers/net/meson.build                       |   1 +
 mk/rte.app.mk                                 |   1 +
 13 files changed, 1065 insertions(+)
 create mode 100644 doc/guides/nics/af_xdp.rst
 create mode 100644 doc/guides/nics/features/af_xdp.ini
 create mode 100644 drivers/net/af_xdp/Makefile
 create mode 100644 drivers/net/af_xdp/meson.build
 create mode 100644 drivers/net/af_xdp/rte_eth_af_xdp.c
 create mode 100644 drivers/net/af_xdp/rte_pmd_af_xdp_version.map
MAINTAINERS +6 -0
index 452b8eb82..1cc54b439 100644
@@ -468,6 +468,12 @@ M: John W. Linville <[email protected]>
 F: drivers/net/af_packet/
 F: doc/guides/nics/features/afpacket.ini
 
+Linux AF_XDP
+M: Xiaolong Ye <[email protected]>
+M: Qi Zhang <[email protected]>
+F: drivers/net/af_xdp/
+F: doc/guides/nics/features/af_xdp.rst
+
 Amazon ENA
 M: Marcin Wojtas <[email protected]>
 M: Michal Krawczyk <[email protected]>
config/common_base +5 -0
index 0b09a9348..4044de205 100644
@@ -416,6 +416,11 @@ CONFIG_RTE_LIBRTE_VMXNET3_DEBUG_TX_FREE=n
 #
 CONFIG_RTE_LIBRTE_PMD_AF_PACKET=n
 
+#
+# Compile software PMD backed by AF_XDP sockets (Linux only)
+#
+CONFIG_RTE_LIBRTE_PMD_AF_XDP=n
+
 #
 # Compile link bonding PMD library
 #
doc/guides/nics/af_xdp.rst new file +45 -0

45 lines not on this page · raw message

doc/guides/nics/features/af_xdp.ini new file +11 -0
new file mode 100644
index 000000000..36953c2de
@@ -0,0 +1,11 @@
+;
+; Supported features of the 'af_xdp' network poll mode driver.
+;
+; Refer to default.ini for the full list of available PMD features.
+;
+[Features]
+Link status          = Y
+MTU update           = Y
+Promiscuous mode     = Y
+Stats per queue      = Y
+x86-64               = Y
doc/guides/nics/index.rst +1 -0
index 5c80e3baa..a4b80a3d0 100644
@@ -12,6 +12,7 @@ Network Interface Controller Drivers
     features
     build_and_test
     af_packet
+    af_xdp
     ark
     atlantic
     avp
doc/guides/rel_notes/release_19_05.rst +7 -0
index 6f76de3ff..14317cf16 100644
@@ -65,6 +65,13 @@ New Features
     process.
   * Added support for Rx packet types list in a secondary process.
 
+* **Added the AF_XDP PMD.**
+
+  Added a Linux-specific PMD driver for AF_XDP, it can create the AF_XDP socket
+  and bind it to a specific netdev queue, it allows a DPDK application to send
+  and receive raw packets through the socket which would bypass the kernel
+  network stack to achieve high performance packet processing.
+
 * **Updated Mellanox drivers.**
 
    New features and improvements were done in mlx4 and mlx5 PMDs:
drivers/net/Makefile +1 -0
index 502869a87..5d401b8c5 100644
@@ -9,6 +9,7 @@ ifeq ($(CONFIG_RTE_LIBRTE_THUNDERX_NICVF_PMD),d)
 endif
 
 DIRS-$(CONFIG_RTE_LIBRTE_PMD_AF_PACKET) += af_packet
+DIRS-$(CONFIG_RTE_LIBRTE_PMD_AF_XDP) += af_xdp
 DIRS-$(CONFIG_RTE_LIBRTE_ARK_PMD) += ark
 DIRS-$(CONFIG_RTE_LIBRTE_ATLANTIC_PMD) += atlantic
 DIRS-$(CONFIG_RTE_LIBRTE_AVP_PMD) += avp
drivers/net/af_xdp/Makefile new file +32 -0
new file mode 100644
index 000000000..db7d9aa57
@@ -0,0 +1,32 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2018 Intel Corporation
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+#
+# library name
+#
+LIB = librte_pmd_af_xdp.a
+
+EXPORT_MAP := rte_pmd_af_xdp_version.map
+
+LIBABIVER := 1
+
+CFLAGS += -O3
+
+# require kernel version >= v5.1-rc1
+CFLAGS += -I$(RTE_KERNELDIR)/tools/include
+CFLAGS += -I$(RTE_KERNELDIR)/tools/lib/bpf
+
+CFLAGS += $(WERROR_FLAGS)
+LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring
+LDLIBS += -lrte_ethdev -lrte_net -lrte_kvargs
+LDLIBS += -lrte_bus_vdev
+LDLIBS += -lbpf
+
+#
+# all source are stored in SRCS-y
+#
+SRCS-$(CONFIG_RTE_LIBRTE_PMD_AF_XDP) += rte_eth_af_xdp.c
+
+include $(RTE_SDK)/mk/rte.lib.mk
drivers/net/af_xdp/meson.build new file +21 -0
new file mode 100644
index 000000000..7e51169b4
@@ -0,0 +1,21 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2018 Intel Corporation
+
+if host_machine.system() != 'linux'
+	build = false
+endif
+
+bpf_dep = dependency('libbpf', required: false)
+if bpf_dep.found()
+	build = true
+else
+	bpf_dep = cc.find_library('libbpf', required: false)
+	if bpf_dep.found() and cc.has_header('xsk.h', dependencies: bpf_dep) and cc.has_header('linux/if_xdp.h')
+		build = true
+		pkgconfig_extra_libs += '-lbpf'
+	else
+		build = false
+	endif
+endif
+sources = files('rte_eth_af_xdp.c')
+ext_deps += bpf_dep
drivers/net/af_xdp/rte_eth_af_xdp.c new file +931 -0

931 lines not on this page · raw message

drivers/net/af_xdp/rte_pmd_af_xdp_version.map new file +3 -0
new file mode 100644
index 000000000..c6db030fe
@@ -0,0 +1,3 @@
+DPDK_19.05 {
+	local: *;
+};
drivers/net/meson.build +1 -0
index 3ecc78cee..1105e72d8 100644
@@ -2,6 +2,7 @@
 # Copyright(c) 2017 Intel Corporation
 
 drivers = ['af_packet',
+	'af_xdp',
 	'ark',
 	'atlantic',
 	'avp',
mk/rte.app.mk +1 -0
index 262132fc6..be0af73cc 100644
@@ -143,6 +143,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_DPAA2_MEMPOOL)  += -lrte_mempool_dpaa2
 endif
 
 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AF_PACKET)  += -lrte_pmd_af_packet
+_LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AF_XDP)     += -lrte_pmd_af_xdp -lelf -lbpf
 _LDLIBS-$(CONFIG_RTE_LIBRTE_ARK_PMD)        += -lrte_pmd_ark
 _LDLIBS-$(CONFIG_RTE_LIBRTE_ATLANTIC_PMD)   += -lrte_pmd_atlantic
 _LDLIBS-$(CONFIG_RTE_LIBRTE_AVP_PMD)        += -lrte_pmd_avp
Signature · 1 line
2.17.1
#119 lore raw

Re: [PATCH v6 1/5] net/af_xdp: introduce AF XDP PMD driver

doc/guides/nics/af_xdp.rst line 20

Quoted 6 lines · On Tue, 26 Mar 2019 20:20:25 +0800 Xiaolong Ye <[email protected]> wrote:
doc/guides/nics/af_xdp.rst new file +6 -0
+This Linux-specific PMD driver creates the AF_XDP socket and binds it to a
+specific netdev queue, it allows a DPDK application to send and receive raw
+packets through the socket which would bypass the kernel network stack.
+Current implementation only supports single queue, multi-queues feature will
+be added later.
+

It might be worth mentioning that MTU in XDP is limited because the kernel doesn't allow XDP with segmented packets.

#120 lore raw

Re: [PATCH v6 1/5] net/af_xdp: introduce AF XDP PMD driver

Quoted 12 lines · Stephen Hemminger

doc/guides/nics/af_xdp.rst line 20

Quoted 6 lines · On Tue, 26 Mar 2019 20:20:25 +0800 Xiaolong Ye <[email protected]> wrote:
doc/guides/nics/af_xdp.rst new file +6 -0
+This Linux-specific PMD driver creates the AF_XDP socket and binds it to a
+specific netdev queue, it allows a DPDK application to send and receive raw
+packets through the socket which would bypass the kernel network stack.
+Current implementation only supports single queue, multi-queues feature will
+be added later.
+

It might be worth mentioning that MTU in XDP is limited because the kernel doesn't allow XDP with segmented packets.

Ok, will add it in next version.

Thanks,
Xiaolong

#121 lore raw

PATCH v6 2/5 lib/mbuf: introduce helper to create mempool with flags

In reply to Xiaolong Ye

This allows applications to create mbuf mempool with specific flags such as MEMPOOL_F_NO_SPREAD if they want fixed size memory objects.

---
 lib/librte_mbuf/rte_mbuf.c           | 29 ++++++++++++++----
 lib/librte_mbuf/rte_mbuf.h           | 45 ++++++++++++++++++++++++++++
 lib/librte_mbuf/rte_mbuf_version.map |  1 +
 3 files changed, 70 insertions(+), 5 deletions(-)
lib/librte_mbuf/rte_mbuf.c +24 -5
index 21f6f7404..c1db9e298 100644
@@ -106,11 +106,10 @@ rte_pktmbuf_init(struct rte_mempool *mp,
 	m->next = NULL;
 }
 
-/* Helper to create a mbuf pool with given mempool ops name*/
-struct rte_mempool *
-rte_pktmbuf_pool_create_by_ops(const char *name, unsigned int n,
+static struct rte_mempool *
+rte_pktmbuf_pool_create_by_ops_with_flags(const char *name, unsigned int n,
 	unsigned int cache_size, uint16_t priv_size, uint16_t data_room_size,
-	int socket_id, const char *ops_name)
+	unsigned int flags, int socket_id, const char *ops_name)
 {
 	struct rte_mempool *mp;
 	struct rte_pktmbuf_pool_private mbp_priv;
@@ -130,7 +129,7 @@ rte_pktmbuf_pool_create_by_ops(const char *name, unsigned int n,
 	mbp_priv.mbuf_priv_size = priv_size;
 
 	mp = rte_mempool_create_empty(name, n, elt_size, cache_size,
-		 sizeof(struct rte_pktmbuf_pool_private), socket_id, 0);
+		 sizeof(struct rte_pktmbuf_pool_private), socket_id, flags);
 	if (mp == NULL)
 		return NULL;
 
@@ -157,6 +156,16 @@ rte_pktmbuf_pool_create_by_ops(const char *name, unsigned int n,
 	return mp;
 }
 
+/* Helper to create a mbuf pool with given mempool ops name*/
+struct rte_mempool *
+rte_pktmbuf_pool_create_by_ops(const char *name, unsigned int n,
+	unsigned int cache_size, uint16_t priv_size, uint16_t data_room_size,
+	int socket_id, const char *ops_name)
+{
+	return rte_pktmbuf_pool_create_by_ops_with_flags(name, n, cache_size,
+			 priv_size, data_room_size, 0, socket_id, ops_name);
+}
+
 /* helper to create a mbuf pool */
 struct rte_mempool *
 rte_pktmbuf_pool_create(const char *name, unsigned int n,
@@ -167,6 +176,16 @@ rte_pktmbuf_pool_create(const char *name, unsigned int n,
 			data_room_size, socket_id, NULL);
 }
 
+/* helper to create a mbuf pool with flags (e.g. NO_SPREAD) */
+struct rte_mempool * __rte_experimental
+rte_pktmbuf_pool_create_with_flags(const char *name, unsigned int n,
+	unsigned int cache_size, uint16_t priv_size, uint16_t data_room_size,
+	unsigned int flags, int socket_id)
+{
+	return rte_pktmbuf_pool_create_by_ops_with_flags(name, n, cache_size,
+			priv_size, data_room_size, flags, socket_id, NULL);
+}
+
 /* do some sanity checks on a mbuf: panic if it fails */
 void
 rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header)
lib/librte_mbuf/rte_mbuf.h +45 -0

51 lines not on this page · raw message

lib/librte_mbuf/rte_mbuf_version.map +1 -0
index 2662a37bf..2579538e0 100644
@@ -50,4 +50,5 @@ EXPERIMENTAL {
 	global:
 
 	rte_mbuf_check;
+	rte_pktmbuf_pool_create_with_flags;
 } DPDK_18.08;
Signature · 1 line
2.17.1
#122 lore raw

PATCH v6 3/5 lib/mempool: allow page size aligned mempool

In reply to Xiaolong Ye

Allow create a mempool with page size aligned base address.

---
 lib/librte_mempool/rte_mempool.c | 3 +++
 lib/librte_mempool/rte_mempool.h | 1 +
 2 files changed, 4 insertions(+)
lib/librte_mempool/rte_mempool.c +3 -0
index 683b216f9..cfbb49ea5 100644
@@ -543,6 +543,9 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 		if (try_contig)
 			flags |= RTE_MEMZONE_IOVA_CONTIG;
 
+		if (mp->flags & MEMPOOL_CHUNK_F_PAGE_ALIGN)
+			align = RTE_MAX(align, (size_t)getpagesize());
+
 		mz = rte_memzone_reserve_aligned(mz_name, mem_size,
 				mp->socket_id, flags, align);
 
lib/librte_mempool/rte_mempool.h +1 -0
index 7c9cd9a2f..47729f7c9 100644
@@ -264,6 +264,7 @@ struct rte_mempool {
 #define MEMPOOL_F_POOL_CREATED   0x0010 /**< Internal: pool is created. */
 #define MEMPOOL_F_NO_IOVA_CONTIG 0x0020 /**< Don't need IOVA contiguous objs. */
 #define MEMPOOL_F_NO_PHYS_CONTIG MEMPOOL_F_NO_IOVA_CONTIG /* deprecated */
+#define MEMPOOL_CHUNK_F_PAGE_ALIGN     0x0040 /**< Chunk's base address is page aligned */
 
 /**
  * @internal When debug is enabled, store some statistics.
Signature · 1 line
2.17.1
#123 lore raw

PATCH v6 4/5 net/af_xdp: use mbuf mempool for buffer management

In reply to Xiaolong Ye

Now, af_xdp registered memory buffer is managed by rte_mempool. mbuf allocated from rte_mempool can be converted to xdp_desc's address and vice versa.

---
 drivers/net/af_xdp/rte_eth_af_xdp.c | 117 +++++++++++++++++-----------
 1 file changed, 72 insertions(+), 45 deletions(-)
drivers/net/af_xdp/rte_eth_af_xdp.c +72 -45
index 47a496ed7..a1fda9212 100644
@@ -48,7 +48,11 @@ static int af_xdp_logtype;
 
 #define ETH_AF_XDP_FRAME_SIZE		XSK_UMEM__DEFAULT_FRAME_SIZE
 #define ETH_AF_XDP_NUM_BUFFERS		4096
-#define ETH_AF_XDP_DATA_HEADROOM	0
+/* mempool hdrobj size (64 bytes) + sizeof(struct rte_mbuf) (128 bytes) */
+#define ETH_AF_XDP_MBUF_OVERHEAD	192
+/* data start from offset 320 (192 + 128) bytes */
+#define ETH_AF_XDP_DATA_HEADROOM				\
+	(ETH_AF_XDP_MBUF_OVERHEAD + RTE_PKTMBUF_HEADROOM)
 #define ETH_AF_XDP_DFLT_NUM_DESCS	XSK_RING_CONS__DEFAULT_NUM_DESCS
 #define ETH_AF_XDP_DFLT_QUEUE_IDX	0
 
@@ -61,7 +65,7 @@ struct xsk_umem_info {
 	struct xsk_ring_prod fq;
 	struct xsk_ring_cons cq;
 	struct xsk_umem *umem;
-	struct rte_ring *buf_ring;
+	struct rte_mempool *mb_pool;
 	void *buffer;
 };
 
@@ -123,10 +127,30 @@ static struct rte_eth_link pmd_link = {
 	.link_autoneg = ETH_LINK_AUTONEG
 };
 
+static inline struct rte_mbuf *
+addr_to_mbuf(struct xsk_umem_info *umem, uint64_t addr)
+{
+	uint64_t offset = (addr / ETH_AF_XDP_FRAME_SIZE *
+			ETH_AF_XDP_FRAME_SIZE);
+	struct rte_mbuf *mbuf = (struct rte_mbuf *)((uint64_t)umem->buffer +
+				    offset + ETH_AF_XDP_MBUF_OVERHEAD -
+				    sizeof(struct rte_mbuf));
+	mbuf->data_off = addr - offset - ETH_AF_XDP_MBUF_OVERHEAD;
+	return mbuf;
+}
+
+static inline uint64_t
+mbuf_to_addr(struct xsk_umem_info *umem, struct rte_mbuf *mbuf)
+{
+	return (uint64_t)mbuf->buf_addr + mbuf->data_off -
+		(uint64_t)umem->buffer;
+}
+
 static inline int
 reserve_fill_queue(struct xsk_umem_info *umem, int reserve_size)
 {
 	struct xsk_ring_prod *fq = &umem->fq;
+	struct rte_mbuf *mbuf;
 	uint32_t idx;
 	int i, ret;
 
@@ -138,13 +162,15 @@ reserve_fill_queue(struct xsk_umem_info *umem, int reserve_size)
 
 	for (i = 0; i < reserve_size; i++) {
 		__u64 *fq_addr;
-		void *addr = NULL;
-		if (rte_ring_dequeue(umem->buf_ring, &addr)) {
+		uint64_t addr;
+		mbuf = rte_pktmbuf_alloc(umem->mb_pool);
+		if (unlikely(mbuf == NULL)) {
 			i--;
 			break;
 		}
+		addr = mbuf_to_addr(umem, mbuf);
 		fq_addr = xsk_ring_prod__fill_addr(fq, idx++);
-		*fq_addr = (uint64_t)addr;
+		*fq_addr = addr;
 	}
 
 	xsk_ring_prod__submit(fq, i);
@@ -196,7 +222,7 @@ eth_af_xdp_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		rx_bytes += len;
 		bufs[count++] = mbufs[i];
 
-		rte_ring_enqueue(umem->buf_ring, (void *)addr);
+		rte_pktmbuf_free(addr_to_mbuf(umem, addr));
 	}
 
 	xsk_ring_cons__release(rx, rcvd);
@@ -219,7 +245,7 @@ static void pull_umem_cq(struct xsk_umem_info *umem, int size)
 	for (i = 0; i < n; i++) {
 		uint64_t addr;
 		addr = *xsk_ring_cons__comp_addr(cq, idx_cq++);
-		rte_ring_enqueue(umem->buf_ring, (void *)addr);
+		rte_pktmbuf_free(addr_to_mbuf(umem, addr));
 	}
 
 	xsk_ring_cons__release(cq, n);
@@ -248,7 +274,7 @@ eth_af_xdp_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	struct pkt_tx_queue *txq = queue;
 	struct xsk_umem_info *umem = txq->pair->umem;
 	struct rte_mbuf *mbuf;
-	void *addrs[ETH_AF_XDP_TX_BATCH_SIZE];
+	struct rte_mbuf *mbuf_to_tx;
 	unsigned long tx_bytes = 0;
 	int i, valid = 0;
 	uint32_t idx_tx;
@@ -257,11 +283,6 @@ eth_af_xdp_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 
 	pull_umem_cq(umem, nb_pkts);
 
-	nb_pkts = rte_ring_dequeue_bulk(umem->buf_ring, addrs,
-					nb_pkts, NULL);
-	if (nb_pkts == 0)
-		return 0;
-
 	if (xsk_ring_prod__reserve(&txq->tx, nb_pkts, &idx_tx) != nb_pkts) {
 		kick_tx(txq);
 		return 0;
@@ -275,7 +296,12 @@ eth_af_xdp_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		desc = xsk_ring_prod__tx_desc(&txq->tx, idx_tx + i);
 		mbuf = bufs[i];
 		if (mbuf->pkt_len <= buf_len) {
-			desc->addr = (uint64_t)addrs[valid];
+			mbuf_to_tx = rte_pktmbuf_alloc(umem->mb_pool);
+			if (unlikely(mbuf_to_tx == NULL)) {
+				rte_pktmbuf_free(mbuf);
+				continue;
+			}
+			desc->addr = mbuf_to_addr(umem, mbuf_to_tx);
 			desc->len = mbuf->pkt_len;
 			pkt = xsk_umem__get_data(umem->buffer,
 						 desc->addr);
@@ -291,10 +317,6 @@ eth_af_xdp_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 
 	kick_tx(txq);
 
-	if (valid < nb_pkts)
-		rte_ring_enqueue_bulk(umem->buf_ring, &addrs[valid],
-				 nb_pkts - valid, NULL);
-
 	txq->stats.err_pkts += nb_pkts - valid;
 	txq->stats.tx_pkts += valid;
 	txq->stats.tx_bytes += tx_bytes;
@@ -443,16 +465,29 @@ eth_link_update(struct rte_eth_dev *dev __rte_unused,
 
 static void xdp_umem_destroy(struct xsk_umem_info *umem)
 {
-	free(umem->buffer);
-	umem->buffer = NULL;
-
-	rte_ring_free(umem->buf_ring);
-	umem->buf_ring = NULL;
+	rte_mempool_free(umem->mb_pool);
+	umem->mb_pool = NULL;
 
 	rte_free(umem);
 	umem = NULL;
 }
 
+static inline uint64_t get_base_addr(struct rte_mempool *mp)
+{
+	struct rte_mempool_memhdr *memhdr;
+
+	memhdr = STAILQ_FIRST(&mp->mem_list);
+	return (uint64_t)(memhdr->addr);
+}
+
+static inline uint64_t get_len(struct rte_mempool *mp)
+{
+	struct rte_mempool_memhdr *memhdr;
+
+	memhdr = STAILQ_FIRST(&mp->mem_list);
+	return (uint64_t)(memhdr->len);
+}
+
 static struct xsk_umem_info *xdp_umem_configure(void)
 {
 	struct xsk_umem_info *umem;
@@ -461,9 +496,8 @@ static struct xsk_umem_info *xdp_umem_configure(void)
 		.comp_size = ETH_AF_XDP_DFLT_NUM_DESCS,
 		.frame_size = ETH_AF_XDP_FRAME_SIZE,
 		.frame_headroom = ETH_AF_XDP_DATA_HEADROOM };
-	void *bufs = NULL;
+	void *base_addr = NULL;
 	int ret;
-	uint64_t i;
 
 	umem = rte_zmalloc_socket("umem", sizeof(*umem), 0, rte_socket_id());
 	if (umem == NULL) {
@@ -471,26 +505,20 @@ static struct xsk_umem_info *xdp_umem_configure(void)
 		return NULL;
 	}
 
-	umem->buf_ring = rte_ring_create("af_xdp_ring",
-					 ETH_AF_XDP_NUM_BUFFERS,
-					 SOCKET_ID_ANY,
-					 0x0);
-	if (umem->buf_ring == NULL) {
-		AF_XDP_LOG(ERR, "Failed to create rte_ring\n");
+	umem->mb_pool = rte_pktmbuf_pool_create_with_flags("af_xdp_mempool",
+			ETH_AF_XDP_NUM_BUFFERS,
+			250, 0,
+			ETH_AF_XDP_FRAME_SIZE -
+			ETH_AF_XDP_MBUF_OVERHEAD,
+			MEMPOOL_F_NO_SPREAD | MEMPOOL_CHUNK_F_PAGE_ALIGN,
+			SOCKET_ID_ANY);
+	if (umem->mb_pool == NULL || umem->mb_pool->nb_mem_chunks != 1) {
+		AF_XDP_LOG(ERR, "Failed to create mempool\n");
 		goto err;
 	}
+	base_addr = (void *)get_base_addr(umem->mb_pool);
 
-	for (i = 0; i < ETH_AF_XDP_NUM_BUFFERS; i++)
-		rte_ring_enqueue(umem->buf_ring,
-				 (void *)(i * ETH_AF_XDP_FRAME_SIZE +
-					  ETH_AF_XDP_DATA_HEADROOM));
-
-	if (posix_memalign(&bufs, getpagesize(),
-			   ETH_AF_XDP_NUM_BUFFERS * ETH_AF_XDP_FRAME_SIZE)) {
-		AF_XDP_LOG(ERR, "Failed to allocate memory pool.\n");
-		goto err;
-	}
-	ret = xsk_umem__create(&umem->umem, bufs,
+	ret = xsk_umem__create(&umem->umem, base_addr,
 			       ETH_AF_XDP_NUM_BUFFERS * ETH_AF_XDP_FRAME_SIZE,
 			       &umem->fq, &umem->cq,
 			       &usr_config);
@@ -499,7 +527,7 @@ static struct xsk_umem_info *xdp_umem_configure(void)
 		AF_XDP_LOG(ERR, "Failed to create umem");
 		goto err;
 	}
-	umem->buffer = bufs;
+	umem->buffer = base_addr;
 
 	return umem;
 
@@ -903,10 +931,9 @@ rte_pmd_af_xdp_remove(struct rte_vdev_device *dev)
 
 	internals = eth_dev->data->dev_private;
 
-	rte_ring_free(internals->umem->buf_ring);
-	rte_free(internals->umem->buffer);
 	rte_free(internals->umem);
 
+	rte_mempool_free(internals->umem->mb_pool);
 	rte_eth_dev_release_port(eth_dev);
 
 
Signature · 1 line
2.17.1
#124 lore raw

Re: [PATCH v6 4/5] net/af_xdp: use mbuf mempool for buffer management

Hi Xiaolong,

Quoted 14 lines · Xiaolong Ye

Now, af_xdp registered memory buffer is managed by rte_mempool. mbuf allocated from rte_mempool can be converted to xdp_desc's address and vice versa.

---
 drivers/net/af_xdp/rte_eth_af_xdp.c | 117 +++++++++++++++++-----------
 1 file changed, 72 insertions(+), 45 deletions(-)
drivers/net/af_xdp/rte_eth_af_xdp.c +0 -0
index 47a496ed7..a1fda9212 100644

drivers/net/af_xdp/rte_eth_af_xdp.c static int af_xdp_logtype; · line 55

Quoted 9 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +5 -1
@@ -48,7 +48,11 @@ static int af_xdp_logtype;
 
 #define ETH_AF_XDP_FRAME_SIZE		XSK_UMEM__DEFAULT_FRAME_SIZE
 #define ETH_AF_XDP_NUM_BUFFERS		4096
-#define ETH_AF_XDP_DATA_HEADROOM	0
+/* mempool hdrobj size (64 bytes) + sizeof(struct rte_mbuf) (128 bytes) */
+#define ETH_AF_XDP_MBUF_OVERHEAD	192
+/* data start from offset 320 (192 + 128) bytes */
+#define ETH_AF_XDP_DATA_HEADROOM				\
+	(ETH_AF_XDP_MBUF_OVERHEAD + RTE_PKTMBUF_HEADROOM)

Having these constants looks quite dangerous too me. It imposes the size of the mbuf, and the mempool header size. It would at least require compilation checks.

[...]

drivers/net/af_xdp/rte_eth_af_xdp.c static struct xsk_umem_info *xdp_umem_configure(void) · line 519

Quoted 12 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +10 -0
+	umem->mb_pool = rte_pktmbuf_pool_create_with_flags("af_xdp_mempool",
+			ETH_AF_XDP_NUM_BUFFERS,
+			250, 0,
+			ETH_AF_XDP_FRAME_SIZE -
+			ETH_AF_XDP_MBUF_OVERHEAD,
+			MEMPOOL_F_NO_SPREAD | MEMPOOL_CHUNK_F_PAGE_ALIGN,
+			SOCKET_ID_ANY);
+	if (umem->mb_pool == NULL || umem->mb_pool->nb_mem_chunks != 1) {
+		AF_XDP_LOG(ERR, "Failed to create mempool\n");
 		goto err;
 	}
+	base_addr = (void *)get_base_addr(umem->mb_pool);

Creating a mempool in the pmd like this does not look good to me for several reasons:
- the user application creates its mempool with a specific private area in its mbufs. Here there is no private area, so it will break applications doing this.
- in patch 3 (mempool), you ensure that the chunk starts at a page-aligned address, and you expect that given the other flags and the constants at the top of the file, the data will be aligned. In my opinion it is not ideal.
- the user application may create a large number of mbufs, for instance if the application manages large reassembly queues, or tcp sockets. Here the driver limits the number of mbufs to 4k per rx queue.
- the socket_id is any, so it won't be efficient on numa architectures.

May I suggest another idea?

Allocate the xsk_umem almost like in patch 1, but using rte_memzone allocation instead of posix_memalign() (and it will be faster, because it will use hugepages). And do not allocate any mempool in the driver.

When you receive a packet in the xsk_umem, allocate a new mbuf from the standard pool. Then, use rte_pktmbuf_attach_extbuf() to attach the xsk memory to the mbuf. You will have to register a callback to return the xsk memory when the mbuf is transmitted or freed.

This is, by the way, something I don't understand in your current
implementation: what happens if a mbuf is received in the af_xdp driver, and freed by the application? How does the xsk buffer is returned?

Using rte_pktmbuf_attach_extbuf() would remove changes in mbuf and mempool, at the price of (maybe) decreasing the performance. But I think there are some places where it can be optimized.

I understand my feedback comes late -- as usual :( -- but if you are in a hurry for RC1, maybe we can consider to put the 1st patch only, and add the zero-copy mode in a second patch later. What do you think?

Regards,
Olivier

#125 lore raw

Re: [PATCH v6 4/5] net/af_xdp: use mbuf mempool for buffer management

Hi, Olivier

Thanks for the comments.

Quoted 51 lines · Olivier Matz

Hi Xiaolong,

Quoted 14 lines · Xiaolong Ye

Now, af_xdp registered memory buffer is managed by rte_mempool. mbuf allocated from rte_mempool can be converted to xdp_desc's address and vice versa.

---
 drivers/net/af_xdp/rte_eth_af_xdp.c | 117 +++++++++++++++++-----------
 1 file changed, 72 insertions(+), 45 deletions(-)
drivers/net/af_xdp/rte_eth_af_xdp.c +0 -0
index 47a496ed7..a1fda9212 100644

drivers/net/af_xdp/rte_eth_af_xdp.c static int af_xdp_logtype; · line 55

Quoted 9 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +5 -1
@@ -48,7 +48,11 @@ static int af_xdp_logtype;
 
 #define ETH_AF_XDP_FRAME_SIZE		XSK_UMEM__DEFAULT_FRAME_SIZE
 #define ETH_AF_XDP_NUM_BUFFERS		4096
-#define ETH_AF_XDP_DATA_HEADROOM	0
+/* mempool hdrobj size (64 bytes) + sizeof(struct rte_mbuf) (128 bytes) */
+#define ETH_AF_XDP_MBUF_OVERHEAD	192
+/* data start from offset 320 (192 + 128) bytes */
+#define ETH_AF_XDP_DATA_HEADROOM				\
+	(ETH_AF_XDP_MBUF_OVERHEAD + RTE_PKTMBUF_HEADROOM)

Having these constants looks quite dangerous too me. It imposes the size of the mbuf, and the mempool header size. It would at least require compilation checks.

[...]

drivers/net/af_xdp/rte_eth_af_xdp.c static struct xsk_umem_info *xdp_umem_configure(void) · line 519

Quoted 12 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +10 -0
+	umem->mb_pool = rte_pktmbuf_pool_create_with_flags("af_xdp_mempool",
+			ETH_AF_XDP_NUM_BUFFERS,
+			250, 0,
+			ETH_AF_XDP_FRAME_SIZE -
+			ETH_AF_XDP_MBUF_OVERHEAD,
+			MEMPOOL_F_NO_SPREAD | MEMPOOL_CHUNK_F_PAGE_ALIGN,
+			SOCKET_ID_ANY);
+	if (umem->mb_pool == NULL || umem->mb_pool->nb_mem_chunks != 1) {
+		AF_XDP_LOG(ERR, "Failed to create mempool\n");
 		goto err;
 	}
+	base_addr = (void *)get_base_addr(umem->mb_pool);

Creating a mempool in the pmd like this does not look good to me for several reasons:
- the user application creates its mempool with a specific private area in its mbufs. Here there is no private area, so it will break applications doing this.

Quoted 8 lines

- in patch 3 (mempool), you ensure that the chunk starts at a page-aligned address, and you expect that given the other flags and the constants at the top of the file, the data will be aligned. In my opinion it is not ideal.
- the user application may create a large number of mbufs, for instance if the application manages large reassembly queues, or tcp sockets. Here the driver limits the number of mbufs to 4k per rx queue.
- the socket_id is any, so it won't be efficient on numa architectures.

Our mbuf/mempool change regarding to zero copy does have limitations.

Quoted 7 lines

May I suggest another idea?

Allocate the xsk_umem almost like in patch 1, but using rte_memzone allocation instead of posix_memalign() (and it will be faster, because it will use hugepages). And do not allocate any mempool in the driver.

rte_memzone_reserve_aligned is better than posix_memalign, I'll use it in my first patch.

Quoted 4 lines

When you receive a packet in the xsk_umem, allocate a new mbuf from the standard pool. Then, use rte_pktmbuf_attach_extbuf() to attach the xsk memory to the mbuf. You will have to register a callback to return the xsk memory when the mbuf is transmitted or freed.

I'll try to investigate how to implement it.

Quoted 4 lines

This is, by the way, something I don't understand in your current
implementation: what happens if a mbuf is received in the af_xdp driver, and freed by the application? How does the xsk buffer is returned?

It is coordinated by the fill ring. The fill ring is used by the application ( user space) to send down addr for the kernel to fill in with Rx packet data. So for the free side, we just return it to the mempool, and each time in rx_pkt_burst, we would allocate new mbufs and submit corresponding addrs to fill ring, that's how we return the xsk buffer to kernel.

Quoted 6 lines

Using rte_pktmbuf_attach_extbuf() would remove changes in mbuf and mempool, at the price of (maybe) decreasing the performance. But I think there are some places where it can be optimized.

I understand my feedback comes late -- as usual :( -- but if you are in

Sorry for not Cc you in my patch set.

Quoted 2 lines

a hurry for RC1, maybe we can consider to put the 1st patch only, and add the zero-copy mode in a second patch later. What do you think?

Sounds a sensible plan, I'll try to exteranl mbuf buffer scheme first.

Thanks,
Xiaolong

Quoted 5 lines

Regards,
Olivier

#126 lore raw

Re: [PATCH v6 4/5] net/af_xdp: use mbuf mempool for buffer management

Quoted 88 lines

-----Original Message-----
From: Ye, Xiaolong
Sent: Sunday, March 31, 2019 8:38 PM
To: Olivier Matz <[email protected]>
Cc: [email protected]; David Marchand <[email protected]>; Andrew Rybchenko <[email protected]>; Zhang, Qi Z <[email protected]>; Karlsson, Magnus <[email protected]>; Topel, Bjorn <[email protected]>; Maxime Coquelin <[email protected]>; Stephen Hemminger <[email protected]>; Yigit, Ferruh <[email protected]>; Luca Boccassi <[email protected]>; Richardson, Bruce <[email protected]>; Ananyev, Konstantin <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v6 4/5] net/af_xdp: use mbuf mempool for buffer management

Hi, Olivier

Thanks for the comments.

Quoted 13 lines · Olivier Matz

Hi Xiaolong,

Quoted 10 lines · Xiaolong Ye

Now, af_xdp registered memory buffer is managed by rte_mempool. mbuf allocated from rte_mempool can be converted to xdp_desc's address and vice versa.

---
 drivers/net/af_xdp/rte_eth_af_xdp.c | 117
+++++++++++++++++-----------
 1 file changed, 72 insertions(+), 45 deletions(-)
Quoted 8 lines

drivers/net/af_xdp/rte_eth_af_xdp.c static int af_xdp_logtype; · line 49

Quoted 8 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +0 -0
index 47a496ed7..a1fda9212 100644
@@ -48,7 +48,11 @@ static int af_xdp_logtype;
 
 #define ETH_AF_XDP_FRAME_SIZE

XSK_UMEM__DEFAULT_FRAME_SIZE

Quoted 12 lines

drivers/net/af_xdp/rte_eth_af_xdp.c static int af_xdp_logtype; · line 55

Quoted 7 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +5 -1
 #define ETH_AF_XDP_NUM_BUFFERS		4096
-#define ETH_AF_XDP_DATA_HEADROOM	0
+/* mempool hdrobj size (64 bytes) + sizeof(struct rte_mbuf) (128 bytes) */
+#define ETH_AF_XDP_MBUF_OVERHEAD	192
+/* data start from offset 320 (192 + 128) bytes */
+#define ETH_AF_XDP_DATA_HEADROOM				\
+	(ETH_AF_XDP_MBUF_OVERHEAD + RTE_PKTMBUF_HEADROOM)

Having these constants looks quite dangerous too me. It imposes the size of the mbuf, and the mempool header size. It would at least require compilation checks.

Quoted 3 lines

[...]

drivers/net/af_xdp/rte_eth_af_xdp.c

Quoted 1 line
drivers/net/af_xdp/rte_eth_af_xdp.c +1 -0
+	umem->mb_pool =

rte_pktmbuf_pool_create_with_flags("af_xdp_mempool",

Quoted 5 lines

drivers/net/af_xdp/rte_eth_af_xdp.c static struct xsk_umem_info *xdp_umem_configure(void)

Quoted 5 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +5 -0
+			ETH_AF_XDP_NUM_BUFFERS,
+			250, 0,
+			ETH_AF_XDP_FRAME_SIZE -
+			ETH_AF_XDP_MBUF_OVERHEAD,
+			MEMPOOL_F_NO_SPREAD |

MEMPOOL_CHUNK_F_PAGE_ALIGN,

Quoted 2 lines

drivers/net/af_xdp/rte_eth_af_xdp.c

Quoted 2 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +2 -0
+			SOCKET_ID_ANY);
+	if (umem->mb_pool == NULL || umem->mb_pool->nb_mem_chunks != 1)

{

Quoted 10 lines

drivers/net/af_xdp/rte_eth_af_xdp.c static struct xsk_umem_info *xdp_umem_configure(void) · line 519

Quoted 4 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +2 -0
+		AF_XDP_LOG(ERR, "Failed to create mempool\n");
 		goto err;
 	}
+	base_addr = (void *)get_base_addr(umem->mb_pool);

Creating a mempool in the pmd like this does not look good to me for several reasons:
- the user application creates its mempool with a specific private area in its mbufs. Here there is no private area, so it will break applications doing this.

Quoted 8 lines

- in patch 3 (mempool), you ensure that the chunk starts at a page-aligned address, and you expect that given the other flags and the constants at the top of the file, the data will be aligned. In my opinion it is not ideal.
- the user application may create a large number of mbufs, for instance if the application manages large reassembly queues, or tcp sockets. Here the driver limits the number of mbufs to 4k per rx queue.
- the socket_id is any, so it won't be efficient on numa architectures.

Quoted 1 line

Our mbuf/mempool change regarding to zero copy does have limitations.

Just want to clarify, the above code is only reached for non-zero copy case.
here we create a private memory pool be used to manage AF_XDP umem, it's not the Rx queues' s memory pool itself. so I don't think there is concern on the private area and 4k per rx queue for above code.

Quoted 53 lines
Quoted 8 lines

May I suggest another idea?

Allocate the xsk_umem almost like in patch 1, but using rte_memzone allocation instead of posix_memalign() (and it will be faster, because it will use hugepages). And do not allocate any mempool in the driver.

rte_memzone_reserve_aligned is better than posix_memalign, I'll use it in my first patch.

Quoted 4 lines

When you receive a packet in the xsk_umem, allocate a new mbuf from the standard pool. Then, use rte_pktmbuf_attach_extbuf() to attach the xsk memory to the mbuf. You will have to register a callback to return the xsk memory when the mbuf is transmitted or freed.

I'll try to investigate how to implement it.

Quoted 4 lines

This is, by the way, something I don't understand in your current
implementation: what happens if a mbuf is received in the af_xdp driver, and freed by the application? How does the xsk buffer is returned?

It is coordinated by the fill ring. The fill ring is used by the application ( user space) to send down addr for the kernel to fill in with Rx packet data.
So for the free side, we just return it to the mempool, and each time in rx_pkt_burst, we would allocate new mbufs and submit corresponding addrs to fill ring, that's how we return the xsk buffer to kernel.

Quoted 6 lines

Using rte_pktmbuf_attach_extbuf() would remove changes in mbuf and mempool, at the price of (maybe) decreasing the performance. But I think there are some places where it can be optimized.

I understand my feedback comes late -- as usual :( -- but if you are in

Sorry for not Cc you in my patch set.

Quoted 2 lines

a hurry for RC1, maybe we can consider to put the 1st patch only, and add the zero-copy mode in a second patch later. What do you think?

Sounds a sensible plan, I'll try to exteranl mbuf buffer scheme first.

Thanks,
Xiaolong

Quoted 5 lines

Regards,
Olivier

#127 lore raw

PATCH v6 5/5 net/af_xdp: enable zero copy

In reply to Xiaolong Ye

Try to check if external mempool (from rx_queue_setup) is fit for af_xdp, if it is, it will be registered to af_xdp socket directly and there will be no packet data copy on Rx and Tx.

---
 drivers/net/af_xdp/rte_eth_af_xdp.c | 130 ++++++++++++++++++++--------
 1 file changed, 96 insertions(+), 34 deletions(-)
drivers/net/af_xdp/rte_eth_af_xdp.c +96 -34
index a1fda9212..c6ade4c94 100644
@@ -67,6 +67,7 @@ struct xsk_umem_info {
 	struct xsk_umem *umem;
 	struct rte_mempool *mb_pool;
 	void *buffer;
+	uint8_t zc;
 };
 
 struct rx_stats {
@@ -85,6 +86,7 @@ struct pkt_rx_queue {
 
 	struct pkt_tx_queue *pair;
 	uint16_t queue_idx;
+	uint8_t zc;
 };
 
 struct tx_stats {
@@ -202,7 +204,9 @@ eth_af_xdp_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	if (xsk_prod_nb_free(fq, free_thresh) >= free_thresh)
 		(void)reserve_fill_queue(umem, ETH_AF_XDP_RX_BATCH_SIZE);
 
-	if (unlikely(rte_pktmbuf_alloc_bulk(rxq->mb_pool, mbufs, rcvd) != 0))
+	if (!rxq->zc &&
+		unlikely(rte_pktmbuf_alloc_bulk(rxq->mb_pool,
+				mbufs, rcvd) != 0))
 		return 0;
 
 	for (i = 0; i < rcvd; i++) {
@@ -216,13 +220,23 @@ eth_af_xdp_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		len = desc->len;
 		pkt = xsk_umem__get_data(rxq->umem->buffer, addr);
 
-		rte_memcpy(rte_pktmbuf_mtod(mbufs[i], void *), pkt, len);
-		rte_pktmbuf_pkt_len(mbufs[i]) = len;
-		rte_pktmbuf_data_len(mbufs[i]) = len;
-		rx_bytes += len;
-		bufs[count++] = mbufs[i];
-
-		rte_pktmbuf_free(addr_to_mbuf(umem, addr));
+		if (rxq->zc) {
+			struct rte_mbuf *mbuf;
+			mbuf = addr_to_mbuf(rxq->umem, addr);
+			rte_pktmbuf_pkt_len(mbuf) = len;
+			rte_pktmbuf_data_len(mbuf) = len;
+			rx_bytes += len;
+			bufs[count++] = mbuf;
+		} else {
+			rte_memcpy(rte_pktmbuf_mtod(mbufs[i], void *),
+					pkt, len);
+			rte_pktmbuf_pkt_len(mbufs[i]) = len;
+			rte_pktmbuf_data_len(mbufs[i]) = len;
+			rx_bytes += len;
+			bufs[count++] = mbufs[i];
+
+			rte_pktmbuf_free(addr_to_mbuf(umem, addr));
+		}
 	}
 
 	xsk_ring_cons__release(rx, rcvd);
@@ -295,22 +309,29 @@ eth_af_xdp_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 					- ETH_AF_XDP_DATA_HEADROOM;
 		desc = xsk_ring_prod__tx_desc(&txq->tx, idx_tx + i);
 		mbuf = bufs[i];
-		if (mbuf->pkt_len <= buf_len) {
-			mbuf_to_tx = rte_pktmbuf_alloc(umem->mb_pool);
-			if (unlikely(mbuf_to_tx == NULL)) {
-				rte_pktmbuf_free(mbuf);
-				continue;
-			}
-			desc->addr = mbuf_to_addr(umem, mbuf_to_tx);
+		if (txq->pair->zc && mbuf->pool == umem->mb_pool) {
+			desc->addr = mbuf_to_addr(umem, mbuf);
 			desc->len = mbuf->pkt_len;
-			pkt = xsk_umem__get_data(umem->buffer,
-						 desc->addr);
-			rte_memcpy(pkt, rte_pktmbuf_mtod(mbuf, void *),
-			       desc->len);
 			valid++;
 			tx_bytes += mbuf->pkt_len;
+		} else {
+			if (mbuf->pkt_len <= buf_len) {
+				mbuf_to_tx = rte_pktmbuf_alloc(umem->mb_pool);
+				if (unlikely(mbuf_to_tx == NULL)) {
+					rte_pktmbuf_free(mbuf);
+					continue;
+				}
+				desc->addr = mbuf_to_addr(umem, mbuf_to_tx);
+				desc->len = mbuf->pkt_len;
+				pkt = xsk_umem__get_data(umem->buffer,
+							 desc->addr);
+				memcpy(pkt, rte_pktmbuf_mtod(mbuf, void *),
+				       desc->len);
+				valid++;
+				tx_bytes += mbuf->pkt_len;
+			}
+			rte_pktmbuf_free(mbuf);
 		}
-		rte_pktmbuf_free(mbuf);
 	}
 
 	xsk_ring_prod__submit(&txq->tx, nb_pkts);
@@ -488,7 +509,7 @@ static inline uint64_t get_len(struct rte_mempool *mp)
 	return (uint64_t)(memhdr->len);
 }
 
-static struct xsk_umem_info *xdp_umem_configure(void)
+static struct xsk_umem_info *xdp_umem_configure(struct rte_mempool *mb_pool)
 {
 	struct xsk_umem_info *umem;
 	struct xsk_umem_config usr_config = {
@@ -505,16 +526,23 @@ static struct xsk_umem_info *xdp_umem_configure(void)
 		return NULL;
 	}
 
-	umem->mb_pool = rte_pktmbuf_pool_create_with_flags("af_xdp_mempool",
-			ETH_AF_XDP_NUM_BUFFERS,
-			250, 0,
-			ETH_AF_XDP_FRAME_SIZE -
-			ETH_AF_XDP_MBUF_OVERHEAD,
-			MEMPOOL_F_NO_SPREAD | MEMPOOL_CHUNK_F_PAGE_ALIGN,
-			SOCKET_ID_ANY);
-	if (umem->mb_pool == NULL || umem->mb_pool->nb_mem_chunks != 1) {
-		AF_XDP_LOG(ERR, "Failed to create mempool\n");
-		goto err;
+	if (!mb_pool) {
+		umem->mb_pool = rte_pktmbuf_pool_create_with_flags("af_xdp_mempool",
+				ETH_AF_XDP_NUM_BUFFERS,
+				250, 0,
+				ETH_AF_XDP_FRAME_SIZE -
+				ETH_AF_XDP_MBUF_OVERHEAD,
+				MEMPOOL_F_NO_SPREAD | MEMPOOL_CHUNK_F_PAGE_ALIGN,
+				SOCKET_ID_ANY);
+
+		if (umem->mb_pool == NULL ||
+				umem->mb_pool->nb_mem_chunks != 1) {
+			AF_XDP_LOG(ERR, "Failed to create mempool\n");
+			goto err;
+		}
+	} else {
+		umem->mb_pool = mb_pool;
+		umem->zc = 1;
 	}
 	base_addr = (void *)get_base_addr(umem->mb_pool);
 
@@ -536,16 +564,43 @@ static struct xsk_umem_info *xdp_umem_configure(void)
 	return NULL;
 }
 
+static uint8_t
+check_mempool_zc(struct rte_mempool *mp)
+{
+	RTE_ASSERT(mp);
+
+	/* must continues */
+	if (mp->nb_mem_chunks > 1)
+		return 0;
+
+	/* check header size */
+	if (mp->header_size != RTE_CACHE_LINE_SIZE)
+		return 0;
+
+	/* check base address */
+	if ((uint64_t)get_base_addr(mp) % getpagesize() != 0)
+		return 0;
+
+	/* check chunk size */
+	if ((mp->elt_size + mp->header_size + mp->trailer_size) %
+	    ETH_AF_XDP_FRAME_SIZE != 0)
+		return 0;
+
+	return 1;
+}
+
 static int
 xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
-	      int ring_size)
+	      int ring_size, struct rte_mempool *mb_pool)
 {
 	struct xsk_socket_config cfg;
 	struct pkt_tx_queue *txq = rxq->pair;
+	struct rte_mempool *mp;
 	int ret = 0;
 	int reserve_size;
 
-	rxq->umem = xdp_umem_configure();
+	mp = check_mempool_zc(mb_pool) ? mb_pool : NULL;
+	rxq->umem = xdp_umem_configure(mp);
 	if (rxq->umem == NULL)
 		return -ENOMEM;
 
@@ -622,7 +677,7 @@ eth_rx_queue_setup(struct rte_eth_dev *dev,
 
 	rxq->mb_pool = mb_pool;
 
-	if (xsk_configure(internals, rxq, nb_rx_desc)) {
+	if (xsk_configure(internals, rxq, nb_rx_desc, mb_pool)) {
 		AF_XDP_LOG(ERR, "Failed to configure xdp socket\n");
 		ret = -EINVAL;
 		goto err;
@@ -630,6 +685,13 @@ eth_rx_queue_setup(struct rte_eth_dev *dev,
 
 	internals->umem = rxq->umem;
 
+	if (mb_pool == internals->umem->mb_pool)
+		rxq->zc = internals->umem->zc;
+
+	if (rxq->zc)
+		AF_XDP_LOG(INFO,
+			"zero copy enabled on rx queue %d\n", rx_queue_id);
+
 	dev->data->rx_queues[rx_queue_id] = rxq;
 	return 0;
 
Signature · 1 line
2.17.1
#128 lore raw

v7 cover Introduce AF_XDP PMD

In reply to Xiaolong Ye

Overview
========

This patchset adds a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux, see below links [1] [2] for details of AF_XDP introduction:

AF_XDP roadmap
==============
- AF_XDP is included in upstream kernel since 4.18, and AF_XDP support in libbpf has been merged in v5.1-rc1.
- Now i40e and ixgbe drivers have supported zero copy mode.

Change logs
===========

v7:
- mention mtu limitation in af_xdp.rst
- fix the vdev name in af_xdp.rst

V6:

- remove the newline in AF_XDP_LOG definition to avoid double new lines issue.
- rename MEMPOOL_F_PAGE_ALIGN to MEMPOOL_CHUNK_F_PAGE_ALIGN.

V5:

- disable AF_XDP pmd by default due to it requires kernel more recent than minimum kernel version supported by DPDK
- address other review comments of Maxime

V4:

- change vdev name to net_af_xdp
- adopt dynamic log type for all logging
- Fix other style issues raised by Stephen

V3:

- Fix all style issues pointed by Stephen, Mattias, David.
- Drop the testpmd change as we'll adopt Jerin's suggestion to add a new mempool driver to handle the application use of AF_XDP's zero copy feature.

V2:
- Fix a NULL pointer reference crash issue
- Fix txonly stop sending traffic in zc mode
- Refactor rte_mbuf.c to avoid ABI breakage.
- Fix multiple style issues pointed by Ferruh, David, Stephen, Luca.

changes vs RFC sent by Qi last Aug:

- Re-work base on AF_XDP's interface changes since the new libbpf has provided higher-level APIs that hide many of the details of the AP_XDP uapi. After the rework, it helps to reduce 300+ lines of code.

- multi-queues is not supported due to current libbpf doesn't support multi-sockets on a single umem.

- No extra steps to load xdp program manually, since the current behavior of libbpf would load a default xdp program when user calls xsk_socket__create. userspace application only needs to handle the cleanup.

How to try
==========

1. take the kernel >= v5.1-rc1, build kernel and replace your host kernel with it.

make sure you turn on XDP sockets when compiling

Networking support -->
Networking options -->
[ * ] XDP sockets

2. build libbpf in tools/lib/bpf, and copy the libbpf.a and libbpf.so to /usr/lib64

cd tools/lib/bpf
make

3. ethtool -L enp59s0f0 combined 1

4. extra step to build dpdk

explicitly enable AF_XDP pmd by adding below line to config/common_linux

CONFIG_RTE_LIBRTE_PMD_AF_XDP=y

5. start testpmd

   ./build/app/testpmd -c 0xc -n 4 --vdev net_af_xdp,iface=enp59s0f0,queue=0 -- -i --rxq=1 --txq=1

in this case, default xdp program will be loaded and linked to queue 0 of enp59s0f0, network traffics travel to queue 0 will be redirected to af_xdp socket.

Xiaolong Ye (5):
net/af_xdp: introduce AF XDP PMD driver lib/mbuf: introduce helper to create mempool with flags lib/mempool: allow page size aligned mempool net/af_xdp: use mbuf mempool for buffer management net/af_xdp: enable zero copy

 MAINTAINERS                                   |    6 +
 config/common_base                            |    5 +
 doc/guides/nics/af_xdp.rst                    |   45 +
 doc/guides/nics/features/af_xdp.ini           |   11 +
 doc/guides/nics/index.rst                     |    1 +
 doc/guides/rel_notes/release_19_05.rst        |    7 +
 drivers/net/Makefile                          |    1 +
 drivers/net/af_xdp/Makefile                   |   32 +
 drivers/net/af_xdp/meson.build                |   21 +
 drivers/net/af_xdp/rte_eth_af_xdp.c           | 1020 +++++++++++++++++
 drivers/net/af_xdp/rte_pmd_af_xdp_version.map |    3 +
 drivers/net/meson.build                       |    1 +
 lib/librte_mbuf/rte_mbuf.c                    |   29 +-
 lib/librte_mbuf/rte_mbuf.h                    |   45 +
 lib/librte_mbuf/rte_mbuf_version.map          |    1 +
 lib/librte_mempool/rte_mempool.c              |    3 +
 lib/librte_mempool/rte_mempool.h              |    1 +
 mk/rte.app.mk                                 |    1 +
 18 files changed, 1228 insertions(+), 5 deletions(-)
 create mode 100644 doc/guides/nics/af_xdp.rst
 create mode 100644 doc/guides/nics/features/af_xdp.ini
 create mode 100644 drivers/net/af_xdp/Makefile
 create mode 100644 drivers/net/af_xdp/meson.build
 create mode 100644 drivers/net/af_xdp/rte_eth_af_xdp.c
 create mode 100644 drivers/net/af_xdp/rte_pmd_af_xdp_version.map
Signature · 1 line
2.17.1
#129 lore raw

PATCH v7 1/5 net/af_xdp: introduce AF XDP PMD driver

Add a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux. More info about AF_XDP, please refer to [1] [2].

This is the vanilla version PMD which just uses a raw buffer registered as the umem.

[1] https://fosdem.org/2018/schedule/event/af_xdp/
[2] https://lwn.net/Articles/745934/

---
 MAINTAINERS                                   |   6 +
 config/common_base                            |   5 +
 doc/guides/nics/af_xdp.rst                    |  48 +
 doc/guides/nics/features/af_xdp.ini           |  11 +
 doc/guides/nics/index.rst                     |   1 +
 doc/guides/rel_notes/release_19_05.rst        |   7 +
 drivers/net/Makefile                          |   1 +
 drivers/net/af_xdp/Makefile                   |  32 +
 drivers/net/af_xdp/meson.build                |  21 +
 drivers/net/af_xdp/rte_eth_af_xdp.c           | 931 ++++++++++++++++++
 drivers/net/af_xdp/rte_pmd_af_xdp_version.map |   3 +
 drivers/net/meson.build                       |   1 +
 mk/rte.app.mk                                 |   1 +
 13 files changed, 1068 insertions(+)
 create mode 100644 doc/guides/nics/af_xdp.rst
 create mode 100644 doc/guides/nics/features/af_xdp.ini
 create mode 100644 drivers/net/af_xdp/Makefile
 create mode 100644 drivers/net/af_xdp/meson.build
 create mode 100644 drivers/net/af_xdp/rte_eth_af_xdp.c
 create mode 100644 drivers/net/af_xdp/rte_pmd_af_xdp_version.map
MAINTAINERS +6 -0
index 21e164095..58ebe9d58 100644
@@ -474,6 +474,12 @@ M: John W. Linville <[email protected]>
 F: drivers/net/af_packet/
 F: doc/guides/nics/features/afpacket.ini
 
+Linux AF_XDP
+M: Xiaolong Ye <[email protected]>
+M: Qi Zhang <[email protected]>
+F: drivers/net/af_xdp/
+F: doc/guides/nics/features/af_xdp.rst
+
 Amazon ENA
 M: Marcin Wojtas <[email protected]>
 M: Michal Krawczyk <[email protected]>
config/common_base +5 -0
index 0b09a9348..4044de205 100644
@@ -416,6 +416,11 @@ CONFIG_RTE_LIBRTE_VMXNET3_DEBUG_TX_FREE=n
 #
 CONFIG_RTE_LIBRTE_PMD_AF_PACKET=n
 
+#
+# Compile software PMD backed by AF_XDP sockets (Linux only)
+#
+CONFIG_RTE_LIBRTE_PMD_AF_XDP=n
+
 #
 # Compile link bonding PMD library
 #
doc/guides/nics/af_xdp.rst new file +48 -0

48 lines not on this page · raw message

doc/guides/nics/features/af_xdp.ini new file +11 -0
new file mode 100644
index 000000000..36953c2de
@@ -0,0 +1,11 @@
+;
+; Supported features of the 'af_xdp' network poll mode driver.
+;
+; Refer to default.ini for the full list of available PMD features.
+;
+[Features]
+Link status          = Y
+MTU update           = Y
+Promiscuous mode     = Y
+Stats per queue      = Y
+x86-64               = Y
doc/guides/nics/index.rst +1 -0
index 5c80e3baa..a4b80a3d0 100644
@@ -12,6 +12,7 @@ Network Interface Controller Drivers
     features
     build_and_test
     af_packet
+    af_xdp
     ark
     atlantic
     avp
doc/guides/rel_notes/release_19_05.rst +7 -0
index d11bb5a2b..c6facb88a 100644
@@ -65,6 +65,13 @@ New Features
     process.
   * Added support for Rx packet types list in a secondary process.
 
+* **Added the AF_XDP PMD.**
+
+  Added a Linux-specific PMD driver for AF_XDP, it can create the AF_XDP socket
+  and bind it to a specific netdev queue, it allows a DPDK application to send
+  and receive raw packets through the socket which would bypass the kernel
+  network stack to achieve high performance packet processing.
+
 * **Updated Mellanox drivers.**
 
    New features and improvements were done in mlx4 and mlx5 PMDs:
drivers/net/Makefile +1 -0
index 502869a87..5d401b8c5 100644
@@ -9,6 +9,7 @@ ifeq ($(CONFIG_RTE_LIBRTE_THUNDERX_NICVF_PMD),d)
 endif
 
 DIRS-$(CONFIG_RTE_LIBRTE_PMD_AF_PACKET) += af_packet
+DIRS-$(CONFIG_RTE_LIBRTE_PMD_AF_XDP) += af_xdp
 DIRS-$(CONFIG_RTE_LIBRTE_ARK_PMD) += ark
 DIRS-$(CONFIG_RTE_LIBRTE_ATLANTIC_PMD) += atlantic
 DIRS-$(CONFIG_RTE_LIBRTE_AVP_PMD) += avp
drivers/net/af_xdp/Makefile new file +32 -0
new file mode 100644
index 000000000..db7d9aa57
@@ -0,0 +1,32 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2018 Intel Corporation
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+#
+# library name
+#
+LIB = librte_pmd_af_xdp.a
+
+EXPORT_MAP := rte_pmd_af_xdp_version.map
+
+LIBABIVER := 1
+
+CFLAGS += -O3
+
+# require kernel version >= v5.1-rc1
+CFLAGS += -I$(RTE_KERNELDIR)/tools/include
+CFLAGS += -I$(RTE_KERNELDIR)/tools/lib/bpf
+
+CFLAGS += $(WERROR_FLAGS)
+LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring
+LDLIBS += -lrte_ethdev -lrte_net -lrte_kvargs
+LDLIBS += -lrte_bus_vdev
+LDLIBS += -lbpf
+
+#
+# all source are stored in SRCS-y
+#
+SRCS-$(CONFIG_RTE_LIBRTE_PMD_AF_XDP) += rte_eth_af_xdp.c
+
+include $(RTE_SDK)/mk/rte.lib.mk
drivers/net/af_xdp/meson.build new file +21 -0
new file mode 100644
index 000000000..7e51169b4
@@ -0,0 +1,21 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2018 Intel Corporation
+
+if host_machine.system() != 'linux'
+	build = false
+endif
+
+bpf_dep = dependency('libbpf', required: false)
+if bpf_dep.found()
+	build = true
+else
+	bpf_dep = cc.find_library('libbpf', required: false)
+	if bpf_dep.found() and cc.has_header('xsk.h', dependencies: bpf_dep) and cc.has_header('linux/if_xdp.h')
+		build = true
+		pkgconfig_extra_libs += '-lbpf'
+	else
+		build = false
+	endif
+endif
+sources = files('rte_eth_af_xdp.c')
+ext_deps += bpf_dep
drivers/net/af_xdp/rte_eth_af_xdp.c new file +931 -0

931 lines not on this page · raw message

drivers/net/af_xdp/rte_pmd_af_xdp_version.map new file +3 -0
new file mode 100644
index 000000000..c6db030fe
@@ -0,0 +1,3 @@
+DPDK_19.05 {
+	local: *;
+};
drivers/net/meson.build +1 -0
index 3ecc78cee..1105e72d8 100644
@@ -2,6 +2,7 @@
 # Copyright(c) 2017 Intel Corporation
 
 drivers = ['af_packet',
+	'af_xdp',
 	'ark',
 	'atlantic',
 	'avp',
mk/rte.app.mk +1 -0
index 262132fc6..be0af73cc 100644
@@ -143,6 +143,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_DPAA2_MEMPOOL)  += -lrte_mempool_dpaa2
 endif
 
 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AF_PACKET)  += -lrte_pmd_af_packet
+_LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AF_XDP)     += -lrte_pmd_af_xdp -lelf -lbpf
 _LDLIBS-$(CONFIG_RTE_LIBRTE_ARK_PMD)        += -lrte_pmd_ark
 _LDLIBS-$(CONFIG_RTE_LIBRTE_ATLANTIC_PMD)   += -lrte_pmd_atlantic
 _LDLIBS-$(CONFIG_RTE_LIBRTE_AVP_PMD)        += -lrte_pmd_avp
Signature · 1 line
2.17.1
#130 lore raw

Re: [PATCH v7 1/5] net/af_xdp: introduce AF XDP PMD driver

Quoted 11 lines · Xiaolong Ye

Add a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux. More info about AF_XDP, please refer to [1] [2].

This is the vanilla version PMD which just uses a raw buffer registered as the umem.

[1] https://fosdem.org/2018/schedule/event/af_xdp/
[2] https://lwn.net/Articles/745934/

Hi Xiaolong,

Mostly looks good, only there are a few comments on minor issues, can you please check them?

<...>

MAINTAINERS M: John W. Linville <[email protected]> · line 481

Quoted 9 lines
MAINTAINERS +5 -0
@@ -474,6 +474,12 @@ M: John W. Linville <[email protected]>
 F: drivers/net/af_packet/
 F: doc/guides/nics/features/afpacket.ini
 
+Linux AF_XDP
+M: Xiaolong Ye <[email protected]>
+M: Qi Zhang <[email protected]>
+F: drivers/net/af_xdp/
+F: doc/guides/nics/features/af_xdp.rst

Can you please add .ini file too?

<...>

drivers/net/af_xdp/rte_eth_af_xdp.c line 117

Quoted 5 lines
drivers/net/af_xdp/rte_eth_af_xdp.c new file +5 -0
+static const char * const valid_arguments[] = {
+	ETH_AF_XDP_IFACE_ARG,
+	ETH_AF_XDP_QUEUE_IDX_ARG,
+	NULL
+};

Minor issue, but can you please keep close the .*ARG defines and this structure, either move this up or move defines down just above this struct?

drivers/net/af_xdp/rte_eth_af_xdp.c line 124

Quoted 7 lines
drivers/net/af_xdp/rte_eth_af_xdp.c new file +7 -0
+
+static struct rte_eth_link pmd_link = {
+	.link_speed = ETH_SPEED_NUM_10G,
+	.link_duplex = ETH_LINK_FULL_DUPLEX,
+	.link_status = ETH_LINK_DOWN,
+	.link_autoneg = ETH_LINK_AUTONEG
+};

Can this variable be const?

<...>

drivers/net/af_xdp/rte_eth_af_xdp.c line 339

Quoted 10 lines
drivers/net/af_xdp/rte_eth_af_xdp.c new file +10 -0
+static void
+eth_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
+{
+	struct pmd_internals *internals = dev->data->dev_private;
+
+	dev_info->if_index = internals->if_index;
+	dev_info->max_mac_addrs = 1;
+	dev_info->max_rx_pktlen = ETH_FRAME_LEN;
+	dev_info->max_rx_queues = 1;
+	dev_info->max_tx_queues = 1;

What do you think documenting the only single queue supported limitation?

<...>

Review

Quoted 2 lines
(quoted diff) +2 -0
+static void remove_xdp_program(struct pmd_internals *internals)
+{

According coding convention it should be:

static void
remove_xdp_program(struct pmd_internals *internals) {

There is a usage of mixture, can you please update them according convention?

<...>

drivers/net/af_xdp/rte_eth_af_xdp.c line 874

Quoted 4 lines
drivers/net/af_xdp/rte_eth_af_xdp.c new file +4 -0
+	if (parse_parameters(kvlist, if_name, &xsk_queue_idx) < 0) {
+		AF_XDP_LOG(ERR, "Invalid kvargs value\n");
+		return -EINVAL;
+	}

At this point we don't know if the user provided a "if_name" value, needs a way to confirm mandantory devargs provided before continue.

<...>

drivers/net/af_xdp/rte_eth_af_xdp.c line 922

Quoted 2 lines
drivers/net/af_xdp/rte_eth_af_xdp.c new file +2 -0
+RTE_PMD_REGISTER_VDEV(net_af_xdp, pmd_af_xdp_drv);
+RTE_PMD_REGISTER_PARAM_STRING(eth_af_xdp,

s/eth_af_xdp/net_af_xdp

drivers/net/af_xdp/rte_eth_af_xdp.c line 928

Quoted 6 lines
drivers/net/af_xdp/rte_eth_af_xdp.c new file +6 -0
+			      "iface=<string> "
+			      "queue=<int> ");
+
+RTE_INIT(af_xdp_init_log)
+{
+	af_xdp_logtype = rte_log_register("pmd.net.xdp");

why not "pmd.net.af_xdp"?

<...>

mk/rte.app.mk _LDLIBS-$(CONFIG_RTE_LIBRTE_DPAA2_MEMPOOL) += -lrte_mempool_dpaa2 · line 146

Quoted 5 lines
mk/rte.app.mk +1 -0
@@ -143,6 +143,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_DPAA2_MEMPOOL)  += -lrte_mempool_dpaa2
 endif
 
 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AF_PACKET)  += -lrte_pmd_af_packet
+_LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AF_XDP)     += -lrte_pmd_af_xdp -lelf -lbpf

Is "-lelf" still required?

#131 lore raw

Re: [PATCH v7 1/5] net/af_xdp: introduce AF XDP PMD driver

Quoted 10 lines · Ferruh Yigit

Review _LDLIBS-$(CONFIG_RTE_LIBRTE_DPAA2_MEMPOOL) += · line 148

Quoted 8 lines
(quoted diff) +1 -3
@@ -143,6 +143,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_DPAA2_MEMPOOL)  +=
-lrte_mempool_dpaa2
  endif
 
  _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AF_PACKET)  +=
-lrte_pmd_af_packet
+_LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AF_XDP)     += -lrte_pmd_af_xdp
-lelf -lbpf

Is "-lelf" still required?

This was fixed upstream in the bpf tree by Björn:

https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git/commit/?id=89dedaef49d36adc2bb5e7e4c38b52fa3013c7c8

Signature · 2 lines
Kind regards,
Luca Boccassi
#132 lore raw

Re: [PATCH v7 1/5] net/af_xdp: introduce AF XDP PMD driver

Quoted 12 lines · Luca Boccassi
Quoted 10 lines · Ferruh Yigit

Review _LDLIBS-$(CONFIG_RTE_LIBRTE_DPAA2_MEMPOOL) += · line 148

Quoted 8 lines
(quoted diff) +1 -3
@@ -143,6 +143,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_DPAA2_MEMPOOL)  +=
-lrte_mempool_dpaa2
  endif
 
  _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AF_PACKET)  +=
-lrte_pmd_af_packet
+_LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AF_XDP)     += -lrte_pmd_af_xdp
-lelf -lbpf

Is "-lelf" still required?

Quoted 4 lines

This was fixed upstream in the bpf tree by Björn:

https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git/commit/?id=89dedaef49d36adc2bb5e7e4c38b52fa3013c7c8

ahh, but this is bpf tree. So it means this change won't be in 5.1 right? Should we add this back for 5.1?

#133 lore raw

Re: [PATCH v7 1/5] net/af_xdp: introduce AF XDP PMD driver

In reply to Ferruh Yigit

Hi, Ferruh

Thanks for the comments.

Quoted 24 lines · Ferruh Yigit
Quoted 11 lines · Xiaolong Ye

Add a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux. More info about AF_XDP, please refer to [1] [2].

This is the vanilla version PMD which just uses a raw buffer registered as the umem.

[1] https://fosdem.org/2018/schedule/event/af_xdp/
[2] https://lwn.net/Articles/745934/

Hi Xiaolong,

Mostly looks good, only there are a few comments on minor issues, can you please check them?

<...>

Quoted 4 lines
MAINTAINERS +0 -0
@@ -474,6 +474,12 @@ M: John W. Linville <[email protected]>
 F: drivers/net/af_packet/
 F: doc/guides/nics/features/afpacket.ini
 
Quoted 7 lines

MAINTAINERS M: John W. Linville <[email protected]> · line 481

Quoted 5 lines
MAINTAINERS +5 -0
+Linux AF_XDP
+M: Xiaolong Ye <[email protected]>
+M: Qi Zhang <[email protected]>
+F: drivers/net/af_xdp/
+F: doc/guides/nics/features/af_xdp.rst

Can you please add .ini file too?

Will add.

Quoted 11 lines

<...>

drivers/net/af_xdp/rte_eth_af_xdp.c line 117

Quoted 5 lines
drivers/net/af_xdp/rte_eth_af_xdp.c new file +5 -0
+static const char * const valid_arguments[] = {
+	ETH_AF_XDP_IFACE_ARG,
+	ETH_AF_XDP_QUEUE_IDX_ARG,
+	NULL
+};

Minor issue, but can you please keep close the .*ARG defines and this structure, either move this up or move defines down just above this struct?

Got it, I'll put them together.

Quoted 10 lines

drivers/net/af_xdp/rte_eth_af_xdp.c line 124

Quoted 8 lines
drivers/net/af_xdp/rte_eth_af_xdp.c new file +7 -0
+
+static struct rte_eth_link pmd_link = {
+	.link_speed = ETH_SPEED_NUM_10G,
+	.link_duplex = ETH_LINK_FULL_DUPLEX,
+	.link_status = ETH_LINK_DOWN,
+	.link_autoneg = ETH_LINK_AUTONEG
+};

Can this variable be const?

Will do.

Quoted 15 lines

<...>

drivers/net/af_xdp/rte_eth_af_xdp.c line 339

Quoted 10 lines
drivers/net/af_xdp/rte_eth_af_xdp.c new file +10 -0
+static void
+eth_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
+{
+	struct pmd_internals *internals = dev->data->dev_private;
+
+	dev_info->if_index = internals->if_index;
+	dev_info->max_mac_addrs = 1;
+	dev_info->max_rx_pktlen = ETH_FRAME_LEN;
+	dev_info->max_rx_queues = 1;
+	dev_info->max_tx_queues = 1;

What do you think documenting the only single queue supported limitation?

I've mentioned the single queue limitation in af_xdp.rst, or you mean we also need to comment it here?

Quoted 8 lines

<...>

Review

Quoted 2 lines
(quoted diff) +2 -0
+static void remove_xdp_program(struct pmd_internals *internals)
+{

According coding convention it should be:

Quoted 7 lines

static void
remove_xdp_program(struct pmd_internals *internals) {

There is a usage of mixture, can you please update them according convention?

<...>

Will do.

Quoted 10 lines

drivers/net/af_xdp/rte_eth_af_xdp.c line 874

Quoted 5 lines
drivers/net/af_xdp/rte_eth_af_xdp.c new file +4 -0
+	if (parse_parameters(kvlist, if_name, &xsk_queue_idx) < 0) {
+		AF_XDP_LOG(ERR, "Invalid kvargs value\n");
+		return -EINVAL;
+	}

At this point we don't know if the user provided a "if_name" value, needs a way to confirm mandantory devargs provided before continue.

<...>

Got it, will do.

Quoted 5 lines

drivers/net/af_xdp/rte_eth_af_xdp.c line 922

Quoted 3 lines
drivers/net/af_xdp/rte_eth_af_xdp.c new file +2 -0
+RTE_PMD_REGISTER_VDEV(net_af_xdp, pmd_af_xdp_drv);
+RTE_PMD_REGISTER_PARAM_STRING(eth_af_xdp,

s/eth_af_xdp/net_af_xdp

Got it.

Quoted 9 lines

drivers/net/af_xdp/rte_eth_af_xdp.c line 928

Quoted 7 lines
drivers/net/af_xdp/rte_eth_af_xdp.c new file +6 -0
+			      "iface=<string> "
+			      "queue=<int> ");
+
+RTE_INIT(af_xdp_init_log)
+{
+	af_xdp_logtype = rte_log_register("pmd.net.xdp");

why not "pmd.net.af_xdp"?

Will do.

Quoted 10 lines

<...>

mk/rte.app.mk _LDLIBS-$(CONFIG_RTE_LIBRTE_DPAA2_MEMPOOL) += -lrte_mempool_dpaa2 · line 146

Quoted 5 lines
mk/rte.app.mk +1 -0
@@ -143,6 +143,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_DPAA2_MEMPOOL)  += -lrte_mempool_dpaa2
 endif
 
 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AF_PACKET)  += -lrte_pmd_af_packet
+_LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AF_XDP)     += -lrte_pmd_af_xdp -lelf -lbpf

Is "-lelf" still required?

Will remove it since Bjorn hasn't sent the fix patch to kernel community.

Thanks,
Xiaolong

#134 lore raw

Re: [PATCH v7 1/5] net/af_xdp: introduce AF XDP PMD driver

Quoted 13 lines · Ye Xiaolong
Quoted 13 lines

<...>

drivers/net/af_xdp/rte_eth_af_xdp.c line 339

Quoted 10 lines
drivers/net/af_xdp/rte_eth_af_xdp.c new file +10 -0
+static void
+eth_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
+{
+	struct pmd_internals *internals = dev->data->dev_private;
+
+	dev_info->if_index = internals->if_index;
+	dev_info->max_mac_addrs = 1;
+	dev_info->max_rx_pktlen = ETH_FRAME_LEN;
+	dev_info->max_rx_queues = 1;
+	dev_info->max_tx_queues = 1;

What do you think documenting the only single queue supported limitation?

Quoted 3 lines

I've mentioned the single queue limitation in af_xdp.rst, or you mean we also need to comment it here?

I missed it in af_xdp.rst, if documented there I think it is OK.

#135 lore raw

PATCH v7 2/5 lib/mbuf: introduce helper to create mempool with flags

In reply to Xiaolong Ye

This allows applications to create mbuf mempool with specific flags such as MEMPOOL_F_NO_SPREAD if they want fixed size memory objects.

---
 lib/librte_mbuf/rte_mbuf.c           | 29 ++++++++++++++----
 lib/librte_mbuf/rte_mbuf.h           | 45 ++++++++++++++++++++++++++++
 lib/librte_mbuf/rte_mbuf_version.map |  1 +
 3 files changed, 70 insertions(+), 5 deletions(-)
lib/librte_mbuf/rte_mbuf.c +24 -5
index 21f6f7404..c1db9e298 100644
@@ -106,11 +106,10 @@ rte_pktmbuf_init(struct rte_mempool *mp,
 	m->next = NULL;
 }
 
-/* Helper to create a mbuf pool with given mempool ops name*/
-struct rte_mempool *
-rte_pktmbuf_pool_create_by_ops(const char *name, unsigned int n,
+static struct rte_mempool *
+rte_pktmbuf_pool_create_by_ops_with_flags(const char *name, unsigned int n,
 	unsigned int cache_size, uint16_t priv_size, uint16_t data_room_size,
-	int socket_id, const char *ops_name)
+	unsigned int flags, int socket_id, const char *ops_name)
 {
 	struct rte_mempool *mp;
 	struct rte_pktmbuf_pool_private mbp_priv;
@@ -130,7 +129,7 @@ rte_pktmbuf_pool_create_by_ops(const char *name, unsigned int n,
 	mbp_priv.mbuf_priv_size = priv_size;
 
 	mp = rte_mempool_create_empty(name, n, elt_size, cache_size,
-		 sizeof(struct rte_pktmbuf_pool_private), socket_id, 0);
+		 sizeof(struct rte_pktmbuf_pool_private), socket_id, flags);
 	if (mp == NULL)
 		return NULL;
 
@@ -157,6 +156,16 @@ rte_pktmbuf_pool_create_by_ops(const char *name, unsigned int n,
 	return mp;
 }
 
+/* Helper to create a mbuf pool with given mempool ops name*/
+struct rte_mempool *
+rte_pktmbuf_pool_create_by_ops(const char *name, unsigned int n,
+	unsigned int cache_size, uint16_t priv_size, uint16_t data_room_size,
+	int socket_id, const char *ops_name)
+{
+	return rte_pktmbuf_pool_create_by_ops_with_flags(name, n, cache_size,
+			 priv_size, data_room_size, 0, socket_id, ops_name);
+}
+
 /* helper to create a mbuf pool */
 struct rte_mempool *
 rte_pktmbuf_pool_create(const char *name, unsigned int n,
@@ -167,6 +176,16 @@ rte_pktmbuf_pool_create(const char *name, unsigned int n,
 			data_room_size, socket_id, NULL);
 }
 
+/* helper to create a mbuf pool with flags (e.g. NO_SPREAD) */
+struct rte_mempool * __rte_experimental
+rte_pktmbuf_pool_create_with_flags(const char *name, unsigned int n,
+	unsigned int cache_size, uint16_t priv_size, uint16_t data_room_size,
+	unsigned int flags, int socket_id)
+{
+	return rte_pktmbuf_pool_create_by_ops_with_flags(name, n, cache_size,
+			priv_size, data_room_size, flags, socket_id, NULL);
+}
+
 /* do some sanity checks on a mbuf: panic if it fails */
 void
 rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header)
lib/librte_mbuf/rte_mbuf.h +45 -0

51 lines not on this page · raw message

lib/librte_mbuf/rte_mbuf_version.map +1 -0
index 2662a37bf..2579538e0 100644
@@ -50,4 +50,5 @@ EXPERIMENTAL {
 	global:
 
 	rte_mbuf_check;
+	rte_pktmbuf_pool_create_with_flags;
 } DPDK_18.08;
Signature · 1 line
2.17.1
#136 lore raw

Re: [PATCH v7 2/5] lib/mbuf: introduce helper to create mempool with flags

Quoted 5 lines · Xiaolong Ye

This allows applications to create mbuf mempool with specific flags such as MEMPOOL_F_NO_SPREAD if they want fixed size memory objects.

Hi Olivier,

Can you please check this patch?
I would like to get the PMD for rc1 but it has a dependency to this mbuf change.

Thanks,
ferruh

#137 lore raw

PATCH v7 3/5 lib/mempool: allow page size aligned mempool

In reply to Xiaolong Ye

Allow create a mempool with page size aligned base address.

---
 lib/librte_mempool/rte_mempool.c | 3 +++
 lib/librte_mempool/rte_mempool.h | 1 +
 2 files changed, 4 insertions(+)
lib/librte_mempool/rte_mempool.c +3 -0
index 683b216f9..cfbb49ea5 100644
@@ -543,6 +543,9 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 		if (try_contig)
 			flags |= RTE_MEMZONE_IOVA_CONTIG;
 
+		if (mp->flags & MEMPOOL_CHUNK_F_PAGE_ALIGN)
+			align = RTE_MAX(align, (size_t)getpagesize());
+
 		mz = rte_memzone_reserve_aligned(mz_name, mem_size,
 				mp->socket_id, flags, align);
 
lib/librte_mempool/rte_mempool.h +1 -0
index 7c9cd9a2f..47729f7c9 100644
@@ -264,6 +264,7 @@ struct rte_mempool {
 #define MEMPOOL_F_POOL_CREATED   0x0010 /**< Internal: pool is created. */
 #define MEMPOOL_F_NO_IOVA_CONTIG 0x0020 /**< Don't need IOVA contiguous objs. */
 #define MEMPOOL_F_NO_PHYS_CONTIG MEMPOOL_F_NO_IOVA_CONTIG /* deprecated */
+#define MEMPOOL_CHUNK_F_PAGE_ALIGN     0x0040 /**< Chunk's base address is page aligned */
 
 /**
  * @internal When debug is enabled, store some statistics.
Signature · 1 line
2.17.1
#138 lore raw

Re: [PATCH v7 3/5] lib/mempool: allow page size aligned mempool

Quoted 4 lines · Xiaolong Ye

Allow create a mempool with page size aligned base address.

Hi Andrew, Olivier,

Can you please check this patch,
It is adding a new mempool flag which is dependency for the pmd.

Thanks,
ferruh

#139 lore raw

Re: [PATCH v7 3/5] lib/mempool: allow page size aligned mempool

In reply to Xiaolong Ye
Quoted 28 lines · Xiaolong Ye

Allow create a mempool with page size aligned base address.

---
  lib/librte_mempool/rte_mempool.c | 3 +++
  lib/librte_mempool/rte_mempool.h | 1 +
  2 files changed, 4 insertions(+)
lib/librte_mempool/rte_mempool.c +3 -0
index 683b216f9..cfbb49ea5 100644
@@ -543,6 +543,9 @@ rte_mempool_populate_default(struct rte_mempool *mp)
  		if (try_contig)
  			flags |= RTE_MEMZONE_IOVA_CONTIG;
 
+		if (mp->flags & MEMPOOL_CHUNK_F_PAGE_ALIGN)
+			align = RTE_MAX(align, (size_t)getpagesize());
+
  		mz = rte_memzone_reserve_aligned(mz_name, mem_size,
  				mp->socket_id, flags, align);
 
lib/librte_mempool/rte_mempool.h +0 -0
index 7c9cd9a2f..47729f7c9 100644

lib/librte_mempool/rte_mempool.h struct rte_mempool { · line 267

Quoted 4 lines
lib/librte_mempool/rte_mempool.h +1 -0
@@ -264,6 +264,7 @@ struct rte_mempool {
  #define MEMPOOL_F_POOL_CREATED   0x0010 /**< Internal: pool is created. */
  #define MEMPOOL_F_NO_IOVA_CONTIG 0x0020 /**< Don't need IOVA contiguous objs. */
  #define MEMPOOL_F_NO_PHYS_CONTIG MEMPOOL_F_NO_IOVA_CONTIG /* deprecated */
+#define MEMPOOL_CHUNK_F_PAGE_ALIGN     0x0040 /**< Chunk's base address is page aligned */

Now the define name better explains what happens. I would name it MEMPOOL_F_CHUNK_PAGE_ALIGN to have MEMPOOL_F_ prefix for all flags, but it is minor. More important is what is behind and I have doubts that it is a right way to go.

I have already asked what is the final goal (but agree that question is unclear). Personally I doubt that the final goal is just having chunk page aligned.

It looks like the patch makes an assumption on how chunk is sliced into objects/elements and the property of chunk address allows to achieve some goal with elements start address. It looks very fragile and easily breakable with other flags (or no flags).

Also prefix should be just "mempool:", not "lib/mempool".

Andrew.

#140 lore raw

Re: [PATCH v7 3/5] lib/mempool: allow page size aligned mempool

Hi,

Quoted 42 lines · Andrew Rybchenko
Quoted 26 lines · Xiaolong Ye

Allow create a mempool with page size aligned base address.

---
  lib/librte_mempool/rte_mempool.c | 3 +++
  lib/librte_mempool/rte_mempool.h | 1 +
  2 files changed, 4 insertions(+)
lib/librte_mempool/rte_mempool.c +3 -0
index 683b216f9..cfbb49ea5 100644
@@ -543,6 +543,9 @@ rte_mempool_populate_default(struct rte_mempool *mp)
  		if (try_contig)
  			flags |= RTE_MEMZONE_IOVA_CONTIG;
+		if (mp->flags & MEMPOOL_CHUNK_F_PAGE_ALIGN)
+			align = RTE_MAX(align, (size_t)getpagesize());
+
  		mz = rte_memzone_reserve_aligned(mz_name, mem_size,
  				mp->socket_id, flags, align);
lib/librte_mempool/rte_mempool.h +0 -0
index 7c9cd9a2f..47729f7c9 100644

lib/librte_mempool/rte_mempool.h struct rte_mempool { · line 267

Quoted 4 lines
lib/librte_mempool/rte_mempool.h +1 -0
@@ -264,6 +264,7 @@ struct rte_mempool {
  #define MEMPOOL_F_POOL_CREATED   0x0010 /**< Internal: pool is created. */
  #define MEMPOOL_F_NO_IOVA_CONTIG 0x0020 /**< Don't need IOVA contiguous objs. */
  #define MEMPOOL_F_NO_PHYS_CONTIG MEMPOOL_F_NO_IOVA_CONTIG /* deprecated */
+#define MEMPOOL_CHUNK_F_PAGE_ALIGN     0x0040 /**< Chunk's base address is page aligned */

Now the define name better explains what happens. I would name it MEMPOOL_F_CHUNK_PAGE_ALIGN to have MEMPOOL_F_ prefix for all flags, but it is minor. More important is what is behind and I have doubts that it is
a right way to go.

I have already asked what is the final goal (but agree that question is unclear).
Personally I doubt that the final goal is just having chunk page aligned.

Quoted 6 lines

It looks like the patch makes an assumption on how chunk is sliced into objects/elements and the property of chunk address allows to achieve some goal with elements start address. It looks very fragile and easily breakable with other flags (or no flags).

Also prefix should be just "mempool:", not "lib/mempool".

+1
I agree with Andrew. Please see my comment in patch 4.

Regards,
Olivier

#141 lore raw

PATCH v7 4/5 net/af_xdp: use mbuf mempool for buffer management

In reply to Xiaolong Ye

Now, af_xdp registered memory buffer is managed by rte_mempool. mbuf allocated from rte_mempool can be converted to xdp_desc's address and vice versa.

---
 drivers/net/af_xdp/rte_eth_af_xdp.c | 117 +++++++++++++++++-----------
 1 file changed, 72 insertions(+), 45 deletions(-)
drivers/net/af_xdp/rte_eth_af_xdp.c +72 -45
index 47a496ed7..a1fda9212 100644
@@ -48,7 +48,11 @@ static int af_xdp_logtype;
 
 #define ETH_AF_XDP_FRAME_SIZE		XSK_UMEM__DEFAULT_FRAME_SIZE
 #define ETH_AF_XDP_NUM_BUFFERS		4096
-#define ETH_AF_XDP_DATA_HEADROOM	0
+/* mempool hdrobj size (64 bytes) + sizeof(struct rte_mbuf) (128 bytes) */
+#define ETH_AF_XDP_MBUF_OVERHEAD	192
+/* data start from offset 320 (192 + 128) bytes */
+#define ETH_AF_XDP_DATA_HEADROOM				\
+	(ETH_AF_XDP_MBUF_OVERHEAD + RTE_PKTMBUF_HEADROOM)
 #define ETH_AF_XDP_DFLT_NUM_DESCS	XSK_RING_CONS__DEFAULT_NUM_DESCS
 #define ETH_AF_XDP_DFLT_QUEUE_IDX	0
 
@@ -61,7 +65,7 @@ struct xsk_umem_info {
 	struct xsk_ring_prod fq;
 	struct xsk_ring_cons cq;
 	struct xsk_umem *umem;
-	struct rte_ring *buf_ring;
+	struct rte_mempool *mb_pool;
 	void *buffer;
 };
 
@@ -123,10 +127,30 @@ static struct rte_eth_link pmd_link = {
 	.link_autoneg = ETH_LINK_AUTONEG
 };
 
+static inline struct rte_mbuf *
+addr_to_mbuf(struct xsk_umem_info *umem, uint64_t addr)
+{
+	uint64_t offset = (addr / ETH_AF_XDP_FRAME_SIZE *
+			ETH_AF_XDP_FRAME_SIZE);
+	struct rte_mbuf *mbuf = (struct rte_mbuf *)((uint64_t)umem->buffer +
+				    offset + ETH_AF_XDP_MBUF_OVERHEAD -
+				    sizeof(struct rte_mbuf));
+	mbuf->data_off = addr - offset - ETH_AF_XDP_MBUF_OVERHEAD;
+	return mbuf;
+}
+
+static inline uint64_t
+mbuf_to_addr(struct xsk_umem_info *umem, struct rte_mbuf *mbuf)
+{
+	return (uint64_t)mbuf->buf_addr + mbuf->data_off -
+		(uint64_t)umem->buffer;
+}
+
 static inline int
 reserve_fill_queue(struct xsk_umem_info *umem, int reserve_size)
 {
 	struct xsk_ring_prod *fq = &umem->fq;
+	struct rte_mbuf *mbuf;
 	uint32_t idx;
 	int i, ret;
 
@@ -138,13 +162,15 @@ reserve_fill_queue(struct xsk_umem_info *umem, int reserve_size)
 
 	for (i = 0; i < reserve_size; i++) {
 		__u64 *fq_addr;
-		void *addr = NULL;
-		if (rte_ring_dequeue(umem->buf_ring, &addr)) {
+		uint64_t addr;
+		mbuf = rte_pktmbuf_alloc(umem->mb_pool);
+		if (unlikely(mbuf == NULL)) {
 			i--;
 			break;
 		}
+		addr = mbuf_to_addr(umem, mbuf);
 		fq_addr = xsk_ring_prod__fill_addr(fq, idx++);
-		*fq_addr = (uint64_t)addr;
+		*fq_addr = addr;
 	}
 
 	xsk_ring_prod__submit(fq, i);
@@ -196,7 +222,7 @@ eth_af_xdp_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		rx_bytes += len;
 		bufs[count++] = mbufs[i];
 
-		rte_ring_enqueue(umem->buf_ring, (void *)addr);
+		rte_pktmbuf_free(addr_to_mbuf(umem, addr));
 	}
 
 	xsk_ring_cons__release(rx, rcvd);
@@ -219,7 +245,7 @@ static void pull_umem_cq(struct xsk_umem_info *umem, int size)
 	for (i = 0; i < n; i++) {
 		uint64_t addr;
 		addr = *xsk_ring_cons__comp_addr(cq, idx_cq++);
-		rte_ring_enqueue(umem->buf_ring, (void *)addr);
+		rte_pktmbuf_free(addr_to_mbuf(umem, addr));
 	}
 
 	xsk_ring_cons__release(cq, n);
@@ -248,7 +274,7 @@ eth_af_xdp_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	struct pkt_tx_queue *txq = queue;
 	struct xsk_umem_info *umem = txq->pair->umem;
 	struct rte_mbuf *mbuf;
-	void *addrs[ETH_AF_XDP_TX_BATCH_SIZE];
+	struct rte_mbuf *mbuf_to_tx;
 	unsigned long tx_bytes = 0;
 	int i, valid = 0;
 	uint32_t idx_tx;
@@ -257,11 +283,6 @@ eth_af_xdp_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 
 	pull_umem_cq(umem, nb_pkts);
 
-	nb_pkts = rte_ring_dequeue_bulk(umem->buf_ring, addrs,
-					nb_pkts, NULL);
-	if (nb_pkts == 0)
-		return 0;
-
 	if (xsk_ring_prod__reserve(&txq->tx, nb_pkts, &idx_tx) != nb_pkts) {
 		kick_tx(txq);
 		return 0;
@@ -275,7 +296,12 @@ eth_af_xdp_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		desc = xsk_ring_prod__tx_desc(&txq->tx, idx_tx + i);
 		mbuf = bufs[i];
 		if (mbuf->pkt_len <= buf_len) {
-			desc->addr = (uint64_t)addrs[valid];
+			mbuf_to_tx = rte_pktmbuf_alloc(umem->mb_pool);
+			if (unlikely(mbuf_to_tx == NULL)) {
+				rte_pktmbuf_free(mbuf);
+				continue;
+			}
+			desc->addr = mbuf_to_addr(umem, mbuf_to_tx);
 			desc->len = mbuf->pkt_len;
 			pkt = xsk_umem__get_data(umem->buffer,
 						 desc->addr);
@@ -291,10 +317,6 @@ eth_af_xdp_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 
 	kick_tx(txq);
 
-	if (valid < nb_pkts)
-		rte_ring_enqueue_bulk(umem->buf_ring, &addrs[valid],
-				 nb_pkts - valid, NULL);
-
 	txq->stats.err_pkts += nb_pkts - valid;
 	txq->stats.tx_pkts += valid;
 	txq->stats.tx_bytes += tx_bytes;
@@ -443,16 +465,29 @@ eth_link_update(struct rte_eth_dev *dev __rte_unused,
 
 static void xdp_umem_destroy(struct xsk_umem_info *umem)
 {
-	free(umem->buffer);
-	umem->buffer = NULL;
-
-	rte_ring_free(umem->buf_ring);
-	umem->buf_ring = NULL;
+	rte_mempool_free(umem->mb_pool);
+	umem->mb_pool = NULL;
 
 	rte_free(umem);
 	umem = NULL;
 }
 
+static inline uint64_t get_base_addr(struct rte_mempool *mp)
+{
+	struct rte_mempool_memhdr *memhdr;
+
+	memhdr = STAILQ_FIRST(&mp->mem_list);
+	return (uint64_t)(memhdr->addr);
+}
+
+static inline uint64_t get_len(struct rte_mempool *mp)
+{
+	struct rte_mempool_memhdr *memhdr;
+
+	memhdr = STAILQ_FIRST(&mp->mem_list);
+	return (uint64_t)(memhdr->len);
+}
+
 static struct xsk_umem_info *xdp_umem_configure(void)
 {
 	struct xsk_umem_info *umem;
@@ -461,9 +496,8 @@ static struct xsk_umem_info *xdp_umem_configure(void)
 		.comp_size = ETH_AF_XDP_DFLT_NUM_DESCS,
 		.frame_size = ETH_AF_XDP_FRAME_SIZE,
 		.frame_headroom = ETH_AF_XDP_DATA_HEADROOM };
-	void *bufs = NULL;
+	void *base_addr = NULL;
 	int ret;
-	uint64_t i;
 
 	umem = rte_zmalloc_socket("umem", sizeof(*umem), 0, rte_socket_id());
 	if (umem == NULL) {
@@ -471,26 +505,20 @@ static struct xsk_umem_info *xdp_umem_configure(void)
 		return NULL;
 	}
 
-	umem->buf_ring = rte_ring_create("af_xdp_ring",
-					 ETH_AF_XDP_NUM_BUFFERS,
-					 SOCKET_ID_ANY,
-					 0x0);
-	if (umem->buf_ring == NULL) {
-		AF_XDP_LOG(ERR, "Failed to create rte_ring\n");
+	umem->mb_pool = rte_pktmbuf_pool_create_with_flags("af_xdp_mempool",
+			ETH_AF_XDP_NUM_BUFFERS,
+			250, 0,
+			ETH_AF_XDP_FRAME_SIZE -
+			ETH_AF_XDP_MBUF_OVERHEAD,
+			MEMPOOL_F_NO_SPREAD | MEMPOOL_CHUNK_F_PAGE_ALIGN,
+			SOCKET_ID_ANY);
+	if (umem->mb_pool == NULL || umem->mb_pool->nb_mem_chunks != 1) {
+		AF_XDP_LOG(ERR, "Failed to create mempool\n");
 		goto err;
 	}
+	base_addr = (void *)get_base_addr(umem->mb_pool);
 
-	for (i = 0; i < ETH_AF_XDP_NUM_BUFFERS; i++)
-		rte_ring_enqueue(umem->buf_ring,
-				 (void *)(i * ETH_AF_XDP_FRAME_SIZE +
-					  ETH_AF_XDP_DATA_HEADROOM));
-
-	if (posix_memalign(&bufs, getpagesize(),
-			   ETH_AF_XDP_NUM_BUFFERS * ETH_AF_XDP_FRAME_SIZE)) {
-		AF_XDP_LOG(ERR, "Failed to allocate memory pool.\n");
-		goto err;
-	}
-	ret = xsk_umem__create(&umem->umem, bufs,
+	ret = xsk_umem__create(&umem->umem, base_addr,
 			       ETH_AF_XDP_NUM_BUFFERS * ETH_AF_XDP_FRAME_SIZE,
 			       &umem->fq, &umem->cq,
 			       &usr_config);
@@ -499,7 +527,7 @@ static struct xsk_umem_info *xdp_umem_configure(void)
 		AF_XDP_LOG(ERR, "Failed to create umem");
 		goto err;
 	}
-	umem->buffer = bufs;
+	umem->buffer = base_addr;
 
 	return umem;
 
@@ -903,10 +931,9 @@ rte_pmd_af_xdp_remove(struct rte_vdev_device *dev)
 
 	internals = eth_dev->data->dev_private;
 
-	rte_ring_free(internals->umem->buf_ring);
-	rte_free(internals->umem->buffer);
 	rte_free(internals->umem);
 
+	rte_mempool_free(internals->umem->mb_pool);
 	rte_eth_dev_release_port(eth_dev);
 
 
Signature · 1 line
2.17.1
#142 lore raw

PATCH v7 5/5 net/af_xdp: enable zero copy

In reply to Xiaolong Ye

Try to check if external mempool (from rx_queue_setup) is fit for af_xdp, if it is, it will be registered to af_xdp socket directly and there will be no packet data copy on Rx and Tx.

---
 drivers/net/af_xdp/rte_eth_af_xdp.c | 130 ++++++++++++++++++++--------
 1 file changed, 96 insertions(+), 34 deletions(-)
drivers/net/af_xdp/rte_eth_af_xdp.c +96 -34
index a1fda9212..c6ade4c94 100644
@@ -67,6 +67,7 @@ struct xsk_umem_info {
 	struct xsk_umem *umem;
 	struct rte_mempool *mb_pool;
 	void *buffer;
+	uint8_t zc;
 };
 
 struct rx_stats {
@@ -85,6 +86,7 @@ struct pkt_rx_queue {
 
 	struct pkt_tx_queue *pair;
 	uint16_t queue_idx;
+	uint8_t zc;
 };
 
 struct tx_stats {
@@ -202,7 +204,9 @@ eth_af_xdp_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	if (xsk_prod_nb_free(fq, free_thresh) >= free_thresh)
 		(void)reserve_fill_queue(umem, ETH_AF_XDP_RX_BATCH_SIZE);
 
-	if (unlikely(rte_pktmbuf_alloc_bulk(rxq->mb_pool, mbufs, rcvd) != 0))
+	if (!rxq->zc &&
+		unlikely(rte_pktmbuf_alloc_bulk(rxq->mb_pool,
+				mbufs, rcvd) != 0))
 		return 0;
 
 	for (i = 0; i < rcvd; i++) {
@@ -216,13 +220,23 @@ eth_af_xdp_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		len = desc->len;
 		pkt = xsk_umem__get_data(rxq->umem->buffer, addr);
 
-		rte_memcpy(rte_pktmbuf_mtod(mbufs[i], void *), pkt, len);
-		rte_pktmbuf_pkt_len(mbufs[i]) = len;
-		rte_pktmbuf_data_len(mbufs[i]) = len;
-		rx_bytes += len;
-		bufs[count++] = mbufs[i];
-
-		rte_pktmbuf_free(addr_to_mbuf(umem, addr));
+		if (rxq->zc) {
+			struct rte_mbuf *mbuf;
+			mbuf = addr_to_mbuf(rxq->umem, addr);
+			rte_pktmbuf_pkt_len(mbuf) = len;
+			rte_pktmbuf_data_len(mbuf) = len;
+			rx_bytes += len;
+			bufs[count++] = mbuf;
+		} else {
+			rte_memcpy(rte_pktmbuf_mtod(mbufs[i], void *),
+					pkt, len);
+			rte_pktmbuf_pkt_len(mbufs[i]) = len;
+			rte_pktmbuf_data_len(mbufs[i]) = len;
+			rx_bytes += len;
+			bufs[count++] = mbufs[i];
+
+			rte_pktmbuf_free(addr_to_mbuf(umem, addr));
+		}
 	}
 
 	xsk_ring_cons__release(rx, rcvd);
@@ -295,22 +309,29 @@ eth_af_xdp_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 					- ETH_AF_XDP_DATA_HEADROOM;
 		desc = xsk_ring_prod__tx_desc(&txq->tx, idx_tx + i);
 		mbuf = bufs[i];
-		if (mbuf->pkt_len <= buf_len) {
-			mbuf_to_tx = rte_pktmbuf_alloc(umem->mb_pool);
-			if (unlikely(mbuf_to_tx == NULL)) {
-				rte_pktmbuf_free(mbuf);
-				continue;
-			}
-			desc->addr = mbuf_to_addr(umem, mbuf_to_tx);
+		if (txq->pair->zc && mbuf->pool == umem->mb_pool) {
+			desc->addr = mbuf_to_addr(umem, mbuf);
 			desc->len = mbuf->pkt_len;
-			pkt = xsk_umem__get_data(umem->buffer,
-						 desc->addr);
-			rte_memcpy(pkt, rte_pktmbuf_mtod(mbuf, void *),
-			       desc->len);
 			valid++;
 			tx_bytes += mbuf->pkt_len;
+		} else {
+			if (mbuf->pkt_len <= buf_len) {
+				mbuf_to_tx = rte_pktmbuf_alloc(umem->mb_pool);
+				if (unlikely(mbuf_to_tx == NULL)) {
+					rte_pktmbuf_free(mbuf);
+					continue;
+				}
+				desc->addr = mbuf_to_addr(umem, mbuf_to_tx);
+				desc->len = mbuf->pkt_len;
+				pkt = xsk_umem__get_data(umem->buffer,
+							 desc->addr);
+				memcpy(pkt, rte_pktmbuf_mtod(mbuf, void *),
+				       desc->len);
+				valid++;
+				tx_bytes += mbuf->pkt_len;
+			}
+			rte_pktmbuf_free(mbuf);
 		}
-		rte_pktmbuf_free(mbuf);
 	}
 
 	xsk_ring_prod__submit(&txq->tx, nb_pkts);
@@ -488,7 +509,7 @@ static inline uint64_t get_len(struct rte_mempool *mp)
 	return (uint64_t)(memhdr->len);
 }
 
-static struct xsk_umem_info *xdp_umem_configure(void)
+static struct xsk_umem_info *xdp_umem_configure(struct rte_mempool *mb_pool)
 {
 	struct xsk_umem_info *umem;
 	struct xsk_umem_config usr_config = {
@@ -505,16 +526,23 @@ static struct xsk_umem_info *xdp_umem_configure(void)
 		return NULL;
 	}
 
-	umem->mb_pool = rte_pktmbuf_pool_create_with_flags("af_xdp_mempool",
-			ETH_AF_XDP_NUM_BUFFERS,
-			250, 0,
-			ETH_AF_XDP_FRAME_SIZE -
-			ETH_AF_XDP_MBUF_OVERHEAD,
-			MEMPOOL_F_NO_SPREAD | MEMPOOL_CHUNK_F_PAGE_ALIGN,
-			SOCKET_ID_ANY);
-	if (umem->mb_pool == NULL || umem->mb_pool->nb_mem_chunks != 1) {
-		AF_XDP_LOG(ERR, "Failed to create mempool\n");
-		goto err;
+	if (!mb_pool) {
+		umem->mb_pool = rte_pktmbuf_pool_create_with_flags("af_xdp_mempool",
+				ETH_AF_XDP_NUM_BUFFERS,
+				250, 0,
+				ETH_AF_XDP_FRAME_SIZE -
+				ETH_AF_XDP_MBUF_OVERHEAD,
+				MEMPOOL_F_NO_SPREAD | MEMPOOL_CHUNK_F_PAGE_ALIGN,
+				SOCKET_ID_ANY);
+
+		if (umem->mb_pool == NULL ||
+				umem->mb_pool->nb_mem_chunks != 1) {
+			AF_XDP_LOG(ERR, "Failed to create mempool\n");
+			goto err;
+		}
+	} else {
+		umem->mb_pool = mb_pool;
+		umem->zc = 1;
 	}
 	base_addr = (void *)get_base_addr(umem->mb_pool);
 
@@ -536,16 +564,43 @@ static struct xsk_umem_info *xdp_umem_configure(void)
 	return NULL;
 }
 
+static uint8_t
+check_mempool_zc(struct rte_mempool *mp)
+{
+	RTE_ASSERT(mp);
+
+	/* must continues */
+	if (mp->nb_mem_chunks > 1)
+		return 0;
+
+	/* check header size */
+	if (mp->header_size != RTE_CACHE_LINE_SIZE)
+		return 0;
+
+	/* check base address */
+	if ((uint64_t)get_base_addr(mp) % getpagesize() != 0)
+		return 0;
+
+	/* check chunk size */
+	if ((mp->elt_size + mp->header_size + mp->trailer_size) %
+	    ETH_AF_XDP_FRAME_SIZE != 0)
+		return 0;
+
+	return 1;
+}
+
 static int
 xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
-	      int ring_size)
+	      int ring_size, struct rte_mempool *mb_pool)
 {
 	struct xsk_socket_config cfg;
 	struct pkt_tx_queue *txq = rxq->pair;
+	struct rte_mempool *mp;
 	int ret = 0;
 	int reserve_size;
 
-	rxq->umem = xdp_umem_configure();
+	mp = check_mempool_zc(mb_pool) ? mb_pool : NULL;
+	rxq->umem = xdp_umem_configure(mp);
 	if (rxq->umem == NULL)
 		return -ENOMEM;
 
@@ -622,7 +677,7 @@ eth_rx_queue_setup(struct rte_eth_dev *dev,
 
 	rxq->mb_pool = mb_pool;
 
-	if (xsk_configure(internals, rxq, nb_rx_desc)) {
+	if (xsk_configure(internals, rxq, nb_rx_desc, mb_pool)) {
 		AF_XDP_LOG(ERR, "Failed to configure xdp socket\n");
 		ret = -EINVAL;
 		goto err;
@@ -630,6 +685,13 @@ eth_rx_queue_setup(struct rte_eth_dev *dev,
 
 	internals->umem = rxq->umem;
 
+	if (mb_pool == internals->umem->mb_pool)
+		rxq->zc = internals->umem->zc;
+
+	if (rxq->zc)
+		AF_XDP_LOG(INFO,
+			"zero copy enabled on rx queue %d\n", rx_queue_id);
+
 	dev->data->rx_queues[rx_queue_id] = rxq;
 	return 0;
 
Signature · 1 line
2.17.1
#143 lore raw

Re: [PATCH v7 5/5] net/af_xdp: enable zero copy

Quoted 29 lines · Xiaolong Ye

Try to check if external mempool (from rx_queue_setup) is fit for af_xdp, if it is, it will be registered to af_xdp socket directly and there will be no packet data copy on Rx and Tx.

---
 drivers/net/af_xdp/rte_eth_af_xdp.c | 130 ++++++++++++++++++++--------
 1 file changed, 96 insertions(+), 34 deletions(-)
drivers/net/af_xdp/rte_eth_af_xdp.c +2 -0
index a1fda9212..c6ade4c94 100644
@@ -67,6 +67,7 @@ struct xsk_umem_info {
 	struct xsk_umem *umem;
 	struct rte_mempool *mb_pool;
 	void *buffer;
+	uint8_t zc;
 };
 
 struct rx_stats {
@@ -85,6 +86,7 @@ struct pkt_rx_queue {
 
 	struct pkt_tx_queue *pair;
 	uint16_t queue_idx;
+	uint8_t zc;
 };
 
 struct tx_stats {

<...>

drivers/net/af_xdp/rte_eth_af_xdp.c eth_rx_queue_setup(struct rte_eth_dev *dev, · line 694

Quoted 11 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +7 -0
@@ -630,6 +685,13 @@ eth_rx_queue_setup(struct rte_eth_dev *dev,
 
 	internals->umem = rxq->umem;
 
+	if (mb_pool == internals->umem->mb_pool)
+		rxq->zc = internals->umem->zc;
+
+	if (rxq->zc)
+		AF_XDP_LOG(INFO,
+			"zero copy enabled on rx queue %d\n", rx_queue_id);
+

The "zero copy" implemented in this patch, also the variable 'zc', is from 'af_xdp' umem to mbuf data via versa copy, right?
There is also another "zero copy" support in af_xdp, device to buffers... Do you think can these be confused with each other, should we have another log message and variable name for this one?
Indeed I can't think of a good name, but something like, "pmd/driver zero copy" & 'pmd_zc' ??

#144 lore raw

Re: [PATCH v7 5/5] net/af_xdp: enable zero copy

Quoted 37 lines · Ferruh Yigit
Quoted 29 lines · Xiaolong Ye

Try to check if external mempool (from rx_queue_setup) is fit for af_xdp, if it is, it will be registered to af_xdp socket directly and there will be no packet data copy on Rx and Tx.

---
 drivers/net/af_xdp/rte_eth_af_xdp.c | 130 ++++++++++++++++++++--------
 1 file changed, 96 insertions(+), 34 deletions(-)
drivers/net/af_xdp/rte_eth_af_xdp.c +2 -0
index a1fda9212..c6ade4c94 100644
@@ -67,6 +67,7 @@ struct xsk_umem_info {
 	struct xsk_umem *umem;
 	struct rte_mempool *mb_pool;
 	void *buffer;
+	uint8_t zc;
 };
 
 struct rx_stats {
@@ -85,6 +86,7 @@ struct pkt_rx_queue {
 
 	struct pkt_tx_queue *pair;
 	uint16_t queue_idx;
+	uint8_t zc;
 };
 
 struct tx_stats {

<...>

Quoted 4 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +0 -0
@@ -630,6 +685,13 @@ eth_rx_queue_setup(struct rte_eth_dev *dev,
 
 	internals->umem = rxq->umem;
 
Quoted 15 lines

drivers/net/af_xdp/rte_eth_af_xdp.c eth_rx_queue_setup(struct rte_eth_dev *dev, · line 694

Quoted 7 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +7 -0
+	if (mb_pool == internals->umem->mb_pool)
+		rxq->zc = internals->umem->zc;
+
+	if (rxq->zc)
+		AF_XDP_LOG(INFO,
+			"zero copy enabled on rx queue %d\n", rx_queue_id);
+

The "zero copy" implemented in this patch, also the variable 'zc', is from 'af_xdp' umem to mbuf data via versa copy, right?
There is also another "zero copy" support in af_xdp, device to buffers... Do you think can these be confused with each other, should we have another log message and variable name for this one?
Indeed I can't think of a good name, but something like, "pmd/driver zero copy" & 'pmd_zc' ??

That's a good suggestion, will adopt it.

Thanks,
Xiaolong

#145 lore raw

v8 cover AF_XDP PMD

In reply to Xiaolong Ye

Hi, all

Overview
========

This patchset adds a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux, see below links [1] [2] for details of AF_XDP introduction:

AF_XDP roadmap
==============
- AF_XDP is included in upstream kernel since 4.18, and AF_XDP support in libbpf has been merged in v5.1-rc1.
- Now i40e and ixgbe drivers have supported zero copy mode.

Change logs
===========

v8:
- address Ferruh's comments on V7
- replace posix_memalign with rte_memzone_reserve_aligned to get better performance
- keep the first patch only as Oliver suggested as zero copy part implementation is still in suspense, we may provide the related patch later.

v7:
- mention mtu limitation in af_xdp.rst
- fix the vdev name in af_xdp.rst

V6:

- remove the newline in AF_XDP_LOG definition to avoid double new lines issue.
- rename MEMPOOL_F_PAGE_ALIGN to MEMPOOL_CHUNK_F_PAGE_ALIGN.

V5:

- disable AF_XDP pmd by default due to it requires kernel more recent than minimum kernel version supported by DPDK
- address other review comments of Maxime

V4:

- change vdev name to net_af_xdp
- adopt dynamic log type for all logging
- Fix other style issues raised by Stephen

V3:

- Fix all style issues pointed by Stephen, Mattias, David.
- Drop the testpmd change as we'll adopt Jerin's suggestion to add a new mempool driver to handle the application use of AF_XDP's zero copy feature.

V2:
- Fix a NULL pointer reference crash issue
- Fix txonly stop sending traffic in zc mode
- Refactor rte_mbuf.c to avoid ABI breakage.
- Fix multiple style issues pointed by Ferruh, David, Stephen, Luca.

changes vs RFC sent by Qi last Aug:

- Re-work base on AF_XDP's interface changes since the new libbpf has provided higher-level APIs that hide many of the details of the AP_XDP uapi. After the rework, it helps to reduce 300+ lines of code.

- multi-queues is not supported due to current libbpf doesn't support multi-sockets on a single umem.

- No extra steps to load xdp program manually, since the current behavior of libbpf would load a default xdp program when user calls xsk_socket__create. userspace application only needs to handle the cleanup.

How to try
==========

1. take the kernel >= v5.1-rc1, build kernel and replace your host kernel with it.

make sure you turn on XDP sockets when compiling

Networking support -->
Networking options -->
[ * ] XDP sockets

2. build libbpf in tools/lib/bpf, and copy the libbpf.a and libbpf.so to /usr/lib64

cd tools/lib/bpf
make

3. ethtool -L enp59s0f0 combined 1

4. extra step to build dpdk

explicitly enable AF_XDP pmd by adding below line to config/common_linux

CONFIG_RTE_LIBRTE_PMD_AF_XDP=y

5. start testpmd

   ./build/app/testpmd -c 0xc -n 4 --vdev net_af_xdp,iface=enp59s0f0,queue=0 -- -i --rxq=1 --txq=1

in this case, default xdp program will be loaded and linked to queue 0 of enp59s0f0, network traffics travel to queue 0 will be redirected to af_xdp socket.

Xiaolong Ye (1):
net/af_xdp: introduce AF XDP PMD driver

 MAINTAINERS                                   |   7 +
 config/common_base                            |   5 +
 doc/guides/nics/af_xdp.rst                    |  48 +
 doc/guides/nics/features/af_xdp.ini           |  11 +
 doc/guides/nics/index.rst                     |   1 +
 doc/guides/rel_notes/release_19_05.rst        |   7 +
 drivers/net/Makefile                          |   1 +
 drivers/net/af_xdp/Makefile                   |  32 +
 drivers/net/af_xdp/meson.build                |  21 +
 drivers/net/af_xdp/rte_eth_af_xdp.c           | 945 ++++++++++++++++++
 drivers/net/af_xdp/rte_pmd_af_xdp_version.map |   3 +
 drivers/net/meson.build                       |   1 +
 mk/rte.app.mk                                 |   1 +
 13 files changed, 1083 insertions(+)
 create mode 100644 doc/guides/nics/af_xdp.rst
 create mode 100644 doc/guides/nics/features/af_xdp.ini
 create mode 100644 drivers/net/af_xdp/Makefile
 create mode 100644 drivers/net/af_xdp/meson.build
 create mode 100644 drivers/net/af_xdp/rte_eth_af_xdp.c
 create mode 100644 drivers/net/af_xdp/rte_pmd_af_xdp_version.map
Signature · 1 line
2.17.1
#146 lore raw

PATCH v8 1/1 net/af_xdp: introduce AF XDP PMD driver

Add a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux. More info about AF_XDP, please refer to [1] [2].

This is the vanilla version PMD which just uses a raw buffer registered as the umem.

[1] https://fosdem.org/2018/schedule/event/af_xdp/
[2] https://lwn.net/Articles/745934/

---
 MAINTAINERS                                   |   7 +
 config/common_base                            |   5 +
 doc/guides/nics/af_xdp.rst                    |  48 +
 doc/guides/nics/features/af_xdp.ini           |  11 +
 doc/guides/nics/index.rst                     |   1 +
 doc/guides/rel_notes/release_19_05.rst        |   7 +
 drivers/net/Makefile                          |   1 +
 drivers/net/af_xdp/Makefile                   |  32 +
 drivers/net/af_xdp/meson.build                |  21 +
 drivers/net/af_xdp/rte_eth_af_xdp.c           | 945 ++++++++++++++++++
 drivers/net/af_xdp/rte_pmd_af_xdp_version.map |   3 +
 drivers/net/meson.build                       |   1 +
 mk/rte.app.mk                                 |   1 +
 13 files changed, 1083 insertions(+)
 create mode 100644 doc/guides/nics/af_xdp.rst
 create mode 100644 doc/guides/nics/features/af_xdp.ini
 create mode 100644 drivers/net/af_xdp/Makefile
 create mode 100644 drivers/net/af_xdp/meson.build
 create mode 100644 drivers/net/af_xdp/rte_eth_af_xdp.c
 create mode 100644 drivers/net/af_xdp/rte_pmd_af_xdp_version.map
MAINTAINERS +7 -0
index e9ff2b4c2..c13ae8215 100644
@@ -479,6 +479,13 @@ M: John W. Linville <[email protected]>
 F: drivers/net/af_packet/
 F: doc/guides/nics/features/afpacket.ini
 
+Linux AF_XDP
+M: Xiaolong Ye <[email protected]>
+M: Qi Zhang <[email protected]>
+F: drivers/net/af_xdp/
+F: doc/guides/nics/af_xdp.rst
+F: doc/guides/nics/features/af_xdp.ini
+
 Amazon ENA
 M: Marcin Wojtas <[email protected]>
 M: Michal Krawczyk <[email protected]>
config/common_base +5 -0
index 6292bc4af..b95ee03d7 100644
@@ -430,6 +430,11 @@ CONFIG_RTE_LIBRTE_VMXNET3_DEBUG_TX_FREE=n
 #
 CONFIG_RTE_LIBRTE_PMD_AF_PACKET=n
 
+#
+# Compile software PMD backed by AF_XDP sockets (Linux only)
+#
+CONFIG_RTE_LIBRTE_PMD_AF_XDP=n
+
 #
 # Compile link bonding PMD library
 #
doc/guides/nics/af_xdp.rst new file +48 -0

48 lines not on this page · raw message

doc/guides/nics/features/af_xdp.ini new file +11 -0
new file mode 100644
index 000000000..36953c2de
@@ -0,0 +1,11 @@
+;
+; Supported features of the 'af_xdp' network poll mode driver.
+;
+; Refer to default.ini for the full list of available PMD features.
+;
+[Features]
+Link status          = Y
+MTU update           = Y
+Promiscuous mode     = Y
+Stats per queue      = Y
+x86-64               = Y
doc/guides/nics/index.rst +1 -0
index 5c80e3baa..a4b80a3d0 100644
@@ -12,6 +12,7 @@ Network Interface Controller Drivers
     features
     build_and_test
     af_packet
+    af_xdp
     ark
     atlantic
     avp
doc/guides/rel_notes/release_19_05.rst +7 -0
index aae8ff602..cdf0d4a95 100644
@@ -65,6 +65,13 @@ New Features
     process.
   * Added support for Rx packet types list in a secondary process.
 
+* **Added the AF_XDP PMD.**
+
+  Added a Linux-specific PMD driver for AF_XDP, it can create the AF_XDP socket
+  and bind it to a specific netdev queue, it allows a DPDK application to send
+  and receive raw packets through the socket which would bypass the kernel
+  network stack to achieve high performance packet processing.
+
 * **Updated Mellanox drivers.**
 
    New features and improvements were done in mlx4 and mlx5 PMDs:
drivers/net/Makefile +1 -0
index 502869a87..5d401b8c5 100644
@@ -9,6 +9,7 @@ ifeq ($(CONFIG_RTE_LIBRTE_THUNDERX_NICVF_PMD),d)
 endif
 
 DIRS-$(CONFIG_RTE_LIBRTE_PMD_AF_PACKET) += af_packet
+DIRS-$(CONFIG_RTE_LIBRTE_PMD_AF_XDP) += af_xdp
 DIRS-$(CONFIG_RTE_LIBRTE_ARK_PMD) += ark
 DIRS-$(CONFIG_RTE_LIBRTE_ATLANTIC_PMD) += atlantic
 DIRS-$(CONFIG_RTE_LIBRTE_AVP_PMD) += avp
drivers/net/af_xdp/Makefile new file +32 -0
new file mode 100644
index 000000000..8343e3016
@@ -0,0 +1,32 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+#
+# library name
+#
+LIB = librte_pmd_af_xdp.a
+
+EXPORT_MAP := rte_pmd_af_xdp_version.map
+
+LIBABIVER := 1
+
+CFLAGS += -O3
+
+# require kernel version >= v5.1-rc1
+CFLAGS += -I$(RTE_KERNELDIR)/tools/include
+CFLAGS += -I$(RTE_KERNELDIR)/tools/lib/bpf
+
+CFLAGS += $(WERROR_FLAGS)
+LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring
+LDLIBS += -lrte_ethdev -lrte_net -lrte_kvargs
+LDLIBS += -lrte_bus_vdev
+LDLIBS += -lbpf
+
+#
+# all source are stored in SRCS-y
+#
+SRCS-$(CONFIG_RTE_LIBRTE_PMD_AF_XDP) += rte_eth_af_xdp.c
+
+include $(RTE_SDK)/mk/rte.lib.mk
drivers/net/af_xdp/meson.build new file +21 -0
new file mode 100644
index 000000000..d40aae190
@@ -0,0 +1,21 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+if host_machine.system() != 'linux'
+	build = false
+endif
+
+bpf_dep = dependency('libbpf', required: false)
+if bpf_dep.found()
+	build = true
+else
+	bpf_dep = cc.find_library('libbpf', required: false)
+	if bpf_dep.found() and cc.has_header('xsk.h', dependencies: bpf_dep) and cc.has_header('linux/if_xdp.h')
+		build = true
+		pkgconfig_extra_libs += '-lbpf'
+	else
+		build = false
+	endif
+endif
+sources = files('rte_eth_af_xdp.c')
+ext_deps += bpf_dep
drivers/net/af_xdp/rte_eth_af_xdp.c new file +945 -0

945 lines not on this page · raw message

drivers/net/af_xdp/rte_pmd_af_xdp_version.map new file +3 -0
new file mode 100644
index 000000000..c6db030fe
@@ -0,0 +1,3 @@
+DPDK_19.05 {
+	local: *;
+};
drivers/net/meson.build +1 -0
index 3ecc78cee..1105e72d8 100644
@@ -2,6 +2,7 @@
 # Copyright(c) 2017 Intel Corporation
 
 drivers = ['af_packet',
+	'af_xdp',
 	'ark',
 	'atlantic',
 	'avp',
mk/rte.app.mk +1 -0
index 262132fc6..f916bc9ef 100644
@@ -143,6 +143,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_DPAA2_MEMPOOL)  += -lrte_mempool_dpaa2
 endif
 
 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AF_PACKET)  += -lrte_pmd_af_packet
+_LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AF_XDP)     += -lrte_pmd_af_xdp -lbpf
 _LDLIBS-$(CONFIG_RTE_LIBRTE_ARK_PMD)        += -lrte_pmd_ark
 _LDLIBS-$(CONFIG_RTE_LIBRTE_ATLANTIC_PMD)   += -lrte_pmd_atlantic
 _LDLIBS-$(CONFIG_RTE_LIBRTE_AVP_PMD)        += -lrte_pmd_avp
Signature · 1 line
2.17.1
#147 lore raw

Re: [PATCH v8 1/1] net/af_xdp: introduce AF XDP PMD driver

Quoted 13 lines · On Tue, 2 Apr 2019 18:45:54 +0800 Xiaolong Ye <[email protected]> wrote:
drivers/net/af_xdp/rte_eth_af_xdp.c new file +13 -0
+
+#include <rte_mbuf.h>
+#include <rte_ethdev_driver.h>
+#include <rte_ethdev_vdev.h>
+#include <rte_malloc.h>
+#include <rte_kvargs.h>
+#include <rte_bus_vdev.h>
+#include <rte_string_fns.h>
+
+#include <linux/if_ether.h>
+#include <linux/if_xdp.h>
+#include <linux/if_link.h>
+#include <asm/barrier.h>

drivers/net/af_xdp/rte_eth_af_xdp.c line 26

Quoted 10 lines
drivers/net/af_xdp/rte_eth_af_xdp.c new file +10 -0
+#include <arpa/inet.h>
+#include <net/if.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include <poll.h>
+#include <bpf/bpf.h>
+#include <xsk.h>

The ordering here seems surprising. The usual ordering is:

Libc includes:
#include <stdio.h>
...
Sys includes:
#include <sys/types.h>

Linux includes:
#include <linux/if_xdp.h>

DPDK includes:
#include <rte_mbuf.h>

If I run "Include what you use" it has different suggestions. Some of which you should ignore but overall there are several good ones.

rte_eth_af_xdp.c should add these lines:

#include <asm/int-ll64.h>           // for __u64
#include <bits/stdint-uintn.h>      // for uint16_t, uint64_t, uint32_t
#include <errno.h>                  // for EINVAL, errno, EAGAIN, ENOMEM, EBUSY
#include <netinet/in.h>             // for IPPROTO_IP
#include <rte_ethdev.h>             // for rte_eth_dev, rte_eth_dev_data
#include <stdlib.h>                 // for strtol
#include <string.h>                 // for NULL, memset, strlen
#include "rte_branch_prediction.h"  // for unlikely
#include "rte_common.h"             // for __rte_unused, RTE_MIN, RTE_PRIORI...
#include "rte_config.h"             // for RTE_PKTMBUF_HEADROOM
#include "rte_dev.h"                // for rte_device, RTE_PMD_REGISTER_PARA...
#include "rte_eal.h"                // for rte_eal_process_type, rte_proc_ty...
#include "rte_ethdev.h"             // for rte_eth_stats, rte_eth_dev_info
#include "rte_ether.h"              // for ETHER_ADDR_LEN, ether_addr
#include "rte_lcore.h"              // for rte_socket_id
#include "rte_log.h"                // for rte_log, RTE_LOG_ERR, RTE_LOG_INFO
#include "rte_memory.h"             // for SOCKET_ID_ANY
#include "rte_memzone.h"            // for rte_memzone_free, RTE_MEMZONE_IOV...
#include "rte_ring.h"               // for rte_ring_free, rte_ring_create

struct rte_mempool;

rte_eth_af_xdp.c should remove these lines:
- #include <arpa/inet.h> // lines 17-17
- #include <poll.h> // lines 24-24
- #include <rte_ethdev_vdev.h> // lines 7-7
- #include <sys/mman.h> // lines 22-22
- #include <sys/types.h> // lines 19-19

#148 lore raw

Re: [PATCH v8 1/1] net/af_xdp: introduce AF XDP PMD driver

Quoted 66 lines · Stephen Hemminger
Quoted 13 lines · On Tue, 2 Apr 2019 18:45:54 +0800 Xiaolong Ye <[email protected]> wrote:
drivers/net/af_xdp/rte_eth_af_xdp.c new file +13 -0
+
+#include <rte_mbuf.h>
+#include <rte_ethdev_driver.h>
+#include <rte_ethdev_vdev.h>
+#include <rte_malloc.h>
+#include <rte_kvargs.h>
+#include <rte_bus_vdev.h>
+#include <rte_string_fns.h>
+
+#include <linux/if_ether.h>
+#include <linux/if_xdp.h>
+#include <linux/if_link.h>
+#include <asm/barrier.h>

drivers/net/af_xdp/rte_eth_af_xdp.c line 26

Quoted 10 lines
drivers/net/af_xdp/rte_eth_af_xdp.c new file +10 -0
+#include <arpa/inet.h>
+#include <net/if.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include <poll.h>
+#include <bpf/bpf.h>
+#include <xsk.h>

The ordering here seems surprising. The usual ordering is:

Libc includes:
#include <stdio.h>
...
Sys includes:
#include <sys/types.h>

Linux includes:
#include <linux/if_xdp.h>

DPDK includes:
#include <rte_mbuf.h>

If I run "Include what you use" it has different suggestions. Some of which you should ignore but overall there are several good ones.

rte_eth_af_xdp.c should add these lines:

#include <asm/int-ll64.h>           // for __u64
#include <bits/stdint-uintn.h>      // for uint16_t, uint64_t, uint32_t
#include <errno.h>                  // for EINVAL, errno, EAGAIN, ENOMEM, EBUSY
#include <netinet/in.h>             // for IPPROTO_IP
#include <rte_ethdev.h>             // for rte_eth_dev, rte_eth_dev_data
#include <stdlib.h>                 // for strtol
#include <string.h>                 // for NULL, memset, strlen
#include "rte_branch_prediction.h"  // for unlikely
#include "rte_common.h"             // for __rte_unused, RTE_MIN, RTE_PRIORI...
#include "rte_config.h"             // for RTE_PKTMBUF_HEADROOM
#include "rte_dev.h"                // for rte_device, RTE_PMD_REGISTER_PARA...
#include "rte_eal.h"                // for rte_eal_process_type, rte_proc_ty...
#include "rte_ethdev.h"             // for rte_eth_stats, rte_eth_dev_info
#include "rte_ether.h"              // for ETHER_ADDR_LEN, ether_addr
#include "rte_lcore.h"              // for rte_socket_id
#include "rte_log.h"                // for rte_log, RTE_LOG_ERR, RTE_LOG_INFO
#include "rte_memory.h"             // for SOCKET_ID_ANY
#include "rte_memzone.h"            // for rte_memzone_free, RTE_MEMZONE_IOV...
#include "rte_ring.h"               // for rte_ring_free, rte_ring_create
Quoted 9 lines

struct rte_mempool;

rte_eth_af_xdp.c should remove these lines:
- #include <arpa/inet.h> // lines 17-17
- #include <poll.h> // lines 24-24
- #include <rte_ethdev_vdev.h> // lines 7-7
- #include <sys/mman.h> // lines 22-22
- #include <sys/types.h> // lines 19-19

Thanks for pointing out, I'll adjust the headers.

Thanks,
Xiaolong

Quoted 3 lines
#149 lore raw

v9 cover Introduce AF_XDP PMD

In reply to Xiaolong Ye

Overview
========

This patchset adds a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux, see below links [1] [2] for details of AF_XDP introduction:

AF_XDP roadmap
==============
- AF_XDP is included in upstream kernel since 4.18, and AF_XDP support in libbpf has been merged in v5.1-rc1.
- Now i40e and ixgbe drivers have supported zero copy mode.

Change logs
===========
V9:
- adjust header files order according to Stephen's suggestion

v8:
- address Ferruh's comments on V7
- replace posix_memalign with rte_memzone_reserve_aligned to get better performance
- keep the first patch only as Oliver suggested as zero copy part implementation is still in suspense, we may provide the related patch later.

v7:
- mention mtu limitation in af_xdp.rst
- fix the vdev name in af_xdp.rst

V6:

- remove the newline in AF_XDP_LOG definition to avoid double new lines issue.
- rename MEMPOOL_F_PAGE_ALIGN to MEMPOOL_CHUNK_F_PAGE_ALIGN.

V5:

- disable AF_XDP pmd by default due to it requires kernel more recent than minimum kernel version supported by DPDK
- address other review comments of Maxime

V4:

- change vdev name to net_af_xdp
- adopt dynamic log type for all logging
- Fix other style issues raised by Stephen

V3:

- Fix all style issues pointed by Stephen, Mattias, David.
- Drop the testpmd change as we'll adopt Jerin's suggestion to add a new mempool driver to handle the application use of AF_XDP's zero copy feature.

V2:
- Fix a NULL pointer reference crash issue
- Fix txonly stop sending traffic in zc mode
- Refactor rte_mbuf.c to avoid ABI breakage.
- Fix multiple style issues pointed by Ferruh, David, Stephen, Luca.

changes vs RFC sent by Qi last Aug:

- Re-work base on AF_XDP's interface changes since the new libbpf has provided higher-level APIs that hide many of the details of the AP_XDP uapi. After the rework, it helps to reduce 300+ lines of code.

- multi-queues is not supported due to current libbpf doesn't support multi-sockets on a single umem.

- No extra steps to load xdp program manually, since the current behavior of libbpf would load a default xdp program when user calls xsk_socket__create. userspace application only needs to handle the cleanup.

How to try
==========

1. take the kernel >= v5.1-rc1, build kernel and replace your host kernel with it.

make sure you turn on XDP sockets when compiling

Networking support -->
Networking options -->
[ * ] XDP sockets

2. build libbpf in tools/lib/bpf, and copy the libbpf.a and libbpf.so to /usr/lib64

cd tools/lib/bpf
make

3. ethtool -L enp59s0f0 combined 1

4. extra step to build dpdk

explicitly enable AF_XDP pmd by adding below line to config/common_linux

CONFIG_RTE_LIBRTE_PMD_AF_XDP=y

5. start testpmd

   ./build/app/testpmd -c 0xc -n 4 --vdev net_af_xdp,iface=enp59s0f0,queue=0 -- -i --rxq=1 --txq=1

in this case, default xdp program will be loaded and linked to queue 0 of enp59s0f0, network traffics travel to queue 0 will be redirected to af_xdp socket.

Xiaolong Ye (1):
net/af_xdp: introduce AF XDP PMD driver

 MAINTAINERS                                   |   7 +
 config/common_base                            |   5 +
 doc/guides/nics/af_xdp.rst                    |  48 +
 doc/guides/nics/features/af_xdp.ini           |  11 +
 doc/guides/nics/index.rst                     |   1 +
 doc/guides/rel_notes/release_19_05.rst        |   7 +
 drivers/net/Makefile                          |   1 +
 drivers/net/af_xdp/Makefile                   |  32 +
 drivers/net/af_xdp/meson.build                |  21 +
 drivers/net/af_xdp/rte_eth_af_xdp.c           | 956 ++++++++++++++++++
 drivers/net/af_xdp/rte_pmd_af_xdp_version.map |   3 +
 drivers/net/meson.build                       |   1 +
 mk/rte.app.mk                                 |   1 +
 13 files changed, 1094 insertions(+)
 create mode 100644 doc/guides/nics/af_xdp.rst
 create mode 100644 doc/guides/nics/features/af_xdp.ini
 create mode 100644 drivers/net/af_xdp/Makefile
 create mode 100644 drivers/net/af_xdp/meson.build
 create mode 100644 drivers/net/af_xdp/rte_eth_af_xdp.c
 create mode 100644 drivers/net/af_xdp/rte_pmd_af_xdp_version.map
Signature · 1 line
2.17.1
#150 lore raw

PATCH v9 1/1 net/af_xdp: introduce AF XDP PMD driver

Add a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux. More info about AF_XDP, please refer to [1] [2].

This is the vanilla version PMD which just uses a raw buffer registered as the umem.

[1] https://fosdem.org/2018/schedule/event/af_xdp/
[2] https://lwn.net/Articles/745934/

---
 MAINTAINERS                                   |   7 +
 config/common_base                            |   5 +
 doc/guides/nics/af_xdp.rst                    |  48 +
 doc/guides/nics/features/af_xdp.ini           |  11 +
 doc/guides/nics/index.rst                     |   1 +
 doc/guides/rel_notes/release_19_05.rst        |   7 +
 drivers/net/Makefile                          |   1 +
 drivers/net/af_xdp/Makefile                   |  32 +
 drivers/net/af_xdp/meson.build                |  21 +
 drivers/net/af_xdp/rte_eth_af_xdp.c           | 956 ++++++++++++++++++
 drivers/net/af_xdp/rte_pmd_af_xdp_version.map |   3 +
 drivers/net/meson.build                       |   1 +
 mk/rte.app.mk                                 |   1 +
 13 files changed, 1094 insertions(+)
 create mode 100644 doc/guides/nics/af_xdp.rst
 create mode 100644 doc/guides/nics/features/af_xdp.ini
 create mode 100644 drivers/net/af_xdp/Makefile
 create mode 100644 drivers/net/af_xdp/meson.build
 create mode 100644 drivers/net/af_xdp/rte_eth_af_xdp.c
 create mode 100644 drivers/net/af_xdp/rte_pmd_af_xdp_version.map
MAINTAINERS +7 -0
index e9ff2b4c2..c13ae8215 100644
@@ -479,6 +479,13 @@ M: John W. Linville <[email protected]>
 F: drivers/net/af_packet/
 F: doc/guides/nics/features/afpacket.ini
 
+Linux AF_XDP
+M: Xiaolong Ye <[email protected]>
+M: Qi Zhang <[email protected]>
+F: drivers/net/af_xdp/
+F: doc/guides/nics/af_xdp.rst
+F: doc/guides/nics/features/af_xdp.ini
+
 Amazon ENA
 M: Marcin Wojtas <[email protected]>
 M: Michal Krawczyk <[email protected]>
config/common_base +5 -0
index 6292bc4af..b95ee03d7 100644
@@ -430,6 +430,11 @@ CONFIG_RTE_LIBRTE_VMXNET3_DEBUG_TX_FREE=n
 #
 CONFIG_RTE_LIBRTE_PMD_AF_PACKET=n
 
+#
+# Compile software PMD backed by AF_XDP sockets (Linux only)
+#
+CONFIG_RTE_LIBRTE_PMD_AF_XDP=n
+
 #
 # Compile link bonding PMD library
 #
doc/guides/nics/af_xdp.rst new file +48 -0

48 lines not on this page · raw message

doc/guides/nics/features/af_xdp.ini new file +11 -0
new file mode 100644
index 000000000..36953c2de
@@ -0,0 +1,11 @@
+;
+; Supported features of the 'af_xdp' network poll mode driver.
+;
+; Refer to default.ini for the full list of available PMD features.
+;
+[Features]
+Link status          = Y
+MTU update           = Y
+Promiscuous mode     = Y
+Stats per queue      = Y
+x86-64               = Y
doc/guides/nics/index.rst +1 -0
index 5c80e3baa..a4b80a3d0 100644
@@ -12,6 +12,7 @@ Network Interface Controller Drivers
     features
     build_and_test
     af_packet
+    af_xdp
     ark
     atlantic
     avp
doc/guides/rel_notes/release_19_05.rst +7 -0
index bdad1ddbe..79e36739f 100644
@@ -74,6 +74,13 @@ New Features
     process.
   * Added support for Rx packet types list in a secondary process.
 
+* **Added the AF_XDP PMD.**
+
+  Added a Linux-specific PMD driver for AF_XDP, it can create the AF_XDP socket
+  and bind it to a specific netdev queue, it allows a DPDK application to send
+  and receive raw packets through the socket which would bypass the kernel
+  network stack to achieve high performance packet processing.
+
 * **Updated Mellanox drivers.**
 
    New features and improvements were done in mlx4 and mlx5 PMDs:
drivers/net/Makefile +1 -0
index 502869a87..5d401b8c5 100644
@@ -9,6 +9,7 @@ ifeq ($(CONFIG_RTE_LIBRTE_THUNDERX_NICVF_PMD),d)
 endif
 
 DIRS-$(CONFIG_RTE_LIBRTE_PMD_AF_PACKET) += af_packet
+DIRS-$(CONFIG_RTE_LIBRTE_PMD_AF_XDP) += af_xdp
 DIRS-$(CONFIG_RTE_LIBRTE_ARK_PMD) += ark
 DIRS-$(CONFIG_RTE_LIBRTE_ATLANTIC_PMD) += atlantic
 DIRS-$(CONFIG_RTE_LIBRTE_AVP_PMD) += avp
drivers/net/af_xdp/Makefile new file +32 -0
new file mode 100644
index 000000000..8343e3016
@@ -0,0 +1,32 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+#
+# library name
+#
+LIB = librte_pmd_af_xdp.a
+
+EXPORT_MAP := rte_pmd_af_xdp_version.map
+
+LIBABIVER := 1
+
+CFLAGS += -O3
+
+# require kernel version >= v5.1-rc1
+CFLAGS += -I$(RTE_KERNELDIR)/tools/include
+CFLAGS += -I$(RTE_KERNELDIR)/tools/lib/bpf
+
+CFLAGS += $(WERROR_FLAGS)
+LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring
+LDLIBS += -lrte_ethdev -lrte_net -lrte_kvargs
+LDLIBS += -lrte_bus_vdev
+LDLIBS += -lbpf
+
+#
+# all source are stored in SRCS-y
+#
+SRCS-$(CONFIG_RTE_LIBRTE_PMD_AF_XDP) += rte_eth_af_xdp.c
+
+include $(RTE_SDK)/mk/rte.lib.mk
drivers/net/af_xdp/meson.build new file +21 -0
new file mode 100644
index 000000000..d40aae190
@@ -0,0 +1,21 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+if host_machine.system() != 'linux'
+	build = false
+endif
+
+bpf_dep = dependency('libbpf', required: false)
+if bpf_dep.found()
+	build = true
+else
+	bpf_dep = cc.find_library('libbpf', required: false)
+	if bpf_dep.found() and cc.has_header('xsk.h', dependencies: bpf_dep) and cc.has_header('linux/if_xdp.h')
+		build = true
+		pkgconfig_extra_libs += '-lbpf'
+	else
+		build = false
+	endif
+endif
+sources = files('rte_eth_af_xdp.c')
+ext_deps += bpf_dep
drivers/net/af_xdp/rte_eth_af_xdp.c new file +956 -0

956 lines not on this page · raw message

drivers/net/af_xdp/rte_pmd_af_xdp_version.map new file +3 -0
new file mode 100644
index 000000000..c6db030fe
@@ -0,0 +1,3 @@
+DPDK_19.05 {
+	local: *;
+};
drivers/net/meson.build +1 -0
index 3ecc78cee..1105e72d8 100644
@@ -2,6 +2,7 @@
 # Copyright(c) 2017 Intel Corporation
 
 drivers = ['af_packet',
+	'af_xdp',
 	'ark',
 	'atlantic',
 	'avp',
mk/rte.app.mk +1 -0
index 262132fc6..f916bc9ef 100644
@@ -143,6 +143,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_DPAA2_MEMPOOL)  += -lrte_mempool_dpaa2
 endif
 
 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AF_PACKET)  += -lrte_pmd_af_packet
+_LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AF_XDP)     += -lrte_pmd_af_xdp -lbpf
 _LDLIBS-$(CONFIG_RTE_LIBRTE_ARK_PMD)        += -lrte_pmd_ark
 _LDLIBS-$(CONFIG_RTE_LIBRTE_ATLANTIC_PMD)   += -lrte_pmd_atlantic
 _LDLIBS-$(CONFIG_RTE_LIBRTE_AVP_PMD)        += -lrte_pmd_avp
Signature · 1 line
2.17.1
#151 lore raw

Re: [PATCH v9 1/1] net/af_xdp: introduce AF XDP PMD driver

drivers/net/af_xdp/rte_eth_af_xdp.c line 251

Quoted 1 line · On Tue, 2 Apr 2019 23:46:53 +0800 Xiaolong Ye <[email protected]> wrote:
drivers/net/af_xdp/rte_eth_af_xdp.c new file +1 -0
+		/* pull from complete qeueu to leave more space */

Overall looks good, one last spelling error

#152 lore raw

Re: [PATCH v9 1/1] net/af_xdp: introduce AF XDP PMD driver

Quoted 6 lines · Stephen Hemminger

drivers/net/af_xdp/rte_eth_af_xdp.c line 251

Quoted 1 line · On Tue, 2 Apr 2019 23:46:53 +0800 Xiaolong Ye <[email protected]> wrote:
drivers/net/af_xdp/rte_eth_af_xdp.c new file +1 -0
+		/* pull from complete qeueu to leave more space */

Overall looks good, one last spelling error

Sorry for the typo, will fix in in next version.

Thanks,
Xiaolong

#153 lore raw

Re: [PATCH v9 1/1] net/af_xdp: introduce AF XDP PMD driver

In reply to Xiaolong Ye
Quoted 16 lines · Xiaolong Ye
drivers/net/af_xdp/Makefile new file +9 -0
new file mode 100644
index 000000000..8343e3016
@@ -0,0 +1,32 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+#
+# library name
+#
+LIB = librte_pmd_af_xdp.a

drivers/net/af_xdp/Makefile line 19

Quoted 10 lines
drivers/net/af_xdp/Makefile new file +10 -0
+
+EXPORT_MAP := rte_pmd_af_xdp_version.map
+
+LIBABIVER := 1
+
+CFLAGS += -O3
+
+# require kernel version >= v5.1-rc1
+CFLAGS += -I$(RTE_KERNELDIR)/tools/include
+CFLAGS += -I$(RTE_KERNELDIR)/tools/lib/bpf

Sorry for not noticing this before, but doesn't this require the full kernel tree rather than just the typical headers package? Requiring the full kernel tree to be available at build time will make this unbuildable on distros that still use makefiles, like RHEL and SUSE. At least on Debian and Ubuntu, the kernel headers packages distributed do not include the full kernel tree, only the headers, so there's no tools/lib or tools/include.

Like other dependencies, this should assume they are installed as regular libraries, eg:

CFLAGS += $(shell command -v pkg-config > /dev/null 2>&1 && pkg-config --cflags libbpf || echo "-I/usr/include/bpf")

drivers/net/af_xdp/Makefile line 25

Quoted 5 lines
drivers/net/af_xdp/Makefile new file +5 -0
+CFLAGS += $(WERROR_FLAGS)
+LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring
+LDLIBS += -lrte_ethdev -lrte_net -lrte_kvargs
+LDLIBS += -lrte_bus_vdev
+LDLIBS += -lbpf

LDLIBS += $(shell command -v pkg-config > /dev/null 2>&1 && pkg-config --libs libbpf || echo "-lbpf")

Signature · 2 lines
Kind regards,
Luca Boccassi
#154 lore raw

Re: [PATCH v9 1/1] net/af_xdp: introduce AF XDP PMD driver

Hi, Luca

Quoted 28 lines · Luca Boccassi
Quoted 16 lines · Xiaolong Ye
drivers/net/af_xdp/Makefile new file +9 -0
new file mode 100644
index 000000000..8343e3016
@@ -0,0 +1,32 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+#
+# library name
+#
+LIB = librte_pmd_af_xdp.a

drivers/net/af_xdp/Makefile line 19

Quoted 10 lines
drivers/net/af_xdp/Makefile new file +10 -0
+
+EXPORT_MAP := rte_pmd_af_xdp_version.map
+
+LIBABIVER := 1
+
+CFLAGS += -O3
+
+# require kernel version >= v5.1-rc1
+CFLAGS += -I$(RTE_KERNELDIR)/tools/include
+CFLAGS += -I$(RTE_KERNELDIR)/tools/lib/bpf
Quoted 7 lines

Sorry for not noticing this before, but doesn't this require the full kernel tree rather than just the typical headers package? Requiring the full kernel tree to be available at build time will make this unbuildable on distros that still use makefiles, like RHEL and SUSE. At least on Debian and Ubuntu, the kernel headers packages distributed do not include the full kernel tree, only the headers, so there's no tools/lib or tools/include.

Currently we do have dependencies on the kernel src tree, as xsk.h and asm/barrier wouldn't be installed by libbpf, so before libbpf handles these properly, can we keep the current RTE_KERNELDIR in Makefile for now, and mention the dependencies in document, also suggest users to config RTE_KERNELDIR to correct kernel src tree if they want to use af_xdp pmd?

Something like:

dependencies:
- kernel source code (>= v5.1-rc1)
- build libbfp and install

Thanks,
Xiaolong

Quoted 17 lines

Like other dependencies, this should assume they are installed as regular libraries, eg:

CFLAGS += $(shell command -v pkg-config > /dev/null 2>&1 && pkg-config --cflags libbpf || echo "-I/usr/include/bpf")

drivers/net/af_xdp/Makefile line 25

Quoted 5 lines
drivers/net/af_xdp/Makefile new file +5 -0
+CFLAGS += $(WERROR_FLAGS)
+LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring
+LDLIBS += -lrte_ethdev -lrte_net -lrte_kvargs
+LDLIBS += -lrte_bus_vdev
+LDLIBS += -lbpf

LDLIBS += $(shell command -v pkg-config > /dev/null 2>&1 && pkg-config --libs libbpf || echo "-lbpf")

Signature · 2 lines
Kind regards,
Luca Boccassi
#155 lore raw

Re: [PATCH v9 1/1] net/af_xdp: introduce AF XDP PMD driver

Quoted 53 lines · Ye Xiaolong

Hi, Luca

Quoted 31 lines · Luca Boccassi
Quoted 16 lines · Xiaolong Ye
drivers/net/af_xdp/Makefile new file +9 -0
new file mode 100644
index 000000000..8343e3016
@@ -0,0 +1,32 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+#
+# library name
+#
+LIB = librte_pmd_af_xdp.a

drivers/net/af_xdp/Makefile line 19

Quoted 10 lines
drivers/net/af_xdp/Makefile new file +10 -0
+
+EXPORT_MAP := rte_pmd_af_xdp_version.map
+
+LIBABIVER := 1
+
+CFLAGS += -O3
+
+# require kernel version >= v5.1-rc1
+CFLAGS += -I$(RTE_KERNELDIR)/tools/include
+CFLAGS += -I$(RTE_KERNELDIR)/tools/lib/bpf

Sorry for not noticing this before, but doesn't this require the full
kernel tree rather than just the typical headers package? Requiring

Quoted 8 lines

the
full kernel tree to be available at build time will make this unbuildable on distros that still use makefiles, like RHEL and SUSE. At
least on Debian and Ubuntu, the kernel headers packages distributed do
not include the full kernel tree, only the headers, so there's no tools/lib or tools/include.

Currently we do have dependencies on the kernel src tree, as xsk.h and
asm/barrier wouldn't be installed by libbpf, so before libbpf handles these
properly, can we keep the current RTE_KERNELDIR in Makefile for now, and mention
the dependencies in document, also suggest users to config RTE_KERNELDIR to correct
kernel src tree if they want to use af_xdp pmd?

Quoted 8 lines

Something like:

dependencies:
- kernel source code (>= v5.1-rc1)
- build libbfp and install

Thanks,
Xiaolong

asm/barrier.h is installed by the kernel headers packages so it would be fine (although not ideal) and not need the full source tree. xsk.h is a bit more worrying, as it looks like an internal header from here.

Is it really necessary for external applications to use an internal- only header and a kernel header to be able to use libbpf?

Signature · 2 lines
Kind regards,
Luca Boccassi
#156 lore raw

Re: [PATCH v9 1/1] net/af_xdp: introduce AF XDP PMD driver

Quoted 67 lines · Luca Boccassi
Quoted 57 lines · Ye Xiaolong

Hi, Luca

Quoted 33 lines · Luca Boccassi
Quoted 16 lines · Xiaolong Ye
drivers/net/af_xdp/Makefile new file +9 -0
new file mode 100644
index 000000000..8343e3016
@@ -0,0 +1,32 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+#
+# library name
+#
+LIB = librte_pmd_af_xdp.a

drivers/net/af_xdp/Makefile line 19

Quoted 10 lines
drivers/net/af_xdp/Makefile new file +10 -0
+
+EXPORT_MAP := rte_pmd_af_xdp_version.map
+
+LIBABIVER := 1
+
+CFLAGS += -O3
+
+# require kernel version >= v5.1-rc1
+CFLAGS += -I$(RTE_KERNELDIR)/tools/include
+CFLAGS += -I$(RTE_KERNELDIR)/tools/lib/bpf

Sorry for not noticing this before, but doesn't this require the full
kernel tree rather than just the typical headers package? Requiring
the

Quoted 8 lines

full kernel tree to be available at build time will make this unbuildable on distros that still use makefiles, like RHEL and SUSE. At
least on Debian and Ubuntu, the kernel headers packages distributed
do
not include the full kernel tree, only the headers, so there's no tools/lib or tools/include.

Currently we do have dependencies on the kernel src tree, as xsk.h and
asm/barrier wouldn't be installed by libbpf, so before libbpf handles
these
properly, can we keep the current RTE_KERNELDIR in Makefile for now,
and mention
the dependencies in document, also suggest users to config RTE_KERNELDIR to correct
kernel src tree if they want to use af_xdp pmd?

Quoted 8 lines

Something like:

dependencies:
- kernel source code (>= v5.1-rc1)
- build libbfp and install

Thanks,
Xiaolong

Quoted 8 lines

asm/barrier.h is installed by the kernel headers packages so it would be fine (although not ideal) and not need the full source tree. xsk.h is a bit more worrying, as it looks like an internal header from
here.

Is it really necessary for external applications to use an internal- only header and a kernel header to be able to use libbpf?

Actually, xsk.h is now installed by the library makefile:

https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git/commit/?id=379e2014c95b

So the full kernel source tree is no longer required.

Is asm/barrier.h really required? Isn't there an userspace alternative?

Also, the license in asm/barrier.h is GPL-2.0 only. It is not a userspace header so it is not covered by the userspace exception, which means at the very least the af_xdp PMD shared object is also licensed under GPL-2.0 only, isn't it?

Signature · 2 lines
Kind regards,
Luca Boccassi
#157 lore raw

Re: [PATCH v9 1/1] net/af_xdp: introduce AF XDP PMD driver

Quoted 74 lines · Luca Boccassi
Quoted 73 lines · Luca Boccassi
Quoted 57 lines · Ye Xiaolong

Hi, Luca

Quoted 33 lines · Luca Boccassi
Quoted 16 lines · Xiaolong Ye
drivers/net/af_xdp/Makefile new file +9 -0
new file mode 100644
index 000000000..8343e3016
@@ -0,0 +1,32 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+#
+# library name
+#
+LIB = librte_pmd_af_xdp.a

drivers/net/af_xdp/Makefile line 19

Quoted 10 lines
drivers/net/af_xdp/Makefile new file +10 -0
+
+EXPORT_MAP := rte_pmd_af_xdp_version.map
+
+LIBABIVER := 1
+
+CFLAGS += -O3
+
+# require kernel version >= v5.1-rc1
+CFLAGS += -I$(RTE_KERNELDIR)/tools/include
+CFLAGS += -I$(RTE_KERNELDIR)/tools/lib/bpf

Sorry for not noticing this before, but doesn't this require the full
kernel tree rather than just the typical headers package? Requiring
the

Quoted 8 lines

full kernel tree to be available at build time will make this unbuildable on distros that still use makefiles, like RHEL and SUSE. At
least on Debian and Ubuntu, the kernel headers packages distributed
do
not include the full kernel tree, only the headers, so there's no tools/lib or tools/include.

Currently we do have dependencies on the kernel src tree, as xsk.h and
asm/barrier wouldn't be installed by libbpf, so before libbpf handles
these
properly, can we keep the current RTE_KERNELDIR in Makefile for now,
and mention
the dependencies in document, also suggest users to config RTE_KERNELDIR to correct
kernel src tree if they want to use af_xdp pmd?

Quoted 8 lines

Something like:

dependencies:
- kernel source code (>= v5.1-rc1)
- build libbfp and install

Thanks,
Xiaolong

asm/barrier.h is installed by the kernel headers packages so it would be fine (although not ideal) and not need the full source tree. xsk.h is a bit more worrying, as it looks like an internal header from
here.

Quoted 6 lines
Quoted 2 lines

Is it really necessary for external applications to use an internal- only header and a kernel header to be able to use libbpf?

Actually, xsk.h is now installed by the library makefile:

https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git/commit/?id=379e2014c95b

Good to have this one. But again it is in BPF tree and it won't be in 5.1.

I suggested changing code as following for now, it would help to keep changes small when above patch merged into kernel:
CFLAGS += -I$(RTE_KERNELDIR)/tools/lib [in makefile]
#include <bpf/xsk.h> [in .c file]

Quoted 4 lines

So the full kernel source tree is no longer required.

Is asm/barrier.h really required? Isn't there an userspace alternative?

The 'asm/barrier.h' in the kernel headers and the 'tools/include/asm/barrier.h' looks different, the one in the kernel source has dependency to other kernel headers.

I wonder same thing, what is used from 'tools/include/asm/barrier.h' and if it can be avoided.

Anyway, as Xiaolong mentioned, following is working, can it work from a distro point of view:
- get kernel source code (>= v5.1-rc1)
- build libbfp and install
- set 'RTE_KERNELDIR' to point kernel source path
- build dpdk with af_xdp enabled

Quoted 6 lines

Also, the license in asm/barrier.h is GPL-2.0 only. It is not a userspace header so it is not covered by the userspace exception, which means at the very least the af_xdp PMD shared object is also licensed under GPL-2.0 only, isn't it?

#158 lore raw

Re: [PATCH v9 1/1] net/af_xdp: introduce AF XDP PMD driver

Quoted 84 lines · Ferruh Yigit
Quoted 83 lines · Luca Boccassi
Quoted 81 lines · Luca Boccassi
Quoted 61 lines · Ye Xiaolong

Hi, Luca

Quoted 36 lines · Luca Boccassi
Quoted 16 lines · Xiaolong Ye
drivers/net/af_xdp/Makefile new file +9 -0
new file mode 100644
index 000000000..8343e3016
@@ -0,0 +1,32 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+#
+# library name
+#
+LIB = librte_pmd_af_xdp.a

drivers/net/af_xdp/Makefile line 19

Quoted 10 lines
drivers/net/af_xdp/Makefile new file +10 -0
+
+EXPORT_MAP := rte_pmd_af_xdp_version.map
+
+LIBABIVER := 1
+
+CFLAGS += -O3
+
+# require kernel version >= v5.1-rc1
+CFLAGS += -I$(RTE_KERNELDIR)/tools/include
+CFLAGS += -I$(RTE_KERNELDIR)/tools/lib/bpf

Sorry for not noticing this before, but doesn't this require the
full
kernel tree rather than just the typical headers package? Requiring
the
full kernel tree to be available at build time will make this unbuildable on distros that still use makefiles, like RHEL

Quoted 8 lines

and
SUSE. At
least on Debian and Ubuntu, the kernel headers packages distributed
do
not include the full kernel tree, only the headers, so there's no
tools/lib or tools/include.

Currently we do have dependencies on the kernel src tree, as xsk.h
and
asm/barrier wouldn't be installed by libbpf, so before libbpf handles
these
properly, can we keep the current RTE_KERNELDIR in Makefile for now,
and mention
the dependencies in document, also suggest users to config RTE_KERNELDIR to correct
kernel src tree if they want to use af_xdp pmd?

Quoted 8 lines

Something like:

dependencies:
- kernel source code (>= v5.1-rc1)
- build libbfp and install

Thanks,
Xiaolong

asm/barrier.h is installed by the kernel headers packages so it would
be fine (although not ideal) and not need the full source tree. xsk.h is a bit more worrying, as it looks like an internal header from
here.

Is it really necessary for external applications to use an internal-
only header and a kernel header to be able to use libbpf?

Quoted 7 lines
Quoted 4 lines

Actually, xsk.h is now installed by the library makefile:

https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git/commit/?id=379e2014c95b

Good to have this one. But again it is in BPF tree and it won't be in 5.1.

It looks like a small and required bug fix to me, and 5.1 is still in RC state, so perhaps there's still time.

Bjorn and Magnus, any chance the above makefile install fix could be sent for inclusion in 5.1-rc4?

Quoted 17 lines

I suggested changing code as following for now, it would help to keep changes
small when above patch merged into kernel:
CFLAGS += -I$(RTE_KERNELDIR)/tools/lib [in makefile]
#include <bpf/xsk.h> [in .c file]

Quoted 4 lines

So the full kernel source tree is no longer required.

Is asm/barrier.h really required? Isn't there an userspace alternative?

The 'asm/barrier.h' in the kernel headers and the 'tools/include/asm/barrier.h'
looks different, the one in the kernel source has dependency to other kernel
headers.

Quoted 3 lines

I wonder same thing, what is used from 'tools/include/asm/barrier.h' and if it
can be avoided.

The one in tools/include also is GPL-2.0 only so it cannot be included from the PMD, which is BSD-3-clause only (and it recursively includes the other arch-specific kernel headers)

Quoted 7 lines

Anyway, as Xiaolong mentioned, following is working, can it work from a distro
point of view:
- get kernel source code (>= v5.1-rc1)
- build libbfp and install
- set 'RTE_KERNELDIR' to point kernel source path
- build dpdk with af_xdp enabled

As long as the full kernel tree is required, we cannot enable it in Debian and Ubuntu - we can't have it at build time on the build workers, and also there's the licensing problem.

Quoted 9 lines
Quoted 7 lines

Also, the license in asm/barrier.h is GPL-2.0 only. It is not a userspace header so it is not covered by the userspace exception, which
means at the very least the af_xdp PMD shared object is also licensed
under GPL-2.0 only, isn't it?

Signature · 2 lines
Kind regards,
Luca Boccassi
#159 lore raw

Re: [PATCH v9 1/1] net/af_xdp: introduce AF XDP PMD driver

Quoted 99 lines · Luca Boccassi
Quoted 90 lines · Ferruh Yigit
Quoted 89 lines · Luca Boccassi
Quoted 82 lines · Luca Boccassi
Quoted 64 lines · Ye Xiaolong

Hi, Luca

Quoted 38 lines · Luca Boccassi
Quoted 16 lines · Xiaolong Ye
drivers/net/af_xdp/Makefile new file +9 -0
new file mode 100644
index 000000000..8343e3016
@@ -0,0 +1,32 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+#
+# library name
+#
+LIB = librte_pmd_af_xdp.a

drivers/net/af_xdp/Makefile line 19

Quoted 10 lines
drivers/net/af_xdp/Makefile new file +10 -0
+
+EXPORT_MAP := rte_pmd_af_xdp_version.map
+
+LIBABIVER := 1
+
+CFLAGS += -O3
+
+# require kernel version >= v5.1-rc1
+CFLAGS += -I$(RTE_KERNELDIR)/tools/include
+CFLAGS += -I$(RTE_KERNELDIR)/tools/lib/bpf

Sorry for not noticing this before, but doesn't this require
the
full
kernel tree rather than just the typical headers package? Requiring
the
full kernel tree to be available at build time will make this
unbuildable on distros that still use makefiles, like RHEL

Quoted 8 lines

and
SUSE. At
least on Debian and Ubuntu, the kernel headers packages distributed
do
not include the full kernel tree, only the headers, so there's no
tools/lib or tools/include.

Currently we do have dependencies on the kernel src tree, as xsk.h
and
asm/barrier wouldn't be installed by libbpf, so before libbpf handles
these
properly, can we keep the current RTE_KERNELDIR in Makefile for
now,
and mention
the dependencies in document, also suggest users to config RTE_KERNELDIR to correct
kernel src tree if they want to use af_xdp pmd?

Quoted 8 lines

Something like:

dependencies:
- kernel source code (>= v5.1-rc1)
- build libbfp and install

Thanks,
Xiaolong

asm/barrier.h is installed by the kernel headers packages so it would
be fine (although not ideal) and not need the full source tree. xsk.h is a bit more worrying, as it looks like an internal header
from
here.

Quoted 3 lines

Is it really necessary for external applications to use an internal-
only header and a kernel header to be able to use libbpf?

Actually, xsk.h is now installed by the library makefile:

Quoted 7 lines
Quoted 3 lines

https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git/commit/?id=379e2014c95b

Good to have this one. But again it is in BPF tree and it won't be in
5.1.

Quoted 5 lines

It looks like a small and required bug fix to me, and 5.1 is still in RC state, so perhaps there's still time.

Bjorn and Magnus, any chance the above makefile install fix could be sent for inclusion in 5.1-rc4?

Actually the bpf tree was already merged in the net tree a couple of days ago. As far as I understand from the process, this should mean that this fix should be set for inclusion in Linus' tree in time for 5.1-rc4:

https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git/commit?id=379e2014c95b7a454713da822b8ef4ec51ab8a75

Signature · 2 lines
Kind regards,
Luca Boccassi
#160 lore raw

Re: [PATCH v9 1/1] net/af_xdp: introduce AF XDP PMD driver

Quoted 106 lines · Luca Boccassi
Quoted 99 lines · Luca Boccassi
Quoted 90 lines · Ferruh Yigit
Quoted 89 lines · Luca Boccassi
Quoted 82 lines · Luca Boccassi
Quoted 64 lines · Ye Xiaolong

Hi, Luca

Quoted 38 lines · Luca Boccassi
Quoted 16 lines · Xiaolong Ye
drivers/net/af_xdp/Makefile new file +9 -0
new file mode 100644
index 000000000..8343e3016
@@ -0,0 +1,32 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+#
+# library name
+#
+LIB = librte_pmd_af_xdp.a

drivers/net/af_xdp/Makefile line 19

Quoted 10 lines
drivers/net/af_xdp/Makefile new file +10 -0
+
+EXPORT_MAP := rte_pmd_af_xdp_version.map
+
+LIBABIVER := 1
+
+CFLAGS += -O3
+
+# require kernel version >= v5.1-rc1
+CFLAGS += -I$(RTE_KERNELDIR)/tools/include
+CFLAGS += -I$(RTE_KERNELDIR)/tools/lib/bpf

Sorry for not noticing this before, but doesn't this require
the
full
kernel tree rather than just the typical headers package? Requiring
the
full kernel tree to be available at build time will make this
unbuildable on distros that still use makefiles, like RHEL

Quoted 8 lines

and
SUSE. At
least on Debian and Ubuntu, the kernel headers packages distributed
do
not include the full kernel tree, only the headers, so there's no
tools/lib or tools/include.

Currently we do have dependencies on the kernel src tree, as xsk.h
and
asm/barrier wouldn't be installed by libbpf, so before libbpf handles
these
properly, can we keep the current RTE_KERNELDIR in Makefile for
now,
and mention
the dependencies in document, also suggest users to config RTE_KERNELDIR to correct
kernel src tree if they want to use af_xdp pmd?

Quoted 8 lines

Something like:

dependencies:
- kernel source code (>= v5.1-rc1)
- build libbfp and install

Thanks,
Xiaolong

asm/barrier.h is installed by the kernel headers packages so it would
be fine (although not ideal) and not need the full source tree. xsk.h is a bit more worrying, as it looks like an internal header
from
here.

Quoted 3 lines

Is it really necessary for external applications to use an internal-
only header and a kernel header to be able to use libbpf?

Actually, xsk.h is now installed by the library makefile:

Quoted 7 lines
Quoted 3 lines

https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git/commit/?id=379e2014c95b

Good to have this one. But again it is in BPF tree and it won't be in
5.1.

Quoted 5 lines

It looks like a small and required bug fix to me, and 5.1 is still in RC state, so perhaps there's still time.

Bjorn and Magnus, any chance the above makefile install fix could be sent for inclusion in 5.1-rc4?

Quoted 7 lines

Actually the bpf tree was already merged in the net tree a couple of days ago. As far as I understand from the process, this should mean that this fix should be set for inclusion in Linus' tree in time for 5.1-rc4:

https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git/commit?id=379e2014c95b7a454713da822b8ef4ec51ab8a75

My bad, it seems 'bpf' tree can be merged into 'net' tree, but also there is another 'bpf-next' for further releases.

So I believe it is OK to expect the fixes you pointed in 'bpf' tree to be in 5.1

#161 lore raw

Re: [PATCH v9 1/1] net/af_xdp: introduce AF XDP PMD driver

In reply to Luca Boccassi
Quoted 90 lines · Luca Boccassi
Quoted 89 lines · Ferruh Yigit
Quoted 87 lines · Luca Boccassi
Quoted 78 lines · Luca Boccassi
Quoted 61 lines · Ye Xiaolong

Hi, Luca

Quoted 36 lines · Luca Boccassi
Quoted 16 lines · Xiaolong Ye
drivers/net/af_xdp/Makefile new file +9 -0
new file mode 100644
index 000000000..8343e3016
@@ -0,0 +1,32 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+#
+# library name
+#
+LIB = librte_pmd_af_xdp.a

drivers/net/af_xdp/Makefile line 19

Quoted 10 lines
drivers/net/af_xdp/Makefile new file +10 -0
+
+EXPORT_MAP := rte_pmd_af_xdp_version.map
+
+LIBABIVER := 1
+
+CFLAGS += -O3
+
+# require kernel version >= v5.1-rc1
+CFLAGS += -I$(RTE_KERNELDIR)/tools/include
+CFLAGS += -I$(RTE_KERNELDIR)/tools/lib/bpf

Sorry for not noticing this before, but doesn't this require the
full
kernel tree rather than just the typical headers package? Requiring
the
full kernel tree to be available at build time will make this unbuildable on distros that still use makefiles, like RHEL

Quoted 8 lines

and
SUSE. At
least on Debian and Ubuntu, the kernel headers packages distributed
do
not include the full kernel tree, only the headers, so there's no
tools/lib or tools/include.

Currently we do have dependencies on the kernel src tree, as xsk.h
and
asm/barrier wouldn't be installed by libbpf, so before libbpf handles
these
properly, can we keep the current RTE_KERNELDIR in Makefile for now,
and mention
the dependencies in document, also suggest users to config RTE_KERNELDIR to correct
kernel src tree if they want to use af_xdp pmd?

Quoted 8 lines

Something like:

dependencies:
- kernel source code (>= v5.1-rc1)
- build libbfp and install

Thanks,
Xiaolong

asm/barrier.h is installed by the kernel headers packages so it would
be fine (although not ideal) and not need the full source tree. xsk.h is a bit more worrying, as it looks like an internal header from
here.

Quoted 3 lines

Is it really necessary for external applications to use an internal-
only header and a kernel header to be able to use libbpf?

Actually, xsk.h is now installed by the library makefile:

https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git/commit/?id=379e2014c95b

Quoted 29 lines
Quoted 2 lines

Good to have this one. But again it is in BPF tree and it won't be in 5.1.

It looks like a small and required bug fix to me, and 5.1 is still in RC state, so perhaps there's still time.

Bjorn and Magnus, any chance the above makefile install fix could be sent for inclusion in 5.1-rc4?

Quoted 20 lines

I suggested changing code as following for now, it would help to keep changes
small when above patch merged into kernel:
CFLAGS += -I$(RTE_KERNELDIR)/tools/lib [in makefile]
#include <bpf/xsk.h> [in .c file]

Quoted 4 lines

So the full kernel source tree is no longer required.

Is asm/barrier.h really required? Isn't there an userspace alternative?

The 'asm/barrier.h' in the kernel headers and the 'tools/include/asm/barrier.h'
looks different, the one in the kernel source has dependency to other kernel
headers.

I wonder same thing, what is used from 'tools/include/asm/barrier.h' and if it
can be avoided.

It seems, 'tools/include/asm/barrier.h' is required for 'smp_wmb()' & 'smp_rmb()' in 'xsk.h'.
We have equivalents of these in DPDK [1], and perhaps it can be possible to use them and not include this header at all.

in 'rte_eth_af_xdp.c', before including 'xsk.h', we can include an local compatibility header which does following should work:
#define smp_rmb() rte_rmb()
#define smp_wmb() rte_wmb()

@Xiaolong, what do you think?

[1]
https://git.dpdk.org/dpdk/tree/lib/librte_eal/common/include/arch/x86/rte_atomic.h?h=v19.02#n30

Quoted 13 lines

The one in tools/include also is GPL-2.0 only so it cannot be included from the PMD, which is BSD-3-clause only (and it recursively includes the other arch-specific kernel headers)

Quoted 7 lines

Anyway, as Xiaolong mentioned, following is working, can it work from a distro
point of view:
- get kernel source code (>= v5.1-rc1)
- build libbfp and install
- set 'RTE_KERNELDIR' to point kernel source path
- build dpdk with af_xdp enabled

Quoted 3 lines

As long as the full kernel tree is required, we cannot enable it in Debian and Ubuntu - we can't have it at build time on the build workers, and also there's the licensing problem.

Got it.

In above steps, 'libbpf' also build from kernel source tree, will it be problem in you builds to not have it build from source?

If not, taking into account that xsk.h also will be fixed, only 'tools/include/asm/barrier.h' remains the problem, and it looks like it can be solved, please check above.

Quoted 10 lines
Quoted 10 lines
Quoted 8 lines

Also, the license in asm/barrier.h is GPL-2.0 only. It is not a userspace header so it is not covered by the userspace exception, which
means at the very least the af_xdp PMD shared object is also licensed
under GPL-2.0 only, isn't it?

#162 lore raw

Re: [PATCH v9 1/1] net/af_xdp: introduce AF XDP PMD driver

Quoted 149 lines · Ferruh Yigit
Quoted 104 lines · Luca Boccassi
Quoted 95 lines · Ferruh Yigit
Quoted 94 lines · Luca Boccassi
Quoted 87 lines · Luca Boccassi
Quoted 67 lines · Ye Xiaolong

Hi, Luca

Quoted 39 lines · Luca Boccassi
Quoted 16 lines · Xiaolong Ye
drivers/net/af_xdp/Makefile new file +9 -0
new file mode 100644
index 000000000..8343e3016
@@ -0,0 +1,32 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+#
+# library name
+#
+LIB = librte_pmd_af_xdp.a

drivers/net/af_xdp/Makefile line 19

Quoted 10 lines
drivers/net/af_xdp/Makefile new file +10 -0
+
+EXPORT_MAP := rte_pmd_af_xdp_version.map
+
+LIBABIVER := 1
+
+CFLAGS += -O3
+
+# require kernel version >= v5.1-rc1
+CFLAGS += -I$(RTE_KERNELDIR)/tools/include
+CFLAGS += -I$(RTE_KERNELDIR)/tools/lib/bpf

Sorry for not noticing this before, but doesn't this require
the
full
kernel tree rather than just the typical headers package? Requiring
the
full kernel tree to be available at build time will make this
unbuildable on distros that still use makefiles, like RHEL

Quoted 8 lines

and
SUSE. At
least on Debian and Ubuntu, the kernel headers packages distributed
do
not include the full kernel tree, only the headers, so there's no
tools/lib or tools/include.

Currently we do have dependencies on the kernel src tree, as
xsk.h
and
asm/barrier wouldn't be installed by libbpf, so before libbpf
handles
these
properly, can we keep the current RTE_KERNELDIR in Makefile for
now,
and mention
the dependencies in document, also suggest users to config RTE_KERNELDIR to correct
kernel src tree if they want to use af_xdp pmd?

Quoted 8 lines

Something like:

dependencies:
- kernel source code (>= v5.1-rc1)
- build libbfp and install

Thanks,
Xiaolong

asm/barrier.h is installed by the kernel headers packages so it
would
be fine (although not ideal) and not need the full source tree.
xsk.h is a bit more worrying, as it looks like an internal header
from
here.

Quoted 3 lines

Is it really necessary for external applications to use an internal-
only header and a kernel header to be able to use libbpf?

Actually, xsk.h is now installed by the library makefile:

Quoted 7 lines
Quoted 3 lines

https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git/commit/?id=379e2014c95b

Good to have this one. But again it is in BPF tree and it won't be in
5.1.

Quoted 31 lines

It looks like a small and required bug fix to me, and 5.1 is still in
RC state, so perhaps there's still time.

Bjorn and Magnus, any chance the above makefile install fix could be
sent for inclusion in 5.1-rc4?

Quoted 23 lines

I suggested changing code as following for now, it would help to keep
changes
small when above patch merged into kernel:
CFLAGS += -I$(RTE_KERNELDIR)/tools/lib [in makefile]
#include <bpf/xsk.h> [in .c file]

Quoted 4 lines

So the full kernel source tree is no longer required.

Is asm/barrier.h really required? Isn't there an userspace alternative?

The 'asm/barrier.h' in the kernel headers and the 'tools/include/asm/barrier.h'
looks different, the one in the kernel source has dependency to other
kernel
headers.

I wonder same thing, what is used from
'tools/include/asm/barrier.h'
and if it
can be avoided.

It seems, 'tools/include/asm/barrier.h' is required for 'smp_wmb()' & 'smp_rmb()' in 'xsk.h'.
We have equivalents of these in DPDK [1], and perhaps it can be possible to use
them and not include this header at all.

in 'rte_eth_af_xdp.c', before including 'xsk.h', we can include an local
compatibility header which does following should work:
#define smp_rmb() rte_rmb()
#define smp_wmb() rte_wmb()

Quoted 4 lines

@Xiaolong, what do you think?

[1]
https://git.dpdk.org/dpdk/tree/lib/librte_eal/common/include/arch/x86/rte_atomic.h?h=v19.02#n30

Perfect, that looks like a great solution for the PMD.

For the broader picture, now that xsk.h is a public userspace header, it should at some point in the future be fixed to avoid depending on an internal kernel definition for the barriers, and either ship their own or depend on another public header that provides them. Otherwise every application that wants to use bpf with xdp needs to provide their own implementation - but this is not relanted to this patchset and we can live without for the moment in DPDK.

Quoted 21 lines
Quoted 15 lines

The one in tools/include also is GPL-2.0 only so it cannot be included
from the PMD, which is BSD-3-clause only (and it recursively includes
the other arch-specific kernel headers)

Quoted 8 lines

Anyway, as Xiaolong mentioned, following is working, can it work from
a distro
point of view:
- get kernel source code (>= v5.1-rc1)
- build libbfp and install
- set 'RTE_KERNELDIR' to point kernel source path
- build dpdk with af_xdp enabled

Quoted 3 lines

As long as the full kernel tree is required, we cannot enable it in Debian and Ubuntu - we can't have it at build time on the build workers, and also there's the licensing problem.

Got it.

Quoted 8 lines

In above steps, 'libbpf' also build from kernel source tree, will it be problem
in you builds to not have it build from source?

If not, taking into account that xsk.h also will be fixed, only 'tools/include/asm/barrier.h' remains the problem, and it looks like it can be
solved, please check above.

libbpf is already packaged separately in Debian and I think other distros will follow soon, so it's all good for me once the barrier issue is solved.

https://packages.debian.org/buster/libbpf-dev

Quoted 1 line

From the makefile's perspective it should not matter where it comes

from - the headers should be expected to be in /usr/include and the library in /usr/lib* - and pkg-config can help with that if available. And if a user wants to use a custom path, then it's no different than any of the other dependencies on other external libraries

Signature · 2 lines
Kind regards,
Luca Boccassi
#163 lore raw

Re: [PATCH v9 1/1] net/af_xdp: introduce AF XDP PMD driver

On 04/03, Luca Boccassi wrote:
[snip]

Quoted 18 lines
Quoted 11 lines

Got it.

In above steps, 'libbpf' also build from kernel source tree, will it be problem
in you builds to not have it build from source?

If not, taking into account that xsk.h also will be fixed, only 'tools/include/asm/barrier.h' remains the problem, and it looks like it can be
solved, please check above.

libbpf is already packaged separately in Debian and I think other distros will follow soon, so it's all good for me once the barrier issue is solved.

https://packages.debian.org/buster/libbpf-dev

Quoted 7 lines

From the makefile's perspective it should not matter where it comes from - the headers should be expected to be in /usr/include and the library in /usr/lib* - and pkg-config can help with that if available. And if a user wants to use a custom path, then it's no different than any of the other dependencies on other external libraries

From tools/lib/bpf/Makefile, after make install_lib and make install_headers,

the headers and library would be put in /usr/local/include/bpf and /usr/local/lib*, Is it ok?

Thanks,
Xiaolong

Quoted 4 lines
Signature · 3 lines
-- 
Kind regards,
Luca Boccassi
#164 lore raw

Re: [PATCH v9 1/1] net/af_xdp: introduce AF XDP PMD driver

Quoted 30 lines · Ye Xiaolong

On 04/03, Luca Boccassi wrote:
[snip]

Quoted 20 lines
Quoted 7 lines

Got it.

In above steps, 'libbpf' also build from kernel source tree, will it
be problem
in you builds to not have it build from source?

Quoted 5 lines

If not, taking into account that xsk.h also will be fixed, only 'tools/include/asm/barrier.h' remains the problem, and it looks like
it can be
solved, please check above.

libbpf is already packaged separately in Debian and I think other distros will follow soon, so it's all good for me once the barrier issue is solved.

https://packages.debian.org/buster/libbpf-dev

Quoted 7 lines

From the makefile's perspective it should not matter where it comes from - the headers should be expected to be in /usr/include and the library in /usr/lib* - and pkg-config can help with that if available.
And if a user wants to use a custom path, then it's no different than
any of the other dependencies on other external libraries

Quoted 5 lines

From tools/lib/bpf/Makefile, after make install_lib and make install_headers,
the headers and library would be put in /usr/local/include/bpf and /usr/local/lib*,
Is it ok?

Yes certainly that's fine, that's expected for local installations, and users can specify a prefix with the upstream's makefile if they want to install somewhere else.

Signature · 2 lines
Kind regards,
Luca Boccassi
#165 lore raw

Re: [PATCH v9 1/1] net/af_xdp: introduce AF XDP PMD driver

Quoted 37 lines · Luca Boccassi
Quoted 30 lines · Ye Xiaolong

On 04/03, Luca Boccassi wrote:
[snip]

Quoted 20 lines
Quoted 7 lines

Got it.

In above steps, 'libbpf' also build from kernel source tree, will it
be problem
in you builds to not have it build from source?

Quoted 5 lines

If not, taking into account that xsk.h also will be fixed, only 'tools/include/asm/barrier.h' remains the problem, and it looks like
it can be
solved, please check above.

libbpf is already packaged separately in Debian and I think other distros will follow soon, so it's all good for me once the barrier issue is solved.

https://packages.debian.org/buster/libbpf-dev

Quoted 7 lines

From the makefile's perspective it should not matter where it comes from - the headers should be expected to be in /usr/include and the library in /usr/lib* - and pkg-config can help with that if available.
And if a user wants to use a custom path, then it's no different than
any of the other dependencies on other external libraries

Quoted 5 lines

From tools/lib/bpf/Makefile, after make install_lib and make install_headers,
the headers and library would be put in /usr/local/include/bpf and /usr/local/lib*,
Is it ok?

Quoted 3 lines

Yes certainly that's fine, that's expected for local installations, and users can specify a prefix with the upstream's makefile if they want to install somewhere else.

In my local test, if I run make install_lib to install the libbpf.so to /usr/local/lib64, -lbpf specified in af_xdp pmd still fails to find the library, the build would end up with a lot of undefined references which are defined in libbpf. It means during dpdk compilation, it won't search libraries in /usr/local/lib*, right?

Install the libbpf to /usr/lib64 via make install_lib prefix=/usr doesn't have this issue, so shall I just document it in af_xdp.rst or there is other proper way to do it?

Thanks,
Xiaolong

Quoted 4 lines
Signature · 3 lines
-- 
Kind regards,
Luca Boccassi
#166 lore raw

Re: [PATCH v9 1/1] net/af_xdp: introduce AF XDP PMD driver

Quoted 42 lines · Ye Xiaolong
Quoted 37 lines · Luca Boccassi
Quoted 30 lines · Ye Xiaolong

On 04/03, Luca Boccassi wrote:
[snip]

Quoted 20 lines
Quoted 7 lines

Got it.

In above steps, 'libbpf' also build from kernel source tree, will it
be problem
in you builds to not have it build from source?

Quoted 5 lines

If not, taking into account that xsk.h also will be fixed, only 'tools/include/asm/barrier.h' remains the problem, and it looks like
it can be
solved, please check above.

libbpf is already packaged separately in Debian and I think other distros will follow soon, so it's all good for me once the barrier issue is solved.

https://packages.debian.org/buster/libbpf-dev

Quoted 7 lines

From the makefile's perspective it should not matter where it comes from - the headers should be expected to be in /usr/include and the library in /usr/lib* - and pkg-config can help with that if available.
And if a user wants to use a custom path, then it's no different than
any of the other dependencies on other external libraries

Quoted 5 lines

From tools/lib/bpf/Makefile, after make install_lib and make install_headers,
the headers and library would be put in /usr/local/include/bpf and /usr/local/lib*,
Is it ok?

Quoted 3 lines

Yes certainly that's fine, that's expected for local installations, and users can specify a prefix with the upstream's makefile if they want to install somewhere else.

Quoted 9 lines

In my local test, if I run make install_lib to install the libbpf.so to /usr/local/lib64, -lbpf specified in af_xdp pmd still fails to find the library, the build would end up with a lot of undefined references which are defined in libbpf. It means during dpdk compilation, it won't search libraries in /usr/local/lib*, right?

Install the libbpf to /usr/lib64 via make install_lib prefix=/usr doesn't have this issue, so shall I just document it in af_xdp.rst or there is other proper way to do it?

At a guess I'd say you are using Fedora Linux, right? Fedora is unusual in that it doesn't by default add /usr/local to the library and header search paths so you need to explicitly add them to your environment. Other distros should work fine for this.

/Bruce

#167 lore raw

Re: [PATCH v9 1/1] net/af_xdp: introduce AF XDP PMD driver

Quoted 48 lines · Bruce Richardson
Quoted 47 lines · Ye Xiaolong
Quoted 37 lines · Luca Boccassi
Quoted 30 lines · Ye Xiaolong

On 04/03, Luca Boccassi wrote:
[snip]

Quoted 20 lines
Quoted 7 lines

Got it.

In above steps, 'libbpf' also build from kernel source tree, will it
be problem
in you builds to not have it build from source?

Quoted 5 lines

If not, taking into account that xsk.h also will be fixed, only 'tools/include/asm/barrier.h' remains the problem, and it looks like
it can be
solved, please check above.

libbpf is already packaged separately in Debian and I think other distros will follow soon, so it's all good for me once the barrier issue is solved.

https://packages.debian.org/buster/libbpf-dev

Quoted 7 lines

From the makefile's perspective it should not matter where it comes from - the headers should be expected to be in /usr/include and the library in /usr/lib* - and pkg-config can help with that if available.
And if a user wants to use a custom path, then it's no different than
any of the other dependencies on other external libraries

Quoted 5 lines

From tools/lib/bpf/Makefile, after make install_lib and make install_headers,
the headers and library would be put in /usr/local/include/bpf and /usr/local/lib*,
Is it ok?

Quoted 3 lines

Yes certainly that's fine, that's expected for local installations, and users can specify a prefix with the upstream's makefile if they want to install somewhere else.

In my local test, if I run make install_lib to install the libbpf.so to /usr/local/lib64, -lbpf specified in af_xdp pmd still fails to find the library, the build would end up with a lot of undefined references which are defined in libbpf. It means during dpdk compilation, it won't search libraries in /usr/local/lib*, right?

Quoted 8 lines
Quoted 4 lines

Install the libbpf to /usr/lib64 via make install_lib prefix=/usr doesn't have this issue, so shall I just document it in af_xdp.rst or there is other proper way to do it?

At a guess I'd say you are using Fedora Linux, right? Fedora is unusual in that it doesn't by default add /usr/local to the library and header search paths so you need to explicitly add them to your environment. Other distros should work fine for this.

I am using centos 7.4, I guess it has the same issue as Fedora you mentioned above.

Thanks,
Xiaolong

Quoted 2 lines

/Bruce

#168 lore raw

Re: [PATCH v9 1/1] net/af_xdp: introduce AF XDP PMD driver

In reply to Ferruh Yigit

On 04/03, Ferruh Yigit wrote:
[snip]

Quoted 6 lines

It seems, 'tools/include/asm/barrier.h' is required for 'smp_wmb()' & 'smp_rmb()' in 'xsk.h'.
We have equivalents of these in DPDK [1], and perhaps it can be possible to use them and not include this header at all.

Quoted 6 lines

in 'rte_eth_af_xdp.c', before including 'xsk.h', we can include an local compatibility header which does following should work:
#define smp_rmb() rte_rmb()
#define smp_wmb() rte_wmb()

@Xiaolong, what do you think?

It sounds perfect to me, I'll take it in my next version.
Something to confirm, So we can now assume af_xdp pmd user would use kernel (say v5.1-rc4) that contains fixes regarding to xsk.h and libelf, I still need to do following changes.

1. I shall use <bpf/xsk.h> as xsk.h should be installed in system folders.
2. -lelf is not needed in rte.app.mk
3. I need to document the libbpf build and install steps in af_xdp.rst
4. add the above two defines before including xsk.h

Thanks,
Xiaolong

Quoted 42 lines

[1]
https://git.dpdk.org/dpdk/tree/lib/librte_eal/common/include/arch/x86/rte_atomic.h?h=v19.02#n30

Quoted 13 lines

The one in tools/include also is GPL-2.0 only so it cannot be included from the PMD, which is BSD-3-clause only (and it recursively includes the other arch-specific kernel headers)

Quoted 7 lines

Anyway, as Xiaolong mentioned, following is working, can it work from a distro
point of view:
- get kernel source code (>= v5.1-rc1)
- build libbfp and install
- set 'RTE_KERNELDIR' to point kernel source path
- build dpdk with af_xdp enabled

Quoted 3 lines

As long as the full kernel tree is required, we cannot enable it in Debian and Ubuntu - we can't have it at build time on the build workers, and also there's the licensing problem.

Got it.

In above steps, 'libbpf' also build from kernel source tree, will it be problem in you builds to not have it build from source?

If not, taking into account that xsk.h also will be fixed, only 'tools/include/asm/barrier.h' remains the problem, and it looks like it can be solved, please check above.

Quoted 10 lines
Quoted 10 lines
Quoted 8 lines

Also, the license in asm/barrier.h is GPL-2.0 only. It is not a userspace header so it is not covered by the userspace exception, which
means at the very least the af_xdp PMD shared object is also licensed
under GPL-2.0 only, isn't it?

#169 lore raw

Re: [PATCH v9 1/1] net/af_xdp: introduce AF XDP PMD driver

Quoted 20 lines · Ye Xiaolong

On 04/03, Ferruh Yigit wrote:
[snip]

Quoted 6 lines

It seems, 'tools/include/asm/barrier.h' is required for 'smp_wmb()' & 'smp_rmb()' in 'xsk.h'.
We have equivalents of these in DPDK [1], and perhaps it can be possible to use them and not include this header at all.

Quoted 6 lines

in 'rte_eth_af_xdp.c', before including 'xsk.h', we can include an local compatibility header which does following should work:
#define smp_rmb() rte_rmb()
#define smp_wmb() rte_wmb()

@Xiaolong, what do you think?

It sounds perfect to me, I'll take it in my next version.
Something to confirm, So we can now assume af_xdp pmd user would use kernel (say v5.1-rc4) that contains fixes regarding to xsk.h and libelf, I still need to do following changes.

Quoted 4 lines

1. I shall use <bpf/xsk.h> as xsk.h should be installed in system folders.
2. -lelf is not needed in rte.app.mk
3. I need to document the libbpf build and install steps in af_xdp.rst
4. add the above two defines before including xsk.h

Looks good to me,
only for item 4) instead of putting those defines into .c file directly, can create a private header in driver folder, put those lines and I assume will need a few includes for rte_rmb as well, and include that header before xsk.h.

Quoted 47 lines

Thanks,
Xiaolong

Quoted 42 lines

[1]
https://git.dpdk.org/dpdk/tree/lib/librte_eal/common/include/arch/x86/rte_atomic.h?h=v19.02#n30

Quoted 13 lines

The one in tools/include also is GPL-2.0 only so it cannot be included from the PMD, which is BSD-3-clause only (and it recursively includes the other arch-specific kernel headers)

Quoted 7 lines

Anyway, as Xiaolong mentioned, following is working, can it work from a distro
point of view:
- get kernel source code (>= v5.1-rc1)
- build libbfp and install
- set 'RTE_KERNELDIR' to point kernel source path
- build dpdk with af_xdp enabled

Quoted 3 lines

As long as the full kernel tree is required, we cannot enable it in Debian and Ubuntu - we can't have it at build time on the build workers, and also there's the licensing problem.

Got it.

In above steps, 'libbpf' also build from kernel source tree, will it be problem in you builds to not have it build from source?

If not, taking into account that xsk.h also will be fixed, only 'tools/include/asm/barrier.h' remains the problem, and it looks like it can be solved, please check above.

Quoted 10 lines
Quoted 10 lines
Quoted 8 lines

Also, the license in asm/barrier.h is GPL-2.0 only. It is not a userspace header so it is not covered by the userspace exception, which
means at the very least the af_xdp PMD shared object is also licensed
under GPL-2.0 only, isn't it?

#170 lore raw

Re: [PATCH v9 1/1] net/af_xdp: introduce AF XDP PMD driver

Quoted 26 lines · Ferruh Yigit
Quoted 20 lines · Ye Xiaolong

On 04/03, Ferruh Yigit wrote:
[snip]

Quoted 6 lines

It seems, 'tools/include/asm/barrier.h' is required for 'smp_wmb()' & 'smp_rmb()' in 'xsk.h'.
We have equivalents of these in DPDK [1], and perhaps it can be possible to use them and not include this header at all.

Quoted 6 lines

in 'rte_eth_af_xdp.c', before including 'xsk.h', we can include an local compatibility header which does following should work:
#define smp_rmb() rte_rmb()
#define smp_wmb() rte_wmb()

@Xiaolong, what do you think?

It sounds perfect to me, I'll take it in my next version.
Something to confirm, So we can now assume af_xdp pmd user would use kernel (say v5.1-rc4) that contains fixes regarding to xsk.h and libelf, I still need to do following changes.

Quoted 4 lines

1. I shall use <bpf/xsk.h> as xsk.h should be installed in system folders.
2. -lelf is not needed in rte.app.mk
3. I need to document the libbpf build and install steps in af_xdp.rst
4. add the above two defines before including xsk.h

Quoted 4 lines

Looks good to me,
only for item 4) instead of putting those defines into .c file directly, can create a private header in driver folder, put those lines and I assume will need a few includes for rte_rmb as well, and include that header before xsk.h.

Sounds better, will do.

Thanks,
Xiaolong

Quoted 49 lines
Quoted 48 lines

Thanks,
Xiaolong

Quoted 42 lines

[1]
https://git.dpdk.org/dpdk/tree/lib/librte_eal/common/include/arch/x86/rte_atomic.h?h=v19.02#n30

Quoted 13 lines

The one in tools/include also is GPL-2.0 only so it cannot be included from the PMD, which is BSD-3-clause only (and it recursively includes the other arch-specific kernel headers)

Quoted 7 lines

Anyway, as Xiaolong mentioned, following is working, can it work from a distro
point of view:
- get kernel source code (>= v5.1-rc1)
- build libbfp and install
- set 'RTE_KERNELDIR' to point kernel source path
- build dpdk with af_xdp enabled

Quoted 3 lines

As long as the full kernel tree is required, we cannot enable it in Debian and Ubuntu - we can't have it at build time on the build workers, and also there's the licensing problem.

Got it.

In above steps, 'libbpf' also build from kernel source tree, will it be problem in you builds to not have it build from source?

If not, taking into account that xsk.h also will be fixed, only 'tools/include/asm/barrier.h' remains the problem, and it looks like it can be solved, please check above.

Quoted 10 lines
Quoted 10 lines
Quoted 8 lines

Also, the license in asm/barrier.h is GPL-2.0 only. It is not a userspace header so it is not covered by the userspace exception, which
means at the very least the af_xdp PMD shared object is also licensed
under GPL-2.0 only, isn't it?

#171 lore raw

[dpdk-dev] [BUG] net/af_xdp: Current code can only create one af_xdp device

I tested the new af_xdp based device on the current master branch and noticed, that the usage of static mempool names allows only for the creation of a single af_xdp vdev. If a second vdev of the same type gets created, the mempool allocation fails.

Best regards,
Markus Theil

#172 lore raw

Re: [dpdk-dev] [BUG] net/af_xdp: Current code can only create one af_xdp device

Hi, Markus

Quoted 4 lines · Markus Theil

I tested the new af_xdp based device on the current master branch and noticed, that the usage of static mempool names allows only for the creation of a single af_xdp vdev. If a second vdev of the same type gets created, the mempool allocation fails.

Thanks for reporting, could you paste the cmdline you used and the error log? Are you referring to ring creation or mempool creation?

Thanks,
Xiaolong

Quoted 3 lines

Best regards,
Markus Theil

#173 lore raw

Re: [dpdk-dev] [BUG] net/af_xdp: Current code can only create one af_xdp device

Hi Xiaolong,

I tested your commit "net/af_xdp: fix creating multiple instance" on the current master branch. It does not work for me in the following minimal test setting:

1) allocate 2x 1GB huge pages for DPDK

2) ip link add p1 type veth peer name p2

3) ./dpdk-testpmd --vdev=net_af_xdp0,iface=p1 --vdev=net_af_xdp1,iface=p2 (I also tested this with two igb devices, with the same errors)

I'm using Linux 5.1-rc6 and an up to date libbpf. The setup works for the first device and fails for the second device when creating bpf maps in libbpf ("qidconf_map" or "xsks_map"). It seems, that these maps also need unique names and cannot exist twice under the same name. Furthermore if running step 3 again after it failed for the first time, xdp vdev allocation already fails for the first xdp vdev and does not reach the second one. Please let me know if you need some program output or more information from me.

Best regards,
Markus

Quoted 15 lines · Ye Xiaolong

Hi, Markus

Quoted 4 lines · Markus Theil

I tested the new af_xdp based device on the current master branch and noticed, that the usage of static mempool names allows only for the creation of a single af_xdp vdev. If a second vdev of the same type gets created, the mempool allocation fails.

Thanks for reporting, could you paste the cmdline you used and the error log? Are you referring to ring creation or mempool creation?

Thanks,
Xiaolong

Quoted 2 lines

Best regards,
Markus Theil

#174 lore raw

Re: [dpdk-dev] [BUG] net/af_xdp: Current code can only create one af_xdp device

Hi, Markus

Quoted 6 lines · Markus Theil

Hi Xiaolong,

I tested your commit "net/af_xdp: fix creating multiple instance" on the current master branch. It does not work for me in the following minimal test setting:

Quoted 7 lines

1) allocate 2x 1GB huge pages for DPDK

2) ip link add p1 type veth peer name p2

3) ./dpdk-testpmd --vdev=net_af_xdp0,iface=p1 --vdev=net_af_xdp1,iface=p2 (I also tested this with two igb devices, with the same errors)

I've tested 19.05-rc2, started testpmd with 2 af_xdp vdev (with two i40e devices), and it works for me.

$ ./x86_64-native-linuxapp-gcc/app/testpmd -l 5,6 -n 4 --log-level=pmd.net.af_xdp:info -b 82:00.1 --no-pci --vdev net_af_xdp0,iface=ens786f1 --vdev net_af_xdp1,iface=ens786f0
EAL: Detected 88 lcore(s)
EAL: Detected 2 NUMA nodes
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
EAL: Probing VFIO support...
rte_pmd_af_xdp_probe(): Initializing pmd_af_xdp for net_af_xdp0
rte_pmd_af_xdp_probe(): Initializing pmd_af_xdp for net_af_xdp1
testpmd: create a new mbuf pool <mbuf_pool_socket_0>: n=155456, size=2176, socket=0
testpmd: preferred mempool ops selected: ring_mp_mc
Configuring Port 0 (socket 0)
Port 0: 3C:FD:FE:C5:E2:41
Configuring Port 1 (socket 0)
Port 1: 3C:FD:FE:C5:E2:40
Checking link statuses...
Done
No commandline core given, start packet forwarding
io packet forwarding - ports=2 - cores=1 - streams=2 - NUMA support enabled, MP allocation mode: native
Logical Core 6 (socket 0) forwards packets on 2 streams:
  RX P=0/Q=0 (socket 0) -> TX P=1/Q=0 (socket 0) peer=02:00:00:00:00:01
  RX P=1/Q=0 (socket 0) -> TX P=0/Q=0 (socket 0) peer=02:00:00:00:00:00

io packet forwarding packets/burst=32
nb forwarding cores=1 - nb forwarding ports=2 port 0: RX queue number: 1 Tx queue number: 1
Rx offloads=0x0 Tx offloads=0x0
RX queue: 0
RX desc=0 - RX free threshold=0
RX threshold registers: pthresh=0 hthresh=0 wthresh=0 RX Offloads=0x0
TX queue: 0
TX desc=0 - TX free threshold=0
TX threshold registers: pthresh=0 hthresh=0 wthresh=0 TX offloads=0x0 - TX RS bit threshold=0
port 1: RX queue number: 1 Tx queue number: 1
Rx offloads=0x0 Tx offloads=0x0
RX queue: 0
RX desc=0 - RX free threshold=0
RX threshold registers: pthresh=0 hthresh=0 wthresh=0 RX Offloads=0x0
TX queue: 0
TX desc=0 - TX free threshold=0
TX threshold registers: pthresh=0 hthresh=0 wthresh=0 TX offloads=0x0 - TX RS bit threshold=0
Press enter to exit

Could you paste your whole failure log here?

Quoted 5 lines

I'm using Linux 5.1-rc6 and an up to date libbpf. The setup works for the first device and fails for the second device when creating bpf maps in libbpf ("qidconf_map" or "xsks_map"). It seems, that these maps also need unique names and cannot exist twice under the same name.

So far as I know, there should not be such contraint, the bpf maps creations are wrapped in libbpf.

Quoted 8 lines

Furthermore if running step 3 again after it failed for the first time, xdp vdev allocation already fails for the first xdp vdev and does not reach the second one. Please let me know if you need some program output or more information from me.

Best regards,
Markus

Thanks,
Xiaolong

Quoted 18 lines · Ye Xiaolong
Quoted 15 lines

Hi, Markus

Quoted 4 lines · Markus Theil

I tested the new af_xdp based device on the current master branch and noticed, that the usage of static mempool names allows only for the creation of a single af_xdp vdev. If a second vdev of the same type gets created, the mempool allocation fails.

Thanks for reporting, could you paste the cmdline you used and the error log? Are you referring to ring creation or mempool creation?

Thanks,
Xiaolong

Quoted 2 lines

Best regards,
Markus Theil

#175 lore raw

Re: [dpdk-dev] [BUG] net/af_xdp: Current code can only create one af_xdp device

Hi Xiaolong,

I also tested with i40e devices, with the same result.

./dpdk-testpmd -n 4 --log-level=pmd.net.af_xdp:debug --no-pci --vdev net_af_xdp0,iface=enp36s0f0 --vdev net_af_xdp1,iface=enp36s0f1
EAL: Detected 16 lcore(s)
EAL: Detected 1 NUMA nodes
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
EAL: No free hugepages reported in hugepages-2048kB
EAL: No available hugepages reported in hugepages-2048kB
EAL: Probing VFIO support...
rte_pmd_af_xdp_probe(): Initializing pmd_af_xdp for net_af_xdp0 rte_pmd_af_xdp_probe(): Initializing pmd_af_xdp for net_af_xdp1
testpmd: create a new mbuf pool <mbuf_pool_socket_0>: n=267456, size=2176, socket=0
testpmd: preferred mempool ops selected: ring_mp_mc Configuring Port 0 (socket 0)
Port 0: 3C:FD:FE:A3:E7:30
Configuring Port 1 (socket 0)
xsk_configure(): Failed to create xsk socket. (-1) eth_rx_queue_setup(): Failed to configure xdp socket
Fail to configure port 1 rx queues
EAL: Error - exiting with code: 1
  Cause: Start ports failed

If I execute the same call again, I get error -16 already on the first port:

./dpdk-testpmd -n 4 --log-level=pmd.net.af_xdp:debug --no-pci --vdev net_af_xdp0,iface=enp36s0f0 --vdev net_af_xdp1,iface=enp36s0f1
EAL: Detected 16 lcore(s)
EAL: Detected 1 NUMA nodes
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
EAL: No free hugepages reported in hugepages-2048kB
EAL: No available hugepages reported in hugepages-2048kB
EAL: Probing VFIO support...
rte_pmd_af_xdp_probe(): Initializing pmd_af_xdp for net_af_xdp0 rte_pmd_af_xdp_probe(): Initializing pmd_af_xdp for net_af_xdp1
testpmd: create a new mbuf pool <mbuf_pool_socket_0>: n=267456, size=2176, socket=0
testpmd: preferred mempool ops selected: ring_mp_mc Configuring Port 0 (socket 0)
xsk_configure(): Failed to create xsk socket. (-16) eth_rx_queue_setup(): Failed to configure xdp socket
Fail to configure port 0 rx queues
EAL: Error - exiting with code: 1
  Cause: Start ports failed

Software versions/commits/infos:

- Linux 5.1-rc6
- DPDK 7f251bcf22c5729792f9243480af1b3c072876a5 (19.05-rc2)
- libbpf from https://github.com/libbpf/libbpf
(910c475f09e5c269f441d7496c27dace30dc2335)
- DPDK and libbpf build with meson

Best regards,
Markus

Quoted 99 lines · Ye Xiaolong

Hi, Markus

Quoted 6 lines · Markus Theil

Hi Xiaolong,

I tested your commit "net/af_xdp: fix creating multiple instance" on the current master branch. It does not work for me in the following minimal test setting:

Quoted 7 lines

1) allocate 2x 1GB huge pages for DPDK

2) ip link add p1 type veth peer name p2

3) ./dpdk-testpmd --vdev=net_af_xdp0,iface=p1 --vdev=net_af_xdp1,iface=p2 (I also tested this with two igb devices, with the same errors)

I've tested 19.05-rc2, started testpmd with 2 af_xdp vdev (with two i40e devices), and it works for me.

$ ./x86_64-native-linuxapp-gcc/app/testpmd -l 5,6 -n 4 --log-level=pmd.net.af_xdp:info -b 82:00.1 --no-pci --vdev net_af_xdp0,iface=ens786f1 --vdev net_af_xdp1,iface=ens786f0
EAL: Detected 88 lcore(s)
EAL: Detected 2 NUMA nodes
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
EAL: Probing VFIO support...
rte_pmd_af_xdp_probe(): Initializing pmd_af_xdp for net_af_xdp0
rte_pmd_af_xdp_probe(): Initializing pmd_af_xdp for net_af_xdp1
testpmd: create a new mbuf pool <mbuf_pool_socket_0>: n=155456, size=2176, socket=0
testpmd: preferred mempool ops selected: ring_mp_mc
Configuring Port 0 (socket 0)
Port 0: 3C:FD:FE:C5:E2:41
Configuring Port 1 (socket 0)
Port 1: 3C:FD:FE:C5:E2:40
Checking link statuses...
Done
No commandline core given, start packet forwarding
io packet forwarding - ports=2 - cores=1 - streams=2 - NUMA support enabled, MP allocation mode: native
Logical Core 6 (socket 0) forwards packets on 2 streams:
  RX P=0/Q=0 (socket 0) -> TX P=1/Q=0 (socket 0) peer=02:00:00:00:00:01
  RX P=1/Q=0 (socket 0) -> TX P=0/Q=0 (socket 0) peer=02:00:00:00:00:00

io packet forwarding packets/burst=32
nb forwarding cores=1 - nb forwarding ports=2 port 0: RX queue number: 1 Tx queue number: 1
Rx offloads=0x0 Tx offloads=0x0
RX queue: 0
RX desc=0 - RX free threshold=0
RX threshold registers: pthresh=0 hthresh=0 wthresh=0 RX Offloads=0x0
TX queue: 0
TX desc=0 - TX free threshold=0
TX threshold registers: pthresh=0 hthresh=0 wthresh=0 TX offloads=0x0 - TX RS bit threshold=0
port 1: RX queue number: 1 Tx queue number: 1
Rx offloads=0x0 Tx offloads=0x0
RX queue: 0
RX desc=0 - RX free threshold=0
RX threshold registers: pthresh=0 hthresh=0 wthresh=0 RX Offloads=0x0
TX queue: 0
TX desc=0 - TX free threshold=0
TX threshold registers: pthresh=0 hthresh=0 wthresh=0 TX offloads=0x0 - TX RS bit threshold=0
Press enter to exit

Could you paste your whole failure log here?

Quoted 4 lines

I'm using Linux 5.1-rc6 and an up to date libbpf. The setup works for the first device and fails for the second device when creating bpf maps in libbpf ("qidconf_map" or "xsks_map"). It seems, that these maps also need unique names and cannot exist twice under the same name.

So far as I know, there should not be such contraint, the bpf maps creations are wrapped in libbpf.

Quoted 8 lines

Furthermore if running step 3 again after it failed for the first time, xdp vdev allocation already fails for the first xdp vdev and does not reach the second one. Please let me know if you need some program output or more information from me.

Best regards,
Markus

Thanks,
Xiaolong

Quoted 16 lines · Ye Xiaolong
Quoted 15 lines

Hi, Markus

Quoted 4 lines · Markus Theil

I tested the new af_xdp based device on the current master branch and noticed, that the usage of static mempool names allows only for the creation of a single af_xdp vdev. If a second vdev of the same type gets created, the mempool allocation fails.

Thanks for reporting, could you paste the cmdline you used and the error log? Are you referring to ring creation or mempool creation?

Thanks,
Xiaolong

Quoted 2 lines

Best regards,
Markus Theil

#176 lore raw

Re: [dpdk-dev] [BUG] net/af_xdp: Current code can only create one af_xdp device

Hi, Markus

Quoted 17 lines · Markus Theil

Hi Xiaolong,

I also tested with i40e devices, with the same result.

./dpdk-testpmd -n 4 --log-level=pmd.net.af_xdp:debug --no-pci --vdev net_af_xdp0,iface=enp36s0f0 --vdev net_af_xdp1,iface=enp36s0f1
EAL: Detected 16 lcore(s)
EAL: Detected 1 NUMA nodes
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
EAL: No free hugepages reported in hugepages-2048kB
EAL: No available hugepages reported in hugepages-2048kB
EAL: Probing VFIO support...
rte_pmd_af_xdp_probe(): Initializing pmd_af_xdp for net_af_xdp0 rte_pmd_af_xdp_probe(): Initializing pmd_af_xdp for net_af_xdp1
testpmd: create a new mbuf pool <mbuf_pool_socket_0>: n=267456, size=2176, socket=0
testpmd: preferred mempool ops selected: ring_mp_mc

Quoted 9 lines

Configuring Port 0 (socket 0)
Port 0: 3C:FD:FE:A3:E7:30
Configuring Port 1 (socket 0) xsk_configure(): Failed to create xsk socket. (-1) eth_rx_queue_setup(): Failed to configure xdp socket Fail to configure port 1 rx queues
EAL: Error - exiting with code: 1
  Cause: Start ports failed

What about one vdev instance on your side? And have you brought up the interface? xsk_configure requires the interface to be up state.

dsd
Thanks,
Xiaolong

Quoted 133 lines

If I execute the same call again, I get error -16 already on the first port:

./dpdk-testpmd -n 4 --log-level=pmd.net.af_xdp:debug --no-pci --vdev net_af_xdp0,iface=enp36s0f0 --vdev net_af_xdp1,iface=enp36s0f1
EAL: Detected 16 lcore(s)
EAL: Detected 1 NUMA nodes
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
EAL: No free hugepages reported in hugepages-2048kB
EAL: No available hugepages reported in hugepages-2048kB
EAL: Probing VFIO support...
rte_pmd_af_xdp_probe(): Initializing pmd_af_xdp for net_af_xdp0 rte_pmd_af_xdp_probe(): Initializing pmd_af_xdp for net_af_xdp1
testpmd: create a new mbuf pool <mbuf_pool_socket_0>: n=267456, size=2176, socket=0
testpmd: preferred mempool ops selected: ring_mp_mc Configuring Port 0 (socket 0)
xsk_configure(): Failed to create xsk socket. (-16) eth_rx_queue_setup(): Failed to configure xdp socket
Fail to configure port 0 rx queues
EAL: Error - exiting with code: 1
  Cause: Start ports failed

Software versions/commits/infos:

- Linux 5.1-rc6
- DPDK 7f251bcf22c5729792f9243480af1b3c072876a5 (19.05-rc2)
- libbpf from https://github.com/libbpf/libbpf
(910c475f09e5c269f441d7496c27dace30dc2335)
- DPDK and libbpf build with meson

Best regards,
Markus

Quoted 99 lines · Ye Xiaolong

Hi, Markus

Quoted 6 lines · Markus Theil

Hi Xiaolong,

I tested your commit "net/af_xdp: fix creating multiple instance" on the current master branch. It does not work for me in the following minimal test setting:

Quoted 7 lines

1) allocate 2x 1GB huge pages for DPDK

2) ip link add p1 type veth peer name p2

3) ./dpdk-testpmd --vdev=net_af_xdp0,iface=p1 --vdev=net_af_xdp1,iface=p2 (I also tested this with two igb devices, with the same errors)

I've tested 19.05-rc2, started testpmd with 2 af_xdp vdev (with two i40e devices), and it works for me.

$ ./x86_64-native-linuxapp-gcc/app/testpmd -l 5,6 -n 4 --log-level=pmd.net.af_xdp:info -b 82:00.1 --no-pci --vdev net_af_xdp0,iface=ens786f1 --vdev net_af_xdp1,iface=ens786f0
EAL: Detected 88 lcore(s)
EAL: Detected 2 NUMA nodes
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
EAL: Probing VFIO support...
rte_pmd_af_xdp_probe(): Initializing pmd_af_xdp for net_af_xdp0
rte_pmd_af_xdp_probe(): Initializing pmd_af_xdp for net_af_xdp1
testpmd: create a new mbuf pool <mbuf_pool_socket_0>: n=155456, size=2176, socket=0
testpmd: preferred mempool ops selected: ring_mp_mc
Configuring Port 0 (socket 0)
Port 0: 3C:FD:FE:C5:E2:41
Configuring Port 1 (socket 0)
Port 1: 3C:FD:FE:C5:E2:40
Checking link statuses...
Done
No commandline core given, start packet forwarding
io packet forwarding - ports=2 - cores=1 - streams=2 - NUMA support enabled, MP allocation mode: native
Logical Core 6 (socket 0) forwards packets on 2 streams:
  RX P=0/Q=0 (socket 0) -> TX P=1/Q=0 (socket 0) peer=02:00:00:00:00:01
  RX P=1/Q=0 (socket 0) -> TX P=0/Q=0 (socket 0) peer=02:00:00:00:00:00

io packet forwarding packets/burst=32
nb forwarding cores=1 - nb forwarding ports=2 port 0: RX queue number: 1 Tx queue number: 1
Rx offloads=0x0 Tx offloads=0x0
RX queue: 0
RX desc=0 - RX free threshold=0
RX threshold registers: pthresh=0 hthresh=0 wthresh=0 RX Offloads=0x0
TX queue: 0
TX desc=0 - TX free threshold=0
TX threshold registers: pthresh=0 hthresh=0 wthresh=0 TX offloads=0x0 - TX RS bit threshold=0
port 1: RX queue number: 1 Tx queue number: 1
Rx offloads=0x0 Tx offloads=0x0
RX queue: 0
RX desc=0 - RX free threshold=0
RX threshold registers: pthresh=0 hthresh=0 wthresh=0 RX Offloads=0x0
TX queue: 0
TX desc=0 - TX free threshold=0
TX threshold registers: pthresh=0 hthresh=0 wthresh=0 TX offloads=0x0 - TX RS bit threshold=0
Press enter to exit

Could you paste your whole failure log here?

Quoted 4 lines

I'm using Linux 5.1-rc6 and an up to date libbpf. The setup works for the first device and fails for the second device when creating bpf maps in libbpf ("qidconf_map" or "xsks_map"). It seems, that these maps also need unique names and cannot exist twice under the same name.

So far as I know, there should not be such contraint, the bpf maps creations are wrapped in libbpf.

Quoted 8 lines

Furthermore if running step 3 again after it failed for the first time, xdp vdev allocation already fails for the first xdp vdev and does not reach the second one. Please let me know if you need some program output or more information from me.

Best regards,
Markus

Thanks,
Xiaolong

Quoted 16 lines · Ye Xiaolong
Quoted 15 lines

Hi, Markus

Quoted 4 lines · Markus Theil

I tested the new af_xdp based device on the current master branch and noticed, that the usage of static mempool names allows only for the creation of a single af_xdp vdev. If a second vdev of the same type gets created, the mempool allocation fails.

Thanks for reporting, could you paste the cmdline you used and the error log? Are you referring to ring creation or mempool creation?

Thanks,
Xiaolong

Quoted 2 lines

Best regards,
Markus Theil

#177 lore raw

Re: [dpdk-dev] [BUG] net/af_xdp: Current code can only create one af_xdp device

Hi Xiaolong,

with only one vdev everything works. It stops working if I use two vdevs. Both interfaces were brought up before testing.

Best regards,
Markus

Quoted 170 lines · Ye Xiaolong

Hi, Markus

Quoted 17 lines · Markus Theil

Hi Xiaolong,

I also tested with i40e devices, with the same result.

./dpdk-testpmd -n 4 --log-level=pmd.net.af_xdp:debug --no-pci --vdev net_af_xdp0,iface=enp36s0f0 --vdev net_af_xdp1,iface=enp36s0f1
EAL: Detected 16 lcore(s)
EAL: Detected 1 NUMA nodes
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
EAL: No free hugepages reported in hugepages-2048kB
EAL: No available hugepages reported in hugepages-2048kB
EAL: Probing VFIO support...
rte_pmd_af_xdp_probe(): Initializing pmd_af_xdp for net_af_xdp0 rte_pmd_af_xdp_probe(): Initializing pmd_af_xdp for net_af_xdp1
testpmd: create a new mbuf pool <mbuf_pool_socket_0>: n=267456, size=2176, socket=0
testpmd: preferred mempool ops selected: ring_mp_mc

Quoted 9 lines

Configuring Port 0 (socket 0)
Port 0: 3C:FD:FE:A3:E7:30
Configuring Port 1 (socket 0) xsk_configure(): Failed to create xsk socket. (-1) eth_rx_queue_setup(): Failed to configure xdp socket Fail to configure port 1 rx queues
EAL: Error - exiting with code: 1
  Cause: Start ports failed

What about one vdev instance on your side? And have you brought up the interface? xsk_configure requires the interface to be up state.

dsd
Thanks,
Xiaolong

Quoted 133 lines

If I execute the same call again, I get error -16 already on the first port:

./dpdk-testpmd -n 4 --log-level=pmd.net.af_xdp:debug --no-pci --vdev net_af_xdp0,iface=enp36s0f0 --vdev net_af_xdp1,iface=enp36s0f1
EAL: Detected 16 lcore(s)
EAL: Detected 1 NUMA nodes
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
EAL: No free hugepages reported in hugepages-2048kB
EAL: No available hugepages reported in hugepages-2048kB
EAL: Probing VFIO support...
rte_pmd_af_xdp_probe(): Initializing pmd_af_xdp for net_af_xdp0 rte_pmd_af_xdp_probe(): Initializing pmd_af_xdp for net_af_xdp1
testpmd: create a new mbuf pool <mbuf_pool_socket_0>: n=267456, size=2176, socket=0
testpmd: preferred mempool ops selected: ring_mp_mc Configuring Port 0 (socket 0)
xsk_configure(): Failed to create xsk socket. (-16) eth_rx_queue_setup(): Failed to configure xdp socket
Fail to configure port 0 rx queues
EAL: Error - exiting with code: 1
  Cause: Start ports failed

Software versions/commits/infos:

- Linux 5.1-rc6
- DPDK 7f251bcf22c5729792f9243480af1b3c072876a5 (19.05-rc2)
- libbpf from https://github.com/libbpf/libbpf
(910c475f09e5c269f441d7496c27dace30dc2335)
- DPDK and libbpf build with meson

Best regards,
Markus

Quoted 99 lines · Ye Xiaolong

Hi, Markus

Quoted 6 lines · Markus Theil

Hi Xiaolong,

I tested your commit "net/af_xdp: fix creating multiple instance" on the current master branch. It does not work for me in the following minimal test setting:

Quoted 7 lines

1) allocate 2x 1GB huge pages for DPDK

2) ip link add p1 type veth peer name p2

3) ./dpdk-testpmd --vdev=net_af_xdp0,iface=p1 --vdev=net_af_xdp1,iface=p2 (I also tested this with two igb devices, with the same errors)

I've tested 19.05-rc2, started testpmd with 2 af_xdp vdev (with two i40e devices), and it works for me.

$ ./x86_64-native-linuxapp-gcc/app/testpmd -l 5,6 -n 4 --log-level=pmd.net.af_xdp:info -b 82:00.1 --no-pci --vdev net_af_xdp0,iface=ens786f1 --vdev net_af_xdp1,iface=ens786f0
EAL: Detected 88 lcore(s)
EAL: Detected 2 NUMA nodes
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
EAL: Probing VFIO support...
rte_pmd_af_xdp_probe(): Initializing pmd_af_xdp for net_af_xdp0
rte_pmd_af_xdp_probe(): Initializing pmd_af_xdp for net_af_xdp1
testpmd: create a new mbuf pool <mbuf_pool_socket_0>: n=155456, size=2176, socket=0
testpmd: preferred mempool ops selected: ring_mp_mc
Configuring Port 0 (socket 0)
Port 0: 3C:FD:FE:C5:E2:41
Configuring Port 1 (socket 0)
Port 1: 3C:FD:FE:C5:E2:40
Checking link statuses...
Done
No commandline core given, start packet forwarding
io packet forwarding - ports=2 - cores=1 - streams=2 - NUMA support enabled, MP allocation mode: native
Logical Core 6 (socket 0) forwards packets on 2 streams:
  RX P=0/Q=0 (socket 0) -> TX P=1/Q=0 (socket 0) peer=02:00:00:00:00:01
  RX P=1/Q=0 (socket 0) -> TX P=0/Q=0 (socket 0) peer=02:00:00:00:00:00

io packet forwarding packets/burst=32
nb forwarding cores=1 - nb forwarding ports=2 port 0: RX queue number: 1 Tx queue number: 1
Rx offloads=0x0 Tx offloads=0x0
RX queue: 0
RX desc=0 - RX free threshold=0
RX threshold registers: pthresh=0 hthresh=0 wthresh=0 RX Offloads=0x0
TX queue: 0
TX desc=0 - TX free threshold=0
TX threshold registers: pthresh=0 hthresh=0 wthresh=0 TX offloads=0x0 - TX RS bit threshold=0
port 1: RX queue number: 1 Tx queue number: 1
Rx offloads=0x0 Tx offloads=0x0
RX queue: 0
RX desc=0 - RX free threshold=0
RX threshold registers: pthresh=0 hthresh=0 wthresh=0 RX Offloads=0x0
TX queue: 0
TX desc=0 - TX free threshold=0
TX threshold registers: pthresh=0 hthresh=0 wthresh=0 TX offloads=0x0 - TX RS bit threshold=0
Press enter to exit

Could you paste your whole failure log here?

Quoted 4 lines

I'm using Linux 5.1-rc6 and an up to date libbpf. The setup works for the first device and fails for the second device when creating bpf maps in libbpf ("qidconf_map" or "xsks_map"). It seems, that these maps also need unique names and cannot exist twice under the same name.

So far as I know, there should not be such contraint, the bpf maps creations are wrapped in libbpf.

Quoted 8 lines

Furthermore if running step 3 again after it failed for the first time, xdp vdev allocation already fails for the first xdp vdev and does not reach the second one. Please let me know if you need some program output or more information from me.

Best regards,
Markus

Thanks,
Xiaolong

Quoted 16 lines · Ye Xiaolong
Quoted 15 lines

Hi, Markus

Quoted 4 lines · Markus Theil

I tested the new af_xdp based device on the current master branch and noticed, that the usage of static mempool names allows only for the creation of a single af_xdp vdev. If a second vdev of the same type gets created, the mempool allocation fails.

Thanks for reporting, could you paste the cmdline you used and the error log? Are you referring to ring creation or mempool creation?

Thanks,
Xiaolong

Quoted 2 lines

Best regards,
Markus Theil

Signature · 9 lines
Markus Theil

Technische Universität Ilmenau, Fachgebiet Telematik/Rechnernetze
Postfach 100565
98684 Ilmenau, Germany

Phone: +49 3677 69-4582
Email: markus[dot]theil[at]tu-ilmenau[dot]de
Web: http://www.tu-ilmenau.de/telematik
#178 lore raw

Re: [dpdk-dev] [BUG] net/af_xdp: Current code can only create one af_xdp device

In reply to Markus Theil

Hi, Markus

Quoted 17 lines · Markus Theil

Hi Xiaolong,

I also tested with i40e devices, with the same result.

./dpdk-testpmd -n 4 --log-level=pmd.net.af_xdp:debug --no-pci --vdev net_af_xdp0,iface=enp36s0f0 --vdev net_af_xdp1,iface=enp36s0f1
EAL: Detected 16 lcore(s)
EAL: Detected 1 NUMA nodes
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
EAL: No free hugepages reported in hugepages-2048kB
EAL: No available hugepages reported in hugepages-2048kB
EAL: Probing VFIO support...
rte_pmd_af_xdp_probe(): Initializing pmd_af_xdp for net_af_xdp0 rte_pmd_af_xdp_probe(): Initializing pmd_af_xdp for net_af_xdp1
testpmd: create a new mbuf pool <mbuf_pool_socket_0>: n=267456, size=2176, socket=0
testpmd: preferred mempool ops selected: ring_mp_mc

Quoted 8 lines

Configuring Port 0 (socket 0)
Port 0: 3C:FD:FE:A3:E7:30
Configuring Port 1 (socket 0) xsk_configure(): Failed to create xsk socket. (-1) eth_rx_queue_setup(): Failed to configure xdp socket Fail to configure port 1 rx queues
EAL: Error - exiting with code: 1
  Cause: Start ports failed

(-1) error should typically refer to "Operation not permitted", any special configuration for you interfaces and were you running it with root privilege? and out of curiosity, why you got (-1) in your log, do you add some private patch to print the errno?

Thanks,
Xiaolong

Quoted 134 lines

If I execute the same call again, I get error -16 already on the first port:

./dpdk-testpmd -n 4 --log-level=pmd.net.af_xdp:debug --no-pci --vdev net_af_xdp0,iface=enp36s0f0 --vdev net_af_xdp1,iface=enp36s0f1
EAL: Detected 16 lcore(s)
EAL: Detected 1 NUMA nodes
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
EAL: No free hugepages reported in hugepages-2048kB
EAL: No available hugepages reported in hugepages-2048kB
EAL: Probing VFIO support...
rte_pmd_af_xdp_probe(): Initializing pmd_af_xdp for net_af_xdp0 rte_pmd_af_xdp_probe(): Initializing pmd_af_xdp for net_af_xdp1
testpmd: create a new mbuf pool <mbuf_pool_socket_0>: n=267456, size=2176, socket=0
testpmd: preferred mempool ops selected: ring_mp_mc Configuring Port 0 (socket 0)
xsk_configure(): Failed to create xsk socket. (-16) eth_rx_queue_setup(): Failed to configure xdp socket
Fail to configure port 0 rx queues
EAL: Error - exiting with code: 1
  Cause: Start ports failed

Software versions/commits/infos:

- Linux 5.1-rc6
- DPDK 7f251bcf22c5729792f9243480af1b3c072876a5 (19.05-rc2)
- libbpf from https://github.com/libbpf/libbpf
(910c475f09e5c269f441d7496c27dace30dc2335)
- DPDK and libbpf build with meson

Best regards,
Markus

Quoted 99 lines · Ye Xiaolong

Hi, Markus

Quoted 6 lines · Markus Theil

Hi Xiaolong,

I tested your commit "net/af_xdp: fix creating multiple instance" on the current master branch. It does not work for me in the following minimal test setting:

Quoted 7 lines

1) allocate 2x 1GB huge pages for DPDK

2) ip link add p1 type veth peer name p2

3) ./dpdk-testpmd --vdev=net_af_xdp0,iface=p1 --vdev=net_af_xdp1,iface=p2 (I also tested this with two igb devices, with the same errors)

I've tested 19.05-rc2, started testpmd with 2 af_xdp vdev (with two i40e devices), and it works for me.

$ ./x86_64-native-linuxapp-gcc/app/testpmd -l 5,6 -n 4 --log-level=pmd.net.af_xdp:info -b 82:00.1 --no-pci --vdev net_af_xdp0,iface=ens786f1 --vdev net_af_xdp1,iface=ens786f0
EAL: Detected 88 lcore(s)
EAL: Detected 2 NUMA nodes
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
EAL: Probing VFIO support...
rte_pmd_af_xdp_probe(): Initializing pmd_af_xdp for net_af_xdp0
rte_pmd_af_xdp_probe(): Initializing pmd_af_xdp for net_af_xdp1
testpmd: create a new mbuf pool <mbuf_pool_socket_0>: n=155456, size=2176, socket=0
testpmd: preferred mempool ops selected: ring_mp_mc
Configuring Port 0 (socket 0)
Port 0: 3C:FD:FE:C5:E2:41
Configuring Port 1 (socket 0)
Port 1: 3C:FD:FE:C5:E2:40
Checking link statuses...
Done
No commandline core given, start packet forwarding
io packet forwarding - ports=2 - cores=1 - streams=2 - NUMA support enabled, MP allocation mode: native
Logical Core 6 (socket 0) forwards packets on 2 streams:
  RX P=0/Q=0 (socket 0) -> TX P=1/Q=0 (socket 0) peer=02:00:00:00:00:01
  RX P=1/Q=0 (socket 0) -> TX P=0/Q=0 (socket 0) peer=02:00:00:00:00:00

io packet forwarding packets/burst=32
nb forwarding cores=1 - nb forwarding ports=2 port 0: RX queue number: 1 Tx queue number: 1
Rx offloads=0x0 Tx offloads=0x0
RX queue: 0
RX desc=0 - RX free threshold=0
RX threshold registers: pthresh=0 hthresh=0 wthresh=0 RX Offloads=0x0
TX queue: 0
TX desc=0 - TX free threshold=0
TX threshold registers: pthresh=0 hthresh=0 wthresh=0 TX offloads=0x0 - TX RS bit threshold=0
port 1: RX queue number: 1 Tx queue number: 1
Rx offloads=0x0 Tx offloads=0x0
RX queue: 0
RX desc=0 - RX free threshold=0
RX threshold registers: pthresh=0 hthresh=0 wthresh=0 RX Offloads=0x0
TX queue: 0
TX desc=0 - TX free threshold=0
TX threshold registers: pthresh=0 hthresh=0 wthresh=0 TX offloads=0x0 - TX RS bit threshold=0
Press enter to exit

Could you paste your whole failure log here?

Quoted 4 lines

I'm using Linux 5.1-rc6 and an up to date libbpf. The setup works for the first device and fails for the second device when creating bpf maps in libbpf ("qidconf_map" or "xsks_map"). It seems, that these maps also need unique names and cannot exist twice under the same name.

So far as I know, there should not be such contraint, the bpf maps creations are wrapped in libbpf.

Quoted 8 lines

Furthermore if running step 3 again after it failed for the first time, xdp vdev allocation already fails for the first xdp vdev and does not reach the second one. Please let me know if you need some program output or more information from me.

Best regards,
Markus

Thanks,
Xiaolong

Quoted 16 lines · Ye Xiaolong
Quoted 15 lines

Hi, Markus

Quoted 4 lines · Markus Theil

I tested the new af_xdp based device on the current master branch and noticed, that the usage of static mempool names allows only for the creation of a single af_xdp vdev. If a second vdev of the same type gets created, the mempool allocation fails.

Thanks for reporting, could you paste the cmdline you used and the error log? Are you referring to ring creation or mempool creation?

Thanks,
Xiaolong

Quoted 2 lines

Best regards,
Markus Theil

#179 lore raw

PATCH 1/2 net/af_xdp: name the buf ring dynamically

In reply to Markus Theil

Naming the buf_ring dynamically allows to create multiple af_xdp vdevs.

Fixes f1debd77efaf ("net/af_xdp: introduce AF_XDP PMD")
---
 drivers/net/af_xdp/rte_eth_af_xdp.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/net/af_xdp/rte_eth_af_xdp.c +6 -3
index 497e2cfde..d8e99204e 100644
@@ -473,7 +473,7 @@ xdp_umem_destroy(struct xsk_umem_info *umem)
 }
 
 static struct
-xsk_umem_info *xdp_umem_configure(void)
+xsk_umem_info *xdp_umem_configure(struct pmd_internals *internals)
 {
 	struct xsk_umem_info *umem;
 	const struct rte_memzone *mz;
@@ -482,6 +482,7 @@ xsk_umem_info *xdp_umem_configure(void)
 		.comp_size = ETH_AF_XDP_DFLT_NUM_DESCS,
 		.frame_size = ETH_AF_XDP_FRAME_SIZE,
 		.frame_headroom = ETH_AF_XDP_DATA_HEADROOM };
+	char ring_name[RTE_RING_NAMESIZE];
 	int ret;
 	uint64_t i;
 
@@ -491,7 +492,9 @@ xsk_umem_info *xdp_umem_configure(void)
 		return NULL;
 	}
 
-	umem->buf_ring = rte_ring_create("af_xdp_ring",
+	ret = snprintf(ring_name, sizeof(ring_name), "af_xdp_ring_%s_%d",
+		       internals->if_name, internals->queue_idx);
+	umem->buf_ring = rte_ring_create(ring_name,
 					 ETH_AF_XDP_NUM_BUFFERS,
 					 rte_socket_id(),
 					 0x0);
@@ -541,7 +544,7 @@ xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
 	int ret = 0;
 	int reserve_size;
 
-	rxq->umem = xdp_umem_configure();
+	rxq->umem = xdp_umem_configure(internals);
 	if (rxq->umem == NULL)
 		return -ENOMEM;
 
Signature · 1 line
2.17.1
#180 lore raw

PATCH 2/2 net/af_xdp: name the umem memzone dynamically

Naming the umem memzone dynamically allows to create multiple af_xdp vdevs.

Fixes f1debd77efaf ("net/af_xdp: introduce AF_XDP PMD")
---
 drivers/net/af_xdp/rte_eth_af_xdp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/af_xdp/rte_eth_af_xdp.c +4 -1
index d8e99204e..666b4c17e 100644
@@ -483,6 +483,7 @@ xsk_umem_info *xdp_umem_configure(struct pmd_internals *internals)
 		.frame_size = ETH_AF_XDP_FRAME_SIZE,
 		.frame_headroom = ETH_AF_XDP_DATA_HEADROOM };
 	char ring_name[RTE_RING_NAMESIZE];
+	char mz_name[RTE_MEMZONE_NAMESIZE];
 	int ret;
 	uint64_t i;
 
@@ -508,7 +509,9 @@ xsk_umem_info *xdp_umem_configure(struct pmd_internals *internals)
 				 (void *)(i * ETH_AF_XDP_FRAME_SIZE +
 					  ETH_AF_XDP_DATA_HEADROOM));
 
-	mz = rte_memzone_reserve_aligned("af_xdp uemem",
+	ret = snprintf(mz_name, sizeof(mz_name), "af_xdp_umem_%s_%d",
+		       internals->if_name, internals->queue_idx);
+	mz = rte_memzone_reserve_aligned(mz_name,
 			ETH_AF_XDP_NUM_BUFFERS * ETH_AF_XDP_FRAME_SIZE,
 			rte_socket_id(), RTE_MEMZONE_IOVA_CONTIG,
 			getpagesize());
Signature · 1 line
2.17.1
Reviewed-by on v1 2/2
#181 lore raw

Re: [dpdk-dev] [PATCH v1 2/2] net/af_xdp: name the umem memzone dynamically

Quoted 25 lines · Xiaolong Ye

Naming the umem memzone dynamically allows to create multiple af_xdp vdevs.

Fixes f1debd77efaf ("net/af_xdp: introduce AF_XDP PMD")
---
 drivers/net/af_xdp/rte_eth_af_xdp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/af_xdp/rte_eth_af_xdp.c +1 -0
index d8e99204e..666b4c17e 100644
@@ -483,6 +483,7 @@ xsk_umem_info *xdp_umem_configure(struct pmd_internals
 *internals)
                .frame_size = ETH_AF_XDP_FRAME_SIZE,
                .frame_headroom = ETH_AF_XDP_DATA_HEADROOM };
        char ring_name[RTE_RING_NAMESIZE];
+       char mz_name[RTE_MEMZONE_NAMESIZE];
        int ret;
        uint64_t i;

drivers/net/af_xdp/rte_eth_af_xdp.c xsk_umem_info *xdp_umem_configure(struct pmd_internals · line 515

Quoted 8 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +2 -1
@@ -508,7 +509,9 @@ xsk_umem_info *xdp_umem_configure(struct pmd_internals
 *internals)
                                 (void *)(i * ETH_AF_XDP_FRAME_SIZE +
                                          ETH_AF_XDP_DATA_HEADROOM));
 
-       mz = rte_memzone_reserve_aligned("af_xdp uemem",
+       ret = snprintf(mz_name, sizeof(mz_name), "af_xdp_umem_%s_%d",
+                      internals->if_name, internals->queue_idx);
 

Idem previous patch.

+ mz = rte_memzone_reserve_aligned(mz_name,

Quoted 7 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +0 -1
                        ETH_AF_XDP_NUM_BUFFERS * ETH_AF_XDP_FRAME_SIZE,
                        rte_socket_id(), RTE_MEMZONE_IOVA_CONTIG,
                        getpagesize());
--

2.17.1

How about squashing those two patches as a single one ?
The issue is that you can't create multiple devices. Having the first one still leaves the issue.

Signature · 1 line
David Marchand
#182 lore raw

Re: [dpdk-dev] [PATCH v1 2/2] net/af_xdp: name the umem memzone dynamically

Quoted 46 lines · David Marchand
Quoted 25 lines · Xiaolong Ye

Naming the umem memzone dynamically allows to create multiple af_xdp vdevs.

Fixes f1debd77efaf ("net/af_xdp: introduce AF_XDP PMD")
---
 drivers/net/af_xdp/rte_eth_af_xdp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/af_xdp/rte_eth_af_xdp.c +1 -0
index d8e99204e..666b4c17e 100644
@@ -483,6 +483,7 @@ xsk_umem_info *xdp_umem_configure(struct pmd_internals
 *internals)
                .frame_size = ETH_AF_XDP_FRAME_SIZE,
                .frame_headroom = ETH_AF_XDP_DATA_HEADROOM };
        char ring_name[RTE_RING_NAMESIZE];
+       char mz_name[RTE_MEMZONE_NAMESIZE];
        int ret;
        uint64_t i;

drivers/net/af_xdp/rte_eth_af_xdp.c xsk_umem_info *xdp_umem_configure(struct pmd_internals · line 515

Quoted 8 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +2 -1
@@ -508,7 +509,9 @@ xsk_umem_info *xdp_umem_configure(struct pmd_internals
 *internals)
                                 (void *)(i * ETH_AF_XDP_FRAME_SIZE +
                                          ETH_AF_XDP_DATA_HEADROOM));
 
-       mz = rte_memzone_reserve_aligned("af_xdp uemem",
+       ret = snprintf(mz_name, sizeof(mz_name), "af_xdp_umem_%s_%d",
+                      internals->if_name, internals->queue_idx);
 

Idem previous patch.

+ mz = rte_memzone_reserve_aligned(mz_name,

Quoted 7 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +0 -1
                        ETH_AF_XDP_NUM_BUFFERS * ETH_AF_XDP_FRAME_SIZE,
                        rte_socket_id(), RTE_MEMZONE_IOVA_CONTIG,
                        getpagesize());
--

2.17.1

Quoted 4 lines

How about squashing those two patches as a single one ?
The issue is that you can't create multiple devices. Having the first one still leaves the issue.

+1 to squash. let me make a new version applying minor issues you pointed in other patch, squashing both and keeping your review tag.

Quoted 3 lines
#183 lore raw

Re: [dpdk-dev] [PATCH v1 2/2] net/af_xdp: name the umem memzone dynamically

Quoted 47 lines · Ferruh Yigit
Quoted 46 lines · David Marchand
Quoted 25 lines · Xiaolong Ye

Naming the umem memzone dynamically allows to create multiple af_xdp vdevs.

Fixes f1debd77efaf ("net/af_xdp: introduce AF_XDP PMD")
---
 drivers/net/af_xdp/rte_eth_af_xdp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/af_xdp/rte_eth_af_xdp.c +1 -0
index d8e99204e..666b4c17e 100644
@@ -483,6 +483,7 @@ xsk_umem_info *xdp_umem_configure(struct pmd_internals
 *internals)
                .frame_size = ETH_AF_XDP_FRAME_SIZE,
                .frame_headroom = ETH_AF_XDP_DATA_HEADROOM };
        char ring_name[RTE_RING_NAMESIZE];
+       char mz_name[RTE_MEMZONE_NAMESIZE];
        int ret;
        uint64_t i;

drivers/net/af_xdp/rte_eth_af_xdp.c xsk_umem_info *xdp_umem_configure(struct pmd_internals · line 515

Quoted 8 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +2 -1
@@ -508,7 +509,9 @@ xsk_umem_info *xdp_umem_configure(struct pmd_internals
 *internals)
                                 (void *)(i * ETH_AF_XDP_FRAME_SIZE +
                                          ETH_AF_XDP_DATA_HEADROOM));
 
-       mz = rte_memzone_reserve_aligned("af_xdp uemem",
+       ret = snprintf(mz_name, sizeof(mz_name), "af_xdp_umem_%s_%d",
+                      internals->if_name, internals->queue_idx);
 

Idem previous patch.

+ mz = rte_memzone_reserve_aligned(mz_name,

Quoted 7 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +0 -1
                        ETH_AF_XDP_NUM_BUFFERS * ETH_AF_XDP_FRAME_SIZE,
                        rte_socket_id(), RTE_MEMZONE_IOVA_CONTIG,
                        getpagesize());
--

2.17.1

Quoted 7 lines
Quoted 4 lines

How about squashing those two patches as a single one ?
The issue is that you can't create multiple devices. Having the first one still leaves the issue.

+1 to squash. let me make a new version applying minor issues you pointed in other patch, squashing both and keeping your review tag.

Thanks for doing the new patch.

Quoted 5 lines
Quoted 4 lines
Reviewed-by on v1 1/2
#184 lore raw

Re: [dpdk-dev] [PATCH v1 1/2] net/af_xdp: name the buf ring dynamically

In reply to Xiaolong Ye
Quoted 33 lines · Xiaolong Ye

Naming the buf_ring dynamically allows to create multiple af_xdp vdevs.

Fixes f1debd77efaf ("net/af_xdp: introduce AF_XDP PMD")
---
 drivers/net/af_xdp/rte_eth_af_xdp.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/net/af_xdp/rte_eth_af_xdp.c +2 -1
index 497e2cfde..d8e99204e 100644
@@ -473,7 +473,7 @@ xdp_umem_destroy(struct xsk_umem_info *umem)
 }
 
 static struct
-xsk_umem_info *xdp_umem_configure(void)
+xsk_umem_info *xdp_umem_configure(struct pmd_internals *internals)
 {
        struct xsk_umem_info *umem;
        const struct rte_memzone *mz;
@@ -482,6 +482,7 @@ xsk_umem_info *xdp_umem_configure(void)
                .comp_size = ETH_AF_XDP_DFLT_NUM_DESCS,
                .frame_size = ETH_AF_XDP_FRAME_SIZE,
                .frame_headroom = ETH_AF_XDP_DATA_HEADROOM };
+       char ring_name[RTE_RING_NAMESIZE];
        int ret;
        uint64_t i;
 

drivers/net/af_xdp/rte_eth_af_xdp.c xsk_umem_info *xdp_umem_configure(void) · line 497

Quoted 7 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +2 -1
@@ -491,7 +492,9 @@ xsk_umem_info *xdp_umem_configure(void)
                return NULL;
        }
 
-       umem->buf_ring = rte_ring_create("af_xdp_ring",
+       ret = snprintf(ring_name, sizeof(ring_name), "af_xdp_ring_%s_%d",
+                      internals->if_name, internals->queue_idx);
 

You can drop the ret assignment, you won't check it anyway. queue_idx is unsigned %d -> %u ?

+ umem->buf_ring = rte_ring_create(ring_name,

Quoted 14 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +1 -2
                                         ETH_AF_XDP_NUM_BUFFERS,
                                         rte_socket_id(),
                                         0x0);
@@ -541,7 +544,7 @@ xsk_configure(struct pmd_internals *internals, struct
 pkt_rx_queue *rxq,
        int ret = 0;
        int reserve_size;
 
-       rxq->umem = xdp_umem_configure();
+       rxq->umem = xdp_umem_configure(internals);
        if (rxq->umem == NULL)
                return -ENOMEM;
 
--
Quoted 3 lines

2.17.1

Signature · 1 line
David Marchand
#185 lore raw

PATCH v2 1/1 net/af_xdp: fix creating multiple instance

In reply to Xiaolong Ye

From: Xiaolong Ye <[email protected]>

Naming the buf_ring and umem memzone dynamically allows to create multiple af_xdp vdevs.

Fixes f1debd77efaf ("net/af_xdp: introduce AF_XDP PMD")

---
v2:
* squashed buf_ring & memzone patches
* removed unused return value
* changed format specifier to unsigned

---
 drivers/net/af_xdp/rte_eth_af_xdp.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/net/af_xdp/rte_eth_af_xdp.c +10 -4
index 497e2cfde..acf9ad605 100644
@@ -473,7 +473,7 @@ xdp_umem_destroy(struct xsk_umem_info *umem)
 }
 
 static struct
-xsk_umem_info *xdp_umem_configure(void)
+xsk_umem_info *xdp_umem_configure(struct pmd_internals *internals)
 {
 	struct xsk_umem_info *umem;
 	const struct rte_memzone *mz;
@@ -482,6 +482,8 @@ xsk_umem_info *xdp_umem_configure(void)
 		.comp_size = ETH_AF_XDP_DFLT_NUM_DESCS,
 		.frame_size = ETH_AF_XDP_FRAME_SIZE,
 		.frame_headroom = ETH_AF_XDP_DATA_HEADROOM };
+	char ring_name[RTE_RING_NAMESIZE];
+	char mz_name[RTE_MEMZONE_NAMESIZE];
 	int ret;
 	uint64_t i;
 
@@ -491,7 +493,9 @@ xsk_umem_info *xdp_umem_configure(void)
 		return NULL;
 	}
 
-	umem->buf_ring = rte_ring_create("af_xdp_ring",
+	snprintf(ring_name, sizeof(ring_name), "af_xdp_ring_%s_%u",
+		       internals->if_name, internals->queue_idx);
+	umem->buf_ring = rte_ring_create(ring_name,
 					 ETH_AF_XDP_NUM_BUFFERS,
 					 rte_socket_id(),
 					 0x0);
@@ -505,7 +509,9 @@ xsk_umem_info *xdp_umem_configure(void)
 				 (void *)(i * ETH_AF_XDP_FRAME_SIZE +
 					  ETH_AF_XDP_DATA_HEADROOM));
 
-	mz = rte_memzone_reserve_aligned("af_xdp uemem",
+	snprintf(mz_name, sizeof(mz_name), "af_xdp_umem_%s_%u",
+		       internals->if_name, internals->queue_idx);
+	mz = rte_memzone_reserve_aligned(mz_name,
 			ETH_AF_XDP_NUM_BUFFERS * ETH_AF_XDP_FRAME_SIZE,
 			rte_socket_id(), RTE_MEMZONE_IOVA_CONTIG,
 			getpagesize());
@@ -541,7 +547,7 @@ xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
 	int ret = 0;
 	int reserve_size;
 
-	rxq->umem = xdp_umem_configure();
+	rxq->umem = xdp_umem_configure(internals);
 	if (rxq->umem == NULL)
 		return -ENOMEM;
 
Signature · 1 line
2.20.1
Applied
#186 lore raw

Re: [dpdk-dev] [PATCH v2] net/af_xdp: fix creating multiple instance

Quoted 10 lines · Ferruh Yigit

From: Xiaolong Ye <[email protected]>

Naming the buf_ring and umem memzone dynamically allows to create multiple af_xdp vdevs.

Fixes f1debd77efaf ("net/af_xdp: introduce AF_XDP PMD")

Applied to dpdk-next-net/master, thanks.

#187 lore raw

Re: [PATCH v9 1/1] net/af_xdp: introduce AF XDP PMD driver

In reply to Xiaolong Ye
Quoted 11 lines · Xiaolong Ye

Add a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux. More info about AF_XDP, please refer to [1] [2].

This is the vanilla version PMD which just uses a raw buffer registered as the umem.

[1] https://fosdem.org/2018/schedule/event/af_xdp/
[2] https://lwn.net/Articles/745934/

<...>

drivers/net/af_xdp/rte_eth_af_xdp.c line 17

Quoted 7 lines
drivers/net/af_xdp/rte_eth_af_xdp.c new file +5 -0
@@ -0,0 +1,956 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Intel Corporation.
+ */
 
+#include <bpf/bpf.h>
+#include <xsk.h>

Under linux, both headers are in same 'bpf' folder, why one included as 'bpf/bpf.h' but other 'xsk.h'?

Perhaps this is not problem when headers are installed into system folders, but I am compiling using RTE_KERNELDIR, which used in Makefile as:
-I$(RTE_KERNELDIR)/tools/lib/bpf

This fails to find 'bpf/bpf.h'

Also for '-lbpf', shouldn't need to add '-L$(RTE_KERNELDIR)/tools/lib/bpf', to new added line in 'rte.app.mk', so that it can find the library?

I assume you are building in a system with new kernel, I think you need this for functionality, where 'xsk.h' is located in that case? Because I was thinking building and installing libbpf can solve the issue but it is not installing 'xsk.h', not sure why, so not exactly solving.

if you still need "CFLAGS += -I$(RTE_KERNELDIR)/tools/lib/bpf" for your case, does it make sense update as following:
CFLAGS += -I$(RTE_KERNELDIR)/tools/lib
#include <bpf/xsk.h>

#188 lore raw

Re: [PATCH v9 1/1] net/af_xdp: introduce AF XDP PMD driver

Quoted 26 lines · Ferruh Yigit
Quoted 11 lines · Xiaolong Ye

Add a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux. More info about AF_XDP, please refer to [1] [2].

This is the vanilla version PMD which just uses a raw buffer registered as the umem.

[1] https://fosdem.org/2018/schedule/event/af_xdp/
[2] https://lwn.net/Articles/745934/

<...>

drivers/net/af_xdp/rte_eth_af_xdp.c line 17

Quoted 7 lines
drivers/net/af_xdp/rte_eth_af_xdp.c new file +5 -0
@@ -0,0 +1,956 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Intel Corporation.
+ */
 
+#include <bpf/bpf.h>
+#include <xsk.h>

Under linux, both headers are in same 'bpf' folder, why one included as 'bpf/bpf.h' but other 'xsk.h'?

Quoted 3 lines

Perhaps this is not problem when headers are installed into system folders, but I am compiling using RTE_KERNELDIR, which used in Makefile as:
-I$(RTE_KERNELDIR)/tools/lib/bpf

When installed in system folders they will still need the "bpf" prefix. On my system after running "make headers_install" in libbpf folder, the headers are placed in "/usr/local/include/bpf/"

Quoted 11 lines

This fails to find 'bpf/bpf.h'

Also for '-lbpf', shouldn't need to add '-L$(RTE_KERNELDIR)/tools/lib/bpf', to new added line in 'rte.app.mk', so that it can find the library?

I assume you are building in a system with new kernel, I think you need this for functionality, where 'xsk.h' is located in that case? Because I was thinking building and installing libbpf can solve the issue but it is not installing 'xsk.h', not sure why, so not exactly solving.

Quoted 4 lines

if you still need "CFLAGS += -I$(RTE_KERNELDIR)/tools/lib/bpf" for your case, does it make sense update as following:
CFLAGS += -I$(RTE_KERNELDIR)/tools/lib
#include <bpf/xsk.h>

We should not include in any driver a cflag or ldflag that points to the kernel dir. We should expect the headers for libbpf in a regular include folder and the library itself in /usr/lib or /usr/local/lib.

/Bruce

#189 lore raw

Re: [PATCH v9 1/1] net/af_xdp: introduce AF XDP PMD driver

Quoted 27 lines · Bruce Richardson
Quoted 26 lines · Ferruh Yigit
Quoted 11 lines · Xiaolong Ye

Add a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux. More info about AF_XDP, please refer to [1] [2].

This is the vanilla version PMD which just uses a raw buffer registered as the umem.

[1] https://fosdem.org/2018/schedule/event/af_xdp/
[2] https://lwn.net/Articles/745934/

<...>

drivers/net/af_xdp/rte_eth_af_xdp.c line 17

Quoted 7 lines
drivers/net/af_xdp/rte_eth_af_xdp.c new file +5 -0
@@ -0,0 +1,956 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Intel Corporation.
+ */
 
+#include <bpf/bpf.h>
+#include <xsk.h>

Under linux, both headers are in same 'bpf' folder, why one included as 'bpf/bpf.h' but other 'xsk.h'?

Quoted 7 lines
Quoted 3 lines

Perhaps this is not problem when headers are installed into system folders, but I am compiling using RTE_KERNELDIR, which used in Makefile as:
-I$(RTE_KERNELDIR)/tools/lib/bpf

When installed in system folders they will still need the "bpf" prefix. On my system after running "make headers_install" in libbpf folder, the headers are placed in "/usr/local/include/bpf/"

This is for 'xsk.h' which was not installed via "make headers_install", but as Luca pointed out there is a patch to install 'xsk.h' too, so it should be OK to remove that line.

Quoted 12 lines
Quoted 12 lines

This fails to find 'bpf/bpf.h'

Also for '-lbpf', shouldn't need to add '-L$(RTE_KERNELDIR)/tools/lib/bpf', to new added line in 'rte.app.mk', so that it can find the library?

I assume you are building in a system with new kernel, I think you need this for functionality, where 'xsk.h' is located in that case? Because I was thinking building and installing libbpf can solve the issue but it is not installing 'xsk.h', not sure why, so not exactly solving.

Quoted 8 lines
Quoted 4 lines

if you still need "CFLAGS += -I$(RTE_KERNELDIR)/tools/lib/bpf" for your case, does it make sense update as following:
CFLAGS += -I$(RTE_KERNELDIR)/tools/lib
#include <bpf/xsk.h>

We should not include in any driver a cflag or ldflag that points to the kernel dir. We should expect the headers for libbpf in a regular include folder and the library itself in /usr/lib or /usr/local/lib.

Overall agree, but there is a dependency from 'xsk.h' to 'tools/include/asm/barrier.h', and this header file is not installed into system folders, it can be found only in kernel source code.

Hopefully it looks like there is a way to get rid of 'tools/include/asm/barrier.h' dependency for DPDK, so we can remove that cflags too.

#190 lore raw

v10 cover Introduce AF_XDP PMD

In reply to Xiaolong Ye

Overview
========

This patchset adds a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux, see below links [1] [2] for details of AF_XDP introduction:

AF_XDP roadmap
==============
- AF_XDP is included in upstream kernel since 4.18, and AF_XDP support in libbpf has been merged in v5.1-rc1.
- Now i40e and ixgbe drivers have supported zero copy mode.

Change logs
===========
v10:

- refine the Makefile, remove RTE_KERNELDIR related CFLAGS
- add a new internal file af_xdp_deps.h to handle the dependency for asm/barrier.h
- fix a typo observed by Stephen
- rename xsk.h to bpf/xsk.h as xsk.h is assumed to be installed in /usr/local/include/bpf
- add libbpf build steps in af_xdp.rst

v9:
- adjust header files order according to Stephen's suggestion

v8:
- address Ferruh's comments on V7
- replace posix_memalign with rte_memzone_reserve_aligned to get better performance
- keep the first patch only as Oliver suggested as zero copy part implementation is still in suspense, we may provide the related patch later.

v7:
- mention mtu limitation in af_xdp.rst
- fix the vdev name in af_xdp.rst

V6:

- remove the newline in AF_XDP_LOG definition to avoid double new lines issue.
- rename MEMPOOL_F_PAGE_ALIGN to MEMPOOL_CHUNK_F_PAGE_ALIGN.

V5:

- disable AF_XDP pmd by default due to it requires kernel more recent than minimum kernel version supported by DPDK
- address other review comments of Maxime

V4:

- change vdev name to net_af_xdp
- adopt dynamic log type for all logging
- Fix other style issues raised by Stephen

V3:

- Fix all style issues pointed by Stephen, Mattias, David.
- Drop the testpmd change as we'll adopt Jerin's suggestion to add a new mempool driver to handle the application use of AF_XDP's zero copy feature.

V2:
- Fix a NULL pointer reference crash issue
- Fix txonly stop sending traffic in zc mode
- Refactor rte_mbuf.c to avoid ABI breakage.
- Fix multiple style issues pointed by Ferruh, David, Stephen, Luca.

changes vs RFC sent by Qi last Aug:

- Re-work base on AF_XDP's interface changes since the new libbpf has provided higher-level APIs that hide many of the details of the AP_XDP uapi. After the rework, it helps to reduce 300+ lines of code.

- multi-queues is not supported due to current libbpf doesn't support multi-sockets on a single umem.

- No extra steps to load xdp program manually, since the current behavior of libbpf would load a default xdp program when user calls xsk_socket__create. userspace application only needs to handle the cleanup.

How to try
==========

1. take the kernel >= v5.1-rc1, build kernel and replace your host kernel with it.

make sure you turn on XDP sockets when compiling

Networking support -->
Networking options -->
[ * ] XDP sockets

2. build & install libbpf in tools/lib/bpf

cd tools/lib/bpf
make install_lib
make install_headers

3. ethtool -L enp59s0f0 combined 1

4. extra step to build dpdk

explicitly enable AF_XDP pmd by adding below line to config/common_linux

CONFIG_RTE_LIBRTE_PMD_AF_XDP=y

5. start testpmd

   ./build/app/testpmd -c 0xc -n 4 --vdev net_af_xdp,iface=enp59s0f0,queue=0 -- -i --rxq=1 --txq=1

in this case, default xdp program will be loaded and linked to queue 0 of enp59s0f0, network traffics travel to queue 0 will be redirected to af_xdp socket.

Xiaolong Ye (1):
net/af_xdp: introduce AF XDP PMD driver

 MAINTAINERS                                   |   7 +
 config/common_base                            |   5 +
 doc/guides/nics/af_xdp.rst                    |  50 +
 doc/guides/nics/features/af_xdp.ini           |  11 +
 doc/guides/nics/index.rst                     |   1 +
 doc/guides/rel_notes/release_19_05.rst        |   7 +
 drivers/net/Makefile                          |   1 +
 drivers/net/af_xdp/Makefile                   |  28 +
 drivers/net/af_xdp/af_xdp_deps.h              |  14 +
 drivers/net/af_xdp/meson.build                |  21 +
 drivers/net/af_xdp/rte_eth_af_xdp.c           | 955 ++++++++++++++++++
 drivers/net/af_xdp/rte_pmd_af_xdp_version.map |   3 +
 drivers/net/meson.build                       |   1 +
 mk/rte.app.mk                                 |   1 +
 14 files changed, 1105 insertions(+)
 create mode 100644 doc/guides/nics/af_xdp.rst
 create mode 100644 doc/guides/nics/features/af_xdp.ini
 create mode 100644 drivers/net/af_xdp/Makefile
 create mode 100644 drivers/net/af_xdp/af_xdp_deps.h
 create mode 100644 drivers/net/af_xdp/meson.build
 create mode 100644 drivers/net/af_xdp/rte_eth_af_xdp.c
 create mode 100644 drivers/net/af_xdp/rte_pmd_af_xdp_version.map
Signature · 1 line
2.17.1
#191 lore raw

PATCH v10 1/1 net/af_xdp: introduce AF XDP PMD driver

Add a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux. More info about AF_XDP, please refer to [1] [2].

This is the vanilla version PMD which just uses a raw buffer registered as the umem.

[1] https://fosdem.org/2018/schedule/event/af_xdp/
[2] https://lwn.net/Articles/745934/

---
 MAINTAINERS                                   |   7 +
 config/common_base                            |   5 +
 doc/guides/nics/af_xdp.rst                    |  50 +
 doc/guides/nics/features/af_xdp.ini           |  11 +
 doc/guides/nics/index.rst                     |   1 +
 doc/guides/rel_notes/release_19_05.rst        |   7 +
 drivers/net/Makefile                          |   1 +
 drivers/net/af_xdp/Makefile                   |  28 +
 drivers/net/af_xdp/af_xdp_deps.h              |  14 +
 drivers/net/af_xdp/meson.build                |  21 +
 drivers/net/af_xdp/rte_eth_af_xdp.c           | 955 ++++++++++++++++++
 drivers/net/af_xdp/rte_pmd_af_xdp_version.map |   3 +
 drivers/net/meson.build                       |   1 +
 mk/rte.app.mk                                 |   1 +
 14 files changed, 1105 insertions(+)
 create mode 100644 doc/guides/nics/af_xdp.rst
 create mode 100644 doc/guides/nics/features/af_xdp.ini
 create mode 100644 drivers/net/af_xdp/Makefile
 create mode 100644 drivers/net/af_xdp/af_xdp_deps.h
 create mode 100644 drivers/net/af_xdp/meson.build
 create mode 100644 drivers/net/af_xdp/rte_eth_af_xdp.c
 create mode 100644 drivers/net/af_xdp/rte_pmd_af_xdp_version.map
MAINTAINERS +7 -0
index 71ac8cd4b..f30572c07 100644
@@ -489,6 +489,13 @@ M: John W. Linville <[email protected]>
 F: drivers/net/af_packet/
 F: doc/guides/nics/features/afpacket.ini
 
+Linux AF_XDP
+M: Xiaolong Ye <[email protected]>
+M: Qi Zhang <[email protected]>
+F: drivers/net/af_xdp/
+F: doc/guides/nics/af_xdp.rst
+F: doc/guides/nics/features/af_xdp.ini
+
 Amazon ENA
 M: Marcin Wojtas <[email protected]>
 M: Michal Krawczyk <[email protected]>
config/common_base +5 -0
index 6292bc4af..b95ee03d7 100644
@@ -430,6 +430,11 @@ CONFIG_RTE_LIBRTE_VMXNET3_DEBUG_TX_FREE=n
 #
 CONFIG_RTE_LIBRTE_PMD_AF_PACKET=n
 
+#
+# Compile software PMD backed by AF_XDP sockets (Linux only)
+#
+CONFIG_RTE_LIBRTE_PMD_AF_XDP=n
+
 #
 # Compile link bonding PMD library
 #
doc/guides/nics/af_xdp.rst new file +50 -0

50 lines not on this page · raw message

doc/guides/nics/features/af_xdp.ini new file +11 -0
new file mode 100644
index 000000000..36953c2de
@@ -0,0 +1,11 @@
+;
+; Supported features of the 'af_xdp' network poll mode driver.
+;
+; Refer to default.ini for the full list of available PMD features.
+;
+[Features]
+Link status          = Y
+MTU update           = Y
+Promiscuous mode     = Y
+Stats per queue      = Y
+x86-64               = Y
doc/guides/nics/index.rst +1 -0
index 5c80e3baa..a4b80a3d0 100644
@@ -12,6 +12,7 @@ Network Interface Controller Drivers
     features
     build_and_test
     af_packet
+    af_xdp
     ark
     atlantic
     avp
doc/guides/rel_notes/release_19_05.rst +7 -0
index bdad1ddbe..79e36739f 100644
@@ -74,6 +74,13 @@ New Features
     process.
   * Added support for Rx packet types list in a secondary process.
 
+* **Added the AF_XDP PMD.**
+
+  Added a Linux-specific PMD driver for AF_XDP, it can create the AF_XDP socket
+  and bind it to a specific netdev queue, it allows a DPDK application to send
+  and receive raw packets through the socket which would bypass the kernel
+  network stack to achieve high performance packet processing.
+
 * **Updated Mellanox drivers.**
 
    New features and improvements were done in mlx4 and mlx5 PMDs:
drivers/net/Makefile +1 -0
index 502869a87..5d401b8c5 100644
@@ -9,6 +9,7 @@ ifeq ($(CONFIG_RTE_LIBRTE_THUNDERX_NICVF_PMD),d)
 endif
 
 DIRS-$(CONFIG_RTE_LIBRTE_PMD_AF_PACKET) += af_packet
+DIRS-$(CONFIG_RTE_LIBRTE_PMD_AF_XDP) += af_xdp
 DIRS-$(CONFIG_RTE_LIBRTE_ARK_PMD) += ark
 DIRS-$(CONFIG_RTE_LIBRTE_ATLANTIC_PMD) += atlantic
 DIRS-$(CONFIG_RTE_LIBRTE_AVP_PMD) += avp
drivers/net/af_xdp/Makefile new file +28 -0
new file mode 100644
index 000000000..eeba6b693
@@ -0,0 +1,28 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+#
+# library name
+#
+LIB = librte_pmd_af_xdp.a
+
+EXPORT_MAP := rte_pmd_af_xdp_version.map
+
+LIBABIVER := 1
+
+CFLAGS += -O3
+
+CFLAGS += $(WERROR_FLAGS)
+LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring
+LDLIBS += -lrte_ethdev -lrte_net -lrte_kvargs
+LDLIBS += -lrte_bus_vdev
+LDLIBS += $(shell command -v pkg-config > /dev/null 2>&1 && pkg-config --libs libbpf || echo "-lbpf")
+
+#
+# all source are stored in SRCS-y
+#
+SRCS-$(CONFIG_RTE_LIBRTE_PMD_AF_XDP) += rte_eth_af_xdp.c
+
+include $(RTE_SDK)/mk/rte.lib.mk
drivers/net/af_xdp/af_xdp_deps.h new file +14 -0
new file mode 100644
index 000000000..8c8f8b6ab
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Intel Corporation.
+ */
+
+#ifndef AF_XDP_DEPS_H_
+#define AF_XDP_DEPS_H_
+
+#include <rte_atomic.h>
+#include <rte_branch_prediction.h>
+
+#define smp_rmb() rte_rmb()
+#define smp_wmb() rte_wmb()
+
+#endif /* AF_XDP_DEPS_H_ */
drivers/net/af_xdp/meson.build new file +21 -0
new file mode 100644
index 000000000..d40aae190
@@ -0,0 +1,21 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+if host_machine.system() != 'linux'
+	build = false
+endif
+
+bpf_dep = dependency('libbpf', required: false)
+if bpf_dep.found()
+	build = true
+else
+	bpf_dep = cc.find_library('libbpf', required: false)
+	if bpf_dep.found() and cc.has_header('xsk.h', dependencies: bpf_dep) and cc.has_header('linux/if_xdp.h')
+		build = true
+		pkgconfig_extra_libs += '-lbpf'
+	else
+		build = false
+	endif
+endif
+sources = files('rte_eth_af_xdp.c')
+ext_deps += bpf_dep
drivers/net/af_xdp/rte_eth_af_xdp.c new file +955 -0

955 lines not on this page · raw message

drivers/net/af_xdp/rte_pmd_af_xdp_version.map new file +3 -0
new file mode 100644
index 000000000..c6db030fe
@@ -0,0 +1,3 @@
+DPDK_19.05 {
+	local: *;
+};
drivers/net/meson.build +1 -0
index 3ecc78cee..1105e72d8 100644
@@ -2,6 +2,7 @@
 # Copyright(c) 2017 Intel Corporation
 
 drivers = ['af_packet',
+	'af_xdp',
 	'ark',
 	'atlantic',
 	'avp',
mk/rte.app.mk +1 -0
index 262132fc6..f916bc9ef 100644
@@ -143,6 +143,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_DPAA2_MEMPOOL)  += -lrte_mempool_dpaa2
 endif
 
 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AF_PACKET)  += -lrte_pmd_af_packet
+_LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AF_XDP)     += -lrte_pmd_af_xdp -lbpf
 _LDLIBS-$(CONFIG_RTE_LIBRTE_ARK_PMD)        += -lrte_pmd_ark
 _LDLIBS-$(CONFIG_RTE_LIBRTE_ATLANTIC_PMD)   += -lrte_pmd_atlantic
 _LDLIBS-$(CONFIG_RTE_LIBRTE_AVP_PMD)        += -lrte_pmd_avp
Signature · 1 line
2.17.1
Acked-by on v10 1/1
#192 lore raw

Re: [PATCH v10 1/1] net/af_xdp: introduce AF XDP PMD driver

Quoted 35 lines · Xiaolong Ye

Add a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux. More info about AF_XDP, please refer to
[1]
[2].

This is the vanilla version PMD which just uses a raw buffer registered as
the umem.

[1]
https://fosdem.org/2018/schedule/event/af_xdp/

[2]
https://lwn.net/Articles/745934/

Signed-off-by: Xiaolong Ye <
[email protected]

Quoted 1 line
---
 MAINTAINERS                                   |   7 +
 config/common_base                            |   5 +
 doc/guides/nics/af_xdp.rst                    |  50 +
 doc/guides/nics/features/af_xdp.ini           |  11 +
 doc/guides/nics/index.rst                     |   1 +
 doc/guides/rel_notes/release_19_05.rst        |   7 +
 drivers/net/Makefile                          |   1 +
 drivers/net/af_xdp/Makefile                   |  28 +
 drivers/net/af_xdp/af_xdp_deps.h              |  14 +
 drivers/net/af_xdp/meson.build                |  21 +
 drivers/net/af_xdp/rte_eth_af_xdp.c           | 955
++++++++++++++++++
 drivers/net/af_xdp/rte_pmd_af_xdp_version.map |   3 +
 drivers/net/meson.build                       |   1 +
 mk/rte.app.mk                                 |   1 +
Quoted 8 lines
 14 files changed, 1105 insertions(+)
 create mode 100644 doc/guides/nics/af_xdp.rst
 create mode 100644 doc/guides/nics/features/af_xdp.ini
 create mode 100644 drivers/net/af_xdp/Makefile
 create mode 100644 drivers/net/af_xdp/af_xdp_deps.h
 create mode 100644 drivers/net/af_xdp/meson.build
 create mode 100644 drivers/net/af_xdp/rte_eth_af_xdp.c
 create mode 100644 drivers/net/af_xdp/rte_pmd_af_xdp_version.map
Signature · 2 lines
Kind regards,
Luca Boccassi
#193 lore raw

Re: [PATCH v10 1/1] net/af_xdp: introduce AF XDP PMD driver

In reply to Xiaolong Ye
Quoted 11 lines · Xiaolong Ye

Add a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux. More info about AF_XDP, please refer to [1] [2].

This is the vanilla version PMD which just uses a raw buffer registered as the umem.

[1] https://fosdem.org/2018/schedule/event/af_xdp/
[2] https://lwn.net/Articles/745934/

I am not able to test functionality but code looks good to me, I can compile via Makefile (with suggested steps in doc) but not able to build with meson, can you please check below comments?

<...>

drivers/net/af_xdp/meson.build line 6

Quoted 7 lines
drivers/net/af_xdp/meson.build new file +6 -0
@@ -0,0 +1,21 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+if host_machine.system() != 'linux'
+	build = false
+endif

After this point, if build is false it shouldn't continue to below checks I think.

Review line 8

Quoted 2 lines
(quoted diff) +2 -0
+
+bpf_dep = dependency('libbpf', required: false)

My library is in '/usr/local/lib64/libbpf.so' but this line can't find it. Where does 'dependency()' checks for libraries?

drivers/net/af_xdp/meson.build line 12

Quoted 4 lines
drivers/net/af_xdp/meson.build new file +4 -0
+if bpf_dep.found()
+	build = true
+else
+	bpf_dep = cc.find_library('libbpf', required: false)

Also this line can't find it, in log it says "(tried pkgconfig and cmake)" and yes there is no pkgconfig for it, any idea how 'cmake' used?

drivers/net/af_xdp/meson.build line 13

Quoted 1 line
drivers/net/af_xdp/meson.build new file +1 -0
+	if bpf_dep.found() and cc.has_header('xsk.h', dependencies: bpf_dep) and cc.has_header('linux/if_xdp.h')

Should this be 'lib/xsk.h' now?

Quoted 8 lines
drivers/net/af_xdp/meson.build new file +8 -0
+		build = true
+		pkgconfig_extra_libs += '-lbpf'
+	else
+		build = false
+	endif
+endif
+sources = files('rte_eth_af_xdp.c')
+ext_deps += bpf_dep
#194 lore raw

Re: [PATCH v10 1/1] net/af_xdp: introduce AF XDP PMD driver

Quoted 41 lines · Ferruh Yigit
Quoted 13 lines · Xiaolong Ye

Add a new PMD driver for AF_XDP which is a proposed faster version of
AF_PACKET interface in Linux. More info about AF_XDP, please refer to [1]
[2].

This is the vanilla version PMD which just uses a raw buffer registered as
the umem.

[1]
https://fosdem.org/2018/schedule/event/af_xdp/

Quoted 7 lines

[2]
https://lwn.net/Articles/745934/

Signed-off-by: Xiaolong Ye <
[email protected]

Quoted 1 line

I am not able to test functionality but code looks good to me, I can compile via
Makefile (with suggested steps in doc) but not able to build with meson, can you
please check below comments?

<...>

drivers/net/af_xdp/meson.build line 6

Quoted 7 lines
drivers/net/af_xdp/meson.build new file +6 -0
@@ -0,0 +1,21 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+if host_machine.system() != 'linux'
+	build = false
+endif

After this point, if build is false it shouldn't continue to below checks I think.

Quoted 6 lines

Review line 8

Quoted 2 lines
(quoted diff) +2 -0
+
+bpf_dep = dependency('libbpf', required: false)

My library is in '/usr/local/lib64/libbpf.so' but this line can't find it. Where
does 'dependency()' checks for libraries?

dependency() uses only pkg-config (or cmake or embedded specific tools, neither of which applies to bpf), so if you haven't built from bpf-next you won't have the pkg-config file installed, and it will fall back to the next block.

Side note, there's an issue open upstream in Meson to merge dependency() and find_library(), with some traction but it's not done yet.

For me building from bpf-next it works fine:

$ PKG_CONFIG_PATH=/tmp/bpf/lib64/pkgconfig/ ninja -C build-gcc-shared
...
Dependency libbpf found: YES 0.0.2
...
$ lddtree build-gcc-shared/drivers/librte_pmd_af_xdp.so.1.1 
librte_pmd_af_xdp.so.1.1 => build-gcc-shared/drivers/librte_pmd_af_xdp.so.1.1 (interpreter => none)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2
    libnuma.so.1 => /lib/x86_64-linux-gnu/libnuma.so.1
    librte_ethdev.so.12 => build-gcc-shared/drivers/../lib/librte_ethdev.so.12
    librte_eal.so.10 => build-gcc-shared/drivers/../lib/librte_eal.so.10
    librte_kvargs.so.1 => build-gcc-shared/drivers/../lib/librte_kvargs.so.1
    librte_net.so.1 => build-gcc-shared/drivers/../lib/librte_net.so.1
    librte_mbuf.so.5 => build-gcc-shared/drivers/../lib/librte_mbuf.so.5
    librte_mempool.so.5 => build-gcc-shared/drivers/../lib/librte_mempool.so.5
    librte_ring.so.2 => build-gcc-shared/drivers/../lib/librte_ring.so.2
    librte_cmdline.so.2 => build-gcc-shared/drivers/../lib/librte_cmdline.so.2
    librte_meter.so.2 => build-gcc-shared/drivers/../lib/librte_meter.so.2
    librte_bus_pci.so.2 => not found
    librte_pci.so.1 => build-gcc-shared/drivers/../lib/librte_pci.so.1
    librte_bus_vdev.so.2 => not found
    libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1
    libbpf.so.0 => /tmp/bpf/lib64/libbpf.so.0
        libelf.so.1 => /lib/x86_64-linux-gnu/libelf.so.1
            libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6
    ld-linux-x86-64.so.2 => /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
Quoted 8 lines

drivers/net/af_xdp/meson.build line 12

Quoted 4 lines
drivers/net/af_xdp/meson.build new file +4 -0
+if bpf_dep.found()
+	build = true
+else
+	bpf_dep = cc.find_library('libbpf', required: false)

Also this line can't find it, in log it says "(tried pkgconfig and cmake)" and
yes there is no pkgconfig for it, any idea how 'cmake' used?

The issue here is that it should be cc.find_library('bpf' - not 'libbpf'. I missed this when reviewing, good catch.

That's because find_library just does a compilation test passing the value to the compiler as a linker flag - so right now it's passing -llibbpf. Fixing this line and the header line below makes it work without pkg-config:

$ CPPFLAGS=-I/tmp/bpf/include LDFLAGS=-L/tmp/bpf/lib64 meson testt
...
Dependency libbpf found: NO (tried pkgconfig and cmake)
Library bpf found: YES
Quoted 4 lines
Quoted 2 lines
(quoted diff) +1 -0
+	if bpf_dep.found() and cc.has_header('xsk.h', dependencies:

bpf_dep) and cc.has_header('linux/if_xdp.h')

Should this be 'lib/xsk.h' now?

Yes, this should be 'bpf/xsk.h'

Signature · 2 lines
Kind regards,
Luca Boccassi
#195 lore raw

Re: [PATCH v10 1/1] net/af_xdp: introduce AF XDP PMD driver

Quoted 107 lines · Luca Boccassi
Quoted 41 lines · Ferruh Yigit
Quoted 13 lines · Xiaolong Ye

Add a new PMD driver for AF_XDP which is a proposed faster version of
AF_PACKET interface in Linux. More info about AF_XDP, please refer to [1]
[2].

This is the vanilla version PMD which just uses a raw buffer registered as
the umem.

[1]
https://fosdem.org/2018/schedule/event/af_xdp/

Quoted 7 lines

[2]
https://lwn.net/Articles/745934/

Signed-off-by: Xiaolong Ye <
[email protected]

Quoted 1 line

I am not able to test functionality but code looks good to me, I can compile via
Makefile (with suggested steps in doc) but not able to build with meson, can you
please check below comments?

<...>

drivers/net/af_xdp/meson.build line 6

Quoted 7 lines
drivers/net/af_xdp/meson.build new file +6 -0
@@ -0,0 +1,21 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+if host_machine.system() != 'linux'
+	build = false
+endif

After this point, if build is false it shouldn't continue to below checks I think.

Quoted 6 lines

Review line 8

Quoted 2 lines
(quoted diff) +2 -0
+
+bpf_dep = dependency('libbpf', required: false)

My library is in '/usr/local/lib64/libbpf.so' but this line can't find it. Where
does 'dependency()' checks for libraries?

dependency() uses only pkg-config (or cmake or embedded specific tools, neither of which applies to bpf), so if you haven't built from bpf-next you won't have the pkg-config file installed, and it will fall back to the next block.

Side note, there's an issue open upstream in Meson to merge dependency() and find_library(), with some traction but it's not done yet.

For me building from bpf-next it works fine:

$ PKG_CONFIG_PATH=/tmp/bpf/lib64/pkgconfig/ ninja -C build-gcc-shared
...
Dependency libbpf found: YES 0.0.2
...
$ lddtree build-gcc-shared/drivers/librte_pmd_af_xdp.so.1.1 
librte_pmd_af_xdp.so.1.1 => build-gcc-shared/drivers/librte_pmd_af_xdp.so.1.1 (interpreter => none)
   libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6
   libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2
   libnuma.so.1 => /lib/x86_64-linux-gnu/libnuma.so.1
   librte_ethdev.so.12 => build-gcc-shared/drivers/../lib/librte_ethdev.so.12
   librte_eal.so.10 => build-gcc-shared/drivers/../lib/librte_eal.so.10
   librte_kvargs.so.1 => build-gcc-shared/drivers/../lib/librte_kvargs.so.1
   librte_net.so.1 => build-gcc-shared/drivers/../lib/librte_net.so.1
   librte_mbuf.so.5 => build-gcc-shared/drivers/../lib/librte_mbuf.so.5
   librte_mempool.so.5 => build-gcc-shared/drivers/../lib/librte_mempool.so.5
   librte_ring.so.2 => build-gcc-shared/drivers/../lib/librte_ring.so.2
   librte_cmdline.so.2 => build-gcc-shared/drivers/../lib/librte_cmdline.so.2
   librte_meter.so.2 => build-gcc-shared/drivers/../lib/librte_meter.so.2
   librte_bus_pci.so.2 => not found
   librte_pci.so.1 => build-gcc-shared/drivers/../lib/librte_pci.so.1
   librte_bus_vdev.so.2 => not found
   libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0
       librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1
   libbpf.so.0 => /tmp/bpf/lib64/libbpf.so.0
       libelf.so.1 => /lib/x86_64-linux-gnu/libelf.so.1
           libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1
   libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0
   libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6
   ld-linux-x86-64.so.2 => /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
Quoted 8 lines

drivers/net/af_xdp/meson.build line 12

Quoted 4 lines
drivers/net/af_xdp/meson.build new file +4 -0
+if bpf_dep.found()
+	build = true
+else
+	bpf_dep = cc.find_library('libbpf', required: false)

Also this line can't find it, in log it says "(tried pkgconfig and cmake)" and
yes there is no pkgconfig for it, any idea how 'cmake' used?

The issue here is that it should be cc.find_library('bpf' - not 'libbpf'. I missed this when reviewing, good catch.

That's because find_library just does a compilation test passing the value to the compiler as a linker flag - so right now it's passing -llibbpf. Fixing this line and the header line below makes it work without pkg-config:

Quoted 4 lines
$ CPPFLAGS=-I/tmp/bpf/include LDFLAGS=-L/tmp/bpf/lib64 meson testt
...
Dependency libbpf found: NO (tried pkgconfig and cmake)
Library bpf found: YES

Thanks for pointing out, will adopt it.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
(quoted diff) +1 -0
+	if bpf_dep.found() and cc.has_header('xsk.h', dependencies:

bpf_dep) and cc.has_header('linux/if_xdp.h')

Should this be 'lib/xsk.h' now?

Yes, this should be 'bpf/xsk.h'

Will change it in next version.

Thanks,
Xiaolong

Quoted 4 lines
Signature · 3 lines
-- 
Kind regards,
Luca Boccassi
#196 lore raw

Re: [PATCH v10 1/1] net/af_xdp: introduce AF XDP PMD driver

In reply to Luca Boccassi

Hi, Luca

Quoted 107 lines · Luca Boccassi
Quoted 41 lines · Ferruh Yigit
Quoted 13 lines · Xiaolong Ye

Add a new PMD driver for AF_XDP which is a proposed faster version of
AF_PACKET interface in Linux. More info about AF_XDP, please refer to [1]
[2].

This is the vanilla version PMD which just uses a raw buffer registered as
the umem.

[1]
https://fosdem.org/2018/schedule/event/af_xdp/

Quoted 7 lines

[2]
https://lwn.net/Articles/745934/

Signed-off-by: Xiaolong Ye <
[email protected]

Quoted 1 line

I am not able to test functionality but code looks good to me, I can compile via
Makefile (with suggested steps in doc) but not able to build with meson, can you
please check below comments?

<...>

drivers/net/af_xdp/meson.build line 6

Quoted 7 lines
drivers/net/af_xdp/meson.build new file +6 -0
@@ -0,0 +1,21 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+if host_machine.system() != 'linux'
+	build = false
+endif

After this point, if build is false it shouldn't continue to below checks I think.

Quoted 6 lines

Review line 8

Quoted 2 lines
(quoted diff) +2 -0
+
+bpf_dep = dependency('libbpf', required: false)

My library is in '/usr/local/lib64/libbpf.so' but this line can't find it. Where
does 'dependency()' checks for libraries?

dependency() uses only pkg-config (or cmake or embedded specific tools, neither of which applies to bpf), so if you haven't built from bpf-next you won't have the pkg-config file installed, and it will fall back to the next block.

Side note, there's an issue open upstream in Meson to merge dependency() and find_library(), with some traction but it's not done yet.

For me building from bpf-next it works fine:

$ PKG_CONFIG_PATH=/tmp/bpf/lib64/pkgconfig/ ninja -C build-gcc-shared
...
Dependency libbpf found: YES 0.0.2
...
$ lddtree build-gcc-shared/drivers/librte_pmd_af_xdp.so.1.1 
librte_pmd_af_xdp.so.1.1 => build-gcc-shared/drivers/librte_pmd_af_xdp.so.1.1 (interpreter => none)
   libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6
   libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2
   libnuma.so.1 => /lib/x86_64-linux-gnu/libnuma.so.1
   librte_ethdev.so.12 => build-gcc-shared/drivers/../lib/librte_ethdev.so.12
   librte_eal.so.10 => build-gcc-shared/drivers/../lib/librte_eal.so.10
   librte_kvargs.so.1 => build-gcc-shared/drivers/../lib/librte_kvargs.so.1
   librte_net.so.1 => build-gcc-shared/drivers/../lib/librte_net.so.1
   librte_mbuf.so.5 => build-gcc-shared/drivers/../lib/librte_mbuf.so.5
   librte_mempool.so.5 => build-gcc-shared/drivers/../lib/librte_mempool.so.5
   librte_ring.so.2 => build-gcc-shared/drivers/../lib/librte_ring.so.2
   librte_cmdline.so.2 => build-gcc-shared/drivers/../lib/librte_cmdline.so.2
   librte_meter.so.2 => build-gcc-shared/drivers/../lib/librte_meter.so.2
   librte_bus_pci.so.2 => not found
   librte_pci.so.1 => build-gcc-shared/drivers/../lib/librte_pci.so.1
   librte_bus_vdev.so.2 => not found
   libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0
       librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1
   libbpf.so.0 => /tmp/bpf/lib64/libbpf.so.0
       libelf.so.1 => /lib/x86_64-linux-gnu/libelf.so.1
           libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1
   libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0
   libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6
   ld-linux-x86-64.so.2 => /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
Quoted 8 lines

drivers/net/af_xdp/meson.build line 12

Quoted 4 lines
drivers/net/af_xdp/meson.build new file +4 -0
+if bpf_dep.found()
+	build = true
+else
+	bpf_dep = cc.find_library('libbpf', required: false)

Also this line can't find it, in log it says "(tried pkgconfig and cmake)" and
yes there is no pkgconfig for it, any idea how 'cmake' used?

The issue here is that it should be cc.find_library('bpf' - not 'libbpf'. I missed this when reviewing, good catch.

That's because find_library just does a compilation test passing the value to the compiler as a linker flag - so right now it's passing -llibbpf. Fixing this line and the header line below makes it work without pkg-config:

Quoted 4 lines
$ CPPFLAGS=-I/tmp/bpf/include LDFLAGS=-L/tmp/bpf/lib64 meson testt
...
Dependency libbpf found: NO (tried pkgconfig and cmake)
Library bpf found: YES

After apply the fix in af_xdp pmd's meson.build, now I was able to build library for af_xdp pmd.

$ ls drivers/ |grep xdp
a715181@@rte_pmd_af_xdp@sha
a715181@@rte_pmd_af_xdp@sta
a715181@@tmp_rte_pmd_af_xdp@sta
librte_pmd_af_xdp.a
librte_pmd_af_xdp.so
librte_pmd_af_xdp.so.1
librte_pmd_af_xdp.so.1.1
libtmp_rte_pmd_af_xdp.a
rte_pmd_af_xdp.pmd.c

But I found that if I install libbpf to /usr/local/lib64 by default, application built by meson build will fail to run:

$ ./dpdk-testpmd
./dpdk-testpmd: error while loading shared libraries: libbpf.so.0: cannot open shared object file: No such file or directory

While install libbpf to /usr/lib doesn't have this issue (I was testing on ubuntu system). Is it a expected behavior? Do we need any fix for it?

Thanks,
Xiaolong

Quoted 11 lines
Quoted 5 lines
Quoted 3 lines
(quoted diff) +1 -0
+	if bpf_dep.found() and cc.has_header('xsk.h', dependencies:

bpf_dep) and cc.has_header('linux/if_xdp.h')

Should this be 'lib/xsk.h' now?

Yes, this should be 'bpf/xsk.h'

Signature · 2 lines
Kind regards,
Luca Boccassi
#197 lore raw

Re: [PATCH v10 1/1] net/af_xdp: introduce AF XDP PMD driver

Quoted 143 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Ye Xiaolong
Sent: Thursday, April 4, 2019 1:55 PM
To: Ferruh Yigit <[email protected]>; Luca Boccassi <[email protected]>
Cc: [email protected]; Stephen Hemminger <[email protected]>; Qi Zhang <[email protected]>; Karlsson Magnus <[email protected]>; Topel Bjorn <[email protected]>; Maxime Coquelin <[email protected]>; Bruce Richardson <[email protected]>; Ananyev Konstantin <[email protected]>; David Marchand <[email protected]>; Andrew Rybchenko <[email protected]>; Olivier Matz <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v10 1/1] net/af_xdp: introduce AF XDP PMD driver

Hi, Luca

Quoted 52 lines · Luca Boccassi
Quoted 36 lines · Ferruh Yigit
Quoted 10 lines · Xiaolong Ye

Add a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux. More info about AF_XDP, please refer to [1] [2].

This is the vanilla version PMD which just uses a raw buffer registered as the umem.

[1]
https://fosdem.org/2018/schedule/event/af_xdp/

Quoted 7 lines

[2]
https://lwn.net/Articles/745934/

Signed-off-by: Xiaolong Ye <
[email protected]

Quoted 1 line

I am not able to test functionality but code looks good to me, I can compile via Makefile (with suggested steps in doc) but not able to build with meson, can you please check below comments?

<...>

drivers/net/af_xdp/meson.build line 6

Quoted 7 lines
drivers/net/af_xdp/meson.build new file +6 -0
@@ -0,0 +1,21 @@
+# SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2019 Intel
+Corporation
+
+if host_machine.system() != 'linux'
+	build = false
+endif

After this point, if build is false it shouldn't continue to below checks I think.

Quoted 5 lines

Review line 8

Quoted 2 lines
(quoted diff) +2 -0
+
+bpf_dep = dependency('libbpf', required: false)

My library is in '/usr/local/lib64/libbpf.so' but this line can't find it. Where does 'dependency()' checks for libraries?

dependency() uses only pkg-config (or cmake or embedded specific tools, neither of which applies to bpf), so if you haven't built from bpf-next you won't have the pkg-config file installed, and it will fall back to the next block.

Side note, there's an issue open upstream in Meson to merge dependency() and find_library(), with some traction but it's not done yet.

Quoted 8 lines

For me building from bpf-next it works fine:

$ PKG_CONFIG_PATH=/tmp/bpf/lib64/pkgconfig/ ninja -C build-gcc-shared
...
Dependency libbpf found: YES 0.0.2
...
$ lddtree build-gcc-shared/drivers/librte_pmd_af_xdp.so.1.1
librte_pmd_af_xdp.so.1.1 => build-gcc-

shared/drivers/librte_pmd_af_xdp.so.1.1 (interpreter => none)

Quoted 4 lines
   libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6
   libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2
   libnuma.so.1 => /lib/x86_64-linux-gnu/libnuma.so.1
   librte_ethdev.so.12 => build-gcc-

shared/drivers/../lib/librte_ethdev.so.12

Quoted 5 lines
   librte_eal.so.10 => build-gcc-shared/drivers/../lib/librte_eal.so.10
   librte_kvargs.so.1 => build-gcc-shared/drivers/../lib/librte_kvargs.so.1
   librte_net.so.1 => build-gcc-shared/drivers/../lib/librte_net.so.1
   librte_mbuf.so.5 => build-gcc-shared/drivers/../lib/librte_mbuf.so.5
   librte_mempool.so.5 => build-gcc-

shared/drivers/../lib/librte_mempool.so.5

Quoted 27 lines
   librte_ring.so.2 => build-gcc-shared/drivers/../lib/librte_ring.so.2
   librte_cmdline.so.2 => build-gcc-shared/drivers/../lib/librte_cmdline.so.2
   librte_meter.so.2 => build-gcc-shared/drivers/../lib/librte_meter.so.2
   librte_bus_pci.so.2 => not found
   librte_pci.so.1 => build-gcc-shared/drivers/../lib/librte_pci.so.1
   librte_bus_vdev.so.2 => not found
   libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0
       librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1
   libbpf.so.0 => /tmp/bpf/lib64/libbpf.so.0
       libelf.so.1 => /lib/x86_64-linux-gnu/libelf.so.1
           libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1
   libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0
   libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6
   ld-linux-x86-64.so.2 => /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
Quoted 8 lines

drivers/net/af_xdp/meson.build line 12

Quoted 4 lines
drivers/net/af_xdp/meson.build new file +4 -0
+if bpf_dep.found()
+	build = true
+else
+	bpf_dep = cc.find_library('libbpf', required: false)

Also this line can't find it, in log it says "(tried pkgconfig and cmake)" and yes there is no pkgconfig for it, any idea how 'cmake' used?

The issue here is that it should be cc.find_library('bpf' - not 'libbpf'. I missed this when reviewing, good catch.

Quoted 8 lines

That's because find_library just does a compilation test passing the value to the compiler as a linker flag - so right now it's passing -llibbpf. Fixing this line and the header line below makes it work without pkg-config:

$ CPPFLAGS=-I/tmp/bpf/include LDFLAGS=-L/tmp/bpf/lib64 meson testt ...
Dependency libbpf found: NO (tried pkgconfig and cmake) Library bpf
found: YES

After apply the fix in af_xdp pmd's meson.build, now I was able to build library for af_xdp pmd.

$ ls drivers/ |grep xdp
a715181@@rte_pmd_af_xdp@sha
a715181@@rte_pmd_af_xdp@sta
a715181@@tmp_rte_pmd_af_xdp@sta
librte_pmd_af_xdp.a
librte_pmd_af_xdp.so
librte_pmd_af_xdp.so.1
librte_pmd_af_xdp.so.1.1
libtmp_rte_pmd_af_xdp.a
rte_pmd_af_xdp.pmd.c

But I found that if I install libbpf to /usr/local/lib64 by default, application built by meson build will fail to run:

Quoted 7 lines
$ ./dpdk-testpmd
./dpdk-testpmd: error while loading shared libraries: libbpf.so.0: cannot open
shared object file: No such file or directory

While install libbpf to /usr/lib doesn't have this issue (I was testing on ubuntu system).
Is it a expected behavior? Do we need any fix for it?

Hi, Xiaolong

I have encountered the same issue on ubuntu-arm64-server with Kernel v5.1.0-rc3+. If I read correctly, I think Luca's patch can solve this issue.
https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/commit/?id=dd399ac9e343c7573c47d6820e4a23013c54749d

So, will this patch in v5.1-rc4 ?

Thanks,
Phil

Quoted 14 lines

Thanks,
Xiaolong

Quoted 11 lines
Quoted 5 lines
Quoted 3 lines
(quoted diff) +1 -0
+	if bpf_dep.found() and cc.has_header('xsk.h', dependencies:

bpf_dep) and cc.has_header('linux/if_xdp.h')

Should this be 'lib/xsk.h' now?

Yes, this should be 'bpf/xsk.h'

--
Kind regards,
Luca Boccassi

#198 lore raw

Re: [PATCH v10 1/1] net/af_xdp: introduce AF XDP PMD driver

In reply to Ye Xiaolong
Quoted 159 lines · Ye Xiaolong

Hi, Luca

Quoted 132 lines · Luca Boccassi
Quoted 47 lines · Ferruh Yigit
Quoted 16 lines · Xiaolong Ye

Add a new PMD driver for AF_XDP which is a proposed faster version
of
AF_PACKET interface in Linux. More info about AF_XDP, please refer
to [1]
[2].

This is the vanilla version PMD which just uses a raw buffer registered as
the umem.

[1]
https://fosdem.org/2018/schedule/event/af_xdp/

Quoted 8 lines

[2]
https://lwn.net/Articles/745934/

Signed-off-by: Xiaolong Ye <
[email protected]

I am not able to test functionality but code looks good to me, I can
compile via
Makefile (with suggested steps in doc) but not able to build with meson, can you
please check below comments?

<...>

drivers/net/af_xdp/meson.build line 6

Quoted 7 lines
drivers/net/af_xdp/meson.build new file +6 -0
@@ -0,0 +1,21 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+if host_machine.system() != 'linux'
+	build = false
+endif

After this point, if build is false it shouldn't continue to below
checks I think.

Quoted 6 lines

Review line 8

Quoted 2 lines
(quoted diff) +2 -0
+
+bpf_dep = dependency('libbpf', required: false)

My library is in '/usr/local/lib64/libbpf.so' but this line can't find it. Where
does 'dependency()' checks for libraries?

dependency() uses only pkg-config (or cmake or embedded specific tools,
neither of which applies to bpf), so if you haven't built from bpf- next
you won't have the pkg-config file installed, and it will fall back to
the next block.

Side note, there's an issue open upstream in Meson to merge dependency() and find_library(), with some traction but it's not done
yet.

For me building from bpf-next it works fine:

$ PKG_CONFIG_PATH=/tmp/bpf/lib64/pkgconfig/ ninja -C build-gcc-
shared
...
Dependency libbpf found: YES 0.0.2
...
$ lddtree build-gcc-shared/drivers/librte_pmd_af_xdp.so.1.1 
librte_pmd_af_xdp.so.1.1 => build-gcc-
shared/drivers/librte_pmd_af_xdp.so.1.1 (interpreter => none)
   libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6
   libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2
   libnuma.so.1 => /lib/x86_64-linux-gnu/libnuma.so.1
   librte_ethdev.so.12 => build-gcc-
shared/drivers/../lib/librte_ethdev.so.12
   librte_eal.so.10 => build-gcc-
shared/drivers/../lib/librte_eal.so.10
   librte_kvargs.so.1 => build-gcc-
shared/drivers/../lib/librte_kvargs.so.1
   librte_net.so.1 => build-gcc-
shared/drivers/../lib/librte_net.so.1
   librte_mbuf.so.5 => build-gcc-
shared/drivers/../lib/librte_mbuf.so.5
   librte_mempool.so.5 => build-gcc-
shared/drivers/../lib/librte_mempool.so.5
   librte_ring.so.2 => build-gcc-
shared/drivers/../lib/librte_ring.so.2
   librte_cmdline.so.2 => build-gcc-
shared/drivers/../lib/librte_cmdline.so.2
   librte_meter.so.2 => build-gcc-
shared/drivers/../lib/librte_meter.so.2
   librte_bus_pci.so.2 => not found
   librte_pci.so.1 => build-gcc-
shared/drivers/../lib/librte_pci.so.1
   librte_bus_vdev.so.2 => not found
   libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0
       librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1
   libbpf.so.0 => /tmp/bpf/lib64/libbpf.so.0
       libelf.so.1 => /lib/x86_64-linux-gnu/libelf.so.1
           libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1
   libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0
   libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6
   ld-linux-x86-64.so.2 => /lib/x86_64-linux-gnu/ld-linux-x86-
64.so.2
Quoted 9 lines

drivers/net/af_xdp/meson.build line 12

Quoted 4 lines
drivers/net/af_xdp/meson.build new file +4 -0
+if bpf_dep.found()
+	build = true
+else
+	bpf_dep = cc.find_library('libbpf', required: false)

Also this line can't find it, in log it says "(tried pkgconfig and
cmake)" and
yes there is no pkgconfig for it, any idea how 'cmake' used?

The issue here is that it should be cc.find_library('bpf' - not 'libbpf'. I missed this when reviewing, good catch.

That's because find_library just does a compilation test passing the
value to the compiler as a linker flag - so right now it's passing -llibbpf. Fixing this line and the header line below makes it work without pkg-config:

Quoted 4 lines
$ CPPFLAGS=-I/tmp/bpf/include LDFLAGS=-L/tmp/bpf/lib64 meson testt
...
Dependency libbpf found: NO (tried pkgconfig and cmake)
Library bpf found: YES

After apply the fix in af_xdp pmd's meson.build, now I was able to build
library for af_xdp pmd.

$ ls drivers/ |grep xdp
a715181@@rte_pmd_af_xdp@sha
a715181@@rte_pmd_af_xdp@sta
a715181@@tmp_rte_pmd_af_xdp@sta
librte_pmd_af_xdp.a
librte_pmd_af_xdp.so
librte_pmd_af_xdp.so.1
librte_pmd_af_xdp.so.1.1
libtmp_rte_pmd_af_xdp.a
rte_pmd_af_xdp.pmd.c

But I found that if I install libbpf to /usr/local/lib64 by default, application
built by meson build will fail to run:

Quoted 7 lines
$ ./dpdk-testpmd
./dpdk-testpmd: error while loading shared libraries: libbpf.so.0:
cannot open shared object file: No such file or directory

While install libbpf to /usr/lib doesn't have this issue (I was testing on ubuntu system).
Is it a expected behavior? Do we need any fix for it?

Hi,

That is expected and distro specific: if your distro doesn't add /usr/local/lib* to the compiler path, it also won't be in the LD_LIBRARY_PATH.

So if you do:

LD_LIBRARY_PATH=/usr/local/lib64 ./dpdk-testpmd

It should then work. It's not related to the build system, but just to what the default paths are in the distro.

Signature · 2 lines
Kind regards,
Luca Boccassi
#199 lore raw

Re: [PATCH v10 1/1] net/af_xdp: introduce AF XDP PMD driver

Quoted 30 lines · Luca Boccassi
Quoted 20 lines

After apply the fix in af_xdp pmd's meson.build, now I was able to build
library for af_xdp pmd.

$ ls drivers/ |grep xdp
a715181@@rte_pmd_af_xdp@sha
a715181@@rte_pmd_af_xdp@sta
a715181@@tmp_rte_pmd_af_xdp@sta
librte_pmd_af_xdp.a
librte_pmd_af_xdp.so
librte_pmd_af_xdp.so.1
librte_pmd_af_xdp.so.1.1
libtmp_rte_pmd_af_xdp.a
rte_pmd_af_xdp.pmd.c

But I found that if I install libbpf to /usr/local/lib64 by default, application
built by meson build will fail to run:

Quoted 7 lines
$ ./dpdk-testpmd
./dpdk-testpmd: error while loading shared libraries: libbpf.so.0:
cannot open shared object file: No such file or directory

While install libbpf to /usr/lib doesn't have this issue (I was testing on ubuntu system).
Is it a expected behavior? Do we need any fix for it?

Hi,

Quoted 7 lines

That is expected and distro specific: if your distro doesn't add /usr/local/lib* to the compiler path, it also won't be in the LD_LIBRARY_PATH.

So if you do:

LD_LIBRARY_PATH=/usr/local/lib64 ./dpdk-testpmd

Yes, it does work for me.

Quoted 3 lines

It should then work. It's not related to the build system, but just to what the default paths are in the distro.

Thanks for confirmation, then I can send my v11 out :)

Thanks,
Xiaolong

Quoted 4 lines
Signature · 3 lines
-- 
Kind regards,
Luca Boccassi
#200 lore raw

Re: [PATCH v10 1/1] net/af_xdp: introduce AF XDP PMD driver

In reply to Ferruh Yigit

Hi, Ferruh

Quoted 8 lines · Ferruh Yigit
Quoted 7 lines · Xiaolong Ye

Add a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux. More info about AF_XDP, please refer to [1] [2].

This is the vanilla version PMD which just uses a raw buffer registered as the umem.

Quoted 9 lines
Quoted 4 lines

[1] https://fosdem.org/2018/schedule/event/af_xdp/
[2] https://lwn.net/Articles/745934/

I am not able to test functionality but code looks good to me, I can compile via Makefile (with suggested steps in doc) but not able to build with meson, can you please check below comments?

My bad, sorry for not testing out meson build.

Quoted 11 lines

<...>

drivers/net/af_xdp/meson.build line 6

Quoted 7 lines
drivers/net/af_xdp/meson.build new file +6 -0
@@ -0,0 +1,21 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+if host_machine.system() != 'linux'
+	build = false
+endif

After this point, if build is false it shouldn't continue to below checks I think.

Make sense, will do.

Quoted 7 lines

Review line 8

Quoted 3 lines
(quoted diff) +2 -0
+
+bpf_dep = dependency('libbpf', required: false)

My library is in '/usr/local/lib64/libbpf.so' but this line can't find it. Where does 'dependency()' checks for libraries?

Quoted 7 lines

drivers/net/af_xdp/meson.build line 12

Quoted 4 lines
drivers/net/af_xdp/meson.build new file +4 -0
+if bpf_dep.found()
+	build = true
+else
+	bpf_dep = cc.find_library('libbpf', required: false)

Also this line can't find it, in log it says "(tried pkgconfig and cmake)" and yes there is no pkgconfig for it, any idea how 'cmake' used?

As Luca said, it should be cc.find_library('bpf', required: false), will correct it in next version.

Quoted 4 lines

drivers/net/af_xdp/meson.build line 13

Quoted 2 lines
drivers/net/af_xdp/meson.build new file +1 -0
+	if bpf_dep.found() and cc.has_header('xsk.h', dependencies: bpf_dep) and cc.has_header('linux/if_xdp.h')

Should this be 'lib/xsk.h' now?

Will change to bpf/xsk.h in next version.

Thanks,
Xiaolong

Quoted 10 lines
Quoted 9 lines
drivers/net/af_xdp/meson.build new file +8 -0
+		build = true
+		pkgconfig_extra_libs += '-lbpf'
+	else
+		build = false
+	endif
+endif
+sources = files('rte_eth_af_xdp.c')
+ext_deps += bpf_dep
#201 lore raw

v11 cover Introduce AF_XDP PMD

In reply to Xiaolong Ye

Overview
========

This patchset adds a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux, see below links [1] [2] for details of AF_XDP introduction:

AF_XDP roadmap
==============
- AF_XDP is included in upstream kernel since 4.18, and AF_XDP support in libbpf has been merged in v5.1-rc1.
- Now i40e and ixgbe drivers have supported zero copy mode.

Change logs
===========
v11:

- fix the meson build issue

v10:

- refine the Makefile, remove RTE_KERNELDIR related CFLAGS
- add a new internal file af_xdp_deps.h to handle the dependency for asm/barrier.h
- fix a typo observed by Stephen
- rename xsk.h to bpf/xsk.h as xsk.h is assumed to be installed in /usr/local/include/bpf
- add libbpf build steps in af_xdp.rst

v9:
- adjust header files order according to Stephen's suggestion

v8:
- address Ferruh's comments on V7
- replace posix_memalign with rte_memzone_reserve_aligned to get better performance
- keep the first patch only as Oliver suggested as zero copy part implementation is still in suspense, we may provide the related patch later.

v7:
- mention mtu limitation in af_xdp.rst
- fix the vdev name in af_xdp.rst

V6:

- remove the newline in AF_XDP_LOG definition to avoid double new lines issue.
- rename MEMPOOL_F_PAGE_ALIGN to MEMPOOL_CHUNK_F_PAGE_ALIGN.

V5:

- disable AF_XDP pmd by default due to it requires kernel more recent than minimum kernel version supported by DPDK
- address other review comments of Maxime

V4:

- change vdev name to net_af_xdp
- adopt dynamic log type for all logging
- Fix other style issues raised by Stephen

V3:

- Fix all style issues pointed by Stephen, Mattias, David.
- Drop the testpmd change as we'll adopt Jerin's suggestion to add a new mempool driver to handle the application use of AF_XDP's zero copy feature.

V2:
- Fix a NULL pointer reference crash issue
- Fix txonly stop sending traffic in zc mode
- Refactor rte_mbuf.c to avoid ABI breakage.
- Fix multiple style issues pointed by Ferruh, David, Stephen, Luca.

changes vs RFC sent by Qi last Aug:

- Re-work base on AF_XDP's interface changes since the new libbpf has provided higher-level APIs that hide many of the details of the AP_XDP uapi. After the rework, it helps to reduce 300+ lines of code.

- multi-queues is not supported due to current libbpf doesn't support multi-sockets on a single umem.

- No extra steps to load xdp program manually, since the current behavior of libbpf would load a default xdp program when user calls xsk_socket__create. userspace application only needs to handle the cleanup.

How to try
==========

1. take the kernel >= v5.1-rc1, build kernel and replace your host kernel with it.

make sure you turn on XDP sockets when compiling

Networking support -->
Networking options -->
[ * ] XDP sockets

2. build & install libbpf in tools/lib/bpf

cd tools/lib/bpf
make install_lib
make install_headers

3. ethtool -L enp59s0f0 combined 1

4. extra step to build dpdk

explicitly enable AF_XDP pmd by adding below line to config/common_linux

CONFIG_RTE_LIBRTE_PMD_AF_XDP=y

5. start testpmd

   ./build/app/testpmd -c 0xc -n 4 --vdev net_af_xdp,iface=enp59s0f0,queue=0 -- -i --rxq=1 --txq=1

in this case, default xdp program will be loaded and linked to queue 0 of enp59s0f0, network traffics travel to queue 0 will be redirected to af_xdp socket.

Xiaolong Ye (1):
net/af_xdp: introduce AF XDP PMD driver

 MAINTAINERS                                   |   7 +
 config/common_base                            |   5 +
 doc/guides/nics/af_xdp.rst                    |  50 +
 doc/guides/nics/features/af_xdp.ini           |  11 +
 doc/guides/nics/index.rst                     |   1 +
 doc/guides/rel_notes/release_19_05.rst        |   7 +
 drivers/net/Makefile                          |   1 +
 drivers/net/af_xdp/Makefile                   |  28 +
 drivers/net/af_xdp/af_xdp_deps.h              |  15 +
 drivers/net/af_xdp/meson.build                |  19 +
 drivers/net/af_xdp/rte_eth_af_xdp.c           | 955 ++++++++++++++++++
 drivers/net/af_xdp/rte_pmd_af_xdp_version.map |   3 +
 drivers/net/meson.build                       |   1 +
 mk/rte.app.mk                                 |   1 +
 14 files changed, 1104 insertions(+)
 create mode 100644 doc/guides/nics/af_xdp.rst
 create mode 100644 doc/guides/nics/features/af_xdp.ini
 create mode 100644 drivers/net/af_xdp/Makefile
 create mode 100644 drivers/net/af_xdp/af_xdp_deps.h
 create mode 100644 drivers/net/af_xdp/meson.build
 create mode 100644 drivers/net/af_xdp/rte_eth_af_xdp.c
 create mode 100644 drivers/net/af_xdp/rte_pmd_af_xdp_version.map
Signature · 1 line
2.17.1
#202 lore raw

PATCH v11 1/1 net/af_xdp: introduce AF XDP PMD driver

Add a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux. More info about AF_XDP, please refer to [1] [2].

This is the vanilla version PMD which just uses a raw buffer registered as the umem.

[1] https://fosdem.org/2018/schedule/event/af_xdp/
[2] https://lwn.net/Articles/745934/

---
 MAINTAINERS                                   |   7 +
 config/common_base                            |   5 +
 doc/guides/nics/af_xdp.rst                    |  50 +
 doc/guides/nics/features/af_xdp.ini           |  11 +
 doc/guides/nics/index.rst                     |   1 +
 doc/guides/rel_notes/release_19_05.rst        |   7 +
 drivers/net/Makefile                          |   1 +
 drivers/net/af_xdp/Makefile                   |  28 +
 drivers/net/af_xdp/af_xdp_deps.h              |  15 +
 drivers/net/af_xdp/meson.build                |  19 +
 drivers/net/af_xdp/rte_eth_af_xdp.c           | 955 ++++++++++++++++++
 drivers/net/af_xdp/rte_pmd_af_xdp_version.map |   3 +
 drivers/net/meson.build                       |   1 +
 mk/rte.app.mk                                 |   1 +
 14 files changed, 1104 insertions(+)
 create mode 100644 doc/guides/nics/af_xdp.rst
 create mode 100644 doc/guides/nics/features/af_xdp.ini
 create mode 100644 drivers/net/af_xdp/Makefile
 create mode 100644 drivers/net/af_xdp/af_xdp_deps.h
 create mode 100644 drivers/net/af_xdp/meson.build
 create mode 100644 drivers/net/af_xdp/rte_eth_af_xdp.c
 create mode 100644 drivers/net/af_xdp/rte_pmd_af_xdp_version.map
MAINTAINERS +7 -0
index 71ac8cd4b..f30572c07 100644
@@ -489,6 +489,13 @@ M: John W. Linville <[email protected]>
 F: drivers/net/af_packet/
 F: doc/guides/nics/features/afpacket.ini
 
+Linux AF_XDP
+M: Xiaolong Ye <[email protected]>
+M: Qi Zhang <[email protected]>
+F: drivers/net/af_xdp/
+F: doc/guides/nics/af_xdp.rst
+F: doc/guides/nics/features/af_xdp.ini
+
 Amazon ENA
 M: Marcin Wojtas <[email protected]>
 M: Michal Krawczyk <[email protected]>
config/common_base +5 -0
index 6292bc4af..b95ee03d7 100644
@@ -430,6 +430,11 @@ CONFIG_RTE_LIBRTE_VMXNET3_DEBUG_TX_FREE=n
 #
 CONFIG_RTE_LIBRTE_PMD_AF_PACKET=n
 
+#
+# Compile software PMD backed by AF_XDP sockets (Linux only)
+#
+CONFIG_RTE_LIBRTE_PMD_AF_XDP=n
+
 #
 # Compile link bonding PMD library
 #
doc/guides/nics/af_xdp.rst new file +50 -0

50 lines not on this page · raw message

doc/guides/nics/features/af_xdp.ini new file +11 -0
new file mode 100644
index 000000000..36953c2de
@@ -0,0 +1,11 @@
+;
+; Supported features of the 'af_xdp' network poll mode driver.
+;
+; Refer to default.ini for the full list of available PMD features.
+;
+[Features]
+Link status          = Y
+MTU update           = Y
+Promiscuous mode     = Y
+Stats per queue      = Y
+x86-64               = Y
doc/guides/nics/index.rst +1 -0
index 5c80e3baa..a4b80a3d0 100644
@@ -12,6 +12,7 @@ Network Interface Controller Drivers
     features
     build_and_test
     af_packet
+    af_xdp
     ark
     atlantic
     avp
doc/guides/rel_notes/release_19_05.rst +7 -0
index bdad1ddbe..79e36739f 100644
@@ -74,6 +74,13 @@ New Features
     process.
   * Added support for Rx packet types list in a secondary process.
 
+* **Added the AF_XDP PMD.**
+
+  Added a Linux-specific PMD driver for AF_XDP, it can create the AF_XDP socket
+  and bind it to a specific netdev queue, it allows a DPDK application to send
+  and receive raw packets through the socket which would bypass the kernel
+  network stack to achieve high performance packet processing.
+
 * **Updated Mellanox drivers.**
 
    New features and improvements were done in mlx4 and mlx5 PMDs:
drivers/net/Makefile +1 -0
index 502869a87..5d401b8c5 100644
@@ -9,6 +9,7 @@ ifeq ($(CONFIG_RTE_LIBRTE_THUNDERX_NICVF_PMD),d)
 endif
 
 DIRS-$(CONFIG_RTE_LIBRTE_PMD_AF_PACKET) += af_packet
+DIRS-$(CONFIG_RTE_LIBRTE_PMD_AF_XDP) += af_xdp
 DIRS-$(CONFIG_RTE_LIBRTE_ARK_PMD) += ark
 DIRS-$(CONFIG_RTE_LIBRTE_ATLANTIC_PMD) += atlantic
 DIRS-$(CONFIG_RTE_LIBRTE_AVP_PMD) += avp
drivers/net/af_xdp/Makefile new file +28 -0
new file mode 100644
index 000000000..eeba6b693
@@ -0,0 +1,28 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+#
+# library name
+#
+LIB = librte_pmd_af_xdp.a
+
+EXPORT_MAP := rte_pmd_af_xdp_version.map
+
+LIBABIVER := 1
+
+CFLAGS += -O3
+
+CFLAGS += $(WERROR_FLAGS)
+LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring
+LDLIBS += -lrte_ethdev -lrte_net -lrte_kvargs
+LDLIBS += -lrte_bus_vdev
+LDLIBS += $(shell command -v pkg-config > /dev/null 2>&1 && pkg-config --libs libbpf || echo "-lbpf")
+
+#
+# all source are stored in SRCS-y
+#
+SRCS-$(CONFIG_RTE_LIBRTE_PMD_AF_XDP) += rte_eth_af_xdp.c
+
+include $(RTE_SDK)/mk/rte.lib.mk
drivers/net/af_xdp/af_xdp_deps.h new file +15 -0
new file mode 100644
index 000000000..18416d094
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Intel Corporation.
+ */
+
+#ifndef AF_XDP_DEPS_H_
+#define AF_XDP_DEPS_H_
+
+#include <rte_atomic.h>
+#include <rte_branch_prediction.h>
+
+/* This is to fix the xsk.h's dependency on asm/barrier.h */
+#define smp_rmb() rte_rmb()
+#define smp_wmb() rte_wmb()
+
+#endif /* AF_XDP_DEPS_H_ */
drivers/net/af_xdp/meson.build new file +19 -0
new file mode 100644
index 000000000..840c93728
@@ -0,0 +1,19 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+if host_machine.system() == 'linux'
+	bpf_dep = dependency('libbpf', required: false)
+	if bpf_dep.found()
+		build = true
+	else
+		bpf_dep = cc.find_library('bpf', required: false)
+		if bpf_dep.found() and cc.has_header('bpf/xsk.h', dependencies: bpf_dep) and cc.has_header('linux/if_xdp.h')
+			build = true
+			pkgconfig_extra_libs += '-lbpf'
+		else
+			build = false
+		endif
+	endif
+	ext_deps += bpf_dep
+endif
+sources = files('rte_eth_af_xdp.c')
drivers/net/af_xdp/rte_eth_af_xdp.c new file +955 -0

955 lines not on this page · raw message

drivers/net/af_xdp/rte_pmd_af_xdp_version.map new file +3 -0
new file mode 100644
index 000000000..c6db030fe
@@ -0,0 +1,3 @@
+DPDK_19.05 {
+	local: *;
+};
drivers/net/meson.build +1 -0
index 3ecc78cee..1105e72d8 100644
@@ -2,6 +2,7 @@
 # Copyright(c) 2017 Intel Corporation
 
 drivers = ['af_packet',
+	'af_xdp',
 	'ark',
 	'atlantic',
 	'avp',
mk/rte.app.mk +1 -0
index 262132fc6..f916bc9ef 100644
@@ -143,6 +143,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_DPAA2_MEMPOOL)  += -lrte_mempool_dpaa2
 endif
 
 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AF_PACKET)  += -lrte_pmd_af_packet
+_LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AF_XDP)     += -lrte_pmd_af_xdp -lbpf
 _LDLIBS-$(CONFIG_RTE_LIBRTE_ARK_PMD)        += -lrte_pmd_ark
 _LDLIBS-$(CONFIG_RTE_LIBRTE_ATLANTIC_PMD)   += -lrte_pmd_atlantic
 _LDLIBS-$(CONFIG_RTE_LIBRTE_AVP_PMD)        += -lrte_pmd_avp
Signature · 1 line
2.17.1
Acked-by on v11 1/1
#203 lore raw

Re: [PATCH v11 1/1] net/af_xdp: introduce AF XDP PMD driver

Quoted 35 lines · Xiaolong Ye

Add a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux. More info about AF_XDP, please refer to
[1]
[2].

This is the vanilla version PMD which just uses a raw buffer registered as
the umem.

[1]
https://fosdem.org/2018/schedule/event/af_xdp/

[2]
https://lwn.net/Articles/745934/

Signed-off-by: Xiaolong Ye <
[email protected]

Quoted 1 line
---
 MAINTAINERS                                   |   7 +
 config/common_base                            |   5 +
 doc/guides/nics/af_xdp.rst                    |  50 +
 doc/guides/nics/features/af_xdp.ini           |  11 +
 doc/guides/nics/index.rst                     |   1 +
 doc/guides/rel_notes/release_19_05.rst        |   7 +
 drivers/net/Makefile                          |   1 +
 drivers/net/af_xdp/Makefile                   |  28 +
 drivers/net/af_xdp/af_xdp_deps.h              |  15 +
 drivers/net/af_xdp/meson.build                |  19 +
 drivers/net/af_xdp/rte_eth_af_xdp.c           | 955
++++++++++++++++++
 drivers/net/af_xdp/rte_pmd_af_xdp_version.map |   3 +
 drivers/net/meson.build                       |   1 +
 mk/rte.app.mk                                 |   1 +
Quoted 8 lines
 14 files changed, 1104 insertions(+)
 create mode 100644 doc/guides/nics/af_xdp.rst
 create mode 100644 doc/guides/nics/features/af_xdp.ini
 create mode 100644 drivers/net/af_xdp/Makefile
 create mode 100644 drivers/net/af_xdp/af_xdp_deps.h
 create mode 100644 drivers/net/af_xdp/meson.build
 create mode 100644 drivers/net/af_xdp/rte_eth_af_xdp.c
 create mode 100644 drivers/net/af_xdp/rte_pmd_af_xdp_version.map
Signature · 2 lines
Kind regards,
Luca Boccassi
Reviewed-by
#204 lore raw

Re: [PATCH v11 1/1] net/af_xdp: introduce AF XDP PMD driver

Quoted 13 lines · On Thu, 04 Apr 2019 17:20:43 +0100 Luca Boccassi <[email protected]> wrote:
Quoted 12 lines · Xiaolong Ye

Add a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux. More info about AF_XDP, please refer to
[1]
[2].

This is the vanilla version PMD which just uses a raw buffer registered as
the umem.

[1]
https://fosdem.org/2018/schedule/event/af_xdp/

Quoted 6 lines
Quoted 6 lines

[2]
https://lwn.net/Articles/745934/

Signed-off-by: Xiaolong Ye <
[email protected]

Reviewed-by Applied
#205 lore raw

Re: [PATCH v11 1/1] net/af_xdp: introduce AF XDP PMD driver

Quoted 16 lines · Stephen Hemminger
Quoted 13 lines · On Thu, 04 Apr 2019 17:20:43 +0100 Luca Boccassi <[email protected]> wrote:
Quoted 12 lines · Xiaolong Ye

Add a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux. More info about AF_XDP, please refer to
[1]
[2].

This is the vanilla version PMD which just uses a raw buffer registered as
the umem.

[1]
https://fosdem.org/2018/schedule/event/af_xdp/

Quoted 9 lines
Quoted 6 lines
Quoted 6 lines

[2]
https://lwn.net/Articles/745934/

Signed-off-by: Xiaolong Ye <
[email protected]

Applied to dpdk-next-net/master, thanks.

#206 lore raw

Re: [dpdk-dev] [PATCH v11 1/1] net/af_xdp: introduce AF XDP PMD driver

In reply to Xiaolong Ye
Quoted 11 lines · Xiaolong Ye

Add a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux. More info about AF_XDP, please refer to [1] [2].

This is the vanilla version PMD which just uses a raw buffer registered as the umem.

[1] https://fosdem.org/2018/schedule/event/af_xdp/
[2] https://lwn.net/Articles/745934/

<...>

Quoted 15 lines
drivers/net/af_xdp/meson.build new file +9 -0
new file mode 100644
index 000000000..840c93728
@@ -0,0 +1,19 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+if host_machine.system() == 'linux'
+	bpf_dep = dependency('libbpf', required: false)
+	if bpf_dep.found()
+		build = true
+	else
+		bpf_dep = cc.find_library('bpf', required: false)

drivers/net/af_xdp/meson.build line 19

Quoted 10 lines
drivers/net/af_xdp/meson.build new file +10 -0
+		if bpf_dep.found() and cc.has_header('bpf/xsk.h', dependencies: bpf_dep) and cc.has_header('linux/if_xdp.h')
+			build = true
+			pkgconfig_extra_libs += '-lbpf'
+		else
+			build = false
+		endif
+	endif
+	ext_deps += bpf_dep
+endif
+sources = files('rte_eth_af_xdp.c')

if system is not 'linux', by default build will be 'true', right, so will it try to build the driver in that case?
What about setting "build = false" before the linux check, so won't need to set it false again in the if block, only set it true if dependencies found? And can 'ext_deps' go out of if block?

#207 lore raw

Re: [dpdk-dev] [PATCH v11 1/1] net/af_xdp: introduce AF XDP PMD driver

Hi, Ferruh

Quoted 37 lines · Ferruh Yigit
Quoted 11 lines · Xiaolong Ye

Add a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux. More info about AF_XDP, please refer to [1] [2].

This is the vanilla version PMD which just uses a raw buffer registered as the umem.

[1] https://fosdem.org/2018/schedule/event/af_xdp/
[2] https://lwn.net/Articles/745934/

<...>

Quoted 22 lines
drivers/net/af_xdp/meson.build new file +16 -0
new file mode 100644
index 000000000..840c93728
@@ -0,0 +1,19 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+if host_machine.system() == 'linux'
+	bpf_dep = dependency('libbpf', required: false)
+	if bpf_dep.found()
+		build = true
+	else
+		bpf_dep = cc.find_library('bpf', required: false)
+		if bpf_dep.found() and cc.has_header('bpf/xsk.h', dependencies: bpf_dep) and cc.has_header('linux/if_xdp.h')
+			build = true
+			pkgconfig_extra_libs += '-lbpf'
+		else
+			build = false
+		endif
+	endif
Quoted 8 lines

drivers/net/af_xdp/meson.build line 19

Quoted 3 lines
drivers/net/af_xdp/meson.build new file +3 -0
+	ext_deps += bpf_dep
+endif
+sources = files('rte_eth_af_xdp.c')

if system is not 'linux', by default build will be 'true', right, so will it try to build the driver in that case?
What about setting "build = false" before the linux check, so won't need to set it false again in the if block, only set it true if dependencies found?

This is a good catch, we do need to initialize build = false first, otherwise meson/ninja would just try to build af_xdp pmd if system is not linux, which is undesired. Do I need to send a separate patch for this so you can squash it into af_xdp pmd patch?

Quoted 1 line

And can 'ext_deps' go out of if block?

If we move ext_deps += bpf_dep out of if block and build system is not linux, there would be error "ERROR: Unknown variable "bpf_dep".", so we need either initialize bpf_dep (to value like NULL?) first or keep ext_deps += bpf_dep inside the if block, I'd prefer keep it as it is, what's you opinion?

Thanks,
Xiaolong

#208 lore raw

Re: [dpdk-dev] [PATCH v11 1/1] net/af_xdp: introduce AF XDP PMD driver

Quoted 49 lines · Ye Xiaolong

Hi, Ferruh

Quoted 37 lines · Ferruh Yigit
Quoted 11 lines · Xiaolong Ye

Add a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux. More info about AF_XDP, please refer to [1] [2].

This is the vanilla version PMD which just uses a raw buffer registered as the umem.

[1] https://fosdem.org/2018/schedule/event/af_xdp/
[2] https://lwn.net/Articles/745934/

<...>

Quoted 22 lines
drivers/net/af_xdp/meson.build new file +16 -0
new file mode 100644
index 000000000..840c93728
@@ -0,0 +1,19 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+if host_machine.system() == 'linux'
+	bpf_dep = dependency('libbpf', required: false)
+	if bpf_dep.found()
+		build = true
+	else
+		bpf_dep = cc.find_library('bpf', required: false)
+		if bpf_dep.found() and cc.has_header('bpf/xsk.h', dependencies: bpf_dep) and cc.has_header('linux/if_xdp.h')
+			build = true
+			pkgconfig_extra_libs += '-lbpf'
+		else
+			build = false
+		endif
+	endif
Quoted 8 lines

drivers/net/af_xdp/meson.build line 19

Quoted 3 lines
drivers/net/af_xdp/meson.build new file +3 -0
+	ext_deps += bpf_dep
+endif
+sources = files('rte_eth_af_xdp.c')

if system is not 'linux', by default build will be 'true', right, so will it try to build the driver in that case?
What about setting "build = false" before the linux check, so won't need to set it false again in the if block, only set it true if dependencies found?

Quoted 4 lines

This is a good catch, we do need to initialize build = false first, otherwise meson/ninja would just try to build af_xdp pmd if system is not linux, which is undesired. Do I need to send a separate patch for this so you can squash it into af_xdp pmd patch?

If you are agree with the change, I can send the patch and squash it into the original af_xdp commit:

  diff --git a/drivers/net/af_xdp/meson.build b/drivers/net/af_xdp/meson.build
  index 840c93728..e3d86c39a 100644
  --- a/drivers/net/af_xdp/meson.build
  +++ b/drivers/net/af_xdp/meson.build
  @@ -1,6 +1,7 @@
   # SPDX-License-Identifier: BSD-3-Clause
   # Copyright(c) 2019 Intel Corporation

+build = false
if host_machine.system() == 'linux'
bpf_dep = dependency('libbpf', required: false) if bpf_dep.found()
@@ -10,8 +11,6 @@ if host_machine.system() == 'linux'
if bpf_dep.found() and cc.has_header('bpf/xsk.h',
dependencies: bpf_dep) and cc.has_header('linux/if_xdp.h')
build = true pkgconfig_extra_libs += '-lbpf'
- else
- build = false

                  endif
          endif
          ext_deps += bpf_dep
Quoted 7 lines
Quoted 2 lines

And can 'ext_deps' go out of if block?

If we move ext_deps += bpf_dep out of if block and build system is not linux, there would be error "ERROR: Unknown variable "bpf_dep".", so we need either initialize bpf_dep (to value like NULL?) first or keep ext_deps += bpf_dep inside the if block, I'd prefer keep it as it is, what's you opinion?

OK to keep as it is.

#209 lore raw

Re: [dpdk-dev] [PATCH v11 1/1] net/af_xdp: introduce AF XDP PMD driver

Quoted 77 lines · Ferruh Yigit
Quoted 49 lines · Ye Xiaolong

Hi, Ferruh

Quoted 37 lines · Ferruh Yigit
Quoted 11 lines · Xiaolong Ye

Add a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux. More info about AF_XDP, please refer to [1] [2].

This is the vanilla version PMD which just uses a raw buffer registered as the umem.

[1] https://fosdem.org/2018/schedule/event/af_xdp/
[2] https://lwn.net/Articles/745934/

<...>

Quoted 22 lines
drivers/net/af_xdp/meson.build new file +16 -0
new file mode 100644
index 000000000..840c93728
@@ -0,0 +1,19 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+if host_machine.system() == 'linux'
+	bpf_dep = dependency('libbpf', required: false)
+	if bpf_dep.found()
+		build = true
+	else
+		bpf_dep = cc.find_library('bpf', required: false)
+		if bpf_dep.found() and cc.has_header('bpf/xsk.h', dependencies: bpf_dep) and cc.has_header('linux/if_xdp.h')
+			build = true
+			pkgconfig_extra_libs += '-lbpf'
+		else
+			build = false
+		endif
+	endif
Quoted 8 lines

drivers/net/af_xdp/meson.build line 19

Quoted 3 lines
drivers/net/af_xdp/meson.build new file +3 -0
+	ext_deps += bpf_dep
+endif
+sources = files('rte_eth_af_xdp.c')

if system is not 'linux', by default build will be 'true', right, so will it try to build the driver in that case?
What about setting "build = false" before the linux check, so won't need to set it false again in the if block, only set it true if dependencies found?

Quoted 4 lines

This is a good catch, we do need to initialize build = false first, otherwise meson/ninja would just try to build af_xdp pmd if system is not linux, which is undesired. Do I need to send a separate patch for this so you can squash it into af_xdp pmd patch?

If you are agree with the change, I can send the patch and squash it into the original af_xdp commit:

diff --git a/drivers/net/af_xdp/meson.build b/drivers/net/af_xdp/meson.build index 840c93728..e3d86c39a 100644
--- a/drivers/net/af_xdp/meson.build
+++ b/drivers/net/af_xdp/meson.build
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2019 Intel Corporation

+build = false
if host_machine.system() == 'linux'
bpf_dep = dependency('libbpf', required: false) if bpf_dep.found()
@@ -10,8 +11,6 @@ if host_machine.system() == 'linux'
if bpf_dep.found() and cc.has_header('bpf/xsk.h',
dependencies: bpf_dep) and cc.has_header('linux/if_xdp.h')
build = true pkgconfig_extra_libs += '-lbpf'
- else
- build = false

Quoted 4 lines
                 endif
         endif
         ext_deps += bpf_dep

Looks good to me, thanks for the fix.

Thanks,
Xiaolong

Quoted 9 lines
Quoted 7 lines
Quoted 2 lines

And can 'ext_deps' go out of if block?

If we move ext_deps += bpf_dep out of if block and build system is not linux, there would be error "ERROR: Unknown variable "bpf_dep".", so we need either initialize bpf_dep (to value like NULL?) first or keep ext_deps += bpf_dep inside the if block, I'd prefer keep it as it is, what's you opinion?

OK to keep as it is.

#210 lore raw

Re: [dpdk-dev] [PATCH v11 1/1] net/af_xdp: introduce AF XDP PMD driver

In reply to Ye Xiaolong
Quoted 54 lines · Ye Xiaolong

Hi, Ferruh

Quoted 37 lines · Ferruh Yigit
Quoted 11 lines · Xiaolong Ye

Add a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux. More info about AF_XDP, please refer to [1] [2].

This is the vanilla version PMD which just uses a raw buffer registered as the umem.

[1] https://fosdem.org/2018/schedule/event/af_xdp/
[2] https://lwn.net/Articles/745934/

<...>

Quoted 22 lines
drivers/net/af_xdp/meson.build new file +16 -0
new file mode 100644
index 000000000..840c93728
@@ -0,0 +1,19 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+if host_machine.system() == 'linux'
+	bpf_dep = dependency('libbpf', required: false)
+	if bpf_dep.found()
+		build = true
+	else
+		bpf_dep = cc.find_library('bpf', required: false)
+		if bpf_dep.found() and cc.has_header('bpf/xsk.h', dependencies: bpf_dep) and cc.has_header('linux/if_xdp.h')
+			build = true
+			pkgconfig_extra_libs += '-lbpf'
+		else
+			build = false
+		endif
+	endif
Quoted 8 lines

drivers/net/af_xdp/meson.build line 19

Quoted 3 lines
drivers/net/af_xdp/meson.build new file +3 -0
+	ext_deps += bpf_dep
+endif
+sources = files('rte_eth_af_xdp.c')

if system is not 'linux', by default build will be 'true', right, so will it try to build the driver in that case?
What about setting "build = false" before the linux check, so won't need to set it false again in the if block, only set it true if dependencies found?

This is a good catch, we do need to initialize build = false first, otherwise meson/ninja would just try to build af_xdp pmd if system is not linux, which is undesired. Do I need to send a separate patch for this so you can squash it into af_xdp pmd patch?

Quoted 6 lines
Quoted 1 line

And can 'ext_deps' go out of if block?

If we move ext_deps += bpf_dep out of if block and build system is not linux, there would be error "ERROR: Unknown variable "bpf_dep".", so we need either initialize bpf_dep (to value like NULL?) first or keep ext_deps += bpf_dep inside the if block, I'd prefer keep it as it is, what's you opinion?

Actually, a suggestion - rather than limiting the build to linux, why not just limit the build to the presence of libbpf, and not bother checking the OS?

/Bruce

#211 lore raw

Re: [dpdk-dev] [PATCH v11 1/1] net/af_xdp: introduce AF XDP PMD driver

Quoted 57 lines · Bruce Richardson
Quoted 56 lines · Ye Xiaolong

Hi, Ferruh

Quoted 37 lines · Ferruh Yigit
Quoted 11 lines · Xiaolong Ye

Add a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux. More info about AF_XDP, please refer to [1] [2].

This is the vanilla version PMD which just uses a raw buffer registered as the umem.

[1] https://fosdem.org/2018/schedule/event/af_xdp/
[2] https://lwn.net/Articles/745934/

<...>

Quoted 22 lines
drivers/net/af_xdp/meson.build new file +16 -0
new file mode 100644
index 000000000..840c93728
@@ -0,0 +1,19 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+if host_machine.system() == 'linux'
+	bpf_dep = dependency('libbpf', required: false)
+	if bpf_dep.found()
+		build = true
+	else
+		bpf_dep = cc.find_library('bpf', required: false)
+		if bpf_dep.found() and cc.has_header('bpf/xsk.h', dependencies: bpf_dep) and cc.has_header('linux/if_xdp.h')
+			build = true
+			pkgconfig_extra_libs += '-lbpf'
+		else
+			build = false
+		endif
+	endif
Quoted 8 lines

drivers/net/af_xdp/meson.build line 19

Quoted 3 lines
drivers/net/af_xdp/meson.build new file +3 -0
+	ext_deps += bpf_dep
+endif
+sources = files('rte_eth_af_xdp.c')

if system is not 'linux', by default build will be 'true', right, so will it try to build the driver in that case?
What about setting "build = false" before the linux check, so won't need to set it false again in the if block, only set it true if dependencies found?

This is a good catch, we do need to initialize build = false first, otherwise meson/ninja would just try to build af_xdp pmd if system is not linux, which is undesired. Do I need to send a separate patch for this so you can squash it into af_xdp pmd patch?

Quoted 1 line

And can 'ext_deps' go out of if block?

Quoted 8 lines
Quoted 4 lines

If we move ext_deps += bpf_dep out of if block and build system is not linux, there would be error "ERROR: Unknown variable "bpf_dep".", so we need either initialize bpf_dep (to value like NULL?) first or keep ext_deps += bpf_dep inside the if block, I'd prefer keep it as it is, what's you opinion?

Actually, a suggestion - rather than limiting the build to linux, why not just limit the build to the presence of libbpf, and not bother checking the OS?

If this won't cause a problem for other OS in case they have the library, I have no objection.

#212 lore raw

Re: [dpdk-dev] [PATCH v11 1/1] net/af_xdp: introduce AF XDP PMD driver

Quoted 63 lines · Ferruh Yigit
Quoted 62 lines · Bruce Richardson
Quoted 60 lines · Ye Xiaolong

Hi, Ferruh

Quoted 37 lines · Ferruh Yigit
Quoted 11 lines · Xiaolong Ye

Add a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux. More info about AF_XDP, please refer to [1] [2].

This is the vanilla version PMD which just uses a raw buffer registered as the umem.

[1] https://fosdem.org/2018/schedule/event/af_xdp/
[2] https://lwn.net/Articles/745934/

<...>

Quoted 22 lines
drivers/net/af_xdp/meson.build new file +16 -0
new file mode 100644
index 000000000..840c93728
@@ -0,0 +1,19 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+if host_machine.system() == 'linux'
+	bpf_dep = dependency('libbpf', required: false)
+	if bpf_dep.found()
+		build = true
+	else
+		bpf_dep = cc.find_library('bpf', required: false)
+		if bpf_dep.found() and cc.has_header('bpf/xsk.h', dependencies: bpf_dep) and cc.has_header('linux/if_xdp.h')
+			build = true
+			pkgconfig_extra_libs += '-lbpf'
+		else
+			build = false
+		endif
+	endif
Quoted 8 lines

drivers/net/af_xdp/meson.build line 19

Quoted 3 lines
drivers/net/af_xdp/meson.build new file +3 -0
+	ext_deps += bpf_dep
+endif
+sources = files('rte_eth_af_xdp.c')

if system is not 'linux', by default build will be 'true', right, so will it try to build the driver in that case?
What about setting "build = false" before the linux check, so won't need to set it false again in the if block, only set it true if dependencies found?

This is a good catch, we do need to initialize build = false first, otherwise meson/ninja would just try to build af_xdp pmd if system is not linux, which is undesired. Do I need to send a separate patch for this so you can squash it into af_xdp pmd patch?

Quoted 1 line

And can 'ext_deps' go out of if block?

If we move ext_deps += bpf_dep out of if block and build system is not linux, there would be error "ERROR: Unknown variable "bpf_dep".", so we need either initialize bpf_dep (to value like NULL?) first or keep ext_deps += bpf_dep inside the if block, I'd prefer keep it as it is, what's you opinion?

Quoted 7 lines
Quoted 3 lines

Actually, a suggestion - rather than limiting the build to linux, why not just limit the build to the presence of libbpf, and not bother checking the OS?

If this won't cause a problem for other OS in case they have the library, I have no objection.

Well, they shouldn't have, and we also check for the header file "linux/if_xdp.h", so I don't think an additional check for linux itself is required. Generally, I think it's better to check for the requirements of a driver directly, rather than assuming that only certain environments would ever have them.
Just sent my suggested patch: http://patches.dpdk.org/patch/52357/

/Bruce

Reviewed-by on the v11 series
#213 lore raw
In reply to Xiaolong Ye
Quoted 117 lines · Xiaolong Ye

Overview
========

This patchset adds a new PMD driver for AF_XDP which is a proposed faster version of AF_PACKET interface in Linux, see below links [1] [2] for details of AF_XDP introduction:

AF_XDP roadmap
==============
- AF_XDP is included in upstream kernel since 4.18, and AF_XDP support in libbpf has been merged in v5.1-rc1.
- Now i40e and ixgbe drivers have supported zero copy mode.

Change logs
===========
v11:

- fix the meson build issue

v10:

- refine the Makefile, remove RTE_KERNELDIR related CFLAGS
- add a new internal file af_xdp_deps.h to handle the dependency for asm/barrier.h
- fix a typo observed by Stephen
- rename xsk.h to bpf/xsk.h as xsk.h is assumed to be installed in /usr/local/include/bpf
- add libbpf build steps in af_xdp.rst

v9:
- adjust header files order according to Stephen's suggestion

v8:
- address Ferruh's comments on V7
- replace posix_memalign with rte_memzone_reserve_aligned to get better performance
- keep the first patch only as Oliver suggested as zero copy part implementation is still in suspense, we may provide the related patch later.

v7:
- mention mtu limitation in af_xdp.rst
- fix the vdev name in af_xdp.rst

V6:

- remove the newline in AF_XDP_LOG definition to avoid double new lines issue.
- rename MEMPOOL_F_PAGE_ALIGN to MEMPOOL_CHUNK_F_PAGE_ALIGN.

V5:

- disable AF_XDP pmd by default due to it requires kernel more recent than minimum kernel version supported by DPDK
- address other review comments of Maxime

V4:

- change vdev name to net_af_xdp
- adopt dynamic log type for all logging
- Fix other style issues raised by Stephen

V3:

- Fix all style issues pointed by Stephen, Mattias, David.
- Drop the testpmd change as we'll adopt Jerin's suggestion to add a new mempool driver to handle the application use of AF_XDP's zero copy feature.

V2:
- Fix a NULL pointer reference crash issue
- Fix txonly stop sending traffic in zc mode
- Refactor rte_mbuf.c to avoid ABI breakage.
- Fix multiple style issues pointed by Ferruh, David, Stephen, Luca.

changes vs RFC sent by Qi last Aug:

- Re-work base on AF_XDP's interface changes since the new libbpf has provided higher-level APIs that hide many of the details of the AP_XDP uapi. After the rework, it helps to reduce 300+ lines of code.

- multi-queues is not supported due to current libbpf doesn't support multi-sockets on a single umem.

- No extra steps to load xdp program manually, since the current behavior of libbpf would load a default xdp program when user calls xsk_socket__create. userspace application only needs to handle the cleanup.

How to try
==========

1. take the kernel >= v5.1-rc1, build kernel and replace your host kernel with it.

make sure you turn on XDP sockets when compiling

   Networking support -->
        Networking options -->
                [ * ] XDP sockets

2. build & install libbpf in tools/lib/bpf

cd tools/lib/bpf
make install_lib
make install_headers

3. ethtool -L enp59s0f0 combined 1

4. extra step to build dpdk

explicitly enable AF_XDP pmd by adding below line to config/common_linux

CONFIG_RTE_LIBRTE_PMD_AF_XDP=y

5. start testpmd

Quoted 7 lines
   ./build/app/testpmd -c 0xc -n 4 --vdev net_af_xdp,iface=enp59s0f0,queue=0 -- -i --rxq=1 --txq=1

in this case, default xdp program will be loaded and linked to queue 0 of enp59s0f0, network traffics travel to queue 0 will be redirected to af_xdp socket.

Xiaolong Ye (1):
net/af_xdp: introduce AF XDP PMD driver