Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/pci/ixgbe Don't pre-allocate a cluster not to do m_f...



details:   https://anonhg.NetBSD.org/src/rev/c6641862d21d
branches:  trunk
changeset: 1023454:c6641862d21d
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Wed Sep 08 08:46:28 2021 +0000

description:
Don't pre-allocate a cluster not to do m_freem() it on RXCOPY case.

diffstat:

 sys/dev/pci/ixgbe/ix_txrx.c |  85 +++++++++++++++++++++++---------------------
 1 files changed, 44 insertions(+), 41 deletions(-)

diffs (136 lines):

diff -r 73dd607a402d -r c6641862d21d sys/dev/pci/ixgbe/ix_txrx.c
--- a/sys/dev/pci/ixgbe/ix_txrx.c       Wed Sep 08 07:25:55 2021 +0000
+++ b/sys/dev/pci/ixgbe/ix_txrx.c       Wed Sep 08 08:46:28 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ix_txrx.c,v 1.92 2021/09/07 08:17:20 msaitoh Exp $ */
+/* $NetBSD: ix_txrx.c,v 1.93 2021/09/08 08:46:28 msaitoh Exp $ */
 
 /******************************************************************************
 
@@ -64,7 +64,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ix_txrx.c,v 1.92 2021/09/07 08:17:20 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ix_txrx.c,v 1.93 2021/09/08 08:46:28 msaitoh Exp $");
 
 #include "opt_inet.h"
 #include "opt_inet6.h"
@@ -1837,6 +1837,7 @@
                u16         len;
                u16         vtag = 0;
                bool        eop;
+               bool        discard = false;
 
                /* Sync the ring. */
                ixgbe_dmamap_sync(rxr->rxdma.dma_tag, rxr->rxdma.dma_map,
@@ -1852,7 +1853,7 @@
                        break;
 
                loopcount++;
-               sendmp = NULL;
+               sendmp = newmp = NULL;
                nbuf = NULL;
                rsc = 0;
                cur->wb.upper.status_error = 0;
@@ -1876,15 +1877,30 @@
                        goto next_desc;
                }
 
-               /* pre-alloc new mbuf */
-               if (!discard_multidesc) {
-                       newmp = ixgbe_getcl();
-                       if (__predict_false(newmp == NULL))
-                               rxr->no_mbuf.ev_count++;
-               } else
-                       newmp = NULL;
+               if (__predict_false(discard_multidesc))
+                       discard = true;
+               else {
+                       /* Pre-alloc new mbuf. */
 
-               if (__predict_false(newmp == NULL)) {
+                       if ((rbuf->fmp == NULL) &&
+                           eop && (len <= adapter->rx_copy_len)) {
+                               /* For short packet. See below. */
+                               sendmp = m_gethdr(M_NOWAIT, MT_DATA);
+                               if (__predict_false(sendmp == NULL)) {
+                                       rxr->no_mbuf.ev_count++;
+                                       discard = true;
+                               }
+                       } else {
+                               /* For long packet. */
+                               newmp = ixgbe_getcl();
+                               if (__predict_false(newmp == NULL)) {
+                                       rxr->no_mbuf.ev_count++;
+                                       discard = true;
+                               }
+                       }
+               }
+
+               if (__predict_false(discard)) {
                        /*
                         * Descriptor initialization is already done by the
                         * above code (cur->wb.upper.status_error = 0).
@@ -1950,8 +1966,10 @@
                 * See if there is a stored head
                 * that determines what we are
                 */
-               sendmp = rbuf->fmp;
-               if (sendmp != NULL) {  /* secondary frag */
+               if (rbuf->fmp != NULL) {
+                       /* Secondary frag */
+                       sendmp = rbuf->fmp;
+
                        /* Update new (used in future) mbuf */
                        newmp->m_pkthdr.len = newmp->m_len = rxr->mbuf_sz;
                        IXGBE_M_ADJ(adapter, rxr, newmp);
@@ -1971,35 +1989,20 @@
                         * packet.
                         */
 
-                       /*
-                        * Optimize.  This might be a small packet, maybe just
-                        * a TCP ACK. Copy into a new mbuf, and Leave the old
-                        * mbuf+cluster for re-use.
-                        */
-                       if (eop && len <= adapter->rx_copy_len) {
-                               sendmp = m_gethdr(M_NOWAIT, MT_DATA);
-                               if (sendmp != NULL) {
-                                       sendmp->m_data += ETHER_ALIGN;
-                                       memcpy(mtod(sendmp, void *),
-                                           mtod(mp, void *), len);
-                                       rxr->rx_copies.ev_count++;
-                                       rbuf->flags |= IXGBE_RX_COPY;
+                       if (eop && (len <= adapter->rx_copy_len)) {
+                               /*
+                                * Optimize.  This might be a small packet, may
+                                * be just a TCP ACK. Copy into a new mbuf, and
+                                * Leave the old mbuf+cluster for re-use.
+                                */
+                               sendmp->m_data += ETHER_ALIGN;
+                               memcpy(mtod(sendmp, void *),
+                                   mtod(mp, void *), len);
+                               rxr->rx_copies.ev_count++;
+                               rbuf->flags |= IXGBE_RX_COPY;
+                       } else {
+                               /* Non short packet */
 
-                                       /*
-                                        * Free pre-allocated mbuf anymore
-                                        * because we recycle the current
-                                        * buffer.
-                                        */
-                                       m_freem(newmp);
-                               }
-                       }
-
-                       /*
-                        * Two cases:
-                        * a) non small packet(i.e. !IXGBE_RX_COPY).
-                        * b) a small packet but the above m_gethdr() failed.
-                        */
-                       if (sendmp == NULL) {
                                /* Update new (used in future) mbuf */
                                newmp->m_pkthdr.len = newmp->m_len
                                    = rxr->mbuf_sz;



Home | Main Index | Thread Index | Old Index