Nuke huge mbuf macros stage 1/2: Remove massive inline mbuf macros to reduce
authorMatthew Dillon <dillon@dragonflybsd.org>
Sat, 19 Jul 2003 21:09:27 +0000 (21:09 +0000)
committerMatthew Dillon <dillon@dragonflybsd.org>
Sat, 19 Jul 2003 21:09:27 +0000 (21:09 +0000)
L1/L2 cache pollution.  Est. performance improvement of 4-6% and the kernel
is 42KB smaller.

Submitted-by: Bosko Milekic <bmilekic@technokratis.com>
sys/kern/uipc_mbuf.c
sys/sys/mbuf.h

index 9fae9e0..1b726e5 100644 (file)
@@ -32,7 +32,7 @@
  *
  *     @(#)uipc_mbuf.c 8.2 (Berkeley) 1/4/94
  * $FreeBSD: src/sys/kern/uipc_mbuf.c,v 1.51.2.24 2003/04/15 06:59:29 silby Exp $
- * $DragonFly: src/sys/kern/uipc_mbuf.c,v 1.5 2003/07/10 04:47:54 dillon Exp $
+ * $DragonFly: src/sys/kern/uipc_mbuf.c,v 1.6 2003/07/19 21:09:24 dillon Exp $
  */
 
 #include "opt_param.h"
@@ -437,7 +437,8 @@ struct mbuf *
 m_retry(i, t)
        int i, t;
 {
-       register struct mbuf *m;
+       struct mbuf *m;
+       int ms;
 
        /*
         * Must only do the reclaim if not in an interrupt context.
@@ -450,21 +451,24 @@ m_retry(i, t)
                m_reclaim();
        }
 
-       /*
-        * Both m_mballoc_wait and m_retry must be nulled because
-        * when the MGET macro is run from here, we deffinately do _not_
-        * want to enter an instance of m_mballoc_wait() or m_retry() (again!)
-        */
-#define m_mballoc_wait(caller,type)    (struct mbuf *)0
-#define m_retry(i, t)  (struct mbuf *)0
-       MGET(m, i, t);
-#undef m_retry
-#undef m_mballoc_wait
-
-       if (m != NULL)
+       ms = splimp();
+       if (mmbfree == NULL)
+               (void)m_mballoc(1, i);
+       m = mmbfree;
+       if (m != NULL) {
+               mmbfree = m->m_next;
+               mbtypes[MT_FREE]--;
+               m->m_type = t;
+               mbtypes[t]++;
+               m->m_next = NULL;
+               m->m_nextpkt = NULL;
+               m->m_data = m->m_dat;
+               m->m_flags = 0;
+               splx(ms);
                mbstat.m_wait++;
-       else {
+       else {
                static int last_report ; /* when we did that (in ticks) */
+               splx(ms);
                mbstat.m_drops++;
                if (ticks < last_report || (ticks - last_report) >= hz) {
                        last_report = ticks;
@@ -482,7 +486,8 @@ struct mbuf *
 m_retryhdr(i, t)
        int i, t;
 {
-       register struct mbuf *m;
+       struct mbuf *m;
+       int ms;
 
        /*
         * Must only do the reclaim if not in an interrupt context.
@@ -495,16 +500,28 @@ m_retryhdr(i, t)
                m_reclaim();
        }
 
-#define m_mballoc_wait(caller,type)    (struct mbuf *)0
-#define m_retryhdr(i, t) (struct mbuf *)0
-       MGETHDR(m, i, t);
-#undef m_retryhdr
-#undef m_mballoc_wait
-
-       if (m != NULL)  
+       ms = splimp();
+       if (mmbfree == NULL)
+               (void)m_mballoc(1, i);
+       m = mmbfree;
+       if (m != NULL) {
+               mmbfree = m->m_next;
+               mbtypes[MT_FREE]--;
+               m->m_type = t;
+               mbtypes[t]++;
+               m->m_next = NULL;
+               m->m_nextpkt = NULL;
+               m->m_data = m->m_pktdat;
+               m->m_flags = M_PKTHDR;
+               m->m_pkthdr.rcvif = NULL;
+               SLIST_INIT(&m->m_pkthdr.tags);
+               m->m_pkthdr.csum_flags = 0;
+               splx(ms);
                mbstat.m_wait++;
-       else    {
+       } else {
                static int last_report ; /* when we did that (in ticks) */
+
+               splx(ms);
                mbstat.m_drops++;
                if (ticks < last_report || (ticks - last_report) >= hz) {
                        last_report = ticks;
@@ -539,9 +556,29 @@ struct mbuf *
 m_get(how, type)
        int how, type;
 {
-       register struct mbuf *m;
-
-       MGET(m, how, type);
+       struct mbuf *m;
+       int ms;
+
+       ms = splimp();
+       if (mmbfree == NULL)
+               (void)m_mballoc(1, how);
+       m = mmbfree;
+       if (m != NULL) {
+               mmbfree = m->m_next;
+               mbtypes[MT_FREE]--;
+               m->m_type = type;
+               mbtypes[type]++;
+               m->m_next = NULL;
+               m->m_nextpkt = NULL;
+               m->m_data = m->m_dat;
+               m->m_flags = 0;
+               splx(ms);
+       } else {
+               splx(ms);
+               m = m_retry(how, type);
+               if (m == NULL && how == M_WAIT)
+                       m = m_mballoc_wait(MGET_C, type);
+       }
        return (m);
 }
 
@@ -549,9 +586,32 @@ struct mbuf *
 m_gethdr(how, type)
        int how, type;
 {
-       register struct mbuf *m;
-
-       MGETHDR(m, how, type);
+       struct mbuf *m;
+       int ms;
+
+       ms = splimp();
+       if (mmbfree == NULL)
+               (void)m_mballoc(1, how);
+       m = mmbfree;
+       if (m != NULL) {
+               mmbfree = m->m_next;
+               mbtypes[MT_FREE]--;
+               m->m_type = type;
+               mbtypes[type]++;
+               m->m_next = NULL;
+               m->m_nextpkt = NULL;
+               m->m_data = m->m_pktdat;
+               m->m_flags = M_PKTHDR;
+               m->m_pkthdr.rcvif = NULL;
+               SLIST_INIT(&m->m_pkthdr.tags);
+               m->m_pkthdr.csum_flags = 0;
+               splx(ms);
+       } else {
+               splx(ms);
+               m = m_retryhdr(how, type);
+               if (m == NULL && how == M_WAIT)
+                       m = m_mballoc_wait(MGETHDR_C, type);
+       }
        return (m);
 }
 
index 4f45f6b..d418b2f 100644 (file)
@@ -32,7 +32,7 @@
  *
  *     @(#)mbuf.h      8.5 (Berkeley) 2/19/95
  * $FreeBSD: src/sys/sys/mbuf.h,v 1.44.2.17 2003/04/15 06:15:02 silby Exp $
- * $DragonFly: src/sys/sys/mbuf.h,v 1.2 2003/06/17 04:28:58 dillon Exp $
+ * $DragonFly: src/sys/sys/mbuf.h,v 1.3 2003/07/19 21:09:27 dillon Exp $
  */
 
 #ifndef _SYS_MBUF_H_
@@ -300,7 +300,7 @@ union mcluster {
 } while (0)
 
 /*
- * mbuf allocation/deallocation macros:
+ * mbuf allocation/deallocation macros (YYY deprecated, too big):
  *
  *     MGET(struct mbuf *m, int how, int type)
  * allocates an mbuf and initializes it to contain internal data.
@@ -310,66 +310,11 @@ union mcluster {
  * and internal data.
  */
 #define        MGET(m, how, type) do {                                         \
-       struct mbuf *_mm;                                               \
-       int _mhow = (how);                                              \
-       int _mtype = (type);                                            \
-       int _ms = splimp();                                             \
-                                                                       \
-       if (mmbfree == NULL)                                            \
-               (void)m_mballoc(1, _mhow);                              \
-       _mm = mmbfree;                                                  \
-       if (_mm != NULL) {                                              \
-               mmbfree = _mm->m_next;                                  \
-               mbtypes[MT_FREE]--;                                     \
-               _mm->m_type = _mtype;                                   \
-               mbtypes[_mtype]++;                                      \
-               _mm->m_next = NULL;                                     \
-               _mm->m_nextpkt = NULL;                                  \
-               _mm->m_data = _mm->m_dat;                               \
-               _mm->m_flags = 0;                                       \
-               (m) = _mm;                                              \
-               splx(_ms);                                              \
-       } else {                                                        \
-               splx(_ms);                                              \
-               _mm = m_retry(_mhow, _mtype);                           \
-               if (_mm == NULL && _mhow == M_WAIT)                     \
-                       (m) = m_mballoc_wait(MGET_C, _mtype);           \
-               else                                                    \
-                       (m) = _mm;                                      \
-       }                                                               \
+       (m) = m_get((how), (type));                                     \
 } while (0)
 
 #define        MGETHDR(m, how, type) do {                                      \
-       struct mbuf *_mm;                                               \
-       int _mhow = (how);                                              \
-       int _mtype = (type);                                            \
-       int _ms = splimp();                                             \
-                                                                       \
-       if (mmbfree == NULL)                                            \
-               (void)m_mballoc(1, _mhow);                              \
-       _mm = mmbfree;                                                  \
-       if (_mm != NULL) {                                              \
-               mmbfree = _mm->m_next;                                  \
-               mbtypes[MT_FREE]--;                                     \
-               _mm->m_type = _mtype;                                   \
-               mbtypes[_mtype]++;                                      \
-               _mm->m_next = NULL;                                     \
-               _mm->m_nextpkt = NULL;                                  \
-               _mm->m_data = _mm->m_pktdat;                            \
-               _mm->m_flags = M_PKTHDR;                                \
-               _mm->m_pkthdr.rcvif = NULL;                             \
-               SLIST_INIT(&_mm->m_pkthdr.tags);                        \
-               _mm->m_pkthdr.csum_flags = 0;                           \
-               (m) = _mm;                                              \
-               splx(_ms);                                              \
-       } else {                                                        \
-               splx(_ms);                                              \
-               _mm = m_retryhdr(_mhow, _mtype);                        \
-               if (_mm == NULL && _mhow == M_WAIT)                     \
-                       (m) = m_mballoc_wait(MGETHDR_C, _mtype);        \
-               else                                                    \
-                       (m) = _mm;                                      \
-       }                                                               \
+       (m) = m_gethdr((how), (type));                                  \
 } while (0)
 
 /*