Module Name: src
Committed By: msaitoh
Date: Thu Aug 19 10:18:13 UTC 2021
Modified Files:
src/sys/dev/pci/ixgbe: ix_txrx.c ixgbe_osdep.h
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/sys/dev/pci/ixgbe/ix_txrx.c
cvs rdiff -u -r1.28 -r1.29 src/sys/dev/pci/ixgbe/ixgbe_osdep.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/pci/ixgbe/ix_txrx.c
diff -u src/sys/dev/pci/ixgbe/ix_txrx.c:1.85 src/sys/dev/pci/ixgbe/ix_txrx.c:1.86
--- src/sys/dev/pci/ixgbe/ix_txrx.c:1.85 Thu Aug 19 08:53:21 2021
+++ src/sys/dev/pci/ixgbe/ix_txrx.c Thu Aug 19 10:18:13 2021
@@ -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 bool ixgbe_rsc_enable = FALSE;
*/
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 @@ ixgbe_refresh_mbufs(struct rx_ring *rxr,
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 @@ ixgbe_setup_receive_ring(struct rx_ring
}
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 @@ ixgbe_rxeof(struct ix_queue *que)
*/
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;
Index: src/sys/dev/pci/ixgbe/ixgbe_osdep.h
diff -u src/sys/dev/pci/ixgbe/ixgbe_osdep.h:1.28 src/sys/dev/pci/ixgbe/ixgbe_osdep.h:1.29
--- src/sys/dev/pci/ixgbe/ixgbe_osdep.h:1.28 Tue Sep 1 04:19:16 2020
+++ src/sys/dev/pci/ixgbe/ixgbe_osdep.h Thu Aug 19 10:18:13 2021
@@ -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 @@ void prefetch(void *x)
#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;