Source-Changes-HG archive

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

[src/trunk]: src/sys Change the semantics of mbuf external storage "ext_free"...



details:   https://anonhg.NetBSD.org/src/rev/61d65d72dae8
branches:  trunk
changeset: 526337:61d65d72dae8
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Thu May 02 16:22:43 2002 +0000

description:
Change the semantics of mbuf external storage "ext_free" routines
so that they're more useful for arbitrary types of external storage:

* Add an "mbuf *" argument to (*ext_free)().  If non-NULL, (*ext_free)()
  is expected to free the mbuf itself.  This allows (*ext_free)() to use
  the mbuf for bookkeeping (e.g. deferring the work to a helper thread).
  If the "mbuf *" argument is NULL, we are assumed to be in a context
  which is safe for performing the destructor operation *now*.
* Adjust MEXTREMOVE() and MFREE() routines for above change.
* Update "ade" and "ti" drivers for new semantics.

diffstat:

 sys/arch/alpha/a12/if_ade.c |  12 ++++++++-
 sys/dev/pci/if_ti.c         |  17 +++++++++-----
 sys/sys/mbuf.h              |  53 ++++++++++++++++++++++++++++++++++----------
 3 files changed, 62 insertions(+), 20 deletions(-)

diffs (189 lines):

diff -r 4f919b158edc -r 61d65d72dae8 sys/arch/alpha/a12/if_ade.c
--- a/sys/arch/alpha/a12/if_ade.c       Thu May 02 16:11:28 2002 +0000
+++ b/sys/arch/alpha/a12/if_ade.c       Thu May 02 16:22:43 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ade.c,v 1.12 2001/07/12 23:35:42 thorpej Exp $      */
+/*     $NetBSD: if_ade.c,v 1.13 2002/05/02 16:22:43 thorpej Exp $      */
 
 /*
  * NOTE: this version of if_de was modified for bounce buffers prior
@@ -234,8 +234,16 @@
  * course, they won't be needing de(4) drivers.
  */
 static void
-donothing(caddr_t m, u_int p, void *q)
+donothing(struct mbuf *m, caddr_t buf, u_int size, void *arg)
 {
+       int s;
+
+       if (__predict_true(m != NULL)) {
+               s = splvm();
+               pool_cache_put(&mbpool_cache, m);
+               splx(s);
+       }
+
 }
 static void a12r2pb(void *vsrc, void *vdst, int len) {
        long    bounce[9];
diff -r 4f919b158edc -r 61d65d72dae8 sys/dev/pci/if_ti.c
--- a/sys/dev/pci/if_ti.c       Thu May 02 16:11:28 2002 +0000
+++ b/sys/dev/pci/if_ti.c       Thu May 02 16:22:43 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_ti.c,v 1.46 2002/04/28 01:00:26 thorpej Exp $ */
+/* $NetBSD: if_ti.c,v 1.47 2002/05/02 16:22:45 thorpej Exp $ */
 
 /*
  * Copyright (c) 1997, 1998, 1999
@@ -81,7 +81,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ti.c,v 1.46 2002/04/28 01:00:26 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ti.c,v 1.47 2002/05/02 16:22:45 thorpej Exp $");
 
 #include "bpfilter.h"
 #include "opt_inet.h"
@@ -195,7 +195,7 @@
 static void ti_handle_events   __P((struct ti_softc *));
 static int ti_alloc_jumbo_mem  __P((struct ti_softc *));
 static void *ti_jalloc         __P((struct ti_softc *));
-static void ti_jfree           __P((caddr_t, u_int, void *));
+static void ti_jfree           __P((struct mbuf *, caddr_t, u_int, void *));
 static int ti_newbuf_std       __P((struct ti_softc *, int, struct mbuf *, bus_dmamap_t));
 static int ti_newbuf_mini      __P((struct ti_softc *, int, struct mbuf *, bus_dmamap_t));
 static int ti_newbuf_jumbo     __P((struct ti_softc *, int, struct mbuf *));
@@ -682,13 +682,14 @@
 /*
  * Release a jumbo buffer.
  */
-static void ti_jfree(buf, size, arg)
+static void ti_jfree(m, buf, size, arg)
+       struct mbuf             *m;
        caddr_t                 buf;
        u_int                   size;
        void *arg;
 {
        struct ti_softc         *sc;
-       int                     i;
+       int                     i, s;
        struct ti_jpool_entry   *entry;
 
        /* Extract the softc struct pointer. */
@@ -704,6 +705,8 @@
 
        if ((i < 0) || (i >= TI_JSLOTS))
                panic("ti_jfree: asked to free buffer that we don't manage!");
+
+       s = splvm();
        entry = SIMPLEQ_FIRST(&sc->ti_jinuse_listhead);
        if (entry == NULL)
                panic("ti_jfree: buffer not in use!");
@@ -713,7 +716,9 @@
        SIMPLEQ_INSERT_HEAD(&sc->ti_jfree_listhead, 
             entry, jpool_entries);
 
-       return;
+       if (__predict_true(m != NULL))
+               pool_cache_put(&mbpool_cache, m);
+       splx(s);
 }
 
 
diff -r 4f919b158edc -r 61d65d72dae8 sys/sys/mbuf.h
--- a/sys/sys/mbuf.h    Thu May 02 16:11:28 2002 +0000
+++ b/sys/sys/mbuf.h    Thu May 02 16:22:43 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mbuf.h,v 1.64 2002/03/09 01:46:32 thorpej Exp $        */
+/*     $NetBSD: mbuf.h,v 1.65 2002/05/02 16:22:45 thorpej Exp $        */
 
 /*-
  * Copyright (c) 1996, 1997, 1999, 2001 The NetBSD Foundation, Inc.
@@ -150,7 +150,7 @@
 struct m_ext {
        caddr_t ext_buf;                /* start of buffer */
        void    (*ext_free)             /* free routine if not the usual */
-               __P((caddr_t, u_int, void *));
+               __P((struct mbuf *, caddr_t, u_int, void *));
        void    *ext_arg;               /* argument for ext_free */
        u_int   ext_size;               /* size of buffer, for ext_free */
        int     ext_type;               /* malloc type */
@@ -392,24 +392,32 @@
        MCLINITREFERENCE(m);                                            \
 } while (/* CONSTCOND */ 0)
 
