Source-Changes-HG archive

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

[src/trunk]: src/sys Improve the pool allocator's diagnostic helpers, adding ...



details:   https://anonhg.NetBSD.org/src/rev/4d05f2891fad
branches:  trunk
changeset: 472868:4d05f2891fad
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Mon May 10 21:13:05 1999 +0000

description:
Improve the pool allocator's diagnostic helpers, adding the ability to
log on a per-pool basis, reentrancy checking, and dumping various pool
information from DDB.

diffstat:

 sys/ddb/db_command.c |   16 ++-
 sys/ddb/db_command.h |    3 +-
 sys/kern/subr_pool.c |  310 ++++++++++++++++++++++++++++++++++++++------------
 sys/sys/pool.h       |   34 +++--
 4 files changed, 268 insertions(+), 95 deletions(-)

diffs (truncated from 772 to 300 lines):

diff -r fe904420c77e -r 4d05f2891fad sys/ddb/db_command.c
--- a/sys/ddb/db_command.c      Mon May 10 19:34:22 1999 +0000
+++ b/sys/ddb/db_command.c      Mon May 10 21:13:05 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: db_command.c,v 1.30 1999/04/12 20:38:20 pk Exp $       */
+/*     $NetBSD: db_command.c,v 1.31 1999/05/10 21:13:05 thorpej Exp $  */
 
 /* 
  * Mach Operating System
@@ -35,6 +35,7 @@
 #include <sys/systm.h>
 #include <sys/reboot.h>
 #include <sys/proc.h>
+#include <sys/pool.h>
 
 #include <machine/db_machdep.h>                /* type definitions */
 
@@ -338,6 +339,18 @@
        uvm_page_printit((struct vm_page *) addr, full, db_printf);
 }
 
+/*ARGSUSED*/
+void
+db_pool_print_cmd(addr, have_addr, count, modif)
+       db_expr_t       addr;
+       int             have_addr;
+       db_expr_t       count;
+       char *          modif;
+{
+
+       pool_printit((struct pool *) addr, modif, db_printf);
+}
+
 /*
  * 'show' commands
  */
@@ -356,6 +369,7 @@
        { "map",        db_map_print_cmd,       0,      NULL },
        { "object",     db_object_print_cmd,    0,      NULL },
        { "page",       db_page_print_cmd,      0,      NULL },
+       { "pool",       db_pool_print_cmd,      0,      NULL },
        { NULL,         NULL,                   0,      NULL, }
 };
 
diff -r fe904420c77e -r 4d05f2891fad sys/ddb/db_command.h
--- a/sys/ddb/db_command.h      Mon May 10 19:34:22 1999 +0000
+++ b/sys/ddb/db_command.h      Mon May 10 21:13:05 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: db_command.h,v 1.12 1999/04/12 20:38:21 pk Exp $       */
+/*     $NetBSD: db_command.h,v 1.13 1999/05/10 21:13:05 thorpej Exp $  */
 
 /* 
  * Mach Operating System
@@ -40,6 +40,7 @@
 void db_map_print_cmd __P((db_expr_t, int, db_expr_t, char *));
 void db_object_print_cmd __P((db_expr_t, int, db_expr_t, char *));
 void db_page_print_cmd __P((db_expr_t, int, db_expr_t, char *));
+void db_pool_print_cmd __P((db_expr_t, int, db_expr_t, char *));
 void db_machine_commands_install __P((struct db_command *));
 void db_help_cmd __P((void));
 void db_command_loop __P((void));
diff -r fe904420c77e -r 4d05f2891fad sys/kern/subr_pool.c
--- a/sys/kern/subr_pool.c      Mon May 10 19:34:22 1999 +0000
+++ b/sys/kern/subr_pool.c      Mon May 10 21:13:05 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_pool.c,v 1.24 1999/04/29 17:47:19 scottr Exp $    */
+/*     $NetBSD: subr_pool.c,v 1.25 1999/05/10 21:13:05 thorpej Exp $   */
 
 /*-
  * Copyright (c) 1997, 1999 The NetBSD Foundation, Inc.
@@ -37,6 +37,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include "opt_pool.h"
 #include "opt_poollog.h"
 
 #include <sys/param.h>
@@ -95,14 +96,14 @@
 struct pool_item {
 #ifdef DIAGNOSTIC
        int pi_magic;
-#define PI_MAGIC 0xdeadbeef
+#define        PI_MAGIC 0xdeadbeef
 #endif
        /* Other entries use only this list entry */
        TAILQ_ENTRY(pool_item)  pi_list;
 };
 
 
-#define PR_HASH_INDEX(pp,addr) \
+#define        PR_HASH_INDEX(pp,addr) \
        (((u_long)(addr) >> (pp)->pr_pageshift) & (PR_HASHTABSIZE - 1))
 
 
@@ -115,11 +116,9 @@
 static void    *pool_page_alloc __P((unsigned long, int, int));
 static void    pool_page_free __P((void *, unsigned long, int));
 
-#if defined(POOL_DIAGNOSTIC) || defined(DEBUG)
-static void pool_print1 __P((struct pool *, const char *));
-#endif
+static void pool_print1 __P((struct pool *, const char *,
+       void (*)(const char *, ...)));
 
-#ifdef POOL_DIAGNOSTIC
 /*
  * Pool log entry. An array of these is allocated in pool_create().
  */
@@ -127,8 +126,8 @@
        const char      *pl_file;
        long            pl_line;
        int             pl_action;
-#define PRLOG_GET      1
-#define PRLOG_PUT      2
+#define        PRLOG_GET       1
+#define        PRLOG_PUT       2
        void            *pl_addr;
 };
 
