Source-Changes-HG archive

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

[src/trunk]: src Wipe out the last vestiges of POOL_INIT with one swift strok...



details:   https://anonhg.NetBSD.org/src/rev/dac30b05afdf
branches:  trunk
changeset: 747397:dac30b05afdf
user:      pooka <pooka%NetBSD.org@localhost>
date:      Sun Sep 13 18:45:10 2009 +0000

description:
Wipe out the last vestiges of POOL_INIT with one swift stroke.  In
most cases, use a proper constructor.  For proplib, give a local
equivalent of POOL_INIT for the kernel object implementation.  This
way the code structure can be preserved, and a local link set is
not hazardous anyway (unless proplib is split to several modules,
but that'll be the day).

tested by booting a kernel in qemu and compile-testing i386/ALL

diffstat:

 common/include/prop/proplib.h         |   6 +++++-
 common/lib/libprop/prop_kern.c        |  17 ++++++++++++++++-
 common/lib/libprop/prop_object_impl.h |  15 ++++++++++++---
 sys/compat/sa/compat_sa.c             |  30 ++++++++++++++++++++----------
 sys/dev/ata/ata.c                     |  20 ++++++++++++++++----
 sys/dev/rnd.c                         |  22 ++++++++++++++++++----
 sys/kern/init_main.c                  |  15 +++++++++++++--
 sys/kern/kern_lwp.c                   |   9 +++++----
 sys/kern/kern_malloc.c                |   8 ++++++--
 sys/kern/kern_malloc_debug.c          |  15 +++++++++++----
 sys/kern/kern_time.c                  |  14 +++++++-------
 sys/kern/subr_pool.c                  |  11 ++---------
 sys/netbt/bt_proto.c                  |   6 ++++--
 sys/netbt/l2cap.h                     |   5 +++--
 sys/netbt/l2cap_misc.c                |  19 +++++++++++++------
 sys/netbt/rfcomm.h                    |   5 +++--
 sys/netbt/rfcomm_session.c            |  15 +++++++++++----
 sys/netinet/igmp.c                    |   9 +++++----
 sys/sys/malloc.h                      |   3 ++-
 sys/sys/pool.h                        |  19 +------------------
 sys/sys/savar.h                       |   4 +++-
 sys/uvm/uvm_aobj.c                    |   9 +++++----
 sys/uvm/uvm_swap.c                    |  14 ++++++++------
 23 files changed, 189 insertions(+), 101 deletions(-)

diffs (truncated from 897 to 300 lines):

diff -r f5a63d252c44 -r dac30b05afdf common/include/prop/proplib.h
--- a/common/include/prop/proplib.h     Sun Sep 13 18:39:20 2009 +0000
+++ b/common/include/prop/proplib.h     Sun Sep 13 18:45:10 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: proplib.h,v 1.6 2008/04/28 20:22:51 martin Exp $       */
+/*     $NetBSD: proplib.h,v 1.7 2009/09/13 18:45:10 pooka Exp $        */
 
 /*-
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -43,4 +43,8 @@
 
 #include <prop/plistref.h>
 
+#ifdef _KERNEL
+void   prop_kern_init(void);
+#endif
+
 #endif /* _PROPLIB_PROPLIB_H_ */
diff -r f5a63d252c44 -r dac30b05afdf common/lib/libprop/prop_kern.c
--- a/common/lib/libprop/prop_kern.c    Sun Sep 13 18:39:20 2009 +0000
+++ b/common/lib/libprop/prop_kern.c    Sun Sep 13 18:45:10 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: prop_kern.c,v 1.9 2008/04/28 20:22:53 martin Exp $     */
+/*     $NetBSD: prop_kern.c,v 1.10 2009/09/13 18:45:10 pooka Exp $     */
 
 /*-
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -224,12 +224,27 @@
 #include <sys/systm.h>
 #include <sys/proc.h>
 #include <sys/resource.h>
+#include <sys/pool.h>
 
 #include <uvm/uvm.h>
 
+#include "prop_object_impl.h"
+
 /* Arbitrary limit ioctl input to 64KB */
 unsigned int prop_object_copyin_limit = 65536;
 
+/* initialize proplib for use in the kernel */
+void
+prop_kern_init(void)
+{
+       __link_set_decl(prop_linkpools, struct prop_pool_init);
+       struct prop_pool_init * const *pi;
+
+       __link_set_foreach(pi, prop_linkpools)
+               pool_init((*pi)->pp, (*pi)->size, 0, 0, 0, (*pi)->wchan,
+                   &pool_allocator_nointr, IPL_NONE);
+}
+
 static int
 _prop_object_copyin_ioctl(const struct plistref *pref, const prop_type_t type,
                          const u_long cmd, prop_object_t *objp)
diff -r f5a63d252c44 -r dac30b05afdf common/lib/libprop/prop_object_impl.h
--- a/common/lib/libprop/prop_object_impl.h     Sun Sep 13 18:39:20 2009 +0000
+++ b/common/lib/libprop/prop_object_impl.h     Sun Sep 13 18:45:10 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: prop_object_impl.h,v 1.29 2009/01/03 18:31:34 pooka Exp $      */
+/*     $NetBSD: prop_object_impl.h,v 1.30 2009/09/13 18:45:10 pooka Exp $      */
 
 /*-
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -263,8 +263,17 @@
 #define        _PROP_POOL_GET(p)               pool_get(&(p), PR_WAITOK)
 #define        _PROP_POOL_PUT(p, v)            pool_put(&(p), (v))
 
-#define        _PROP_POOL_INIT(p, s, d)                                        \
-               POOL_INIT(p, s, 0, 0, 0, d, &pool_allocator_nointr, IPL_NONE);
+struct prop_pool_init {
+       struct pool *pp;
+       size_t size;
+       const char *wchan;
+};
+#define        _PROP_POOL_INIT(pp, size, wchan)                                \
+struct pool pp;                                                                \
+static const struct prop_pool_init _link_ ## pp[1] = {                 \
+       { &pp, size, wchan }                                            \
+};                                                                     \
+__link_set_add_rodata(prop_linkpools, _link_ ## pp);
 
 #define        _PROP_MALLOC_DEFINE(t, s, l)                                    \
                MALLOC_DEFINE(t, s, l);
diff -r f5a63d252c44 -r dac30b05afdf sys/compat/sa/compat_sa.c
--- a/sys/compat/sa/compat_sa.c Sun Sep 13 18:39:20 2009 +0000
+++ b/sys/compat/sa/compat_sa.c Sun Sep 13 18:45:10 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: compat_sa.c,v 1.10 2009/04/16 07:42:28 skrll Exp $     */
+/*     $NetBSD: compat_sa.c,v 1.11 2009/09/13 18:45:10 pooka Exp $     */
 
 /*-
  * Copyright (c) 2001, 2004, 2005, 2006 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
 #include "opt_ktrace.h"
 #include "opt_multiprocessor.h"
 #include "opt_sa.h"
-__KERNEL_RCSID(0, "$NetBSD: compat_sa.c,v 1.10 2009/04/16 07:42:28 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: compat_sa.c,v 1.11 2009/09/13 18:45:10 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -82,26 +82,22 @@
 /*
  * memory pool for sadata structures
  */
-static POOL_INIT(sadata_pool, sizeof(struct sadata), 0, 0, 0, "sadatapl",
-    &pool_allocator_nointr, IPL_NONE);
+static struct pool sadata_pool;
 
 /*
  * memory pool for pending upcalls
  */
-static POOL_INIT(saupcall_pool, sizeof(struct sadata_upcall), 0, 0, 0,
-    "saupcpl", &pool_allocator_nointr, IPL_NONE);
+static struct pool saupcall_pool;
 
 /*
  * memory pool for sastack structs
  */
-static POOL_INIT(sastack_pool, sizeof(struct sastack), 0, 0, 0, "sastackpl",
-    &pool_allocator_nointr, IPL_NONE);
+static struct pool sastack_pool;
 
 /*
  * memory pool for sadata_vp structures
  */
-static POOL_INIT(savp_pool, sizeof(struct sadata_vp), 0, 0, 0, "savppl",
-    &pool_allocator_nointr, IPL_NONE);
+static struct pool savp_pool;
 
 static struct sadata_vp *sa_newsavp(struct proc *);
 static void sa_freevp(struct proc *, struct sadata *, struct sadata_vp *);
@@ -165,6 +161,20 @@
 kmutex_t       saupcall_mutex;
 SIMPLEQ_HEAD(, sadata_upcall) saupcall_freelist;
 
+void
+sa_init(void)
+{
+
+       pool_init(&sadata_pool, sizeof(struct sadata), 0, 0, 0, "sadatapl",
+           &pool_allocator_nointr, IPL_NONE);
+       pool_init(&saupcall_pool, sizeof(struct sadata_upcall), 0, 0, 0,
+           "saupcpl", &pool_allocator_nointr, IPL_NONE);
+       pool_init(&sastack_pool, sizeof(struct sastack), 0, 0, 0, "sastackpl",
+           &pool_allocator_nointr, IPL_NONE);
+       pool_init(&savp_pool, sizeof(struct sadata_vp), 0, 0, 0, "savppl",
+           &pool_allocator_nointr, IPL_NONE);
+}
+
 /*
  * sa_critpath API
  * permit other parts of the kernel to make SA_LWP_STATE_{UN,}LOCK calls.
diff -r f5a63d252c44 -r dac30b05afdf sys/dev/ata/ata.c
--- a/sys/dev/ata/ata.c Sun Sep 13 18:39:20 2009 +0000
+++ b/sys/dev/ata/ata.c Sun Sep 13 18:45:10 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ata.c,v 1.106 2009/05/12 12:10:29 cegger Exp $ */
+/*     $NetBSD: ata.c,v 1.107 2009/09/13 18:45:10 pooka Exp $  */
 
 /*
  * Copyright (c) 1998, 2001 Manuel Bouyer.  All rights reserved.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ata.c,v 1.106 2009/05/12 12:10:29 cegger Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ata.c,v 1.107 2009/09/13 18:45:10 pooka Exp $");
 
 #include "opt_ata.h"
 
@@ -50,6 +50,7 @@
 #include <sys/simplelock.h>
 #include <sys/intr.h>
 #include <sys/bus.h>
+#include <sys/once.h>
 
 #include <dev/ata/ataconf.h>
 #include <dev/ata/atareg.h>
@@ -78,8 +79,7 @@
 #define ATADEBUG_PRINT(args, level)
 #endif
 
-POOL_INIT(ata_xfer_pool, sizeof(struct ata_xfer), 0, 0, 0, "ataspl", NULL,
-    IPL_BIO);
+static struct pool ata_xfer_pool;
 
 /*
  * A queue of atabus instances, used to ensure the same bus probe order
@@ -429,6 +429,15 @@
        return (1);
 }
 
+static int
+atabus_xferpool_init(void)
+{
+
+       pool_init(&ata_xfer_pool, sizeof(struct ata_xfer), 0, 0, 0, "ataspl",
+           NULL, IPL_BIO);
+       return 0;
+}
+
 /*
  * atabus_attach:
  *
@@ -440,6 +449,7 @@
        struct atabus_softc *sc = device_private(self);
        struct ata_channel *chp = aux;
        struct atabus_initq *initq;
+       static ONCE_DECL(poolinit_ctrl);
        int error;
 
        sc->sc_chan = chp;
@@ -452,6 +462,8 @@
        if (ata_addref(chp))
                return;
 
+       RUN_ONCE(&poolinit_ctrl, atabus_xferpool_init);
+
        initq = malloc(sizeof(*initq), M_DEVBUF, M_WAITOK);
        initq->atabus_sc = sc;
        TAILQ_INSERT_TAIL(&atabus_initq_head, initq, atabus_initq);
diff -r f5a63d252c44 -r dac30b05afdf sys/dev/rnd.c
--- a/sys/dev/rnd.c     Sun Sep 13 18:39:20 2009 +0000
+++ b/sys/dev/rnd.c     Sun Sep 13 18:45:10 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rnd.c,v 1.74 2009/09/08 20:57:59 pooka Exp $   */
+/*     $NetBSD: rnd.c,v 1.75 2009/09/13 18:45:10 pooka Exp $   */
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rnd.c,v 1.74 2009/09/08 20:57:59 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rnd.c,v 1.75 2009/09/13 18:45:10 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/ioctl.h>
@@ -49,6 +49,7 @@
 #include <sys/vnode.h>
 #include <sys/pool.h>
 #include <sys/kauth.h>
+#include <sys/once.h>
 
 #ifdef __HAVE_CPU_COUNTER
 #include <machine/cpu_counter.h>
@@ -117,8 +118,7 @@
 /*
  * Memory pool for sample buffers
  */
-POOL_INIT(rnd_mempool, sizeof(rnd_sample_t), 0, 0, 0, "rndsample", NULL,
-    IPL_VM);
+static struct pool rnd_mempool;
 
 /*
  * Our random pool.  This is defined here rather than using the general
@@ -268,6 +268,16 @@
        return (1);
 }
 
+static int
+rnd_mempool_init(void)
+{
+
+       pool_init(&rnd_mempool, sizeof(rnd_sample_t), 0, 0, 0, "rndsample",
+           NULL, IPL_VM);
+       return 0;
+}
+static ONCE_DECL(rnd_mempoolinit_ctrl);
+
 /*
  * "Attach" the random device. This is an (almost) empty stub, since
  * pseudo-devices don't get attached until after config, after the
@@ -279,6 +289,8 @@
 {
        u_int32_t c;
 
+       RUN_ONCE(&rnd_mempoolinit_ctrl, rnd_mempool_init);
+
        /* Trap unwary players who don't call rnd_init() early */
        KASSERT(rnd_ready);
 
@@ -816,6 +828,8 @@
 {
        u_int32_t ts;
 
+       RUN_ONCE(&rnd_mempoolinit_ctrl, rnd_mempool_init);
+
        ts = rnd_counter();
 
        strlcpy(rs->data.name, name, sizeof(rs->data.name));
diff -r f5a63d252c44 -r dac30b05afdf sys/kern/init_main.c
--- a/sys/kern/init_main.c      Sun Sep 13 18:39:20 2009 +0000
+++ b/sys/kern/init_main.c      Sun Sep 13 18:45:10 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: init_main.c,v 1.398 2009/09/03 15:20:08 pooka Exp $    */
+/*     $NetBSD: init_main.c,v 1.399 2009/09/13 18:45:10 pooka Exp $    */



Home | Main Index | Thread Index | Old Index