-#define        _MEXTREMOVE(m)                                                  \
+#define        MEXTREMOVE(m)                                                   \
 do {                                                                   \
+       int _ms_ = splvm(); /* MBUFLOCK */                              \
        if (MCLISREFERENCED(m)) {                                       \
                _MCLDEREFERENCE(m);                                     \
+               splx(_ms_);                                             \
        } else if ((m)->m_flags & M_CLUSTER) {                          \
                pool_cache_put(&mclpool_cache, (m)->m_ext.ext_buf);     \
+               splx(_ms_);                                             \
        } else if ((m)->m_ext.ext_free) {                               \
-               (*((m)->m_ext.ext_free))((m)->m_ext.ext_buf,            \
+               /*                                                      \
+                * NOTE: We assume that MEXTREMOVE() is called from     \
+                * code where it is safe to invoke the free routine     \
+                * without the mbuf to perform bookkeeping.             \
+                */                                                     \
+               splx(_ms_);                                             \
+               (*((m)->m_ext.ext_free))(NULL, (m)->m_ext.ext_buf,      \
                    (m)->m_ext.ext_size, (m)->m_ext.ext_arg);           \
        } else {                                                        \
-               free((m)->m_ext.ext_buf,(m)->m_ext.ext_type);           \
+               splx(_ms_);                                             \
+               free((m)->m_ext.ext_buf, (m)->m_ext.ext_type);          \
        }                                                               \
        (m)->m_flags &= ~(M_CLUSTER|M_EXT);                             \
        (m)->m_ext.ext_size = 0;        /* why ??? */                   \
 } while (/* CONSTCOND */ 0)
 
-#define        MEXTREMOVE(m)   MBUFLOCK(_MEXTREMOVE((m));)
-
 /*
  * Reset the data pointer on an mbuf.
  */
@@ -435,15 +443,36 @@
 #define        MFREE(m, n)                                                     \
        MBUFLOCK(                                                       \
                mbstat.m_mtypes[(m)->m_type]--;                         \
-               if (((m)->m_flags & M_PKTHDR) != 0 && (m)->m_pkthdr.aux) { \
+               if (((m)->m_flags & M_PKTHDR) != 0 &&                   \
+                   (m)->m_pkthdr.aux != NULL) {                        \
                        m_freem((m)->m_pkthdr.aux);                     \
                        (m)->m_pkthdr.aux = NULL;                       \
                }                                                       \
+               (n) = (m)->m_next;                                      \
                if ((m)->m_flags & M_EXT) {                             \
-                       _MEXTREMOVE((m));                               \
-               }                                                       \
-               (n) = (m)->m_next;                                      \
-               pool_cache_put(&mbpool_cache, (m));                     \
+                       if (MCLISREFERENCED(m)) {                       \
+                               _MCLDEREFERENCE(m);                     \
+                               pool_cache_put(&mbpool_cache, (m));     \
+                       } else if ((m)->m_flags & M_CLUSTER) {          \
+                               pool_cache_put(&mclpool_cache,          \
+                                   (m)->m_ext.ext_buf);                \
+                               pool_cache_put(&mbpool_cache, (m));     \
+                       } else if ((m)->m_ext.ext_free) {               \
+                               /*                                      \
+                                * (*ext_free)() is responsible for     \
+                                * freeing the mbuf when it is safe.    \
+                                */                                     \
+                               (*((m)->m_ext.ext_free))((m),           \
+                                   (m)->m_ext.ext_buf,                 \
+                                   (m)->m_ext.ext_size,                \
+                                   (m)->m_ext.ext_arg);                \
+                       } else {                                        \
+                               free((m)->m_ext.ext_buf,                \
+                                   (m)->m_ext.ext_type);               \
+                               pool_cache_put(&mbpool_cache, (m));     \
+                       }                                               \
+               } else                                                  \
+                       pool_cache_put(&mbpool_cache, (m));             \
        )
 
 /*



Home | Main Index | Thread Index | Old Index