Source-Changes-HG archive

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

[src/trunk]: src/sys Add a simple_lock_only_held() LOCKDEBUG routine, which a...



details:   https://anonhg.NetBSD.org/src/rev/1528f2fc95a6
branches:  trunk
changeset: 510706:1528f2fc95a6
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Tue Jun 05 04:38:08 2001 +0000

description:
Add a simple_lock_only_held() LOCKDEBUG routine, which allows code
to assert that exactly zero or one (and a specific one) locks are
held.

>From Bill Sommerfeld.

diffstat:

 sys/kern/kern_lock.c |  54 ++++++++++++++++++++++++++++++++++++---------------
 sys/sys/lock.h       |   5 +++-
 2 files changed, 42 insertions(+), 17 deletions(-)

diffs (122 lines):

diff -r 3c64e2a71a23 -r 1528f2fc95a6 sys/kern/kern_lock.c
--- a/sys/kern/kern_lock.c      Tue Jun 05 02:31:16 2001 +0000
+++ b/sys/kern/kern_lock.c      Tue Jun 05 04:38:08 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_lock.c,v 1.54 2001/05/01 04:30:04 enami Exp $     */
+/*     $NetBSD: kern_lock.c,v 1.55 2001/06/05 04:38:09 thorpej Exp $   */
 
 /*-
  * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
@@ -101,7 +101,14 @@
 void   lock_printf(const char *fmt, ...)
     __attribute__((__format__(__printf__,1,2)));
 
-int    lock_debug_syslog = 1;  /* defaults to syslog, but can be patched */
+int    lock_debug_syslog = 0;  /* defaults to syslog, but can be patched */
+
+#ifdef DDB
+#include <ddb/ddbvar.h>
+#include <machine/db_machdep.h>
+#include <ddb/db_command.h>
+#include <ddb/db_interface.h>
+#endif
 #endif
 
 /*
@@ -1217,34 +1224,49 @@
        splx(s);
 }
 
+/*
+ * We must be holding exactly one lock: the sched_lock.
+ */
+
 void
 simple_lock_switchcheck(void)
 {
+
+       simple_lock_only_held(&sched_lock, "switching");
+}
+
+void
+simple_lock_only_held(volatile struct simplelock *lp, const char *where)
+{
        struct simplelock *alp;
        cpuid_t cpu_id = cpu_number();
        int s;
 
-       /*
-        * We must be holding exactly one lock: the sched_lock.
-        */
-
-       SCHED_ASSERT_LOCKED();
-
+       if (lp) {
+               LOCK_ASSERT(simple_lock_held(lp));
+       }
        s = spllock();
        SLOCK_LIST_LOCK();
        for (alp = TAILQ_FIRST(&simplelock_list); alp != NULL;
             alp = TAILQ_NEXT(alp, list)) {
-               if (alp == &sched_lock)
+               if (alp == lp)
                        continue;
-               if (alp->lock_holder == cpu_id) {
-                       lock_printf("switching with held simple_lock %p "
-                           "CPU %lu %s:%d\n",
-                           alp, alp->lock_holder, alp->lock_file,
-                           alp->lock_line);
-                       SLOCK_DEBUGGER();
-               }
+               if (alp->lock_holder == cpu_id)
+                       break;
        }
        SLOCK_LIST_UNLOCK();
        splx(s);
+
+       if (alp != NULL) {
+               lock_printf("%s with held simple_lock %p "
+                   "CPU %lu %s:%d\n",
+                   where, alp, alp->lock_holder, alp->lock_file,
+                   alp->lock_line);
+#ifdef DDB
+               db_stack_trace_print((db_expr_t)__builtin_frame_address(0),
+                   TRUE, 65535, "", printf);
+#endif
+               SLOCK_DEBUGGER();
+       }
 }
 #endif /* LOCKDEBUG */ /* } */
diff -r 3c64e2a71a23 -r 1528f2fc95a6 sys/sys/lock.h
--- a/sys/sys/lock.h    Tue Jun 05 02:31:16 2001 +0000
+++ b/sys/sys/lock.h    Tue Jun 05 04:38:08 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lock.h,v 1.44 2001/05/30 12:07:05 mrg Exp $    */
+/*     $NetBSD: lock.h,v 1.45 2001/06/05 04:38:08 thorpej Exp $        */
 
 /*-
  * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
@@ -318,6 +318,7 @@
 int    _simple_lock_try(__volatile struct simplelock *, const char *, int);
 void   _simple_unlock(__volatile struct simplelock *, const char *, int);
 int    _simple_lock_held(__volatile struct simplelock *);
+void   simple_lock_only_held(__volatile struct simplelock *, const char *);
 
 #define        simple_lock(alp)        _simple_lock((alp), __FILE__, __LINE__)
 #define        simple_lock_try(alp)    _simple_lock_try((alp), __FILE__, __LINE__)
@@ -336,6 +337,7 @@
 #define        simple_lock_try(alp)    __cpu_simple_lock_try(&(alp)->lock_data)
 #define        simple_unlock(alp)      __cpu_simple_unlock(&(alp)->lock_data)
 #define        LOCK_ASSERT(x)          /* nothing */
+#define        simple_lock_only_held(x,y)              /* nothing */
 #else
 #define        simple_lock_init(alp)   (alp)->lock_data = __SIMPLELOCK_UNLOCKED
 #define        simple_lock_try(alp)    (1)
@@ -345,6 +347,7 @@
 #else /* lint */
 #define        simple_lock(alp)        /* nothing */
 #define        simple_unlock(alp)      /* nothing */
+#define        simple_lock_only_held(x,y)              /* nothing */
 #endif /* lint */
 #define        LOCK_ASSERT(x)          /* nothing */
 #endif



Home | Main Index | Thread Index | Old Index