Introducing AF_XDP support
Subsystems (12)
cover Introducing AF_XDP support
From: Björn Töpel <[email protected]>
This RFC introduces a new address family called AF_XDP that is optimized for high performance packet processing and zero-copy semantics. Throughput improvements can be up to 20x compared to V2 and V3 for the micro benchmarks included. Would be great to get your feedback on it. Note that this is the follow up RFC to AF_PACKET V4 from November last year. The feedback from that RFC submission and the presentation at NetdevConf in Seoul was to create a new address family instead of building on top of AF_PACKET. AF_XDP is this new address family.
The main difference between AF_XDP and AF_PACKET V2/V3 on a descriptor level is that TX and RX descriptors are separated from packet buffers. An RX or TX descriptor points to a data buffer in a packet buffer area. RX and TX can share the same packet buffer so that a packet does not have to be copied between RX and TX. Moreover, if a packet needs to be kept for a while due to a possible retransmit, then the descriptor that points to that packet buffer can be changed to point to another buffer and reused right away. This again avoids copying data.
The RX and TX descriptor rings are registered with the setsockopts XDP_RX_RING and XDP_TX_RING, similar to AF_PACKET. The packet buffer area is allocated by user space and registered with the kernel using the new XDP_MEM_REG setsockopt. All these three areas are shared between user space and kernel space. The socket is then bound with a bind() call to a device and a specific queue id on that device, and it is not until bind is completed that traffic starts to flow.
An XDP program can be loaded to direct part of the traffic on that device and queue id to user space through a new redirect action in an XDP program called bpf_xdpsk_redirect that redirects a packet up to the socket in user space. All the other XDP actions work just as before. Note that the current RFC requires the user to load an XDP program to get any traffic to user space (for example all traffic to user space with the one-liner program "return bpf_xdpsk_redirect();"). We plan on introducing a patch that removes this requirement and sends all traffic from a queue to user space if an AF_XDP socket is bound to it.
AF_XDP can operate in three different modes: XDP_SKB, XDP_DRV, and XDP_DRV_ZC (shorthand for XDP_DRV with a zero-copy allocator as there is no specific mode called XDP_DRV_ZC). If the driver does not have support for XDP, or XDP_SKB is explicitly chosen when loading the XDP program, XDP_SKB mode is employed that uses SKBs together with the generic XDP support and copies out the data to user space. A fallback mode that works for any network device. On the other hand, if the driver has support for XDP (all three NDOs: ndo_bpf, ndo_xdp_xmit and ndo_xdp_flush), these NDOs, without any modifications, will be used by the AF_XDP code to provide better performance, but there is still a copy of the data into user space. The last mode, XDP_DRV_ZC, is XDP driver support with the zero-copy user space allocator that provides even better performance. In this mode, the networking HW (or SW driver if it is a virtual driver like veth) DMAs/puts packets straight into the packet buffer that is shared between user space and kernel space. The RX and TX descriptor queues of the networking HW are NOT shared to user space. Only the kernel can read and write these and it is the kernel driver's responsibility to translate these HW specific descriptors to the HW agnostic ones in the virtual descriptor rings that user space sees. This way, a malicious user space program cannot mess with the networking HW. This mode though requires some extensions to XDP.
To get the XDP_DRV_ZC mode to work for RX, we chose to introduce a buffer pool concept so that the same XDP driver code can be used for buffers allocated using the page allocator (XDP_DRV), the user-space zero-copy allocator (XDP_DRV_ZC), or some internal driver specific allocator/cache/recycling mechanism. The ndo_bpf call has also been extended with two commands for registering and unregistering an XSK socket and is in the RX case mainly used to communicate some information about the user-space buffer pool to the driver.
For the TX path, our plan was to use ndo_xdp_xmit and ndo_xdp_flush, but we run into problems with this (further discussion in the challenges section) and had to introduce a new NDO called ndo_xdp_xmit_xsk (xsk = XDP socket). It takes a pointer to a netdevice and an explicit queue id that packets should be sent out on. In contrast to ndo_xdp_xmit, it is asynchronous and pulls packets to be sent from the xdp socket (associated with the dev and queue combination that was provided with the NDO call) using a callback (get_tx_packet), and when they have been transmitted it uses another callback (tx_completion) to signal completion of packets. These callbacks are set via ndo_bpf in the new XDP_REGISTER_XSK command. ndo_xdp_xmit_xsk is exclusively used by the XDP socket code and thus does not clash with the XDP_REDIRECT use of ndo_xdp_xmit. This is one of the reasons that the XDP_DRV mode (without ZC) is currently not supported by TX. Please have a look at the challenges section for further discussions.
The AF_XDP bind call acts on a queue pair (channel in ethtool speak), so the user needs to steer the traffic to the zero-copy enabled queue pair. Which queue to use, is up to the user.
For an untrusted application, HW packet steering to a specific queue pair (the one associated with the application) is a requirement, as the application would otherwise be able to see other user space processes' packets. If the HW cannot support the required packet steering, XDP_DRV or XDP_SKB mode have to be used as they do not expose the NIC's packet buffer into user space as the packets are copied into user space from the NIC's packet buffer in the kernel.
There is a xdpsock benchmarking/test application included. Say that you would like your UDP traffic from port 4242 to end up in queue 16, that we will enable AF_XDP on. Here, we use ethtool for this:
ethtool -N p3p2 rx-flow-hash udp4 fn
ethtool -N p3p2 flow-type udp4 src-port 4242 dst-port 4242 \
action 16
Running the l2fwd benchmark in XDP_DRV_ZC mode can then be done using:
samples/bpf/xdpsock -i p3p2 -q 16 -l -N
For XDP_SKB mode, use the switch "-S" instead of "-N" and all options can be displayed with "-h", as usual.
We have run some benchmarks on a dual socket system with two Broadwell E5 2660 @ 2.0 GHz with hyperthreading turned off. Each socket has 14 cores which gives a total of 28, but only two cores are used in these experiments. One for TR/RX and one for the user space application. The memory is DDR4 @ 2133 MT/s (1067 MHz) and the size of each DIMM is 8192MB and with 8 of those DIMMs in the system we have 64 GB of total memory. The compiler used is gcc version 5.4.0 20160609. The NIC is an Intel I40E 40Gbit/s using the i40e driver.
Below are the results in Mpps of the I40E NIC benchmark runs for 64 byte packets, generated by commercial packet generator HW that is generating packets at full 40 Gbit/s line rate.
XDP baseline numbers without this RFC:xdp_rxq_info --action XDP_DROP 31.3 Mppsxdp_rxq_info --action XDP_TX 16.7 Mpps
XDP performance with this RFC i.e. with the buffer allocator:XDP_DROP 21.0 MppsXDP_TX 11.9 Mpps
AF_PACKET V4 performance from previous RFC on 4.14-rc7:
Benchmark V2 V3 V4 V4+ZC rxdrop 0.67 0.73 0.74 33.7 txpush 0.98 0.98 0.91 19.6 l2fwd 0.66 0.71 0.67 15.5
AF_XDP performance:
Benchmark XDP_SKB XDP_DRV XDP_DRV_ZC (all in Mpps) rxdrop 3.3 11.6 16.9 txpush 2.2 NA* 21.8 l2fwd 1.7 NA* 10.4
* NA since there is no XDP_DRV mode (without ZC) for TX in this RFC, see challenges below.
If we start by comparing XDP_SKB performance with copy mode in AF_PACKET V4, we can see that AF_XDP delivers 3-5 times the throughput, which is positive. We are also happy with the XDP_DRV performance that provides 11.6 Mpps for rxdrop, and should work on any driver implementing full XDP support. Now to the problematic part:XDP_DRV_ZC. The txpush (TX only) benchmark shows decent results at 21.8 Mpps and is better than it was for V4, even though we have spent no time optimizing the code in AF_XDP. (We did that in AF_PACKET V4.) But the RX performance is sliced by half, which is not good. The reason for this is, for the major part, the new buffer allocator which is used for RX ZC only (at this point, see todo section). If you take a look at the XDP baseline numbers, introducing the buffer pool allocator drops the performance by around 30% or 10 Mpps which is obviously not acceptable. We clearly need to give this code some overdue performance love. But the overhanging question is how much overhead it will produce in the end and if this will be acceptable. Another thing to note is that V4 provided 33.7 Mpps for rxdrop, but with AF_XDP we are quite unlikely to get above the XDP_DROP number of 31.3, since we are reusing the XDP infrastructure and driver code on the RX side. So in the end, the AF_XDP XDP_DRV_ZC numbers will likely be lower than the V4 ZC numbers.
We based this patch set on net-next commit 91e6dd828425 ("ipmr: Fix ptrdiff_t print formatting").
Challenges: areas we would really appreciate your help on and that we are having substantial problems with.
* We would like to, if possible, use ndo_xdp_xmit and ndo_xdp_flush instead of introducing another NDO in the form of ndo_xdp_xmit_xsk. The first reason behind our ineptitude to be able to accomplish this is that if both paths use ndo_xdp_xmit, they will create a race as ndo_xdp_xmit currently does not contain any locking. How to implement some type of mutual exclusion here without resorting to slowing down the NDO with a lock? The second problem is that the XDP_REDIRECT code implicitly assumes that core id = queue id. AF_XDP, on the other hand, explicitly specifies a queue id that has nothing to do with the core id (the application can run on any core). How to reconcile these two views in one ndo? If these two problems can be solved, then we would still need to introduce a completion callback and a get_packet callback, but this seems to be less challenging. This would also make it possible to run TX in the XDP_DRV mode (with the default page allocator).
* What should the buffer allocator look like and how to make it generic enough so it can be used by all NIC vendors? Would be great if you could take a look at it and come with suggestions. As you can see from the change log, it took some effort to rewire the i40e code to use the buff pool, and we expect the same to be true for many other NICs. Ideas on how to introduce multiple allocator into XDP in a less intrusive way would be highly appreciated. Another question is how to create a buffer pool that gives rise to very little overhead? We do not know if the current one can be optimized to have an acceptable overhead as we have not started any optimization effort. But we will give it a try during the next week or so to see where it leads.
* In this RFC, do not use an XDP_REDIRECT action other than bpf_xdpsk_redirect for XDP_DRV_ZC. This is because a zero-copy allocated buffer will then be sent to a cpu id / queue_pair through ndo_xdp_xmit that does not know this has been ZC allocated. It will then do a page_free on it and you will get a crash. How to extend ndo_xdp_xmit with some free/completion function that could be called instead of page_free? Hopefully, the same solution can be used here as in the first problem item in this section.
Caveats with this RFC. In contrast to the last section, we believe we have solutions for these but we did not have time to fix them. We chose to show you all the code sooner than later, even though everything does not work. Sorry.
* This RFC is more immature (read, has more bugs) than the AF_PACKET V4 RFC. Some known mentioned here, others unknown.
* We have done absolutely no optimization to this RFC. There is (hopefully) some substantial low hanging fruit that we could fix once we get to this, to improve XDP_DRV_ZC performance to levels that we are not ashamed of and also bring the i40e driver to the same performance levels it had before our changes, which is a must.
* There is a race in the TX XSK clean up code in the i40e driver that triggers a WARN_ON_ONCE. Clearly a bug that needs to be fixed. It can be triggered by performing ifdown/ifup when the application is running, or when changing the number of queues of the device underneath the hood of the application. As a workaround, please refrain from doing these two things without restarting the application, as not all buffers will be returned in the TX path. This bug can also be triggered when killing the application, but has no negative effect in this case as the process will never execute again.
* Before this RFC, ndo_xdp_xmit triggered by an XDP_REDIRECT to a NIC never modified the page count, so the redirect code could assume that the page would still be valid after the NDO call. With the introduction of the xsk_rcv path that is called as a result of an XDP_REDIRECT to an AF_XDP socket, the page count will be decreased if the page is copied out to user space, since we have no use for it anymore. Our somewhat blunt solution to this is to make sure in the i40e driver that the refcount is never under two. Note though, that with the introduction of the buffer pool, this problem disappears. This also means that XDP_DRV will not work out of the box with a Niantic NIC, since it also needs this modification to work. One question that we have is what should the semantics of ndo_xdp_xmit be? Can we always assume that the page count will never be changed by all possible netdevices that implement this NDO, or should we remove this assumption to gain more device implementation flexibility?
To do:
* Optimize performance. No optimization whatsoever was performed on this RFC, in contrast to the previous one for AF_PACKET V4.
* Kernel load module support.
* Polling has not been implemented yet.
* Optimize the user space sample application. It is simple but naive at this point. The one for AF_PACKET V4 had a number of optimizations that have not been introduced in the AF_XDP version.
* Implement a way to pick the XDP_DRV mode even if XDP_DRV_ZC is available. Would be nice to have for the sample application too.
* Introduce a notifier chain for queue changes (caused by ethtool for example). This would get rid of the error callback that we have at this point.
* Use one NAPI context for RX and another one for TX in i40e. This would make it possible to run RX on one core and TX on another for better performance. Today, they need to share a single core since they share NAPI context.
* Get rid of packet arrays (PA) and convert them to the buffer pool allocator by transferring the necessary PA functionality into the buffer pool. This has only been done for RX in ZC mode, while all the other modes are still using packet arrays. Clearly, having two structures with largely the same information is not a good thing.
* Support for AF_XDP sockets without an XPD program loaded. In this case all the traffic on a queue should go up to user space.
* Support shared packet buffers
* Support for packets spanning multiple frames
Thanks: Björn and Magnus
Björn Töpel (16):
xsk: AF_XDP sockets buildable skeleton
xsk: add user memory registration sockopt
xsk: added XDP_{R,T}X_RING sockopt and supporting structures
bpf: added bpf_xdpsk_redirect
net: wire up xsk support in the XDP_REDIRECT path
i40e: add support for XDP_REDIRECT
samples/bpf: added xdpsock program
xsk: add iterator functions to xsk_ring
i40e: introduce external allocator support
i40e: implemented page recycling buff_pool
i40e: start using recycling buff_pool
i40e: separated buff_pool interface from i40e implementaion
xsk: introduce xsk_buff_pool
xdp: added buff_pool support to struct xdp_buff
xsk: add support for zero copy Rx
i40e: implement xsk sub-commands in ndo_bpf for zero copy Rx
Magnus Karlsson (8):
xsk: add bind support and introduce Rx functionality
xsk: introduce Tx functionality
netdevice: added XDP_{UN,}REGISTER_XSK command to ndo_bpf
netdevice: added ndo for transmitting a packet from an XDP socket
xsk: add support for zero copy Tx
i40e: introduced a clean_tx callback function
i40e: introduced Tx completion callbacks
i40e: Tx support for zero copy allocator
drivers/net/ethernet/intel/i40e/Makefile | 3 +- drivers/net/ethernet/intel/i40e/i40e.h | 24 + drivers/net/ethernet/intel/i40e/i40e_buff_pool.c | 580 +++++++++++ drivers/net/ethernet/intel/i40e/i40e_buff_pool.h | 15 + drivers/net/ethernet/intel/i40e/i40e_ethtool.c | 1 - drivers/net/ethernet/intel/i40e/i40e_main.c | 541 +++++++++- drivers/net/ethernet/intel/i40e/i40e_txrx.c | 906 +++++++++-------- drivers/net/ethernet/intel/i40e/i40e_txrx.h | 119 ++- include/linux/buff_pool.h | 136 +++ include/linux/filter.h | 3 +- include/linux/netdevice.h | 25 + include/linux/socket.h | 5 +- include/net/xdp.h | 1 + include/net/xdp_sock.h | 60 ++ include/uapi/linux/bpf.h | 6 +- include/uapi/linux/if_xdp.h | 72 ++ net/Kconfig | 1 + net/Makefile | 1 + net/core/dev.c | 28 +- net/core/filter.c | 88 +- net/core/sock.c | 12 +- net/xdp/Kconfig | 7 + net/xdp/Makefile | 1 + net/xdp/xsk.c | 1142 ++++++++++++++++++++++ net/xdp/xsk.h | 31 + net/xdp/xsk_buff.h | 161 +++ net/xdp/xsk_buff_pool.c | 225 +++++ net/xdp/xsk_buff_pool.h | 17 + net/xdp/xsk_packet_array.c | 62 ++ net/xdp/xsk_packet_array.h | 399 ++++++++ net/xdp/xsk_ring.c | 61 ++ net/xdp/xsk_ring.h | 419 ++++++++ net/xdp/xsk_user_queue.h | 24 + samples/bpf/Makefile | 4 + samples/bpf/xdpsock_kern.c | 11 + samples/bpf/xdpsock_queue.h | 62 ++ samples/bpf/xdpsock_user.c | 642 ++++++++++++ security/selinux/hooks.c | 4 +- security/selinux/include/classmap.h | 4 +- tools/testing/selftests/bpf/bpf_helpers.h | 2 + 40 files changed, 5408 insertions(+), 497 deletions(-) create mode 100644 drivers/net/ethernet/intel/i40e/i40e_buff_pool.c create mode 100644 drivers/net/ethernet/intel/i40e/i40e_buff_pool.h create mode 100644 include/linux/buff_pool.h create mode 100644 include/net/xdp_sock.h create mode 100644 include/uapi/linux/if_xdp.h create mode 100644 net/xdp/Kconfig create mode 100644 net/xdp/Makefile create mode 100644 net/xdp/xsk.c create mode 100644 net/xdp/xsk.h create mode 100644 net/xdp/xsk_buff.h create mode 100644 net/xdp/xsk_buff_pool.c create mode 100644 net/xdp/xsk_buff_pool.h create mode 100644 net/xdp/xsk_packet_array.c create mode 100644 net/xdp/xsk_packet_array.h create mode 100644 net/xdp/xsk_ring.c create mode 100644 net/xdp/xsk_ring.h create mode 100644 net/xdp/xsk_user_queue.h create mode 100644 samples/bpf/xdpsock_kern.c create mode 100644 samples/bpf/xdpsock_queue.h create mode 100644 samples/bpf/xdpsock_user.c
Signature · 1 line
2.14.1
RFC PATCH 1/24 xsk: AF_XDP sockets buildable skeleton
From: Björn Töpel <[email protected]>
Buildable skeleton. Move on, nothing to see.
--- include/linux/socket.h | 5 +- include/uapi/linux/if_xdp.h | 32 +++++++++ net/Kconfig | 1 + net/Makefile | 1 + net/core/sock.c | 12 ++-- net/xdp/Kconfig | 7 ++ net/xdp/Makefile | 1 + net/xdp/xsk.c | 133 ++++++++++++++++++++++++++++++++++++ net/xdp/xsk.h | 18 +++++ security/selinux/hooks.c | 4 +- security/selinux/include/classmap.h | 4 +- 11 files changed, 211 insertions(+), 7 deletions(-) create mode 100644 include/uapi/linux/if_xdp.h create mode 100644 net/xdp/Kconfig create mode 100644 net/xdp/Makefile create mode 100644 net/xdp/xsk.c create mode 100644 net/xdp/xsk.h
include/linux/socket.h +4 -1
@@ -207,8 +207,9 @@ struct ucred {* PF_SMC protocol family that * reuses AF_INET address family */ +#define AF_XDP 44/* XDP sockets */ -#define AF_MAX 44/* For now.. */ +#define AF_MAX 45/* For now.. */ /* Protocol families, same as address families. */ #define PF_UNSPEC AF_UNSPEC
@@ -257,6 +258,7 @@ struct ucred {#define PF_KCM AF_KCM#define PF_QIPCRTR AF_QIPCRTR#define PF_SMC AF_SMC +#define PF_XDP AF_XDP#define PF_MAX AF_MAX/* Maximum queue length specifiable by listen. */
@@ -337,6 +339,7 @@ struct ucred {#define SOL_NFC 280#define SOL_KCM 281#define SOL_TLS 282 +#define SOL_XDP 283/* IPX options */ #define IPX_TYPE 1
include/uapi/linux/if_xdp.h new file +32 -0
@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* +* if_xdp: XDP socket user-space interface +* +* Copyright(c) 2017 Intel Corporation. +* +* Author(s): Björn Töpel <[email protected]> +* Magnus Karlsson <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; version 2 +* of the License. +*/ + +#ifndef _LINUX_IF_XDP_H +#define _LINUX_IF_XDP_H + +#include <linux/types.h> + +struct sockaddr_xdp { +__u16 sxdp_family; +__u32 sxdp_ifindex; +__u32 sxdp_queue_id; +}; + +/* XDP socket options */ +#define XDP_MEM_REG 1 +#define XDP_RX_RING 2 +#define XDP_TX_RING 3 + +#endif /* _LINUX_IF_XDP_H */
net/Kconfig +1 -0
@@ -59,6 +59,7 @@ source "net/tls/Kconfig" source "net/xfrm/Kconfig" source "net/iucv/Kconfig" source "net/smc/Kconfig" +source "net/xdp/Kconfig" config INET bool "TCP/IP networking"
net/Makefile +1 -0
@@ -86,3 +86,4 @@ obj-y += l3mdev/ endif obj-$(CONFIG_QRTR) += qrtr/ obj-$(CONFIG_NET_NCSI) += ncsi/ +obj-$(CONFIG_XDP_SOCKETS) += xdp/
net/core/sock.c +8 -4
@@ -226,7 +226,8 @@ static struct lock_class_key af_family_kern_slock_keys[AF_MAX]; x"AF_RXRPC" , x"AF_ISDN" , x"AF_PHONET" , \ x"AF_IEEE802154" , x"AF_CAIF" , x"AF_ALG" , \ x"AF_NFC" , x"AF_VSOCK" , x"AF_KCM" , \ - x"AF_QIPCRTR" , x"AF_SMC" , x"AF_MAX" + x"AF_QIPCRTR" , x"AF_SMC" , x"AF_XDP" , \ + x"AF_MAX" static const char *const af_family_key_strings[AF_MAX+1] = {_sock_locks ("sk_lock-" )
@@ -262,7 +263,8 @@ static const char *const af_family_rlock_key_strings[AF_MAX+1] = {"rlock-AF_RXRPC" ,"rlock-AF_ISDN" ,"rlock-AF_PHONET" ,"rlock-AF_IEEE802154" ,"rlock-AF_CAIF" ,"rlock-AF_ALG" ,"rlock-AF_NFC" ,"rlock-AF_VSOCK" ,"rlock-AF_KCM" , -"rlock-AF_QIPCRTR" ,"rlock-AF_SMC" ,"rlock-AF_MAX" +"rlock-AF_QIPCRTR" ,"rlock-AF_SMC" ,"rlock-AF_XDP" , +"rlock-AF_MAX" };static const char *const af_family_wlock_key_strings[AF_MAX +1 ] = { "wlock-AF_UNSPEC", "wlock-AF_UNIX" , "wlock-AF_INET" ,
@@ -279,7 +281,8 @@ static const char *const af_family_wlock_key_strings[AF_MAX+1] = {"wlock-AF_RXRPC" ,"wlock-AF_ISDN" ,"wlock-AF_PHONET" ,"wlock-AF_IEEE802154" ,"wlock-AF_CAIF" ,"wlock-AF_ALG" ,"wlock-AF_NFC" ,"wlock-AF_VSOCK" ,"wlock-AF_KCM" , -"wlock-AF_QIPCRTR" ,"wlock-AF_SMC" ,"wlock-AF_MAX" +"wlock-AF_QIPCRTR" ,"wlock-AF_SMC" ,"wlock-AF_XDP" , +"wlock-AF_MAX" };static const char *const af_family_elock_key_strings[AF_MAX +1 ] = { "elock-AF_UNSPEC", "elock-AF_UNIX" , "elock-AF_INET" ,
@@ -296,7 +299,8 @@ static const char *const af_family_elock_key_strings[AF_MAX+1] = {"elock-AF_RXRPC" ,"elock-AF_ISDN" ,"elock-AF_PHONET" ,"elock-AF_IEEE802154" ,"elock-AF_CAIF" ,"elock-AF_ALG" ,"elock-AF_NFC" ,"elock-AF_VSOCK" ,"elock-AF_KCM" , -"elock-AF_QIPCRTR" ,"elock-AF_SMC" ,"elock-AF_MAX" +"elock-AF_QIPCRTR" ,"elock-AF_SMC" ,"elock-AF_XDP" , +"elock-AF_MAX" };/*
net/xdp/Kconfig new file +7 -0
@@ -0,0 +1,7 @@ +config XDP_SOCKETS + bool "XDP sockets" + depends on BPF_SYSCALL + default n + help + XDP sockets allows a channel between XDP programs and + userspace applications.
net/xdp/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_XDP_SOCKETS) += xsk.o
net/xdp/xsk.c new file +133 -0
133 lines not on this page · raw message
net/xdp/xsk.h new file +18 -0
@@ -0,0 +1,18 @@ +/* +* XDP sockets +* Copyright(c) 2017 Intel Corporation. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +*/ + +#ifndef _LINUX_XDPSOCK_H +#define _LINUX_XDPSOCK_H + +#endif /* _LINUX_XDPSOCK_H */
security/selinux/hooks.c +3 -1
@@ -1436,7 +1436,9 @@ static inline u16 socket_type_to_security_class(int family, int type, int protocreturn SECCLASS_QIPCRTR_SOCKET ;case PF_SMC :return SECCLASS_SMC_SOCKET ; -#if PF_MAX >44 +case PF_XDP : +return SECCLASS_XDP_SOCKET ; +#if PF_MAX >45 #error New address family defined, please update this function.#endif }
security/selinux/include/classmap.h +3 -1
@@ -240,9 +240,11 @@ struct security_class_mapping secclass_map[] = { { "manage_subnet", NULL } }, {"bpf" , {"map_create", "map_read", "map_write", "prog_load", "prog_run"} }, + {"xdp_socket" , + { COMMON_SOCK_PERMS, NULL } }, { NULL } }; -#if PF_MAX >44 +#if PF_MAX >45 #error New address family defined, please update secclass_map.#endif
Signature · 1 line
2.14.1
RFC PATCH 2/24 xsk: add user memory registration sockopt
In reply to Björn TöpelFrom: Björn Töpel <[email protected]>
The XDP_MEM_REG socket option allows a process to register a window of user space memory to the kernel. This memory will later be used as frame data buffer.
--- include/uapi/linux/if_xdp.h | 7 ++ net/xdp/xsk.c | 294 +++++++++++++++++++++++++++++++++++++++++++- net/xdp/xsk.h | 19 ++- 3 files changed, 316 insertions(+), 4 deletions(-)
include/uapi/linux/if_xdp.h +7 -0
@@ -29,4 +29,11 @@ struct sockaddr_xdp {#define XDP_RX_RING 2#define XDP_TX_RING 3 +struct xdp_mr_req { +__u64 addr;/* Start of packet data area */ +__u64 len;/* Length of packet data area */ +__u32 frame_size;/* Frame size */ +__u32 data_headroom;/* Frame head room */ +}; +#endif /* _LINUX_IF_XDP_H */
net/xdp/xsk.c +293 -1
327 lines not on this page · raw message
net/xdp/xsk.h +16 -3
@@ -12,7 +12,20 @@* more details. */ -#ifndef _LINUX_XDPSOCK_H -#define _LINUX_XDPSOCK_H +#ifndef _LINUX_XSK_H +#define _LINUX_XSK_H -#endif /* _LINUX_XDPSOCK_H */ +#define XSK_KERNEL_HEADROOM 256/* Headrom for XDP */ + +struct xsk_umem { +struct pid *pid; +struct page **pgs; +unsigned long address; +size_t size; +u32 npgs; +u32 frame_size; +u32 nframes; +u32 data_headroom; +}; + +#endif /* _LINUX_XSK_H */
Signature · 1 line
2.14.1
Re: [RFC PATCH 02/24] xsk: add user memory registration sockopt
Quoted 42 lines · Björn Töpel
From: Björn Töpel <[email protected]>
The
XDP_MEM_REGsocket option allows a process to register a window of user space memory to the kernel. This memory will later be used as frame data buffer.Signed-off-by Björn Töpel <[email protected]>---
net/xdp/xsk.c +33
-0+static struct xsk_umem *xsk_mem_reg (u64 addr,u64 size,u32 frame_size, +u32 data_headroom) +{ +unsigned long lock_limit, locked, npages; +int ret =0 ; +struct xsk_umem *umem; + +if (!can_do_mlock ()) +return ERR_PTR (-EPERM ); + + umem =xsk_umem_create (addr, size, frame_size, data_headroom); +if (IS_ERR (umem)) +return umem; + + npages =PAGE_ALIGN (umem->nframes * umem->frame_size) >>PAGE_SHIFT ; + +down_write (¤t->mm->mmap_sem); + + locked = npages + current->mm->pinned_vm; + lock_limit =rlimit (RLIMIT_MEMLOCK ) >>PAGE_SHIFT ; + +if (locked > lock_limit && !capable (CAP_IPC_LOCK )) { + ret = -ENOMEM ; + goto out; + } + +if (npages ==0 || npages >UINT_MAX ) { + ret = -EINVAL ; + goto out; + } + umem->npgs = npages; + + ret =xsk_umem_pin_pages (umem);
net/xdp/xsk.c line 223
Quoted 10 lines
net/xdp/xsk.c +10
-0+ +out: +if (ret <0 ) { +put_pid (umem->pid); +kfree (umem); + }else { + current->mm->pinned_vm = locked; + } + +up_write (¤t->mm->mmap_sem);
This limits per process. You may want to limit per user. See also mm_account_pinned_pages.
Re: [RFC PATCH 02/24] xsk: add user memory registration sockopt
2018-02-07 17:00 GMT+01:00 Willem de Bruijn <[email protected]>:
Quoted 48 lines · Björn Töpel
Quoted 47 lines
From: Björn Töpel <[email protected]>
The
XDP_MEM_REGsocket option allows a process to register a window of user space memory to the kernel. This memory will later be used as frame data buffer.Signed-off-by Björn Töpel <[email protected]>---
net/xdp/xsk.c +38
-0+static struct xsk_umem *xsk_mem_reg (u64 addr,u64 size,u32 frame_size, +u32 data_headroom) +{ +unsigned long lock_limit, locked, npages; +int ret =0 ; +struct xsk_umem *umem; + +if (!can_do_mlock ()) +return ERR_PTR (-EPERM ); + + umem =xsk_umem_create (addr, size, frame_size, data_headroom); +if (IS_ERR (umem)) +return umem; + + npages =PAGE_ALIGN (umem->nframes * umem->frame_size) >>PAGE_SHIFT ; + +down_write (¤t->mm->mmap_sem); + + locked = npages + current->mm->pinned_vm; + lock_limit =rlimit (RLIMIT_MEMLOCK ) >>PAGE_SHIFT ; + +if (locked > lock_limit && !capable (CAP_IPC_LOCK )) { + ret = -ENOMEM ; + goto out; + } + +if (npages ==0 || npages >UINT_MAX ) { + ret = -EINVAL ; + goto out; + } + umem->npgs = npages; + + ret =xsk_umem_pin_pages (umem); + +out: +if (ret <0 ) { +put_pid (umem->pid); +kfree (umem);
Quoted 8 lines
net/xdp/xsk.c line 223
Quoted 5 lines
net/xdp/xsk.c +5
-0+ }else { + current->mm->pinned_vm = locked; + } + +up_write (¤t->mm->mmap_sem);This limits per process. You may want to limit per user. See also
mm_account_pinned_pages.
Ah, noted! Thanks for pointing that out!
RFC PATCH 3/24 xsk: added XDP_{R,T}X_RING sockopt and supporting structures
In reply to Björn TöpelFrom: Björn Töpel <[email protected]>
This commit contains setup code for the shared user/kernel rings. The rings are used for passing ownership of frame data buffers via descriptors between the kernel and the user space process.
We're also introducing some additional structures:
* xsk_packet array: A batching/caching wrapper on-top of the descriptor ring.
* xsk_buff: The xsk_buff is an entry in the user registered frame data area. Can be seen as a decorated descriptor entry.
* xsk_buff_info: Container of xsk_buffs.
--- include/uapi/linux/if_xdp.h | 33 ++++ net/xdp/Makefile | 2 +- net/xdp/xsk.c | 127 +++++++++++++- net/xdp/xsk_buff.h | 161 ++++++++++++++++++ net/xdp/xsk_packet_array.c | 62 +++++++ net/xdp/xsk_packet_array.h | 394 ++++++++++++++++++++++++++++++++++++++++++++ net/xdp/xsk_ring.c | 60 +++++++ net/xdp/xsk_ring.h | 307 ++++++++++++++++++++++++++++++++++ net/xdp/xsk_user_queue.h | 24 +++ 9 files changed, 1168 insertions(+), 2 deletions(-) create mode 100644 net/xdp/xsk_buff.h create mode 100644 net/xdp/xsk_packet_array.c create mode 100644 net/xdp/xsk_packet_array.h create mode 100644 net/xdp/xsk_ring.c create mode 100644 net/xdp/xsk_ring.h create mode 100644 net/xdp/xsk_user_queue.h
include/uapi/linux/if_xdp.h +33 -0
@@ -36,4 +36,37 @@ struct xdp_mr_req { __u32 data_headroom; /* Frame head room */ }; +struct xdp_ring_req { +__u32 mr_fd;/* FD of packet buffer area registered +* with XDP_MEM_REG +*/ +__u32 desc_nr;/* Number of descriptors in ring */ +}; + +/* Pgoff for mmaping the rings */ +#define XDP_PGOFF_RX_RING 0 +#define XDP_PGOFF_TX_RING 0x80000000 + +/* XDP user space ring structure */ +#define XDP_DESC_KERNEL 0x0080/* The descriptor is owned by the kernel */ +#define XDP_PKT_CONT 1/* The packet continues in the next descriptor */ + +struct xdp_desc { +__u32 idx; +__u32 len; +__u16 offset; +__u8 error;/* an errno */ +__u8 flags; +__u8 padding[4 ]; +}; + +struct xdp_queue { +struct xdp_desc *ring; + +__u32 avail_idx; +__u32 last_used_idx; +__u32 num_free; +__u32 ring_mask; +}; +#endif /* _LINUX_IF_XDP_H */
net/xdp/Makefile +1 -1
@@ -1 +1 @@ -obj-$(CONFIG_XDP_SOCKETS) += xsk.o +obj-$(CONFIG_XDP_SOCKETS) += xsk.o xsk_ring.o xsk_packet_array.o
net/xdp/xsk.c +126 -1
166 lines not on this page · raw message
net/xdp/xsk_buff.h new file +161 -0
161 lines not on this page · raw message
net/xdp/xsk_packet_array.c new file +62 -0
62 lines not on this page · raw message
net/xdp/xsk_packet_array.h new file +394 -0
394 lines not on this page · raw message
net/xdp/xsk_ring.c new file +60 -0
60 lines not on this page · raw message
net/xdp/xsk_ring.h new file +307 -0
307 lines not on this page · raw message
net/xdp/xsk_user_queue.h new file +24 -0
@@ -0,0 +1,24 @@ +#ifndef XSK_USER_QUEUE_H_ +#define XSK_USER_QUEUE_H_ + +#define XDP_KERNEL_HEADROOM 256/* Headrom for XDP */ + +#define XSK_FRAME_COMPLETED XDP_DESC_KERNEL + +enum xsk_validation { +XSK_VALIDATION_NONE ,/* No validation is performed */ +XSK_VALIDATION_RX ,/* Only address to packet buffer validated */ +XSK_VALIDATION_TX /* Full descriptor is validated */ +}; + +struct xsk_packet_array ; + +struct xsk_user_queue { +int (*enqueue)(struct xsk_packet_array *pa,u32 cnt); +int (*enqueue_completed)(struct xsk_packet_array *pa,u32 cnt); +int (*dequeue)(struct xsk_packet_array *pa,u32 cnt); +u32 (*get_ring_size)(struct xsk_user_queue *q); +char *(*get_ring_address)(struct xsk_user_queue *q); +}; + +#endif /* XSK_USER_QUEUE_H_ */
Signature · 1 line
2.14.1
RFC PATCH 4/24 xsk: add bind support and introduce Rx functionality
In reply to Björn TöpelFrom: Magnus Karlsson <[email protected]>
Here the bind syscall is implemented. Also, two frame receive functions are introduced: xsk_rcv and xsk_generic_rcv. The latter is used for the XDP_SKB path, and the first is used for XDP_DRV.
Later commits will wire up the receive functions.
--- include/linux/netdevice.h | 3 + net/xdp/xsk.c | 211 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 210 insertions(+), 4 deletions(-)
include/linux/netdevice.h +3 -0
@@ -688,6 +688,9 @@ struct netdev_rx_queue {struct kobject kobj;struct net_device *dev;struct xdp_rxq_info xdp_rxq; +#ifdef CONFIG_XDP_SOCKETS +struct xdp_sock __rcu *xs; +#endif }____cacheline_aligned_in_smp ;/*
net/xdp/xsk.c +207 -4
239 lines not on this page · raw message
Signature · 1 line
2.14.1
RFC PATCH 5/24 bpf: added bpf_xdpsk_redirect
In reply to Björn TöpelFrom: Björn Töpel <[email protected]>
The bpf_xdpsk_redirect call redirects the XDP context to the XDP socket bound to the receiving queue (if any).
--- include/uapi/linux/bpf.h | 6 +++++- net/core/filter.c | 24 ++++++++++++++++++++++++ tools/testing/selftests/bpf/bpf_helpers.h | 2 ++ 3 files changed, 31 insertions(+), 1 deletion(-)
include/uapi/linux/bpf.h +5 -1
@@ -696,6 +696,9 @@ union bpf_attr {* int bpf_override_return(pt_regs, rc) * @pt_regs: pointer to struct pt_regs * @rc: the return value to set +* +* int bpf_xdpsk_redirect() +* Return: XDP_REDIRECT */ #define __BPF_FUNC_MAPPER (FN ) \ FN(unspec), \
@@ -757,7 +760,8 @@ union bpf_attr {FN (perf_prog_read_value), \FN (getsockopt), \FN (override_return), \ -FN (sock_ops_cb_flags_set), +FN (sock_ops_cb_flags_set), \ +FN (xdpsk_redirect),/* integer value in 'imm' field of BPF_CALL instruction selects which helper * function eBPF program intends to call
net/core/filter.c +24 -0
@@ -1809,6 +1809,8 @@ struct redirect_info {struct bpf_map *map;struct bpf_map *map_to_flush;unsigned long map_owner; +bool to_xsk; +/* XXX cache xsk socket here, to avoid lookup? */ }; static DEFINE_PER_CPU(struct redirect_info, redirect_info);
@@ -2707,6 +2709,7 @@ static int xdp_do_generic_redirect_map(struct net_device *dev, ri->ifindex =0 ; ri->map =NULL ; ri->map_owner =0 ; + ri->to_xsk = false;if (unlikely (xdp_map_invalid (xdp_prog, map_owner))) { err = -EFAULT ;
@@ -2817,6 +2820,25 @@ static const struct bpf_func_proto bpf_xdp_redirect_map_proto = { .arg3_type = ARG_ANYTHING, }; +BPF_CALL_0 (bpf_xdpsk_redirect) +{ +struct redirect_info *ri =this_cpu_ptr (&redirect_info); + +/* XXX Would it be better to check for socket existence here, +* and XDP_ABORTED on failure? Also, then we can populate xsk +* in ri, and don't have to do the lookup multiple times. +*/ + ri->to_xsk = true; + +return XDP_REDIRECT ; +} + +static const struct bpf_func_proto bpf_xdpsk_redirect_proto = { + .func = bpf_xdpsk_redirect, + .gpl_only = false, + .ret_type =RET_INTEGER , +}; +bool bpf_helper_changes_pkt_data (void *func) { if (func == bpf_skb_vlan_push ||
@@ -3544,6 +3566,8 @@ xdp_func_proto(enum bpf_func_id func_id)return &bpf_xdp_redirect_proto;case BPF_FUNC_redirect_map:return &bpf_xdp_redirect_map_proto; +case BPF_FUNC_xdpsk_redirect: +return &bpf_xdpsk_redirect_proto;default :return bpf_base_func_proto (func_id); }
tools/testing/selftests/bpf/bpf_helpers.h +2 -0
@@ -86,6 +86,8 @@ static int (*bpf_perf_prog_read_value)(void *ctx, void *buf, (void *) BPF_FUNC_perf_prog_read_value;static int (*bpf_override_return)(void *ctx,unsigned long rc) = (void *) BPF_FUNC_override_return; +static int (*bpf_xdpsk_redirect)(void ) = + (void *) BPF_FUNC_xdpsk_redirect;/* llvm builtin functions that eBPF C program may use to * emit BPF_LD_ABS and BPF_LD_IND instructions
Signature · 1 line
2.14.1
Re: [RFC PATCH 05/24] bpf: added bpf_xdpsk_redirect
Quoted 2 lines · On Wed, 31 Jan 2018 14:53:37 +0100 Björn Töpel <[email protected]> wrote:
The
bpf_xdpsk_redirectcall redirects the XDP context to the XDP socket bound to the receiving queue (if any).
As I explained in-person at FOSDEM, my suggestion is to use the bpf-map infrastructure for AF_XDP redirect, but people on this upstream mailing also need a chance to validate my idea ;-)
The important thing to keep in-mind is how we can still maintain a SPSC (Single producer Single Consumer) relationship between an RX-queue and a userspace consumer-process.
This AF_XDP "FOSDEM" patchset, store the "xsk" (xdp_sock) pointer directly in the net_device (_rx[].netdev_rx_queue.xs) structure. This limit each RX-queue to service a single xdp_sock. It sounds good from a SPSC pov, but not very flexible. With a "xdp_sock_map" we can get the flexibility to select among multiple xdp_sock'ets (via XDP pre-filter selecting a different map), and still maintain a SPSC relationship. The RX-queue will just have several SPSC relationships with the individual xdp_sock's.
This is true for the AF_XDP-copy mode, and require less driver change. For the AF_XDP-zero-copy (ZC) mode drivers need significant changes anyhow, and in ZC case we will have to disallow this multiple xdp_sock's, which is simply achieved by checking if the xdp_sock pointer returned from the map lookup match the one that userspace requested driver to register it's memory for RX-rings from.
The "xdp_sock_map" is an array, where the index correspond to the queue_index. The bpf_redirect_map() ignore the specified index and instead use xdp_rxq_info->queue_index in the lookup.
Notice that a bpf-map have no pinned relationship with the device or XDP prog loaded. Thus, userspace need to bind() this map to the device before traffic can flow, like the proposed bind() on the xdp_sock. This is to establish the SPSC binding. My proposal is that userspace insert the xdp_sock file-descriptor(s) in the map at the queue-index, and the map (which is also just a file-descriptor) is bound maybe via bind() to a specific device (via the ifindex). Kernel side will walk the map and do required actions xdp_sock's in find in map.
TX-side is harder, as now multiple xdp_sock's can have the same queue-pair ID with the same net_device. But Magnus propose that this can be solved with hardware. As newer NICs have many TX-queue, and the queue-pair ID is just an external visible number, while the kernel internal structure can point to a dedicated TX-queue per xdp_sock.
Signature · 4 lines
Best regards, Jesper Dangaard Brouer MSc.CS, Principal Kernel Engineer at Red Hat LinkedIn: http://www.linkedin.com/in/brouer
Re: [RFC PATCH 05/24] bpf: added bpf_xdpsk_redirect
2018-02-05 14:42 GMT+01:00 Jesper Dangaard Brouer <[email protected]>:
Quoted 33 lines · On Wed, 31 Jan 2018 14:53:37 +0100 Björn Töpel <[email protected]> wrote:
Quoted 3 lines
The
bpf_xdpsk_redirectcall redirects the XDP context to the XDP socket bound to the receiving queue (if any).As I explained in-person at FOSDEM, my suggestion is to use the bpf-map infrastructure for
AF_XDPredirect, but people on this upstream mailing also need a chance to validate my idea ;-)The important thing to keep in-mind is how we can still maintain a SPSC (Single producer Single Consumer) relationship between an RX-queue and a userspace consumer-process.
This
AF_XDP"FOSDEM" patchset, store the "xsk" (xdp_sock) pointer directly in thenet_device(_rx[].netdev_rx_queue.xs) structure. This limit each RX-queue to service a singlexdp_sock. It sounds good from a SPSC pov, but not very flexible. With a "xdp_sock_map" we can get the flexibility to select among multiple xdp_sock'ets (via XDP pre-filter selecting a different map), and still maintain a SPSC relationship. The RX-queue will just have several SPSC relationships with the individual xdp_sock's.This is true for the AF_XDP-copy mode, and require less driver change. For the AF_XDP-zero-copy (ZC) mode drivers need significant changes anyhow, and in ZC case we will have to disallow this multiple xdp_sock's, which is simply achieved by checking if the
xdp_sockpointer returned from the map lookup match the one that userspace requested driver to register it's memory for RX-rings from.The "
xdp_sock_map" is an array, where the index correspond to thequeue_index. Thebpf_redirect_map()ignore the specified index and instead usexdp_rxq_info->queue_indexin the lookup.
Quoted 10 lines
Notice that a bpf-map have no pinned relationship with the device or XDP prog loaded. Thus, userspace need to
bind()this map to the device before traffic can flow, like the proposedbind()on thexdp_sock. This is to establish the SPSC binding. My proposal is that userspace insert thexdp_sockfile-descriptor(s) in the map at the queue-index, and the map (which is also just a file-descriptor) is bound maybe viabind()to a specific device (via the ifindex). Kernel side will walk the map and do required actions xdp_sock's in find in map.
As we discussed at FOSDEM, I like the idea of using a map. This also opens up for configuring the AF_XDP sockets via bpf code, like sockmap does.
I'll have a stab at adding an "xdp_sock_map/xskmap" or similar, and also extending the cgroup sock_ops to support AF_XDP sockets, so that the xskmap can be configured from bpf-land.
Björn
Quoted 11 lines
TX-side is harder, as now multiple xdp_sock's can have the same queue-pair ID with the same
net_device. But Magnus propose that this can be solved with hardware. As newer NICs have many TX-queue, and the queue-pair ID is just an external visible number, while the kernel internal structure can point to a dedicated TX-queue perxdp_sock.--
Best regards,
Jesper Dangaard Brouer
MSc.CS, Principal Kernel Engineer at Red Hat
LinkedIn: http://www.linkedin.com/in/brouer
RFC PATCH 6/24 net: wire up xsk support in the XDP_REDIRECT path
In reply to Björn TöpelFrom: Björn Töpel <[email protected]>
In this commit we add support for XDP programs to redirect frames to a bound AF_XDP socket.
--- include/linux/filter.h | 2 +- include/net/xdp_sock.h | 28 ++++++++++++++++++++ net/core/dev.c | 28 +++++++++++--------- net/core/filter.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 111 insertions(+), 19 deletions(-) create mode 100644 include/net/xdp_sock.h
include/linux/filter.h +1 -1
@@ -747,7 +747,7 @@ struct bpf_prog *bpf_patch_insn_single(struct bpf_prog *prog, u32 off,* This does not appear to be a real limitation for existing software. */ int xdp_do_generic_redirect (struct net_device *dev,struct sk_buff *skb, -struct bpf_prog *prog); +struct xdp_buff *xdp,struct bpf_prog *prog);int xdp_do_redirect (struct net_device *dev,struct xdp_buff *xdp,struct bpf_prog *prog);
include/net/xdp_sock.h new file +28 -0
@@ -0,0 +1,28 @@ +#ifndef _LINUX_AF_XDP_SOCK_H +#define _LINUX_AF_XDP_SOCK_H + +struct xdp_sock ; +struct xdp_buff ; + +#ifdef CONFIG_XDP_SOCKETS +int xsk_generic_rcv (struct xdp_buff *xdp); +struct xdp_sock *xsk_rcv (struct xdp_sock *xsk,struct xdp_buff *xdp); +void xsk_flush (struct xdp_sock *xsk); +#else +static inline int xsk_generic_rcv (struct xdp_buff *xdp) +{ +return -ENOTSUPP ; +} + +static inline struct xdp_sock *xsk_rcv (struct xdp_sock *xsk, +struct xdp_buff *xdp) +{ +return ERR_PTR (-ENOTSUPP ); +} + +static inline void xsk_flush (struct xdp_sock *xsk) +{ +} +#endif /* CONFIG_XDP_SOCKETS */ + +#endif /* _LINUX_AF_XDP_SOCK_H */
net/core/dev.c +15 -13
@@ -3951,11 +3951,11 @@ static struct netdev_rx_queue *netif_get_rxqueue(struct sk_buff *skb) }static u32 netif_receive_generic_xdp (struct sk_buff *skb, +struct xdp_buff *xdp,struct bpf_prog *xdp_prog) {struct netdev_rx_queue *rxqueue;u32 metalen, act =XDP_DROP ; -struct xdp_buff xdp;void *orig_data;int hlen, off;u32 mac_len;
@@ -3991,18 +3991,18 @@ static u32 netif_receive_generic_xdp(struct sk_buff *skb,*/ mac_len = skb->data -skb_mac_header (skb); hlen =skb_headlen (skb) + mac_len; - xdp.data = skb->data - mac_len; - xdp.data_meta = xdp.data; - xdp.data_end = xdp.data + hlen; - xdp.data_hard_start = skb->data -skb_headroom (skb); - orig_data = xdp.data; + xdp->data = skb->data - mac_len; + xdp->data_meta = xdp->data; + xdp->data_end = xdp->data + hlen; + xdp->data_hard_start = skb->data -skb_headroom (skb); + orig_data = xdp->data; rxqueue =netif_get_rxqueue (skb); - xdp.rxq = &rxqueue->xdp_rxq; + xdp->rxq = &rxqueue->xdp_rxq; - act =bpf_prog_run_xdp (xdp_prog, &xdp); + act =bpf_prog_run_xdp (xdp_prog, xdp); - off = xdp.data - orig_data; + off = xdp->data - orig_data;if (off >0 )__skb_pull (skb, off);else if (off <0 )
@@ -4015,7 +4015,7 @@ static u32 netif_receive_generic_xdp(struct sk_buff *skb,__skb_push (skb, mac_len);break ;case XDP_PASS : - metalen = xdp.data - xdp.data_meta; + metalen = xdp->data - xdp->data_meta;if (metalen)skb_metadata_set (skb, metalen);break ;
@@ -4065,17 +4065,19 @@ static struct static_key generic_xdp_needed __read_mostly;int do_xdp_generic (struct bpf_prog *xdp_prog,struct sk_buff *skb) {if (xdp_prog) { -u32 act =netif_receive_generic_xdp (skb, xdp_prog); +struct xdp_buff xdp; +u32 act;int err; + act =netif_receive_generic_xdp (skb, &xdp, xdp_prog);if (act !=XDP_PASS ) {switch (act) {case XDP_REDIRECT : err =xdp_do_generic_redirect (skb->dev, skb, - xdp_prog); + &xdp, xdp_prog);if (err) goto out_redir; -/* fallthru to submit skb */ +break ;case XDP_TX :generic_xdp_tx (skb, xdp_prog);break ;
net/core/filter.c +67 -5
156 lines not on this page · raw message
Signature · 1 line
2.14.1
RFC PATCH 7/24 xsk: introduce Tx functionality
In reply to Björn TöpelFrom: Magnus Karlsson <[email protected]>
The xsk socket can now send frames, in addition to receiving them.
--- net/xdp/xsk.c | 191 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 190 insertions(+), 1 deletion(-)
net/xdp/xsk.c +190 -1
@@ -52,6 +52,8 @@ struct xdp_sock {struct xsk_info tx;struct net_device *dev;struct xsk_umem *umem; +/* Protects multiple processes from entering sendmsg */ +struct mutex tx_mutex;u32 ifindex;u16 queue_id; };
@@ -346,8 +348,10 @@ static int xsk_release(struct socket *sock)synchronize_net ();xskpa_destroy (xs->rx.pa); +xskpa_destroy (xs->tx.pa);xsk_umem_destroy (xs_prev->umem);xskq_destroy (xs_prev->rx.q); +xskq_destroy (xs_prev->tx.q);kobject_put (&xs_prev->dev->_rx[xs->queue_id].kobj);dev_put (xs_prev->dev); }
@@ -406,6 +410,8 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len) xs->ifindex = sxdp->sxdp_ifindex; xs->queue_id = sxdp->sxdp_queue_id;spin_lock_init (&xs->rx.pa_lock); +spin_lock_init (&xs->tx.pa_lock); +mutex_init (&xs->tx_mutex);/* Rx */ xs->rx.buff_info =xsk_buff_info_create (xs->rx.umem);
@@ -423,10 +429,31 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len) goto out_rx_pa; } +/* Tx */ + xs->tx.buff_info =xsk_buff_info_create (xs->tx.umem); +if (!xs->tx.buff_info) { + err = -ENOMEM ; + goto out_tx_bi; + } +xskq_set_buff_info (xs->tx.q, xs->tx.buff_info,XSK_VALIDATION_TX ); + + xs->tx.pa =xskpa_create ((struct xsk_user_queue *)xs->tx.q, + xs->tx.buff_info,XSK_ARRAY_SIZE ); +if (!xs->tx.pa) { + err = -ENOMEM ; + goto out_tx_pa; + } +rcu_assign_pointer (dev->_rx[sxdp->sxdp_queue_id].xs, xs); goto out_unlock; +out_tx_pa: +xsk_buff_info_destroy (xs->tx.buff_info); + xs->tx.buff_info =NULL ; +out_tx_bi: +xskpa_destroy (xs->rx.pa); + xs->rx.pa =NULL ; out_rx_pa:xsk_buff_info_destroy (xs->rx.buff_info); xs->rx.buff_info =NULL ;
@@ -621,9 +648,171 @@ static int xsk_getsockopt(struct socket *sock, int level, int optname,return -EOPNOTSUPP ; } +void xsk_tx_completion (struct net_device *dev,u16 queue_index, +unsigned int npackets) +{ +unsigned long flags; +struct xdp_sock *xs; + +rcu_read_lock (); + xs =lookup_xsk (dev, queue_index); +if (unlikely (!xs)) { +rcu_read_unlock (); +return ; + } + +spin_lock_irqsave (&xs->tx.pa_lock, flags); +WARN_ON_ONCE (xskpa_flush_n (xs->tx.pa, npackets)); +spin_unlock_irqrestore (&xs->tx.pa_lock, flags); +rcu_read_unlock (); +} +EXPORT_SYMBOL_GPL (xsk_tx_completion); + +static void xsk_destruct_skb (struct sk_buff *skb) +{ +u64 idx = (u64 )skb_shinfo (skb)->destructor_arg; +struct xsk_frame_set p = {.start = idx, + .curr = idx, + .end = idx +1 }; +struct xdp_sock *xs; +unsigned long flags; + +rcu_read_lock (); + xs =lookup_xsk (skb->dev,skb_get_queue_mapping (skb)); +if (unlikely (!xs)) { +rcu_read_unlock (); +return ; + } + + p.pkt_arr = xs->tx.pa; +xskf_packet_completed (&p); +spin_lock_irqsave (&xs->tx.pa_lock, flags); +WARN_ON_ONCE (xskpa_flush_completed (xs->tx.pa)); +spin_unlock_irqrestore (&xs->tx.pa_lock, flags); +rcu_read_unlock (); + +sock_wfree (skb); +} + +static int xsk_xmit_skb (struct sk_buff *skb) +{ +struct net_device *dev = skb->dev; +struct sk_buff *orig_skb = skb; +struct netdev_queue *txq; +int ret =NETDEV_TX_BUSY ; +bool again = false; + +if (unlikely (!netif_running (dev) || !netif_carrier_ok (dev))) + goto drop; + + skb =validate_xmit_skb_list (skb, dev, &again); +if (skb != orig_skb) +return NET_XMIT_DROP ; + + txq =skb_get_tx_queue (dev, skb); + +local_bh_disable (); + +HARD_TX_LOCK (dev, txq,smp_processor_id ()); +if (!netif_xmit_frozen_or_drv_stopped (txq)) + ret =netdev_start_xmit (skb, dev, txq, false); +HARD_TX_UNLOCK (dev, txq); + +local_bh_enable (); + +if (!dev_xmit_complete (ret)) + goto out_err; + +return ret; +drop: +atomic_long_inc (&dev->tx_dropped); +out_err: +kfree_skb (skb); +return NET_XMIT_DROP ; +} + +static int xsk_generic_xmit (struct sock *sk,struct msghdr *m, +size_t total_len) +{ +bool need_wait = !(m->msg_flags &MSG_DONTWAIT ); +struct xdp_sock *xs =xdp_sk (sk); +struct xsk_frame_set p; +struct sk_buff *skb; +unsigned long flags; +int err =0 ; + +if (need_wait) +/* Not implemented yet. */ +return -EINVAL ; + +mutex_lock (&xs->tx_mutex); +spin_lock_irqsave (&xs->tx.pa_lock, flags); +xskpa_populate (xs->tx.pa); +spin_unlock_irqrestore (&xs->tx.pa_lock, flags); + +while (xskpa_next_packet (xs->tx.pa, &p)) { +u32 len =xskf_get_packet_len (&p); + +if (unlikely (len > xs->dev->mtu)) { + err = -EMSGSIZE ; + goto out_err; + } + + skb =sock_alloc_send_skb (sk, len, !need_wait, &err); +if (unlikely (!skb)) { + err = -EAGAIN ; + goto out_err; + } + +/* XXX Use fragments for the data here */ +skb_put (skb, len); + err =skb_store_bits (skb,0 ,xskf_get_data (&p), len); +if (unlikely (err)) + goto out_skb; + + skb->dev = xs->dev; + skb->priority = sk->sk_priority; + skb->mark = sk->sk_mark; +skb_set_queue_mapping (skb, xs->queue_id); +skb_shinfo (skb)->destructor_arg = + (void *)(long )xskf_get_frame_id (&p); + skb->destructor = xsk_destruct_skb; + + err =xsk_xmit_skb (skb); +/* Ignore NET_XMIT_CN as packet might have been sent */ +if (err ==NET_XMIT_DROP || err ==NETDEV_TX_BUSY ) { + err = -EAGAIN ; +break ; + } + } + +mutex_unlock (&xs->tx_mutex); +return err; + +out_skb: +kfree_skb (skb); +out_err: +xskf_set_error (&p, -err); +xskf_packet_completed (&p); +spin_lock_irqsave (&xs->tx.pa_lock, flags); +WARN_ON_ONCE (xskpa_flush_completed (xs->tx.pa)); +spin_unlock_irqrestore (&xs->tx.pa_lock, flags); +mutex_unlock (&xs->tx_mutex); + +return err; +} +static int xsk_sendmsg (struct socket *sock,struct msghdr *m,size_t total_len) { -return -EOPNOTSUPP ; +struct sock *sk = sock->sk; +struct xdp_sock *xs =xdp_sk (sk); + +if (unlikely (!xs->dev)) +return -ENXIO ; +if (unlikely (!(xs->dev->flags &IFF_UP ))) +return -ENETDOWN ; + +return xsk_generic_xmit (sk, m, total_len); } static int xsk_mmap(struct file *file, struct socket *sock,
Signature · 1 line
2.14.1
RFC PATCH 8/24 i40e: add support for XDP_REDIRECT
In reply to Björn TöpelFrom: Björn Töpel <[email protected]>
The driver now acts upon the XDP_REDIRECT return action. Two new ndos are implemented, ndo_xdp_xmit and ndo_xdp_flush.
XDP_REDIRECT action enables XDP program to redirect frames to other netdevs. The target redirect/forward netdev might release the XDP data page within the ndo_xdp_xmit function (triggered by xdp_do_redirect), which meant that the i40e page count logic had to be tweaked.
An example. i40e_clean_rx_irq is entered, and one rx_buffer is pulled from the hardware descriptor ring. Say that the actual page refcount is 1. XDP is enabled, and the redirect action is triggered. The target netdev ndo_xdp_xmit decreases the page refcount, resulting in the page being freed. The prior assumption was that the function owned the page until i40e_put_rx_buffer was called, increasing the refcount again.
Now, we don't allow a refcount less than 2. Another option would be calling xdp_do_redirect *after* i40e_put_rx_buffer, but that would required new/more conditionals.
--- drivers/net/ethernet/intel/i40e/i40e_main.c | 2 + drivers/net/ethernet/intel/i40e/i40e_txrx.c | 86 ++++++++++++++++++++++++----- drivers/net/ethernet/intel/i40e/i40e_txrx.h | 3 + 3 files changed, 76 insertions(+), 15 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_main.c +2 -0
@@ -11687,6 +11687,8 @@ static const struct net_device_ops i40e_netdev_ops = { .ndo_bridge_getlink = i40e_ndo_bridge_getlink, .ndo_bridge_setlink = i40e_ndo_bridge_setlink, .ndo_bpf = i40e_xdp, + .ndo_xdp_xmit = i40e_xdp_xmit, + .ndo_xdp_flush = i40e_xdp_flush, };/**
drivers/net/ethernet/intel/i40e/i40e_txrx.c +71 -15
125 lines not on this page · raw message
drivers/net/ethernet/intel/i40e/i40e_txrx.h +3 -0
@@ -505,6 +505,9 @@ u32 i40e_get_tx_pending(struct i40e_ring *ring);void i40e_detect_recover_hung (struct i40e_vsi *vsi);int __i40e_maybe_stop_tx (struct i40e_ring *tx_ring,int size);bool __i40e_chk_linearize (struct sk_buff *skb); +int i40e_xdp_xmit (struct net_device *dev,struct xdp_buff *xdp); +void i40e_xdp_flush (struct net_device *dev); +/** * i40e_get_head - Retrieve head from head writeback
Signature · 1 line
2.14.1
RFC PATCH 9/24 samples/bpf: added xdpsock program
In reply to Björn TöpelFrom: Björn Töpel <[email protected]>
Test program for AF_XDP sockets.
--- samples/bpf/Makefile | 4 + samples/bpf/xdpsock_kern.c | 11 + samples/bpf/xdpsock_queue.h | 62 +++++ samples/bpf/xdpsock_user.c | 642 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 719 insertions(+) create mode 100644 samples/bpf/xdpsock_kern.c create mode 100644 samples/bpf/xdpsock_queue.h create mode 100644 samples/bpf/xdpsock_user.c
samples/bpf/Makefile +4 -0
@@ -43,6 +43,7 @@ hostprogs-y += xdp_redirect_cpu hostprogs-y += xdp_monitor hostprogs-y += xdp_rxq_info hostprogs-y += syscall_tp +hostprogs-y += xdpsock # Libbpf dependencies LIBBPF := ../../tools/lib/bpf/bpf.o
@@ -93,6 +94,7 @@ xdp_redirect_cpu-objs := bpf_load.o $(LIBBPF) xdp_redirect_cpu_user.o xdp_monitor-objs := bpf_load.o $(LIBBPF) xdp_monitor_user.o xdp_rxq_info-objs := bpf_load.o $(LIBBPF) xdp_rxq_info_user.o syscall_tp-objs := bpf_load.o $(LIBBPF) syscall_tp_user.o +xdpsock-objs := bpf_load.o $(LIBBPF) xdpsock_user.o # Tell kbuild to always build the programs always := $(hostprogs-y)
@@ -144,6 +146,7 @@ always += xdp_monitor_kern.o always += xdp_rxq_info_kern.o always += xdp2skb_meta_kern.o always += syscall_tp_kern.o +always += xdpsock_kern.o HOSTCFLAGS += -I$(objtree)/usr/include HOSTCFLAGS += -I$(srctree)/tools/lib/
@@ -188,6 +191,7 @@ HOSTLOADLIBES_xdp_redirect_cpu += -lelf HOSTLOADLIBES_xdp_monitor += -lelf HOSTLOADLIBES_xdp_rxq_info += -lelf HOSTLOADLIBES_syscall_tp += -lelf +HOSTLOADLIBES_xdpsock += -lelf -pthread # Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline: # make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
samples/bpf/xdpsock_kern.c new file +11 -0
@@ -0,0 +1,11 @@ +#define KBUILD_MODNAME "foo" +#include <uapi/linux/bpf.h> +#include "bpf_helpers.h" + +SEC("xdp_sock") +int xdp_sock_prog (struct xdp_md *ctx) +{ +return bpf_xdpsk_redirect (); +} + +char _license[] SEC("license") = "GPL";
samples/bpf/xdpsock_queue.h new file +62 -0
62 lines not on this page · raw message
samples/bpf/xdpsock_user.c new file +642 -0
642 lines not on this page · raw message
Signature · 1 line
2.14.1
RFC PATCH 10/24 netdevice: added XDP_{UN,}REGISTER_XSK command to ndo_bpf
In reply to Björn TöpelFrom: Magnus Karlsson <[email protected]>
Here, ndo_bpf is extended with two sub-commands: XDP_REGISTER_XSK and XDP_UNREGISTER_XSK. They are used to support zero copy allocators with XDP sockets.
--- include/linux/netdevice.h | 17 +++++++++++++++++ include/net/xdp_sock.h | 30 +++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-)
include/linux/netdevice.h +17 -0
@@ -810,10 +810,18 @@ enum bpf_netdev_command { BPF_OFFLOAD_DESTROY,BPF_OFFLOAD_MAP_ALLOC ,BPF_OFFLOAD_MAP_FREE , +/* Registers callbacks with the driver that is used to support +* AF_XDP sockets in zero copy mode. +*/ +XDP_REGISTER_XSK , +/* Unregisters and AF_XDP socket in zero copy mode. */ + XDP_UNREGISTER_XSK, };struct bpf_prog_offload_ops ;struct netlink_ext_ack ; +struct xsk_tx_parms ; +struct xsk_rx_parms ;struct netdev_bpf {enum bpf_netdev_command command;
@@ -844,6 +852,15 @@ struct netdev_bpf {struct {struct bpf_offloaded_map *offmap; }; +/* XDP_REGISTER_XSK, XDP_UNREGISTER_XSK +* All fields used for XDP_REGISTER_XSK. +* queue_id the only field used for XDP_UNREGISTER_XSK. +*/ +struct { +struct xsk_tx_parms *tx_parms; +struct xsk_rx_parms *rx_parms; +u32 queue_id; + } xsk; }; };
include/net/xdp_sock.h +29 -1
@@ -1,8 +1,36 @@#ifndef _LINUX_AF_XDP_SOCK_H#define _LINUX_AF_XDP_SOCK_H -struct xdp_sock ; +#include <linux/dma-direction.h> + +struct buff_pool ; +struct net_device ;struct xdp_buff ; +struct xdp_sock ; + +/* These two functions have to be called from the same serializing conext, +* for example the same NAPI context. +* They should not be called for the XDP_SKB path, only XDP_DRV. +*/ + +struct xsk_tx_parms { +void (*tx_completion)(u32 start,u32 npackets, +unsigned long ctx1,unsigned long ctx2); +unsigned long ctx1; +unsigned long ctx2; +int (*get_tx_packet)(struct net_device *dev,u32 queue_id, +dma_addr_t *dma,void **data,u32 *len, +u32 *offset); +}; + +struct xsk_rx_parms { +struct buff_pool *buff_pool; +int (*dma_map)(struct buff_pool *bp,struct device *dev, +enum dma_data_direction dir, +unsigned long attr); +void *error_report_ctx; +void (*error_report)(void *ctx,int errno); +};#ifdef CONFIG_XDP_SOCKETS int xsk_generic_rcv (struct xdp_buff *xdp);
Signature · 1 line
2.14.1
RFC PATCH 11/24 netdevice: added ndo for transmitting a packet from an XDP socket
In reply to Björn TöpelFrom: Magnus Karlsson <[email protected]>
Only used when a zero copy allocator is used.
--- include/linux/netdevice.h | 5 +++++ 1 file changed, 5 insertions(+)
include/linux/netdevice.h +5 -0
@@ -1178,6 +1178,9 @@ struct dev_ifalias {* int (*ndo_xdp_xmit)(struct net_device *dev, struct xdp_buff *xdp); * This function is used to submit a XDP packet for transmit on a * netdevice. +* int (*ndo_xdp_xmit_xsk)(struct net_device *dev, u32 queue_id); +* This function is used to transmit a packet from an XDP socket +* when a zero copy allocator is used. * void (*ndo_xdp_flush)(struct net_device *dev); * This function is used to inform the driver to flush a particular * xdp tx queue. Must be called on same CPU as xdp_xmit.
@@ -1367,6 +1370,8 @@ struct net_device_ops { struct netdev_bpf *bpf);int (*ndo_xdp_xmit)(struct net_device *dev,struct xdp_buff *xdp); +int (*ndo_xdp_xmit_xsk)(struct net_device *dev, +u32 queue_id);void (*ndo_xdp_flush)(struct net_device *dev); };
Signature · 1 line
2.14.1
RFC PATCH 12/24 xsk: add iterator functions to xsk_ring
In reply to Björn TöpelFrom: Björn Töpel <[email protected]>
Add packet array like functionality that acts directly on the user/kernel shared ring. We'll use this in the zerocopy Rx scenario.
TODO Better naming...
--- net/xdp/xsk_ring.c | 3 +- net/xdp/xsk_ring.h | 136 ++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 126 insertions(+), 13 deletions(-)
net/xdp/xsk_ring.c +2 -1
@@ -41,7 +41,8 @@ struct xsk_queue *xskq_create(u32 nentries) q->queue_ops.enqueue = xskq_enqueue_from_array; q->queue_ops.enqueue_completed = xskq_enqueue_completed_from_array; q->queue_ops.dequeue = xskq_dequeue_to_array; - q->used_idx =0 ; + q->used_idx_head =0 ; + q->used_idx_tail =0 ; q->last_avail_idx =0 ; q->ring_mask = nentries -1 ; q->num_free =0 ;
net/xdp/xsk_ring.h +124 -12
202 lines not on this page · raw message
Signature · 1 line
2.14.1
RFC PATCH 13/24 i40e: introduce external allocator support
In reply to Björn TöpelFrom: Björn Töpel <[email protected]>
Here, buff_pool is introduced, which is an allocator/pool for Rx frames. This commits pulls out the recycling allocator in i40e, starts using the new buff_pool API, and adds a simple non-recycling page allocating buff_pool implementation. Future commits will reintroduce a buff_pool page recycling/flipping implementation.
--- drivers/net/ethernet/intel/i40e/Makefile | 3 +- drivers/net/ethernet/intel/i40e/buff_pool.c | 285 ++++++++++++++ drivers/net/ethernet/intel/i40e/buff_pool.h | 70 ++++ drivers/net/ethernet/intel/i40e/i40e_ethtool.c | 1 - drivers/net/ethernet/intel/i40e/i40e_main.c | 24 +- drivers/net/ethernet/intel/i40e/i40e_txrx.c | 510 +++++++++---------------- drivers/net/ethernet/intel/i40e/i40e_txrx.h | 64 +--- 7 files changed, 541 insertions(+), 416 deletions(-) create mode 100644 drivers/net/ethernet/intel/i40e/buff_pool.c create mode 100644 drivers/net/ethernet/intel/i40e/buff_pool.h
drivers/net/ethernet/intel/i40e/Makefile +2 -1
@@ -45,6 +45,7 @@ i40e-objs := i40e_main.o \ i40e_txrx.o \ i40e_ptp.o \ i40e_client.o \ - i40e_virtchnl_pf.o + i40e_virtchnl_pf.o \ + buff_pool.o i40e-$(CONFIG_I40E_DCB) += i40e_dcb.o i40e_dcb_nl.o
drivers/net/ethernet/intel/i40e/buff_pool.c new file +285 -0
285 lines not on this page · raw message
drivers/net/ethernet/intel/i40e/buff_pool.h new file +70 -0
70 lines not on this page · raw message
drivers/net/ethernet/intel/i40e/i40e_ethtool.c +0 -1
@@ -1647,7 +1647,6 @@ static int i40e_set_ringparam(struct net_device *netdev,*/ rx_rings[i].next_to_use =0 ; rx_rings[i].next_to_clean =0 ; - rx_rings[i].next_to_alloc =0 ;/* do a struct copy */ *vsi->rx_rings[i] = rx_rings[i]; }
drivers/net/ethernet/intel/i40e/i40e_main.c +9 -15
@@ -39,6 +39,7 @@*/ #define CREATE_TRACE_POINTS #include "i40e_trace.h" +#include "buff_pool.h" const char i40e_driver_name[] ="i40e" ; static const char i40e_driver_string[] =
@@ -3217,7 +3218,9 @@ static int i40e_configure_rx_ring(struct i40e_ring *ring)/* clear the context structure first */ memset (&rx_ctx,0 ,sizeof (rx_ctx)); - ring->rx_buf_len = vsi->rx_buf_len; + ring->bpool =i40e_buff_pool_create (ring->dev); + ring->rx_buf_hr = (u16 )bpool_buff_headroom (ring->bpool); + ring->rx_buf_len = (u16 )bpool_buff_size (ring->bpool); rx_ctx.dbuff =DIV_ROUND_UP (ring->rx_buf_len,BIT_ULL (I40E_RXQ_CTX_DBUFF_SHIFT ));
@@ -3312,20 +3315,8 @@ static int i40e_vsi_configure_rx(struct i40e_vsi *vsi)int err =0 ;u16 i; -if (!vsi->netdev || (vsi->back->flags &I40E_FLAG_LEGACY_RX )) { - vsi->max_frame =I40E_MAX_RXBUFFER ; - vsi->rx_buf_len =I40E_RXBUFFER_2048 ; -#if (PAGE_SIZE <8192 ) - } else if (!I40E_2K_TOO_SMALL_WITH_PADDING && - (vsi->netdev->mtu <=ETH_DATA_LEN )) { - vsi->max_frame =I40E_RXBUFFER_1536 -NET_IP_ALIGN ; - vsi->rx_buf_len =I40E_RXBUFFER_1536 -NET_IP_ALIGN ; -#endif - }else { - vsi->max_frame =I40E_MAX_RXBUFFER ; - vsi->rx_buf_len = (PAGE_SIZE <8192 ) ?I40E_RXBUFFER_3072 : -I40E_RXBUFFER_2048 ; - } + vsi->max_frame =I40E_MAX_RXBUFFER ; + vsi->rx_buf_len =I40E_RXBUFFER_3072 ;/* set up individual rings */ for (i =0 ; i < vsi->num_queue_pairs && !err; i++)
@@ -11601,6 +11592,9 @@ static int i40e_xdp_setup(struct i40e_vsi *vsi,bool need_reset;int i; +/* XXX What's the correct behavior here, when we can have +* different different rx_buf_lens per ring? +*/ /* Don't allow frames that span over multiple buffers */ if (frame_size > vsi->rx_buf_len)return -EINVAL ;
drivers/net/ethernet/intel/i40e/i40e_txrx.c +172 -338
732 lines not on this page · raw message
drivers/net/ethernet/intel/i40e/i40e_txrx.h +3 -61
94 lines not on this page · raw message
Signature · 1 line
2.14.1
RFC PATCH 14/24 i40e: implemented page recycling buff_pool
In reply to Björn TöpelFrom: Björn Töpel <[email protected]>
Added a buff_poll implementation that do page recycling.
--- drivers/net/ethernet/intel/i40e/buff_pool.c | 385 ++++++++++++++++++++++++++++ drivers/net/ethernet/intel/i40e/buff_pool.h | 6 + 2 files changed, 391 insertions(+)
drivers/net/ethernet/intel/i40e/buff_pool.c +385 -0
@@ -283,3 +283,388 @@ void i40e_buff_pool_destroy(struct buff_pool *pool)kfree (pool); } +/* Recycling allocator */ + +struct i40e_bpr_header { +dma_addr_t dma; +#if (BITS_PER_LONG >32 ) || (PAGE_SIZE >=65536 ) +__u32 page_offset; +#else +__u16 page_offset; +#endif +__u16 pagecnt_bias; +}; + +struct i40e_bpr_pool { +unsigned int buff_tot_len; +unsigned int buff_len; +unsigned int headroom; +unsigned int pg_order; +unsigned int pg_size; +struct device *dev; +unsigned int head; +unsigned int tail; +unsigned int buffs_size_mask; +struct i40e_bpr_header *buffs[0 ]; +}; + +#define I40E_BPRHDR_ALIGNED_SIZE ALIGN(sizeof(struct i40e_bpr_header), \ + SMP_CACHE_BYTES) + +static int i40e_bpr_alloc (void *pool,unsigned long *handle) +{ +struct i40e_bpr_pool *impl = (struct i40e_bpr_pool *)pool; +struct i40e_bpr_header *hdr; +struct page *pg; +dma_addr_t dma; + +if (impl->head != impl->tail) { + *handle = (unsigned long )impl->buffs[impl->head]; + impl->head = (impl->head +1 ) & impl->buffs_size_mask; + +return 0 ; + } + + pg =dev_alloc_pages (impl->pg_order); +if (unlikely (!pg)) +return -ENOMEM ; + + dma =dma_map_page_attrs (impl->dev, pg,0 , impl->pg_size, +DMA_FROM_DEVICE ,I40E_RX_DMA_ATTR ); + +if (dma_mapping_error (impl->dev, dma)) { +__free_pages (pg, impl->pg_order); +return -ENOMEM ; + } + + hdr = (struct i40e_bpr_header *)page_address (pg); + hdr->dma = dma; + hdr->page_offset =I40E_BPRHDR_ALIGNED_SIZE ; + hdr->pagecnt_bias =1 ; + + *handle = (unsigned long )hdr; + +return 0 ; +} + +static void i40e_bpr_free (void *pool,unsigned long handle) +{ +struct i40e_bpr_pool *impl = (struct i40e_bpr_pool *)pool; +struct i40e_bpr_header *hdr; +unsigned int tail; + + hdr = (struct i40e_bpr_header *)handle; + tail = (impl->tail +1 ) & impl->buffs_size_mask; +/* Is full? */ +if (tail == impl->head) { +dma_unmap_page_attrs (impl->dev, hdr->dma, impl->pg_size, +DMA_FROM_DEVICE ,I40E_RX_DMA_ATTR ); +__page_frag_cache_drain (virt_to_head_page (hdr), + hdr->pagecnt_bias); + } + + impl->buffs[impl->tail] = hdr; + impl->tail = tail; +} + +static unsigned int i40e_bpr_buff_size (void *pool) +{ +struct i40e_bpr_pool *impl = (struct i40e_bpr_pool *)pool; + +return impl->buff_len; +} + +static unsigned int i40e_bpr_total_buff_size (void *pool) +{ +struct i40e_bpr_pool *impl = (struct i40e_bpr_pool *)pool; + +return impl->buff_tot_len; +} + +static unsigned int i40e_bpr_buff_headroom (void *pool) +{ +struct i40e_bpr_pool *impl = (struct i40e_bpr_pool *)pool; + +return impl->headroom; +} + +static unsigned int i40e_bpr_buff_truesize (void *pool) +{ +struct i40e_bpr_pool *impl = (struct i40e_bpr_pool *)pool; + +return impl->buff_tot_len; +} + +static void *i40e_bpr_buff_ptr (void *pool,unsigned long handle) +{ +struct i40e_bpr_header *hdr; + + hdr = (struct i40e_bpr_header *)handle; + +return ((void *)hdr) + hdr->page_offset; +} + +static bool i40e_page_is_reusable (struct page *page) +{ +return (page_to_nid (page) ==numa_mem_id ()) && + !page_is_pfmemalloc (page); +} + +static bool i40e_can_reuse_page (struct i40e_bpr_header *hdr) +{ +unsigned int pagecnt_bias = hdr->pagecnt_bias; +struct page *page =virt_to_head_page (hdr); + +if (unlikely (!i40e_page_is_reusable (page))) +return false; + +#if (PAGE_SIZE <8192 ) +if (unlikely ((page_count (page) - pagecnt_bias) >1 )) +return false; +#else +#define I40E_LAST_OFFSET \ + (PAGE_SIZE - I40E_RXBUFFER_3072 - I40E_BPRHDR_ALIGNED_SIZE) +if (hdr->page_offset >I40E_LAST_OFFSET ) +return false; +#endif + +if (unlikely (!pagecnt_bias)) { +page_ref_add (page,USHRT_MAX ); + hdr->pagecnt_bias =USHRT_MAX ; + } + +return true; +} + +static int i40e_bpr_buff_convert_to_page (void *pool,unsigned long handle, +struct page **pg, +unsigned int *pg_off) +{ +struct i40e_bpr_pool *impl = (struct i40e_bpr_pool *)pool; +struct i40e_bpr_header *hdr; +unsigned int tail; + + hdr = (struct i40e_bpr_header *)handle; + + *pg =virt_to_page (hdr); + *pg_off = hdr->page_offset; + +#if (PAGE_SIZE <8192 ) + hdr->page_offset ^= impl->buff_tot_len; +#else + hdr->page_offset += impl->buff_tot_len; +#endif + hdr->pagecnt_bias--; + + tail = (impl->tail +1 ) & impl->buffs_size_mask; +if (i40e_can_reuse_page (hdr) && tail != impl->head) { + impl->buffs[impl->tail] = hdr; + impl->tail = tail; + +return 0 ; + } + +dma_unmap_page_attrs (impl->dev, hdr->dma, impl->pg_size, +DMA_FROM_DEVICE ,I40E_RX_DMA_ATTR ); +__page_frag_cache_drain (*pg, hdr->pagecnt_bias); +return 0 ; +} + +static dma_addr_t i40e_bpr_buff_dma (void *pool, +unsigned long handle) +{ +struct i40e_bpr_header *hdr; + + hdr = (struct i40e_bpr_header *)handle; + +return hdr->dma + hdr->page_offset; +} + +static void i40e_bpr_buff_dma_sync_cpu (void *pool, +unsigned long handle, +unsigned int off, +unsigned int size) +{ +struct i40e_bpr_pool *impl = (struct i40e_bpr_pool *)pool; +dma_addr_t dma; + + dma =i40e_bpr_buff_dma (pool, handle); +dma_sync_single_range_for_cpu (impl->dev, dma, off, size, +DMA_FROM_DEVICE ); +} + +static void i40e_bpr_buff_dma_sync_dev (void *pool, +unsigned long handle, +unsigned int off, +unsigned int size) +{ +struct i40e_bpr_pool *impl = (struct i40e_bpr_pool *)pool; +dma_addr_t dma; + + dma =i40e_bpr_buff_dma (pool, handle); +dma_sync_single_range_for_device (impl->dev, dma, off, size, +DMA_FROM_DEVICE ); +} + +static void calc_buffer_size_less_8192 (unsigned int mtu,bool reserve_headroom, +unsigned int *buff_tot_len, +unsigned int *buff_len, +unsigned int *headroom, +unsigned int *pg_order) +{ + *pg_order =0 ; + +if (!reserve_headroom) { + *buff_tot_len = (PAGE_SIZE -I40E_BPRHDR_ALIGNED_SIZE ) /2 ; + *buff_len = *buff_tot_len; + *headroom =0 ; + +return ; + } + +/* We're relying on page flipping, so make sure that a page +* (with the buff header removed) / 2 is large enough. +*/ + *buff_tot_len = (PAGE_SIZE -I40E_BPRHDR_ALIGNED_SIZE ) /2 ; +if ((NET_SKB_PAD +I40E_RXBUFFER_1536 ) <= +SKB_WITH_OVERHEAD (*buff_tot_len) && mtu <=ETH_DATA_LEN ) { + *buff_len =I40E_RXBUFFER_1536 ; + *headroom =SKB_WITH_OVERHEAD (*buff_tot_len) - *buff_len; + +return ; + } + + *pg_order =1 ; + *buff_tot_len = ((PAGE_SIZE <<1 ) -I40E_BPRHDR_ALIGNED_SIZE ) /2 ; + *buff_len =I40E_RXBUFFER_3072 ; + *headroom =SKB_WITH_OVERHEAD (*buff_tot_len) - *buff_len; +} + +static void calc_buffer_size_greater_8192 (bool reserve_headroom, +unsigned int *buff_tot_len, +unsigned int *buff_len, +unsigned int *headroom, +unsigned int *pg_order) +{ + *pg_order =0 ; + +if (!reserve_headroom) { + *buff_tot_len =I40E_RXBUFFER_2048 ; + *buff_len =I40E_RXBUFFER_2048 ; + *headroom =0 ; + +return ; + } + + *buff_tot_len =I40E_RXBUFFER_3072 ; + *buff_len =SKB_WITH_OVERHEAD (*buff_tot_len) -NET_SKB_PAD ; + *buff_len = (*buff_len /128 ) *128 ;/* 128B align */ + *headroom = *buff_tot_len - *buff_len; +} + +static void calc_buffer_size (unsigned int mtu,bool reserve_headroom, +unsigned int *buff_tot_len, +unsigned int *buff_len, +unsigned int *headroom, +unsigned int *pg_order) +{ +if (PAGE_SIZE <8192 ) { +calc_buffer_size_less_8192 (mtu, reserve_headroom, + buff_tot_len, + buff_len, + headroom, + pg_order); + +return ; + } + +calc_buffer_size_greater_8192 (reserve_headroom, buff_tot_len, + buff_len, headroom, pg_order); +} + +struct buff_pool *i40e_buff_pool_recycle_create (unsigned int mtu, +bool reserve_headroom, +struct device *dev, +unsigned int pool_size) +{ +struct buff_pool_ops *pool_ops; +struct i40e_bpr_pool *impl; +struct buff_pool *pool; + +if (!is_power_of_2 (pool_size)) { +pr_err ("%s pool_size (%u) is not power of 2\n" , __func__, pool_size); + +return NULL ; + } + + pool =kzalloc (sizeof (*pool),GFP_KERNEL ); +if (!pool) +return NULL ; + + pool_ops =kzalloc (sizeof (*pool_ops),GFP_KERNEL ); +if (!pool_ops) { +kfree (pool); +return NULL ; + } + + impl =kzalloc (sizeof (*impl) + + pool_size *sizeof (struct i40e_bpr_header *), +GFP_KERNEL ); +if (!impl) { +kfree (pool_ops); +kfree (pool); +return NULL ; + } + +calc_buffer_size (mtu, reserve_headroom, + &impl->buff_tot_len, + &impl->buff_len, + &impl->headroom, + &impl->pg_order); + + impl->buffs_size_mask = pool_size -1 ; + impl->dev = dev; + impl->pg_size =PAGE_SIZE << impl->pg_order; + + pool_ops->alloc = i40e_bpr_alloc; + pool_ops->free = i40e_bpr_free; + pool_ops->buff_size = i40e_bpr_buff_size; + pool_ops->total_buff_size = i40e_bpr_total_buff_size; + pool_ops->buff_headroom = i40e_bpr_buff_headroom; + pool_ops->buff_truesize = i40e_bpr_buff_truesize; + pool_ops->buff_ptr = i40e_bpr_buff_ptr; + pool_ops->buff_convert_to_page = i40e_bpr_buff_convert_to_page; + pool_ops->buff_dma = i40e_bpr_buff_dma; + pool_ops->buff_dma_sync_cpu = i40e_bpr_buff_dma_sync_cpu; + pool_ops->buff_dma_sync_dev = i40e_bpr_buff_dma_sync_dev; + +pr_err ("%s mtu=%u reserve=%d pool_size=%u buff_tot_len=%u buff_len=%u headroom=%u pg_order=%u pf_size=%u\n" , + __func__, + mtu, (int )reserve_headroom, pool_size, impl->buff_tot_len, + impl->buff_len, impl->headroom, impl->pg_order, impl->pg_size); + + pool->pool = impl; + pool->ops = pool_ops; + +return pool; +} + +void i40e_buff_pool_recycle_destroy (struct buff_pool *pool) +{ +struct i40e_bpr_pool *impl = (struct i40e_bpr_pool *)pool->pool; +struct i40e_bpr_header *hdr; + +while (impl->head != impl->tail) { + hdr = impl->buffs[impl->head]; +dma_unmap_page_attrs (impl->dev, hdr->dma, impl->pg_size, +DMA_FROM_DEVICE ,I40E_RX_DMA_ATTR ); +__page_frag_cache_drain (virt_to_head_page (hdr), + hdr->pagecnt_bias); + impl->head = (impl->head +1 ) & impl->buffs_size_mask; + } + +kfree (pool->ops); +kfree (pool->pool); +kfree (pool); +} +
drivers/net/ethernet/intel/i40e/buff_pool.h +6 -0
@@ -66,5 +66,11 @@ void bpool_buff_dma_sync_dev(struct buff_pool *pool,struct buff_pool *i40e_buff_pool_create (struct device *dev);void i40e_buff_pool_destroy (struct buff_pool *pool); +struct buff_pool *i40e_buff_pool_recycle_create (unsigned int mtu, +bool reserve_headroom, +struct device *dev, +unsigned int pool_size); +void i40e_buff_pool_recycle_destroy (struct buff_pool *pool); +#endif /* BUFF_POOL_H_ */
Signature · 1 line
2.14.1
RFC PATCH 15/24 i40e: start using recycling buff_pool
In reply to Björn TöpelFrom: Björn Töpel <[email protected]>
Here, we start using the newly added buff_pool implementation.
--- drivers/net/ethernet/intel/i40e/i40e_main.c | 14 +++++++++++++- drivers/net/ethernet/intel/i40e/i40e_txrx.c | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_main.c +13 -1
@@ -3211,6 +3211,8 @@ static int i40e_configure_rx_ring(struct i40e_ring *ring)u16 pf_q = vsi->base_queue + ring->queue_index;struct i40e_hw *hw = &vsi->back->hw;struct i40e_hmc_obj_rxq rx_ctx; +bool reserve_headroom; +unsigned int mtu =0 ;i40e_status err =0 ;bitmap_zero (ring->state, __I40E_RING_STATE_NBITS);
@@ -3218,7 +3220,17 @@ static int i40e_configure_rx_ring(struct i40e_ring *ring)/* clear the context structure first */ memset (&rx_ctx,0 ,sizeof (rx_ctx)); - ring->bpool =i40e_buff_pool_create (ring->dev); + reserve_headroom = !vsi->netdev; + +if (vsi->netdev) { + mtu = vsi->netdev->mtu; + reserve_headroom = !(vsi->back->flags &I40E_FLAG_LEGACY_RX ); + }else { + reserve_headroom = false; + } + ring->bpool =i40e_buff_pool_recycle_create (mtu, reserve_headroom, + ring->dev, + ring->count); ring->rx_buf_hr = (u16 )bpool_buff_headroom (ring->bpool); ring->rx_buf_len = (u16 )bpool_buff_size (ring->bpool);
drivers/net/ethernet/intel/i40e/i40e_txrx.c +1 -1
@@ -1255,7 +1255,7 @@ void i40e_free_rx_resources(struct i40e_ring *rx_ring)kfree (rx_ring->rx_bi); rx_ring->rx_bi =NULL ; -i40e_buff_pool_destroy (rx_ring->bpool); +i40e_buff_pool_recycle_destroy (rx_ring->bpool); rx_ring->bpool =NULL ;if (rx_ring->desc) {
Signature · 1 line
2.14.1
RFC PATCH 16/24 i40e: separated buff_pool interface from i40e implementaion
In reply to Björn TöpelFrom: Björn Töpel <[email protected]>
Moved buff_pool to include, so that buff_pool implementations can be done outside of the i40e module.
---
drivers/net/ethernet/intel/i40e/Makefile | 2 +-
drivers/net/ethernet/intel/i40e/buff_pool.h | 76 -----------
.../intel/i40e/{buff_pool.c => i40e_buff_pool.c} | 148 ++++-----------------
drivers/net/ethernet/intel/i40e/i40e_buff_pool.h | 15 +++
drivers/net/ethernet/intel/i40e/i40e_main.c | 3 +-
drivers/net/ethernet/intel/i40e/i40e_txrx.c | 5 +-
include/linux/buff_pool.h | 136 +++++++++++++++++++
7 files changed, 186 insertions(+), 199 deletions(-)
delete mode 100644 drivers/net/ethernet/intel/i40e/buff_pool.h
rename drivers/net/ethernet/intel/i40e/{buff_pool.c => i40e_buff_pool.c} (82%)
create mode 100644 drivers/net/ethernet/intel/i40e/i40e_buff_pool.h
create mode 100644 include/linux/buff_pool.hdrivers/net/ethernet/intel/i40e/Makefile +1 -1
@@ -46,6 +46,6 @@ i40e-objs := i40e_main.o \ i40e_ptp.o \ i40e_client.o \ i40e_virtchnl_pf.o \ - buff_pool.o + i40e_buff_pool.o i40e-$(CONFIG_I40E_DCB) += i40e_dcb.o i40e_dcb_nl.o
drivers/net/ethernet/intel/i40e/buff_pool.h deleted +0 -76
76 lines not on this page · raw message
drivers/net/ethernet/intel/i40e/i40e_buff_pool.c renamed from drivers/net/ethernet/intel/i40e/buff_pool.c +29 -119
195 lines not on this page · raw message
drivers/net/ethernet/intel/i40e/i40e_buff_pool.h new file +15 -0
@@ -0,0 +1,15 @@ +#ifndef I40E_BUFF_POOL_H_ +#define I40E_BUFF_POOL_H_ + +#include <linux/types.h> + +struct buff_pool ; +struct device ; + +struct buff_pool *i40e_buff_pool_create (struct device *dev); + +struct buff_pool *i40e_buff_pool_recycle_create (unsigned int mtu, +bool reserve_headroom, +struct device *dev, +unsigned int pool_size); +#endif /* I40E_BUFF_POOL_H_ */
drivers/net/ethernet/intel/i40e/i40e_main.c +2 -1
@@ -28,6 +28,7 @@#include <linux/of_net.h> #include <linux/pci.h> #include <linux/bpf.h> +#include <linux/buff_pool.h> /* Local includes */ #include "i40e.h"
@@ -39,7 +40,7 @@*/ #define CREATE_TRACE_POINTS #include "i40e_trace.h" -#include "buff_pool.h" +#include "i40e_buff_pool.h" const char i40e_driver_name[] ="i40e" ; static const char i40e_driver_string[] =
drivers/net/ethernet/intel/i40e/i40e_txrx.c +3 -2
@@ -27,11 +27,12 @@#include <linux/prefetch.h> #include <net/busy_poll.h> #include <linux/bpf_trace.h> +#include <linux/buff_pool.h> #include <net/xdp.h> #include "i40e.h" #include "i40e_trace.h" #include "i40e_prototype.h" -#include "buff_pool.h" +#include "i40e_buff_pool.h" static inline __le64 build_ctob (u32 td_cmd,u32 td_offset,unsigned int size,u32 td_tag)
@@ -1255,7 +1256,7 @@ void i40e_free_rx_resources(struct i40e_ring *rx_ring)kfree (rx_ring->rx_bi); rx_ring->rx_bi =NULL ; -i40e_buff_pool_recycle_destroy (rx_ring->bpool); +bpool_destroy (rx_ring->bpool); rx_ring->bpool =NULL ;if (rx_ring->desc) {
include/linux/buff_pool.h new file +136 -0
136 lines not on this page · raw message
Signature · 1 line
2.14.1
RFC PATCH 17/24 xsk: introduce xsk_buff_pool
In reply to Björn TöpelFrom: Björn Töpel <[email protected]>
The xsk_buff_pool is a buff_pool implementation, that uses frames (buffs) provided by userspace instead of the page allocator.
--- net/xdp/Makefile | 2 +- net/xdp/xsk_buff_pool.c | 225 ++++++++++++++++++++++++++++++++++++++++++++++++ net/xdp/xsk_buff_pool.h | 17 ++++ 3 files changed, 243 insertions(+), 1 deletion(-) create mode 100644 net/xdp/xsk_buff_pool.c create mode 100644 net/xdp/xsk_buff_pool.h
net/xdp/Makefile +1 -1
@@ -1 +1 @@ -obj-$(CONFIG_XDP_SOCKETS) += xsk.o xsk_ring.o xsk_packet_array.o +obj-$(CONFIG_XDP_SOCKETS) += xsk.o xsk_ring.o xsk_packet_array.o xsk_buff_pool.o
net/xdp/xsk_buff_pool.c new file +225 -0
225 lines not on this page · raw message
net/xdp/xsk_buff_pool.h new file +17 -0
@@ -0,0 +1,17 @@ +#ifndef XSK_BUFF_POOL_H_ +#define XSK_BUFF_POOL_H_ + +struct xsk_buff ; +struct xsk_buff_info ; +struct xsk_queue ; + +struct xsk_buff_pool { +struct xsk_buff *free_list; +struct xsk_buff_info *bi; +struct xsk_queue *q; +}; + +struct buff_pool *xsk_buff_pool_create (struct xsk_buff_info *buff_info, +struct xsk_queue *queue); + +#endif /* XSK_BUFF_POOL_H_ */
Signature · 1 line
2.14.1
RFC PATCH 18/24 xdp: added buff_pool support to struct xdp_buff
In reply to Björn TöpelFrom: Björn Töpel <[email protected]>
Extend xdp_buff to with a buff_pool and handle.
--- include/linux/filter.h | 1 + include/net/xdp.h | 1 + 2 files changed, 2 insertions(+)
include/linux/filter.h +1 -0
@@ -504,6 +504,7 @@ struct xdp_buff {void *data_end;void *data_meta;void *data_hard_start; +unsigned long bp_handle;struct xdp_rxq_info *rxq; };
include/net/xdp.h +1 -0
@@ -37,6 +37,7 @@ struct xdp_rxq_info {struct net_device *dev;u32 queue_index;u32 reg_state; +struct buff_pool *bpool; }____cacheline_aligned ;/* perf critical, avoid false-sharing */ int xdp_rxq_info_reg(struct xdp_rxq_info *xdp_rxq,
Signature · 1 line
2.14.1
RFC PATCH 19/24 xsk: add support for zero copy Rx
In reply to Björn TöpelFrom: Björn Töpel <[email protected]>
In this commit we start making use of the new ndo_bpf sub-commands, and try to enable zero copy, if available.
--- net/xdp/xsk.c | 185 +++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 145 insertions(+), 40 deletions(-)
net/xdp/xsk.c +145 -40
@@ -29,15 +29,21 @@#include <linux/netdevice.h> #include <net/sock.h> +#include <net/xdp_sock.h> +#include <linux/buff_pool.h> +#include "xsk.h" #include "xsk_buff.h" #include "xsk_ring.h" +#include "xsk_buff_pool.h" +#include "xsk_packet_array.h" #define XSK_UMEM_MIN_FRAME_SIZE 2048#define XSK_ARRAY_SIZE 512struct xsk_info {struct xsk_packet_array *pa; +struct buff_pool *bp;spinlock_t pa_lock;struct xsk_queue *q;struct xsk_umem *umem;
@@ -56,8 +62,24 @@ struct xdp_sock {struct mutex tx_mutex;u32 ifindex;u16 queue_id; +bool zc_mode; }; +static inline bool xsk_is_zc_cap (struct xdp_sock *xs) +{ +return xs->zc_mode; +} + +static void xsk_set_zc_cap (struct xdp_sock *xs) +{ + xs->zc_mode = true; +} + +static void xsk_clear_zc_cap (struct xdp_sock *xs) +{ + xs->zc_mode = false; +} +static struct xdp_sock *xdp_sk (struct sock *sk) {return (struct xdp_sock *)sk;
@@ -323,6 +345,22 @@ static int xsk_init_tx_ring(struct sock *sk, int mr_fd, u32 desc_nr)return xsk_init_ring (sk, mr_fd, desc_nr, &xs->tx); } +static void xsk_disable_zc (struct xdp_sock *xs) +{ +struct netdev_bpf bpf = {}; + +if (!xsk_is_zc_cap (xs)) +return ; + + bpf.command =XDP_UNREGISTER_XSK ; + bpf.xsk.queue_id = xs->queue_id; + +rtnl_lock (); + (void )xs->dev->netdev_ops->ndo_bpf (xs->dev, &bpf); +rtnl_unlock (); +xsk_clear_zc_cap (xs); +} +static int xsk_release (struct socket *sock) {struct sock *sk = sock->sk;
@@ -344,14 +382,22 @@ static int xsk_release(struct socket *sock) xs_prev = xs->dev->_rx[xs->queue_id].xs;rcu_assign_pointer (xs->dev->_rx[xs->queue_id].xs,NULL ); +xsk_disable_zc (xs); +/* Wait for driver to stop using the xdp socket. */ synchronize_net ();xskpa_destroy (xs->rx.pa); -xskpa_destroy (xs->tx.pa); -xsk_umem_destroy (xs_prev->umem); +bpool_destroy (xs->rx.bp);xskq_destroy (xs_prev->rx.q); +xsk_buff_info_destroy (xs->rx.buff_info); + +xskpa_destroy (xs->tx.pa);xskq_destroy (xs_prev->tx.q); +xsk_buff_info_destroy (xs->tx.buff_info); + +xsk_umem_destroy (xs_prev->umem); +kobject_put (&xs_prev->dev->_rx[xs->queue_id].kobj);dev_put (xs_prev->dev); }
@@ -365,6 +411,45 @@ static int xsk_release(struct socket *sock)return 0 ; } +static int xsk_dma_map_pool_cb (struct buff_pool *pool,struct device *dev, +enum dma_data_direction dir, +unsigned long attrs) +{ +struct xsk_buff_pool *bp = (struct xsk_buff_pool *)pool->pool; + +return xsk_buff_dma_map (bp->bi, dev, dir, attrs); +} + +static void xsk_error_report (void *ctx,int err) +{ +struct xsk_sock *xs = (struct xsk_sock *)ctx; +} + +static void xsk_try_enable_zc (struct xdp_sock *xs) +{ +struct xsk_rx_parms rx_parms = {}; +struct netdev_bpf bpf = {}; +int err; + +if (!xs->dev->netdev_ops->ndo_bpf) +return ; + + rx_parms.buff_pool = xs->rx.bp; + rx_parms.dma_map = xsk_dma_map_pool_cb; + rx_parms.error_report_ctx = xs; + rx_parms.error_report = xsk_error_report; + + bpf.command =XDP_REGISTER_XSK ; + bpf.xsk.rx_parms = &rx_parms; + bpf.xsk.queue_id = xs->queue_id; + +rtnl_lock (); + err = xs->dev->netdev_ops->ndo_bpf (xs->dev, &bpf); +rtnl_unlock (); +if (!err) +xsk_set_zc_cap (xs); +} +static int xsk_bind (struct socket *sock,struct sockaddr *addr,int addr_len) {struct sockaddr_xdp *sxdp = (struct sockaddr_xdp *)addr;
@@ -429,6 +514,13 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len) goto out_rx_pa; } +/* ...and Rx buffer pool is used for zerocopy. */ + xs->rx.bp =xsk_buff_pool_create (xs->rx.buff_info, xs->rx.q); +if (!xs->rx.bp) { + err = -ENOMEM ; + goto out_rx_bp; + } +/* Tx */ xs->tx.buff_info =xsk_buff_info_create (xs->tx.umem);if (!xs->tx.buff_info) {
@@ -446,12 +538,17 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len)rcu_assign_pointer (dev->_rx[sxdp->sxdp_queue_id].xs, xs); +xsk_try_enable_zc (xs); + goto out_unlock; out_tx_pa:xsk_buff_info_destroy (xs->tx.buff_info); xs->tx.buff_info =NULL ; out_tx_bi: +bpool_destroy (xs->rx.bp); + xs->rx.bp =NULL ; +out_rx_bp:xskpa_destroy (xs->rx.pa); xs->rx.pa =NULL ; out_rx_pa:
@@ -509,27 +606,16 @@ int xsk_generic_rcv(struct xdp_buff *xdp) }EXPORT_SYMBOL_GPL (xsk_generic_rcv); -struct xdp_sock *xsk_rcv (struct xdp_sock *xsk,struct xdp_buff *xdp) +static int __xsk_rcv (struct xdp_sock *xs,struct xdp_buff *xdp) {u32 len = xdp->data_end - xdp->data;struct xsk_frame_set p; -rcu_read_lock (); -if (!xsk) - xsk =lookup_xsk (xdp->rxq->dev, xdp->rxq->queue_index); -if (unlikely (!xsk)) { -rcu_read_unlock (); -return ERR_PTR (-EINVAL ); - } - -if (!xskpa_next_frame_populate (xsk->rx.pa, &p)) { -rcu_read_unlock (); -return ERR_PTR (-ENOSPC ); - } +if (!xskpa_next_frame_populate (xs->rx.pa, &p)) +return -ENOSPC ;memcpy (xskf_get_data (&p), xdp->data, len);xskf_set_frame_no_offset (&p, len, true); -rcu_read_unlock ();/* We assume that the semantic of xdp_do_redirect is such that * ndo_xdp_xmit will decrease the refcount of the page when it
@@ -540,41 +626,60 @@ struct xdp_sock *xsk_rcv(struct xdp_sock *xsk, struct xdp_buff *xdp)*/ page_frag_free (xdp->data); -return xsk; +return 0 ; } -EXPORT_SYMBOL_GPL (xsk_rcv); -int xsk_zc_rcv (struct xdp_sock *xsk,struct xdp_buff *xdp) +static void __xsk_rcv_zc (struct xdp_sock *xs,struct xdp_buff *xdp) { -u32 offset = xdp->data - xdp->data_hard_start; -u32 len = xdp->data_end - xdp->data; -struct xsk_frame_set p; +struct xsk_buff *b = (struct xsk_buff *)xdp->bp_handle; -/* We do not need any locking here since we are guaranteed -* a single producer and a single consumer. -*/ -if (xskpa_next_frame_populate (xsk->rx.pa, &p)) { -xskf_set_frame (&p, len, offset, true); -return 0 ; - } - -/* No user-space buffer to put the packet in. */ -return -ENOSPC ; +xskq_enq_lazy (xs->rx.q, b->id, xdp->data_end - xdp->data, + b->offset + (xdp->data - xdp->data_hard_start)); } -EXPORT_SYMBOL_GPL (xsk_zc_rcv); -void xsk_flush (struct xdp_sock *xsk) +struct xdp_sock *xsk_rcv (struct xdp_sock *xsk,struct xdp_buff *xdp) { +int err =0 ; +rcu_read_lock (); -if (!xsk) - xsk =lookup_xsk (xsk->dev, xsk->queue_id); -if (unlikely (!xsk)) { -rcu_read_unlock (); -return ; + +if (!xsk) { + xsk =lookup_xsk (xdp->rxq->dev, xdp->rxq->queue_index); +if (!xsk) { + err = -EINVAL ; + goto out; + } } -WARN_ON_ONCE (xskpa_flush (xsk->rx.pa)); +/* XXX Ick, this is very hacky. Need a better solution */ +if (xdp->rxq->bpool) +__xsk_rcv_zc (xsk, xdp); +else + err =__xsk_rcv (xsk, xdp); + +out:rcu_read_unlock (); + +return err ?ERR_PTR (err) : xsk; +} +EXPORT_SYMBOL_GPL (xsk_rcv); + +static void __xsk_flush (struct xdp_sock *xs) +{ +WARN_ON_ONCE (xskpa_flush (xs->rx.pa)); +} + +static void __xsk_flush_zc (struct xdp_sock *xs) +{ +xskq_enq_flush (xs->rx.q); +} + +void xsk_flush (struct xdp_sock *xsk) +{ +if (xsk_is_zc_cap (xsk)) +__xsk_flush_zc (xsk); +else +__xsk_flush (xsk); }EXPORT_SYMBOL_GPL (xsk_flush);
Signature · 1 line
2.14.1
RFC PATCH 20/24 xsk: add support for zero copy Tx
In reply to Björn TöpelFrom: Magnus Karlsson <[email protected]>
Here, ndo_xdp_xmit_xsk support is wired up, for netdevices supporting the ndo.
--- include/net/xdp_sock.h | 4 ++ net/xdp/xsk.c | 149 +++++++++++++++++++++++++++++++++++++-------- net/xdp/xsk_packet_array.h | 5 ++ 3 files changed, 131 insertions(+), 27 deletions(-)
include/net/xdp_sock.h +4 -0
@@ -14,6 +14,10 @@ struct xdp_sock;*/ struct xsk_tx_parms { +struct buff_pool *buff_pool; +int (*dma_map)(struct buff_pool *bp,struct device *dev, +enum dma_data_direction dir, +unsigned long attr);void (*tx_completion)(u32 start,u32 npackets,unsigned long ctx1,unsigned long ctx2);unsigned long ctx1;
net/xdp/xsk.c +122 -27
223 lines not on this page · raw message
net/xdp/xsk_packet_array.h +5 -0
@@ -149,6 +149,11 @@ static inline void *xskf_get_data(struct xsk_frame_set *p)return buff->data + desc->offset; } +static inline dma_addr_t xskf_get_dma (struct xsk_frame_set *p) +{ +return 0 ; +} +static inline u32 xskf_get_data_offset (struct xsk_frame_set *p) {return p->pkt_arr->items[p->curr & p->pkt_arr->mask].offset;
Signature · 1 line
2.14.1
RFC PATCH 21/24 i40e: implement xsk sub-commands in ndo_bpf for zero copy Rx
In reply to Björn TöpelFrom: Björn Töpel <[email protected]>
In this commit we add support for the two xsk ndo_bpf sub-commands for registering a xsk to the driver.
NB! There's code here for disabling/enabling a queue pair in i40e. Should probably separate this commit from the ndo implementation.
--- drivers/net/ethernet/intel/i40e/i40e.h | 24 ++ drivers/net/ethernet/intel/i40e/i40e_main.c | 434 +++++++++++++++++++++++++++- drivers/net/ethernet/intel/i40e/i40e_txrx.c | 17 +- drivers/net/ethernet/intel/i40e/i40e_txrx.h | 32 ++ 4 files changed, 493 insertions(+), 14 deletions(-)
drivers/net/ethernet/intel/i40e/i40e.h +24 -0
@@ -806,6 +806,10 @@ struct i40e_vsi {/* VSI specific handlers */ irqreturn_t (*irq_handler)(int irq,void *data); + +struct i40e_xsk_ctx **xsk_ctxs; +u16 num_xsk_ctxs; +u16 xsk_ctxs_in_use; }____cacheline_internodealigned_in_smp ;struct i40e_netdev_priv {
@@ -1109,4 +1113,24 @@ static inline bool i40e_enabled_xdp_vsi(struct i40e_vsi *vsi)int i40e_create_queue_channel (struct i40e_vsi *vsi,struct i40e_channel *ch);int i40e_set_bw_limit (struct i40e_vsi *vsi,u16 seid,u64 max_tx_rate); + +static inline bool i40e_xsk_attached (struct i40e_ring *rxr) +{ +bool xdp_on =i40e_enabled_xdp_vsi (rxr->vsi); +int qid = rxr->queue_index; + +return rxr->vsi->xsk_ctxs && rxr->vsi->xsk_ctxs[qid] && xdp_on; +} + +static inline struct buff_pool *i40e_xsk_buff_pool (struct i40e_ring *rxr) +{ +bool xdp_on =i40e_enabled_xdp_vsi (rxr->vsi); +int qid = rxr->queue_index; + +if (!rxr->vsi->xsk_ctxs || !rxr->vsi->xsk_ctxs[qid] || !xdp_on) +return NULL ; + +return rxr->vsi->xsk_ctxs[qid]->buff_pool; +} +#endif /* _I40E_H_ */
drivers/net/ethernet/intel/i40e/i40e_main.c +431 -3
476 lines not on this page · raw message
drivers/net/ethernet/intel/i40e/i40e_txrx.c +6 -11
@@ -1256,8 +1256,11 @@ void i40e_free_rx_resources(struct i40e_ring *rx_ring)kfree (rx_ring->rx_bi); rx_ring->rx_bi =NULL ; -bpool_destroy (rx_ring->bpool); +if (!ring_has_xsk_buff_pool (rx_ring)) +bpool_destroy (rx_ring->bpool); + rx_ring->bpool =NULL ; +clear_ring_xsk_buff_pool (rx_ring);if (rx_ring->desc) { dma_free_coherent(rx_ring->dev, rx_ring->size,
@@ -1917,6 +1920,7 @@ static struct sk_buff *i40e_run_xdp(struct i40e_ring *rx_ring, xdp.data = xdp.data_hard_start + *headroom;xdp_set_data_meta_invalid (&xdp); xdp.data_end = xdp.data + *size; + xdp.bp_handle = handle; xdp.rxq = &rx_ring->xdp_rxq; act =bpf_prog_run_xdp (xdp_prog, &xdp);
@@ -1943,17 +1947,8 @@ static struct sk_buff *i40e_run_xdp(struct i40e_ring *rx_ring, }break ;case XDP_REDIRECT : - err =i40e_xdp_buff_convert_page (rx_ring, &xdp, handle, *size, - *headroom); -if (err) { - result =I40E_XDP_CONSUMED ; -break ; - } - err =xdp_do_redirect (rx_ring->netdev, &xdp, xdp_prog); - result =I40E_XDP_TX ; -if (err) -page_frag_free (xdp.data); + result = err ?I40E_XDP_CONSUMED :I40E_XDP_TX ;break ;default :bpf_warn_invalid_xdp_action (act);
drivers/net/ethernet/intel/i40e/i40e_txrx.h +32 -0
@@ -245,6 +245,14 @@ static inline unsigned int i40e_txd_use_count(unsigned int size)#define I40E_TX_FLAGS_VLAN_PRIO_SHIFT 29#define I40E_TX_FLAGS_VLAN_SHIFT 16 +/* Signals completion of a TX packet for an XDP socket. */ +typedef void (*tx_completion_func )(u32 start,u32 npackets, +unsigned long ctx1,unsigned long ctx2); +/* Returns the next packet to send for an XDP socket. */ +typedef int (*get_tx_packet_func )(struct net_device *dev,u32 queue_id, +dma_addr_t *dma,void **data,u32 *len, +u32 *offset); +struct i40e_tx_buffer {struct i40e_tx_desc *next_to_watch;union {
@@ -291,6 +299,12 @@ enum i40e_ring_state_t { __I40E_RING_STATE_NBITS /* must be last */ }; +struct i40e_xsk_ctx { +struct buff_pool *buff_pool; +void *err_ctx; +void (*err_handler)(void *ctx,int errno); +}; +/* some useful defines for virtchannel interface, which * is the only remaining user of header split */
@@ -346,6 +360,7 @@ struct i40e_ring {#define I40E_TXR_FLAGS_WB_ON_ITR BIT(0)#define I40E_RXR_FLAGS_BUILD_SKB_ENABLED BIT(1)#define I40E_TXR_FLAGS_XDP BIT(2) +#define I40E_RXR_FLAGS_XSK_BUFF_POOL BIT(3)/* stats structs */ struct i40e_queue_stats stats;
@@ -374,6 +389,7 @@ struct i40e_ring {struct i40e_channel *ch;struct xdp_rxq_info xdp_rxq;struct buff_pool *bpool; +struct i40e_xsk_ctx *xsk; }____cacheline_internodealigned_in_smp ;static inline bool ring_uses_build_skb (struct i40e_ring *ring)
@@ -401,6 +417,21 @@ static inline void set_ring_xdp(struct i40e_ring *ring) ring->flags |=I40E_TXR_FLAGS_XDP ; } +static inline bool ring_has_xsk_buff_pool (struct i40e_ring *ring) +{ +return !!(ring->flags &I40E_RXR_FLAGS_XSK_BUFF_POOL ); +} + +static inline void clear_ring_xsk_buff_pool (struct i40e_ring *ring) +{ + ring->flags &= ~I40E_RXR_FLAGS_XSK_BUFF_POOL ; +} + +static inline void set_ring_xsk_buff_pool (struct i40e_ring *ring) +{ + ring->flags |=I40E_RXR_FLAGS_XSK_BUFF_POOL ; +} +enum i40e_latency_range {I40E_LOWEST_LATENCY =0 ,I40E_LOW_LATENCY =1 ,
@@ -536,4 +567,5 @@ static inline struct netdev_queue *txring_txq(const struct i40e_ring *ring) {return netdev_get_tx_queue (ring->netdev, ring->queue_index); } +#endif /* _I40E_TXRX_H_ */
Signature · 1 line
2.14.1
RFC PATCH 22/24 i40e: introduced a clean_tx callback function
In reply to Björn TöpelFrom: Magnus Karlsson <[email protected]>
To be used by XDP and AF_XDP so that they can have their own clean_tx_irq function.
--- drivers/net/ethernet/intel/i40e/i40e_main.c | 4 +++- drivers/net/ethernet/intel/i40e/i40e_txrx.c | 8 ++++---- drivers/net/ethernet/intel/i40e/i40e_txrx.h | 4 ++++ 3 files changed, 11 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_main.c +3 -1
@@ -10053,6 +10053,7 @@ static int i40e_alloc_rings(struct i40e_vsi *vsi) ring->count = vsi->num_desc; ring->size =0 ; ring->dcb_tc =0 ; + ring->clean_tx = i40e_clean_tx_irq;if (vsi->back->hw_features &I40E_HW_WB_ON_ITR_CAPABLE ) ring->flags =I40E_TXR_FLAGS_WB_ON_ITR ; ring->tx_itr_setting = pf->tx_itr_default;
@@ -10065,11 +10066,12 @@ static int i40e_alloc_rings(struct i40e_vsi *vsi) ring->reg_idx = vsi->base_queue + ring->queue_index; ring->ring_active = false; ring->vsi = vsi; - ring->netdev =NULL ; + ring->netdev = vsi->netdev; ring->dev = &pf->pdev->dev; ring->count = vsi->num_desc; ring->size =0 ; ring->dcb_tc =0 ; + ring->clean_tx = i40e_clean_tx_irq;if (vsi->back->hw_features &I40E_HW_WB_ON_ITR_CAPABLE ) ring->flags =I40E_TXR_FLAGS_WB_ON_ITR ;set_ring_xdp (ring);
drivers/net/ethernet/intel/i40e/i40e_txrx.c +4 -4
@@ -681,7 +681,7 @@ void i40e_clean_tx_ring(struct i40e_ring *tx_ring) tx_ring->next_to_use =0 ; tx_ring->next_to_clean =0 ; -if (!tx_ring->netdev) +if (!tx_ring->netdev ||ring_is_xdp (tx_ring))return ;/* cleanup Tx queue statistics */
@@ -791,8 +791,8 @@ void i40e_detect_recover_hung(struct i40e_vsi *vsi)* * Returns true if there's any budget left (e.g. the clean is finished) **/ -static bool i40e_clean_tx_irq (struct i40e_vsi *vsi, -struct i40e_ring *tx_ring,int napi_budget) +bool i40e_clean_tx_irq (struct i40e_vsi *vsi, +struct i40e_ring *tx_ring,int napi_budget) {u16 i = tx_ring->next_to_clean;struct i40e_tx_buffer *tx_buf;
@@ -2249,7 +2249,7 @@ int i40e_napi_poll(struct napi_struct *napi, int budget)* budget and be more aggressive about cleaning up the Tx descriptors. */ i40e_for_each_ring (ring, q_vector->tx) { -if (!i40e_clean_tx_irq (vsi, ring, budget)) { +if (!ring->clean_tx (vsi, ring, budget)) { clean_complete = false;continue ; }
drivers/net/ethernet/intel/i40e/i40e_txrx.h +4 -0
@@ -390,6 +390,8 @@ struct i40e_ring {struct xdp_rxq_info xdp_rxq;struct buff_pool *bpool;struct i40e_xsk_ctx *xsk; +bool (*clean_tx)(struct i40e_vsi *vsi, +struct i40e_ring *tx_ring,int napi_budget); }____cacheline_internodealigned_in_smp ;static inline bool ring_uses_build_skb (struct i40e_ring *ring)
@@ -480,6 +482,8 @@ int __i40e_maybe_stop_tx(struct i40e_ring *tx_ring, int size);bool __i40e_chk_linearize (struct sk_buff *skb);int i40e_xdp_xmit (struct net_device *dev,struct xdp_buff *xdp);void i40e_xdp_flush (struct net_device *dev); +bool i40e_clean_tx_irq (struct i40e_vsi *vsi, +struct i40e_ring *tx_ring,int napi_budget);/**
Signature · 1 line
2.14.1
RFC PATCH 23/24 i40e: introduced Tx completion callbacks
In reply to Björn TöpelFrom: Magnus Karlsson <[email protected]>
Introduced a TX completion callback in the clean_tx_irq function. In order to make it non-introsive to the SKB path, the XDP path now has its own function for cleaning up after TX completion. The XDP cases have been removed from the SKB path, which should make this faster.
This is in preparation for the AF_XDP zero copy mode.
--- drivers/net/ethernet/intel/i40e/i40e_main.c | 2 +- drivers/net/ethernet/intel/i40e/i40e_txrx.c | 182 +++++++++++++++++++++++----- drivers/net/ethernet/intel/i40e/i40e_txrx.h | 6 +- 3 files changed, 159 insertions(+), 31 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_main.c +1 -1
@@ -10071,7 +10071,7 @@ static int i40e_alloc_rings(struct i40e_vsi *vsi) ring->count = vsi->num_desc; ring->size =0 ; ring->dcb_tc =0 ; - ring->clean_tx = i40e_clean_tx_irq; + ring->clean_tx = i40e_xdp_clean_tx_irq;if (vsi->back->hw_features &I40E_HW_WB_ON_ITR_CAPABLE ) ring->flags =I40E_TXR_FLAGS_WB_ON_ITR ;set_ring_xdp (ring);
drivers/net/ethernet/intel/i40e/i40e_txrx.c +153 -29
206 lines not on this page · raw message
drivers/net/ethernet/intel/i40e/i40e_txrx.h +5 -1
@@ -261,6 +261,9 @@ struct i40e_tx_buffer { };unsigned int bytecount;unsigned short gso_segs; +tx_completion_func completion; +unsigned long ctx1; +unsigned long ctx2;DEFINE_DMA_UNMAP_ADDR (dma);DEFINE_DMA_UNMAP_LEN (len);
@@ -484,7 +487,8 @@ int i40e_xdp_xmit(struct net_device *dev, struct xdp_buff *xdp);void i40e_xdp_flush (struct net_device *dev);bool i40e_clean_tx_irq (struct i40e_vsi *vsi,struct i40e_ring *tx_ring,int napi_budget); - +bool i40e_xdp_clean_tx_irq (struct i40e_vsi *vsi, +struct i40e_ring *tx_ring,int napi_budget);/** * i40e_get_head - Retrieve head from head writeback
Signature · 1 line
2.14.1
RFC PATCH 24/24 i40e: Tx support for zero copy allocator
In reply to Björn TöpelFrom: Magnus Karlsson <[email protected]>
Used with AF_XDP sockets.
--- drivers/net/ethernet/intel/i40e/i40e_main.c | 86 ++++++++++- drivers/net/ethernet/intel/i40e/i40e_txrx.c | 218 +++++++++++++++++++++------- drivers/net/ethernet/intel/i40e/i40e_txrx.h | 18 ++- 3 files changed, 255 insertions(+), 67 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_main.c +78 -8
@@ -10027,6 +10027,22 @@ static void i40e_vsi_clear_rings(struct i40e_vsi *vsi) } } +static void i40e_restore_xsk_tx (struct i40e_vsi *vsi,int qid, +struct i40e_ring *xdp_ring) +{ +if (!vsi->xsk_ctxs) +return ; + +if (qid <0 || qid >= vsi->num_xsk_ctxs) +return ; + +if (!vsi->xsk_ctxs[qid]) +return ; + + xdp_ring->xsk_tx_completion = vsi->xsk_ctxs[qid]->tx_comp; + xdp_ring->get_packet = vsi->xsk_ctxs[qid]->get_tx_packet; +} +/** * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI * @vsi: the VSI being configured
@@ -10072,10 +10088,13 @@ static int i40e_alloc_rings(struct i40e_vsi *vsi) ring->size =0 ; ring->dcb_tc =0 ; ring->clean_tx = i40e_xdp_clean_tx_irq; + ring->xdp_tx_completion.func = i40e_xdp_tx_completion; + ring->xdp_tx_completion.ctx1 = (unsigned long )ring;if (vsi->back->hw_features &I40E_HW_WB_ON_ITR_CAPABLE ) ring->flags =I40E_TXR_FLAGS_WB_ON_ITR ;set_ring_xdp (ring); ring->tx_itr_setting = pf->tx_itr_default; +i40e_restore_xsk_tx (vsi, i, ring); vsi->xdp_rings[i] = ring++; setup_rx:
@@ -11985,8 +12004,54 @@ static void i40e_remove_xsk_ctx(struct i40e_vsi *vsi, int queue_id)i40e_free_xsk_ctxs_if_last (vsi); } -static int i40e_xsk_enable (struct net_device *netdev,u32 qid, -struct xsk_rx_parms *parms) +static int i40e_xsk_tx_enable (struct i40e_vsi *vsi,u32 qid, +struct xsk_tx_parms *parms) +{ +struct i40e_ring *xdp_ring =NULL ; +int err; + +if (qid >= vsi->num_queue_pairs) +return -EINVAL ; + +if (!parms->tx_completion || !parms->get_tx_packet) +return -EINVAL ; + + err = parms->dma_map (parms->buff_pool, &vsi->back->pdev->dev, +DMA_TO_DEVICE ,0 ); +if (err) +return err; + + vsi->xsk_ctxs[qid]->tx_comp.func = parms->tx_completion; + vsi->xsk_ctxs[qid]->tx_comp.ctx1 = parms->ctx1; + vsi->xsk_ctxs[qid]->tx_comp.ctx2 = parms->ctx2; + vsi->xsk_ctxs[qid]->get_tx_packet = parms->get_tx_packet; + +if (i40e_enabled_xdp_vsi (vsi)) { + xdp_ring = vsi->tx_rings[qid + vsi->alloc_queue_pairs]; + xdp_ring->xsk_tx_completion.func = parms->tx_completion; + xdp_ring->xsk_tx_completion.ctx1 = parms->ctx1; + xdp_ring->xsk_tx_completion.ctx2 = parms->ctx2; + xdp_ring->get_packet = parms->get_tx_packet; + } + +return 0 ; +} + +static void i40e_xsk_tx_disable (struct i40e_vsi *vsi,u32 queue_id) +{ +struct i40e_ring *xdp_ring; + +if (i40e_enabled_xdp_vsi (vsi)) { + xdp_ring = vsi->tx_rings[queue_id + vsi->alloc_queue_pairs]; + xdp_ring->xsk_tx_completion.func =NULL ; + xdp_ring->xsk_tx_completion.ctx1 =0 ; + xdp_ring->xsk_tx_completion.ctx2 =0 ; + xdp_ring->get_packet =NULL ; + } +} + +static int i40e_xsk_rx_enable (struct net_device *netdev,u32 qid, +struct xsk_rx_parms *parms) {struct i40e_netdev_priv *np =netdev_priv (netdev);struct i40e_vsi *vsi = np->vsi;
@@ -12029,8 +12094,8 @@ static int i40e_xsk_enable(struct net_device *netdev, u32 qid,return 0 ; } -static int i40e_xsk_disable (struct net_device *netdev,u32 qid, -struct xsk_rx_parms *parms) +static int i40e_xsk_rx_disable (struct net_device *netdev,u32 qid, +struct xsk_rx_parms *parms) {struct i40e_netdev_priv *np =netdev_priv (netdev);struct i40e_vsi *vsi = np->vsi;
@@ -12069,6 +12134,7 @@ static int i40e_xdp(struct net_device *dev, {struct i40e_netdev_priv *np =netdev_priv (dev);struct i40e_vsi *vsi = np->vsi; +int err;if (vsi->type !=I40E_VSI_MAIN )return -EINVAL ;
@@ -12081,11 +12147,14 @@ static int i40e_xdp(struct net_device *dev, xdp->prog_id = vsi->xdp_prog ? vsi->xdp_prog->aux->id :0 ;return 0 ;case XDP_REGISTER_XSK : -return i40e_xsk_enable (dev, xdp->xsk.queue_id, - xdp->xsk.rx_parms); + err =i40e_xsk_rx_enable (dev, xdp->xsk.queue_id, + xdp->xsk.rx_parms); +return err ?:i40e_xsk_tx_enable (vsi, xdp->xsk.queue_id, + xdp->xsk.tx_parms);case XDP_UNREGISTER_XSK : -return i40e_xsk_disable (dev, xdp->xsk.queue_id, - xdp->xsk.rx_parms); +i40e_xsk_tx_disable (vsi, xdp->xsk.queue_id); +return i40e_xsk_rx_disable (dev, xdp->xsk.queue_id, + xdp->xsk.rx_parms);default :return -EINVAL ; }
@@ -12125,6 +12194,7 @@ static const struct net_device_ops i40e_netdev_ops = { .ndo_bridge_setlink = i40e_ndo_bridge_setlink, .ndo_bpf = i40e_xdp, .ndo_xdp_xmit = i40e_xdp_xmit, + .ndo_xdp_xmit_xsk = i40e_xdp_xmit_xsk, .ndo_xdp_flush = i40e_xdp_flush, };
drivers/net/ethernet/intel/i40e/i40e_txrx.c +162 -56
338 lines not on this page · raw message
drivers/net/ethernet/intel/i40e/i40e_txrx.h +15 -3
@@ -253,17 +253,21 @@ typedef int (*get_tx_packet_func)(struct net_device *dev, u32 queue_id, dma_addr_t *dma, void **data, u32 *len, u32 *offset); +struct i40e_tx_completion { +tx_completion_func func; +unsigned long ctx1; +unsigned long ctx2; +}; +struct i40e_tx_buffer {struct i40e_tx_desc *next_to_watch;union {struct sk_buff *skb;void *raw_buf; }; +struct i40e_tx_completion *completion;unsigned int bytecount;unsigned short gso_segs; -tx_completion_func completion; -unsigned long ctx1; -unsigned long ctx2;DEFINE_DMA_UNMAP_ADDR (dma);DEFINE_DMA_UNMAP_LEN (len);
@@ -306,6 +310,8 @@ struct i40e_xsk_ctx {struct buff_pool *buff_pool;void *err_ctx;void (*err_handler)(void *ctx,int errno); +struct i40e_tx_completion tx_comp; +get_tx_packet_func get_tx_packet; };/* some useful defines for virtchannel interface, which
@@ -395,6 +401,9 @@ struct i40e_ring {struct i40e_xsk_ctx *xsk;bool (*clean_tx)(struct i40e_vsi *vsi,struct i40e_ring *tx_ring,int napi_budget); +get_tx_packet_func get_packet; +struct i40e_tx_completion xdp_tx_completion; +struct i40e_tx_completion xsk_tx_completion; }____cacheline_internodealigned_in_smp ;static inline bool ring_uses_build_skb (struct i40e_ring *ring)
@@ -484,11 +493,14 @@ void i40e_detect_recover_hung(struct i40e_vsi *vsi);int __i40e_maybe_stop_tx (struct i40e_ring *tx_ring,int size);bool __i40e_chk_linearize (struct sk_buff *skb);int i40e_xdp_xmit (struct net_device *dev,struct xdp_buff *xdp); +int i40e_xdp_xmit_xsk (struct net_device *dev,u32 queue_id);void i40e_xdp_flush (struct net_device *dev);bool i40e_clean_tx_irq (struct i40e_vsi *vsi,struct i40e_ring *tx_ring,int napi_budget);bool i40e_xdp_clean_tx_irq (struct i40e_vsi *vsi,struct i40e_ring *tx_ring,int napi_budget); +void i40e_xdp_tx_completion (u32 start,u32 npackets, +unsigned long ctx1,unsigned long ctx2);/** * i40e_get_head - Retrieve head from head writeback
Signature · 1 line
2.14.1
Quoted 8 lines · On Wed, 31 Jan 2018 14:53:32 +0100 Björn Töpel <[email protected]> wrote:
* In this RFC, do not use an
XDP_REDIRECTaction other thanbpf_xdpsk_redirectforXDP_DRV_ZC. This is because a zero-copy allocated buffer will then be sent to a cpu id /queue_pairthroughndo_xdp_xmitthat does not know this has been ZC allocated. It will then do apage_freeon it and you will get a crash. How to extendndo_xdp_xmitwith some free/completion function that could be called instead ofpage_free? Hopefully, the same solution can be used here as in the first problem item in this section.
I'm prototype-coding extending ndo_xdp_xmit with a free/completion function call, that look at the xdp_rxq_info to determine what allocator type the RX-NIC used (info per RXq), and invoke the appropriate callback.
I dusted off my old page_pool implementation (modifying it to run outside page-allocator). Implemented XDP_REDIRECT for mlx5, and extended xdp_rxq_info, and stored needed info in ixgbe for DMA TX completion. Disabled the mlx5 page cache, and instead use the page_pool.
It worked surprisingly well... test is: pktgen on mlx5 100Gbit/s NIC, and XDP_REDIRECT with xdp_redirect_map sample, out 10G ixgbe NIC.
Performance is surprisingly good... Testing DMA-TX completion on ixgbe, that calls "xdp_return_frame", which is mapped to page_pool_put_page(pool, page); Here DMA-TX-completion runs on CPU#3 and mlx5 RX runs on CPU#0. (Internally page_pool uses ptr_ring, which is what gives the good cross CPU performance).
Show adapter(s) (ixgbe2 mlx5p2) statistics (ONLY that changed!)
Ethtool(ixgbe2 ) stat: 810562253 ( 810,562,253) <= tx_bytes /sec Ethtool(ixgbe2 ) stat: 864600261 ( 864,600,261) <= tx_bytes_nic /sec Ethtool(ixgbe2 ) stat: 13509371 ( 13,509,371) <= tx_packets /sec Ethtool(ixgbe2 ) stat: 13509380 ( 13,509,380) <= tx_pkts_nic /sec Ethtool(mlx5p2 ) stat: 36827369 ( 36,827,369) <= rx_64_bytes_phy /sec Ethtool(mlx5p2 ) stat: 2356953271 ( 2,356,953,271) <= rx_bytes_phy /sec Ethtool(mlx5p2 ) stat: 23313782 ( 23,313,782) <= rx_discards_phy /sec Ethtool(mlx5p2 ) stat: 3019 ( 3,019) <= rx_out_of_buffer /sec Ethtool(mlx5p2 ) stat: 36827395 ( 36,827,395) <= rx_packets_phy /sec Ethtool(mlx5p2 ) stat: 2356924099 ( 2,356,924,099) <= rx_prio0_bytes /sec Ethtool(mlx5p2 ) stat: 13513560 ( 13,513,560) <= rx_prio0_packets /sec Ethtool(mlx5p2 ) stat: 810820253 ( 810,820,253) <= rx_vport_unicast_bytes /sec Ethtool(mlx5p2 ) stat: 13513672 ( 13,513,672) <= rx_vport_unicast_packets /sec
If I only disabled the mlx5 page cache (no page_pool), then single flow performance was 6Mpps, and if I started two flows the collective performance drop to 4Mpps, because we hit the page allocator lock (further negative scaling occurs).
If I keep the mlx5 cache, I see between 7-11Mpps... which varies depending on ixgbe TX-ring size and DMA-completion interrupt levels.
For AF_XDP, we just register another free/completion callback function.
Signature · 4 lines
Best regards, Jesper Dangaard Brouer MSc.CS, Principal Kernel Engineer at Red Hat LinkedIn: http://www.linkedin.com/in/brouer
Quoted 12 lines · On Wed, 31 Jan 2018 14:53:32 +0100 Björn Töpel <[email protected]> wrote:
Below are the results in Mpps of the I40E NIC benchmark runs for 64 byte packets, generated by commercial packet generator HW that is generating packets at full 40 Gbit/s line rate.
XDP baseline numbers without this RFC:
xdp_rxq_info--actionXDP_DROP31.3 Mppsxdp_rxq_info--actionXDP_TX16.7 MppsXDP performance with this RFC i.e. with the buffer allocator:
XDP_DROP21.0 MppsXDP_TX11.9 Mpps
Quoted 5 lines
AF_PACKETV4 performance from previous RFC on 4.14-rc7:Benchmark V2 V3 V4 V4+ZC rxdrop 0.67 0.73 0.74 33.7 txpush 0.98 0.98 0.91 19.6 l2fwd 0.66 0.71 0.67 15.5
My numbers from before:
V4+ZC rxdrop 35.2 Mpps txpush 20.7 Mpps l2fwd 16.9 Mpps
Quoted 5 lines
AF_XDPperformance:Benchmark XDP_SKB XDP_DRV XDP_DRV_ZC (all in Mpps) rxdrop 3.3 11.6 16.9 txpush 2.2 NA* 21.8 l2fwd 1.7 NA* 10.4
The numbers on my system are better than your system, and compared to the my-own before results, the txpush is almost the same, and the gap between l2fwd is smaller for me.
The surprise is the drop in the 'rxdrop' performance.
XDP_DRV_ZC
rxdrop 22.0 Mpps txpush 20.9 Mpps l2fwd 14.2 Mpps
BUT is also seems you have generally slowed down the XDP_DROP results for i40e:
Before:
sudo ./xdp_bench01_mem_access_cost --dev i40e1
XDP_DROP 35878204 35,878,204 no_touch
After this patchset:
$ sudo ./xdp_bench01_mem_access_cost --dev i40e1 XDP_action pps pps-human-readable mem XDP_DROP 28992009 28,992,009 no_touch
And if I read data:
sudo ./xdp_bench01_mem_access_cost --dev i40e1 --read
XDP_action pps pps-human-readable mem XDP_DROP 25107793 25,107,793 read
BTW, see you soon in Brussels (FOSDEM18) ...
Signature · 52 lines
Best regards,
Jesper Dangaard Brouer
MSc.CS, Principal Kernel Engineer at Red Hat
LinkedIn: http://www.linkedin.com/in/brouer
$ sudo ./xdpsock --rxdrop --interface=i40e1 --queue=11
[...]
i40e1:11 rxdrop
pps pkts 60.01
rx 22,040,099 1,322,572,352
tx 0 0
$ sudo ./xdpsock --txonly --interface=i40e1 --queue=11
[...]
i40e1:11 txonly
pps pkts 239.03
rx 0 0
tx 20,937,885 5,004,790,500
$ sudo ./xdpsock --l2fwd --interface=i40e1 --queue=11
[...]
i40e1:11 l2fwd
pps pkts 152.02
rx 14,244,719 2,165,460,044
tx 14,244,718 2,165,459,915
My before results:
$ sudo ./bench_all.sh
You might want to change the parameters in ./bench_all.sh
i40e1 cpu5 duration 30s zc 16
i40e1 v2 rxdrop duration 29.27s rx: 62959986pkts @ 2150794.94pps
i40e1 v3 rxdrop duration 29.18s rx: 68470248pkts @ 2346658.86pps
i40e1 v4 rxdrop duration 29.45s rx: 68900864pkts @ 2339633.99pps
i40e1 v4 rxdrop zc duration 29.36s rx: 1033722048pkts @ 35206198.62pps
i40e1 v2 txonly duration 29.16s tx: 63272640pkts @ 2169632.53pps.
i40e1 v3 txonly duration 29.14s tx: 62531968pkts @ 2145714.21pps.
i40e1 v4 txonly duration 29.48s tx: 40587316pkts @ 1376761.87pps.
i40e1 v4 txonly zc duration 29.36s tx: 608794761pkts @ 20738953.62pps.
i40e1 v2 l2fwd duration 29.19s rx: 57532736pkts @ 1970885.56pps
tx 57532672pkts @ 1970883.37pps.
i40e1 v3 l2fwd duration 29.16s rx: 57675961pkts @ 1978149.64pps
tx: 57675897pkts @ 1978147.44pps.
i40e1 v4 l2fwd duration 29.51s rx: 29732pkts @ 1007.58pps
tx: 28708pkts @ 972.88pps.
i40e1 v4 l2fwd zc duration 29.32s rx: 497528256pkts @ 16969091.01pps
tx: 497527296pkts @ 16969058.27pps.2018-01-31 14:53 GMT+01:00 Björn Töpel <[email protected]>:
Quoted 30 lines
From: Björn Töpel <[email protected]>
This RFC introduces a new address family called
AF_XDPthat is optimized for high performance packet processing and zero-copy semantics. Throughput improvements can be up to 20x compared to V2 and V3 for the micro benchmarks included. Would be great to get your feedback on it. Note that this is the follow up RFC toAF_PACKETV4 from November last year. The feedback from that RFC submission and the presentation at NetdevConf in Seoul was to create a new address family instead of building on top ofAF_PACKET.AF_XDPis this new address family.The main difference between
AF_XDPandAF_PACKETV2/V3 on a descriptor level is that TX and RX descriptors are separated from packet buffers. An RX or TX descriptor points to a data buffer in a packet buffer area. RX and TX can share the same packet buffer so that a packet does not have to be copied between RX and TX. Moreover, if a packet needs to be kept for a while due to a possible retransmit, then the descriptor that points to that packet buffer can be changed to point to another buffer and reused right away. This again avoids copying data.The RX and TX descriptor rings are registered with the setsockopts
XDP_RX_RINGandXDP_TX_RING, similar toAF_PACKET. The packet buffer area is allocated by user space and registered with the kernel using the newXDP_MEM_REGsetsockopt. All these three areas are shared between user space and kernel space. The socket is then bound with abind()call to a device and a specific queue id on that device, and it is not until bind is completed that traffic starts to flow.
Quoted 11 lines
An XDP program can be loaded to direct part of the traffic on that device and queue id to user space through a new redirect action in an XDP program called
bpf_xdpsk_redirectthat redirects a packet up to the socket in user space. All the other XDP actions work just as before. Note that the current RFC requires the user to load an XDP program to get any traffic to user space (for example all traffic to user space with the one-liner program "returnbpf_xdpsk_redirect();"). We plan on introducing a patch that removes this requirement and sends all traffic from a queue to user space if anAF_XDPsocket is bound to it.
We realized, a bit late maybe, that 24 patches is a bit mouthful, so let me try to make it more palatable.
Patch 1 to 7 introduce AF_XDP socket support with copy semantics (require no driver changes). Patch 8 adds XDP_REDIRECT support to i40e and patch 9 is the test application.
The rest of the patches are enabling zero-copy support, and they're messier. So, if you don't really care about zero-copy, just have a look at 1 to 7.
We'd really appreciate your thoughts on the user space APIs (including the bpf APIs).
For the next review, we'll keep the set smaller, and introduce many of the i40e patches as pre-patches.
Björn
Quoted 353 lines
AF_XDPcan operate in three different modes:XDP_SKB,XDP_DRV, andXDP_DRV_ZC(shorthand forXDP_DRVwith a zero-copy allocator as there is no specific mode calledXDP_DRV_ZC). If the driver does not have support for XDP, orXDP_SKBis explicitly chosen when loading the XDP program,XDP_SKBmode is employed that uses SKBs together with the generic XDP support and copies out the data to user space. A fallback mode that works for any network device. On the other hand, if the driver has support for XDP (all three NDOs:ndo_bpf,ndo_xdp_xmitandndo_xdp_flush), these NDOs, without any modifications, will be used by theAF_XDPcode to provide better performance, but there is still a copy of the data into user space. The last mode,XDP_DRV_ZC, is XDP driver support with the zero-copy user space allocator that provides even better performance. In this mode, the networking HW (or SW driver if it is a virtual driver like veth) DMAs/puts packets straight into the packet buffer that is shared between user space and kernel space. The RX and TX descriptor queues of the networking HW are NOT shared to user space. Only the kernel can read and write these and it is the kernel driver's responsibility to translate these HW specific descriptors to the HW agnostic ones in the virtual descriptor rings that user space sees. This way, a malicious user space program cannot mess with the networking HW. This mode though requires some extensions to XDP.To get the
XDP_DRV_ZCmode to work for RX, we chose to introduce a buffer pool concept so that the same XDP driver code can be used for buffers allocated using the page allocator (XDP_DRV), the user-space zero-copy allocator (XDP_DRV_ZC), or some internal driver specific allocator/cache/recycling mechanism. Thendo_bpfcall has also been extended with two commands for registering and unregistering an XSK socket and is in the RX case mainly used to communicate some information about the user-space buffer pool to the driver.For the TX path, our plan was to use
ndo_xdp_xmitandndo_xdp_flush, but we run into problems with this (further discussion in the challenges section) and had to introduce a new NDO calledndo_xdp_xmit_xsk(xsk = XDP socket). It takes a pointer to a netdevice and an explicit queue id that packets should be sent out on. In contrast tondo_xdp_xmit, it is asynchronous and pulls packets to be sent from the xdp socket (associated with the dev and queue combination that was provided with the NDO call) using a callback (get_tx_packet), and when they have been transmitted it uses another callback (tx_completion) to signal completion of packets. These callbacks are set viando_bpfin the newXDP_REGISTER_XSKcommand.ndo_xdp_xmit_xskis exclusively used by the XDP socket code and thus does not clash with theXDP_REDIRECTuse ofndo_xdp_xmit. This is one of the reasons that theXDP_DRVmode (without ZC) is currently not supported by TX. Please have a look at the challenges section for further discussions.The
AF_XDPbind call acts on a queue pair (channel in ethtool speak), so the user needs to steer the traffic to the zero-copy enabled queue pair. Which queue to use, is up to the user.For an untrusted application, HW packet steering to a specific queue pair (the one associated with the application) is a requirement, as the application would otherwise be able to see other user space processes' packets. If the HW cannot support the required packet steering,
XDP_DRVorXDP_SKBmode have to be used as they do not expose the NIC's packet buffer into user space as the packets are copied into user space from the NIC's packet buffer in the kernel.There is a xdpsock benchmarking/test application included. Say that you would like your UDP traffic from port 4242 to end up in queue 16, that we will enable
AF_XDPon. Here, we use ethtool for this:ethtool -N p3p2 rx-flow-hash udp4 fn
ethtool -N p3p2 flow-type udp4 src-port 4242 dst-port 4242 \
action 16Running the l2fwd benchmark in
XDP_DRV_ZCmode can then be done using:samples/bpf/xdpsock -i p3p2 -q 16 -l -NFor
XDP_SKBmode, use the switch "-S" instead of "-N" and all options can be displayed with "-h", as usual.We have run some benchmarks on a dual socket system with two Broadwell E5 2660 @ 2.0 GHz with hyperthreading turned off. Each socket has 14 cores which gives a total of 28, but only two cores are used in these experiments. One for TR/RX and one for the user space application. The memory is DDR4 @ 2133 MT/s (1067 MHz) and the size of each DIMM is 8192MB and with 8 of those DIMMs in the system we have 64 GB of total memory. The compiler used is gcc version 5.4.0 20160609. The NIC is an Intel I40E 40Gbit/s using the i40e driver.
Below are the results in Mpps of the I40E NIC benchmark runs for 64 byte packets, generated by commercial packet generator HW that is generating packets at full 40 Gbit/s line rate.
XDP baseline numbers without this RFC:
xdp_rxq_info--actionXDP_DROP31.3 Mppsxdp_rxq_info--actionXDP_TX16.7 MppsXDP performance with this RFC i.e. with the buffer allocator:
XDP_DROP21.0 MppsXDP_TX11.9 Mpps
AF_PACKETV4 performance from previous RFC on 4.14-rc7:Benchmark V2 V3 V4 V4+ZC rxdrop 0.67 0.73 0.74 33.7 txpush 0.98 0.98 0.91 19.6 l2fwd 0.66 0.71 0.67 15.5
AF_XDPperformance:Benchmark XDP_SKB XDP_DRV XDP_DRV_ZC (all in Mpps) rxdrop 3.3 11.6 16.9 txpush 2.2 NA* 21.8 l2fwd 1.7 NA* 10.4* NA since there is no
XDP_DRVmode (without ZC) for TX in this RFC, see challenges below.If we start by comparing
XDP_SKBperformance with copy mode inAF_PACKETV4, we can see thatAF_XDPdelivers 3-5 times the throughput, which is positive. We are also happy with theXDP_DRVperformance that provides 11.6 Mpps for rxdrop, and should work on any driver implementing full XDP support. Now to the problematic part:XDP_DRV_ZC. The txpush (TX only) benchmark shows decent results at 21.8 Mpps and is better than it was for V4, even though we have spent no time optimizing the code inAF_XDP. (We did that inAF_PACKETV4.) But the RX performance is sliced by half, which is not good. The reason for this is, for the major part, the new buffer allocator which is used for RX ZC only (at this point, see todo section). If you take a look at the XDP baseline numbers, introducing the buffer pool allocator drops the performance by around 30% or 10 Mpps which is obviously not acceptable. We clearly need to give this code some overdue performance love. But the overhanging question is how much overhead it will produce in the end and if this will be acceptable. Another thing to note is that V4 provided 33.7 Mpps for rxdrop, but withAF_XDPwe are quite unlikely to get above theXDP_DROPnumber of 31.3, since we are reusing the XDP infrastructure and driver code on the RX side. So in the end, theAF_XDPXDP_DRV_ZCnumbers will likely be lower than the V4 ZC numbers.We based this patch set on net-next commit
91e6dd828425("ipmr: Fixptrdiff_tprint formatting").Challenges: areas we would really appreciate your help on and that we are having substantial problems with.
* We would like to, if possible, use
ndo_xdp_xmitandndo_xdp_flushinstead of introducing another NDO in the form ofndo_xdp_xmit_xsk. The first reason behind our ineptitude to be able to accomplish this is that if both paths usendo_xdp_xmit, they will create a race asndo_xdp_xmitcurrently does not contain any locking. How to implement some type of mutual exclusion here without resorting to slowing down the NDO with a lock? The second problem is that theXDP_REDIRECTcode implicitly assumes that core id = queue id.AF_XDP, on the other hand, explicitly specifies a queue id that has nothing to do with the core id (the application can run on any core). How to reconcile these two views in one ndo? If these two problems can be solved, then we would still need to introduce a completion callback and aget_packetcallback, but this seems to be less challenging. This would also make it possible to run TX in theXDP_DRVmode (with the default page allocator).* What should the buffer allocator look like and how to make it generic enough so it can be used by all NIC vendors? Would be great if you could take a look at it and come with suggestions. As you can see from the change log, it took some effort to rewire the i40e code to use the buff pool, and we expect the same to be true for many other NICs. Ideas on how to introduce multiple allocator into XDP in a less intrusive way would be highly appreciated. Another question is how to create a buffer pool that gives rise to very little overhead? We do not know if the current one can be optimized to have an acceptable overhead as we have not started any optimization effort. But we will give it a try during the next week or so to see where it leads.
* In this RFC, do not use an
XDP_REDIRECTaction other thanbpf_xdpsk_redirectforXDP_DRV_ZC. This is because a zero-copy allocated buffer will then be sent to a cpu id /queue_pairthroughndo_xdp_xmitthat does not know this has been ZC allocated. It will then do apage_freeon it and you will get a crash. How to extendndo_xdp_xmitwith some free/completion function that could be called instead ofpage_free? Hopefully, the same solution can be used here as in the first problem item in this section.Caveats with this RFC. In contrast to the last section, we believe we have solutions for these but we did not have time to fix them. We chose to show you all the code sooner than later, even though everything does not work. Sorry.
* This RFC is more immature (read, has more bugs) than the
AF_PACKETV4 RFC. Some known mentioned here, others unknown.* We have done absolutely no optimization to this RFC. There is (hopefully) some substantial low hanging fruit that we could fix once we get to this, to improve
XDP_DRV_ZCperformance to levels that we are not ashamed of and also bring the i40e driver to the same performance levels it had before our changes, which is a must.* There is a race in the TX XSK clean up code in the i40e driver that triggers a
WARN_ON_ONCE. Clearly a bug that needs to be fixed. It can be triggered by performing ifdown/ifup when the application is running, or when changing the number of queues of the device underneath the hood of the application. As a workaround, please refrain from doing these two things without restarting the application, as not all buffers will be returned in the TX path. This bug can also be triggered when killing the application, but has no negative effect in this case as the process will never execute again.* Before this RFC,
ndo_xdp_xmittriggered by anXDP_REDIRECTto a NIC never modified the page count, so the redirect code could assume that the page would still be valid after the NDO call. With the introduction of thexsk_rcvpath that is called as a result of anXDP_REDIRECTto anAF_XDPsocket, the page count will be decreased if the page is copied out to user space, since we have no use for it anymore. Our somewhat blunt solution to this is to make sure in the i40e driver that the refcount is never under two. Note though, that with the introduction of the buffer pool, this problem disappears. This also means thatXDP_DRVwill not work out of the box with a Niantic NIC, since it also needs this modification to work. One question that we have is what should the semantics ofndo_xdp_xmitbe? Can we always assume that the page count will never be changed by all possible netdevices that implement this NDO, or should we remove this assumption to gain more device implementation flexibility?To do:
* Optimize performance. No optimization whatsoever was performed on this RFC, in contrast to the previous one for
AF_PACKETV4.* Kernel load module support.
* Polling has not been implemented yet.
* Optimize the user space sample application. It is simple but naive at this point. The one for
AF_PACKETV4 had a number of optimizations that have not been introduced in theAF_XDPversion.* Implement a way to pick the
XDP_DRVmode even ifXDP_DRV_ZCis available. Would be nice to have for the sample application too.* Introduce a notifier chain for queue changes (caused by ethtool for example). This would get rid of the error callback that we have at this point.
* Use one NAPI context for RX and another one for TX in i40e. This would make it possible to run RX on one core and TX on another for better performance. Today, they need to share a single core since they share NAPI context.
* Get rid of packet arrays (PA) and convert them to the buffer pool allocator by transferring the necessary PA functionality into the buffer pool. This has only been done for RX in ZC mode, while all the other modes are still using packet arrays. Clearly, having two structures with largely the same information is not a good thing.
* Support for
AF_XDPsockets without an XPD program loaded. In this case all the traffic on a queue should go up to user space.* Support shared packet buffers
* Support for packets spanning multiple frames
Thanks: Björn and Magnus
Björn Töpel (16):
xsk:AF_XDPsockets buildable skeleton
xsk: add user memory registration sockopt
xsk: added XDP_{R,T}X_RING sockopt and supporting structures
bpf: addedbpf_xdpsk_redirect
net: wire up xsk support in theXDP_REDIRECTpath
i40e: add support forXDP_REDIRECT
samples/bpf: added xdpsock program
xsk: add iterator functions toxsk_ring
i40e: introduce external allocator support
i40e: implemented page recyclingbuff_pool
i40e: start using recyclingbuff_pool
i40e: separatedbuff_poolinterface from i40e implementaion
xsk: introducexsk_buff_pool
xdp: addedbuff_poolsupport to structxdp_buff
xsk: add support for zero copy Rx
i40e: implement xsk sub-commands inndo_bpffor zero copy RxMagnus Karlsson (8):
xsk: add bind support and introduce Rx functionality
xsk: introduce Tx functionality
netdevice: added XDP_{UN,}REGISTER_XSK command tondo_bpf
netdevice: added ndo for transmitting a packet from an XDP socket
xsk: add support for zero copy Tx
i40e: introduced aclean_txcallback function
i40e: introduced Tx completion callbacks
i40e: Tx support for zero copy allocatordrivers/net/ethernet/intel/i40e/Makefile | 3 +- drivers/net/ethernet/intel/i40e/i40e.h | 24 + drivers/net/ethernet/intel/i40e/i40e_buff_pool.c | 580 +++++++++++ drivers/net/ethernet/intel/i40e/i40e_buff_pool.h | 15 + drivers/net/ethernet/intel/i40e/i40e_ethtool.c | 1 - drivers/net/ethernet/intel/i40e/i40e_main.c | 541 +++++++++- drivers/net/ethernet/intel/i40e/i40e_txrx.c | 906 +++++++++-------- drivers/net/ethernet/intel/i40e/i40e_txrx.h | 119 ++- include/linux/buff_pool.h | 136 +++ include/linux/filter.h | 3 +- include/linux/netdevice.h | 25 + include/linux/socket.h | 5 +- include/net/xdp.h | 1 + include/net/xdp_sock.h | 60 ++ include/uapi/linux/bpf.h | 6 +- include/uapi/linux/if_xdp.h | 72 ++ net/Kconfig | 1 + net/Makefile | 1 + net/core/dev.c | 28 +- net/core/filter.c | 88 +- net/core/sock.c | 12 +- net/xdp/Kconfig | 7 + net/xdp/Makefile | 1 + net/xdp/xsk.c | 1142 ++++++++++++++++++++++ net/xdp/xsk.h | 31 + net/xdp/xsk_buff.h | 161 +++ net/xdp/xsk_buff_pool.c | 225 +++++ net/xdp/xsk_buff_pool.h | 17 + net/xdp/xsk_packet_array.c | 62 ++ net/xdp/xsk_packet_array.h | 399 ++++++++ net/xdp/xsk_ring.c | 61 ++ net/xdp/xsk_ring.h | 419 ++++++++ net/xdp/xsk_user_queue.h | 24 + samples/bpf/Makefile | 4 + samples/bpf/xdpsock_kern.c | 11 + samples/bpf/xdpsock_queue.h | 62 ++ samples/bpf/xdpsock_user.c | 642 ++++++++++++ security/selinux/hooks.c | 4 +- security/selinux/include/classmap.h | 4 +- tools/testing/selftests/bpf/bpf_helpers.h | 2 + 40 files changed, 5408 insertions(+), 497 deletions(-) create mode 100644 drivers/net/ethernet/intel/i40e/i40e_buff_pool.c create mode 100644 drivers/net/ethernet/intel/i40e/i40e_buff_pool.h create mode 100644 include/linux/buff_pool.h create mode 100644 include/net/xdp_sock.h create mode 100644 include/uapi/linux/if_xdp.h create mode 100644 net/xdp/Kconfig create mode 100644 net/xdp/Makefile create mode 100644 net/xdp/xsk.c create mode 100644 net/xdp/xsk.h create mode 100644 net/xdp/xsk_buff.h create mode 100644 net/xdp/xsk_buff_pool.c create mode 100644 net/xdp/xsk_buff_pool.h create mode 100644 net/xdp/xsk_packet_array.c create mode 100644 net/xdp/xsk_packet_array.h create mode 100644 net/xdp/xsk_ring.c create mode 100644 net/xdp/xsk_ring.h create mode 100644 net/xdp/xsk_user_queue.h create mode 100644 samples/bpf/xdpsock_kern.c create mode 100644 samples/bpf/xdpsock_queue.h create mode 100644 samples/bpf/xdpsock_user.c--
2.14.1
Quoted 2 lines
We realized, a bit late maybe, that 24 patches is a bit mouthful, so let me try to make it more palatable.
Overall, this approach looks great to me.
The patch set incorporates all the feedback from AF_PACKET V4. At this point I don't have additional high-level interface comments.
As you point out, 24 patches and nearly 6000 changed lines is quite a bit to ingest. Splitting up in smaller patch sets will help give more detailed implementation feedback.
The frame pool and device driver changes are largely independent from AF_XDP and probably should be resolved first (esp. the observed regresssion even without AF_XDP).
As you suggest, it would be great if the need for a separate xsk_packet_array data structure can be avoided.
Since frames from the same frame pool can be forwarded between multiple device ports and thus AF_XDP sockets, that should perhaps be a separate object independent from the sockets. This comment hints at the awkward situation if tied to a descriptor pair:
Review
Quoted 3 lines
(quoted diff) +3
-0+ /* Check if umem is from this socket, if so do not make + * circular references. + */
Since this is in principle just a large shared memory area, could it reuse existing BPF map logic?
More extreme, and perhaps unrealistic, is if the descriptor ring could similarly be a BPF map and the Rx XDP program directly writes the descriptor, instead of triggering xdp_do_xsk_redirect. As we discussed before, this would avoid the need to specify a descriptor format upfront.
2018-02-07 16:54 GMT+01:00 Willem de Bruijn <[email protected]>:
Quoted 5 lines
Quoted 2 lines
We realized, a bit late maybe, that 24 patches is a bit mouthful, so let me try to make it more palatable.
Overall, this approach looks great to me.
Yay! :-)
Quoted 3 lines
The patch set incorporates all the feedback from
AF_PACKETV4. At this point I don't have additional high-level interface comments.
I have a thought on the socket API. Now, we're registering buffer memory *to* the kernel, but mmap:ing the Rx/Tx rings *from* the kernel. I'm leaning towards removing the mmap call, in favor of registering the rings to kernel analogous to the XDP_MEM_REG socket option. We wont guarantee physical contiguous memory for the rings, but I think we can live with that. Thoughts?
Quoted 8 lines
As you point out, 24 patches and nearly 6000 changed lines is quite a bit to ingest. Splitting up in smaller patch sets will help give more detailed implementation feedback.
The frame pool and device driver changes are largely independent from
AF_XDPand probably should be resolved first (esp. the observed regresssion even withoutAF_XDP).
Yeah, the regression is unacceptable.
Another way is starting with the patches without zero-copy first (i.e. the copy path), and later add the driver modifications. That would be the first 7 patches.
Quoted 3 lines
As you suggest, it would be great if the need for a separate
xsk_packet_arraydata structure can be avoided.
Yes, we'll address that!
Quoted 5 lines
Since frames from the same frame pool can be forwarded between multiple device ports and thus
AF_XDPsockets, that should perhaps be a separate object independent from the sockets. This comment hints at the awkward situation if tied to a descriptor pair:
Quoted 7 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ /* Check if umem is from this socket, if so do not make + * circular references. + */Since this is in principle just a large shared memory area, could it reuse existing BPF map logic?
Hmm, care to elaborate on your thinking here?
Quoted 5 lines
More extreme, and perhaps unrealistic, is if the descriptor ring could similarly be a BPF map and the Rx XDP program directly writes the descriptor, instead of triggering
xdp_do_xsk_redirect. As we discussed before, this would avoid the need to specify a descriptor format upfront.
Having the XDP program writeback the descriptor to user space ring is really something that would be useful (writing a virtio-net descriptors...). I need to think a bit more about this. :-) Please share your ideas!
Thanks for looking into the patches!
Björn
Quoted 50 lines · Björn Töpel
2018-02-07 16:54 GMT+01:00 Willem de Bruijn <[email protected]>:
Quoted 5 lines
Quoted 2 lines
We realized, a bit late maybe, that 24 patches is a bit mouthful, so let me try to make it more palatable.
Overall, this approach looks great to me.
Yay! :-)
Quoted 3 lines
The patch set incorporates all the feedback from
AF_PACKETV4. At this point I don't have additional high-level interface comments.I have a thought on the socket API. Now, we're registering buffer memory *to* the kernel, but mmap:ing the Rx/Tx rings *from* the kernel. I'm leaning towards removing the mmap call, in favor of registering the rings to kernel analogous to the
XDP_MEM_REGsocket option. We wont guarantee physical contiguous memory for the rings, but I think we can live with that. Thoughts?Quoted 8 lines
As you point out, 24 patches and nearly 6000 changed lines is quite a bit to ingest. Splitting up in smaller patch sets will help give more detailed implementation feedback.
The frame pool and device driver changes are largely independent from
AF_XDPand probably should be resolved first (esp. the observed regresssion even withoutAF_XDP).Yeah, the regression is unacceptable.
Another way is starting with the patches without zero-copy first (i.e. the copy path), and later add the driver modifications. That would be the first 7 patches.
Quoted 3 lines
As you suggest, it would be great if the need for a separate
xsk_packet_arraydata structure can be avoided.Yes, we'll address that!
Quoted 9 lines
Since frames from the same frame pool can be forwarded between multiple device ports and thus
AF_XDPsockets, that should perhaps be a separate object independent from the sockets. This comment hints at the awkward situation if tied to a descriptor pair:Quoted 3 lines
(quoted diff) +3
-0+ /* Check if umem is from this socket, if so do not make + * circular references. + */
Quoted 5 lines
Quoted 3 lines
Since this is in principle just a large shared memory area, could it reuse existing BPF map logic?
Hmm, care to elaborate on your thinking here?
On second thought, that is not workable. I was thinking of reusing existing mmap support for maps, but that is limited to the perf ring buffer.
Quoted 9 lines
Quoted 5 lines
More extreme, and perhaps unrealistic, is if the descriptor ring could similarly be a BPF map and the Rx XDP program directly writes the descriptor, instead of triggering
xdp_do_xsk_redirect. As we discussed before, this would avoid the need to specify a descriptor format upfront.Having the XDP program writeback the descriptor to user space ring is really something that would be useful (writing a virtio-net descriptors...).
Yes, that's a great use case. This ties in with Jason Wang's presentation on XDP with tap and virtio, too.
https://www.netdevconf.org/2.2/slides/wang-vmperformance-talk.pdf
Quoted 7 lines
I need to think a bit more about this. :-) Please
share your ideas!Thanks for looking into the patches!
Björn
Quoted 144 lines · Björn Töpel
From: Björn Töpel <[email protected]>
This RFC introduces a new address family called
AF_XDPthat is optimized for high performance packet processing and zero-copy semantics. Throughput improvements can be up to 20x compared to V2 and V3 for the micro benchmarks included. Would be great to get your feedback on it. Note that this is the follow up RFC toAF_PACKETV4 from November last year. The feedback from that RFC submission and the presentation at NetdevConf in Seoul was to create a new address family instead of building on top ofAF_PACKET.AF_XDPis this new address family.The main difference between
AF_XDPandAF_PACKETV2/V3 on a descriptor level is that TX and RX descriptors are separated from packet buffers. An RX or TX descriptor points to a data buffer in a packet buffer area. RX and TX can share the same packet buffer so that a packet does not have to be copied between RX and TX. Moreover, if a packet needs to be kept for a while due to a possible retransmit, then the descriptor that points to that packet buffer can be changed to point to another buffer and reused right away. This again avoids copying data.The RX and TX descriptor rings are registered with the setsockopts
XDP_RX_RINGandXDP_TX_RING, similar toAF_PACKET. The packet buffer area is allocated by user space and registered with the kernel using the newXDP_MEM_REGsetsockopt. All these three areas are shared between user space and kernel space. The socket is then bound with abind()call to a device and a specific queue id on that device, and it is not until bind is completed that traffic starts to flow.An XDP program can be loaded to direct part of the traffic on that device and queue id to user space through a new redirect action in an XDP program called
bpf_xdpsk_redirectthat redirects a packet up to the socket in user space. All the other XDP actions work just as before. Note that the current RFC requires the user to load an XDP program to get any traffic to user space (for example all traffic to user space with the one-liner program "returnbpf_xdpsk_redirect();"). We plan on introducing a patch that removes this requirement and sends all traffic from a queue to user space if anAF_XDPsocket is bound to it.
AF_XDPcan operate in three different modes:XDP_SKB,XDP_DRV, andXDP_DRV_ZC(shorthand forXDP_DRVwith a zero-copy allocator as there is no specific mode calledXDP_DRV_ZC). If the driver does not have support for XDP, orXDP_SKBis explicitly chosen when loading the XDP program,XDP_SKBmode is employed that uses SKBs together with the generic XDP support and copies out the data to user space. A fallback mode that works for any network device. On the other hand, if the driver has support for XDP (all three NDOs:ndo_bpf,ndo_xdp_xmitandndo_xdp_flush), these NDOs, without any modifications, will be used by theAF_XDPcode to provide better performance, but there is still a copy of the data into user space. The last mode,XDP_DRV_ZC, is XDP driver support with the zero-copy user space allocator that provides even better performance. In this mode, the networking HW (or SW driver if it is a virtual driver like veth) DMAs/puts packets straight into the packet buffer that is shared between user space and kernel space. The RX and TX descriptor queues of the networking HW are NOT shared to user space. Only the kernel can read and write these and it is the kernel driver's responsibility to translate these HW specific descriptors to the HW agnostic ones in the virtual descriptor rings that user space sees. This way, a malicious user space program cannot mess with the networking HW. This mode though requires some extensions to XDP.To get the
XDP_DRV_ZCmode to work for RX, we chose to introduce a buffer pool concept so that the same XDP driver code can be used for buffers allocated using the page allocator (XDP_DRV), the user-space zero-copy allocator (XDP_DRV_ZC), or some internal driver specific allocator/cache/recycling mechanism. Thendo_bpfcall has also been extended with two commands for registering and unregistering an XSK socket and is in the RX case mainly used to communicate some information about the user-space buffer pool to the driver.For the TX path, our plan was to use
ndo_xdp_xmitandndo_xdp_flush, but we run into problems with this (further discussion in the challenges section) and had to introduce a new NDO calledndo_xdp_xmit_xsk(xsk = XDP socket). It takes a pointer to a netdevice and an explicit queue id that packets should be sent out on. In contrast tondo_xdp_xmit, it is asynchronous and pulls packets to be sent from the xdp socket (associated with the dev and queue combination that was provided with the NDO call) using a callback (get_tx_packet), and when they have been transmitted it uses another callback (tx_completion) to signal completion of packets. These callbacks are set viando_bpfin the newXDP_REGISTER_XSKcommand.ndo_xdp_xmit_xskis exclusively used by the XDP socket code and thus does not clash with theXDP_REDIRECTuse ofndo_xdp_xmit. This is one of the reasons that theXDP_DRVmode (without ZC) is currently not supported by TX. Please have a look at the challenges section for further discussions.The
AF_XDPbind call acts on a queue pair (channel in ethtool speak), so the user needs to steer the traffic to the zero-copy enabled queue pair. Which queue to use, is up to the user.For an untrusted application, HW packet steering to a specific queue pair (the one associated with the application) is a requirement, as the application would otherwise be able to see other user space processes' packets. If the HW cannot support the required packet steering,
XDP_DRVorXDP_SKBmode have to be used as they do not expose the NIC's packet buffer into user space as the packets are copied into user space from the NIC's packet buffer in the kernel.There is a xdpsock benchmarking/test application included. Say that you would like your UDP traffic from port 4242 to end up in queue 16, that we will enable
AF_XDPon. Here, we use ethtool for this:ethtool -N p3p2 rx-flow-hash udp4 fn
ethtool -N p3p2 flow-type udp4 src-port 4242 dst-port 4242 \
action 16Running the l2fwd benchmark in
XDP_DRV_ZCmode can then be done using:samples/bpf/xdpsock -i p3p2 -q 16 -l -NFor
XDP_SKBmode, use the switch "-S" instead of "-N" and all options can be displayed with "-h", as usual.We have run some benchmarks on a dual socket system with two Broadwell E5 2660 @ 2.0 GHz with hyperthreading turned off. Each socket has 14 cores which gives a total of 28, but only two cores are used in these experiments. One for TR/RX and one for the user space application. The memory is DDR4 @ 2133 MT/s (1067 MHz) and the size of each DIMM is 8192MB and with 8 of those DIMMs in the system we have 64 GB of total memory. The compiler used is gcc version 5.4.0 20160609. The NIC is an Intel I40E 40Gbit/s using the i40e driver.
Below are the results in Mpps of the I40E NIC benchmark runs for 64 byte packets, generated by commercial packet generator HW that is generating packets at full 40 Gbit/s line rate.
XDP baseline numbers without this RFC:
xdp_rxq_info--actionXDP_DROP31.3 Mppsxdp_rxq_info--actionXDP_TX16.7 MppsXDP performance with this RFC i.e. with the buffer allocator:
XDP_DROP21.0 MppsXDP_TX11.9 Mpps
AF_PACKETV4 performance from previous RFC on 4.14-rc7:Benchmark V2 V3 V4 V4+ZC rxdrop 0.67 0.73 0.74 33.7 txpush 0.98 0.98 0.91 19.6 l2fwd 0.66 0.71 0.67 15.5
Quoted 6 lines
AF_XDPperformance:Benchmark XDP_SKB XDP_DRV XDP_DRV_ZC (all in Mpps) rxdrop 3.3 11.6 16.9 txpush 2.2 NA* 21.8 l2fwd 1.7 NA* 10.4
Hi Bjorn,
This is very impressive work, thank you for contributing it!
For these benchmarks how are the AF_PACKET and AF_XDP numbers to be compared. For instance is rxdpop comparable to XDP_DROP and "xdp_rxq_info --action XDP_DROP"? Given your explanation below, I believe they are, but it might be better to make that clear up front.
Tom
Quoted 244 lines
* NA since there is no
XDP_DRVmode (without ZC) for TX in this RFC, see challenges below.If we start by comparing
XDP_SKBperformance with copy mode inAF_PACKETV4, we can see thatAF_XDPdelivers 3-5 times the throughput, which is positive. We are also happy with theXDP_DRVperformance that provides 11.6 Mpps for rxdrop, and should work on any driver implementing full XDP support. Now to the problematic part:XDP_DRV_ZC. The txpush (TX only) benchmark shows decent results at 21.8 Mpps and is better than it was for V4, even though we have spent no time optimizing the code inAF_XDP. (We did that inAF_PACKETV4.) But the RX performance is sliced by half, which is not good. The reason for this is, for the major part, the new buffer allocator which is used for RX ZC only (at this point, see todo section). If you take a look at the XDP baseline numbers, introducing the buffer pool allocator drops the performance by around 30% or 10 Mpps which is obviously not acceptable. We clearly need to give this code some overdue performance love. But the overhanging question is how much overhead it will produce in the end and if this will be acceptable. Another thing to note is that V4 provided 33.7 Mpps for rxdrop, but withAF_XDPwe are quite unlikely to get above theXDP_DROPnumber of 31.3, since we are reusing the XDP infrastructure and driver code on the RX side. So in the end, theAF_XDPXDP_DRV_ZCnumbers will likely be lower than the V4 ZC numbers.We based this patch set on net-next commit
91e6dd828425("ipmr: Fixptrdiff_tprint formatting").Challenges: areas we would really appreciate your help on and that we are having substantial problems with.
* We would like to, if possible, use
ndo_xdp_xmitandndo_xdp_flushinstead of introducing another NDO in the form ofndo_xdp_xmit_xsk. The first reason behind our ineptitude to be able to accomplish this is that if both paths usendo_xdp_xmit, they will create a race asndo_xdp_xmitcurrently does not contain any locking. How to implement some type of mutual exclusion here without resorting to slowing down the NDO with a lock? The second problem is that theXDP_REDIRECTcode implicitly assumes that core id = queue id.AF_XDP, on the other hand, explicitly specifies a queue id that has nothing to do with the core id (the application can run on any core). How to reconcile these two views in one ndo? If these two problems can be solved, then we would still need to introduce a completion callback and aget_packetcallback, but this seems to be less challenging. This would also make it possible to run TX in theXDP_DRVmode (with the default page allocator).* What should the buffer allocator look like and how to make it generic enough so it can be used by all NIC vendors? Would be great if you could take a look at it and come with suggestions. As you can see from the change log, it took some effort to rewire the i40e code to use the buff pool, and we expect the same to be true for many other NICs. Ideas on how to introduce multiple allocator into XDP in a less intrusive way would be highly appreciated. Another question is how to create a buffer pool that gives rise to very little overhead? We do not know if the current one can be optimized to have an acceptable overhead as we have not started any optimization effort. But we will give it a try during the next week or so to see where it leads.
* In this RFC, do not use an
XDP_REDIRECTaction other thanbpf_xdpsk_redirectforXDP_DRV_ZC. This is because a zero-copy allocated buffer will then be sent to a cpu id /queue_pairthroughndo_xdp_xmitthat does not know this has been ZC allocated. It will then do apage_freeon it and you will get a crash. How to extendndo_xdp_xmitwith some free/completion function that could be called instead ofpage_free? Hopefully, the same solution can be used here as in the first problem item in this section.Caveats with this RFC. In contrast to the last section, we believe we have solutions for these but we did not have time to fix them. We chose to show you all the code sooner than later, even though everything does not work. Sorry.
* This RFC is more immature (read, has more bugs) than the
AF_PACKETV4 RFC. Some known mentioned here, others unknown.* We have done absolutely no optimization to this RFC. There is (hopefully) some substantial low hanging fruit that we could fix once we get to this, to improve
XDP_DRV_ZCperformance to levels that we are not ashamed of and also bring the i40e driver to the same performance levels it had before our changes, which is a must.* There is a race in the TX XSK clean up code in the i40e driver that triggers a
WARN_ON_ONCE. Clearly a bug that needs to be fixed. It can be triggered by performing ifdown/ifup when the application is running, or when changing the number of queues of the device underneath the hood of the application. As a workaround, please refrain from doing these two things without restarting the application, as not all buffers will be returned in the TX path. This bug can also be triggered when killing the application, but has no negative effect in this case as the process will never execute again.* Before this RFC,
ndo_xdp_xmittriggered by anXDP_REDIRECTto a NIC never modified the page count, so the redirect code could assume that the page would still be valid after the NDO call. With the introduction of thexsk_rcvpath that is called as a result of anXDP_REDIRECTto anAF_XDPsocket, the page count will be decreased if the page is copied out to user space, since we have no use for it anymore. Our somewhat blunt solution to this is to make sure in the i40e driver that the refcount is never under two. Note though, that with the introduction of the buffer pool, this problem disappears. This also means thatXDP_DRVwill not work out of the box with a Niantic NIC, since it also needs this modification to work. One question that we have is what should the semantics ofndo_xdp_xmitbe? Can we always assume that the page count will never be changed by all possible netdevices that implement this NDO, or should we remove this assumption to gain more device implementation flexibility?To do:
* Optimize performance. No optimization whatsoever was performed on this RFC, in contrast to the previous one for
AF_PACKETV4.* Kernel load module support.
* Polling has not been implemented yet.
* Optimize the user space sample application. It is simple but naive at this point. The one for
AF_PACKETV4 had a number of optimizations that have not been introduced in theAF_XDPversion.* Implement a way to pick the
XDP_DRVmode even ifXDP_DRV_ZCis available. Would be nice to have for the sample application too.* Introduce a notifier chain for queue changes (caused by ethtool for example). This would get rid of the error callback that we have at this point.
* Use one NAPI context for RX and another one for TX in i40e. This would make it possible to run RX on one core and TX on another for better performance. Today, they need to share a single core since they share NAPI context.
* Get rid of packet arrays (PA) and convert them to the buffer pool allocator by transferring the necessary PA functionality into the buffer pool. This has only been done for RX in ZC mode, while all the other modes are still using packet arrays. Clearly, having two structures with largely the same information is not a good thing.
* Support for
AF_XDPsockets without an XPD program loaded. In this case all the traffic on a queue should go up to user space.* Support shared packet buffers
* Support for packets spanning multiple frames
Thanks: Björn and Magnus
Björn Töpel (16):
xsk:AF_XDPsockets buildable skeleton
xsk: add user memory registration sockopt
xsk: added XDP_{R,T}X_RING sockopt and supporting structures
bpf: addedbpf_xdpsk_redirect
net: wire up xsk support in theXDP_REDIRECTpath
i40e: add support forXDP_REDIRECT
samples/bpf: added xdpsock program
xsk: add iterator functions toxsk_ring
i40e: introduce external allocator support
i40e: implemented page recyclingbuff_pool
i40e: start using recyclingbuff_pool
i40e: separatedbuff_poolinterface from i40e implementaion
xsk: introducexsk_buff_pool
xdp: addedbuff_poolsupport to structxdp_buff
xsk: add support for zero copy Rx
i40e: implement xsk sub-commands inndo_bpffor zero copy RxMagnus Karlsson (8):
xsk: add bind support and introduce Rx functionality
xsk: introduce Tx functionality
netdevice: added XDP_{UN,}REGISTER_XSK command tondo_bpf
netdevice: added ndo for transmitting a packet from an XDP socket
xsk: add support for zero copy Tx
i40e: introduced aclean_txcallback function
i40e: introduced Tx completion callbacks
i40e: Tx support for zero copy allocatordrivers/net/ethernet/intel/i40e/Makefile | 3 +- drivers/net/ethernet/intel/i40e/i40e.h | 24 + drivers/net/ethernet/intel/i40e/i40e_buff_pool.c | 580 +++++++++++ drivers/net/ethernet/intel/i40e/i40e_buff_pool.h | 15 + drivers/net/ethernet/intel/i40e/i40e_ethtool.c | 1 - drivers/net/ethernet/intel/i40e/i40e_main.c | 541 +++++++++- drivers/net/ethernet/intel/i40e/i40e_txrx.c | 906 +++++++++-------- drivers/net/ethernet/intel/i40e/i40e_txrx.h | 119 ++- include/linux/buff_pool.h | 136 +++ include/linux/filter.h | 3 +- include/linux/netdevice.h | 25 + include/linux/socket.h | 5 +- include/net/xdp.h | 1 + include/net/xdp_sock.h | 60 ++ include/uapi/linux/bpf.h | 6 +- include/uapi/linux/if_xdp.h | 72 ++ net/Kconfig | 1 + net/Makefile | 1 + net/core/dev.c | 28 +- net/core/filter.c | 88 +- net/core/sock.c | 12 +- net/xdp/Kconfig | 7 + net/xdp/Makefile | 1 + net/xdp/xsk.c | 1142 ++++++++++++++++++++++ net/xdp/xsk.h | 31 + net/xdp/xsk_buff.h | 161 +++ net/xdp/xsk_buff_pool.c | 225 +++++ net/xdp/xsk_buff_pool.h | 17 + net/xdp/xsk_packet_array.c | 62 ++ net/xdp/xsk_packet_array.h | 399 ++++++++ net/xdp/xsk_ring.c | 61 ++ net/xdp/xsk_ring.h | 419 ++++++++ net/xdp/xsk_user_queue.h | 24 + samples/bpf/Makefile | 4 + samples/bpf/xdpsock_kern.c | 11 + samples/bpf/xdpsock_queue.h | 62 ++ samples/bpf/xdpsock_user.c | 642 ++++++++++++ security/selinux/hooks.c | 4 +- security/selinux/include/classmap.h | 4 +- tools/testing/selftests/bpf/bpf_helpers.h | 2 + 40 files changed, 5408 insertions(+), 497 deletions(-) create mode 100644 drivers/net/ethernet/intel/i40e/i40e_buff_pool.c create mode 100644 drivers/net/ethernet/intel/i40e/i40e_buff_pool.h create mode 100644 include/linux/buff_pool.h create mode 100644 include/net/xdp_sock.h create mode 100644 include/uapi/linux/if_xdp.h create mode 100644 net/xdp/Kconfig create mode 100644 net/xdp/Makefile create mode 100644 net/xdp/xsk.c create mode 100644 net/xdp/xsk.h create mode 100644 net/xdp/xsk_buff.h create mode 100644 net/xdp/xsk_buff_pool.c create mode 100644 net/xdp/xsk_buff_pool.h create mode 100644 net/xdp/xsk_packet_array.c create mode 100644 net/xdp/xsk_packet_array.h create mode 100644 net/xdp/xsk_ring.c create mode 100644 net/xdp/xsk_ring.h create mode 100644 net/xdp/xsk_user_queue.h create mode 100644 samples/bpf/xdpsock_kern.c create mode 100644 samples/bpf/xdpsock_queue.h create mode 100644 samples/bpf/xdpsock_user.c--
2.14.1
2018-02-07 18:59 GMT+01:00 Tom Herbert <[email protected]>:
Quoted 1 line · Björn Töpel
[...]
Quoted 25 lines
Quoted 19 lines
Below are the results in Mpps of the I40E NIC benchmark runs for 64 byte packets, generated by commercial packet generator HW that is generating packets at full 40 Gbit/s line rate.
XDP baseline numbers without this RFC:
xdp_rxq_info--actionXDP_DROP31.3 Mppsxdp_rxq_info--actionXDP_TX16.7 MppsXDP performance with this RFC i.e. with the buffer allocator:
XDP_DROP21.0 MppsXDP_TX11.9 Mpps
AF_PACKETV4 performance from previous RFC on 4.14-rc7:Benchmark V2 V3 V4 V4+ZC rxdrop 0.67 0.73 0.74 33.7 txpush 0.98 0.98 0.91 19.6 l2fwd 0.66 0.71 0.67 15.5Quoted 6 lines
AF_XDPperformance:Benchmark XDP_SKB XDP_DRV XDP_DRV_ZC (all in Mpps) rxdrop 3.3 11.6 16.9 txpush 2.2 NA* 21.8 l2fwd 1.7 NA* 10.4
Quoted 4 lines
Hi Bjorn,
This is very impressive work, thank you for contributing it!
Thank you for looking at it! :-)
Quoted 5 lines
For these benchmarks how are the
AF_PACKETandAF_XDPnumbers to be compared. For instance is rxdpop comparable toXDP_DROPand "xdp_rxq_info--actionXDP_DROP"? Given your explanation below, I believe they are, but it might be better to make that clear up front.
Ah, yeah, that was a bit confusing:
"xdp_rxq_info --action XDP_DROP" is doing an XDP_DROP (no buffer touching) and should be compared to "XDP_DROP". I meant to write "xdp_rxq_info --action XDP_DROP" instead of "XDP_DROP" for the second case.
So, what this shows is that the buffer allocation scheme in the patch set (buff_pool) has a pretty hard performance regression (21.0 vs 31.3) on the regular XDP (and skb!) path. Not acceptable.
"rxdrop" from AF_PACKET V4 should be compared to "rxdrop" from AF_XDP. This is dropping a packet in user space, whereas the former is dropping a packet in XDP/kernel space.
Less confusing?
Björn
Quoted 144 lines · Björn Töpel
From: Björn Töpel <[email protected]>
This RFC introduces a new address family called
AF_XDPthat is optimized for high performance packet processing and zero-copy semantics. Throughput improvements can be up to 20x compared to V2 and V3 for the micro benchmarks included. Would be great to get your feedback on it. Note that this is the follow up RFC toAF_PACKETV4 from November last year. The feedback from that RFC submission and the presentation at NetdevConf in Seoul was to create a new address family instead of building on top ofAF_PACKET.AF_XDPis this new address family.The main difference between
AF_XDPandAF_PACKETV2/V3 on a descriptor level is that TX and RX descriptors are separated from packet buffers. An RX or TX descriptor points to a data buffer in a packet buffer area. RX and TX can share the same packet buffer so that a packet does not have to be copied between RX and TX. Moreover, if a packet needs to be kept for a while due to a possible retransmit, then the descriptor that points to that packet buffer can be changed to point to another buffer and reused right away. This again avoids copying data.The RX and TX descriptor rings are registered with the setsockopts
XDP_RX_RINGandXDP_TX_RING, similar toAF_PACKET. The packet buffer area is allocated by user space and registered with the kernel using the newXDP_MEM_REGsetsockopt. All these three areas are shared between user space and kernel space. The socket is then bound with abind()call to a device and a specific queue id on that device, and it is not until bind is completed that traffic starts to flow.An XDP program can be loaded to direct part of the traffic on that device and queue id to user space through a new redirect action in an XDP program called
bpf_xdpsk_redirectthat redirects a packet up to the socket in user space. All the other XDP actions work just as before. Note that the current RFC requires the user to load an XDP program to get any traffic to user space (for example all traffic to user space with the one-liner program "returnbpf_xdpsk_redirect();"). We plan on introducing a patch that removes this requirement and sends all traffic from a queue to user space if anAF_XDPsocket is bound to it.
AF_XDPcan operate in three different modes:XDP_SKB,XDP_DRV, andXDP_DRV_ZC(shorthand forXDP_DRVwith a zero-copy allocator as there is no specific mode calledXDP_DRV_ZC). If the driver does not have support for XDP, orXDP_SKBis explicitly chosen when loading the XDP program,XDP_SKBmode is employed that uses SKBs together with the generic XDP support and copies out the data to user space. A fallback mode that works for any network device. On the other hand, if the driver has support for XDP (all three NDOs:ndo_bpf,ndo_xdp_xmitandndo_xdp_flush), these NDOs, without any modifications, will be used by theAF_XDPcode to provide better performance, but there is still a copy of the data into user space. The last mode,XDP_DRV_ZC, is XDP driver support with the zero-copy user space allocator that provides even better performance. In this mode, the networking HW (or SW driver if it is a virtual driver like veth) DMAs/puts packets straight into the packet buffer that is shared between user space and kernel space. The RX and TX descriptor queues of the networking HW are NOT shared to user space. Only the kernel can read and write these and it is the kernel driver's responsibility to translate these HW specific descriptors to the HW agnostic ones in the virtual descriptor rings that user space sees. This way, a malicious user space program cannot mess with the networking HW. This mode though requires some extensions to XDP.To get the
XDP_DRV_ZCmode to work for RX, we chose to introduce a buffer pool concept so that the same XDP driver code can be used for buffers allocated using the page allocator (XDP_DRV), the user-space zero-copy allocator (XDP_DRV_ZC), or some internal driver specific allocator/cache/recycling mechanism. Thendo_bpfcall has also been extended with two commands for registering and unregistering an XSK socket and is in the RX case mainly used to communicate some information about the user-space buffer pool to the driver.For the TX path, our plan was to use
ndo_xdp_xmitandndo_xdp_flush, but we run into problems with this (further discussion in the challenges section) and had to introduce a new NDO calledndo_xdp_xmit_xsk(xsk = XDP socket). It takes a pointer to a netdevice and an explicit queue id that packets should be sent out on. In contrast tondo_xdp_xmit, it is asynchronous and pulls packets to be sent from the xdp socket (associated with the dev and queue combination that was provided with the NDO call) using a callback (get_tx_packet), and when they have been transmitted it uses another callback (tx_completion) to signal completion of packets. These callbacks are set viando_bpfin the newXDP_REGISTER_XSKcommand.ndo_xdp_xmit_xskis exclusively used by the XDP socket code and thus does not clash with theXDP_REDIRECTuse ofndo_xdp_xmit. This is one of the reasons that theXDP_DRVmode (without ZC) is currently not supported by TX. Please have a look at the challenges section for further discussions.The
AF_XDPbind call acts on a queue pair (channel in ethtool speak), so the user needs to steer the traffic to the zero-copy enabled queue pair. Which queue to use, is up to the user.For an untrusted application, HW packet steering to a specific queue pair (the one associated with the application) is a requirement, as the application would otherwise be able to see other user space processes' packets. If the HW cannot support the required packet steering,
XDP_DRVorXDP_SKBmode have to be used as they do not expose the NIC's packet buffer into user space as the packets are copied into user space from the NIC's packet buffer in the kernel.There is a xdpsock benchmarking/test application included. Say that you would like your UDP traffic from port 4242 to end up in queue 16, that we will enable
AF_XDPon. Here, we use ethtool for this:ethtool -N p3p2 rx-flow-hash udp4 fn
ethtool -N p3p2 flow-type udp4 src-port 4242 dst-port 4242 \
action 16Running the l2fwd benchmark in
XDP_DRV_ZCmode can then be done using:samples/bpf/xdpsock -i p3p2 -q 16 -l -NFor
XDP_SKBmode, use the switch "-S" instead of "-N" and all options can be displayed with "-h", as usual.We have run some benchmarks on a dual socket system with two Broadwell E5 2660 @ 2.0 GHz with hyperthreading turned off. Each socket has 14 cores which gives a total of 28, but only two cores are used in these experiments. One for TR/RX and one for the user space application. The memory is DDR4 @ 2133 MT/s (1067 MHz) and the size of each DIMM is 8192MB and with 8 of those DIMMs in the system we have 64 GB of total memory. The compiler used is gcc version 5.4.0 20160609. The NIC is an Intel I40E 40Gbit/s using the i40e driver.
Below are the results in Mpps of the I40E NIC benchmark runs for 64 byte packets, generated by commercial packet generator HW that is generating packets at full 40 Gbit/s line rate.
XDP baseline numbers without this RFC:
xdp_rxq_info--actionXDP_DROP31.3 Mppsxdp_rxq_info--actionXDP_TX16.7 MppsXDP performance with this RFC i.e. with the buffer allocator:
XDP_DROP21.0 MppsXDP_TX11.9 Mpps
AF_PACKETV4 performance from previous RFC on 4.14-rc7:Benchmark V2 V3 V4 V4+ZC rxdrop 0.67 0.73 0.74 33.7 txpush 0.98 0.98 0.91 19.6 l2fwd 0.66 0.71 0.67 15.5
Quoted 6 lines
AF_XDPperformance:Benchmark XDP_SKB XDP_DRV XDP_DRV_ZC (all in Mpps) rxdrop 3.3 11.6 16.9 txpush 2.2 NA* 21.8 l2fwd 1.7 NA* 10.4
Hi,
I also did an evaluation of AF_XDP, however the performance isn't as good as above.
I'd like to share the result and see if there are some tuning suggestions.
System:
16 core, Intel(R) Xeon(R) CPU E5-2440 v2 @ 1.90GHz Intel 10G X540-AT2 ---> so I can only run XDP_SKB mode
AF_XDP performance:
Benchmark XDP_SKB rxdrop 1.27 Mpps txpush 0.99 Mpps
l2fwd 0.85 Mpps
NIC configuration:
the command
"ethtool -N p3p2 flow-type udp4 src-port 4242 dst-port 4242 action 16" doesn't work on my ixgbe driver, so I use ntuple:
ethtool -K enp10s0f0 ntuple on
ethtool -U enp10s0f0 flow-type udp4 src-ip 10.1.1.100 action 1 then
echo 1 > /proc/sys/net/core/bpf_jit_enable
./xdpsock -i enp10s0f0 -r -S --queue=1
I also take a look at perf result:
For rxdrop:
86.56% xdpsock xdpsock [.] main
9.22% xdpsock [kernel.vmlinux] [k] nmi 4.23% xdpsock xdpsock [.] xq_enq
For l2fwd:
20.81% xdpsock xdpsock [.] main
10.64% xdpsock [kernel.vmlinux] [k] clflush_cache_range 8.46% xdpsock [kernel.vmlinux] [k] xsk_sendmsg 6.72% xdpsock [kernel.vmlinux] [k] skb_set_owner_w 5.89% xdpsock [kernel.vmlinux] [k] __domain_mapping 5.74% xdpsock [kernel.vmlinux] [k] alloc_skb_with_frags 4.62% xdpsock [kernel.vmlinux] [k] netif_skb_features 3.96% xdpsock [kernel.vmlinux] [k] ___slab_alloc 3.18% xdpsock [kernel.vmlinux] [k] nmi
I observed that the i40e's XDP_SKB result is much better than my ixgbe's result. I wonder in XDP_SKB mode, does the driver make performance difference? Or my cpu (E5-2440 v2 @ 1.90GHz) is too old?
Thanks
William
Quoted 152 lines · On Mon, 26 Mar 2018 09:06:54 -0700 William Tu <[email protected]> wrote:
Quoted 144 lines · Björn Töpel
From: Björn Töpel <[email protected]>
This RFC introduces a new address family called
AF_XDPthat is optimized for high performance packet processing and zero-copy semantics. Throughput improvements can be up to 20x compared to V2 and V3 for the micro benchmarks included. Would be great to get your feedback on it. Note that this is the follow up RFC toAF_PACKETV4 from November last year. The feedback from that RFC submission and the presentation at NetdevConf in Seoul was to create a new address family instead of building on top ofAF_PACKET.AF_XDPis this new address family.The main difference between
AF_XDPandAF_PACKETV2/V3 on a descriptor level is that TX and RX descriptors are separated from packet buffers. An RX or TX descriptor points to a data buffer in a packet buffer area. RX and TX can share the same packet buffer so that a packet does not have to be copied between RX and TX. Moreover, if a packet needs to be kept for a while due to a possible retransmit, then the descriptor that points to that packet buffer can be changed to point to another buffer and reused right away. This again avoids copying data.The RX and TX descriptor rings are registered with the setsockopts
XDP_RX_RINGandXDP_TX_RING, similar toAF_PACKET. The packet buffer area is allocated by user space and registered with the kernel using the newXDP_MEM_REGsetsockopt. All these three areas are shared between user space and kernel space. The socket is then bound with abind()call to a device and a specific queue id on that device, and it is not until bind is completed that traffic starts to flow.An XDP program can be loaded to direct part of the traffic on that device and queue id to user space through a new redirect action in an XDP program called
bpf_xdpsk_redirectthat redirects a packet up to the socket in user space. All the other XDP actions work just as before. Note that the current RFC requires the user to load an XDP program to get any traffic to user space (for example all traffic to user space with the one-liner program "returnbpf_xdpsk_redirect();"). We plan on introducing a patch that removes this requirement and sends all traffic from a queue to user space if anAF_XDPsocket is bound to it.
AF_XDPcan operate in three different modes:XDP_SKB,XDP_DRV, andXDP_DRV_ZC(shorthand forXDP_DRVwith a zero-copy allocator as there is no specific mode calledXDP_DRV_ZC). If the driver does not have support for XDP, orXDP_SKBis explicitly chosen when loading the XDP program,XDP_SKBmode is employed that uses SKBs together with the generic XDP support and copies out the data to user space. A fallback mode that works for any network device. On the other hand, if the driver has support for XDP (all three NDOs:ndo_bpf,ndo_xdp_xmitandndo_xdp_flush), these NDOs, without any modifications, will be used by theAF_XDPcode to provide better performance, but there is still a copy of the data into user space. The last mode,XDP_DRV_ZC, is XDP driver support with the zero-copy user space allocator that provides even better performance. In this mode, the networking HW (or SW driver if it is a virtual driver like veth) DMAs/puts packets straight into the packet buffer that is shared between user space and kernel space. The RX and TX descriptor queues of the networking HW are NOT shared to user space. Only the kernel can read and write these and it is the kernel driver's responsibility to translate these HW specific descriptors to the HW agnostic ones in the virtual descriptor rings that user space sees. This way, a malicious user space program cannot mess with the networking HW. This mode though requires some extensions to XDP.To get the
XDP_DRV_ZCmode to work for RX, we chose to introduce a buffer pool concept so that the same XDP driver code can be used for buffers allocated using the page allocator (XDP_DRV), the user-space zero-copy allocator (XDP_DRV_ZC), or some internal driver specific allocator/cache/recycling mechanism. Thendo_bpfcall has also been extended with two commands for registering and unregistering an XSK socket and is in the RX case mainly used to communicate some information about the user-space buffer pool to the driver.For the TX path, our plan was to use
ndo_xdp_xmitandndo_xdp_flush, but we run into problems with this (further discussion in the challenges section) and had to introduce a new NDO calledndo_xdp_xmit_xsk(xsk = XDP socket). It takes a pointer to a netdevice and an explicit queue id that packets should be sent out on. In contrast tondo_xdp_xmit, it is asynchronous and pulls packets to be sent from the xdp socket (associated with the dev and queue combination that was provided with the NDO call) using a callback (get_tx_packet), and when they have been transmitted it uses another callback (tx_completion) to signal completion of packets. These callbacks are set viando_bpfin the newXDP_REGISTER_XSKcommand.ndo_xdp_xmit_xskis exclusively used by the XDP socket code and thus does not clash with theXDP_REDIRECTuse ofndo_xdp_xmit. This is one of the reasons that theXDP_DRVmode (without ZC) is currently not supported by TX. Please have a look at the challenges section for further discussions.The
AF_XDPbind call acts on a queue pair (channel in ethtool speak), so the user needs to steer the traffic to the zero-copy enabled queue pair. Which queue to use, is up to the user.For an untrusted application, HW packet steering to a specific queue pair (the one associated with the application) is a requirement, as the application would otherwise be able to see other user space processes' packets. If the HW cannot support the required packet steering,
XDP_DRVorXDP_SKBmode have to be used as they do not expose the NIC's packet buffer into user space as the packets are copied into user space from the NIC's packet buffer in the kernel.There is a xdpsock benchmarking/test application included. Say that you would like your UDP traffic from port 4242 to end up in queue 16, that we will enable
AF_XDPon. Here, we use ethtool for this:ethtool -N p3p2 rx-flow-hash udp4 fn
ethtool -N p3p2 flow-type udp4 src-port 4242 dst-port 4242 \
action 16Running the l2fwd benchmark in
XDP_DRV_ZCmode can then be done using:samples/bpf/xdpsock -i p3p2 -q 16 -l -NFor
XDP_SKBmode, use the switch "-S" instead of "-N" and all options can be displayed with "-h", as usual.We have run some benchmarks on a dual socket system with two Broadwell E5 2660 @ 2.0 GHz with hyperthreading turned off. Each socket has 14 cores which gives a total of 28, but only two cores are used in these experiments. One for TR/RX and one for the user space application. The memory is DDR4 @ 2133 MT/s (1067 MHz) and the size of each DIMM is 8192MB and with 8 of those DIMMs in the system we have 64 GB of total memory. The compiler used is gcc version 5.4.0 20160609. The NIC is an Intel I40E 40Gbit/s using the i40e driver.
Below are the results in Mpps of the I40E NIC benchmark runs for 64 byte packets, generated by commercial packet generator HW that is generating packets at full 40 Gbit/s line rate.
XDP baseline numbers without this RFC:
xdp_rxq_info--actionXDP_DROP31.3 Mppsxdp_rxq_info--actionXDP_TX16.7 MppsXDP performance with this RFC i.e. with the buffer allocator:
XDP_DROP21.0 MppsXDP_TX11.9 Mpps
AF_PACKETV4 performance from previous RFC on 4.14-rc7:Benchmark V2 V3 V4 V4+ZC rxdrop 0.67 0.73 0.74 33.7 txpush 0.98 0.98 0.91 19.6 l2fwd 0.66 0.71 0.67 15.5Quoted 6 lines
AF_XDPperformance:Benchmark XDP_SKB XDP_DRV XDP_DRV_ZC (all in Mpps) rxdrop 3.3 11.6 16.9 txpush 2.2 NA* 21.8 l2fwd 1.7 NA* 10.4
Quoted 8 lines
Hi,
I also did an evaluation ofAF_XDP, however the performance isn't as good as above.
I'd like to share the result and see if there are some tuning suggestions.System:
16 core, Intel(R) Xeon(R) CPU E5-2440 v2 @ 1.90GHz Intel 10G X540-AT2 ---> so I can only runXDP_SKBmode
Hmmm, why is X540-AT2 not able to use XDP natively?
Quoted 5 lines
AF_XDPperformance:Benchmark XDP_SKB rxdrop 1.27 Mpps txpush 0.99 Mppsl2fwd 0.85 Mpps
Definitely too low...
What is the performance if you drop packets via iptables?
Command:
$ iptables -t raw -I PREROUTING -p udp --dport 9 --j DROP
Quoted 11 lines
NIC configuration:
the command
"ethtool -N p3p2 flow-type udp4 src-port 4242 dst-port 4242 action 16" doesn't work on my ixgbe driver, so I use ntuple:ethtool -K enp10s0f0 ntuple on
ethtool -U enp10s0f0 flow-type udp4 src-ip 10.1.1.100 action 1 then
echo 1 >/proc/sys/net/core/bpf_jit_enable
./xdpsock -i enp10s0f0 -r -S --queue=1
Quoted 5 lines
I also take a look at perf result:
For rxdrop:
86.56% xdpsock xdpsock [.] main9.22% xdpsock [kernel.vmlinux] [k] nmi 4.23% xdpsock xdpsock [.] xq_enq
It looks very strange that you see non-maskable interrupt's (NMI) being this high...
Quoted 3 lines
For l2fwd:
20.81% xdpsock xdpsock [.] main 10.64% xdpsock [kernel.vmlinux] [k] clflush_cache_range
Oh, clflush_cache_range is being called!
Do your system use an IOMMU ?
Quoted 7 lines
8.46% xdpsock [kernel.vmlinux] [k] xsk_sendmsg 6.72% xdpsock [kernel.vmlinux] [k] skb_set_owner_w 5.89% xdpsock [kernel.vmlinux] [k] __domain_mapping 5.74% xdpsock [kernel.vmlinux] [k] alloc_skb_with_frags 4.62% xdpsock [kernel.vmlinux] [k] netif_skb_features 3.96% xdpsock [kernel.vmlinux] [k] ___slab_alloc 3.18% xdpsock [kernel.vmlinux] [k] nmi
Again high count for NMI ?!?
Maybe you just forgot to tell perf that you want it to decode the bpf_prog correctly?
https://prototype-kernel.readthedocs.io/en/latest/bpf/troubleshooting.html#perf-tool-symbols
Enable via:
$ sysctl net/core/bpf_jit_kallsyms=1
And use perf report (while BPF is STILL LOADED):
$ perf report --kallsyms=/proc/kallsyms
E.g. for emailing this you can use this command:
$ perf report --sort cpu,comm,dso,symbol --kallsyms=/proc/kallsyms --no-children --stdio -g none | head -n 40
Quoted 3 lines
I observed that the i40e's
XDP_SKBresult is much better than my ixgbe's result. I wonder inXDP_SKBmode, does the driver make performance difference? Or my cpu (E5-2440 v2 @ 1.90GHz) is too old?
I suspect some setup issue on your system.
Signature · 4 lines
Best regards, Jesper Dangaard Brouer MSc.CS, Principal Kernel Engineer at Red Hat LinkedIn: http://www.linkedin.com/in/brouer
Hi Jesper,
Thanks a lot for your prompt reply.
Quoted 10 lines
Quoted 8 lines
Hi,
I also did an evaluation ofAF_XDP, however the performance isn't as good as above.
I'd like to share the result and see if there are some tuning suggestions.System:
16 core, Intel(R) Xeon(R) CPU E5-2440 v2 @ 1.90GHz Intel 10G X540-AT2 ---> so I can only runXDP_SKBmodeHmmm, why is X540-AT2 not able to use XDP natively?
Because I'm only able to use ixgbe driver for this NIC, and AF_XDP patch only has i40e support?
Quoted 9 lines
Quoted 6 lines
AF_XDPperformance:Benchmark XDP_SKB rxdrop 1.27 Mpps txpush 0.99 Mppsl2fwd 0.85 Mpps
Definitely too low...
I did another run, the rxdrop seems better.
Benchmark XDP_SKB
rxdrop 2.3 Mpps
txpush 1.05 Mpps
l2fwd 0.90 Mpps
Quoted 5 lines
What is the performance if you drop packets via iptables?
Command:
$ iptables -t raw -I PREROUTING -p udp --dport 9 --j DROP
I did
# iptables -t raw -I PREROUTING -p udp -i enp10s0f0 -j DROP # iptables -nvL -t raw; sleep 10; iptables -nvL -t raw
and I got 2.9Mpps.
Quoted 11 lines
Quoted 11 lines
NIC configuration:
the command
"ethtool -N p3p2 flow-type udp4 src-port 4242 dst-port 4242 action 16" doesn't work on my ixgbe driver, so I use ntuple:ethtool -K enp10s0f0 ntuple on
ethtool -U enp10s0f0 flow-type udp4 src-ip 10.1.1.100 action 1 then
echo 1 >/proc/sys/net/core/bpf_jit_enable
./xdpsock -i enp10s0f0 -r -S --queue=1
Quoted 9 lines
Quoted 5 lines
I also take a look at perf result:
For rxdrop:
86.56% xdpsock xdpsock [.] main9.22% xdpsock [kernel.vmlinux] [k] nmi 4.23% xdpsock xdpsock [.] xq_enqIt looks very strange that you see non-maskable interrupt's (NMI) being this high...
yes, that's weird. Looking at the perf annotate of nmi, it shows 100% spent on nop instruction.
Quoted 6 lines
Quoted 4 lines
For l2fwd:
20.81% xdpsock xdpsock [.] main 10.64% xdpsock [kernel.vmlinux] [k] clflush_cache_rangeOh,
clflush_cache_rangeis being called!
I though clflush_cache_range is high because we have many smp_rmb, smp_wmb in the xdpsock queue/ring management userspace code.
(perf shows that 75% of this 10.64% spent on mfence instruction.)
Quoted 2 lines
Do your system use an IOMMU ?
Yes.
With CONFIG_INTEL_IOMMU=y
and I saw some related functions called (ex: intel_alloc_iova).
Quoted 18 lines
Quoted 7 lines
8.46% xdpsock [kernel.vmlinux] [k] xsk_sendmsg 6.72% xdpsock [kernel.vmlinux] [k] skb_set_owner_w 5.89% xdpsock [kernel.vmlinux] [k] __domain_mapping 5.74% xdpsock [kernel.vmlinux] [k] alloc_skb_with_frags 4.62% xdpsock [kernel.vmlinux] [k] netif_skb_features 3.96% xdpsock [kernel.vmlinux] [k] ___slab_alloc 3.18% xdpsock [kernel.vmlinux] [k] nmiAgain high count for NMI ?!?
Maybe you just forgot to tell perf that you want it to decode the
bpf_progcorrectly?https://prototype-kernel.readthedocs.io/en/latest/bpf/troubleshooting.html#perf-tool-symbols
Enable via:
$ sysctl net/core/bpf_jit_kallsyms=1
Quoted 8 lines
And use perf report (while BPF is STILL LOADED):
$ perf report --kallsyms=/proc/kallsymsE.g. for emailing this you can use this command:
$ perf report --sort cpu,comm,dso,symbol --kallsyms=/proc/kallsyms --no-children --stdio -g none | head -n 40
Thanks, I followed the steps, the result of l2fwd
# Total Lost Samples: 119
#
# Samples: 2K of event 'cycles:ppp'
# Event count (approx.): 25675705627
#
# Overhead CPU Command Shared Object Symbol
# ........ ... ....... .................. ..................................
#
10.48% 013 xdpsock xdpsock [.] main
9.77% 013 xdpsock [kernel.vmlinux] [k] clflush_cache_range
8.45% 013 xdpsock [kernel.vmlinux] [k] nmi
8.07% 013 xdpsock [kernel.vmlinux] [k] xsk_sendmsg
7.81% 013 xdpsock [kernel.vmlinux] [k] __domain_mapping
4.95% 013 xdpsock [kernel.vmlinux] [k] ixgbe_xmit_frame_ring
4.66% 013 xdpsock [kernel.vmlinux] [k] skb_store_bits
4.39% 013 xdpsock [kernel.vmlinux] [k] syscall_return_via_sysret
3.93% 013 xdpsock [kernel.vmlinux] [k] pfn_to_dma_pte
2.62% 013 xdpsock [kernel.vmlinux] [k] __intel_map_single
2.53% 013 xdpsock [kernel.vmlinux] [k] __alloc_skb
2.36% 013 xdpsock [kernel.vmlinux] [k] iommu_no_mapping
2.21% 013 xdpsock [kernel.vmlinux] [k] alloc_skb_with_frags
2.07% 013 xdpsock [kernel.vmlinux] [k] skb_set_owner_w
1.98% 013 xdpsock [kernel.vmlinux] [k] __kmalloc_node_track_caller
1.94% 013 xdpsock [kernel.vmlinux] [k] ksize
1.84% 013 xdpsock [kernel.vmlinux] [k] validate_xmit_skb_list
1.62% 013 xdpsock [kernel.vmlinux] [k] kmem_cache_alloc_node
1.48% 013 xdpsock [kernel.vmlinux] [k] __kmalloc_reserve.isra.37
1.21% 013 xdpsock xdpsock [.] xq_enq
1.08% 013 xdpsock [kernel.vmlinux] [k] intel_alloc_iovaAnd l2fwd under "perf stat" looks OK to me. There is little context switches, cpu
is fully utilized, 1.17 insn per cycle seems ok.
Performance counter stats for 'CPU(s) 6':
10000.787420 cpu-clock (msec) # 1.000 CPUs
utilized
24 context-switches # 0.002 K/sec
0 cpu-migrations # 0.000 K/sec
0 page-faults # 0.000 K/sec
22,361,333,647 cycles # 2.236 GHz
13,458,442,838 stalled-cycles-frontend # 60.19% frontend
cycles idle
26,251,003,067 instructions # 1.17 insn per
cycle
# 0.51 stalled
cycles per insn
4,938,921,868 branches # 493.853 M/sec
7,591,739 branch-misses # 0.15% of all
branches
10.000835769 seconds time elapsedWill continue investigate...
Thanks
William
2018-03-26 23:58 GMT+02:00 William Tu <[email protected]>:
Quoted 9 lines
Hi Jesper,
Thanks a lot for your prompt reply.
Quoted 5 lines
Quoted 5 lines
Hi,
I also did an evaluation ofAF_XDP, however the performance isn't as good as above.
I'd like to share the result and see if there are some tuning suggestions.
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
System:
16 core, Intel(R) Xeon(R) CPU E5-2440 v2 @ 1.90GHz Intel 10G X540-AT2 ---> so I can only runXDP_SKBmodeHmmm, why is X540-AT2 not able to use XDP natively?
Because I'm only able to use ixgbe driver for this NIC, and
AF_XDPpatch only has i40e support?
It's only i40e that support zero copy. As for native XDP support, only XDP_REDIRECT support is required and ixgbe does support XDP_REDIRECT -- unfortunately, ixgbe still needs a needs a patch to work properly, which is in net-next: ed93a3987128 ("ixgbe: tweak page counting for XDP_REDIRECT").
Quoted 149 lines
Quoted 9 lines
Quoted 6 lines
AF_XDPperformance:Benchmark XDP_SKB rxdrop 1.27 Mpps txpush 0.99 Mppsl2fwd 0.85 Mpps
Definitely too low...
I did another run, the rxdrop seems better.
BenchmarkXDP_SKB
rxdrop 2.3 Mpps
txpush 1.05 Mpps
l2fwd 0.90 MppsQuoted 5 lines
What is the performance if you drop packets via iptables?
Command:
$ iptables -t raw -I PREROUTING -p udp --dport 9 --j DROPI did
# iptables -t raw -I PREROUTING -p udp -i enp10s0f0 -j DROP # iptables -nvL -t raw; sleep 10; iptables -nvL -t rawand I got 2.9Mpps.
Quoted 11 lines
Quoted 11 lines
NIC configuration:
the command
"ethtool -N p3p2 flow-type udp4 src-port 4242 dst-port 4242 action 16" doesn't work on my ixgbe driver, so I use ntuple:ethtool -K enp10s0f0 ntuple on
ethtool -U enp10s0f0 flow-type udp4 src-ip 10.1.1.100 action 1 then
echo 1 >/proc/sys/net/core/bpf_jit_enable
./xdpsock -i enp10s0f0 -r -S --queue=1Quoted 9 lines
Quoted 5 lines
I also take a look at perf result:
For rxdrop:
86.56% xdpsock xdpsock [.] main9.22% xdpsock [kernel.vmlinux] [k] nmi 4.23% xdpsock xdpsock [.] xq_enqIt looks very strange that you see non-maskable interrupt's (NMI) being this high...
yes, that's weird. Looking at the perf annotate of nmi, it shows 100% spent on nop instruction.
Quoted 6 lines
Quoted 4 lines
For l2fwd:
20.81% xdpsock xdpsock [.] main 10.64% xdpsock [kernel.vmlinux] [k] clflush_cache_rangeOh,
clflush_cache_rangeis being called!I though
clflush_cache_rangeis high because we have manysmp_rmb,smp_wmbin the xdpsock queue/ring management userspace code.
(perf shows that 75% of this 10.64% spent on mfence instruction.)Quoted 2 lines
Do your system use an IOMMU ?
Yes.
WithCONFIG_INTEL_IOMMU=y
and I saw some related functions called (ex:intel_alloc_iova).Quoted 18 lines
Quoted 7 lines
8.46% xdpsock [kernel.vmlinux] [k] xsk_sendmsg 6.72% xdpsock [kernel.vmlinux] [k] skb_set_owner_w 5.89% xdpsock [kernel.vmlinux] [k] __domain_mapping 5.74% xdpsock [kernel.vmlinux] [k] alloc_skb_with_frags 4.62% xdpsock [kernel.vmlinux] [k] netif_skb_features 3.96% xdpsock [kernel.vmlinux] [k] ___slab_alloc 3.18% xdpsock [kernel.vmlinux] [k] nmiAgain high count for NMI ?!?
Maybe you just forgot to tell perf that you want it to decode the
bpf_progcorrectly?https://prototype-kernel.readthedocs.io/en/latest/bpf/troubleshooting.html#perf-tool-symbols
Enable via:
$ sysctl net/core/bpf_jit_kallsyms=1Quoted 8 lines
And use perf report (while BPF is STILL LOADED):
$ perf report --kallsyms=/proc/kallsymsE.g. for emailing this you can use this command:
$ perf report --sort cpu,comm,dso,symbol --kallsyms=/proc/kallsyms --no-children --stdio -g none | head -n 40Thanks, I followed the steps, the result of l2fwd
# Total Lost Samples: 119
#
# Samples: 2K of event 'cycles:ppp'
# Event count (approx.): 25675705627
## Overhead CPU Command Shared Object Symbol # ........ ... ....... .................. .................................. # 10.48% 013 xdpsock xdpsock [.] main 9.77% 013 xdpsock [kernel.vmlinux] [k] clflush_cache_range 8.45% 013 xdpsock [kernel.vmlinux] [k] nmi 8.07% 013 xdpsock [kernel.vmlinux] [k] xsk_sendmsg 7.81% 013 xdpsock [kernel.vmlinux] [k] __domain_mapping 4.95% 013 xdpsock [kernel.vmlinux] [k] ixgbe_xmit_frame_ring 4.66% 013 xdpsock [kernel.vmlinux] [k] skb_store_bits 4.39% 013 xdpsock [kernel.vmlinux] [k] syscall_return_via_sysret 3.93% 013 xdpsock [kernel.vmlinux] [k] pfn_to_dma_pte 2.62% 013 xdpsock [kernel.vmlinux] [k] __intel_map_single 2.53% 013 xdpsock [kernel.vmlinux] [k] __alloc_skb 2.36% 013 xdpsock [kernel.vmlinux] [k] iommu_no_mapping 2.21% 013 xdpsock [kernel.vmlinux] [k] alloc_skb_with_frags 2.07% 013 xdpsock [kernel.vmlinux] [k] skb_set_owner_w 1.98% 013 xdpsock [kernel.vmlinux] [k] __kmalloc_node_track_caller 1.94% 013 xdpsock [kernel.vmlinux] [k] ksize 1.84% 013 xdpsock [kernel.vmlinux] [k] validate_xmit_skb_list 1.62% 013 xdpsock [kernel.vmlinux] [k] kmem_cache_alloc_node 1.48% 013 xdpsock [kernel.vmlinux] [k] __kmalloc_reserve.isra.37 1.21% 013 xdpsock xdpsock [.] xq_enq 1.08% 013 xdpsock [kernel.vmlinux] [k] intel_alloc_iovaAnd l2fwd under "perf stat" looks OK to me. There is little context switches, cpu
is fully utilized, 1.17 insn per cycle seems ok.Performance counter stats for 'CPU(s) 6':
10000.787420 cpu-clock (msec) # 1.000 CPUs utilized 24 context-switches # 0.002 K/sec 0 cpu-migrations # 0.000 K/sec 0 page-faults # 0.000 K/sec 22,361,333,647 cycles # 2.236 GHz 13,458,442,838 stalled-cycles-frontend # 60.19% frontend cycles idle 26,251,003,067 instructions # 1.17 insn per cycle # 0.51 stalled cycles per insn 4,938,921,868 branches # 493.853 M/sec 7,591,739 branch-misses # 0.15% of all branches 10.000835769 seconds time elapsedWill continue investigate...
Thanks
William
Quoted 41 lines · On Mon, 26 Mar 2018 14:58:02 -0700 William Tu <[email protected]> wrote:
Quoted 10 lines
Again high count for NMI ?!?
Maybe you just forgot to tell perf that you want it to decode the
bpf_progcorrectly?https://prototype-kernel.readthedocs.io/en/latest/bpf/troubleshooting.html#perf-tool-symbols
Enable via:
$ sysctl net/core/bpf_jit_kallsyms=1Quoted 8 lines
And use perf report (while BPF is STILL LOADED):
$ perf report --kallsyms=/proc/kallsymsE.g. for emailing this you can use this command:
$ perf report --sort cpu,comm,dso,symbol --kallsyms=/proc/kallsyms --no-children --stdio -g none | head -n 40Thanks, I followed the steps, the result of l2fwd
# Total Lost Samples: 119
#
# Samples: 2K of event 'cycles:ppp'
# Event count (approx.): 25675705627
## Overhead CPU Command Shared Object Symbol # ........ ... ....... .................. .................................. # 10.48% 013 xdpsock xdpsock [.] main 9.77% 013 xdpsock [kernel.vmlinux] [k] clflush_cache_range 8.45% 013 xdpsock [kernel.vmlinux] [k] nmi 8.07% 013 xdpsock [kernel.vmlinux] [k] xsk_sendmsg 7.81% 013 xdpsock [kernel.vmlinux] [k] __domain_mapping 4.95% 013 xdpsock [kernel.vmlinux] [k] ixgbe_xmit_frame_ring 4.66% 013 xdpsock [kernel.vmlinux] [k] skb_store_bits 4.39% 013 xdpsock [kernel.vmlinux] [k] syscall_return_via_sysret 3.93% 013 xdpsock [kernel.vmlinux] [k] pfn_to_dma_pte 2.62% 013 xdpsock [kernel.vmlinux] [k] __intel_map_single 2.53% 013 xdpsock [kernel.vmlinux] [k] __alloc_skb 2.36% 013 xdpsock [kernel.vmlinux] [k] iommu_no_mapping 2.21% 013 xdpsock [kernel.vmlinux] [k] alloc_skb_with_frags
Quoted 9 lines
2.07% 013 xdpsock [kernel.vmlinux] [k] skb_set_owner_w
1.98% 013 xdpsock [kernel.vmlinux] [k] __kmalloc_node_track_caller
1.94% 013 xdpsock [kernel.vmlinux] [k] ksize
1.84% 013 xdpsock [kernel.vmlinux] [k] validate_xmit_skb_list
1.62% 013 xdpsock [kernel.vmlinux] [k] kmem_cache_alloc_node
1.48% 013 xdpsock [kernel.vmlinux] [k] __kmalloc_reserve.isra.37
1.21% 013 xdpsock xdpsock [.] xq_enq
1.08% 013 xdpsock [kernel.vmlinux] [k] intel_alloc_iovaYou did use net/core/bpf_jit_kallsyms=1 and correct perf commands decoding of bpf_prog, so the perf top#3 'nmi' is likely a real NMI call... which looks wrong.
Quoted 14 lines
And l2fwd under "perf stat" looks OK to me. There is little context switches, cpu is fully utilized, 1.17 insn per cycle seems ok.
Performance counter stats for 'CPU(s) 6':
10000.787420 cpu-clock (msec) # 1.000 CPUs utilized 24 context-switches # 0.002 K/sec 0 cpu-migrations # 0.000 K/sec 0 page-faults # 0.000 K/sec 22,361,333,647 cycles # 2.236 GHz 13,458,442,838 stalled-cycles-frontend # 60.19% frontend cycles idle 26,251,003,067 instructions # 1.17 insn per cycle # 0.51 stalled cycles per insn 4,938,921,868 branches # 493.853 M/sec 7,591,739 branch-misses # 0.15% of all branches
Quoted 1 line
10.000835769 seconds time elapsed
This perf stat also indicate something is wrong.
The 1.17 insn per cycle is NOT okay, it is too low (compared to what usually I see, e.g. 2.36 insn per cycle).
It clearly says you have 'stalled-cycles-frontend' and '60.19% frontend
cycles idle'. This means your CPU have issues/bottleneck fetching
instructions. Explained by Andi Kleen here [1]
[1] https://github.com/andikleen/pmu-tools/wiki/toplev-manual
Signature · 4 lines
Best regards, Jesper Dangaard Brouer MSc.CS, Principal Kernel Engineer at Red Hat LinkedIn: http://www.linkedin.com/in/brouer
Quoted 54 lines · Jesper Dangaard Brouer
Quoted 41 lines · On Mon, 26 Mar 2018 14:58:02 -0700 William Tu <[email protected]> wrote:
Quoted 10 lines
Again high count for NMI ?!?
Maybe you just forgot to tell perf that you want it to decode the
bpf_progcorrectly?https://prototype-kernel.readthedocs.io/en/latest/bpf/troubleshooting.html#perf-tool-symbols
Enable via:
$ sysctl net/core/bpf_jit_kallsyms=1Quoted 8 lines
And use perf report (while BPF is STILL LOADED):
$ perf report --kallsyms=/proc/kallsymsE.g. for emailing this you can use this command:
$ perf report --sort cpu,comm,dso,symbol --kallsyms=/proc/kallsyms --no-children --stdio -g none | head -n 40Thanks, I followed the steps, the result of l2fwd
# Total Lost Samples: 119
#
# Samples: 2K of event 'cycles:ppp'
# Event count (approx.): 25675705627
## Overhead CPU Command Shared Object Symbol # ........ ... ....... .................. .................................. # 10.48% 013 xdpsock xdpsock [.] main 9.77% 013 xdpsock [kernel.vmlinux] [k] clflush_cache_range 8.45% 013 xdpsock [kernel.vmlinux] [k] nmi 8.07% 013 xdpsock [kernel.vmlinux] [k] xsk_sendmsg 7.81% 013 xdpsock [kernel.vmlinux] [k] __domain_mapping 4.95% 013 xdpsock [kernel.vmlinux] [k] ixgbe_xmit_frame_ring 4.66% 013 xdpsock [kernel.vmlinux] [k] skb_store_bits 4.39% 013 xdpsock [kernel.vmlinux] [k] syscall_return_via_sysret 3.93% 013 xdpsock [kernel.vmlinux] [k] pfn_to_dma_pte 2.62% 013 xdpsock [kernel.vmlinux] [k] __intel_map_single 2.53% 013 xdpsock [kernel.vmlinux] [k] __alloc_skb 2.36% 013 xdpsock [kernel.vmlinux] [k] iommu_no_mapping 2.21% 013 xdpsock [kernel.vmlinux] [k] alloc_skb_with_fragsQuoted 9 lines
2.07% 013 xdpsock [kernel.vmlinux] [k] skb_set_owner_w 1.98% 013 xdpsock [kernel.vmlinux] [k] __kmalloc_node_track_caller 1.94% 013 xdpsock [kernel.vmlinux] [k] ksize 1.84% 013 xdpsock [kernel.vmlinux] [k] validate_xmit_skb_list 1.62% 013 xdpsock [kernel.vmlinux] [k] kmem_cache_alloc_node 1.48% 013 xdpsock [kernel.vmlinux] [k] __kmalloc_reserve.isra.37 1.21% 013 xdpsock xdpsock [.] xq_enq 1.08% 013 xdpsock [kernel.vmlinux] [k] intel_alloc_iova
Quoted 3 lines
You did use net/core/bpf_jit_kallsyms=1 and correct perf commands decoding of
bpf_prog, so the perf top#3 'nmi' is likely a real NMI call... which looks wrong.
Thanks, you're right. Let me dig more on this NMI behavior.
Quoted 19 lines
Quoted 15 lines
And l2fwd under "perf stat" looks OK to me. There is little context switches, cpu is fully utilized, 1.17 insn per cycle seems ok.
Performance counter stats for 'CPU(s) 6':
10000.787420 cpu-clock (msec) # 1.000 CPUs utilized 24 context-switches # 0.002 K/sec 0 cpu-migrations # 0.000 K/sec 0 page-faults # 0.000 K/sec 22,361,333,647 cycles # 2.236 GHz 13,458,442,838 stalled-cycles-frontend # 60.19% frontend cycles idle 26,251,003,067 instructions # 1.17 insn per cycle # 0.51 stalled cycles per insn 4,938,921,868 branches # 493.853 M/sec 7,591,739 branch-misses # 0.15% of all branchesQuoted 1 line
10.000835769 seconds time elapsed
This perf stat also indicate something is wrong.
Quoted 9 lines
The 1.17 insn per cycle is NOT okay, it is too low (compared to what usually I see, e.g. 2.36 insn per cycle).
It clearly says you have 'stalled-cycles-frontend' and '60.19% frontend
cycles idle'. This means your CPU have issues/bottleneck fetching
instructions. Explained by Andi Kleen here [1][1] https://github.com/andikleen/pmu-tools/wiki/toplev-manual
thanks for the link!
It's definitely weird that my frontend cycle (fetch and decode) stalled is so high.
I assume this xdpsock code is small and should all fit into the icache. However, doing another perf stat on xdpsock l2fwd shows
13,720,109,581 stalled-cycles-frontend # 60.01% frontend cycles
idle (23.82%)
<not supported> stalled-cycles-backend
7,994,837 branch-misses # 0.16% of all branches
(23.80%)
996,874,424 bus-cycles # 99.679 M/sec (23.80%)
18,942,220,445 ref-cycles # 1894.067 M/sec (28.56%)
100,983,226 LLC-loads # 10.097 M/sec (23.80%)
4,897,089 LLC-load-misses # 4.85% of all
LL-cache hits (23.80%)
66,659,889 LLC-stores # 6.665 M/sec (9.52%)
8,373 LLC-store-misses # 0.837 K/sec (9.52%)
158,178,410 LLC-prefetches # 15.817 M/sec (9.52%)
3,011,180 LLC-prefetch-misses # 0.301 M/sec (9.52%)
8,190,383,109 dTLB-loads # 818.971 M/sec (9.52%)
20,432,204 dTLB-load-misses # 0.25% of all dTLB
cache hits (9.52%)
3,729,504,674 dTLB-stores # 372.920 M/sec (9.52%)
992,231 dTLB-store-misses # 0.099 M/sec (9.52%)
<not supported> dTLB-prefetches
<not supported> dTLB-prefetch-misses
11,619 iTLB-loads # 0.001 M/sec (9.52%)
1,874,756 iTLB-load-misses # 16135.26% of alliTLB cache hits (14.28%)
I have super high iTLB-load-misses. This is probably the cause of high frontend stalled.
Do you know any way to improve iTLB hit rate?
Thanks
William
Quoted 111 lines · On Tue, 27 Mar 2018 17:06:50 -0700 William Tu <[email protected]> wrote:
Quoted 54 lines · Jesper Dangaard Brouer
Quoted 41 lines · On Mon, 26 Mar 2018 14:58:02 -0700 William Tu <[email protected]> wrote:
Quoted 10 lines
Again high count for NMI ?!?
Maybe you just forgot to tell perf that you want it to decode the
bpf_progcorrectly?https://prototype-kernel.readthedocs.io/en/latest/bpf/troubleshooting.html#perf-tool-symbols
Enable via:
$ sysctl net/core/bpf_jit_kallsyms=1Quoted 8 lines
And use perf report (while BPF is STILL LOADED):
$ perf report --kallsyms=/proc/kallsymsE.g. for emailing this you can use this command:
$ perf report --sort cpu,comm,dso,symbol --kallsyms=/proc/kallsyms --no-children --stdio -g none | head -n 40Thanks, I followed the steps, the result of l2fwd
# Total Lost Samples: 119
#
# Samples: 2K of event 'cycles:ppp'
# Event count (approx.): 25675705627
## Overhead CPU Command Shared Object Symbol # ........ ... ....... .................. .................................. # 10.48% 013 xdpsock xdpsock [.] main 9.77% 013 xdpsock [kernel.vmlinux] [k] clflush_cache_range 8.45% 013 xdpsock [kernel.vmlinux] [k] nmi 8.07% 013 xdpsock [kernel.vmlinux] [k] xsk_sendmsg 7.81% 013 xdpsock [kernel.vmlinux] [k] __domain_mapping 4.95% 013 xdpsock [kernel.vmlinux] [k] ixgbe_xmit_frame_ring 4.66% 013 xdpsock [kernel.vmlinux] [k] skb_store_bits 4.39% 013 xdpsock [kernel.vmlinux] [k] syscall_return_via_sysret 3.93% 013 xdpsock [kernel.vmlinux] [k] pfn_to_dma_pte 2.62% 013 xdpsock [kernel.vmlinux] [k] __intel_map_single 2.53% 013 xdpsock [kernel.vmlinux] [k] __alloc_skb 2.36% 013 xdpsock [kernel.vmlinux] [k] iommu_no_mapping 2.21% 013 xdpsock [kernel.vmlinux] [k] alloc_skb_with_fragsQuoted 9 lines
2.07% 013 xdpsock [kernel.vmlinux] [k] skb_set_owner_w 1.98% 013 xdpsock [kernel.vmlinux] [k] __kmalloc_node_track_caller 1.94% 013 xdpsock [kernel.vmlinux] [k] ksize 1.84% 013 xdpsock [kernel.vmlinux] [k] validate_xmit_skb_list 1.62% 013 xdpsock [kernel.vmlinux] [k] kmem_cache_alloc_node 1.48% 013 xdpsock [kernel.vmlinux] [k] __kmalloc_reserve.isra.37 1.21% 013 xdpsock xdpsock [.] xq_enq 1.08% 013 xdpsock [kernel.vmlinux] [k] intel_alloc_iovaQuoted 3 lines
You did use net/core/bpf_jit_kallsyms=1 and correct perf commands decoding of
bpf_prog, so the perf top#3 'nmi' is likely a real NMI call... which looks wrong.Thanks, you're right. Let me dig more on this NMI behavior.
Quoted 19 lines
Quoted 15 lines
And l2fwd under "perf stat" looks OK to me. There is little context switches, cpu is fully utilized, 1.17 insn per cycle seems ok.
Performance counter stats for 'CPU(s) 6':
10000.787420 cpu-clock (msec) # 1.000 CPUs utilized 24 context-switches # 0.002 K/sec 0 cpu-migrations # 0.000 K/sec 0 page-faults # 0.000 K/sec 22,361,333,647 cycles # 2.236 GHz 13,458,442,838 stalled-cycles-frontend # 60.19% frontend cycles idle 26,251,003,067 instructions # 1.17 insn per cycle # 0.51 stalled cycles per insn 4,938,921,868 branches # 493.853 M/sec 7,591,739 branch-misses # 0.15% of all branchesQuoted 1 line
10.000835769 seconds time elapsed
This perf stat also indicate something is wrong.
Quoted 9 lines
The 1.17 insn per cycle is NOT okay, it is too low (compared to what usually I see, e.g. 2.36 insn per cycle).
It clearly says you have 'stalled-cycles-frontend' and '60.19% frontend
cycles idle'. This means your CPU have issues/bottleneck fetching
instructions. Explained by Andi Kleen here [1][1] https://github.com/andikleen/pmu-tools/wiki/toplev-manual
thanks for the link!
It's definitely weird that my frontend cycle (fetch and decode) stalled is so high.
I assume this xdpsock code is small and should all fit into the icache. However, doing another perf stat on xdpsock l2fwd shows
13,720,109,581 stalled-cycles-frontend # 60.01% frontend cycles
idle (23.82%)<not supported> stalled-cycles-backend
7,994,837 branch-misses # 0.16% of all branches (23.80%) 996,874,424 bus-cycles # 99.679 M/sec (23.80%) 18,942,220,445 ref-cycles # 1894.067 M/sec (28.56%) 100,983,226 LLC-loads # 10.097 M/sec (23.80%) 4,897,089 LLC-load-misses # 4.85% of all LL-cache hits (23.80%) 66,659,889 LLC-stores # 6.665 M/sec (9.52%) 8,373 LLC-store-misses # 0.837 K/sec (9.52%) 158,178,410 LLC-prefetches # 15.817 M/sec (9.52%) 3,011,180 LLC-prefetch-misses # 0.301 M/sec (9.52%)
Quoted 8 lines
8,190,383,109 dTLB-loads # 818.971 M/sec (9.52%)
20,432,204 dTLB-load-misses # 0.25% of all dTLB cache hits (9.52%)
3,729,504,674 dTLB-stores # 372.920 M/sec (9.52%)
992,231 dTLB-store-misses # 0.099 M/sec (9.52%)
<not supported> dTLB-prefetches
<not supported> dTLB-prefetch-misses
11,619 iTLB-loads # 0.001 M/sec (9.52%)
1,874,756 iTLB-load-misses # 16135.26% of all iTLB cache hits (14.28%)What was the sample period for this perf stat?
Quoted 2 lines
I have super high iTLB-load-misses. This is probably the cause of high frontend stalled.
It looks very strange that your iTLB-loads are 11,619, while the iTLB-load-misses are much much higher 1,874,756.
Quoted 1 line
Do you know any way to improve iTLB hit rate?
The xdpsock code should be small enough to fit in the iCache, but it might be layout in memory in an unfortunate way. You could play with rearranging the C-code (look at the objdump alignments).
If you want to know the details about code alignment issue, and how to troubleshoot them, you should read this VERY excellent blog post by Denis Bakhvalov:
https://dendibakh.github.io/blog/2018/01/18/Code_alignment_issues
Signature · 4 lines
Best regards, Jesper Dangaard Brouer MSc.CS, Principal Kernel Engineer at Red Hat LinkedIn: http://www.linkedin.com/in/brouer
Hi Jesper,
Thanks for the comments.
Quoted 26 lines
Quoted 17 lines
I assume this xdpsock code is small and should all fit into the icache. However, doing another perf stat on xdpsock l2fwd shows
13,720,109,581 stalled-cycles-frontend # 60.01% frontend cycles
idle (23.82%)<not supported> stalled-cycles-backend
7,994,837 branch-misses # 0.16% of all branches (23.80%) 996,874,424 bus-cycles # 99.679 M/sec (23.80%) 18,942,220,445 ref-cycles # 1894.067 M/sec (28.56%) 100,983,226 LLC-loads # 10.097 M/sec (23.80%) 4,897,089 LLC-load-misses # 4.85% of all LL-cache hits (23.80%) 66,659,889 LLC-stores # 6.665 M/sec (9.52%) 8,373 LLC-store-misses # 0.837 K/sec (9.52%) 158,178,410 LLC-prefetches # 15.817 M/sec (9.52%) 3,011,180 LLC-prefetch-misses # 0.301 M/sec (9.52%)Quoted 8 lines
8,190,383,109 dTLB-loads # 818.971 M/sec (9.52%) 20,432,204 dTLB-load-misses # 0.25% of all dTLB cache hits (9.52%) 3,729,504,674 dTLB-stores # 372.920 M/sec (9.52%) 992,231 dTLB-store-misses # 0.099 M/sec (9.52%) <not supported> dTLB-prefetches <not supported> dTLB-prefetch-misses 11,619 iTLB-loads # 0.001 M/sec (9.52%) 1,874,756 iTLB-load-misses # 16135.26% of all iTLB cache hits (14.28%)
Quoted 2 lines
What was the sample period for this perf stat?
10 seconds.
root@ovs-smartnic:~/net-next/tools/perf# ./perf stat -C 6 sleep 10
Quoted 6 lines
Quoted 2 lines
I have super high iTLB-load-misses. This is probably the cause of high frontend stalled.
It looks very strange that your iTLB-loads are 11,619, while the iTLB-load-misses are much much higher 1,874,756.
Does it mean cpu try to load the code, then fail, then load again and fail again...
So the number of iTLB loads is larger than misses.
Maybe it's related to high nmi rate, where the nmi handler clear my iTLB? Let me try to remove the nmi interference first.
Quoted 10 lines
Quoted 1 line
Do you know any way to improve iTLB hit rate?
The xdpsock code should be small enough to fit in the iCache, but it might be layout in memory in an unfortunate way. You could play with rearranging the C-code (look at the objdump alignments).
If you want to know the details about code alignment issue, and how to troubleshoot them, you should read this VERY excellent blog post by Denis Bakhvalov:
https://dendibakh.github.io/blog/2018/01/18/Code_alignment_issues
Thanks for the link.
William
Quoted 200 lines · Jesper Dangaard Brouer
Quoted 152 lines · On Mon, 26 Mar 2018 09:06:54 -0700 William Tu <[email protected]> wrote:
Quoted 144 lines · Björn Töpel
From: Björn Töpel <[email protected]>
This RFC introduces a new address family called
AF_XDPthat is optimized for high performance packet processing and zero-copy semantics. Throughput improvements can be up to 20x compared to V2 and V3 for the micro benchmarks included. Would be great to get your feedback on it. Note that this is the follow up RFC toAF_PACKETV4 from November last year. The feedback from that RFC submission and the presentation at NetdevConf in Seoul was to create a new address family instead of building on top ofAF_PACKET.AF_XDPis this new address family.The main difference between
AF_XDPandAF_PACKETV2/V3 on a descriptor level is that TX and RX descriptors are separated from packet buffers. An RX or TX descriptor points to a data buffer in a packet buffer area. RX and TX can share the same packet buffer so that a packet does not have to be copied between RX and TX. Moreover, if a packet needs to be kept for a while due to a possible retransmit, then the descriptor that points to that packet buffer can be changed to point to another buffer and reused right away. This again avoids copying data.The RX and TX descriptor rings are registered with the setsockopts
XDP_RX_RINGandXDP_TX_RING, similar toAF_PACKET. The packet buffer area is allocated by user space and registered with the kernel using the newXDP_MEM_REGsetsockopt. All these three areas are shared between user space and kernel space. The socket is then bound with abind()call to a device and a specific queue id on that device, and it is not until bind is completed that traffic starts to flow.An XDP program can be loaded to direct part of the traffic on that device and queue id to user space through a new redirect action in an XDP program called
bpf_xdpsk_redirectthat redirects a packet up to the socket in user space. All the other XDP actions work just as before. Note that the current RFC requires the user to load an XDP program to get any traffic to user space (for example all traffic to user space with the one-liner program "returnbpf_xdpsk_redirect();"). We plan on introducing a patch that removes this requirement and sends all traffic from a queue to user space if anAF_XDPsocket is bound to it.
AF_XDPcan operate in three different modes:XDP_SKB,XDP_DRV, andXDP_DRV_ZC(shorthand forXDP_DRVwith a zero-copy allocator as there is no specific mode calledXDP_DRV_ZC). If the driver does not have support for XDP, orXDP_SKBis explicitly chosen when loading the XDP program,XDP_SKBmode is employed that uses SKBs together with the generic XDP support and copies out the data to user space. A fallback mode that works for any network device. On the other hand, if the driver has support for XDP (all three NDOs:ndo_bpf,ndo_xdp_xmitandndo_xdp_flush), these NDOs, without any modifications, will be used by theAF_XDPcode to provide better performance, but there is still a copy of the data into user space. The last mode,XDP_DRV_ZC, is XDP driver support with the zero-copy user space allocator that provides even better performance. In this mode, the networking HW (or SW driver if it is a virtual driver like veth) DMAs/puts packets straight into the packet buffer that is shared between user space and kernel space. The RX and TX descriptor queues of the networking HW are NOT shared to user space. Only the kernel can read and write these and it is the kernel driver's responsibility to translate these HW specific descriptors to the HW agnostic ones in the virtual descriptor rings that user space sees. This way, a malicious user space program cannot mess with the networking HW. This mode though requires some extensions to XDP.To get the
XDP_DRV_ZCmode to work for RX, we chose to introduce a buffer pool concept so that the same XDP driver code can be used for buffers allocated using the page allocator (XDP_DRV), the user-space zero-copy allocator (XDP_DRV_ZC), or some internal driver specific allocator/cache/recycling mechanism. Thendo_bpfcall has also been extended with two commands for registering and unregistering an XSK socket and is in the RX case mainly used to communicate some information about the user-space buffer pool to the driver.For the TX path, our plan was to use
ndo_xdp_xmitandndo_xdp_flush, but we run into problems with this (further discussion in the challenges section) and had to introduce a new NDO calledndo_xdp_xmit_xsk(xsk = XDP socket). It takes a pointer to a netdevice and an explicit queue id that packets should be sent out on. In contrast tondo_xdp_xmit, it is asynchronous and pulls packets to be sent from the xdp socket (associated with the dev and queue combination that was provided with the NDO call) using a callback (get_tx_packet), and when they have been transmitted it uses another callback (tx_completion) to signal completion of packets. These callbacks are set viando_bpfin the newXDP_REGISTER_XSKcommand.ndo_xdp_xmit_xskis exclusively used by the XDP socket code and thus does not clash with theXDP_REDIRECTuse ofndo_xdp_xmit. This is one of the reasons that theXDP_DRVmode (without ZC) is currently not supported by TX. Please have a look at the challenges section for further discussions.The
AF_XDPbind call acts on a queue pair (channel in ethtool speak), so the user needs to steer the traffic to the zero-copy enabled queue pair. Which queue to use, is up to the user.For an untrusted application, HW packet steering to a specific queue pair (the one associated with the application) is a requirement, as the application would otherwise be able to see other user space processes' packets. If the HW cannot support the required packet steering,
XDP_DRVorXDP_SKBmode have to be used as they do not expose the NIC's packet buffer into user space as the packets are copied into user space from the NIC's packet buffer in the kernel.There is a xdpsock benchmarking/test application included. Say that you would like your UDP traffic from port 4242 to end up in queue 16, that we will enable
AF_XDPon. Here, we use ethtool for this:ethtool -N p3p2 rx-flow-hash udp4 fn
ethtool -N p3p2 flow-type udp4 src-port 4242 dst-port 4242 \
action 16Running the l2fwd benchmark in
XDP_DRV_ZCmode can then be done using:samples/bpf/xdpsock -i p3p2 -q 16 -l -NFor
XDP_SKBmode, use the switch "-S" instead of "-N" and all options can be displayed with "-h", as usual.We have run some benchmarks on a dual socket system with two Broadwell E5 2660 @ 2.0 GHz with hyperthreading turned off. Each socket has 14 cores which gives a total of 28, but only two cores are used in these experiments. One for TR/RX and one for the user space application. The memory is DDR4 @ 2133 MT/s (1067 MHz) and the size of each DIMM is 8192MB and with 8 of those DIMMs in the system we have 64 GB of total memory. The compiler used is gcc version 5.4.0 20160609. The NIC is an Intel I40E 40Gbit/s using the i40e driver.
Below are the results in Mpps of the I40E NIC benchmark runs for 64 byte packets, generated by commercial packet generator HW that is generating packets at full 40 Gbit/s line rate.
XDP baseline numbers without this RFC:
xdp_rxq_info--actionXDP_DROP31.3 Mppsxdp_rxq_info--actionXDP_TX16.7 MppsXDP performance with this RFC i.e. with the buffer allocator:
XDP_DROP21.0 MppsXDP_TX11.9 Mpps
AF_PACKETV4 performance from previous RFC on 4.14-rc7:Benchmark V2 V3 V4 V4+ZC rxdrop 0.67 0.73 0.74 33.7 txpush 0.98 0.98 0.91 19.6 l2fwd 0.66 0.71 0.67 15.5Quoted 6 lines
AF_XDPperformance:Benchmark XDP_SKB XDP_DRV XDP_DRV_ZC (all in Mpps) rxdrop 3.3 11.6 16.9 txpush 2.2 NA* 21.8 l2fwd 1.7 NA* 10.4Quoted 8 lines
Hi,
I also did an evaluation ofAF_XDP, however the performance isn't as good as above.
I'd like to share the result and see if there are some tuning suggestions.System:
16 core, Intel(R) Xeon(R) CPU E5-2440 v2 @ 1.90GHz Intel 10G X540-AT2 ---> so I can only runXDP_SKBmodeHmmm, why is X540-AT2 not able to use XDP natively?
Quoted 5 lines
AF_XDPperformance:Benchmark XDP_SKB rxdrop 1.27 Mpps txpush 0.99 Mppsl2fwd 0.85 Mpps
Definitely too low...
What is the performance if you drop packets via iptables?
Command:
$ iptables -t raw -I PREROUTING -p udp --dport 9 --j DROPQuoted 11 lines
NIC configuration:
the command
"ethtool -N p3p2 flow-type udp4 src-port 4242 dst-port 4242 action 16" doesn't work on my ixgbe driver, so I use ntuple:ethtool -K enp10s0f0 ntuple on
ethtool -U enp10s0f0 flow-type udp4 src-ip 10.1.1.100 action 1 then
echo 1 >/proc/sys/net/core/bpf_jit_enable
./xdpsock -i enp10s0f0 -r -S --queue=1Quoted 5 lines
I also take a look at perf result:
For rxdrop:
86.56% xdpsock xdpsock [.] main9.22% xdpsock [kernel.vmlinux] [k] nmi 4.23% xdpsock xdpsock [.] xq_enqIt looks very strange that you see non-maskable interrupt's (NMI) being this high...
Quoted 6 lines
Quoted 3 lines
For l2fwd:
20.81% xdpsock xdpsock [.] main 10.64% xdpsock [kernel.vmlinux] [k] clflush_cache_rangeOh,
clflush_cache_rangeis being called!
Do your system use an IOMMU ?
Whats the implication here. Should IOMMU be disabled?
I'm asking because I do see a huge difference while running pktgen test for my performance benchmarks, with and without intel_iommu.
-Tushar
Quoted 34 lines
Quoted 8 lines
8.46% xdpsock [kernel.vmlinux] [k] xsk_sendmsg 6.72% xdpsock [kernel.vmlinux] [k] skb_set_owner_w 5.89% xdpsock [kernel.vmlinux] [k] __domain_mapping 5.74% xdpsock [kernel.vmlinux] [k] alloc_skb_with_frags 4.62% xdpsock [kernel.vmlinux] [k] netif_skb_features 3.96% xdpsock [kernel.vmlinux] [k] ___slab_alloc 3.18% xdpsock [kernel.vmlinux] [k] nmiAgain high count for NMI ?!?
Maybe you just forgot to tell perf that you want it to decode the
bpf_progcorrectly?https://prototype-kernel.readthedocs.io/en/latest/bpf/troubleshooting.html#perf-tool-symbols
Enable via:
$ sysctl net/core/bpf_jit_kallsyms=1And use perf report (while BPF is STILL LOADED):
$ perf report --kallsyms=/proc/kallsymsE.g. for emailing this you can use this command:
$ perf report --sort cpu,comm,dso,symbol --kallsyms=/proc/kallsyms --no-children --stdio -g none | head -n 40Quoted 3 lines
I observed that the i40e's
XDP_SKBresult is much better than my ixgbe's result. I wonder inXDP_SKBmode, does the driver make performance difference? Or my cpu (E5-2440 v2 @ 1.90GHz) is too old?I suspect some setup issue on your system.
Quoted 221 lines · Tushar Dave
Quoted 209 lines · Jesper Dangaard Brouer
Quoted 161 lines · On Mon, 26 Mar 2018 09:06:54 -0700 William Tu <[email protected]> wrote:
Quoted 145 lines · Björn Töpel
From: Björn Töpel <[email protected]>
This RFC introduces a new address family called
AF_XDPthat is optimized for high performance packet processing and zero-copy semantics. Throughput improvements can be up to 20x compared to V2 and V3 for the micro benchmarks included. Would be great to get your feedback on it. Note that this is the follow up RFC toAF_PACKETV4 from November last year. The feedback from that RFC submission and the presentation at NetdevConf in Seoul was to create a new address family instead of building on top ofAF_PACKET.AF_XDPis this new address family.The main difference between
AF_XDPandAF_PACKETV2/V3 on a descriptor level is that TX and RX descriptors are separated from packet buffers. An RX or TX descriptor points to a data buffer in a packet buffer area. RX and TX can share the same packet buffer so that a packet does not have to be copied between RX and TX. Moreover, if a packet needs to be kept for a while due to a possible retransmit, then the descriptor that points to that packet buffer can be changed to point to another buffer and reused right away. This again avoids copying data.The RX and TX descriptor rings are registered with the setsockopts
XDP_RX_RINGandXDP_TX_RING, similar toAF_PACKET. The packet buffer area is allocated by user space and registered with the kernel using the newXDP_MEM_REGsetsockopt. All these three areas are shared between user space and kernel space. The socket is then bound with abind()call to a device and a specific queue id on that device, and it is not until bind is completed that traffic starts to flow.An XDP program can be loaded to direct part of the traffic on that device and queue id to user space through a new redirect action in an XDP program called
bpf_xdpsk_redirectthat redirects a packet up to the socket in user space. All the other XDP actions work just as before. Note that the current RFC requires the user to load an XDP program to get any traffic to user space (for example all traffic to user space with the one-liner program "returnbpf_xdpsk_redirect();"). We plan on introducing a patch that removes this requirement and sends all traffic from a queue to user space if anAF_XDPsocket is bound to it.
AF_XDPcan operate in three different modes:XDP_SKB,XDP_DRV, andXDP_DRV_ZC(shorthand forXDP_DRVwith a zero-copy allocator as there is no specific mode calledXDP_DRV_ZC). If the driver does not have support for XDP, orXDP_SKBis explicitly chosen when loading the XDP program,XDP_SKBmode is employed that uses SKBs together with the generic XDP support and copies out the data to user space. A fallback mode that works for any network device. On the other hand, if the driver has support for XDP (all three NDOs:ndo_bpf,ndo_xdp_xmitandndo_xdp_flush), these NDOs, without any modifications, will be used by theAF_XDPcode to provide better performance, but there is still a copy of the data into user space. The last mode,XDP_DRV_ZC, is XDP driver support with the zero-copy user space allocator that provides even better performance. In this mode, the networking HW (or SW driver if it is a virtual driver like veth) DMAs/puts packets straight into the packet buffer that is shared between user space and kernel space. The RX and TX descriptor queues of the networking HW are NOT shared to user space. Only the kernel can read and write these and it is the kernel driver's responsibility to translate these HW specific descriptors to the HW agnostic ones in the virtual descriptor rings that user space sees. This way, a malicious user space program cannot mess with the networking HW. This mode though requires some extensions to XDP.To get the
XDP_DRV_ZCmode to work for RX, we chose to introduce a buffer pool concept so that the same XDP driver code can be used for buffers allocated using the page allocator (XDP_DRV), the user-space zero-copy allocator (XDP_DRV_ZC), or some internal driver specific allocator/cache/recycling mechanism. Thendo_bpfcall has also been extended with two commands for registering and unregistering an XSK socket and is in the RX case mainly used to communicate some information about the user-space buffer pool to the driver.For the TX path, our plan was to use
ndo_xdp_xmitandndo_xdp_flush, but we run into problems with this (further discussion in the challenges section) and had to introduce a new NDO calledndo_xdp_xmit_xsk(xsk = XDP socket). It takes a pointer to a netdevice and an explicit queue id that packets should be sent out on. In contrast tondo_xdp_xmit, it is asynchronous and pulls packets to be sent from the xdp socket (associated with the dev and queue combination that was provided with the NDO call) using a callback (get_tx_packet), and when they have been transmitted it uses another callback (tx_completion) to signal completion of packets. These callbacks are set viando_bpfin the newXDP_REGISTER_XSKcommand.ndo_xdp_xmit_xskis exclusively used by the XDP socket code and thus does not clash with theXDP_REDIRECTuse ofndo_xdp_xmit. This is one of the reasons that theXDP_DRVmode (without ZC) is currently not supported by TX. Please have a look at the challenges section for further discussions.The
AF_XDPbind call acts on a queue pair (channel in ethtool speak), so the user needs to steer the traffic to the zero-copy enabled queue pair. Which queue to use, is up to the user.For an untrusted application, HW packet steering to a specific queue pair (the one associated with the application) is a requirement, as the application would otherwise be able to see other user space processes' packets. If the HW cannot support the required packet steering,
XDP_DRVorXDP_SKBmode have to be used as they do not expose the NIC's packet buffer into user space as the packets are copied into user space from the NIC's packet buffer in the kernel.There is a xdpsock benchmarking/test application included. Say that you would like your UDP traffic from port 4242 to end up in queue 16, that we will enable
AF_XDPon. Here, we use ethtool for this:ethtool -N p3p2 rx-flow-hash udp4 fn
ethtool -N p3p2 flow-type udp4 src-port 4242 dst-port 4242 \
action 16Running the l2fwd benchmark in
XDP_DRV_ZCmode can then be done using:samples/bpf/xdpsock -i p3p2 -q 16 -l -NFor
XDP_SKBmode, use the switch "-S" instead of "-N" and all options can be displayed with "-h", as usual.We have run some benchmarks on a dual socket system with two Broadwell E5 2660 @ 2.0 GHz with hyperthreading turned off. Each socket has 14 cores which gives a total of 28, but only two cores are used in these experiments. One for TR/RX and one for the user space application. The memory is DDR4 @ 2133 MT/s (1067 MHz) and the size of each DIMM is 8192MB and with 8 of those DIMMs in the system we have 64 GB of total memory. The compiler used is gcc version 5.4.0 20160609. The NIC is an Intel I40E 40Gbit/s using the i40e driver.
Below are the results in Mpps of the I40E NIC benchmark runs for 64 byte packets, generated by commercial packet generator HW that is generating packets at full 40 Gbit/s line rate.
XDP baseline numbers without this RFC:
xdp_rxq_info--actionXDP_DROP31.3 Mppsxdp_rxq_info--actionXDP_TX16.7 MppsXDP performance with this RFC i.e. with the buffer allocator:
XDP_DROP21.0 MppsXDP_TX11.9 Mpps
AF_PACKETV4 performance from previous RFC on 4.14-rc7:Benchmark V2 V3 V4 V4+ZC rxdrop 0.67 0.73 0.74 33.7 txpush 0.98 0.98 0.91 19.6 l2fwd 0.66 0.71 0.67 15.5Quoted 6 lines
AF_XDPperformance:Benchmark XDP_SKB XDP_DRV XDP_DRV_ZC (all in Mpps) rxdrop 3.3 11.6 16.9 txpush 2.2 NA* 21.8 l2fwd 1.7 NA* 10.4Hi,
I also did an evaluation ofAF_XDP, however the performance isn't as good as above.
I'd like to share the result and see if there are some tuning suggestions.Quoted 3 lines
System:
16 core, Intel(R) Xeon(R) CPU E5-2440 v2 @ 1.90GHz Intel 10G X540-AT2 ---> so I can only runXDP_SKBmodeHmmm, why is X540-AT2 not able to use XDP natively?
Quoted 5 lines
AF_XDPperformance:Benchmark XDP_SKB rxdrop 1.27 Mpps txpush 0.99 Mppsl2fwd 0.85 Mpps
Definitely too low...
What is the performance if you drop packets via iptables?
Command:
$ iptables -t raw -I PREROUTING -p udp --dport 9 --j DROPQuoted 11 lines
NIC configuration:
the command
"ethtool -N p3p2 flow-type udp4 src-port 4242 dst-port 4242 action 16" doesn't work on my ixgbe driver, so I use ntuple:ethtool -K enp10s0f0 ntuple on
ethtool -U enp10s0f0 flow-type udp4 src-ip 10.1.1.100 action 1 then
echo 1 >/proc/sys/net/core/bpf_jit_enable
./xdpsock -i enp10s0f0 -r -S --queue=1Quoted 5 lines
I also take a look at perf result:
For rxdrop:
86.56% xdpsock xdpsock [.] main9.22% xdpsock [kernel.vmlinux] [k] nmi 4.23% xdpsock xdpsock [.] xq_enqIt looks very strange that you see non-maskable interrupt's (NMI) being this high...
Quoted 1 line
Quoted 7 lines
Quoted 3 lines
For l2fwd:
20.81% xdpsock xdpsock [.] main 10.64% xdpsock [kernel.vmlinux] [k] clflush_cache_rangeOh,
clflush_cache_rangeis being called!
Do your system use an IOMMU ?
Quoted 6 lines
Whats the implication here. Should IOMMU be disabled?
I'm asking because I do see a huge difference while running pktgen test for my performance benchmarks, with and withoutintel_iommu.-Tushar
For the Intel parts the IOMMU can be expensive primarily for Tx, since it should have minimal impact if the Rx pages are pinned/recycled. I am assuming the same is true here for AF_XDP, Bjorn can correct me if I am wrong.
Basically the IOMMU can make creating/destroying a DMA mapping really expensive. The easiest way to work around it in the case of the Intel IOMMU is to boot with "iommu=pt" which will create an identity mapping for the host. The downside is though that you then have the entire system accessible to the device unless a new mapping is created for it by assigning it to a new IOMMU domain.
Thanks.
- Alex
Quoted 227 lines · Alexander Duyck
Quoted 226 lines · Tushar Dave
Quoted 209 lines · Jesper Dangaard Brouer
Quoted 161 lines · On Mon, 26 Mar 2018 09:06:54 -0700 William Tu <[email protected]> wrote:
Quoted 145 lines · Björn Töpel
From: Björn Töpel <[email protected]>
This RFC introduces a new address family called
AF_XDPthat is optimized for high performance packet processing and zero-copy semantics. Throughput improvements can be up to 20x compared to V2 and V3 for the micro benchmarks included. Would be great to get your feedback on it. Note that this is the follow up RFC toAF_PACKETV4 from November last year. The feedback from that RFC submission and the presentation at NetdevConf in Seoul was to create a new address family instead of building on top ofAF_PACKET.AF_XDPis this new address family.The main difference between
AF_XDPandAF_PACKETV2/V3 on a descriptor level is that TX and RX descriptors are separated from packet buffers. An RX or TX descriptor points to a data buffer in a packet buffer area. RX and TX can share the same packet buffer so that a packet does not have to be copied between RX and TX. Moreover, if a packet needs to be kept for a while due to a possible retransmit, then the descriptor that points to that packet buffer can be changed to point to another buffer and reused right away. This again avoids copying data.The RX and TX descriptor rings are registered with the setsockopts
XDP_RX_RINGandXDP_TX_RING, similar toAF_PACKET. The packet buffer area is allocated by user space and registered with the kernel using the newXDP_MEM_REGsetsockopt. All these three areas are shared between user space and kernel space. The socket is then bound with abind()call to a device and a specific queue id on that device, and it is not until bind is completed that traffic starts to flow.An XDP program can be loaded to direct part of the traffic on that device and queue id to user space through a new redirect action in an XDP program called
bpf_xdpsk_redirectthat redirects a packet up to the socket in user space. All the other XDP actions work just as before. Note that the current RFC requires the user to load an XDP program to get any traffic to user space (for example all traffic to user space with the one-liner program "returnbpf_xdpsk_redirect();"). We plan on introducing a patch that removes this requirement and sends all traffic from a queue to user space if anAF_XDPsocket is bound to it.
AF_XDPcan operate in three different modes:XDP_SKB,XDP_DRV, andXDP_DRV_ZC(shorthand forXDP_DRVwith a zero-copy allocator as there is no specific mode calledXDP_DRV_ZC). If the driver does not have support for XDP, orXDP_SKBis explicitly chosen when loading the XDP program,XDP_SKBmode is employed that uses SKBs together with the generic XDP support and copies out the data to user space. A fallback mode that works for any network device. On the other hand, if the driver has support for XDP (all three NDOs:ndo_bpf,ndo_xdp_xmitandndo_xdp_flush), these NDOs, without any modifications, will be used by theAF_XDPcode to provide better performance, but there is still a copy of the data into user space. The last mode,XDP_DRV_ZC, is XDP driver support with the zero-copy user space allocator that provides even better performance. In this mode, the networking HW (or SW driver if it is a virtual driver like veth) DMAs/puts packets straight into the packet buffer that is shared between user space and kernel space. The RX and TX descriptor queues of the networking HW are NOT shared to user space. Only the kernel can read and write these and it is the kernel driver's responsibility to translate these HW specific descriptors to the HW agnostic ones in the virtual descriptor rings that user space sees. This way, a malicious user space program cannot mess with the networking HW. This mode though requires some extensions to XDP.To get the
XDP_DRV_ZCmode to work for RX, we chose to introduce a buffer pool concept so that the same XDP driver code can be used for buffers allocated using the page allocator (XDP_DRV), the user-space zero-copy allocator (XDP_DRV_ZC), or some internal driver specific allocator/cache/recycling mechanism. Thendo_bpfcall has also been extended with two commands for registering and unregistering an XSK socket and is in the RX case mainly used to communicate some information about the user-space buffer pool to the driver.For the TX path, our plan was to use
ndo_xdp_xmitandndo_xdp_flush, but we run into problems with this (further discussion in the challenges section) and had to introduce a new NDO calledndo_xdp_xmit_xsk(xsk = XDP socket). It takes a pointer to a netdevice and an explicit queue id that packets should be sent out on. In contrast tondo_xdp_xmit, it is asynchronous and pulls packets to be sent from the xdp socket (associated with the dev and queue combination that was provided with the NDO call) using a callback (get_tx_packet), and when they have been transmitted it uses another callback (tx_completion) to signal completion of packets. These callbacks are set viando_bpfin the newXDP_REGISTER_XSKcommand.ndo_xdp_xmit_xskis exclusively used by the XDP socket code and thus does not clash with theXDP_REDIRECTuse ofndo_xdp_xmit. This is one of the reasons that theXDP_DRVmode (without ZC) is currently not supported by TX. Please have a look at the challenges section for further discussions.The
AF_XDPbind call acts on a queue pair (channel in ethtool speak), so the user needs to steer the traffic to the zero-copy enabled queue pair. Which queue to use, is up to the user.For an untrusted application, HW packet steering to a specific queue pair (the one associated with the application) is a requirement, as the application would otherwise be able to see other user space processes' packets. If the HW cannot support the required packet steering,
XDP_DRVorXDP_SKBmode have to be used as they do not expose the NIC's packet buffer into user space as the packets are copied into user space from the NIC's packet buffer in the kernel.There is a xdpsock benchmarking/test application included. Say that you would like your UDP traffic from port 4242 to end up in queue 16, that we will enable
AF_XDPon. Here, we use ethtool for this:ethtool -N p3p2 rx-flow-hash udp4 fn
ethtool -N p3p2 flow-type udp4 src-port 4242 dst-port 4242 \
action 16Running the l2fwd benchmark in
XDP_DRV_ZCmode can then be done using:samples/bpf/xdpsock -i p3p2 -q 16 -l -NFor
XDP_SKBmode, use the switch "-S" instead of "-N" and all options can be displayed with "-h", as usual.We have run some benchmarks on a dual socket system with two Broadwell E5 2660 @ 2.0 GHz with hyperthreading turned off. Each socket has 14 cores which gives a total of 28, but only two cores are used in these experiments. One for TR/RX and one for the user space application. The memory is DDR4 @ 2133 MT/s (1067 MHz) and the size of each DIMM is 8192MB and with 8 of those DIMMs in the system we have 64 GB of total memory. The compiler used is gcc version 5.4.0 20160609. The NIC is an Intel I40E 40Gbit/s using the i40e driver.
Below are the results in Mpps of the I40E NIC benchmark runs for 64 byte packets, generated by commercial packet generator HW that is generating packets at full 40 Gbit/s line rate.
XDP baseline numbers without this RFC:
xdp_rxq_info--actionXDP_DROP31.3 Mppsxdp_rxq_info--actionXDP_TX16.7 MppsXDP performance with this RFC i.e. with the buffer allocator:
XDP_DROP21.0 MppsXDP_TX11.9 Mpps
AF_PACKETV4 performance from previous RFC on 4.14-rc7:Benchmark V2 V3 V4 V4+ZC rxdrop 0.67 0.73 0.74 33.7 txpush 0.98 0.98 0.91 19.6 l2fwd 0.66 0.71 0.67 15.5Quoted 6 lines
AF_XDPperformance:Benchmark XDP_SKB XDP_DRV XDP_DRV_ZC (all in Mpps) rxdrop 3.3 11.6 16.9 txpush 2.2 NA* 21.8 l2fwd 1.7 NA* 10.4Hi,
I also did an evaluation ofAF_XDP, however the performance isn't as good as above.
I'd like to share the result and see if there are some tuning suggestions.Quoted 3 lines
System:
16 core, Intel(R) Xeon(R) CPU E5-2440 v2 @ 1.90GHz Intel 10G X540-AT2 ---> so I can only runXDP_SKBmodeHmmm, why is X540-AT2 not able to use XDP natively?
Quoted 5 lines
AF_XDPperformance:Benchmark XDP_SKB rxdrop 1.27 Mpps txpush 0.99 Mppsl2fwd 0.85 Mpps
Definitely too low...
What is the performance if you drop packets via iptables?
Command:
$ iptables -t raw -I PREROUTING -p udp --dport 9 --j DROPQuoted 11 lines
NIC configuration:
the command
"ethtool -N p3p2 flow-type udp4 src-port 4242 dst-port 4242 action 16" doesn't work on my ixgbe driver, so I use ntuple:ethtool -K enp10s0f0 ntuple on
ethtool -U enp10s0f0 flow-type udp4 src-ip 10.1.1.100 action 1 then
echo 1 >/proc/sys/net/core/bpf_jit_enable
./xdpsock -i enp10s0f0 -r -S --queue=1Quoted 5 lines
I also take a look at perf result:
For rxdrop:
86.56% xdpsock xdpsock [.] main9.22% xdpsock [kernel.vmlinux] [k] nmi 4.23% xdpsock xdpsock [.] xq_enqIt looks very strange that you see non-maskable interrupt's (NMI) being this high...
Quoted 1 line
Quoted 7 lines
Quoted 3 lines
For l2fwd:
20.81% xdpsock xdpsock [.] main 10.64% xdpsock [kernel.vmlinux] [k] clflush_cache_rangeOh,
clflush_cache_rangeis being called!
Do your system use an IOMMU ?Whats the implication here. Should IOMMU be disabled?
I'm asking because I do see a huge difference while running pktgen test for my performance benchmarks, with and withoutintel_iommu.
Quoted 6 lines
Quoted 1 line
-Tushar
For the Intel parts the IOMMU can be expensive primarily for Tx, since it should have minimal impact if the Rx pages are pinned/recycled. I am assuming the same is true here for
AF_XDP, Bjorn can correct me if I am wrong.
Indeed. Intel iommu has least effect on RX because of premap/recycle. But TX dma map and unmap is really expensive!
Quoted 7 lines
Basically the IOMMU can make creating/destroying a DMA mapping really expensive. The easiest way to work around it in the case of the Intel IOMMU is to boot with "iommu=pt" which will create an identity mapping for the host. The downside is though that you then have the entire system accessible to the device unless a new mapping is created for it by assigning it to a new IOMMU domain.
Yeah thats what I would say, If you really want to use intel iommu and don't want to hit by performance , use 'iommu=pt'.
Good to have confirmation from you Alex. Thanks.
btw, I don't want to distract this thread on iommu discussion however even using 'pt' doesn't give you the same performance numbers that you rather get with intel iommu disabled!
-Tushar
Quoted 5 lines
Thanks.
- Alex
Quoted 12 lines
Indeed. Intel iommu has least effect on RX because of premap/recycle. But TX dma map and unmap is really expensive!
Quoted 7 lines
Basically the IOMMU can make creating/destroying a DMA mapping really expensive. The easiest way to work around it in the case of the Intel IOMMU is to boot with "iommu=pt" which will create an identity mapping for the host. The downside is though that you then have the entire system accessible to the device unless a new mapping is created for it by assigning it to a new IOMMU domain.
Quoted 5 lines
Yeah thats what I would say, If you really want to use intel iommu and don't want to hit by performance , use 'iommu=pt'.
Good to have confirmation from you Alex. Thanks.
Thanks for the suggestion! Update my performance number:
without iommu=pt (posted before)
Benchmark XDP_SKB
rxdrop 2.3 Mpps
txpush 1.05 Mpps
l2fwd 0.90 Mpps
with iommu=pt (new)
Benchmark XDP_SKB
rxdrop 2.24 Mpps
txpush 1.54 Mpps
l2fwd 1.23 Mpps
TX indeed shows better rate, while RX remains.
William
2018-03-27 1:03 GMT+02:00 Alexander Duyck <[email protected]>:
Quoted 1 line · Tushar Dave
[...]
Quoted 6 lines
Quoted 6 lines
Whats the implication here. Should IOMMU be disabled?
I'm asking because I do see a huge difference while running pktgen test for my performance benchmarks, with and withoutintel_iommu.
Quoted 7 lines
Quoted 1 line
-Tushar
For the Intel parts the IOMMU can be expensive primarily for Tx, since it should have minimal impact if the Rx pages are pinned/recycled. I am assuming the same is true here for
AF_XDP, Bjorn can correct me if I am wrong.
For the non-zc case the DMA mapping is done in the Tx fast path, so there, as Alex says, you'll definitely see a performance penalty. For Rx the page-recycle mechanism (Intel drivers) usally avoids doing any DMA mappings in the fast-path.
As for AF_XDP zerocopy mode, we do the DMA mapping up front (avoiding the single-use mappings), to avoid that performance hit. Keep in mind, though, that the IOTLB is still in play, and usually performs worse under pressure, than the non-IOMMU case.
Quoted 13 lines
Basically the IOMMU can make creating/destroying a DMA mapping really expensive. The easiest way to work around it in the case of the Intel IOMMU is to boot with "iommu=pt" which will create an identity mapping for the host. The downside is though that you then have the entire system accessible to the device unless a new mapping is created for it by assigning it to a new IOMMU domain.
Thanks.
- Alex