Skip to content

Commit eb087cd

Browse files
mfijalkoanguy11
authored andcommitted
ice: propagate xdp_ring onto rx_ring
With rings being split, it is now convenient to introduce a pointer to XDP ring within the Rx ring. For XDP_TX workloads this means that xdp_rings array access will be skipped, which was executed per each processed frame. Also, read the XDP prog once per NAPI and if prog is present, set up the local xdp_ring pointer. Reading prog a single time was discussed in [1] with some concern raised by Toke around dispatcher handling and having the need for going through the RCU grace period in the ndo_bpf driver callback, but ice currently is torning down NAPI instances regardless of the prog presence on VSI. Although the pointer to XDP ring introduced to Rx ring makes things a lot slimmer/simpler, I still feel that single prog read per NAPI lifetime is beneficial. Further patch that will introduce the fallback path will also get a profit from that as xdp_ring pointer will be set during the XDP rings setup. [1]: https://lore.kernel.org/bpf/[email protected]/ Signed-off-by: Maciej Fijalkowski <[email protected]> Tested-by: George Kuruvinakunnel <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent a55e16f commit eb087cd

File tree

6 files changed

+35
-29
lines changed

6 files changed

+35
-29
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2396,6 +2396,9 @@ static int ice_xdp_alloc_setup_rings(struct ice_vsi *vsi)
23962396
xdp_ring->xsk_pool = ice_tx_xsk_pool(xdp_ring);
23972397
}
23982398

2399+
ice_for_each_rxq(vsi, i)
2400+
vsi->rx_rings[i]->xdp_ring = vsi->xdp_rings[i];
2401+
23992402
return 0;
24002403

