Source-Changes-HG archive

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

[src/trunk]: src/sys/kern Move initialization of pool_allocator_lock before i...



details:   https://anonhg.NetBSD.org/src/rev/3b0780b36cf9
branches:  trunk
changeset: 750480:3b0780b36cf9
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Sat Jan 02 15:20:39 2010 +0000

description:
Move initialization of pool_allocator_lock before its first use.
This failed on archs where a mutex isn't initialized to a zero
value.

Defer allocation of pool log to the logging action, if allocation
fails, it will be retried the next time something is logged.

Clear pool log on allocation so that ddb doesn't crash when showing
so far unused log entries.

diffstat:

 sys/kern/subr_pool.c |  38 +++++++++++++++++++++-----------------
 1 files changed, 21 insertions(+), 17 deletions(-)

diffs (104 lines):

diff -r b25628cac1e7 -r 3b0780b36cf9 sys/kern/subr_pool.c
--- a/sys/kern/subr_pool.c      Sat Jan 02 10:57:35 2010 +0000
+++ b/sys/kern/subr_pool.c      Sat Jan 02 15:20:39 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_pool.c,v 1.178 2009/12/30 18:57:17 elad Exp $     */
+/*     $NetBSD: subr_pool.c,v 1.179 2010/01/02 15:20:39 mlelstv Exp $  */
 
 /*-
  * Copyright (c) 1997, 1999, 2000, 2002, 2007, 2008 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.178 2009/12/30 18:57:17 elad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.179 2010/01/02 15:20:39 mlelstv Exp $");
 
 #include "opt_ddb.h"
 #include "opt_pool.h"
@@ -234,16 +234,28 @@
 static inline void
 pr_log(struct pool *pp, void *v, int action, const char *file, long line)
 {
-       int n = pp->pr_curlogentry;
+       int n;
        struct pool_log *pl;
 
        if ((pp->pr_roflags & PR_LOGGING) == 0)
                return;
 
+       if (pp->pr_log == NULL) {
+               if (kmem_map != NULL)
+                       pp->pr_log = malloc(
+                               pool_logsize * sizeof(struct pool_log),
+                               M_TEMP, M_NOWAIT | M_ZERO);
+               if (pp->pr_log == NULL)
+                       return;
+               pp->pr_curlogentry = 0;
+               pp->pr_logsize = pool_logsize;
+       }
+
        /*
         * Fill in the current entry. Wrap around and overwrite
         * the oldest entry if necessary.
         */
+       n = pp->pr_curlogentry;
        pl = &pp->pr_log[n];
        pl->pl_file = file;
        pl->pl_line = line;
@@ -261,7 +273,7 @@
        int i = pp->pr_logsize;
        int n = pp->pr_curlogentry;
 
-       if ((pp->pr_roflags & PR_LOGGING) == 0)
+       if (pp->pr_log == NULL)
                return;
 
        /*
@@ -593,6 +605,7 @@
        struct pool_allocator *pa;
 
        mutex_init(&pool_head_lock, MUTEX_DEFAULT, IPL_NONE);
+       mutex_init(&pool_allocator_lock, MUTEX_DEFAULT, IPL_NONE);
        cv_init(&pool_busy, "poolbusy");
 
        while ((pa = SLIST_FIRST(&pa_deferinitq)) != NULL) {
@@ -607,8 +620,6 @@
 
        pool_init(&cache_cpu_pool, sizeof(pool_cache_cpu_t), coherency_unit,
            0, 0, "pcachecpu", &pool_allocator_nointr, IPL_NONE);
-
-       mutex_init(&pool_allocator_lock, MUTEX_DEFAULT, IPL_NONE);
 }
 
 /*
@@ -793,16 +804,7 @@
        pp->pr_nidle = 0;
        pp->pr_refcnt = 0;
 
-#ifdef POOL_DIAGNOSTIC
-       if (flags & PR_LOGGING) {
-               if (kmem_map == NULL ||
-                   (pp->pr_log = malloc(pool_logsize * sizeof(struct pool_log),
-                    M_TEMP, M_NOWAIT)) == NULL)
-                       pp->pr_roflags &= ~PR_LOGGING;
-               pp->pr_curlogentry = 0;
-               pp->pr_logsize = pool_logsize;
-       }
-#endif
+       pp->pr_log = NULL;
 
        pp->pr_entered_file = NULL;
        pp->pr_entered_line = 0;
@@ -928,8 +930,10 @@
        pr_pagelist_free(pp, &pq);
 
 #ifdef POOL_DIAGNOSTIC
-       if ((pp->pr_roflags & PR_LOGGING) != 0)
+       if (pp->pr_log != NULL) {
                free(pp->pr_log, M_TEMP);
+               pp->pr_log = NULL;
+       }
 #endif
 
        cv_destroy(&pp->pr_cv);



Home | Main Index | Thread Index | Old Index