Skip to contentSkip to conversation

net/af_xdp: shared UMEM support

PATCH Superseded Ciara Loftus 2 participants 5 messages Sep 7, 2020 – Sep 17, 2020

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover net/af_xdp: shared UMEM support

This patch integrates support for shared UMEMs into the AF_XDP PMD. The feature is currently available in the linux-next tree [1] and should be available in the v5.10 kernel.

Detailed information on the shared UMEM feature can be found in the kernel documentation.

Support for the kernel feature is detected in DPDK by querying the LINUX_KERNEL_VERSION and ensuring a kernel >= 5.10.0. Since this kernel is not yet released, if one wishes to test this patch now it is suggested to use the aforementioned linux-next tree and modify the version check to align with the version of that tree. Once the kernel is released (~December) this will no longer be necessary.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=acabf32805f7

Ciara Loftus (1):
net/af_xdp: shared UMEM support

 doc/guides/nics/af_xdp.rst          |   6 +-
 drivers/net/af_xdp/compat.h         |  10 +
 drivers/net/af_xdp/meson.build      |   4 +
 drivers/net/af_xdp/rte_eth_af_xdp.c | 307 ++++++++++++++++++++++------
 4 files changed, 260 insertions(+), 67 deletions(-)
 create mode 100644 drivers/net/af_xdp/compat.h
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 net/af_xdp: shared UMEM support

Kernel v5.10 will introduce the ability to efficiently share a UMEM between AF_XDP sockets bound to different queue ids on the same or different devices. This patch integrates that functionality into the AF_XDP PMD.

A PMD will attempt to share a UMEM with others if the shared_umem=1 vdev arg is set. UMEMs can only be shared across PMDs with the same mempool, up to a limited number of PMDs goverened by the size of the given mempool. Sharing UMEMs is not supported for non-zero-copy (aligned) mode.

The benefit of sharing UMEM across PMDs is a saving in memory due to not having to register the UMEM multiple times. Throughput was measured to remain within 2% of the default mode (not sharing UMEM).

A version of libbpf >= v0.2.0 is required and the appropriate pkg-config file for libbpf must be installed such that meson can determine the version.

---
 doc/guides/nics/af_xdp.rst          |   6 +-
 drivers/net/af_xdp/compat.h         |  10 +
 drivers/net/af_xdp/meson.build      |   4 +
 drivers/net/af_xdp/rte_eth_af_xdp.c | 307 ++++++++++++++++++++++------
 4 files changed, 260 insertions(+), 67 deletions(-)
 create mode 100644 drivers/net/af_xdp/compat.h
doc/guides/nics/af_xdp.rst +5 -1
index 07bdd29e29..d22e2c9fa8 100644
@@ -1,5 +1,5 @@
 ..  SPDX-License-Identifier: BSD-3-Clause
-    Copyright(c) 2019 Intel Corporation.
+    Copyright(c) 2020 Intel Corporation.
 
 AF_XDP Poll Mode Driver
 ==========================
@@ -32,6 +32,8 @@ The following options can be provided to set up an af_xdp port in DPDK.
 *   ``iface`` - name of the Kernel interface to attach to (required);
 *   ``start_queue`` - starting netdev queue id (optional, default 0);
 *   ``queue_count`` - total netdev queue number (optional, default 1);
+*   ``shared_umem`` - PMD will attempt to share UMEM with others (optional,
+    default 0);
 
 Prerequisites
 -------------
@@ -45,6 +47,8 @@ This is a Linux-specific PMD, thus the following prerequisites apply:
 *  A Kernel bound interface to attach to;
 *  For need_wakeup feature, it requires kernel version later than v5.3-rc1;
 *  For PMD zero copy, it requires kernel version later than v5.4-rc1;
+*  For shared_umem, it requires kernel version v5.10 or later and libbpf version
+   v0.2.0 or later.
 
 Set up an af_xdp interface
 -----------------------------
