Skip to content

Commit 3876ff5

Browse files
mfijalkoborkmann
authored andcommitted
ice: xsk: Handle SW XDP ring wrap and bump tail more often
Currently, 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. Signed-off-by: Magnus Karlsson <[email protected]> Signed-off-by: Maciej Fijalkowski <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Reviewed-by: Alexander Lobakin <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 296f13f commit 3876ff5

File tree

2 files changed

+81
-20
lines changed

2 files changed

+81
-20
lines changed

drivers/net/ethernet/intel/ice/ice_txrx.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ static inline int ice_skb_pad(void)
111111
(u16)((((R)->next_to_clean > (R)->next_to_use) ? 0 : (R)->count) + \
112112
(R)->next_to_clean - (R)->next_to_use - 1)
113113

114+
#define ICE_RING_QUARTER(R) ((R)->count >> 2)
115+
114116
#define ICE_TX_FLAGS_TSO BIT(0)
115117
#define ICE_TX_FLAGS_HW_VLAN BIT(1)
116118
#define ICE_TX_FLAGS_SW_VLAN BIT(2)

drivers/net/ethernet/intel/ice/ice_xsk.c

Lines changed: 79 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -367,33 +367,28 @@ int ice_xsk_pool_setup(struct ice_vsi *vsi, struct xsk_buff_pool *pool, u16 qid)
367367
}
368368

369369
/**
370-
* ice_alloc_rx_bufs_zc - allocate a number of Rx buffers
371-
* @rx_ring: Rx ring
370+
* ice_fill_rx_descs - pick buffers from XSK buffer pool and use it
371+
* @pool: XSK Buffer pool to pull the buffers from
372+
* @xdp: SW ring of xdp_buff that will hold the buffers
373+
* @rx_desc: Pointer to Rx descriptors that will be filled
372374
* @count: The number of buffers to allocate
373375
*
374376
* This function allocates a number of Rx buffers from the fill ring
375377
* or the internal recycle mechanism and places them on the Rx ring.
376378
*
377-
* Returns true if all allocations were successful, false if any fail.
379+
* Note that ring wrap should be handled by caller of this function.
380+
*
381+
* Returns the amount of allocated Rx descriptors
378382
*/
379-
bool ice_alloc_rx_bufs_zc(struct ice_rx_ring *rx_ring, u16 count)
383+
static u16 ice_fill_rx_descs(struct xsk_buff_pool *pool, struct xdp_buff **xdp,
384+
union ice_32b_rx_flex_desc *rx_desc, u16 count)
380385
{
381-
union ice_32b_rx_flex_desc *rx_desc;
382-
u16 ntu = rx_ring->next_to_use;
383-
struct xdp_buff **xdp;
384-
u32 nb_buffs, i;
385386
dma_addr_t dma;
387+
u16 buffs;
388+
int i;
386389

387-
rx_desc = ICE_RX_DESC(rx_ring, ntu);
388-
xdp = ice_xdp_buf(rx_ring, ntu);
389-
390-
nb_buffs = min_t(u16, count, rx_ring->count - ntu);
391-
nb_buffs = xsk_buff_alloc_batch(rx_ring->xsk_pool, xdp, nb_buffs);
392-
if (!nb_buffs)
393-
return false;
394-
395-
i = nb_buffs;
396-
while (i--) {
390+
buffs = xsk_buff_alloc_batch(pool, xdp, count);
391+
for (i = 0; i < buffs; i++) {
397392
dma = xsk_buff_xdp_get_dma(*xdp);
398393
rx_desc->read.pkt_addr = cpu_to_le64(dma);
399394
rx_desc->wb.status_error0 = 0;
@@ -402,13 +397,77 @@ bool ice_alloc_rx_bufs_zc(struct ice_rx_ring *rx_ring, u16 count)
402397
xdp++;
403398
}
404399

400+
return buffs;
401+
}
402+
403+
/**
404+
* __ice_alloc_rx_bufs_zc - allocate a number of Rx buffers
405+
* @rx_ring: Rx ring
406+
* @count: The number of buffers to allocate
407+
*
408+
* Place the @count of descriptors onto Rx ring. Handle the ring wrap
409+
* for case where space from next_to_use up to the end of ring is less
410+
* than @count. Finally do a tail bump.
411+
*
412+
* Returns true if all allocations were successful, false if any fail.
413+
*/
414+
static bool __ice_alloc_rx_bufs_zc(struct ice_rx_ring *rx_ring, u16 count)
415+
{
416+
union ice_32b_rx_flex_desc *rx_desc;
417+
u32 nb_buffs_extra = 0, nb_buffs;
418+
u16 ntu = rx_ring->next_to_use;
419+
u16 total_count = count;
420+
struct xdp_buff **xdp;
421+
422+
rx_desc = ICE_RX_DESC(rx_ring, ntu);
423+
xdp = ice_xdp_buf(rx_ring, ntu);
424+
425+
if (ntu + count >= rx_ring->count) {
426+
nb_buffs_extra = ice_fill_rx_descs(rx_ring->xsk_pool, xdp,
427+
rx_desc,
428+
rx_ring->count - ntu);
429+
rx_desc = ICE_RX_DESC(rx_ring, 0);
430+
xdp = ice_xdp_buf(rx_ring, 0);
431+
ntu = 0;
432+
count -= nb_buffs_extra;
433+
ice_release_rx_desc(rx_ring, 0);
434+
}
435+
436+
nb_buffs = ice_fill_rx_descs(rx_ring->xsk_pool, xdp, rx_desc, count);
437+
405438
ntu += nb_buffs;
406439
if (ntu == rx_ring->count)
407440
ntu = 0;
408441

409-
ice_release_rx_desc(rx_ring, ntu);
442+
if (rx_ring->next_to_use != ntu)
443+
ice_release_rx_desc(rx_ring, ntu);
444+
445+
return total_count == (nb_buffs_extra + nb_buffs);
446+
}
447+
448+
/**
449+
* ice_alloc_rx_bufs_zc - allocate a number of Rx buffers
450+
* @rx_ring: Rx ring
451+
* @count: The number of buffers to allocate
452+
*
453+
* Wrapper for internal allocation routine; figure out how many tail
454+
* bumps should take place based on the given threshold
455+
*
456+
* Returns true if all calls to internal alloc routine succeeded
457+
*/
458+
bool ice_alloc_rx_bufs_zc(struct ice_rx_ring *rx_ring, u16 count)
459+
{
460+
u16 rx_thresh = ICE_RING_QUARTER(rx_ring);
461+
u16 batched, leftover, i, tail_bumps;
462+
463+
batched = ALIGN_DOWN(count, rx_thresh);
464+
tail_bumps = batched / rx_thresh;
465+
leftover = count & (rx_thresh - 1);
410466

411-
return count == nb_buffs;
467+
for (i = 0; i < tail_bumps; i++)
468+
if (!__ice_alloc_rx_bufs_zc(rx_ring, rx_thresh))
469+
return false;
470+
return __ice_alloc_rx_bufs_zc(rx_ring, leftover);
412471
}
413472

414473
/**

0 commit comments

Comments
 (0)