ionic: better Tx SG handling
Subsystems (3)
cover ionic: better Tx SG handling
The primary patch here is to be sure we're not hitting linearize on a Tx skb when we don't really need to. The other two are related details.
Shannon Nelson (3):
ionic: count SGs in packet to minimize linearize
ionic: add a check for max SGs and SKB frags
ionic: expand the descriptor bufs array
.../net/ethernet/pensando/ionic/ionic_dev.h | 3 +- .../net/ethernet/pensando/ionic/ionic_lif.c | 12 +++ .../net/ethernet/pensando/ionic/ionic_txrx.c | 77 ++++++++++++++++--- 3 files changed, 82 insertions(+), 10 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/3 ionic: count SGs in packet to minimize linearize
There are some cases where an skb carries more frags than the number of SGs that ionic can support per descriptor - this forces the driver to linearize the skb. However, if this is a TSO packet that is going to become multiple descriptors (one per MTU-sized packet) and spread the frags across them, this time-consuming linearization is likely not necessary.
We scan the frag list and count up the number of SGs that would be created for each descriptor that would be generated, and only linearize if we hit the SG limit on a descriptor. In most cases, we won't even get to the frag list scan, so this doesn't affect typical traffic.
--- .../net/ethernet/pensando/ionic/ionic_txrx.c | 77 ++++++++++++++++--- 1 file changed, 68 insertions(+), 9 deletions(-)
drivers/net/ethernet/pensando/ionic/ionic_txrx.c +68 -9
@@ -1239,25 +1239,84 @@ static int ionic_tx(struct ionic_queue *q, struct sk_buff *skb)static int ionic_tx_descs_needed (struct ionic_queue *q,struct sk_buff *skb) {struct ionic_tx_stats *stats =q_to_tx_stats (q); +bool too_many_frags = false; +skb_frag_t *frag; +int desc_bufs; +int chunk_len; +int frag_rem; +int tso_rem; +int seg_rem; +bool encap; +int hdrlen;int ndescs;int err;/* Each desc is mss long max, so a descriptor for each gso_seg */ -if (skb_is_gso (skb)) +if (skb_is_gso (skb)) { ndescs =skb_shinfo (skb)->gso_segs; -else + }else { ndescs =1 ; +if (skb_shinfo (skb)->nr_frags > q->max_sg_elems) { + too_many_frags = true; + goto linearize; + } + } -/* If non-TSO, just need 1 desc and nr_frags sg elems */ -if (skb_shinfo (skb)->nr_frags <= q->max_sg_elems) +/* If non-TSO, or no frags to check, we're done */ +if (!skb_is_gso (skb) || !skb_shinfo (skb)->nr_frags)return ndescs; -/* Too many frags, so linearize */ - err =skb_linearize (skb); -if (err) -return err; +/* We need to scan the skb to be sure that none of the MTU sized +* packets in the TSO will require more sgs per descriptor than we +* can support. We loop through the frags, add up the lengths for +* a packet, and count the number of sgs used per packet. +*/ + tso_rem = skb->len; + frag =skb_shinfo (skb)->frags; + encap = skb->encapsulation; + +/* start with just hdr in first part of first descriptor */ +if (encap) + hdrlen =skb_inner_tcp_all_headers (skb); +else + hdrlen =skb_tcp_all_headers (skb); + seg_rem =min_t (int, tso_rem, hdrlen +skb_shinfo (skb)->gso_size); + frag_rem = hdrlen; + +while (tso_rem >0 ) { + desc_bufs =0 ; +while (seg_rem >0 ) { + desc_bufs++; + +/* We add the +1 because we can take buffers for one +* more than we have SGs: one for the initial desc data +* in addition to the SG segments that might follow. +*/ +if (desc_bufs > q->max_sg_elems +1 ) { + too_many_frags = true; + goto linearize; + } + +if (frag_rem ==0 ) { + frag_rem =skb_frag_size (frag); + frag++; + } + chunk_len =min (frag_rem, seg_rem); + frag_rem -= chunk_len; + tso_rem -= chunk_len; + seg_rem -= chunk_len; + } + + seg_rem =min_t (int, tso_rem,skb_shinfo (skb)->gso_size); + } - stats->linearize++; +linearize: +if (too_many_frags) { + err =skb_linearize (skb); +if (err) +return err; + stats->linearize++; + }return ndescs; }
Signature · 1 line
2.17.1
PATCH 2/3 ionic: add a check for max SGs and SKB frags
In reply to Shannon NelsonAdd a check of the queue's max_sg_elems against the maximum frags we expect to see per SKB and take the smaller of the two as our max for the queues' descriptor buffer allocations.
--- drivers/net/ethernet/pensando/ionic/ionic_lif.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/net/ethernet/pensando/ionic/ionic_lif.c +12 -0
@@ -3831,6 +3831,18 @@ static void ionic_lif_queue_identify(struct ionic_lif *lif) qtype, qti->max_sg_elems);dev_dbg (ionic->dev," qtype[%d].sg_desc_stride = %d\n" , qtype, qti->sg_desc_stride); + +if (qti->max_sg_elems >=IONIC_MAX_FRAGS ) { + qti->max_sg_elems =IONIC_MAX_FRAGS -1 ; +dev_dbg (ionic->dev,"limiting qtype %d max_sg_elems to IONIC_MAX_FRAGS-1 %d\n" , + qtype, qti->max_sg_elems); + } + +if (qti->max_sg_elems >MAX_SKB_FRAGS ) { + qti->max_sg_elems =MAX_SKB_FRAGS ; +dev_dbg (ionic->dev,"limiting qtype %d max_sg_elems to MAX_SKB_FRAGS %d\n" , + qtype, qti->max_sg_elems); + } } }
Signature · 1 line
2.17.1
PATCH 3/3 ionic: expand the descriptor bufs array
In reply to Shannon NelsonWhen processing a TSO we may have frags spread across several descriptors, and the total count of frags in one skb may exceed our per descriptor IONIC_MAX_FRAGS: this is fine as long as each descriptor has fewer frags than the limit. Since the skb could have as many as MAX_SKB_FRAGS, and the first descriptor is where we track and map the frag buffers, we need to be sure we can map buffers for all of the frags plus the TSO header in the first descriptor's buffer array.
--- drivers/net/ethernet/pensando/ionic/ionic_dev.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/pensando/ionic/ionic_dev.h +2 -1
@@ -7,6 +7,7 @@#include <linux/atomic.h> #include <linux/mutex.h> #include <linux/workqueue.h> +#include <linux/skbuff.h> #include "ionic_if.h" #include "ionic_regs.h"
@@ -216,7 +217,7 @@ struct ionic_desc_info { };unsigned int bytes;unsigned int nbufs; -struct ionic_buf_info bufs[IONIC_MAX_FRAGS ]; +struct ionic_buf_info bufs[MAX_SKB_FRAGS +1 ];ionic_desc_cb cb;void *cb_arg; };
Signature · 1 line
2.17.1
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Quoted 9 lines · On Mon, 18 Sep 2023 15:21:33 -0700 you wrote:
The primary patch here is to be sure we're not hitting linearize on a Tx skb when we don't really need to. The other two are related details.
Shannon Nelson (3):
ionic: count SGs in packet to minimize linearize
ionic: add a check for max SGs and SKB frags
ionic: expand the descriptor bufs array[...]
Here is the summary with links:
- [net-next,1/3] ionic: count SGs in packet to minimize linearize
https://git.kernel.org/netdev/net-next/c/4d9d72200d4c - [net-next,2/3] ionic: add a check for max SGs and SKB frags https://git.kernel.org/netdev/net-next/c/40d835391b4f - [net-next,3/3] ionic: expand the descriptor bufs array https://git.kernel.org/netdev/net-next/c/529cdfd5e3a6
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Quoted 8 lines · Shannon Nelson
The primary patch here is to be sure we're not hitting linearize on a Tx skb when we don't really need to. The other two are related details.
Shannon Nelson (3):
ionic: count SGs in packet to minimize linearize
ionic: add a check for max SGs and SKB frags
ionic: expand the descriptor bufs array
Quoted 5 lines
.../net/ethernet/pensando/ionic/ionic_dev.h | 3 +- .../net/ethernet/pensando/ionic/ionic_lif.c | 12 +++ .../net/ethernet/pensando/ionic/ionic_txrx.c | 77 ++++++++++++++++--- 3 files changed, 82 insertions(+), 10 deletions(-)