drivers/net/af_xdp/compat.h new file +10 -0
new file mode 100644
index 0000000000..7a3e825d8f
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2020 Intel Corporation.
+ */
+
+#include <linux/version.h>
+
+#if KERNEL_VERSION(5, 10, 0) <= LINUX_VERSION_CODE && \
+	defined(RTE_LIBRTE_AF_XDP_PMD_SHARED_UMEM)
+#define ETH_AF_XDP_SHARED_UMEM 1
+#endif
drivers/net/af_xdp/meson.build +4 -0
index 307aa0e388..fead8dd99f 100644
@@ -10,6 +10,10 @@ endif
 
 if bpf_dep.found() and cc.has_header('bpf/xsk.h') and cc.has_header('linux/if_xdp.h')
 	ext_deps += bpf_dep
+	bpf_ver_dep = dependency('libbpf', version : '>=0.2.0', required: false)
+	if bpf_ver_dep.found()
+		dpdk_conf.set('RTE_LIBRTE_AF_XDP_PMD_SHARED_UMEM', 1)
+	endif
 else
 	build = false
 	reason = 'missing dependency, "libbpf"'
drivers/net/af_xdp/rte_eth_af_xdp.c +241 -66

587 lines not on this page · raw message

Signature · 1 line
2.17.1
#2 lore raw
Quoted 27 lines

-----Original Message-----
From: Loftus, Ciara <[email protected]>
Sent: Monday 7 September 2020 17:16
To: [email protected]
Cc: Loftus, Ciara <[email protected]>
Subject: [PATCH 1/1] net/af_xdp: shared UMEM support

Kernel v5.10 will introduce the ability to efficiently share a UMEM between AF_XDP sockets bound to different queue ids on the same or different devices. This patch integrates that functionality into the AF_XDP PMD.

A PMD will attempt to share a UMEM with others if the shared_umem=1 vdev arg is set. UMEMs can only be shared across PMDs with the same mempool, up to a limited number of PMDs goverened by the size of the given mempool.
Sharing UMEMs is not supported for non-zero-copy (aligned) mode.

The benefit of sharing UMEM across PMDs is a saving in memory due to not having to register the UMEM multiple times. Throughput was measured to remain within 2% of the default mode (not sharing UMEM).

A version of libbpf >= v0.2.0 is required and the appropriate pkg-config file for libbpf must be installed such that meson can determine the version.

<snip>

