Source-Changes-HG archive

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

[src/trunk]: src/sys/kern crashme(9): New debug.crashme.mutex_recursion method.



details:   https://anonhg.NetBSD.org/src/rev/4cf9ca7d9110
branches:  trunk
changeset: 369772:4cf9ca7d9110
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Tue Aug 30 22:38:26 2022 +0000

description:
crashme(9): New debug.crashme.mutex_recursion method.

Takes a lock twice.  Set it to 1 for adaptive lock, 2 for spin lock.

diffstat:

 sys/kern/kern_crashme.c |  38 +++++++++++++++++++++++++++++++++++++-
 1 files changed, 37 insertions(+), 1 deletions(-)

diffs (63 lines):

diff -r cb5f4d78d3ea -r 4cf9ca7d9110 sys/kern/kern_crashme.c
--- a/sys/kern/kern_crashme.c   Tue Aug 30 22:38:17 2022 +0000
+++ b/sys/kern/kern_crashme.c   Tue Aug 30 22:38:26 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_crashme.c,v 1.6 2022/08/16 10:24:17 riastradh Exp $       */
+/*     $NetBSD: kern_crashme.c,v 1.7 2022/08/30 22:38:26 riastradh Exp $       */
 
 /*
  * Copyright (c) 2018, 2019 Matthew R. Green
@@ -66,6 +66,7 @@
 #ifdef LOCKDEBUG
 static int crashme_kernel_lock_spinout(int);
 #endif
+static int crashme_mutex_recursion(int);
 
 #define CMNODE(name, lname, func)      \
     {                                  \
@@ -85,6 +86,8 @@
     CMNODE("kernel_lock_spinout", "infinite kernel lock",
        crashme_kernel_lock_spinout),
 #endif
+    CMNODE("mutex_recursion", "enter the same mutex twice",
+       crashme_mutex_recursion),
 };
 static crashme_node *first_node;
 static kmutex_t crashme_lock;
@@ -290,3 +293,36 @@
        return 0;
 }
 #endif
+
+static int
+crashme_mutex_recursion(int flags)
+{
+       kmutex_t crashme_spinlock;
+
+       switch (flags) {
+       case 0:
+               return 0;
+       case 1:
+       default:
+               /*
+                * printf makes the return address of the first
+                * mutex_enter call a little more obvious, so the line
+                * number of the _return address_ for the first
+                * mutex_enter doesn't confusingly point at the second
+                * mutex_enter.
+                */
+               mutex_enter(&crashme_lock);
+               printf("%s: locked once\n", __func__);
+               mutex_enter(&crashme_lock);
+               printf("%s: locked twice\n", __func__);
+               return -1;
+       case 2:
+               mutex_init(&crashme_spinlock, MUTEX_DEFAULT, IPL_VM);
+               printf("%s: initialized\n", __func__);
+               mutex_enter(&crashme_spinlock);
+               printf("%s: locked once\n", __func__);
+               mutex_enter(&crashme_spinlock);
+               printf("%s: locked twice\n", __func__);
+               return -1;
+       }
+}



Home | Main Index | Thread Index | Old Index