ice: post-mbuf fixes
Subsystems (4)
cover ice: post-mbuf fixes
The set grew from the poor performance of %BPF_F_TEST_XDP_LIVE_FRAMES when the ice-backed device is a sender. Initially there were around 3.3 Mpps / thread, while I have 5.5 on skb-based pktgen...
After fixing 0005 (0004 is a prereq for it) first (strange thing nobody noticed that earlier), I started catching random OOMs. This is how 0002 (and partially 0001) appeared.
0003 is a suggestion from Maciej to not waste time on refactoring dead lines. 0006 is a "cherry on top" to get away with the final 6.7 Mpps. 4.5 of 6 are fixes, but only the first three are tagged, since it then starts being tricky. I may backport them manually later on.
TL;DR for the series is that shortcuts are good, but only as long as they don't make the driver miss important things. %XDP_TX is purely driver-local, however .ndo_xdp_xmit() is not, and sometimes assumptions can be unsafe there.
With that series and also one core code patch[0], "live frames" and xdp-trafficgen are now safe'n'fast on ice (probably more to come).
[0] https://lore.kernel.org/all/[email protected]
---
Goes to directly to bpf-next as touches the recently added/changed code.
Alexander Lobakin (6):
ice: fix ice_tx_ring::xdp_tx_active underflow
ice: fix XDP Tx ring overrun
ice: remove two impossible branches on XDP Tx cleaning
ice: robustify cleaning/completing XDP Tx buffers
ice: fix freeing XDP frames backed by Page Pool
ice: micro-optimize .ndo_xdp_xmit() path
drivers/net/ethernet/intel/ice/ice_txrx.c | 67 +++++++++----- drivers/net/ethernet/intel/ice/ice_txrx.h | 37 ++++++-- drivers/net/ethernet/intel/ice/ice_txrx_lib.c | 88 ++++++++++++------- drivers/net/ethernet/intel/ice/ice_txrx_lib.h | 4 +- drivers/net/ethernet/intel/ice/ice_xsk.c | 12 +-- 5 files changed, 136 insertions(+), 72 deletions(-)
Signature · 1 line
2.39.1
PATCH 1/6 ice: fix ice_tx_ring::xdp_tx_active underflow
xdp_tx_active is used to indicate whether an XDP ring has any %XDP_TX frames queued to shortcut processing Tx cleaning for XSk-enabled queues. When !XSk, it simply indicates whether the ring has any queued frames in general.
It gets increased on each frame placed onto the ring and counts the whole frame, not each frag. However, currently it gets decremented in ice_clean_xdp_tx_buf(), which is called per each buffer, i.e. per each frag. Thus, on completing multi-frag frames, an underflow happens. Move the decrement to the outer function and do it once per frame, not buf. Also, do that on the stack and update the ring counter after the loop is done to save several cycles.
XSk rings are fine since there are no frags at the moment.
--- drivers/net/ethernet/intel/ice/ice_txrx_lib.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/ice/ice_txrx_lib.c +3 -2
@@ -231,7 +231,6 @@ ice_clean_xdp_tx_buf(struct ice_tx_ring *xdp_ring, struct ice_tx_buf *tx_buf)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 ); - xdp_ring->xdp_tx_active--;page_frag_free (tx_buf->raw_buf); tx_buf->raw_buf =NULL ; }
@@ -246,8 +245,8 @@ static u32 ice_clean_xdp_irq(struct ice_tx_ring *xdp_ring)u32 ntc = xdp_ring->next_to_clean;struct ice_tx_desc *tx_desc;u32 cnt = xdp_ring->count; +u32 frags, xdp_tx =0 ;u32 ready_frames =0 ; -u32 frags;u32 idx;u32 ret;
@@ -274,6 +273,7 @@ static u32 ice_clean_xdp_irq(struct ice_tx_ring *xdp_ring) total_pkts++;/* count head + frags */ ready_frames -= frags +1 ; + xdp_tx++;if (xdp_ring->xsk_pool)xsk_buff_free (tx_buf->xdp);
@@ -295,6 +295,7 @@ static u32 ice_clean_xdp_irq(struct ice_tx_ring *xdp_ring) tx_desc->cmd_type_offset_bsz =0 ; xdp_ring->next_to_clean = ntc; + xdp_ring->xdp_tx_active -= xdp_tx;ice_update_tx_ring_stats (xdp_ring, total_pkts, total_bytes);return ret;
Signature · 1 line
2.39.1
PATCH 2/6 ice: fix XDP Tx ring overrun
In reply to Alexander LobakinSometimes, under heavy XDP Tx traffic, e.g. when using XDP traffic generator (%BPF_F_TEST_XDP_LIVE_FRAMES), the machine can catch OOM due to the driver not freeing all of the pages passed to it by .ndo_xdp_xmit().
Turned out that during the development of the tagged commit, the check, which ensures that we have a free descriptor to queue a frame, moved into the branch happening only when a buffer has frags. Otherwise, we only run a cleaning cycle, but don't check anything.
ATST, there can be situations when the driver gets new frames to send, but there are no buffers that can be cleaned/completed and the ring has no free slots. It's very rare, but still possible (> 6.5 Mpps per ring). The driver then fills the next buffer/descriptor, effectively overwriting the data, which still needs to be freed.
Restore the check after the cleaning routine to make sure there is a slot to queue a new frame. When there are frags, there still will be a separate check that we can place all of them, but if the ring is full, there's no point in wasting any more time.
(minor: make !ready_frames unlikely since it happens ~1-2 times per
billion of frames)
--- drivers/net/ethernet/intel/ice/ice_txrx_lib.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/net/ethernet/intel/ice/ice_txrx_lib.c +12 -7
@@ -260,7 +260,7 @@ static u32 ice_clean_xdp_irq(struct ice_tx_ring *xdp_ring) ready_frames = idx + cnt - ntc +1 ; } -if (!ready_frames) +if (unlikely (!ready_frames))return 0 ; ret = ready_frames;
@@ -322,17 +322,17 @@ int __ice_xmit_xdp_ring(struct xdp_buff *xdp, struct ice_tx_ring *xdp_ring)u32 frag =0 ; free_space =ICE_DESC_UNUSED (xdp_ring); - -if (ICE_DESC_UNUSED (xdp_ring) <ICE_RING_QUARTER (xdp_ring)) +if (free_space <ICE_RING_QUARTER (xdp_ring)) free_space +=ice_clean_xdp_irq (xdp_ring); +if (unlikely (!free_space)) + goto busy; +if (unlikely (xdp_buff_has_frags (xdp))) { sinfo =xdp_get_shared_info_from_buff (xdp); nr_frags = sinfo->nr_frags; -if (free_space < nr_frags +1 ) { - xdp_ring->ring_stats->tx_stats.tx_busy++; -return ICE_XDP_CONSUMED ; - } +if (free_space < nr_frags +1 ) + goto busy; } tx_desc =ICE_TX_DESC (xdp_ring, ntu);
@@ -396,6 +396,11 @@ int __ice_xmit_xdp_ring(struct xdp_buff *xdp, struct ice_tx_ring *xdp_ring) ntu--; }return ICE_XDP_CONSUMED ; + +busy: + xdp_ring->ring_stats->tx_stats.tx_busy++; + +return ICE_XDP_CONSUMED ; }/**
Signature · 1 line
2.39.1
PATCH 3/6 ice: remove two impossible branches on XDP Tx cleaning
In reply to Alexander LobakinThe tagged commit started sending %XDP_TX frames from XSk Rx ring directly without converting it to an &xdp_frame. However, when XSk is enabled on a queue pair, it has its separate Tx cleaning functions, so neither ice_clean_xdp_irq() nor ice_unmap_and_free_tx_buf() ever happens there.
Remove impossible branches in order to reduce the diffstat of the upcoming change.
--- drivers/net/ethernet/intel/ice/ice_txrx.c | 5 +---- drivers/net/ethernet/intel/ice/ice_txrx_lib.c | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-)
drivers/net/ethernet/intel/ice/ice_txrx.c +1 -4
@@ -116,10 +116,7 @@ ice_unmap_and_free_tx_buf(struct ice_tx_ring *ring, struct ice_tx_buf *tx_buf)if (tx_buf->tx_flags &ICE_TX_FLAGS_DUMMY_PKT ) {devm_kfree (ring->dev, tx_buf->raw_buf); }else if (ice_ring_is_xdp (ring)) { -if (ring->xsk_pool) -xsk_buff_free (tx_buf->xdp); -else -page_frag_free (tx_buf->raw_buf); +page_frag_free (tx_buf->raw_buf); }else {dev_kfree_skb_any (tx_buf->skb); }
drivers/net/ethernet/intel/ice/ice_txrx_lib.c +1 -4
@@ -275,10 +275,7 @@ static u32 ice_clean_xdp_irq(struct ice_tx_ring *xdp_ring) ready_frames -= frags +1 ; xdp_tx++; -if (xdp_ring->xsk_pool) -xsk_buff_free (tx_buf->xdp); -else -ice_clean_xdp_tx_buf (xdp_ring, tx_buf); +ice_clean_xdp_tx_buf (xdp_ring, tx_buf); ntc++;if (ntc == cnt) ntc =0 ;
Signature · 1 line
2.39.1
PATCH 4/6 ice: robustify cleaning/completing XDP Tx buffers
In reply to Alexander LobakinWhen queueing frames from a Page Pool for redirecting to a device backed by the ice driver, perf top shows heavy load on page_alloc() and page_frag_free(), despite that on a properly working system it must be fully or at least almost zero-alloc. The problem is in fact a bit deeper and raises from how ice cleans up completed Tx buffers.
The story so far: when cleaning/freeing the resources related to a particular completed Tx frame (skbs, DMA mappings etc.), ice uses some heuristics only without setting any type explicitly (except for dummy Flow Director packets, which are marked via ice_tx_buf::tx_flags). This kinda works, but only up to some point. For example, currently ice assumes that each frame coming to __ice_xmit_xdp_ring(), is backed by either plain order-0 page or plain page frag, while it may also be backed by Page Pool or any other possible memory models introduced in future. This means any &xdp_frame must be freed properly via xdp_return_frame() family with no assumptions.
In order to do that, the whole heuristics must be replaced with setting the Tx buffer/frame type explicitly, just how it's always been done via an enum. Let us reuse 16 bits from ::tx_flags -- 1 bit-and instr won't hurt much -- especially given that sometimes there was a check for %ICE_TX_FLAGS_DUMMY_PKT, which is now turned from a flag to an enum member. The rest of the changes is straightforward and most of it is just a conversion to rely now on the type set in &ice_tx_buf rather than to some secondary properties.
For now, no functional changes intended, the change only prepares the ground for starting freeing XDP frames properly next step. And it must be done atomically/synchronously to not break stuff.
--- drivers/net/ethernet/intel/ice/ice_txrx.c | 38 +++++++++---------- drivers/net/ethernet/intel/ice/ice_txrx.h | 34 ++++++++++++----- drivers/net/ethernet/intel/ice/ice_txrx_lib.c | 15 ++++++-- drivers/net/ethernet/intel/ice/ice_xsk.c | 12 +++--- 4 files changed, 63 insertions(+), 36 deletions(-)
drivers/net/ethernet/intel/ice/ice_txrx.c +19 -19
@@ -85,7 +85,7 @@ ice_prgm_fdir_fltr(struct ice_vsi *vsi, struct ice_fltr_desc *fdir_desc, td_cmd =ICE_TXD_LAST_DESC_CMD |ICE_TX_DESC_CMD_DUMMY |ICE_TX_DESC_CMD_RE ; - tx_buf->tx_flags =ICE_TX_FLAGS_DUMMY_PKT ; + tx_buf->type =ICE_TX_BUF_DUMMY ; tx_buf->raw_buf = raw_packet; tx_desc->cmd_type_offset_bsz =
@@ -112,28 +112,26 @@ ice_prgm_fdir_fltr(struct ice_vsi *vsi, struct ice_fltr_desc *fdir_desc,static void ice_unmap_and_free_tx_buf (struct ice_tx_ring *ring,struct ice_tx_buf *tx_buf) { -if (tx_buf->skb) { -if (tx_buf->tx_flags &ICE_TX_FLAGS_DUMMY_PKT ) { -devm_kfree (ring->dev, tx_buf->raw_buf); - }else if (ice_ring_is_xdp (ring)) { -page_frag_free (tx_buf->raw_buf); - }else { -dev_kfree_skb_any (tx_buf->skb); - } -if (dma_unmap_len (tx_buf, len)) -dma_unmap_single (ring->dev, -dma_unmap_addr (tx_buf, dma), -dma_unmap_len (tx_buf, len), -DMA_TO_DEVICE ); - }else if (dma_unmap_len (tx_buf, len)) { +if (dma_unmap_len (tx_buf, len))dma_unmap_page (ring->dev,dma_unmap_addr (tx_buf, dma),dma_unmap_len (tx_buf, len),DMA_TO_DEVICE ); + +switch (tx_buf->type) { +case ICE_TX_BUF_DUMMY : +devm_kfree (ring->dev, tx_buf->raw_buf); +break ; +case ICE_TX_BUF_SKB : +dev_kfree_skb_any (tx_buf->skb); +break ; +case ICE_TX_BUF_XDP_TX : +page_frag_free (tx_buf->raw_buf); +break ; } tx_buf->next_to_watch =NULL ; - tx_buf->skb =NULL ; + tx_buf->type =ICE_TX_BUF_EMPTY ;dma_unmap_len_set (tx_buf, len,0 );/* tx_buf must be completely set up in the transmit path */ }
@@ -266,7 +264,7 @@ static bool ice_clean_tx_irq(struct ice_tx_ring *tx_ring, int napi_budget) DMA_TO_DEVICE);/* clear tx_buf data */ - tx_buf->skb =NULL ; + tx_buf->type =ICE_TX_BUF_EMPTY ;dma_unmap_len_set (tx_buf, len,0 );/* unmap remaining buffers */
@@ -1709,6 +1707,7 @@ ice_tx_map(struct ice_tx_ring *tx_ring, struct ice_tx_buf *first, DMA_TO_DEVICE); tx_buf = &tx_ring->tx_buf[i]; + tx_buf->type =ICE_TX_BUF_FRAG ; }/* record SW timestamp if HW timestamp is not available */
@@ -2352,6 +2351,7 @@ ice_xmit_frame_ring(struct sk_buff *skb, struct ice_tx_ring *tx_ring)/* record the location of the first descriptor for this packet */ first = &tx_ring->tx_buf[tx_ring->next_to_use]; first->skb = skb; + first->type =ICE_TX_BUF_SKB ; first->bytecount = max_t(unsigned int, skb->len, ETH_ZLEN); first->gso_segs =1 ; first->tx_flags =0 ;
@@ -2524,11 +2524,11 @@ void ice_clean_ctrl_tx_irq(struct ice_tx_ring *tx_ring)dma_unmap_addr (tx_buf, dma),dma_unmap_len (tx_buf, len), DMA_TO_DEVICE); -if (tx_buf->tx_flags &ICE_TX_FLAGS_DUMMY_PKT ) +if (tx_buf->type ==ICE_TX_BUF_DUMMY )devm_kfree (tx_ring->dev, tx_buf->raw_buf);/* clear next_to_watch to prevent false hangs */ - tx_buf->raw_buf =NULL ; + tx_buf->type =ICE_TX_BUF_EMPTY ; tx_buf->tx_flags =0 ; tx_buf->next_to_watch =NULL ;dma_unmap_len_set (tx_buf, len,0 );
drivers/net/ethernet/intel/ice/ice_txrx.h +25 -9
@@ -121,10 +121,7 @@ static inline int ice_skb_pad(void)#define ICE_TX_FLAGS_TSO BIT(0)#define ICE_TX_FLAGS_HW_VLAN BIT(1)#define ICE_TX_FLAGS_SW_VLAN BIT(2) -/* ICE_TX_FLAGS_DUMMY_PKT is used to mark dummy packets that should be -* freed instead of returned like skb packets. -*/ -#define ICE_TX_FLAGS_DUMMY_PKT BIT(3) +/* Free, was ICE_TX_FLAGS_DUMMY_PKT */ #define ICE_TX_FLAGS_TSYN BIT(4)#define ICE_TX_FLAGS_IPV4 BIT(5)#define ICE_TX_FLAGS_IPV6 BIT(6)
@@ -149,22 +146,41 @@ static inline int ice_skb_pad(void)#define ICE_TXD_LAST_DESC_CMD (ICE_TX_DESC_CMD_EOP | ICE_TX_DESC_CMD_RS) +/** +* enum ice_tx_buf_type - type of &ice_tx_buf to act on Tx completion +* @ICE_TX_BUF_EMPTY: unused OR XSk frame, no action required +* @ICE_TX_BUF_DUMMY: dummy Flow Director packet, unmap and kfree() +* @ICE_TX_BUF_FRAG: mapped skb OR &xdp_buff frag, only unmap DMA +* @ICE_TX_BUF_SKB: &sk_buff, unmap and consume_skb(), update stats +* @ICE_TX_BUF_XDP_TX: &xdp_buff, unmap and page_frag_free(), stats +* @ICE_TX_BUF_XSK_TX: &xdp_buff on XSk queue, xsk_buff_free(), stats +*/ +enum ice_tx_buf_type { +ICE_TX_BUF_EMPTY =0U , +ICE_TX_BUF_DUMMY , +ICE_TX_BUF_FRAG , +ICE_TX_BUF_SKB , +ICE_TX_BUF_XDP_TX , +ICE_TX_BUF_XSK_TX , +}; +struct ice_tx_buf {union {struct ice_tx_desc *next_to_watch;u32 rs_idx; };union { -struct sk_buff *skb; -void *raw_buf;/* used for XDP */ -struct xdp_buff *xdp;/* used for XDP_TX ZC */ +void *raw_buf;/* used for XDP_TX and FDir rules */ +struct sk_buff *skb;/* used for .ndo_start_xmit() */ +struct xdp_buff *xdp;/* used for XDP_TX ZC */ };unsigned int bytecount;union {unsigned int gso_segs; -unsigned int nr_frags;/* used for mbuf XDP */ +unsigned int nr_frags;/* used for mbuf XDP */ }; -u32 tx_flags; +u32 type:16 ;/* &ice_tx_buf_type */ +u32 tx_flags:16 ;DEFINE_DMA_UNMAP_LEN (len);DEFINE_DMA_UNMAP_ADDR (dma); };
drivers/net/ethernet/intel/ice/ice_txrx_lib.c +12 -3
@@ -231,8 +231,14 @@ ice_clean_xdp_tx_buf(struct ice_tx_ring *xdp_ring, struct ice_tx_buf *tx_buf)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 ); -page_frag_free (tx_buf->raw_buf); - tx_buf->raw_buf =NULL ; + +switch (tx_buf->type) { +case ICE_TX_BUF_XDP_TX : +page_frag_free (tx_buf->raw_buf); +break ; + } + + tx_buf->type =ICE_TX_BUF_EMPTY ; }/**
@@ -266,6 +272,7 @@ static u32 ice_clean_xdp_irq(struct ice_tx_ring *xdp_ring)while (ready_frames) {struct ice_tx_buf *tx_buf = &xdp_ring->tx_buf[ntc]; +struct ice_tx_buf *head = tx_buf;/* bytecount holds size of head + frags */ total_bytes += tx_buf->bytecount;
@@ -275,7 +282,6 @@ static u32 ice_clean_xdp_irq(struct ice_tx_ring *xdp_ring) ready_frames -= frags +1 ; xdp_tx++; -ice_clean_xdp_tx_buf (xdp_ring, tx_buf); ntc++;if (ntc == cnt) ntc =0 ;
@@ -288,6 +294,8 @@ static u32 ice_clean_xdp_irq(struct ice_tx_ring *xdp_ring)if (ntc == cnt) ntc =0 ; } + +ice_clean_xdp_tx_buf (xdp_ring, head); } tx_desc->cmd_type_offset_bsz =0 ;
@@ -349,6 +357,7 @@ int __ice_xmit_xdp_ring(struct xdp_buff *xdp, struct ice_tx_ring *xdp_ring) tx_desc->buf_addr =cpu_to_le64 (dma); tx_desc->cmd_type_offset_bsz =ice_build_ctob (0 ,0 , size,0 ); + tx_buf->type =ICE_TX_BUF_XDP_TX ; tx_buf->raw_buf = data; ntu++;
drivers/net/ethernet/intel/ice/ice_xsk.c +7 -5
@@ -631,7 +631,8 @@ static void ice_clean_xdp_irq_zc(struct ice_tx_ring *xdp_ring)for (i =0 ; i < xsk_frames; i++) { tx_buf = &xdp_ring->tx_buf[ntc]; -if (tx_buf->xdp) { +if (tx_buf->type ==ICE_TX_BUF_XSK_TX ) { + tx_buf->type =ICE_TX_BUF_EMPTY ;xsk_buff_free (tx_buf->xdp); xdp_ring->xdp_tx_active--; }else {
@@ -685,6 +686,7 @@ static int ice_xmit_xdp_tx_zc(struct xdp_buff *xdp, tx_buf = &xdp_ring->tx_buf[ntu]; tx_buf->xdp = xdp; + tx_buf->type =ICE_TX_BUF_XSK_TX ; tx_desc =ICE_TX_DESC (xdp_ring, ntu); tx_desc->buf_addr =cpu_to_le64 (dma); tx_desc->cmd_type_offset_bsz = ice_build_ctob(ICE_TX_DESC_CMD_EOP,
@@ -1083,12 +1085,12 @@ void ice_xsk_clean_xdp_ring(struct ice_tx_ring *xdp_ring)while (ntc != ntu) {struct ice_tx_buf *tx_buf = &xdp_ring->tx_buf[ntc]; -if (tx_buf->xdp) +if (tx_buf->type ==ICE_TX_BUF_XSK_TX ) { + tx_buf->type =ICE_TX_BUF_EMPTY ;xsk_buff_free (tx_buf->xdp); -else + }else { xsk_frames++; - - tx_buf->raw_buf =NULL ; + } ntc++;if (ntc >= xdp_ring->count)
Signature · 1 line
2.39.1
PATCH 5/6 ice: fix freeing XDP frames backed by Page Pool
In reply to Alexander LobakinAs already mentioned, freeing any &xdp_frame via page_frag_free() is wrong, as it assumes the frame is backed by either an order-0 page or a page with no "patrons" behind them, while in fact frames backed by Page Pool can be redirected to a device, which's driver doesn't use it. Keep storing a pointer to the raw buffer and then freeing it unconditionally via page_frag_free() for %XDP_TX frames, but introduce a separate type in the enum for frames coming through .ndo_xdp_xmit(), and free them via xdp_return_frame_bulk(). Note that saving xdpf as xdp_buff->data_hard_start is intentional and is always true when everything is configured properly.
After this change, %XDP_REDIRECT from a Page Pool based driver to ice becomes zero-alloc as it should be and horrendous 3.3 Mpps / queue turn into 6.6, hehe.
Let it go with no "Fixes:" tag as it spans across good 5+ commits and can't be trivially backported.
--- drivers/net/ethernet/intel/ice/ice_txrx.c | 5 ++- drivers/net/ethernet/intel/ice/ice_txrx.h | 3 ++ drivers/net/ethernet/intel/ice/ice_txrx_lib.c | 43 +++++++++++++++---- drivers/net/ethernet/intel/ice/ice_txrx_lib.h | 3 +- 4 files changed, 43 insertions(+), 11 deletions(-)
drivers/net/ethernet/intel/ice/ice_txrx.c +4 -1
@@ -128,6 +128,9 @@ ice_unmap_and_free_tx_buf(struct ice_tx_ring *ring, struct ice_tx_buf *tx_buf)case ICE_TX_BUF_XDP_TX :page_frag_free (tx_buf->raw_buf);break ; +case ICE_TX_BUF_XDP_XMIT : +xdp_return_frame (tx_buf->xdpf); +break ; } tx_buf->next_to_watch =NULL ;
@@ -575,7 +578,7 @@ ice_run_xdp(struct ice_rx_ring *rx_ring, struct xdp_buff *xdp,case XDP_TX :if (static_branch_unlikely (&ice_xdp_locking_key))spin_lock (&xdp_ring->tx_lock); - ret =__ice_xmit_xdp_ring (xdp, xdp_ring); + ret =__ice_xmit_xdp_ring (xdp, xdp_ring, false);if (static_branch_unlikely (&ice_xdp_locking_key))spin_unlock (&xdp_ring->tx_lock);if (ret ==ICE_XDP_CONSUMED )
drivers/net/ethernet/intel/ice/ice_txrx.h +3 -0
@@ -153,6 +153,7 @@ static inline int ice_skb_pad(void)* @ICE_TX_BUF_FRAG: mapped skb OR &xdp_buff frag, only unmap DMA * @ICE_TX_BUF_SKB: &sk_buff, unmap and consume_skb(), update stats * @ICE_TX_BUF_XDP_TX: &xdp_buff, unmap and page_frag_free(), stats +* @ICE_TX_BUF_XDP_XMIT: &xdp_frame, unmap and xdp_return_frame(), stats * @ICE_TX_BUF_XSK_TX: &xdp_buff on XSk queue, xsk_buff_free(), stats */ enum ice_tx_buf_type {
@@ -161,6 +162,7 @@ enum ice_tx_buf_type {ICE_TX_BUF_FRAG ,ICE_TX_BUF_SKB ,ICE_TX_BUF_XDP_TX , +ICE_TX_BUF_XDP_XMIT , ICE_TX_BUF_XSK_TX, };
@@ -172,6 +174,7 @@ struct ice_tx_buf {union {void *raw_buf;/* used for XDP_TX and FDir rules */ struct sk_buff *skb;/* used for .ndo_start_xmit() */ +struct xdp_frame *xdpf;/* used for .ndo_xdp_xmit() */ struct xdp_buff *xdp;/* used for XDP_TX ZC */ };unsigned int bytecount;
drivers/net/ethernet/intel/ice/ice_txrx_lib.c +34 -9
114 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_txrx_lib.h +2 -1
@@ -143,7 +143,8 @@ static inline u32 ice_set_rs_bit(const struct ice_tx_ring *xdp_ring)void ice_finalize_xdp_rx (struct ice_tx_ring *xdp_ring,unsigned int xdp_res,u32 first_idx);int ice_xmit_xdp_buff (struct xdp_buff *xdp,struct ice_tx_ring *xdp_ring);int ice_xmit_xdp_ring (struct xdp_frame *xdpf,struct ice_tx_ring *xdp_ring); -int __ice_xmit_xdp_ring (struct xdp_buff *xdp,struct ice_tx_ring *xdp_ring); +int __ice_xmit_xdp_ring (struct xdp_buff *xdp,struct ice_tx_ring *xdp_ring, +bool frame);void ice_release_rx_desc (struct ice_rx_ring *rx_ring,u16 val); void ice_process_skb_fields(struct ice_rx_ring *rx_ring,
Signature · 1 line
2.39.1
PATCH 6/6 ice: micro-optimize .ndo_xdp_xmit() path
In reply to Alexander LobakinAfter the recent mbuf changes, ice_xmit_xdp_ring() became a 3-liner. It makes no sense to keep it global in a different file than its caller. Move it just next to the sole call site and mark static. Also, it doesn't need a full xdp_convert_frame_to_buff(). Save several cycles and fill only the fields used by __ice_xmit_xdp_ring() later on. Finally, since it doesn't modify @xdpf anyhow, mark the argument const to save some more (whole -11 bytes of .text! :D).
Thanks to 1 jump less and less calcs as well, this yields as many as 6.7 Mpps per queue. xdp.data_hard_start = xdpf is fully intentional again (see xdp_convert_buff_to_frame()) and just works when there are no source device's driver issues.
--- drivers/net/ethernet/intel/ice/ice_txrx.c | 21 ++++++++++++++++++- drivers/net/ethernet/intel/ice/ice_txrx_lib.c | 13 ------------ drivers/net/ethernet/intel/ice/ice_txrx_lib.h | 1 - 3 files changed, 20 insertions(+), 15 deletions(-)
drivers/net/ethernet/intel/ice/ice_txrx.c +20 -1
@@ -605,6 +605,25 @@ ice_run_xdp(struct ice_rx_ring *rx_ring, struct xdp_buff *xdp,ice_set_rx_bufs_act (xdp, rx_ring, ret); } +/** +* ice_xmit_xdp_ring - submit frame to XDP ring for transmission +* @xdpf: XDP frame that will be converted to XDP buff +* @xdp_ring: XDP ring for transmission +*/ +static int ice_xmit_xdp_ring (const struct xdp_frame *xdpf, +struct ice_tx_ring *xdp_ring) +{ +struct xdp_buff xdp; + + xdp.data_hard_start = (void *)xdpf; + xdp.data = xdpf->data; + xdp.data_end = xdp.data + xdpf->len; + xdp.frame_sz = xdpf->frame_sz; + xdp.flags = xdpf->flags; + +return __ice_xmit_xdp_ring (&xdp, xdp_ring, true); +} +/** * ice_xdp_xmit - submit packets to XDP ring for transmission * @dev: netdev
@@ -650,7 +669,7 @@ ice_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **frames, tx_buf = &xdp_ring->tx_buf[xdp_ring->next_to_use];for (i =0 ; i < n; i++) { -struct xdp_frame *xdpf = frames[i]; +const struct xdp_frame *xdpf = frames[i];int err; err =ice_xmit_xdp_ring (xdpf, xdp_ring);
drivers/net/ethernet/intel/ice/ice_txrx_lib.c +0 -13
@@ -434,19 +434,6 @@ int __ice_xmit_xdp_ring(struct xdp_buff *xdp, struct ice_tx_ring *xdp_ring,return ICE_XDP_CONSUMED ; } -/** -* ice_xmit_xdp_ring - submit frame to XDP ring for transmission -* @xdpf: XDP frame that will be converted to XDP buff -* @xdp_ring: XDP ring for transmission -*/ -int ice_xmit_xdp_ring (struct xdp_frame *xdpf,struct ice_tx_ring *xdp_ring) -{ -struct xdp_buff xdp; - -xdp_convert_frame_to_buff (xdpf, &xdp); -return __ice_xmit_xdp_ring (&xdp, xdp_ring, true); -} -/** * ice_finalize_xdp_rx - Bump XDP Tx tail and/or flush redirect map * @xdp_ring: XDP ring
drivers/net/ethernet/intel/ice/ice_txrx_lib.h +0 -1
@@ -142,7 +142,6 @@ static inline u32 ice_set_rs_bit(const struct ice_tx_ring *xdp_ring)void ice_finalize_xdp_rx (struct ice_tx_ring *xdp_ring,unsigned int xdp_res,u32 first_idx);int ice_xmit_xdp_buff (struct xdp_buff *xdp,struct ice_tx_ring *xdp_ring); -int ice_xmit_xdp_ring (struct xdp_frame *xdpf,struct ice_tx_ring *xdp_ring);int __ice_xmit_xdp_ring (struct xdp_buff *xdp,struct ice_tx_ring *xdp_ring,bool frame);void ice_release_rx_desc (struct ice_rx_ring *rx_ring,u16 val);
Signature · 1 line
2.39.1
Quoted 12 lines · Alexander Lobakin
The set grew from the poor performance of %BPF_F_TEST_XDP_LIVE_FRAMES when the ice-backed device is a sender. Initially there were around 3.3 Mpps / thread, while I have 5.5 on skb-based pktgen...
After fixing 0005 (0004 is a prereq for it) first (strange thing nobody noticed that earlier), I started catching random OOMs. This is how 0002 (and partially 0001) appeared.
0003 is a suggestion from Maciej to not waste time on refactoring dead lines. 0006 is a "cherry on top" to get away with the final 6.7 Mpps. 4.5 of 6 are fixes, but only the first three are tagged, since it then starts being tricky. I may backport them manually later on.
Quoted 7 lines
TL;DR for the series is that shortcuts are good, but only as long as they don't make the driver miss important things. %XDP_TX is purely driver-local, however .ndo_xdp_xmit() is not, and sometimes assumptions can be unsafe there.
With that series and also one core code patch[0], "live frames" and xdp-trafficgen are now safe'n'fast on ice (probably more to come).
Nice speedup! And cool to see that you're playing around with xdp-trafficgen :)
-Toke
From: Toke Høiland-Jørgensen <[email protected]>
Date: Fri, 10 Feb 2023 19:09:12 +0100
Quoted 19 lines
Quoted 17 lines · Alexander Lobakin
The set grew from the poor performance of %BPF_F_TEST_XDP_LIVE_FRAMES when the ice-backed device is a sender. Initially there were around 3.3 Mpps / thread, while I have 5.5 on skb-based pktgen...
After fixing 0005 (0004 is a prereq for it) first (strange thing nobody noticed that earlier), I started catching random OOMs. This is how 0002 (and partially 0001) appeared.
0003 is a suggestion from Maciej to not waste time on refactoring dead lines. 0006 is a "cherry on top" to get away with the final 6.7 Mpps. 4.5 of 6 are fixes, but only the first three are tagged, since it then starts being tricky. I may backport them manually later on.TL;DR for the series is that shortcuts are good, but only as long as they don't make the driver miss important things. %XDP_TX is purely driver-local, however .ndo_xdp_xmit() is not, and sometimes assumptions can be unsafe there.
Quoted 5 lines
Quoted 2 lines
With that series and also one core code patch[0], "live frames" and xdp-trafficgen are now safe'n'fast on ice (probably more to come).
Nice speedup! And cool to see that you're playing around with xdp-trafficgen :)
It's not only good for bombing receivers without any special HW, but also for uncovering problems with XDP in drivers and/or kernel core, as I can see :D
Quoted 3 lines
-Toke
Thanks,
Olek
Quoted 17 lines · Alexander Lobakin
The set grew from the poor performance of %BPF_F_TEST_XDP_LIVE_FRAMES when the ice-backed device is a sender. Initially there were around 3.3 Mpps / thread, while I have 5.5 on skb-based pktgen...
After fixing 0005 (0004 is a prereq for it) first (strange thing nobody noticed that earlier), I started catching random OOMs. This is how 0002 (and partially 0001) appeared.
0003 is a suggestion from Maciej to not waste time on refactoring dead lines. 0006 is a "cherry on top" to get away with the final 6.7 Mpps. 4.5 of 6 are fixes, but only the first three are tagged, since it then starts being tricky. I may backport them manually later on.TL;DR for the series is that shortcuts are good, but only as long as they don't make the driver miss important things. %XDP_TX is purely driver-local, however .ndo_xdp_xmit() is not, and sometimes assumptions can be unsafe there.
Quoted 6 lines
With that series and also one core code patch[0], "live frames" and xdp-trafficgen are now safe'n'fast on ice (probably more to come).
[0] https://lore.kernel.org/all/[email protected]
---
Goes to directly to bpf-next as touches the recently added/changed code.
For the series:
Quoted 19 lines
Alexander Lobakin (6):
ice: fixice_tx_ring::xdp_tx_activeunderflow
ice: fix XDP Tx ring overrun
ice: remove two impossible branches on XDP Tx cleaning
ice: robustify cleaning/completing XDP Tx buffers
ice: fix freeing XDP frames backed by Page Pool
ice: micro-optimize .ndo_xdp_xmit() pathdrivers/net/ethernet/intel/ice/ice_txrx.c | 67 +++++++++----- drivers/net/ethernet/intel/ice/ice_txrx.h | 37 ++++++-- drivers/net/ethernet/intel/ice/ice_txrx_lib.c | 88 ++++++++++++------- drivers/net/ethernet/intel/ice/ice_txrx_lib.h | 4 +- drivers/net/ethernet/intel/ice/ice_xsk.c | 12 +-- 5 files changed, 136 insertions(+), 72 deletions(-)Signature · 1 line
2.39.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 12 lines · On Fri, 10 Feb 2023 18:06:12 +0100 you wrote:
The set grew from the poor performance of %BPF_F_TEST_XDP_LIVE_FRAMES when the ice-backed device is a sender. Initially there were around 3.3 Mpps / thread, while I have 5.5 on skb-based pktgen...
After fixing 0005 (0004 is a prereq for it) first (strange thing nobody noticed that earlier), I started catching random OOMs. This is how 0002 (and partially 0001) appeared.
0003 is a suggestion from Maciej to not waste time on refactoring dead lines. 0006 is a "cherry on top" to get away with the final 6.7 Mpps. 4.5 of 6 are fixes, but only the first three are tagged, since it then starts being tricky. I may backport them manually later on.
Quoted 1 line
[...]
Here is the summary with links:
- [bpf-next,1/6] ice: fix ice_tx_ring::xdp_tx_active underflow
https://git.kernel.org/bpf/bpf-next/c/bc4db8347003 - [bpf-next,2/6] ice: fix XDP Tx ring overrun https://git.kernel.org/bpf/bpf-next/c/0bd939b60cea - [bpf-next,3/6] ice: remove two impossible branches on XDP Tx cleaning https://git.kernel.org/bpf/bpf-next/c/923096b5cec3 - [bpf-next,4/6] ice: robustify cleaning/completing XDP Tx buffers https://git.kernel.org/bpf/bpf-next/c/aa1d3faf71a6 - [bpf-next,5/6] ice: fix freeing XDP frames backed by Page Pool https://git.kernel.org/bpf/bpf-next/c/055d0920685e - [bpf-next,6/6] ice: micro-optimize .ndo_xdp_xmit() path https://git.kernel.org/bpf/bpf-next/c/ad07f29b9c9a
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html