drivers/net/af_xdp/rte_eth_af_xdp.c static const struct rte_eth_link pmd_link = { · line 166

Quoted 12 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +11 -0
+/* List which tracks PMDs to facilitate sharing UMEMs across them. */
+struct internal_list {
+	TAILQ_ENTRY(internal_list) next;
+	struct rte_eth_dev *eth_dev;
+};
+
+TAILQ_HEAD(internal_list_head, internal_list); static struct
+internal_list_head internal_list =
+	TAILQ_HEAD_INITIALIZER(internal_list);
+
+static pthread_mutex_t internal_list_lock = PTHREAD_MUTEX_INITIALIZER;

[Tahhan, Maryam] do multiple threads typically initialize and ethdev/invoke the underlying driver?
Most apps I've seen initialize the ports one after the other in the starting thread - so if there's not multiple threads doing initialization - we may want to consider removing this mutex... Or maybe do you see something potentially removing a port while a port is being added?

<snip>

#3 lore raw
Quoted 36 lines
Quoted 19 lines

Kernel v5.10 will introduce the ability to efficiently share a UMEM between AF_XDP sockets bound to different queue ids on the same or different devices. This patch integrates that functionality into the AF_XDP PMD.

A PMD will attempt to share a UMEM with others if the shared_umem=1 vdev arg is set. UMEMs can only be shared across PMDs with the same mempool, up to a limited number of PMDs goverened by the size of the given mempool.
Sharing UMEMs is not supported for non-zero-copy (aligned) mode.

The benefit of sharing UMEM across PMDs is a saving in memory due to not having to register the UMEM multiple times. Throughput was measured to remain within 2% of the default mode (not sharing UMEM).

A version of libbpf >= v0.2.0 is required and the appropriate pkg-config file for libbpf must be installed such that meson can determine the version.

<snip>

drivers/net/af_xdp/rte_eth_af_xdp.c static const struct rte_eth_link pmd_link = {

Quoted 12 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +11 -0
+/* List which tracks PMDs to facilitate sharing UMEMs across them. */
+struct internal_list {
+TAILQ_ENTRY(internal_list) next;
+struct rte_eth_dev *eth_dev;
+};
+
+TAILQ_HEAD(internal_list_head, internal_list); static struct
+internal_list_head internal_list =
+TAILQ_HEAD_INITIALIZER(internal_list);
+
+static pthread_mutex_t internal_list_lock =

PTHREAD_MUTEX_INITIALIZER;

Quoted 7 lines

[Tahhan, Maryam] do multiple threads typically initialize and ethdev/invoke the underlying driver?
Most apps I've seen initialize the ports one after the other in the starting thread - so if there's not multiple threads doing initialization - we may want to consider removing this mutex...
Or maybe do you see something potentially removing a port while a port is being added?

Hi Maryam,

Yes. Although unlikely, I'm not aware of any guarantee that a port A cannot be removed when port B is being added and since both operations can touch the tailq I'm inclined to keep the mutex. But I'm open to correction.

Thanks,
Ciara

Quoted 2 lines

<snip>

#4 lore raw
Quoted 55 lines

-----Original Message-----
From: Loftus, Ciara <[email protected]>
Sent: Thursday 17 September 2020 09:55
To: Tahhan, Maryam <[email protected]>
Cc: [email protected]
Subject: RE: [PATCH 1/1] net/af_xdp: shared UMEM support

Quoted 4 lines
Quoted 4 lines

Kernel v5.10 will introduce the ability to efficiently share a UMEM between AF_XDP sockets bound to different queue ids on the same or different devices. This patch integrates that functionality into the AF_XDP

PMD.

Quoted 7 lines
Quoted 7 lines

A PMD will attempt to share a UMEM with others if the shared_umem=1 vdev arg is set. UMEMs can only be shared across PMDs with the same mempool, up to a limited number of PMDs goverened by the size of the given mempool.
Sharing UMEMs is not supported for non-zero-copy (aligned) mode.

Quoted 6 lines
Quoted 6 lines

The benefit of sharing UMEM across PMDs is a saving in memory due to not having to register the UMEM multiple times. Throughput was measured to remain within 2% of the default mode (not sharing UMEM).

A version of libbpf >= v0.2.0 is required and the appropriate pkg-config file for libbpf must be installed such that meson can determine

the version.

Quoted 19 lines
Quoted 2 lines

<snip>

drivers/net/af_xdp/rte_eth_af_xdp.c static const struct rte_eth_link pmd_link = {

Quoted 12 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +11 -0
+/* List which tracks PMDs to facilitate sharing UMEMs across them.
+*/ struct internal_list {
+TAILQ_ENTRY(internal_list) next;
+struct rte_eth_dev *eth_dev;
+};
+
+TAILQ_HEAD(internal_list_head, internal_list); static struct
+internal_list_head internal_list =
+TAILQ_HEAD_INITIALIZER(internal_list);
+
+static pthread_mutex_t internal_list_lock =

PTHREAD_MUTEX_INITIALIZER;

Quoted 7 lines

[Tahhan, Maryam] do multiple threads typically initialize and ethdev/invoke the underlying driver?
Most apps I've seen initialize the ports one after the other in the starting thread - so if there's not multiple threads doing initialization - we may want to consider removing this mutex... Or maybe do you see something potentially removing a port while a port is being added?

Quoted 9 lines

Hi Maryam,

Yes. Although unlikely, I'm not aware of any guarantee that a port A cannot be removed when port B is being added and since both operations can touch the tailq I'm inclined to keep the mutex. But I'm open to correction.

Thanks,
Ciara

No worries :) better to be safe than sorry

Quoted 3 lines
Quoted 2 lines

<snip>