Module Name:    src
Committed By:   mlelstv
Date:           Sat Jan  2 15:20:39 UTC 2010

Modified Files:
        src/sys/kern: subr_pool.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.178 -r1.179 src/sys/kern/subr_pool.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/subr_pool.c
diff -u src/sys/kern/subr_pool.c:1.178 src/sys/kern/subr_pool.c:1.179
--- src/sys/kern/subr_pool.c:1.178	Wed Dec 30 18:57:17 2009
+++ src/sys/kern/subr_pool.c	Sat Jan  2 15:20:39 2010
@@ -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);

Reply via email to