Introducing ixgbe AF_XDP ZC support
Subsystems (3)
cover Introducing ixgbe AF_XDP ZC support
From: Bj?rn T?pel <[email protected]>
This patch set introduces zero-copy AF_XDP support for Intel's ixgbe driver.
The ixgbe zero-copy code is located in its own file ixgbe_xsk.[ch], analogous to the i40e ZC support. Again, as in i40e, code paths have been copied from the XDP path to the zero-copy path. Going forward we will try to generalize more code between the AF_XDP ZC drivers, and also reduce the heavy C&P.
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 7.3.0. The NIC is Intel 82599ES/X520-2 10Gbit/s using the ixgbe driver.
Below are the results in Mpps of the 82599ES/X520-2 NIC benchmark runs for 64B and 1500B packets, generated by a commercial packet generator HW blasting packets at full 10Gbit/s line rate. The results are with retpoline and all other spectre and meltdown fixes.
AF_XDP performance 64B packets:
Benchmark XDP_DRV with zerocopy
rxdrop 14.7 txpush 14.6 l2fwd 11.1
AF_XDP performance 1500B packets:
Benchmark XDP_DRV with zerocopy
rxdrop 0.8
l2fwd 0.8
XDP performance on our system as a base line.
64B packets:
XDP stats CPU Mpps issue-pps XDP-RX CPU 16 14.7 0
1500B packets:
XDP stats CPU Mpps issue-pps XDP-RX CPU 16 0.8 0
The structure of the patch set is as follows:
Patch 1: Introduce Rx/Tx ring enable/disable functionality Patch 2: Preparatory patche to ixgbe driver code for RX Patch 3: ixgbe zero-copy support for RX
Patch 4: Preparatory patch to ixgbe driver code for TX Patch 5: ixgbe zero-copy support for TX
Cheers!
Bj?rn
Bj?rn T?pel (5):
ixgbe: added Rx/Tx ring disable/enable functions
ixgbe: move common Rx functions to ixgbe_txrx_common.h
ixgbe: add AF_XDP zero-copy Rx support
ixgbe: move common Tx functions to ixgbe_txrx_common.h
ixgbe: add AF_XDP zero-copy Tx support
drivers/net/ethernet/intel/ixgbe/Makefile | 3 +- drivers/net/ethernet/intel/ixgbe/ixgbe.h | 27 +- drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 290 ++++++- .../ethernet/intel/ixgbe/ixgbe_txrx_common.h | 50 ++ drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c | 814 ++++++++++++++++++ 5 files changed, 1139 insertions(+), 45 deletions(-) create mode 100644 drivers/net/ethernet/intel/ixgbe/ixgbe_txrx_common.h create mode 100644 drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c
Signature · 1 line
2.17.1
PATCH 1/5 ixgbe: added Rx/Tx ring disable/enable functions
From: Bj?rn T?pel <[email protected]>
Add functions for Rx/Tx ring enable/disable. Instead of resetting the whole device, only the affected ring is disabled or enabled.
This plumbing is used in later commits, when zero-copy AF_XDP support is introduced.
--- drivers/net/ethernet/intel/ixgbe/ixgbe.h | 1 + drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 158 ++++++++++++++++++ 2 files changed, 159 insertions(+)
drivers/net/ethernet/intel/ixgbe/ixgbe.h +1 -0
@@ -271,6 +271,7 @@ enum ixgbe_ring_state_t { __IXGBE_TX_DETECT_HANG, __IXGBE_HANG_CHECK_ARMED, __IXGBE_TX_XDP_RING, + __IXGBE_TX_DISABLED, };#define ring_uses_build_skb (ring) \
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +158 -0
176 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 2/5 ixgbe: move common Rx functions to ixgbe_txrx_common.h
In reply to Björn TöpelFrom: Bj?rn T?pel <[email protected]>
This patch prepares for the upcoming zero-copy Rx functionality, by moving/changing linkage of common functions, used both by the regular path and zero-copy path.
--- drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 29 +++++++------------ .../ethernet/intel/ixgbe/ixgbe_txrx_common.h | 26 +++++++++++++++++ 2 files changed, 37 insertions(+), 18 deletions(-) create mode 100644 drivers/net/ethernet/intel/ixgbe/ixgbe_txrx_common.h
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +11 -18
@@ -40,6 +40,7 @@#include "ixgbe_dcb_82599.h" #include "ixgbe_sriov.h" #include "ixgbe_model.h" +#include "ixgbe_txrx_common.h" char ixgbe_driver_name[] ="ixgbe" ; static const char ixgbe_driver_string[] =
@@ -1673,9 +1674,9 @@ static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,* order to populate the hash, checksum, VLAN, timestamp, protocol, and * other fields within the skb. **/ -static void ixgbe_process_skb_fields (struct ixgbe_ring *rx_ring, -union ixgbe_adv_rx_desc *rx_desc, -struct sk_buff *skb) +void ixgbe_process_skb_fields (struct ixgbe_ring *rx_ring, +union ixgbe_adv_rx_desc *rx_desc, +struct sk_buff *skb) {struct net_device *dev = rx_ring->netdev;u32 flags = rx_ring->q_vector->adapter->flags;
@@ -1708,8 +1709,8 @@ static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring, skb->protocol =eth_type_trans (skb, dev); } -static void ixgbe_rx_skb (struct ixgbe_q_vector *q_vector, -struct sk_buff *skb) +void ixgbe_rx_skb (struct ixgbe_q_vector *q_vector, +struct sk_buff *skb) {napi_gro_receive (&q_vector->napi, skb); }
@@ -1868,9 +1869,9 @@ static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,* * Returns true if an error was encountered and skb was freed. **/ -static bool ixgbe_cleanup_headers (struct ixgbe_ring *rx_ring, -union ixgbe_adv_rx_desc *rx_desc, -struct sk_buff *skb) +bool ixgbe_cleanup_headers (struct ixgbe_ring *rx_ring, +union ixgbe_adv_rx_desc *rx_desc, +struct sk_buff *skb) {struct net_device *netdev = rx_ring->netdev;
@@ -2186,14 +2187,6 @@ static struct sk_buff *ixgbe_build_skb(struct ixgbe_ring *rx_ring,return skb; } -#define IXGBE_XDP_PASS 0 -#define IXGBE_XDP_CONSUMED BIT(0) -#define IXGBE_XDP_TX BIT(1) -#define IXGBE_XDP_REDIR BIT(2) - -static int ixgbe_xmit_xdp_ring (struct ixgbe_adapter *adapter, -struct xdp_frame *xdpf); -static struct sk_buff *ixgbe_run_xdp (struct ixgbe_adapter *adapter,struct ixgbe_ring *rx_ring,struct xdp_buff *xdp)
@@ -8465,8 +8458,8 @@ static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb, }#endif -static int ixgbe_xmit_xdp_ring (struct ixgbe_adapter *adapter, -struct xdp_frame *xdpf) +int ixgbe_xmit_xdp_ring (struct ixgbe_adapter *adapter, +struct xdp_frame *xdpf) {struct ixgbe_ring *ring = adapter->xdp_ring[smp_processor_id ()];struct ixgbe_tx_buffer *tx_buffer;
drivers/net/ethernet/intel/ixgbe/ixgbe_txrx_common.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright(c) 2018 Intel Corporation. */ + +#ifndef _IXGBE_TXRX_COMMON_H_ +#define _IXGBE_TXRX_COMMON_H_ + +#define IXGBE_XDP_PASS 0 +#define IXGBE_XDP_CONSUMED BIT(0) +#define IXGBE_XDP_TX BIT(1) +#define IXGBE_XDP_REDIR BIT(2) + +int ixgbe_xmit_xdp_ring (struct ixgbe_adapter *adapter, +struct xdp_frame *xdpf); +bool ixgbe_cleanup_headers (struct ixgbe_ring *rx_ring, +union ixgbe_adv_rx_desc *rx_desc, +struct sk_buff *skb); +void ixgbe_process_skb_fields (struct ixgbe_ring *rx_ring, +union ixgbe_adv_rx_desc *rx_desc, +struct sk_buff *skb); +void ixgbe_rx_skb (struct ixgbe_q_vector *q_vector, +struct sk_buff *skb); + +void ixgbe_txrx_ring_disable (struct ixgbe_adapter *adapter,int ring); +void ixgbe_txrx_ring_enable (struct ixgbe_adapter *adapter,int ring); + +#endif /* #define _IXGBE_TXRX_COMMON_H_ */
Signature · 1 line
2.17.1
PATCH 3/5 ixgbe: add AF_XDP zero-copy Rx support
In reply to Björn TöpelFrom: Bj?rn T?pel <[email protected]>
This patch adds zero-copy Rx support for AF_XDP sockets. Instead of allocating buffers of type MEM_TYPE_PAGE_SHARED, the Rx frames are allocated as MEM_TYPE_ZERO_COPY when AF_XDP is enabled for a certain queue.
All AF_XDP specific functions are added to a new file, ixgbe_xsk.c.
Note that when AF_XDP zero-copy is enabled, the XDP action XDP_PASS will allocate a new buffer and copy the zero-copy frame prior passing it to the kernel stack.
--- drivers/net/ethernet/intel/ixgbe/Makefile | 3 +- drivers/net/ethernet/intel/ixgbe/ixgbe.h | 26 +- drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 78 ++- .../ethernet/intel/ixgbe/ixgbe_txrx_common.h | 15 + drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c | 639 ++++++++++++++++++ 5 files changed, 741 insertions(+), 20 deletions(-) create mode 100644 drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c
drivers/net/ethernet/intel/ixgbe/Makefile +2 -1
@@ -8,7 +8,8 @@ obj-$(CONFIG_IXGBE) += ixgbe.o ixgbe-objs := ixgbe_main.o ixgbe_common.o ixgbe_ethtool.o \ ixgbe_82599.o ixgbe_82598.o ixgbe_phy.o ixgbe_sriov.o \ - ixgbe_mbx.o ixgbe_x540.o ixgbe_x550.o ixgbe_lib.o ixgbe_ptp.o + ixgbe_mbx.o ixgbe_x540.o ixgbe_x550.o ixgbe_lib.o ixgbe_ptp.o \ + ixgbe_xsk.o ixgbe-$(CONFIG_IXGBE_DCB) += ixgbe_dcb.o ixgbe_dcb_82598.o \ ixgbe_dcb_82599.o ixgbe_dcb_nl.o
drivers/net/ethernet/intel/ixgbe/ixgbe.h +19 -7
@@ -228,13 +228,17 @@ struct ixgbe_tx_buffer {struct ixgbe_rx_buffer {struct sk_buff *skb;dma_addr_t dma; -struct page *page; -#if (BITS_PER_LONG >32 ) || (PAGE_SIZE >=65536 ) -__u32 page_offset; -#else -__u16 page_offset; -#endif -__u16 pagecnt_bias; +union { +struct { +struct page *page; +__u32 page_offset; +__u16 pagecnt_bias; + }; +struct { +void *addr; +u64 handle; + }; + }; };struct ixgbe_queue_stats {
@@ -348,6 +352,9 @@ struct ixgbe_ring {struct ixgbe_rx_queue_stats rx_stats; };struct xdp_rxq_info xdp_rxq; +struct xdp_umem *xsk_umem; +struct zero_copy_allocator zca;/* ZC allocator anchor */ +u16 rx_buf_len; }____cacheline_internodealigned_in_smp ;enum ixgbe_ring_f_enum {
@@ -765,6 +772,11 @@ struct ixgbe_adapter {#ifdef CONFIG_XFRM_OFFLOAD struct ixgbe_ipsec *ipsec;#endif /* CONFIG_XFRM_OFFLOAD */ + +/* AF_XDP zero-copy */ +struct xdp_umem **xsk_umems; +u16 num_xsk_umems_used; +u16 num_xsk_umems; };static inline u8 ixgbe_max_rss_indices (struct ixgbe_adapter *adapter)
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +66 -12
146 lines not on this page · raw message
drivers/net/ethernet/intel/ixgbe/ixgbe_txrx_common.h +15 -0
@@ -23,4 +23,19 @@ void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,void ixgbe_txrx_ring_disable (struct ixgbe_adapter *adapter,int ring);void ixgbe_txrx_ring_enable (struct ixgbe_adapter *adapter,int ring); +struct xdp_umem *ixgbe_xsk_umem (struct ixgbe_adapter *adapter, +struct ixgbe_ring *ring); +int ixgbe_xsk_umem_query (struct ixgbe_adapter *adapter,struct xdp_umem **umem, +u16 qid); +int ixgbe_xsk_umem_setup (struct ixgbe_adapter *adapter,struct xdp_umem *umem, +u16 qid); + +void ixgbe_zca_free (struct zero_copy_allocator *alloc,unsigned long handle); + +void ixgbe_alloc_rx_buffers_zc (struct ixgbe_ring *rx_ring,u16 cleaned_count); +int ixgbe_clean_rx_irq_zc (struct ixgbe_q_vector *q_vector, +struct ixgbe_ring *rx_ring, +const int budget); +void ixgbe_xsk_clean_rx_ring (struct ixgbe_ring *rx_ring); +#endif /* #define _IXGBE_TXRX_COMMON_H_ */
drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c new file +639 -0
639 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH 3/5] ixgbe: add AF_XDP zero-copy Rx support
drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c line 123
Quoted 5 lines · Bj?rn T?pel
drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c new file +5
-0+if (adapter->flags &IXGBE_FLAG_SRIOV_ENABLED ) +return -EINVAL ; + +if (adapter->flags &IXGBE_FLAG_DCB_ENABLED ) +return -EINVAL ;
Hm, should you add UMEM checks to all the places these may get enabled? Like fabf1bce103a ("ixgbe: Prevent unsupported configurations with XDP") did?
Re: [PATCH 3/5] ixgbe: add AF_XDP zero-copy Rx support
Den tis 25 sep. 2018 kl 16:57 skrev Jakub Kicinski <[email protected]>:
Quoted 11 lines · Bj?rn T?pel
drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c line 123
Quoted 5 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c new file +5
-0+if (adapter->flags &IXGBE_FLAG_SRIOV_ENABLED ) +return -EINVAL ; + +if (adapter->flags &IXGBE_FLAG_DCB_ENABLED ) +return -EINVAL ;Hm, should you add UMEM checks to all the places these may get enabled? Like
fabf1bce103a("ixgbe: Prevent unsupported configurations with XDP") did?
Actually, I can remove these checks, since it's already checked by the XDP path. AF_XDP ZC is enabled only when XDP is enabled. So there's no need to have the XDP checks in the AF_XDP path.
Bj?rn
PATCH 4/5 ixgbe: move common Tx functions to ixgbe_txrx_common.h
In reply to Björn TöpelFrom: Bj?rn T?pel <[email protected]>
This patch prepares for the upcoming zero-copy Tx functionality by moving common functions used both by the regular path and zero-copy path.
--- drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 9 +++------ drivers/net/ethernet/intel/ixgbe/ixgbe_txrx_common.h | 5 +++++ 2 files changed, 8 insertions(+), 6 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +3 -6
@@ -895,8 +895,8 @@ static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction, } } -static inline void ixgbe_irq_rearm_queues (struct ixgbe_adapter *adapter, -u64 qmask) +void ixgbe_irq_rearm_queues (struct ixgbe_adapter *adapter, +u64 qmask) {u32 mask;
@@ -8150,9 +8150,6 @@ static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)return __ixgbe_maybe_stop_tx (tx_ring, size); } -#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \ - IXGBE_TXD_CMD_RS) -static int ixgbe_tx_map (struct ixgbe_ring *tx_ring,struct ixgbe_tx_buffer *first,const u8 hdr_len)
@@ -10275,7 +10272,7 @@ static int ixgbe_xdp(struct net_device *dev, struct netdev_bpf *xdp) } } -static void ixgbe_xdp_ring_update_tail (struct ixgbe_ring *ring) +void ixgbe_xdp_ring_update_tail (struct ixgbe_ring *ring) {/* Force memory writes to complete before letting h/w know there * are new descriptors to fetch.
drivers/net/ethernet/intel/ixgbe/ixgbe_txrx_common.h +5 -0
@@ -9,6 +9,9 @@#define IXGBE_XDP_TX BIT(1)#define IXGBE_XDP_REDIR BIT(2) +#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \ + IXGBE_TXD_CMD_RS) +int ixgbe_xmit_xdp_ring (struct ixgbe_adapter *adapter,struct xdp_frame *xdpf); bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
@@ -19,6 +22,8 @@ void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring, struct sk_buff *skb);void ixgbe_rx_skb (struct ixgbe_q_vector *q_vector,struct sk_buff *skb); +void ixgbe_xdp_ring_update_tail (struct ixgbe_ring *ring); +void ixgbe_irq_rearm_queues (struct ixgbe_adapter *adapter,u64 qmask);void ixgbe_txrx_ring_disable (struct ixgbe_adapter *adapter,int ring);void ixgbe_txrx_ring_enable (struct ixgbe_adapter *adapter,int ring);
Signature · 1 line
2.17.1
PATCH 5/5 ixgbe: add AF_XDP zero-copy Tx support
In reply to Björn TöpelFrom: Bj?rn T?pel <[email protected]>
This patch adds zero-copy Tx support for AF_XDP sockets. It implements the ndo_xsk_async_xmit netdev ndo and performs all the Tx logic from a NAPI context. This means pulling egress packets from the Tx ring, placing the frames on the NIC HW descriptor ring and completing sent frames back to the application via the completion ring.
The regular XDP Tx ring is used for AF_XDP as well. This rationale for this is as follows: XDP_REDIRECT guarantees mutual exclusion between different NAPI contexts based on CPU id. In other words, a netdev can XDP_REDIRECT to another netdev with a different NAPI context, since the operation is bound to a specific core and each core has its own hardware ring.
As the AF_XDP Tx action is running in the same NAPI context and using the same ring, it will also be protected from XDP_REDIRECT actions with the exact same mechanism.
As with AF_XDP Rx, all AF_XDP Tx specific functions are added to ixgbe_xsk.c.
--- drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 16 +- .../ethernet/intel/ixgbe/ixgbe_txrx_common.h | 4 + drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c | 175 ++++++++++++++++++ 3 files changed, 194 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +15 -1
@@ -3161,7 +3161,11 @@ int ixgbe_poll(struct napi_struct *napi, int budget)#endif ixgbe_for_each_ring (ring, q_vector->tx) { -if (!ixgbe_clean_tx_irq (q_vector, ring, budget)) +bool wd = ring->xsk_umem ? +ixgbe_clean_xdp_tx_irq (q_vector, ring, budget) : +ixgbe_clean_tx_irq (q_vector, ring, budget); + +if (!wd) clean_complete = false; }
@@ -3472,6 +3476,9 @@ void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,u32 txdctl =IXGBE_TXDCTL_ENABLE ;u8 reg_idx = ring->reg_idx; +if (ring_is_xdp (ring)) + ring->xsk_umem =ixgbe_xsk_umem (adapter, ring); +/* disable queue to avoid issues while updating state */ IXGBE_WRITE_REG (hw,IXGBE_TXDCTL (reg_idx),0 );IXGBE_WRITE_FLUSH (hw);
@@ -5938,6 +5945,11 @@ static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)u16 i = tx_ring->next_to_clean;struct ixgbe_tx_buffer *tx_buffer = &tx_ring->tx_buffer_info[i]; +if (tx_ring->xsk_umem) { +ixgbe_xsk_clean_tx_ring (tx_ring); + goto out; + } +while (i != tx_ring->next_to_use) {union ixgbe_adv_tx_desc *eop_desc, *tx_desc;
@@ -5989,6 +6001,7 @@ static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)if (!ring_is_xdp (tx_ring))netdev_tx_reset_queue (txring_txq (tx_ring)); +out:/* reset next_to_use and next_to_clean */ tx_ring->next_to_use =0 ; tx_ring->next_to_clean =0 ;
@@ -10369,6 +10382,7 @@ static const struct net_device_ops ixgbe_netdev_ops = { .ndo_features_check = ixgbe_features_check, .ndo_bpf = ixgbe_xdp, .ndo_xdp_xmit = ixgbe_xdp_xmit, + .ndo_xsk_async_xmit = ixgbe_xsk_async_xmit, }; static void ixgbe_disable_txr_hw(struct ixgbe_adapter *adapter,
drivers/net/ethernet/intel/ixgbe/ixgbe_txrx_common.h +4 -0
@@ -42,5 +42,9 @@ int ixgbe_clean_rx_irq_zc(struct ixgbe_q_vector *q_vector,struct ixgbe_ring *rx_ring, const int budget);void ixgbe_xsk_clean_rx_ring (struct ixgbe_ring *rx_ring); +bool ixgbe_clean_xdp_tx_irq (struct ixgbe_q_vector *q_vector, +struct ixgbe_ring *tx_ring,int napi_budget); +int ixgbe_xsk_async_xmit (struct net_device *dev,u32 queue_id); +void ixgbe_xsk_clean_tx_ring (struct ixgbe_ring *tx_ring);#endif /* #define _IXGBE_TXRX_COMMON_H_ */
drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c +175 -0
178 lines not on this page · raw message
Signature · 1 line
2.17.1