Skip to content

Commit 8a11b33

Browse files
mfijalkoborkmann
authored andcommitted
ice: Use xdp->frame_sz instead of recalculating truesize
SKB path calculates truesize on three different functions, which could be avoided as xdp_buff carries the already calculated truesize under xdp_buff::frame_sz. If ice_add_rx_frag() is adjusted to take the xdp_buff as an input just like functions responsible for creating sk_buff initially, codebase could be simplified by removing these redundant recalculations and rely on xdp_buff::frame_sz instead. 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 9070fe3 commit 8a11b33

File tree

1 file changed

+9
-24
lines changed

1 file changed

+9
-24
lines changed

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

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,7 @@ ice_can_reuse_rx_page(struct ice_rx_buf *rx_buf)
840840
/**
841841
* ice_add_rx_frag - Add contents of Rx buffer to sk_buff as a frag
842842
* @rx_ring: Rx descriptor ring to transact packets on
843+
* @xdp: XDP buffer
843844
* @rx_buf: buffer containing page to add
844845
* @skb: sk_buff to place the data into
845846
* @size: packet length from rx_desc
@@ -849,19 +850,14 @@ ice_can_reuse_rx_page(struct ice_rx_buf *rx_buf)
849850
* The function will then update the page offset.
850851
*/
851852
static void
852-
ice_add_rx_frag(struct ice_rx_ring *rx_ring, struct ice_rx_buf *rx_buf,
853-
struct sk_buff *skb, unsigned int size)
853+
ice_add_rx_frag(struct ice_rx_ring *rx_ring, struct xdp_buff *xdp,
854+
struct ice_rx_buf *rx_buf, struct sk_buff *skb,
855+
unsigned int size)
854856
{
855-
#if (PAGE_SIZE >= 8192)
856-
unsigned int truesize = SKB_DATA_ALIGN(size + rx_ring->rx_offset);
857-
#else
858-
unsigned int truesize = ice_rx_pg_size(rx_ring) / 2;
859-
#endif
860-
861857
if (!size)
862858
return;
863859
skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_buf->page,
864-
rx_buf->page_offset, size, truesize);
860+
rx_buf->page_offset, size, xdp->frame_sz);
865861
}
866862

867863
/**
@@ -943,13 +939,6 @@ ice_build_skb(struct ice_rx_ring *rx_ring, struct ice_rx_buf *rx_buf,
943939
struct xdp_buff *xdp)
944940
{
945941
u8 metasize = xdp->data - xdp->data_meta;
946-
#if (PAGE_SIZE < 8192)
947-
unsigned int truesize = ice_rx_pg_size(rx_ring) / 2;
948-
#else
949-
unsigned int truesize = SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) +
950-
SKB_DATA_ALIGN(xdp->data_end -
951-
xdp->data_hard_start);
952-
#endif
953942
struct sk_buff *skb;
954943

955944
/* Prefetch first cache line of first page. If xdp->data_meta
@@ -959,7 +948,7 @@ ice_build_skb(struct ice_rx_ring *rx_ring, struct ice_rx_buf *rx_buf,
959948
*/
960949
net_prefetch(xdp->data_meta);
961950
/* build an skb around the page buffer */
962-
skb = napi_build_skb(xdp->data_hard_start, truesize);
951+
skb = napi_build_skb(xdp->data_hard_start, xdp->frame_sz);
963952
if (unlikely(!skb))
964953
return NULL;
965954

@@ -1017,13 +1006,9 @@ ice_construct_skb(struct ice_rx_ring *rx_ring, struct ice_rx_buf *rx_buf,
10171006
/* if we exhaust the linear part then add what is left as a frag */
10181007
size -= headlen;
10191008
if (size) {
1020-
#if (PAGE_SIZE >= 8192)
1021-
unsigned int truesize = SKB_DATA_ALIGN(size);
1022-
#else
1023-
unsigned int truesize = ice_rx_pg_size(rx_ring) / 2;
1024-
#endif
10251009
skb_add_rx_frag(skb, 0, rx_buf->page,
1026-
rx_buf->page_offset + headlen, size, truesize);
1010+
rx_buf->page_offset + headlen, size,
1011+
xdp->frame_sz);
10271012
} else {
10281013
/* buffer is unused, change the act that should be taken later
10291014
* on; data was copied onto skb's linear part so there's no
@@ -1176,7 +1161,7 @@ int ice_clean_rx_irq(struct ice_rx_ring *rx_ring, int budget)
11761161
continue;
11771162
construct_skb:
11781163
if (skb) {
1179-
ice_add_rx_frag(rx_ring, rx_buf, skb, size);
1164+
ice_add_rx_frag(rx_ring, xdp, rx_buf, skb, size);
11801165
} else if (likely(xdp->data)) {
11811166
if (ice_ring_uses_build_skb(rx_ring))
11821167
skb = ice_build_skb(rx_ring, rx_buf, xdp);

0 commit comments

Comments
 (0)