Skip to content

Commit ac07533

Browse files
mfijalkoborkmann
authored andcommitted
ice: Store page count inside ice_rx_buf
This will allow us to avoid carrying additional auxiliary array of page counts when dealing with XDP multi buffer support. Previously combining fragmented frame to skb was not affected in the same way as XDP would be as whole frame is needed to be in place before executing XDP prog. Therefore, when going through HW Rx descriptors one-by-one, calls to ice_put_rx_buf() need to be taken *after* running XDP prog on a potentially multi buffered frame, so some additional storage of page count is needed. By adding page count to rx buf, it will make it easier to walk through processed entries at the end of rx cleaning routine and decide whether or not buffers should be recycled. While at it, bump ice_rx_buf::pagecnt_bias from u16 up to u32. It was proven many times that calculations on variables smaller than standard register size are harmful. This was also the case during experiments with embedding page count to ice_rx_buf - when this was added as u16 it had a performance impact. Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Reviewed-by: Alexander Lobakin <alexandr.lobakin@intel.com> Link: https://lore.kernel.org/bpf/20230131204506.219292-4-maciej.fijalkowski@intel.com
1 parent cb0473e commit ac07533

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

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

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -791,15 +791,14 @@ ice_rx_buf_adjust_pg_offset(struct ice_rx_buf *rx_buf, unsigned int size)
791791
/**
792792
* ice_can_reuse_rx_page - Determine if page can be reused for another Rx
793793
* @rx_buf: buffer containing the page
794-
* @rx_buf_pgcnt: rx_buf page refcount pre xdp_do_redirect() call
795794
*
796795
* If page is reusable, we have a green light for calling ice_reuse_rx_page,
797796
* which will assign the current buffer to the buffer that next_to_alloc is
798797
* pointing to; otherwise, the DMA mapping needs to be destroyed and
799798
* page freed
800799
*/
801800
static bool
802-
ice_can_reuse_rx_page(struct ice_rx_buf *rx_buf, int rx_buf_pgcnt)
801+
ice_can_reuse_rx_page(struct ice_rx_buf *rx_buf)
803802
{
804803
unsigned int pagecnt_bias = rx_buf->pagecnt_bias;
805804
struct page *page = rx_buf->page;
@@ -810,7 +809,7 @@ ice_can_reuse_rx_page(struct ice_rx_buf *rx_buf, int rx_buf_pgcnt)
810809

811810
#if (PAGE_SIZE < 8192)
812811
/* if we are only owner of page we can reuse it */
813-
if (unlikely((rx_buf_pgcnt - pagecnt_bias) > 1))
812+
if (unlikely(rx_buf->pgcnt - pagecnt_bias > 1))
814813
return false;
815814
#else
816815
#define ICE_LAST_OFFSET \
@@ -894,19 +893,17 @@ ice_reuse_rx_page(struct ice_rx_ring *rx_ring, struct ice_rx_buf *old_buf)
894893
* ice_get_rx_buf - Fetch Rx buffer and synchronize data for use
895894
* @rx_ring: Rx descriptor ring to transact packets on
896895
* @size: size of buffer to add to skb
897-
* @rx_buf_pgcnt: rx_buf page refcount
898896
*
899897
* This function will pull an Rx buffer from the ring and synchronize it
900898
* for use by the CPU.
901899
*/
902900
static struct ice_rx_buf *
903-
ice_get_rx_buf(struct ice_rx_ring *rx_ring, const unsigned int size,
904-
int *rx_buf_pgcnt)
901+
ice_get_rx_buf(struct ice_rx_ring *rx_ring, const unsigned int size)
905902
{
906903
struct ice_rx_buf *rx_buf;
907904

908905
rx_buf = &rx_ring->rx_buf[rx_ring->next_to_clean];
909-
*rx_buf_pgcnt =
906+
rx_buf->pgcnt =
910907
#if (PAGE_SIZE < 8192)
911908
page_count(rx_buf->page);
912909
#else
@@ -1042,15 +1039,13 @@ ice_construct_skb(struct ice_rx_ring *rx_ring, struct ice_rx_buf *rx_buf,
10421039
* ice_put_rx_buf - Clean up used buffer and either recycle or free
10431040
* @rx_ring: Rx descriptor ring to transact packets on
10441041
* @rx_buf: Rx buffer to pull data from
1045-
* @rx_buf_pgcnt: Rx buffer page count pre xdp_do_redirect()
10461042
*
10471043
* This function will update next_to_clean and then clean up the contents
10481044
* of the rx_buf. It will either recycle the buffer or unmap it and free
10491045
* the associated resources.
10501046
*/
10511047
static void
1052-
ice_put_rx_buf(struct ice_rx_ring *rx_ring, struct ice_rx_buf *rx_buf,
1053-
int rx_buf_pgcnt)
1048+
ice_put_rx_buf(struct ice_rx_ring *rx_ring, struct ice_rx_buf *rx_buf)
10541049
{
10551050
u16 ntc = rx_ring->next_to_clean + 1;
10561051

@@ -1061,7 +1056,7 @@ ice_put_rx_buf(struct ice_rx_ring *rx_ring, struct ice_rx_buf *rx_buf,
10611056
if (!rx_buf)
10621057
return;
10631058

1064-
if (ice_can_reuse_rx_page(rx_buf, rx_buf_pgcnt)) {
1059+
if (ice_can_reuse_rx_page(rx_buf)) {
10651060
/* hand second half of page back to the ring */
10661061
ice_reuse_rx_page(rx_ring, rx_buf);
10671062
} else {
@@ -1137,7 +1132,6 @@ int ice_clean_rx_irq(struct ice_rx_ring *rx_ring, int budget)
11371132
unsigned char *hard_start;
11381133
unsigned int size;
11391134
u16 stat_err_bits;
1140-
int rx_buf_pgcnt;
11411135
u16 vlan_tag = 0;
11421136
u16 rx_ptype;
11431137

@@ -1166,7 +1160,7 @@ int ice_clean_rx_irq(struct ice_rx_ring *rx_ring, int budget)
11661160
if (rx_desc->wb.rxdid == FDIR_DESC_RXDID &&
11671161
ctrl_vsi->vf)
11681162
ice_vc_fdir_irq_handler(ctrl_vsi, rx_desc);
1169-
ice_put_rx_buf(rx_ring, NULL, 0);
1163+
ice_put_rx_buf(rx_ring, NULL);
11701164
cleaned_count++;
11711165
continue;
11721166
}
@@ -1175,7 +1169,7 @@ int ice_clean_rx_irq(struct ice_rx_ring *rx_ring, int budget)
11751169
ICE_RX_FLX_DESC_PKT_LEN_M;
11761170

11771171
/* retrieve a buffer from the ring */
1178-
rx_buf = ice_get_rx_buf(rx_ring, size, &rx_buf_pgcnt);
1172+
rx_buf = ice_get_rx_buf(rx_ring, size);
11791173

11801174
if (!size) {
11811175
xdp->data = NULL;
@@ -1209,7 +1203,7 @@ int ice_clean_rx_irq(struct ice_rx_ring *rx_ring, int budget)
12091203
total_rx_pkts++;
12101204

12111205
cleaned_count++;
1212-
ice_put_rx_buf(rx_ring, rx_buf, rx_buf_pgcnt);
1206+
ice_put_rx_buf(rx_ring, rx_buf);
12131207
continue;
12141208
construct_skb:
12151209
if (skb) {
@@ -1228,7 +1222,7 @@ int ice_clean_rx_irq(struct ice_rx_ring *rx_ring, int budget)
12281222
break;
12291223
}
12301224

1231-
ice_put_rx_buf(rx_ring, rx_buf, rx_buf_pgcnt);
1225+
ice_put_rx_buf(rx_ring, rx_buf);
12321226
cleaned_count++;
12331227

12341228
/* skip if it is NOP desc */

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ struct ice_rx_buf {
172172
dma_addr_t dma;
173173
struct page *page;
174174
unsigned int page_offset;
175-
u16 pagecnt_bias;
175+
unsigned int pgcnt;
176+
unsigned int pagecnt_bias;
176177
};
177178

178179
struct ice_q_stats {

0 commit comments

Comments
 (0)