24012404
free_xdp_rings:

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -537,27 +537,26 @@ ice_rx_frame_truesize(struct ice_rx_ring *rx_ring, unsigned int __maybe_unused s
537537
* @rx_ring: Rx ring
538538
* @xdp: xdp_buff used as input to the XDP program
539539
* @xdp_prog: XDP program to run
540+
* @xdp_ring: ring to be used for XDP_TX action
540541
*
541542
* Returns any of ICE_XDP_{PASS, CONSUMED, TX, REDIR}
542543
*/
543544
static int
544545
ice_run_xdp(struct ice_rx_ring *rx_ring, struct xdp_buff *xdp,
545-
struct bpf_prog *xdp_prog)
546+
struct bpf_prog *xdp_prog, struct ice_tx_ring *xdp_ring)
546547
{
547-
struct ice_tx_ring *xdp_ring;
548-
int err, result;
548+
int err;
549549
u32 act;
550550

551551
act = bpf_prog_run_xdp(xdp_prog, xdp);
552552
switch (act) {
553553
case XDP_PASS:
554554
return ICE_XDP_PASS;
555555
case XDP_TX:
556-
xdp_ring = rx_ring->vsi->xdp_rings[smp_processor_id()];
557-
result = ice_xmit_xdp_ring(xdp->data, xdp->data_end - xdp->data, xdp_ring);
558-
if (result == ICE_XDP_CONSUMED)
556+
err = ice_xmit_xdp_ring(xdp->data, xdp->data_end - xdp->data, xdp_ring);
557+
if (err == ICE_XDP_CONSUMED)
559558
goto out_failure;
560-
return result;
559+
return err;
561560
case XDP_REDIRECT:
562561
err = xdp_do_redirect(rx_ring->netdev, xdp, xdp_prog);
563562
if (err)
@@ -1083,6 +1082,7 @@ int ice_clean_rx_irq(struct ice_rx_ring *rx_ring, int budget)
10831082
unsigned int total_rx_bytes = 0, total_rx_pkts = 0, frame_sz = 0;
10841083
u16 cleaned_count = ICE_DESC_UNUSED(rx_ring);
10851084
unsigned int offset = rx_ring->rx_offset;
1085+
struct ice_tx_ring *xdp_ring = NULL;
10861086
unsigned int xdp_res, xdp_xmit = 0;
10871087
struct sk_buff *skb = rx_ring->skb;
10881088
struct bpf_prog *xdp_prog = NULL;
@@ -1095,6 +1095,10 @@ int ice_clean_rx_irq(struct ice_rx_ring *rx_ring, int budget)
10951095
#endif
10961096
xdp_init_buff(&xdp, frame_sz, &rx_ring->xdp_rxq);
10971097

1098+
xdp_prog = READ_ONCE(rx_ring->xdp_prog);
1099+
if (xdp_prog)
1100+
xdp_ring = rx_ring->xdp_ring;
1101+
10981102
/* start the loop to process Rx packets bounded by 'budget' */
10991103
while (likely(total_rx_pkts < (unsigned int)budget)) {
11001104
union ice_32b_rx_flex_desc *rx_desc;
@@ -1158,11 +1162,10 @@ int ice_clean_rx_irq(struct ice_rx_ring *rx_ring, int budget)
11581162
xdp.frame_sz = ice_rx_frame_truesize(rx_ring, size);
11591163
#endif
11601164

1161-
xdp_prog = READ_ONCE(rx_ring->xdp_prog);
11621165
if (!xdp_prog)
11631166
goto construct_skb;
11641167

1165-
xdp_res = ice_run_xdp(rx_ring, &xdp, xdp_prog);
1168+
xdp_res = ice_run_xdp(rx_ring, &xdp, xdp_prog, xdp_ring);
11661169
if (!xdp_res)
11671170
goto construct_skb;
11681171
if (xdp_res & (ICE_XDP_TX | ICE_XDP_REDIR)) {
@@ -1239,7 +1242,7 @@ int ice_clean_rx_irq(struct ice_rx_ring *rx_ring, int budget)
12391242
failure = ice_alloc_rx_bufs(rx_ring, cleaned_count);
12401243

12411244
if (xdp_prog)
1242-
ice_finalize_xdp_rx(rx_ring, xdp_xmit);
1245+
ice_finalize_xdp_rx(xdp_ring, xdp_xmit);
12431246
rx_ring->skb = skb;
12441247

12451248
ice_update_rx_ring_stats(rx_ring, total_rx_pkts, total_rx_bytes);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ struct ice_rx_ring {
287287
struct rcu_head rcu; /* to avoid race on free */
288288
/* CL4 - 3rd cacheline starts here */
289289
struct bpf_prog *xdp_prog;
290+
struct ice_tx_ring *xdp_ring;
290291
struct xsk_buff_pool *xsk_pool;
291292
struct sk_buff *skb;
292293
dma_addr_t dma; /* physical address of ring */

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,22 +283,18 @@ int ice_xmit_xdp_buff(struct xdp_buff *xdp, struct ice_tx_ring *xdp_ring)
283283

284284
/**
285285
* ice_finalize_xdp_rx - Bump XDP Tx tail and/or flush redirect map
286-
* @rx_ring: Rx ring
286+
* @xdp_ring: XDP ring
287287
* @xdp_res: Result of the receive batch
288288
*
289289
* This function bumps XDP Tx tail and/or flush redirect map, and
290290
* should be called when a batch of packets has been processed in the
291291
* napi loop.
292292
*/
293-
void ice_finalize_xdp_rx(struct ice_rx_ring *rx_ring, unsigned int xdp_res)
293+
void ice_finalize_xdp_rx(struct ice_tx_ring *xdp_ring, unsigned int xdp_res)
294294
{
295295
if (xdp_res & ICE_XDP_REDIR)
296296
xdp_do_flush_map();
297297

298-
if (xdp_res & ICE_XDP_TX) {
299-
struct ice_tx_ring *xdp_ring =
300-
rx_ring->vsi->xdp_rings[smp_processor_id()];
301-
298+
if (xdp_res & ICE_XDP_TX)
302299
ice_xdp_ring_update_tail(xdp_ring);
303-
}
304300
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static inline void ice_xdp_ring_update_tail(struct ice_tx_ring *xdp_ring)
4646
writel_relaxed(xdp_ring->next_to_use, xdp_ring->tail);
4747
}
4848

49-
void ice_finalize_xdp_rx(struct ice_rx_ring *xdp_ring, unsigned int xdp_res);
49+
void ice_finalize_xdp_rx(struct ice_tx_ring *xdp_ring, unsigned int xdp_res);
5050
int ice_xmit_xdp_buff(struct xdp_buff *xdp, struct ice_tx_ring *xdp_ring);
5151
int ice_xmit_xdp_ring(void *data, u16 size, struct ice_tx_ring *xdp_ring);
5252
void ice_release_rx_desc(struct ice_rx_ring *rx_ring, u16 val);

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -452,22 +452,18 @@ ice_construct_skb_zc(struct ice_rx_ring *rx_ring, struct xdp_buff **xdp_arr)
452452
* ice_run_xdp_zc - Executes an XDP program in zero-copy path
453453
* @rx_ring: Rx ring
454454
* @xdp: xdp_buff used as input to the XDP program
455+
* @xdp_prog: XDP program to run
456+
* @xdp_ring: ring to be used for XDP_TX action
455457
*
456458
* Returns any of ICE_XDP_{PASS, CONSUMED, TX, REDIR}
457459
*/
458460
static int
459-
ice_run_xdp_zc(struct ice_rx_ring *rx_ring, struct xdp_buff *xdp)
461+
ice_run_xdp_zc(struct ice_rx_ring *rx_ring, struct xdp_buff *xdp,
462+
struct bpf_prog *xdp_prog, struct ice_tx_ring *xdp_ring)
460463
{
461464
int err, result = ICE_XDP_PASS;
462-
struct ice_tx_ring *xdp_ring;
463-
struct bpf_prog *xdp_prog;
464465
u32 act;
465466

466-
/* ZC patch is enabled only when XDP program is set,
467-
* so here it can not be NULL
468-
*/
469-
xdp_prog = READ_ONCE(rx_ring->xdp_prog);
470-
471467
act = bpf_prog_run_xdp(xdp_prog, xdp);
472468

473469
if (likely(act == XDP_REDIRECT)) {
@@ -481,7 +477,6 @@ ice_run_xdp_zc(struct ice_rx_ring *rx_ring, struct xdp_buff *xdp)
481477
case XDP_PASS:
482478
break;
483479
case XDP_TX:
484-
xdp_ring = rx_ring->vsi->xdp_rings[rx_ring->q_index];
485480
result = ice_xmit_xdp_buff(xdp, xdp_ring);
486481
if (result == ICE_XDP_CONSUMED)
487482
goto out_failure;
@@ -512,9 +507,17 @@ int ice_clean_rx_irq_zc(struct ice_rx_ring *rx_ring, int budget)
512507
{
513508
unsigned int total_rx_bytes = 0, total_rx_packets = 0;
514509
u16 cleaned_count = ICE_DESC_UNUSED(rx_ring);
510+
struct ice_tx_ring *xdp_ring;
515511
unsigned int xdp_xmit = 0;
512+
struct bpf_prog *xdp_prog;
516513
bool failure = false;
517514

515+
/* ZC patch is enabled only when XDP program is set,
516+
* so here it can not be NULL
517+
*/
518+
xdp_prog = READ_ONCE(rx_ring->xdp_prog);
519+
xdp_ring = rx_ring->xdp_ring;
520+
518521
while (likely(total_rx_packets < (unsigned int)budget)) {
519522
union ice_32b_rx_flex_desc *rx_desc;
520523
unsigned int size, xdp_res = 0;
@@ -545,7 +548,7 @@ int ice_clean_rx_irq_zc(struct ice_rx_ring *rx_ring, int budget)
545548
xsk_buff_set_size(*xdp, size);
546549
xsk_buff_dma_sync_for_cpu(*xdp, rx_ring->xsk_pool);
547550

548-
xdp_res = ice_run_xdp_zc(rx_ring, *xdp);
551+
xdp_res = ice_run_xdp_zc(rx_ring, *xdp, xdp_prog, xdp_ring);
549552
if (xdp_res) {
550553
if (xdp_res & (ICE_XDP_TX | ICE_XDP_REDIR))
551554
xdp_xmit |= xdp_res;
@@ -593,7 +596,7 @@ int ice_clean_rx_irq_zc(struct ice_rx_ring *rx_ring, int budget)
593596
if (cleaned_count >= ICE_RX_BUF_WRITE)
594597
failure = !ice_alloc_rx_bufs_zc(rx_ring, cleaned_count);
595598

596-
ice_finalize_xdp_rx(rx_ring, xdp_xmit);
599+
ice_finalize_xdp_rx(xdp_ring, xdp_xmit);
597600
ice_update_rx_ring_stats(rx_ring, total_rx_packets, total_rx_bytes);
598601

599602
if (xsk_uses_need_wakeup(rx_ring->xsk_pool)) {

0 commit comments

Comments
 (0)