aboutsummaryrefslogtreecommitdiff
path: root/sys/kern/kern_mutex.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/kern/kern_mutex.c')
-rw-r--r--sys/kern/kern_mutex.c75
1 files changed, 73 insertions, 2 deletions
diff --git a/sys/kern/kern_mutex.c b/sys/kern/kern_mutex.c
index 874540de96a2..9f79ab40d507 100644
--- a/sys/kern/kern_mutex.c
+++ b/sys/kern/kern_mutex.c
@@ -89,16 +89,26 @@ __FBSDID("$FreeBSD$");
#define mtx_owner(m) (mtx_unowned((m)) ? NULL \
: (struct thread *)((m)->mtx_lock & MTX_FLAGMASK))
+#ifdef DDB
+static void db_show_mtx(struct lock_object *lock);
+#endif
+
/*
* Lock classes for sleep and spin mutexes.
*/
struct lock_class lock_class_mtx_sleep = {
"sleep mutex",
- LC_SLEEPLOCK | LC_RECURSABLE
+ LC_SLEEPLOCK | LC_RECURSABLE,
+#ifdef DDB
+ db_show_mtx
+#endif
};
struct lock_class lock_class_mtx_spin = {
"spin mutex",
- LC_SPINLOCK | LC_RECURSABLE
+ LC_SPINLOCK | LC_RECURSABLE,
+#ifdef DDB
+ db_show_mtx
+#endif
};
/*
@@ -905,3 +915,64 @@ mutex_init(void)
mtx_init(&devmtx, "cdev", NULL, MTX_DEF);
mtx_lock(&Giant);
}
+
+#ifdef DDB
+/* XXX: This function is not mutex-specific. */
+DB_SHOW_COMMAND(lock, db_show_lock)
+{
+ struct lock_object *lock;
+
+ if (!have_addr)
+ return;
+ lock = (struct lock_object *)addr;
+ if (lock->lo_class != &lock_class_mtx_sleep &&
+ lock->lo_class != &lock_class_mtx_spin &&
+ lock->lo_class != &lock_class_sx) {
+ db_printf("Unknown lock class\n");
+ return;
+ }
+ db_printf(" class: %s\n", lock->lo_class->lc_name);
+ db_printf(" name: %s\n", lock->lo_name);
+ if (lock->lo_type && lock->lo_type != lock->lo_name)
+ db_printf(" type: %s\n", lock->lo_type);
+ lock->lo_class->lc_ddb_show(lock);
+}
+
+void
+db_show_mtx(struct lock_object *lock)
+{
+ struct thread *td;
+ struct mtx *m;
+
+ m = (struct mtx *)lock;
+
+ db_printf(" flags: {");
+ if (m->mtx_object.lo_class == &lock_class_mtx_spin)
+ db_printf("SPIN");
+ else
+ db_printf("DEF");
+ if (m->mtx_object.lo_flags & LO_RECURSABLE)
+ db_printf(", RECURSE");
+ if (m->mtx_object.lo_flags & LO_DUPOK)
+ db_printf(", DUPOK");
+ db_printf("}\n");
+ db_printf(" state: {");
+ if (mtx_unowned(m))
+ db_printf("UNOWNED");
+ else {
+ db_printf("OWNED");
+ if (m->mtx_lock & MTX_CONTESTED)
+ db_printf(", CONTESTED");
+ if (m->mtx_lock & MTX_RECURSED)
+ db_printf(", RECURSED");
+ }
+ db_printf("}\n");
+ if (!mtx_unowned(m)) {
+ td = mtx_owner(m);
+ db_printf(" owner: %p (tid %d, pid %d, \"%s\")\n", td,
+ td->td_tid, td->td_proc->p_pid, td->td_proc->p_comm);
+ if (mtx_recursed(m))
+ db_printf(" recursed: %d\n", m->mtx_recurse);
+ }
+}
+#endif