@@ -139,8 +138,14 @@
 
 int pool_logsize = POOL_LOGSIZE;
 
+#ifdef DIAGNOSTIC
 static void    pr_log __P((struct pool *, void *, int, const char *, long));
-static void    pr_printlog __P((struct pool *));
+static void    pr_printlog __P((struct pool *, struct pool_item *,
+                   void (*)(const char *, ...)));
+static void    pr_enter __P((struct pool *, const char *, long));
+static void    pr_leave __P((struct pool *));
+static void    pr_enter_check __P((struct pool *,
+                   void (*)(const char *, ...)));
 
 static __inline__ void
 pr_log(pp, v, action, file, line)
@@ -171,8 +176,10 @@
 }
 
 static void
-pr_printlog(pp)
+pr_printlog(pp, pi, pr)
        struct pool *pp;
+       struct pool_item *pi;
+       void (*pr) __P((const char *, ...));
 {
        int i = pp->pr_logsize;
        int n = pp->pr_curlogentry;
@@ -180,30 +187,76 @@
        if ((pp->pr_roflags & PR_LOGGING) == 0)
                return;
 
-       pool_print1(pp, "printlog");
-
        /*
         * Print all entries in this pool's log.
         */
        while (i-- > 0) {
                struct pool_log *pl = &pp->pr_log[n];
                if (pl->pl_action != 0) {
-                       printf("log entry %d:\n", i);
-                       printf("\taction = %s, addr = %p\n",
-                               pl->pl_action == PRLOG_GET ? "get" : "put",
-                               pl->pl_addr);
-                       printf("\tfile: %s at line %lu\n",
-                               pl->pl_file, pl->pl_line);
+                       if (pi == NULL || pi == pl->pl_addr) {
+                               (*pr)("\tlog entry %d:\n", i);
+                               (*pr)("\t\taction = %s, addr = %p\n",
+                                   pl->pl_action == PRLOG_GET ? "get" : "put",
+                                   pl->pl_addr);
+                               (*pr)("\t\tfile: %s at line %lu\n",
+                                   pl->pl_file, pl->pl_line);
+                       }
                }
                if (++n >= pp->pr_logsize)
                        n = 0;
        }
 }
+
+static __inline__ void
+pr_enter(pp, file, line)
+       struct pool *pp;
+       const char *file;
+       long line;
+{
+
+       if (pp->pr_entered_file != NULL) {
+               printf("pool %s: reentrancy at file %s line %ld\n",
+                   pp->pr_wchan, file, line);
+               printf("         previous entry at file %s line %ld\n",
+                   pp->pr_entered_file, pp->pr_entered_line);
+               panic("pr_enter");
+       }
+
+       pp->pr_entered_file = file;
+       pp->pr_entered_line = line;
+}
+
+static __inline__ void
+pr_leave(pp)
+       struct pool *pp;
+{
+
+       if (pp->pr_entered_file == NULL) {
+               printf("pool %s not entered?\n", pp->pr_wchan);
+               panic("pr_leave");
+       }
+
+       pp->pr_entered_file = NULL;
+       pp->pr_entered_line = 0;
+}
+
+static __inline__ void
+pr_enter_check(pp, pr)
+       struct pool *pp;
+       void (*pr) __P((const char *, ...));
+{
+
+       if (pp->pr_entered_file != NULL)
+               (*pr)("\n\tcurrently entered from file %s line %ld\n",
+                   pp->pr_entered_file, pp->pr_entered_line);
+}
 #else
-#define pr_log(pp, v, action, file, line)
-#define pr_printlog(pp)
-#endif
-
+#define        pr_log(pp, v, action, file, line)
+#define        pr_printlog(pp, pi, pr)
+#define        pr_enter(pp, file, line)
+#define        pr_leave(pp)
+#define        pr_enter_check(pp, pr)
+#endif /* DIAGNOSTIC */
 
 /*
  * Return the pool page header based on page address.
@@ -302,11 +355,6 @@
                return (NULL);
 
        flags = PR_FREEHEADER;
-#ifdef POOL_DIAGNOSTIC
-       if (pool_logsize != 0)
-               flags |= PR_LOGGING;
-#endif
-
        pool_init(pp, size, align, ioff, flags, wchan, pagesz,
                  alloc, release, mtype);
 
@@ -341,6 +389,14 @@
 {
        int off, slack, i;
 
+#ifdef POOL_DIAGNOSTIC
+       /*
+        * Always log if POOL_DIAGNOSTIC is defined.
+        */
+       if (pool_logsize != 0)
+               flags |= PR_LOGGING;
+#endif
+
        /*
         * Check arguments and construct default values.
         */
@@ -440,16 +496,17 @@
        pp->pr_hiwat = 0;
        pp->pr_nidle = 0;
 
-#ifdef POOL_DIAGNOSTIC
-       if ((flags & PR_LOGGING) != 0) {
-               pp->pr_log = malloc(pool_logsize * sizeof(struct pool_log),
-                                   M_TEMP, M_NOWAIT);
-               if (pp->pr_log == NULL)
+       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_entered_file = NULL;
+       pp->pr_entered_line = 0;
 
        simple_lock_init(&pp->pr_slock);
 
@@ -479,7 +536,7 @@
 
 #ifdef DIAGNOSTIC
        if (pp->pr_nout != 0) {
-               pr_printlog(pp);
+               pr_printlog(pp, NULL, printf);
                panic("pool_destroy: pool busy: still out: %u\n",
                    pp->pr_nout);
        }
@@ -497,10 +554,8 @@
        drainpp = NULL;
        simple_unlock(&pool_head_slock);



Home | Main Index | Thread Index | Old Index