[PATCH 3/3] network: Do not use MSIZE
Sebastian Huber
sebastian.huber at embedded-brains.de
Mon May 22 12:16:02 UTC 2017
Do not use the MSIZE for the legacy network stack. Instead use
_SYS_MBUF_LEGACY_MSIZE.
Update #2833.
---
cpukit/libnetworking/kern/uipc_socket2.c | 4 ++--
cpukit/libnetworking/rtems/rtems_glue.c | 10 +++++-----
cpukit/libnetworking/sys/mbuf.h | 8 +++++---
cpukit/libnetworking/sys/socketvar.h | 4 ++--
4 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/cpukit/libnetworking/kern/uipc_socket2.c b/cpukit/libnetworking/kern/uipc_socket2.c
index c2d18b1..e6ea672 100644
--- a/cpukit/libnetworking/kern/uipc_socket2.c
+++ b/cpukit/libnetworking/kern/uipc_socket2.c
@@ -343,7 +343,7 @@ int
sbreserve(struct sockbuf *sb, u_long cc)
{
- if (cc > sb_max * MCLBYTES / (MSIZE + MCLBYTES))
+ if (cc > sb_max * MCLBYTES / (_SYS_MBUF_LEGACY_MSIZE + MCLBYTES))
return (0);
sb->sb_hiwat = cc;
sb->sb_mbmax = min(cc * sb_efficiency, sb_max);
@@ -424,7 +424,7 @@ sbcheck(struct sockbuf *sb)
for (m = sb->sb_mb; m; m = m->m_next) {
len += m->m_len;
- mbcnt += MSIZE;
+ mbcnt += _SYS_MBUF_LEGACY_MSIZE;
if (m->m_flags & M_EXT) /*XXX*/ /* pretty sure this is bogus */
mbcnt += m->m_ext.ext_size;
if (m->m_nextpkt)
diff --git a/cpukit/libnetworking/rtems/rtems_glue.c b/cpukit/libnetworking/rtems/rtems_glue.c
index 46f8765..ac75fb0 100644
--- a/cpukit/libnetworking/rtems/rtems_glue.c
+++ b/cpukit/libnetworking/rtems/rtems_glue.c
@@ -39,7 +39,7 @@
/*
* Memory allocation
*/
-static uint32_t nmbuf = (64L * 1024L) / MSIZE;
+static uint32_t nmbuf = (64L * 1024L) / _SYS_MBUF_LEGACY_MSIZE;
uint32_t nmbclusters = (128L * 1024L) / MCLBYTES;
/*
@@ -221,8 +221,8 @@ bsd_init (void)
* Set up mbuf data structures
*/
- p = rtems_bsdnet_malloc_mbuf(nmbuf * MSIZE + MSIZE - 1,MBUF_MALLOC_MBUF);
- p = (char *)(((uintptr_t)p + MSIZE - 1) & ~(MSIZE - 1));
+ p = rtems_bsdnet_malloc_mbuf(nmbuf * _SYS_MBUF_LEGACY_MSIZE + _SYS_MBUF_LEGACY_MSIZE - 1,MBUF_MALLOC_MBUF);
+ p = (char *)(((uintptr_t)p + _SYS_MBUF_LEGACY_MSIZE - 1) & ~(_SYS_MBUF_LEGACY_MSIZE - 1));
if (p == NULL) {
printf ("Can't get network memory.\n");
return -1;
@@ -230,7 +230,7 @@ bsd_init (void)
for (i = 0; i < nmbuf; i++) {
((struct mbuf *)p)->m_next = mmbfree;
mmbfree = (struct mbuf *)p;
- p += MSIZE;
+ p += _SYS_MBUF_LEGACY_MSIZE;
}
mbstat.m_mbufs = nmbuf;
mbstat.m_mtypes[MT_FREE] = nmbuf;
@@ -296,7 +296,7 @@ rtems_bsdnet_initialize (void)
* Set the memory allocation limits
*/
if (rtems_bsdnet_config.mbuf_bytecount)
- nmbuf = rtems_bsdnet_config.mbuf_bytecount / MSIZE;
+ nmbuf = rtems_bsdnet_config.mbuf_bytecount / _SYS_MBUF_LEGACY_MSIZE;
if (rtems_bsdnet_config.mbuf_cluster_bytecount)
nmbclusters = rtems_bsdnet_config.mbuf_cluster_bytecount / MCLBYTES;
diff --git a/cpukit/libnetworking/sys/mbuf.h b/cpukit/libnetworking/sys/mbuf.h
index 48e9e40..8d0c6c2 100644
--- a/cpukit/libnetworking/sys/mbuf.h
+++ b/cpukit/libnetworking/sys/mbuf.h
@@ -34,19 +34,21 @@
#ifndef _SYS_MBUF_H_
#define _SYS_MBUF_H_
+#include <sys/param.h>
#ifndef M_WAITOK
#include <sys/malloc.h>
#endif
/*
- * Mbufs are of a single size, MSIZE (machine/machparam.h), which
+ * Mbufs are of a single size, _SYS_MBUF_LEGACY_MSIZE (machine/machparam.h), which
* includes overhead. An mbuf may add a single "mbuf cluster" of size
* MCLBYTES (also in machine/machparam.h), which has no additional overhead
* and is used instead of the internal data area; this is done when
* at least MINCLSIZE of data must be stored.
*/
-#define MLEN (MSIZE - sizeof(struct m_hdr)) /* normal data len */
+#define _SYS_MBUF_LEGACY_MSIZE 128
+#define MLEN (_SYS_MBUF_LEGACY_MSIZE - sizeof(struct m_hdr)) /* normal data len */
#define MHLEN (MLEN - sizeof(struct pkthdr)) /* data len w/pkthdr */
#define MINCLSIZE (MHLEN + MLEN) /* smallest amount to put in cluster */
#define M_MAXCOMPRESS (MHLEN / 2) /* max amount to copy for compression */
@@ -59,7 +61,7 @@
* cltom(x) -- Convert cluster # to ptr to beginning of cluster
*/
#define mtod(m, t) ((t)((m)->m_data))
-#define dtom(x) ((struct mbuf *)((intptr_t)(x) & ~(MSIZE-1)))
+#define dtom(x) ((struct mbuf *)((intptr_t)(x) & ~(_SYS_MBUF_LEGACY_MSIZE-1)))
#define mtocl(x) (((uintptr_t)(x) - (uintptr_t)mbutl) >> MCLSHIFT)
#define cltom(x) ((caddr_t)((u_long)mbutl + ((u_long)(x) << MCLSHIFT)))
diff --git a/cpukit/libnetworking/sys/socketvar.h b/cpukit/libnetworking/sys/socketvar.h
index 13b3674..bc3709c 100644
--- a/cpukit/libnetworking/sys/socketvar.h
+++ b/cpukit/libnetworking/sys/socketvar.h
@@ -160,7 +160,7 @@ struct socket {
/* adjust counters in sb reflecting allocation of m */
#define sballoc(sb, m) { \
(sb)->sb_cc += (m)->m_len; \
- (sb)->sb_mbcnt += MSIZE; \
+ (sb)->sb_mbcnt += _SYS_MBUF_LEGACY_MSIZE; \
if ((m)->m_flags & M_EXT) \
(sb)->sb_mbcnt += (m)->m_ext.ext_size; \
}
@@ -168,7 +168,7 @@ struct socket {
/* adjust counters in sb reflecting freeing of m */
#define sbfree(sb, m) { \
(sb)->sb_cc -= (m)->m_len; \
- (sb)->sb_mbcnt -= MSIZE; \
+ (sb)->sb_mbcnt -= _SYS_MBUF_LEGACY_MSIZE; \
if ((m)->m_flags & M_EXT) \
(sb)->sb_mbcnt -= (m)->m_ext.ext_size; \
}
--
1.8.4.5
More information about the devel
mailing list