igb: Add support for AF_XDP zero-copy
Subsystems (4)
v3 cover igb: Add support for AF_XDP zero-copy
The first couple of patches adds helper funcctions to prepare for AF_XDP zero-copy support which comes in the last couple of patches, one each for Rx and TX paths.
As mentioned in v1 patchset [0], I don't have access to an actual IGB device to provide correct performance numbers. I have used Intel 82576EB emulator in QEMU [1] to test the changes to IGB driver.
The tests use one isolated vCPU for RX/TX and one isolated vCPU for the xdp-sock application [2]. Hope these measurements provide at the least some indication on the increase in performance when using ZC, especially in the TX path. It would be awesome if someone with a real IGB NIC can test the patch.
AF_XDP performance using 64 byte packets in Kpps.
Benchmark: XDP-SKB XDP-DRV XDP-DRV(ZC)
rxdrop 220 235 350
txpush 1.000 1.000 410
l2fwd 1.000 1.000 200
AF_XDP performance using 1500 byte packets in Kpps.
Benchmark: XDP-SKB XDP-DRV XDP-DRV(ZC)
rxdrop 200 210 310
txpush 1.000 1.000 410
l2fwd 0.900 1.000 160
[0]: https://lore.kernel.org/intel-wired-lan/[email protected]/
[1]: https://www.qemu.org/docs/master/system/devices/igb.html
[2]: https://github.com/xdp-project/bpf-examples/tree/master/AF_XDP-example
v2->v3:
- Avoid TX unit hang when using AF_XDP zero-copy by setting time_stamp on the tx_buffer_info
- Fix uninitialized nb_buffs (Simon Horman)
v1->v2:
- Use batch XSK APIs (Maciej Fijalkowski)
- Follow reverse xmas tree convention and remove the ternary operator use (Simon Horman)
Sriram Yagnaraman (4):
igb: prepare for AF_XDP zero-copy support
igb: Introduce XSK data structures and helpers
igb: add AF_XDP zero-copy Rx support
igb: add AF_XDP zero-copy Tx support
drivers/net/ethernet/intel/igb/Makefile | 2 +- drivers/net/ethernet/intel/igb/igb.h | 35 +- drivers/net/ethernet/intel/igb/igb_main.c | 181 ++++++-- drivers/net/ethernet/intel/igb/igb_xsk.c | 522 ++++++++++++++++++++++ 4 files changed, 694 insertions(+), 46 deletions(-) create mode 100644 drivers/net/ethernet/intel/igb/igb_xsk.c
Signature · 1 line
2.34.1
PATCH v3 1/4 igb: prepare for AF_XDP zero-copy support
Always call igb_xdp_ring_update_tail under __netif_tx_lock, add a comment to indicate that. This is needed to share the same TX ring between XDP, XSK and slow paths.
Remove static qualifiers on the following functions to be able to call from XSK specific file that is added in the later patches
- igb_xdp_tx_queue_mapping
- igb_xdp_ring_update_tail
- igb_clean_tx_ring
- igb_clean_rx_ring
- igb_run_xdp
- igb_process_skb_fields
Introduce igb_xdp_is_enabled() to check if an XDP program is assigned to the device.
--- drivers/net/ethernet/intel/igb/igb.h | 15 ++++++++++++ drivers/net/ethernet/intel/igb/igb_main.c | 29 +++++++++++------------ 2 files changed, 29 insertions(+), 15 deletions(-)
drivers/net/ethernet/intel/igb/igb.h +15 -0
@@ -718,6 +718,8 @@ extern char igb_driver_name[];int igb_xmit_xdp_ring (struct igb_adapter *adapter,struct igb_ring *ring,struct xdp_frame *xdpf); +struct igb_ring *igb_xdp_tx_queue_mapping (struct igb_adapter *adapter); +void igb_xdp_ring_update_tail (struct igb_ring *ring);int igb_open (struct net_device *netdev);int igb_close (struct net_device *netdev);int igb_up (struct igb_adapter *);
@@ -731,12 +733,20 @@ int igb_setup_tx_resources(struct igb_ring *);int igb_setup_rx_resources (struct igb_ring *);void igb_free_tx_resources (struct igb_ring *);void igb_free_rx_resources (struct igb_ring *); +void igb_clean_tx_ring (struct igb_ring *tx_ring); +void igb_clean_rx_ring (struct igb_ring *rx_ring);void igb_configure_tx_ring (struct igb_adapter *,struct igb_ring *);void igb_configure_rx_ring (struct igb_adapter *,struct igb_ring *);void igb_setup_tctl (struct igb_adapter *);void igb_setup_rctl (struct igb_adapter *);void igb_setup_srrctl (struct igb_adapter *,struct igb_ring *);netdev_tx_t igb_xmit_frame_ring (struct sk_buff *,struct igb_ring *); +struct sk_buff *igb_run_xdp (struct igb_adapter *adapter, +struct igb_ring *rx_ring, +struct xdp_buff *xdp); +void igb_process_skb_fields (struct igb_ring *rx_ring, +union e1000_adv_rx_desc *rx_desc, +struct sk_buff *skb);void igb_alloc_rx_buffers (struct igb_ring *,u16 );void igb_update_stats (struct igb_adapter *);bool igb_has_link (struct igb_adapter *adapter);
@@ -797,6 +807,11 @@ static inline struct netdev_queue *txring_txq(const struct igb_ring *tx_ring)return netdev_get_tx_queue (tx_ring->netdev, tx_ring->queue_index); } +static inline bool igb_xdp_is_enabled (struct igb_adapter *adapter) +{ +return !!adapter->xdp_prog; +} +int igb_add_filter (struct igb_adapter *adapter,struct igb_nfc_filter *input); int igb_erase_filter(struct igb_adapter *adapter,
drivers/net/ethernet/intel/igb/igb_main.c +14 -15
@@ -117,8 +117,6 @@ static void igb_configure_tx(struct igb_adapter *);static void igb_configure_rx (struct igb_adapter *);static void igb_clean_all_tx_rings (struct igb_adapter *);static void igb_clean_all_rx_rings (struct igb_adapter *); -static void igb_clean_tx_ring (struct igb_ring *); -static void igb_clean_rx_ring (struct igb_ring *);static void igb_set_rx_mode (struct net_device *);static void igb_update_phy_info (struct timer_list *);static void igb_watchdog (struct timer_list *);
@@ -2939,7 +2937,8 @@ static int igb_xdp(struct net_device *dev, struct netdev_bpf *xdp) } } -static void igb_xdp_ring_update_tail (struct igb_ring *ring) +/* This function assumes __netif_tx_lock is held by the caller. */ +void igb_xdp_ring_update_tail (struct igb_ring *ring) {/* Force memory writes to complete before letting h/w know there * are new descriptors to fetch.
@@ -2948,7 +2947,7 @@ static void igb_xdp_ring_update_tail(struct igb_ring *ring)writel (ring->next_to_use, ring->tail); } -static struct igb_ring *igb_xdp_tx_queue_mapping (struct igb_adapter *adapter) +struct igb_ring *igb_xdp_tx_queue_mapping (struct igb_adapter *adapter) {unsigned int r_idx =smp_processor_id ();
@@ -3025,11 +3024,11 @@ static int igb_xdp_xmit(struct net_device *dev, int n, nxmit++; } -__netif_tx_unlock (nq); -if (unlikely (flags &XDP_XMIT_FLUSH ))igb_xdp_ring_update_tail (tx_ring); +__netif_tx_unlock (nq); +return nxmit; }
@@ -4897,7 +4896,7 @@ static void igb_free_all_tx_resources(struct igb_adapter *adapter)* igb_clean_tx_ring - Free Tx Buffers * @tx_ring: ring to be cleaned **/ -static void igb_clean_tx_ring (struct igb_ring *tx_ring) +void igb_clean_tx_ring (struct igb_ring *tx_ring) {u16 i = tx_ring->next_to_clean;struct igb_tx_buffer *tx_buffer = &tx_ring->tx_buffer_info[i];
@@ -5016,7 +5015,7 @@ static void igb_free_all_rx_resources(struct igb_adapter *adapter)* igb_clean_rx_ring - Free Rx Buffers per Queue * @rx_ring: ring to free buffers from **/ -static void igb_clean_rx_ring (struct igb_ring *rx_ring) +void igb_clean_rx_ring (struct igb_ring *rx_ring) {u16 i = rx_ring->next_to_clean;
@@ -6631,7 +6630,7 @@ static int igb_change_mtu(struct net_device *netdev, int new_mtu)struct igb_adapter *adapter =netdev_priv (netdev);int max_frame = new_mtu +IGB_ETH_PKT_HDR_PAD ; -if (adapter->xdp_prog) { +if (igb_xdp_is_enabled (adapter)) {int i;for (i =0 ; i < adapter->num_rx_queues; i++) {
@@ -8600,9 +8599,9 @@ static struct sk_buff *igb_build_skb(struct igb_ring *rx_ring,return skb; } -static struct sk_buff *igb_run_xdp (struct igb_adapter *adapter, -struct igb_ring *rx_ring, -struct xdp_buff *xdp) +struct sk_buff *igb_run_xdp (struct igb_adapter *adapter, +struct igb_ring *rx_ring, +struct xdp_buff *xdp) {int err, result =IGB_XDP_PASS ;struct bpf_prog *xdp_prog;
@@ -8798,9 +8797,9 @@ static bool igb_cleanup_headers(struct igb_ring *rx_ring,* order to populate the hash, checksum, VLAN, timestamp, protocol, and * other fields within the skb. **/ -static void igb_process_skb_fields (struct igb_ring *rx_ring, -union e1000_adv_rx_desc *rx_desc, -struct sk_buff *skb) +void igb_process_skb_fields (struct igb_ring *rx_ring, +union e1000_adv_rx_desc *rx_desc, +struct sk_buff *skb) {struct net_device *dev = rx_ring->netdev;
Signature · 1 line
2.34.1
PATCH v3 2/4 igb: Introduce XSK data structures and helpers
In reply to Sriram YagnaramanAdd the following ring flags
- IGB_RING_FLAG_TX_DISABLED (when xsk pool is being setup)
- IGB_RING_FLAG_AF_XDP_ZC (xsk pool is active)
Add a xdp_buff array for use with XSK receive batch API, and a pointer to xsk_pool in igb_adapter.
Add enable/disable functions for TX and RX rings
Add enable/disable functions for XSK pool
Add xsk wakeup function
None of the above functionality will be active until NETDEV_XDP_ACT_XSK_ZEROCOPY is advertised in netdev->xdp_features.
--- drivers/net/ethernet/intel/igb/Makefile | 2 +- drivers/net/ethernet/intel/igb/igb.h | 14 +- drivers/net/ethernet/intel/igb/igb_main.c | 9 + drivers/net/ethernet/intel/igb/igb_xsk.c | 210 ++++++++++++++++++++++ 4 files changed, 233 insertions(+), 2 deletions(-) create mode 100644 drivers/net/ethernet/intel/igb/igb_xsk.c
drivers/net/ethernet/intel/igb/Makefile +1 -1
@@ -8,4 +8,4 @@ obj-$(CONFIG_IGB) += igb.o igb-objs := igb_main.o igb_ethtool.o e1000_82575.o \ e1000_mac.o e1000_nvm.o e1000_phy.o e1000_mbx.o \ - e1000_i210.o igb_ptp.o igb_hwmon.o + e1000_i210.o igb_ptp.o igb_hwmon.o igb_xsk.o
drivers/net/ethernet/intel/igb/igb.h +13 -1
@@ -20,6 +20,7 @@#include <linux/mdio.h> #include <net/xdp.h> +#include <net/xdp_sock_drv.h> struct igb_adapter ;
@@ -320,6 +321,7 @@ struct igb_ring {union {/* array of buffer info structs */ struct igb_tx_buffer *tx_buffer_info;struct igb_rx_buffer *rx_buffer_info; +struct xdp_buff **rx_buffer_info_zc; };void *desc;/* descriptor ring memory */ unsigned long flags;/* ring specific flags */
@@ -357,6 +359,7 @@ struct igb_ring { }; };struct xdp_rxq_info xdp_rxq; +struct xsk_buff_pool *xsk_pool; }____cacheline_internodealigned_in_smp ;struct igb_q_vector {
@@ -384,7 +387,9 @@ enum e1000_ring_flags_t {IGB_RING_FLAG_RX_SCTP_CSUM ,IGB_RING_FLAG_RX_LB_VLAN_BSWAP ,IGB_RING_FLAG_TX_CTX_IDX , - IGB_RING_FLAG_TX_DETECT_HANG +IGB_RING_FLAG_TX_DETECT_HANG , +IGB_RING_FLAG_TX_DISABLED , + IGB_RING_FLAG_AF_XDP_ZC };#define ring_uses_large_buffer (ring) \
@@ -822,4 +827,11 @@ int igb_add_mac_steering_filter(struct igb_adapter *adapter,int igb_del_mac_steering_filter (struct igb_adapter *adapter,const u8 *addr,u8 queue,u8 flags); +struct xsk_buff_pool *igb_xsk_pool (struct igb_adapter *adapter, +struct igb_ring *ring); +int igb_xsk_pool_setup (struct igb_adapter *adapter, +struct xsk_buff_pool *pool, +u16 qid); +int igb_xsk_wakeup (struct net_device *dev,u32 qid,u32 flags); +#endif /* _IGB_H_ */
drivers/net/ethernet/intel/igb/igb_main.c +9 -0
@@ -2929,9 +2929,14 @@ static int igb_xdp_setup(struct net_device *dev, struct netdev_bpf *bpf)static int igb_xdp (struct net_device *dev,struct netdev_bpf *xdp) { +struct igb_adapter *adapter =netdev_priv (dev); +switch (xdp->command) {case XDP_SETUP_PROG :return igb_xdp_setup (dev, xdp); +case XDP_SETUP_XSK_POOL : +return igb_xsk_pool_setup (adapter, xdp->xsk.pool, + xdp->xsk.queue_id);default :return -EINVAL ; }
@@ -3058,6 +3063,7 @@ static const struct net_device_ops igb_netdev_ops = { .ndo_setup_tc = igb_setup_tc, .ndo_bpf = igb_xdp, .ndo_xdp_xmit = igb_xdp_xmit, + .ndo_xsk_wakeup = igb_xsk_wakeup, };/**
@@ -4376,6 +4382,8 @@ void igb_configure_tx_ring(struct igb_adapter *adapter,u64 tdba = ring->dma;int reg_idx = ring->reg_idx; + ring->xsk_pool =igb_xsk_pool (adapter, ring); +wr32 (E1000_TDLEN (reg_idx), ring->count *sizeof (union e1000_adv_tx_desc )); wr32(E1000_TDBAL(reg_idx),
@@ -4771,6 +4779,7 @@ void igb_configure_rx_ring(struct igb_adapter *adapter,xdp_rxq_info_unreg_mem_model (&ring->xdp_rxq);WARN_ON (xdp_rxq_info_reg_mem_model (&ring->xdp_rxq,MEM_TYPE_PAGE_SHARED ,NULL )); + ring->xsk_pool =igb_xsk_pool (adapter, ring);/* disable the queue */ wr32 (E1000_RXDCTL (reg_idx),0 );
drivers/net/ethernet/intel/igb/igb_xsk.c new file +210 -0
210 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v3 3/4 igb: add AF_XDP zero-copy Rx support
In reply to Sriram YagnaramanAdd support for AF_XDP zero-copy receive path.
When AF_XDP zero-copy is enabled, the rx buffers are allocated from the xsk buff pool using igb_alloc_rx_buffers_zc.
Use xsk_pool_get_rx_frame_size to set SRRCTL rx buf size when zero-copy is enabled.
--- drivers/net/ethernet/intel/igb/igb.h | 4 + drivers/net/ethernet/intel/igb/igb_main.c | 87 +++++-- drivers/net/ethernet/intel/igb/igb_xsk.c | 262 +++++++++++++++++++++- 3 files changed, 332 insertions(+), 21 deletions(-)
drivers/net/ethernet/intel/igb/igb.h +4 -0
@@ -87,6 +87,7 @@ struct igb_adapter;#define IGB_XDP_CONSUMED BIT(0)#define IGB_XDP_TX BIT(1)#define IGB_XDP_REDIR BIT(2) +#define IGB_XDP_EXIT BIT(3)struct vf_data_storage {unsigned char vf_mac_addresses[ETH_ALEN ];
@@ -832,6 +833,9 @@ struct xsk_buff_pool *igb_xsk_pool(struct igb_adapter *adapter,int igb_xsk_pool_setup (struct igb_adapter *adapter,struct xsk_buff_pool *pool,u16 qid); +bool igb_alloc_rx_buffers_zc (struct igb_ring *rx_ring,u16 count); +void igb_clean_rx_ring_zc (struct igb_ring *rx_ring); +int igb_clean_rx_irq_zc (struct igb_q_vector *q_vector,const int budget);int igb_xsk_wakeup (struct net_device *dev,u32 qid,u32 flags);#endif /* _IGB_H_ */
drivers/net/ethernet/intel/igb/igb_main.c +67 -20
184 lines not on this page · raw message
drivers/net/ethernet/intel/igb/igb_xsk.c +261 -1
274 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH iwl-next v3 3/4] igb: add AF_XDP zero-copy Rx support
Quoted 9 lines · Sriram Yagnaraman
Add support for
AF_XDPzero-copy receive path.When
AF_XDPzero-copy is enabled, the rx buffers are allocated from the xsk buff pool usingigb_alloc_rx_buffers_zc.Use
xsk_pool_get_rx_frame_sizeto set SRRCTL rx buf size when zero-copy is enabled.Signed-off-by Sriram Yagnaraman <[email protected]>
...
Quoted 22 lines
drivers/net/ethernet/intel/igb/igb_main.c +4
-2@@ -502,12 +502,14 @@ static void igb_dump(struct igb_adapter *adapter)for (i =0 ; i < rx_ring->count; i++) {const char *next_desc; -struct igb_rx_buffer *buffer_info; - buffer_info = &rx_ring->rx_buffer_info[i]; +struct igb_rx_buffer *buffer_info =NULL ; rx_desc =IGB_RX_DESC (rx_ring, i); u0 = (struct my_u0 *)rx_desc; staterr =le32_to_cpu (rx_desc->wb.upper.status_error); +if (!rx_ring->xsk_pool) + buffer_info = &rx_ring->rx_buffer_info[i]; +if (i == rx_ring->next_to_use) next_desc =" NTU" ;else if (i == rx_ring->next_to_clean)
drivers/net/ethernet/intel/igb/igb_main.c static void igb_dump(struct igb_adapter *adapter) · line 532
Quoted 1 line
drivers/net/ethernet/intel/igb/igb_main.c +0
-0@@ -530,7 +532,7 @@ static void igb_dump(struct igb_adapter *adapter) (u64)buffer_info->dma,
Hi Sriram,
Here buffer_info is dereferenced...
drivers/net/ethernet/intel/igb/igb_main.c static void igb_dump(struct igb_adapter *adapter) · line 535
Quoted 4 lines
drivers/net/ethernet/intel/igb/igb_main.c +1
-1next_desc); - if (netif_msg_pktdata(adapter) && + if (netif_msg_pktdata(adapter) && buffer_info &&
And here buffer_info is checked against NULL.
This combination doesn't seem quite right.
Quoted 3 lines
drivers/net/ethernet/intel/igb/igb_main.c +0
-0buffer_info->dma && buffer_info->page) { print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
RE: [PATCH iwl-next v3 3/4] igb: add AF_XDP zero-copy Rx support
Quoted 66 lines
-----Original Message-----
From: Simon Horman <[email protected]>
Sent: Saturday, 15 July 2023 11:23
To: Sriram Yagnaraman <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Jesse Brandeburg <[email protected]>; Tony Nguyen <[email protected]>; David S . Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Alexei Starovoitov <[email protected]>; Daniel Borkmann <[email protected]>; Jesper Dangaard Brouer <[email protected]>; John Fastabend <[email protected]>; Björn Töpel <[email protected]>; Magnus Karlsson <[email protected]>; Maciej Fijalkowski <[email protected]>; Jonathan Lemon <[email protected]>
Subject: Re: [PATCH iwl-next v3 3/4] igb: addAF_XDPzero-copy Rx supportQuoted 9 lines · Sriram Yagnaraman
Add support for
AF_XDPzero-copy receive path.When
AF_XDPzero-copy is enabled, the rx buffers are allocated from the xsk buff pool usingigb_alloc_rx_buffers_zc.Use
xsk_pool_get_rx_frame_sizeto set SRRCTL rx buf size when zero-copy is enabled.Signed-off-by Sriram Yagnaraman <[email protected]>...
Quoted 22 lines
drivers/net/ethernet/intel/igb/igb_main.c +4
-2@@ -502,12 +502,14 @@ static void igb_dump(struct igb_adapter *adapter)for (i =0 ; i < rx_ring->count; i++) {const char *next_desc; -struct igb_rx_buffer *buffer_info; - buffer_info = &rx_ring->rx_buffer_info[i]; +struct igb_rx_buffer *buffer_info =NULL ; rx_desc =IGB_RX_DESC (rx_ring, i); u0 = (struct my_u0 *)rx_desc; staterr =le32_to_cpu (rx_desc- wb.upper.status_error); +if (!rx_ring->xsk_pool) + buffer_info = &rx_ring->rx_buffer_info[i]; +if (i == rx_ring->next_to_use)drivers/net/ethernet/intel/igb/igb_main.c
Quoted 2 lines
drivers/net/ethernet/intel/igb/igb_main.c +0
-0next_desc =" NTU" ; else if (i == rx_ring->next_to_clean) @@ -530,7 +532,7@@ static
Quoted 2 lines
void
igb_dump(struct igb_adapter *adapter)
(u64)buffer_info->dma,Hi Sriram,
Here
buffer_infois dereferenced...Quoted 2 lines
next_desc);
Quoted 7 lines
drivers/net/ethernet/intel/igb/igb_main.c
Quoted 2 lines
drivers/net/ethernet/intel/igb/igb_main.c +1
-1- if (netif_msg_pktdata(adapter) && + if (netif_msg_pktdata(adapter) && buffer_info&&
And here
buffer_infois checked against NULL.This combination doesn't seem quite right.
ACK, I will fix this. I am unable to test this path though.
Quoted 4 lines
Quoted 4 lines
drivers/net/ethernet/intel/igb/igb_main.c +0
-0buffer_info->dma && buffer_info->page) { print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
PATCH v3 4/4 igb: add AF_XDP zero-copy Tx support
In reply to Sriram YagnaramanAdd support for AF_XDP zero-copy transmit path.
A new TX buffer type IGB_TYPE_XSK is introduced to indicate that the Tx frame was allocated from the xsk buff pool, so igb_clean_tx_ring and igb_clean_tx_irq can clean the buffers correctly based on type.
igb_xmit_zc performs the actual packet transmit when AF_XDP zero-copy is enabled. We share the TX ring between slow path, XDP and AF_XDP zero-copy, so we use the netdev queue lock to ensure mutual exclusion.
--- drivers/net/ethernet/intel/igb/igb.h | 2 + drivers/net/ethernet/intel/igb/igb_main.c | 56 +++++++++++++++++++---- drivers/net/ethernet/intel/igb/igb_xsk.c | 52 +++++++++++++++++++++ 3 files changed, 101 insertions(+), 9 deletions(-)
drivers/net/ethernet/intel/igb/igb.h +2 -0
@@ -257,6 +257,7 @@ enum igb_tx_flags {enum igb_tx_buf_type {IGB_TYPE_SKB =0 ,IGB_TYPE_XDP , +IGB_TYPE_XSK };/* wrapper around a pointer to a socket buffer,
@@ -836,6 +837,7 @@ int igb_xsk_pool_setup(struct igb_adapter *adapter,bool igb_alloc_rx_buffers_zc (struct igb_ring *rx_ring,u16 count);void igb_clean_rx_ring_zc (struct igb_ring *rx_ring);int igb_clean_rx_irq_zc (struct igb_q_vector *q_vector,const int budget); +bool igb_xmit_zc (struct igb_ring *tx_ring);int igb_xsk_wakeup (struct net_device *dev,u32 qid,u32 flags);#endif /* _IGB_H_ */
drivers/net/ethernet/intel/igb/igb_main.c +47 -9
128 lines not on this page · raw message
drivers/net/ethernet/intel/igb/igb_xsk.c +52 -0
58 lines not on this page · raw message
Signature · 1 line
2.34.1