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 Use m_adj(ETHER_ALIGN) more. Tested by me ...



details:   https://anonhg.NetBSD.org/src/rev/521c42f97bef
branches:  trunk
changeset: 1023005:521c42f97bef
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Thu Aug 19 10:18:13 2021 +0000

description:
Use m_adj(ETHER_ALIGN) more. Tested by me (amd64,aarch64) and rin (alpha).

 - Align with ETHER_ALIGN everywhere where mbuf is allocated.
 - Remove extra setting of M_PKTHDR. No functional change.
 - Add comment.

diffstat:

 sys/dev/pci/ixgbe/ix_txrx.c     |  64 +++++++++++++++++++++++++++++-----------
 sys/dev/pci/ixgbe/ixgbe_osdep.h |  21 +------------
 2 files changed, 47 insertions(+), 38 deletions(-)

diffs (168 lines):

diff -r 59556f37a317 -r 521c42f97bef sys/dev/pci/ixgbe/ix_txrx.c
--- a/sys/dev/pci/ixgbe/ix_txrx.c       Thu Aug 19 09:05:22 2021 +0000
+++ b/sys/dev/pci/ixgbe/ix_txrx.c       Thu Aug 19 10:18:13 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ix_txrx.c,v 1.85 2021/08/19 08:53:21 msaitoh Exp $ */
+/* $NetBSD: ix_txrx.c,v 1.86 2021/08/19 10:18:13 msaitoh Exp $ */
 
 /******************************************************************************
 
@@ -64,7 +64,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ix_txrx.c,v 1.85 2021/08/19 08:53:21 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ix_txrx.c,v 1.86 2021/08/19 10:18:13 msaitoh Exp $");
 
 #include "opt_inet.h"
 #include "opt_inet6.h"
@@ -96,6 +96,10 @@
  */
 static int atr_sample_rate = 20;
 
+#define IXGBE_M_ADJ(adapter, rxr, mp)                                  \
+       if (adapter->max_frame_size <= (rxr->mbuf_sz - ETHER_ALIGN))    \
+               m_adj(mp, ETHER_ALIGN)
+
 /************************************************************************
  *  Local Function prototypes
  ************************************************************************/
@@ -1353,14 +1357,11 @@
                                rxr->no_jmbuf.ev_count++;
                                goto update;
                        }
-                       if (adapter->max_frame_size
-                           <= (rxr->mbuf_sz - ETHER_ALIGN))
-                               m_adj(mp, ETHER_ALIGN);
+                       mp->m_pkthdr.len = mp->m_len = rxr->mbuf_sz;
+                       IXGBE_M_ADJ(adapter, rxr, mp);
                } else
                        mp = rxbuf->buf;
 
-               mp->m_pkthdr.len = mp->m_len = rxr->mbuf_sz;
-
                /* If we're dealing with an mbuf that was copied rather
                 * than replaced, there's no need to go through busdma.
                 */
@@ -1554,6 +1555,7 @@
                }
                mp = rxbuf->buf;
                mp->m_pkthdr.len = mp->m_len = rxr->mbuf_sz;
+               IXGBE_M_ADJ(adapter, rxr, mp);
                /* Get the memory mapping */
                error = bus_dmamap_load_mbuf(rxr->ptag->dt_dmat, rxbuf->pmap,
                    mp, BUS_DMA_NOWAIT);
@@ -1964,41 +1966,67 @@
                 */
                sendmp = rbuf->fmp;
                if (sendmp != NULL) {  /* secondary frag */
+                       /* Update new (used in future) mbuf */
+                       newmp->m_pkthdr.len = newmp->m_len = rxr->mbuf_sz;
+                       IXGBE_M_ADJ(adapter, rxr, newmp);
                        rbuf->buf = newmp;
                        rbuf->fmp = NULL;
+
+                       /* For secondary frag */
                        mp->m_len = len;
                        mp->m_flags &= ~M_PKTHDR;
+
+                       /* For sendmp */
                        sendmp->m_pkthdr.len += mp->m_len;
                } else {
                        /*
-                        * Optimize.  This might be a small packet,
-                        * maybe just a TCP ACK.  Do a fast copy that
-                        * is cache aligned into a new mbuf, and
-                        * leave the old mbuf+cluster for re-use.
+                        * It's the first segment of a multi descriptor
+                        * packet or a single segment which contains a full
+                        * 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 += IXGBE_RX_COPY_ALIGN;
-                                       ixgbe_bcopy(mp->m_data, sendmp->m_data,
-                                           len);
-                                       sendmp->m_len = len;
+                                       sendmp->m_data += ETHER_ALIGN;
+                                       memcpy(mtod(sendmp, void *),
+                                           mtod(mp, void *), len);
                                        rxr->rx_copies.ev_count++;
                                        rbuf->flags |= IXGBE_RX_COPY;
 
+                                       /*
+                                        * 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;
+                               IXGBE_M_ADJ(adapter, rxr, newmp);
                                rbuf->buf = newmp;
                                rbuf->fmp = NULL;
-                               mp->m_len = len;
+
+                               /* For sendmp */
                                sendmp = mp;
                        }
 
                        /* first desc of a non-ps chain */
-                       sendmp->m_flags |= M_PKTHDR;
-                       sendmp->m_pkthdr.len = len;
+                       sendmp->m_pkthdr.len = sendmp->m_len = len;
                }
                ++processed;
 
diff -r 59556f37a317 -r 521c42f97bef sys/dev/pci/ixgbe/ixgbe_osdep.h
--- a/sys/dev/pci/ixgbe/ixgbe_osdep.h   Thu Aug 19 09:05:22 2021 +0000
+++ b/sys/dev/pci/ixgbe/ixgbe_osdep.h   Thu Aug 19 10:18:13 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe_osdep.h,v 1.28 2020/09/01 04:19:16 msaitoh Exp $ */
+/* $NetBSD: ixgbe_osdep.h,v 1.29 2021/08/19 10:18:13 msaitoh Exp $ */
 
 /******************************************************************************
   SPDX-License-Identifier: BSD-3-Clause
@@ -167,25 +167,6 @@
 #define prefetch(x)
 #endif
 
-/*
- * Optimized bcopy thanks to Luigi Rizzo's investigative work.  Assumes
- * non-overlapping regions and 32-byte padding on both src and dst.
- */
-static __inline int
-ixgbe_bcopy(void *restrict _src, void *restrict _dst, int l)
-{
-       uint64_t *src = _src;
-       uint64_t *dst = _dst;
-
-       for (; l > 0; l -= 32) {
-               *dst++ = *src++;
-               *dst++ = *src++;
-               *dst++ = *src++;
-               *dst++ = *src++;
-       }
-       return (0);
-}
-
 struct ixgbe_osdep
 {
        struct ethercom    ec;



Home | Main Index | Thread Index | Old Index