xsk: Intel driver improvements
Subsystems (5)
Maciej Fijalkowski
maintainerv5 cover xsk: Intel driver improvements
Hi,
Unfortunately, similar scalability issues that were addressed for XDP processing in ice, exist for XDP in the zero-copy driver used by AF_XDP. Let's resolve them in mostly the same way as we did in [0] and utilize the Tx batching API from XSK buffer pool.
Move the array of Tx descriptors that is used with batching approach to the XSK buffer pool. This means that future users of this API will not have carry the array on their own side, they can simple refer to pool's tx_desc array.
We also improve the Rx side where we extend ice_alloc_rx_buf_zc() to handle the ring wrap and bump Rx tail more frequently. By doing so, Rx side is adjusted to Tx and it was needed for l2fwd scenario.
Here are the improvements of performance numbers that this set brings measured with xdpsock app in busy poll mode for 1 and 2 core modes. Both Tx and Rx rings were sized to 1k length and busy poll budget was 256.
----------------------------------------------------------------
| txonly: | l2fwd | rxdrop
----------------------------------------------------------------
1C | 149% | 14% | 3%
----------------------------------------------------------------
2C | 134% | 20% | 5%
----------------------------------------------------------------
Next step will be to introduce batching onto Rx side.
v5:
* collect acks
* fix typos
* correct comments showing cache line boundaries in ice_tx_ring struct v4 - address Alexandr's review:
* new patch (2) for making sure ring size is pow(2) when attaching xsk socket
* don't open code ALIGN_DOWN (patch 3)
* resign from storing tx_thresh in ice_tx_ring (patch 4)
* scope variables in a better way for Tx batching (patch 7) v3:
* drop likely() that was wrapping napi_complete_done (patch 1)
* introduce configurable Tx threshold (patch 2)
* handle ring wrap on Rx side when allocating buffers (patch 3)
* respect NAPI budget when cleaning Tx descriptors in ZC (patch 6) v2:
* introduce new patch that resets @next_dd and @next_rs fields
* use batching API for AF_XDP Tx on ice side
Thanks,
Maciej
[0]: https://lore.kernel.org/bpf/[email protected]/
Maciej Fijalkowski (7):
ice: remove likely for napi_complete_done
ice: xsk: force rings to be sized to power of 2
ice: xsk: handle SW XDP ring wrap and bump tail more often
ice: make Tx threshold dependent on ring length
ice: xsk: avoid potential dead AF_XDP Tx processing
ice: xsk: improve AF_XDP ZC Tx and use batching API
ice: xsk: borrow xdp_tx_active logic from i40e
Magnus Karlsson (1):
i40e: xsk: move tmp desc array from driver to pool
drivers/net/ethernet/intel/i40e/i40e_txrx.c | 11 - drivers/net/ethernet/intel/i40e/i40e_txrx.h | 1 - drivers/net/ethernet/intel/i40e/i40e_xsk.c | 4 +- drivers/net/ethernet/intel/ice/ice_ethtool.c | 2 + drivers/net/ethernet/intel/ice/ice_main.c | 4 +- drivers/net/ethernet/intel/ice/ice_txrx.c | 6 +- drivers/net/ethernet/intel/ice/ice_txrx.h | 10 +- drivers/net/ethernet/intel/ice/ice_txrx_lib.c | 15 +- drivers/net/ethernet/intel/ice/ice_xsk.c | 374 ++++++++++++------ drivers/net/ethernet/intel/ice/ice_xsk.h | 27 +- include/net/xdp_sock_drv.h | 5 +- include/net/xsk_buff_pool.h | 1 + net/xdp/xsk.c | 13 +- net/xdp/xsk_buff_pool.c | 7 + net/xdp/xsk_queue.h | 12 +- 15 files changed, 330 insertions(+), 162 deletions(-)
Signature · 1 line
2.33.1
Maciej Fijalkowski
maintainerPATCH v5 1/8 ice: remove likely for napi_complete_done
Remove the likely before napi_complete_done as this is the unlikely case when busy-poll is used. Removing this has a positive performance impact for busy-poll and no negative impact to the regular case.
--- drivers/net/ethernet/intel/ice/ice_txrx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_txrx.c +1 -1
@@ -1513,7 +1513,7 @@ int ice_napi_poll(struct napi_struct *napi, int budget)/* Exit the polling mode, but don't re-enable interrupts if stack might * poll us due to busy-polling */ -if (likely (napi_complete_done (napi, work_done))) { +if (napi_complete_done (napi, work_done)) {ice_net_dim (q_vector);ice_enable_interrupt (q_vector); }else {
Signature · 1 line
2.33.1
Maciej Fijalkowski
maintainerPATCH v5 2/8 ice: xsk: force rings to be sized to power of 2
In reply to Maciej FijalkowskiWith the upcoming introduction of batching to XSK data path, performance wise it will be the best to have the ring descriptor count to be aligned to power of 2.
Check if ring sizes that user is going to attach the XSK socket fulfill the condition above. For Tx side, although check is being done against the Tx queue and in the end the socket will be attached to the XDP queue, it is fine since XDP queues get the ring->count setting from Tx queues.
--- drivers/net/ethernet/intel/ice/ice_xsk.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/net/ethernet/intel/ice/ice_xsk.c +8 -0
@@ -327,6 +327,13 @@ int ice_xsk_pool_setup(struct ice_vsi *vsi, struct xsk_buff_pool *pool, u16 qid)bool if_running, pool_present = !!pool;int ret =0 , pool_failure =0 ; +if (!is_power_of_2 (vsi->rx_rings[qid]->count) || + !is_power_of_2 (vsi->tx_rings[qid]->count)) { +netdev_err (vsi->netdev,"Please align ring sizes to power of 2\n" ); + pool_failure = -EINVAL ; + goto failure; + } + if_running =netif_running (vsi->netdev) &&ice_is_xdp_ena_vsi (vsi);if (if_running) {
@@ -349,6 +356,7 @@ int ice_xsk_pool_setup(struct ice_vsi *vsi, struct xsk_buff_pool *pool, u16 qid)netdev_err (vsi->netdev,"ice_qp_ena error = %d\n" , ret); } +failure:if (pool_failure) {netdev_err (vsi->netdev,"Could not %sable buffer pool, error = %d\n" , pool_present ?"en" :"dis" , pool_failure);
Signature · 1 line
2.33.1
Maciej Fijalkowski
maintainerPATCH v5 3/8 ice: xsk: handle SW XDP ring wrap and bump tail more often
In reply to Maciej FijalkowskiCurrently, if ice_clean_rx_irq_zc() processed the whole ring and next_to_use != 0, then ice_alloc_rx_buf_zc() would not refill the whole ring even if the XSK buffer pool would have enough free entries (either from fill ring or the internal recycle mechanism) - it is because ring wrap is not handled.
Improve the logic in ice_alloc_rx_buf_zc() to address the problem above. Do not clamp the count of buffers that is passed to xsk_buff_alloc_batch() in case when next_to_use + buffer count >= rx_ring->count, but rather split it and have two calls to the mentioned function - one for the part up until the wrap and one for the part after the wrap.
--- drivers/net/ethernet/intel/ice/ice_txrx.h | 2 + drivers/net/ethernet/intel/ice/ice_xsk.c | 99 ++++++++++++++++++----- 2 files changed, 81 insertions(+), 20 deletions(-)
drivers/net/ethernet/intel/ice/ice_txrx.h +2 -0
@@ -111,6 +111,8 @@ static inline int ice_skb_pad(void) (u16)((((R )->next_to_clean > (R )->next_to_use) ?0 : (R )->count) + \ (R)->next_to_clean - (R)->next_to_use - 1) +#define ICE_RING_QUARTER (R ) ((R)->count >> 2) +#define ICE_TX_FLAGS_TSO BIT(0)#define ICE_TX_FLAGS_HW_VLAN BIT(1)#define ICE_TX_FLAGS_SW_VLAN BIT(2)
drivers/net/ethernet/intel/ice/ice_xsk.c +79 -20
125 lines not on this page · raw message
Signature · 1 line
2.33.1
Maciej Fijalkowski
maintainerPATCH v5 4/8 ice: make Tx threshold dependent on ring length
In reply to Maciej FijalkowskiXDP_TX workloads use a concept of Tx threshold that indicates the interval of setting RS bit on descriptors which in turn tells the HW to generate an interrupt to signal the completion of Tx on HW side. It is currently based on a constant value of 32 which might not work out well for various sizes of ring combined with for example batch size that can be set via SO_BUSY_POLL_BUDGET.
Internal tests based on AF_XDP showed that most convenient setup of mentioned threshold is when it is equal to quarter of a ring length.
Make use of recently introduced ICE_RING_QUARTER macro and use this value as a substitute for ICE_TX_THRESH.
Align also ethtool -G callback so that next_dd/next_rs fields are up to date in terms of the ring size.
--- drivers/net/ethernet/intel/ice/ice_ethtool.c | 2 ++ drivers/net/ethernet/intel/ice/ice_main.c | 4 ++-- drivers/net/ethernet/intel/ice/ice_txrx.h | 1 - drivers/net/ethernet/intel/ice/ice_txrx_lib.c | 14 ++++++++------ 4 files changed, 12 insertions(+), 9 deletions(-)
drivers/net/ethernet/intel/ice/ice_ethtool.c +2 -0
@@ -2803,6 +2803,8 @@ ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring,/* clone ring and setup updated count */ xdp_rings[i] = *vsi->xdp_rings[i]; xdp_rings[i].count = new_tx_cnt; + xdp_rings[i].next_dd =ICE_RING_QUARTER (&xdp_rings[i]) -1 ; + xdp_rings[i].next_rs =ICE_RING_QUARTER (&xdp_rings[i]) -1 ; xdp_rings[i].desc =NULL ; xdp_rings[i].tx_buf =NULL ; err =ice_setup_tx_ring (&xdp_rings[i]);
drivers/net/ethernet/intel/ice/ice_main.c +2 -2
@@ -2495,10 +2495,10 @@ static int ice_xdp_alloc_setup_rings(struct ice_vsi *vsi) xdp_ring->reg_idx = vsi->txq_map[xdp_q_idx]; xdp_ring->vsi = vsi; xdp_ring->netdev =NULL ; - xdp_ring->next_dd =ICE_TX_THRESH -1 ; - xdp_ring->next_rs =ICE_TX_THRESH -1 ; xdp_ring->dev = dev; xdp_ring->count = vsi->num_tx_desc; + xdp_ring->next_dd =ICE_RING_QUARTER (xdp_ring) -1 ; + xdp_ring->next_rs =ICE_RING_QUARTER (xdp_ring) -1 ;WRITE_ONCE (vsi->xdp_rings[i], xdp_ring);if (ice_setup_tx_ring (xdp_ring)) goto free_xdp_rings;
drivers/net/ethernet/intel/ice/ice_txrx.h +0 -1
@@ -13,7 +13,6 @@#define ICE_MAX_CHAINED_RX_BUFS 5#define ICE_MAX_BUF_TXD 8#define ICE_MIN_TX_LEN 17 -#define ICE_TX_THRESH 32/* The size limit for a transmit buffer in a descriptor is (16K - 1). * In order to align with the read requests we will align the value to
drivers/net/ethernet/intel/ice/ice_txrx_lib.c +8 -6
@@ -222,6 +222,7 @@ ice_receive_skb(struct ice_rx_ring *rx_ring, struct sk_buff *skb, u16 vlan_tag)static void ice_clean_xdp_irq (struct ice_tx_ring *xdp_ring) {unsigned int total_bytes =0 , total_pkts =0 ; +u16 tx_thresh =ICE_RING_QUARTER (xdp_ring);u16 ntc = xdp_ring->next_to_clean;struct ice_tx_desc *next_dd_desc;u16 next_dd = xdp_ring->next_dd;
@@ -233,7 +234,7 @@ static void ice_clean_xdp_irq(struct ice_tx_ring *xdp_ring) cpu_to_le64(ICE_TX_DESC_DTYPE_DESC_DONE))) return; -for (i =0 ; i <ICE_TX_THRESH ; i++) { +for (i =0 ; i < tx_thresh; i++) { tx_buf = &xdp_ring->tx_buf[ntc]; total_bytes += tx_buf->bytecount;
@@ -254,9 +255,9 @@ static void ice_clean_xdp_irq(struct ice_tx_ring *xdp_ring) } next_dd_desc->cmd_type_offset_bsz =0 ; - xdp_ring->next_dd = xdp_ring->next_dd +ICE_TX_THRESH ; + xdp_ring->next_dd = xdp_ring->next_dd + tx_thresh;if (xdp_ring->next_dd > xdp_ring->count) - xdp_ring->next_dd =ICE_TX_THRESH -1 ; + xdp_ring->next_dd = tx_thresh -1 ; xdp_ring->next_to_clean = ntc;ice_update_tx_ring_stats (xdp_ring, total_pkts, total_bytes); }
@@ -269,12 +270,13 @@ static void ice_clean_xdp_irq(struct ice_tx_ring *xdp_ring)*/ int ice_xmit_xdp_ring (void *data,u16 size,struct ice_tx_ring *xdp_ring) { +u16 tx_thresh =ICE_RING_QUARTER (xdp_ring);u16 i = xdp_ring->next_to_use;struct ice_tx_desc *tx_desc;struct ice_tx_buf *tx_buf;dma_addr_t dma; -if (ICE_DESC_UNUSED (xdp_ring) <ICE_TX_THRESH ) +if (ICE_DESC_UNUSED (xdp_ring) < tx_thresh)ice_clean_xdp_irq (xdp_ring);if (!unlikely (ICE_DESC_UNUSED (xdp_ring))) {
@@ -306,7 +308,7 @@ int ice_xmit_xdp_ring(void *data, u16 size, struct ice_tx_ring *xdp_ring) tx_desc =ICE_TX_DESC (xdp_ring, xdp_ring->next_rs); tx_desc->cmd_type_offset_bsz |=cpu_to_le64 (ICE_TX_DESC_CMD_RS <<ICE_TXD_QW1_CMD_S ); - xdp_ring->next_rs =ICE_TX_THRESH -1 ; + xdp_ring->next_rs = tx_thresh -1 ; } xdp_ring->next_to_use = i;
@@ -314,7 +316,7 @@ int ice_xmit_xdp_ring(void *data, u16 size, struct ice_tx_ring *xdp_ring) tx_desc =ICE_TX_DESC (xdp_ring, xdp_ring->next_rs); tx_desc->cmd_type_offset_bsz |=cpu_to_le64 (ICE_TX_DESC_CMD_RS <<ICE_TXD_QW1_CMD_S ); - xdp_ring->next_rs +=ICE_TX_THRESH ; + xdp_ring->next_rs += tx_thresh; }return ICE_XDP_TX ;
Signature · 1 line
2.33.1
Maciej Fijalkowski
maintainerPATCH v5 5/8 i40e: xsk: move tmp desc array from driver to pool
In reply to Maciej FijalkowskiFrom: Magnus Karlsson <[email protected]>
Move desc_array from the driver to the pool. The reason behind this is that we can then reuse this array as a temporary storage for descriptors in all zero-copy drivers that use the batched interface. This will make it easier to add batching to more drivers.
i40e is the only driver that has a batched Tx zero-copy implementation, so no need to touch any other driver.
--- drivers/net/ethernet/intel/i40e/i40e_txrx.c | 11 ----------- drivers/net/ethernet/intel/i40e/i40e_txrx.h | 1 - drivers/net/ethernet/intel/i40e/i40e_xsk.c | 4 ++-- include/net/xdp_sock_drv.h | 5 ++--- include/net/xsk_buff_pool.h | 1 + net/xdp/xsk.c | 13 ++++++------- net/xdp/xsk_buff_pool.c | 7 +++++++ net/xdp/xsk_queue.h | 12 ++++++------ 8 files changed, 24 insertions(+), 30 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_txrx.c +0 -11
@@ -830,8 +830,6 @@ void i40e_free_tx_resources(struct i40e_ring *tx_ring)i40e_clean_tx_ring (tx_ring);kfree (tx_ring->tx_bi); tx_ring->tx_bi =NULL ; -kfree (tx_ring->xsk_descs); - tx_ring->xsk_descs =NULL ;if (tx_ring->desc) { dma_free_coherent(tx_ring->dev, tx_ring->size,
@@ -1433,13 +1431,6 @@ int i40e_setup_tx_descriptors(struct i40e_ring *tx_ring)if (!tx_ring->tx_bi) goto err; -if (ring_is_xdp (tx_ring)) { - tx_ring->xsk_descs =kcalloc (I40E_MAX_NUM_DESCRIPTORS ,sizeof (*tx_ring->xsk_descs), -GFP_KERNEL ); -if (!tx_ring->xsk_descs) - goto err; - } -u64_stats_init (&tx_ring->syncp);/* round up to nearest 4K */
@@ -1463,8 +1454,6 @@ int i40e_setup_tx_descriptors(struct i40e_ring *tx_ring)return 0 ; err: -kfree (tx_ring->xsk_descs); - tx_ring->xsk_descs =NULL ;kfree (tx_ring->tx_bi); tx_ring->tx_bi =NULL ;return -ENOMEM ;
drivers/net/ethernet/intel/i40e/i40e_txrx.h +0 -1
@@ -390,7 +390,6 @@ struct i40e_ring {u16 rx_offset;struct xdp_rxq_info xdp_rxq;struct xsk_buff_pool *xsk_pool; -struct xdp_desc *xsk_descs;/* For storing descriptors in the AF_XDP ZC path */ }____cacheline_internodealigned_in_smp ;static inline bool ring_uses_build_skb (struct i40e_ring *ring)
drivers/net/ethernet/intel/i40e/i40e_xsk.c +2 -2
@@ -467,11 +467,11 @@ static void i40e_set_rs_bit(struct i40e_ring *xdp_ring)**/ static bool i40e_xmit_zc (struct i40e_ring *xdp_ring,unsigned int budget) { -struct xdp_desc *descs = xdp_ring->xsk_descs; +struct xdp_desc *descs = xdp_ring->xsk_pool->tx_descs;u32 nb_pkts, nb_processed =0 ;unsigned int total_bytes =0 ; - nb_pkts =xsk_tx_peek_release_desc_batch (xdp_ring->xsk_pool, descs, budget); + nb_pkts =xsk_tx_peek_release_desc_batch (xdp_ring->xsk_pool, budget);if (!nb_pkts)return true;
include/net/xdp_sock_drv.h +2 -3
@@ -13,7 +13,7 @@void xsk_tx_completed (struct xsk_buff_pool *pool,u32 nb_entries);bool xsk_tx_peek_desc (struct xsk_buff_pool *pool,struct xdp_desc *desc); -u32 xsk_tx_peek_release_desc_batch (struct xsk_buff_pool *pool,struct xdp_desc *desc,u32 max); +u32 xsk_tx_peek_release_desc_batch (struct xsk_buff_pool *pool,u32 max);void xsk_tx_release (struct xsk_buff_pool *pool);struct xsk_buff_pool *xsk_get_pool_from_qid (struct net_device *dev,u16 queue_id);
@@ -142,8 +142,7 @@ static inline bool xsk_tx_peek_desc(struct xsk_buff_pool *pool,return false; } -static inline u32 xsk_tx_peek_release_desc_batch (struct xsk_buff_pool *pool,struct xdp_desc *desc, -u32 max) +static inline u32 xsk_tx_peek_release_desc_batch (struct xsk_buff_pool *pool,u32 max) {return 0 ; }
include/net/xsk_buff_pool.h +1 -0
@@ -60,6 +60,7 @@ struct xsk_buff_pool {*/ dma_addr_t *dma_pages;struct xdp_buff_xsk *heads; +struct xdp_desc *tx_descs;u64 chunk_mask;u64 addrs_cnt;u32 free_list_cnt;
net/xdp/xsk.c +6 -7
@@ -343,9 +343,9 @@ bool xsk_tx_peek_desc(struct xsk_buff_pool *pool, struct xdp_desc *desc) }EXPORT_SYMBOL (xsk_tx_peek_desc); -static u32 xsk_tx_peek_release_fallback (struct xsk_buff_pool *pool,struct xdp_desc *descs, -u32 max_entries) +static u32 xsk_tx_peek_release_fallback (struct xsk_buff_pool *pool,u32 max_entries) { +struct xdp_desc *descs = pool->tx_descs;u32 nb_pkts =0 ;while (nb_pkts < max_entries &&xsk_tx_peek_desc (pool, &descs[nb_pkts]))
@@ -355,8 +355,7 @@ static u32 xsk_tx_peek_release_fallback(struct xsk_buff_pool *pool, struct xdp_dreturn nb_pkts; } -u32 xsk_tx_peek_release_desc_batch (struct xsk_buff_pool *pool,struct xdp_desc *descs, -u32 max_entries) +u32 xsk_tx_peek_release_desc_batch (struct xsk_buff_pool *pool,u32 max_entries) {struct xdp_sock *xs;u32 nb_pkts;
@@ -365,7 +364,7 @@ u32 xsk_tx_peek_release_desc_batch(struct xsk_buff_pool *pool, struct xdp_desc *if (!list_is_singular (&pool->xsk_tx_list)) {/* Fallback to the non-batched version */ rcu_read_unlock (); -return xsk_tx_peek_release_fallback (pool, descs, max_entries); +return xsk_tx_peek_release_fallback (pool, max_entries); } xs = list_first_or_null_rcu(&pool->xsk_tx_list, struct xdp_sock, tx_list);
@@ -374,7 +373,7 @@ u32 xsk_tx_peek_release_desc_batch(struct xsk_buff_pool *pool, struct xdp_desc * goto out; } - nb_pkts =xskq_cons_peek_desc_batch (xs->tx, descs, pool, max_entries); + nb_pkts =xskq_cons_peek_desc_batch (xs->tx, pool, max_entries);if (!nb_pkts) { xs->tx->queue_empty_descs++; goto out;
@@ -386,7 +385,7 @@ u32 xsk_tx_peek_release_desc_batch(struct xsk_buff_pool *pool, struct xdp_desc ** packets. This avoids having to implement any buffering in * the Tx path. */ - nb_pkts =xskq_prod_reserve_addr_batch (pool->cq, descs, nb_pkts); + nb_pkts =xskq_prod_reserve_addr_batch (pool->cq, pool->tx_descs, nb_pkts);if (!nb_pkts) goto out;
net/xdp/xsk_buff_pool.c +7 -0
@@ -37,6 +37,7 @@ void xp_destroy(struct xsk_buff_pool *pool)if (!pool)return ; +kvfree (pool->tx_descs);kvfree (pool->heads);kvfree (pool); }
@@ -58,6 +59,12 @@ struct xsk_buff_pool *xp_create_and_assign_umem(struct xdp_sock *xs,if (!pool->heads) goto out; +if (xs->tx) { + pool->tx_descs =kcalloc (xs->tx->nentries,sizeof (*pool->tx_descs),GFP_KERNEL ); +if (!pool->tx_descs) + goto out; + } + pool->chunk_mask = ~((u64 )umem->chunk_size -1 ); pool->addrs_cnt = umem->size; pool->heads_cnt = umem->chunks;
net/xdp/xsk_queue.h +6 -6
@@ -205,11 +205,11 @@ static inline bool xskq_cons_read_desc(struct xsk_queue *q,return false; } -static inline u32 xskq_cons_read_desc_batch (struct xsk_queue *q, -struct xdp_desc *descs, -struct xsk_buff_pool *pool,u32 max) +static inline u32 xskq_cons_read_desc_batch (struct xsk_queue *q,struct xsk_buff_pool *pool, +u32 max) {u32 cached_cons = q->cached_cons, nb_entries =0 ; +struct xdp_desc *descs = pool->tx_descs;while (cached_cons != q->cached_prod && nb_entries < max) {struct xdp_rxtx_ring *ring = (struct xdp_rxtx_ring *)q->ring;
@@ -282,12 +282,12 @@ static inline bool xskq_cons_peek_desc(struct xsk_queue *q,return xskq_cons_read_desc (q, desc, pool); } -static inline u32 xskq_cons_peek_desc_batch (struct xsk_queue *q,struct xdp_desc *descs, -struct xsk_buff_pool *pool,u32 max) +static inline u32 xskq_cons_peek_desc_batch (struct xsk_queue *q,struct xsk_buff_pool *pool, +u32 max) {u32 entries =xskq_cons_nb_entries (q, max); -return xskq_cons_read_desc_batch (q, descs, pool, entries); +return xskq_cons_read_desc_batch (q, pool, entries); }/* To improve performance in the xskq_cons_release functions, only update local state here.
Signature · 1 line
2.33.1
Maciej Fijalkowski
maintainerPATCH v5 6/8 ice: xsk: avoid potential dead AF_XDP Tx processing
In reply to Maciej FijalkowskiCommit 9610bd988df9 ("ice: optimize XDP_TX workloads") introduced @next_dd and @next_rs to ice_tx_ring struct. Currently, their state is not restored in ice_clean_tx_ring(), which was not causing any troubles as the XDP rings are gone after we're done with XDP prog on interface.
For upcoming usage of mentioned fields in AF_XDP, this might expose us to a potential dead Tx side. Scenario would look like following (based on xdpsock):
- two xdpsock instances are spawned in Tx mode
- one of them is killed
- XDP prog is kept on interface due to the other xdpsock still running
* this means that XDP rings stayed in place
- xdpsock is launched again on same queue id that was terminated on
- @next_dd and @next_rs setting is bogus, therefore transmit side is broken
To protect us from the above, restore the initial @next_rs and @next_dd values when cleaning the Tx ring.
--- drivers/net/ethernet/intel/ice/ice_txrx.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/intel/ice/ice_txrx.c +2 -0
@@ -173,6 +173,8 @@ void ice_clean_tx_ring(struct ice_tx_ring *tx_ring) tx_ring->next_to_use =0 ; tx_ring->next_to_clean =0 ; + tx_ring->next_dd =ICE_RING_QUARTER (tx_ring) -1 ; + tx_ring->next_rs =ICE_RING_QUARTER (tx_ring) -1 ;if (!tx_ring->netdev)return ;
Signature · 1 line
2.33.1
Maciej Fijalkowski
maintainerPATCH v5 7/8 ice: xsk: improve AF_XDP ZC Tx and use batching API
In reply to Maciej FijalkowskiApply the logic that was done for regular XDP from commit 9610bd988df9 ("ice: optimize XDP_TX workloads") to the ZC side of the driver. On top of that, introduce batching to Tx that is inspired by i40e's implementation with adjustments to the cleaning logic - take into the account NAPI budget in ice_clean_xdp_irq_zc().
Separating the stats structs onto separate cache lines seemed to improve the performance.
--- drivers/net/ethernet/intel/ice/ice_txrx.c | 2 +- drivers/net/ethernet/intel/ice/ice_txrx.h | 6 +- drivers/net/ethernet/intel/ice/ice_xsk.c | 256 ++++++++++++++-------- drivers/net/ethernet/intel/ice/ice_xsk.h | 27 ++- 4 files changed, 190 insertions(+), 101 deletions(-)
drivers/net/ethernet/intel/ice/ice_txrx.c +1 -1
@@ -1462,7 +1462,7 @@ int ice_napi_poll(struct napi_struct *napi, int budget)bool wd;if (tx_ring->xsk_pool) - wd =ice_clean_tx_irq_zc (tx_ring, budget); + wd =ice_xmit_zc (tx_ring,ICE_DESC_UNUSED (tx_ring), budget);else if (ice_ring_is_xdp (tx_ring)) wd = true;else
drivers/net/ethernet/intel/ice/ice_txrx.h +3 -3
@@ -322,17 +322,17 @@ struct ice_tx_ring {u16 count;/* Number of descriptors */ u16 q_index;/* Queue number of ring */ /* stats structs */ -struct ice_q_stats stats; -struct u64_stats_sync syncp;struct ice_txq_stats tx_stats; -/* CL3 - 3rd cacheline starts here */ +struct ice_q_stats stats; +struct u64_stats_sync syncp;struct rcu_head rcu;/* to avoid race on free */ DECLARE_BITMAP (xps_state,ICE_TX_NBITS );/* XPS Config State */ struct ice_channel *ch;struct ice_ptp_tx *tx_tstamps;spinlock_t tx_lock;u32 txq_teid;/* Added Tx queue TEID */ +/* CL4 - 4th cacheline starts here */ #define ICE_TX_FLAGS_RING_XDP BIT(0)u8 flags;u8 dcb_tc;/* Traffic class of ring */
drivers/net/ethernet/intel/ice/ice_xsk.c +167 -89
301 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_xsk.h +19 -8
@@ -6,19 +6,37 @@#include "ice_txrx.h" #include "ice.h" +#define PKTS_PER_BATCH 8 + +#ifdef __clang__ +#define loop_unrolled_for _Pragma("clang loop unroll_count(8)") for +#elif __GNUC__ >=4 +#define loop_unrolled_for _Pragma("GCC unroll 8") for +#else +#define loop_unrolled_for for +#endif +struct ice_vsi ;#ifdef CONFIG_XDP_SOCKETS int ice_xsk_pool_setup (struct ice_vsi *vsi,struct xsk_buff_pool *pool,u16 qid);int ice_clean_rx_irq_zc (struct ice_rx_ring *rx_ring,int budget); -bool ice_clean_tx_irq_zc (struct ice_tx_ring *xdp_ring,int budget);int ice_xsk_wakeup (struct net_device *netdev,u32 queue_id,u32 flags);bool ice_alloc_rx_bufs_zc (struct ice_rx_ring *rx_ring,u16 count);bool ice_xsk_any_rx_ring_ena (struct ice_vsi *vsi);void ice_xsk_clean_rx_ring (struct ice_rx_ring *rx_ring);void ice_xsk_clean_xdp_ring (struct ice_tx_ring *xdp_ring); +bool ice_xmit_zc (struct ice_tx_ring *xdp_ring,u32 budget,int napi_budget);#else +static inline bool +ice_xmit_zc (struct ice_tx_ring __always_unused *xdp_ring, +u32 __always_unused budget, +int __always_unused napi_budget) +{ +return false; +} + static inline int ice_xsk_pool_setup(struct ice_vsi __always_unused *vsi, struct xsk_buff_pool __always_unused *pool,
@@ -34,13 +52,6 @@ ice_clean_rx_irq_zc(struct ice_rx_ring __always_unused *rx_ring,return 0 ; } -static inline bool -ice_clean_tx_irq_zc (struct ice_tx_ring __always_unused *xdp_ring, -int __always_unused budget) -{ -return false; -} -static inline bool ice_alloc_rx_bufs_zc (struct ice_rx_ring __always_unused *rx_ring,u16 __always_unused count)
Signature · 1 line
2.33.1
Maciej Fijalkowski
maintainerPATCH v5 8/8 ice: xsk: borrow xdp_tx_active logic from i40e
In reply to Maciej FijalkowskiOne of the things that commit 5574ff7b7b3d ("i40e: optimize AF_XDP Tx completion path") introduced was the @xdp_tx_active field. Its usage from i40e can be adjusted to ice driver and give us positive performance results.
If the descriptor that @next_dd points to has been sent by HW (its DD bit is set), then we are sure that at least quarter of the ring is ready to be cleaned. If @xdp_tx_active is 0 which means that related xdp_ring is not used for XDP_{TX, REDIRECT} workloads, then we know how many XSK entries should placed to completion queue, IOW walking through the ring can be skipped.
--- drivers/net/ethernet/intel/ice/ice_txrx.h | 1 + drivers/net/ethernet/intel/ice/ice_txrx_lib.c | 1 + drivers/net/ethernet/intel/ice/ice_xsk.c | 15 ++++++++++++--- 3 files changed, 14 insertions(+), 3 deletions(-)
drivers/net/ethernet/intel/ice/ice_txrx.h +1 -0
@@ -333,6 +333,7 @@ struct ice_tx_ring {spinlock_t tx_lock;u32 txq_teid;/* Added Tx queue TEID */ /* CL4 - 4th cacheline starts here */ +u16 xdp_tx_active;#define ICE_TX_FLAGS_RING_XDP BIT(0)u8 flags;u8 dcb_tc;/* Traffic class of ring */
drivers/net/ethernet/intel/ice/ice_txrx_lib.c +1 -0
@@ -302,6 +302,7 @@ int ice_xmit_xdp_ring(void *data, u16 size, struct ice_tx_ring *xdp_ring) tx_desc->cmd_type_offset_bsz =ice_build_ctob (ICE_TX_DESC_CMD_EOP ,0 , size,0 ); + xdp_ring->xdp_tx_active++; i++;if (i == xdp_ring->count) { i =0 ;
drivers/net/ethernet/intel/ice/ice_xsk.c +12 -3
@@ -687,6 +687,7 @@ static void ice_clean_xdp_tx_buf(struct ice_tx_ring *xdp_ring, struct ice_tx_buf *tx_buf) { xdp_return_frame((struct xdp_frame *)tx_buf->raw_buf); + xdp_ring->xdp_tx_active--;dma_unmap_single (xdp_ring->dev,dma_unmap_addr (tx_buf, dma),dma_unmap_len (tx_buf, len),DMA_TO_DEVICE );dma_unmap_len_set (tx_buf, len,0 );
@@ -703,9 +704,8 @@ static u16 ice_clean_xdp_irq_zc(struct ice_tx_ring *xdp_ring, int napi_budget) {u16 tx_thresh =ICE_RING_QUARTER (xdp_ring);int budget = napi_budget / tx_thresh; -u16 ntc = xdp_ring->next_to_clean;u16 next_dd = xdp_ring->next_dd; -u16 cleared_dds =0 ; +u16 ntc, cleared_dds =0 ; do { struct ice_tx_desc *next_dd_desc;
@@ -721,6 +721,12 @@ static u16 ice_clean_xdp_irq_zc(struct ice_tx_ring *xdp_ring, int napi_budget) cleared_dds++; xsk_frames =0 ; +if (likely (!xdp_ring->xdp_tx_active)) { + xsk_frames = tx_thresh; + goto skip; + } + + ntc = xdp_ring->next_to_clean;for (i =0 ; i < tx_thresh; i++) { tx_buf = &xdp_ring->tx_buf[ntc];
@@ -736,6 +742,10 @@ static u16 ice_clean_xdp_irq_zc(struct ice_tx_ring *xdp_ring, int napi_budget)if (ntc >= xdp_ring->count) ntc =0 ; } +skip: + xdp_ring->next_to_clean += tx_thresh; +if (xdp_ring->next_to_clean >= desc_cnt) + xdp_ring->next_to_clean -= desc_cnt;if (xsk_frames)xsk_tx_completed (xdp_ring->xsk_pool, xsk_frames); next_dd_desc->cmd_type_offset_bsz =0 ;
@@ -744,7 +754,6 @@ static u16 ice_clean_xdp_irq_zc(struct ice_tx_ring *xdp_ring, int napi_budget) next_dd = tx_thresh -1 ; }while (budget--); - xdp_ring->next_to_clean = ntc; xdp_ring->next_dd = next_dd;return cleared_dds * tx_thresh;
Signature · 1 line
2.33.1
Re: [PATCH bpf-next v5 8/8] ice: xsk: borrow xdp_tx_active logic from i40e
Quoted 6 lines · Maciej Fijalkowski
One of the things that commit
5574ff7b7b3d("i40e: optimizeAF_XDPTx completion path") introduced was the @xdp_tx_active field. Its usage from i40e can be adjusted to ice driver and give us positive performance results.
Quoted 6 lines
If the descriptor that @next_dd points to has been sent by HW (its DD bit is set), then we are sure that at least quarter of the ring is ready to be cleaned. If @xdp_tx_active is 0 which means that related
xdp_ringis not used for XDP_{TX, REDIRECT} workloads, then we know how many XSK entries should placed to completion queue, IOW walking through the ring can be skipped.
Thanks Maciej.
Quoted 90 lines
Reviewed-by Alexander Lobakin <[email protected]>Signed-off-by Maciej Fijalkowski <[email protected]>--- drivers/net/ethernet/intel/ice/ice_txrx.h | 1 + drivers/net/ethernet/intel/ice/ice_txrx_lib.c | 1 + drivers/net/ethernet/intel/ice/ice_xsk.c | 15 ++++++++++++--- 3 files changed, 14 insertions(+), 3 deletions(-)drivers/net/ethernet/intel/ice/ice_txrx.h +1
-0@@ -333,6 +333,7 @@ struct ice_tx_ring {spinlock_t tx_lock;u32 txq_teid;/* Added Tx queue TEID */ /* CL4 - 4th cacheline starts here */ +u16 xdp_tx_active;#define ICE_TX_FLAGS_RING_XDP BIT(0)u8 flags;u8 dcb_tc;/* Traffic class of ring */ drivers/net/ethernet/intel/ice/ice_txrx_lib.c +1
-0@@ -302,6 +302,7 @@ int ice_xmit_xdp_ring(void *data, u16 size, struct ice_tx_ring *xdp_ring) tx_desc->cmd_type_offset_bsz =ice_build_ctob (ICE_TX_DESC_CMD_EOP ,0 , size,0 ); + xdp_ring->xdp_tx_active++; i++;if (i == xdp_ring->count) { i =0 ;drivers/net/ethernet/intel/ice/ice_xsk.c +12
-4@@ -687,6 +687,7 @@ static void ice_clean_xdp_tx_buf(struct ice_tx_ring *xdp_ring, struct ice_tx_buf *tx_buf) { xdp_return_frame((struct xdp_frame *)tx_buf->raw_buf); + xdp_ring->xdp_tx_active--;dma_unmap_single (xdp_ring->dev,dma_unmap_addr (tx_buf, dma),dma_unmap_len (tx_buf, len),DMA_TO_DEVICE );dma_unmap_len_set (tx_buf, len,0 );@@ -703,9 +704,8 @@ static u16 ice_clean_xdp_irq_zc(struct ice_tx_ring *xdp_ring, int napi_budget) {u16 tx_thresh =ICE_RING_QUARTER (xdp_ring);int budget = napi_budget / tx_thresh; -u16 ntc = xdp_ring->next_to_clean;u16 next_dd = xdp_ring->next_dd; -u16 cleared_dds =0 ; +u16 ntc, cleared_dds =0 ; do { struct ice_tx_desc *next_dd_desc;@@ -721,6 +721,12 @@ static u16 ice_clean_xdp_irq_zc(struct ice_tx_ring *xdp_ring, int napi_budget) cleared_dds++; xsk_frames =0 ; +if (likely (!xdp_ring->xdp_tx_active)) { + xsk_frames = tx_thresh; + goto skip; + } + + ntc = xdp_ring->next_to_clean;for (i =0 ; i < tx_thresh; i++) { tx_buf = &xdp_ring->tx_buf[ntc];@@ -736,6 +742,10 @@ static u16 ice_clean_xdp_irq_zc(struct ice_tx_ring *xdp_ring, int napi_budget)if (ntc >= xdp_ring->count) ntc =0 ; } +skip: + xdp_ring->next_to_clean += tx_thresh; +if (xdp_ring->next_to_clean >= desc_cnt) + xdp_ring->next_to_clean -= desc_cnt;if (xsk_frames)xsk_tx_completed (xdp_ring->xsk_pool, xsk_frames); next_dd_desc->cmd_type_offset_bsz =0 ;@@ -744,7 +754,6 @@ static u16 ice_clean_xdp_irq_zc(struct ice_tx_ring *xdp_ring, int napi_budget) next_dd = tx_thresh -1 ; }while (budget--); - xdp_ring->next_to_clean = ntc; xdp_ring->next_dd = next_dd;return cleared_dds * tx_thresh; --2.33.1
This series was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Hello:
This series was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Quoted 8 lines · On Tue, 25 Jan 2022 17:04:38 +0100 you wrote:
Hi,
Unfortunately, similar scalability issues that were addressed for XDP processing in ice, exist for XDP in the zero-copy driver used by
AF_XDP. Let's resolve them in mostly the same way as we did in [0] and utilize the Tx batching API from XSK buffer pool.[...]
Here is the summary with links:
- [bpf-next,v5,1/8] ice: remove likely for napi_complete_done
https://git.kernel.org/bpf/bpf-next/c/a4e186693cbe - [bpf-next,v5,2/8] ice: xsk: force rings to be sized to power of 2 https://git.kernel.org/bpf/bpf-next/c/296f13ff3854 - [bpf-next,v5,3/8] ice: xsk: handle SW XDP ring wrap and bump tail more often https://git.kernel.org/bpf/bpf-next/c/3876ff525de7 - [bpf-next,v5,4/8] ice: make Tx threshold dependent on ring length https://git.kernel.org/bpf/bpf-next/c/3dd411efe1ed - [bpf-next,v5,5/8] i40e: xsk: move tmp desc array from driver to pool https://git.kernel.org/bpf/bpf-next/c/d1bc532e99be - [bpf-next,v5,6/8] ice: xsk: avoid potential dead AF_XDP Tx processing https://git.kernel.org/bpf/bpf-next/c/86e3f78c8d32 - [bpf-next,v5,7/8] ice: xsk: improve AF_XDP ZC Tx and use batching API https://git.kernel.org/bpf/bpf-next/c/126cdfe1007a - [bpf-next,v5,8/8] ice: xsk: borrow xdp_tx_active logic from i40e https://git.kernel.org/bpf/bpf-next/c/59e92bfe4df7
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html