Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/crash ddb: New `show all tstiles' command.



details:   https://anonhg.NetBSD.org/src/rev/09498b0008ac
branches:  trunk
changeset: 377378:09498b0008ac
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Jul 09 17:10:47 2023 +0000

description:
ddb: New `show all tstiles' command.

Shows who's waiting for which locks and what the owner is up to.

XXX pullup-10

diffstat:

 share/man/man4/ddb.4    |  10 ++++-
 sys/ddb/db_command.c    |  89 +++++++++++++++++++++++++++++++++++++++++++++++-
 sys/ddb/db_syncobj.c    |  73 ++++++++++++++++++++++++++++++++++++++++
 sys/ddb/db_syncobj.h    |  39 +++++++++++++++++++++
 sys/ddb/ddb.h           |   3 +-
 sys/ddb/files.ddb       |   3 +-
 usr.sbin/crash/Makefile |   9 +++-
 7 files changed, 219 insertions(+), 7 deletions(-)

diffs (truncated from 337 to 300 lines):

diff -r 574c8ed59223 -r 09498b0008ac share/man/man4/ddb.4
--- a/share/man/man4/ddb.4      Sun Jul 09 17:03:09 2023 +0000
+++ b/share/man/man4/ddb.4      Sun Jul 09 17:10:47 2023 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: ddb.4,v 1.202 2022/04/28 07:17:52 msaitoh Exp $
+.\"    $NetBSD: ddb.4,v 1.203 2023/07/09 17:10:47 riastradh Exp $
 .\"
 .\" Copyright (c) 1997 - 2019 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -616,6 +616,14 @@ LWP name and wait channel message.
 LWPs currently running on a CPU are marked with the '\&>' sign.
 This is the default.
 .El
+.It Ic show all tstiles Ns Oo Cm /t Oc
+Display all lwps that are currently waiting in turnstiles to acquire
+locks, which locks they are waiting for, and who currently holds them.
+Valid modifiers:
+.Bl -tag -width 3n
+.It Cm /t
+show a stack trace of the lwp that currently holds each lock
+.El
 .It Ic show routes
 Dump the entire
 .Dv AF_INET
diff -r 574c8ed59223 -r 09498b0008ac sys/ddb/db_command.c
--- a/sys/ddb/db_command.c      Sun Jul 09 17:03:09 2023 +0000
+++ b/sys/ddb/db_command.c      Sun Jul 09 17:10:47 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: db_command.c,v 1.182 2023/05/25 21:46:55 uwe Exp $     */
+/*     $NetBSD: db_command.c,v 1.183 2023/07/09 17:10:47 riastradh Exp $       */
 
 /*
  * Copyright (c) 1996, 1997, 1998, 1999, 2002, 2009, 2019
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.182 2023/05/25 21:46:55 uwe Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.183 2023/07/09 17:10:47 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_aio.h"
@@ -94,6 +94,7 @@
 #include <sys/kernhist.h>
 #include <sys/socketvar.h>
 #include <sys/queue.h>
+#include <sys/syncobj.h>
 
 #include <dev/cons.h>
 
@@ -200,6 +201,7 @@ static void db_fncall(db_expr_t, bool, d
 static void     db_help_print_cmd(db_expr_t, bool, db_expr_t, const char *);
 static void    db_lock_print_cmd(db_expr_t, bool, db_expr_t, const char *);
 static void    db_show_all_locks(db_expr_t, bool, db_expr_t, const char *);
+static void    db_show_all_tstiles(db_expr_t, bool, db_expr_t, const char *);
 static void    db_show_lockstats(db_expr_t, bool, db_expr_t, const char *);
 static void    db_show_all_freelists(db_expr_t, bool, db_expr_t, const char *);
 static void    db_mount_print_cmd(db_expr_t, bool, db_expr_t, const char *);
@@ -316,6 +318,8 @@ static const struct db_command db_show_c
            "Print the state of the scheduler's run queues.",
            NULL,NULL) },
        { DDB_ADD_CMD("socket", db_socket_print_cmd,    0,NULL,NULL,NULL) },
+       { DDB_ADD_CMD("tstiles", db_show_all_tstiles,
+           0, "Show who's holding up tstiles", "[/t]", NULL) },
        { DDB_ADD_CMD("uvmexp", db_uvmexp_print_cmd, 0,
            "Print a selection of UVM counters and statistics.",
            NULL,NULL) },
@@ -1363,6 +1367,87 @@ db_show_all_locks(db_expr_t addr, bool h
 }
 
 static void
+db_show_all_tstiles(db_expr_t addr, bool have_addr,
+    db_expr_t count, const char *modif)
+{
+       struct proc *p;
+       bool trace = false;
+
+       if (modif[0] == 't')
+               trace = true;
+
+       db_printf("%5s %5s %16s %16s %16s\n",
+           "PID", "LID", "COMMAND", "WAITING-FOR", "WAIT-CHANNEL");
+       for (p = db_proc_first(); p != NULL; p = db_proc_next(p)) {
+               pid_t pid = -1;
+               char comm[MAXCOMLEN + 1] = "";
+               struct lwp *l = NULL;
+
+               db_read_bytes((db_addr_t)&p->p_pid, sizeof(pid), (char *)&pid);
+               db_read_bytes((db_addr_t)p->p_comm, sizeof(comm), comm);
+               db_read_bytes((db_addr_t)&p->p_lwps.lh_first, sizeof(l),
+                   (char *)&l);
+               while (l != NULL) {
+                       wchan_t wchan = NULL;
+                       char wchanname[128] = "";
+                       const char *wmesg = NULL;
+                       char wmesgbuf[sizeof("tstile")] = "";
+                       lwpid_t lid = -1;
+                       struct syncobj *sobj = NULL;
+                       struct lwp *owner = NULL;
+
+                       db_read_bytes((db_addr_t)&l->l_wchan, sizeof(wchan),
+                           (char *)&wchan);
+                       if (wchan == NULL)
+                               goto next;
+                       db_symstr(wchanname, sizeof(wchanname),
+                           (db_expr_t)wchan, DB_STGY_ANY);
+                       db_read_bytes((db_addr_t)&l->l_wmesg, sizeof(wmesg),
+                           (char *)&wmesg);
+                       if (wmesg != NULL) {
+                               db_read_bytes((db_addr_t)wmesg,
+                                   sizeof(wmesgbuf), wmesgbuf);
+                       }
+
+                       if (strncmp(wmesgbuf, "tstile", sizeof("tstile")) != 0)
+                               goto next;
+
+                       db_read_bytes((db_addr_t)&l->l_lid, sizeof(lid),
+                           (char *)&lid);
+                       db_read_bytes((db_addr_t)&l->l_syncobj, sizeof(sobj),
+                           (char *)&sobj);
+                       if (sobj == NULL) {
+                               db_printf("%5ld %5ld %16s %16s %16s\n",
+                                   (long)pid,
+                                   (long)lid,
+                                   comm,
+                                   "(unknown)",
+                                   wchanname);
+                               goto next;
+                       }
+
+                       owner = db_syncobj_owner(sobj, wchan);
+
+                       db_printf("%5ld %5ld %16s %16lx %16s\n",
+                           (long)pid,
+                           (long)lid,
+                           comm,
+                           (long)owner,
+                           wchanname);
+
+                       if (trace && owner != NULL) {
+                               db_stack_trace_print((db_expr_t)owner,
+                                   /*have_addr*/true, /*count*/-1,
+                                   /*modif(lwp)*/"a", db_printf);
+                       }
+
+next:                  db_read_bytes((db_addr_t)&l->l_sibling.le_next,
+                           sizeof(l), (char *)&l);
+               }
+       }
+}
+
+static void
 db_show_all_freelists(db_expr_t addr, bool have_addr,
     db_expr_t count, const char *modif)
 {
diff -r 574c8ed59223 -r 09498b0008ac sys/ddb/db_syncobj.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/ddb/db_syncobj.c      Sun Jul 09 17:10:47 2023 +0000
@@ -0,0 +1,73 @@
+/*     $NetBSD: db_syncobj.c,v 1.1 2023/07/09 17:10:47 riastradh Exp $ */
+
+/*-
+ * Copyright (c) 2023 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#define        __MUTEX_PRIVATE
+#define        __RWLOCK_PRIVATE
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: db_syncobj.c,v 1.1 2023/07/09 17:10:47 riastradh Exp $");
+
+#include <sys/types.h>
+
+#include <sys/mutex.h>
+#include <sys/null.h>
+#include <sys/rwlock.h>
+#include <sys/syncobj.h>
+
+#include <ddb/ddb.h>
+
+struct lwp *
+db_syncobj_owner(struct syncobj *sobj, wchan_t wchan)
+{
+       db_expr_t mutex_syncobj_;
+       db_expr_t rw_syncobj_;
+
+       if (db_value_of_name("mutex_syncobj", &mutex_syncobj_) &&
+           (db_expr_t)sobj == mutex_syncobj_) {
+               volatile const struct kmutex *mtx = wchan;
+               uintptr_t owner;
+
+               db_read_bytes((db_addr_t)&mtx->mtx_owner, sizeof(owner),
+                   (char *)&owner);
+               return (struct lwp *)(owner & MUTEX_THREAD);
+
+       } else if (db_value_of_name("rw_syncobj", &rw_syncobj_) &&
+           (db_expr_t)sobj == rw_syncobj_) {
+               volatile const struct krwlock *rw = wchan;
+               uintptr_t owner;
+
+               db_read_bytes((db_addr_t)&rw->rw_owner, sizeof(owner),
+                   (char *)&owner);
+               if (owner & RW_WRITE_LOCKED)
+                       return (struct lwp *)(owner & RW_THREAD);
+               return NULL;
+
+       } else {
+               return NULL;
+       }
+}
diff -r 574c8ed59223 -r 09498b0008ac sys/ddb/db_syncobj.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/ddb/db_syncobj.h      Sun Jul 09 17:10:47 2023 +0000
@@ -0,0 +1,39 @@
+/*     $NetBSD: db_syncobj.h,v 1.1 2023/07/09 17:10:47 riastradh Exp $ */
+
+/*-
+ * Copyright (c) 2023 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef        _DDB_DB_SYNCOBJ_H
+#define        _DDB_DB_SYNCOBJ_H
+
+#include <sys/syncobj.h>
+
+struct lwp;
+struct syncobj;
+
+struct lwp *db_syncobj_owner(struct syncobj *, wchan_t);
+
+#endif /* _DDB_DB_SYNCOBJ_H */
diff -r 574c8ed59223 -r 09498b0008ac sys/ddb/ddb.h
--- a/sys/ddb/ddb.h     Sun Jul 09 17:03:09 2023 +0000
+++ b/sys/ddb/ddb.h     Sun Jul 09 17:10:47 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ddb.h,v 1.5 2020/05/31 09:51:55 rin Exp $      */
+/*     $NetBSD: ddb.h,v 1.6 2023/07/09 17:10:47 riastradh Exp $        */
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -50,5 +50,6 @@
 #include <ddb/db_proc.h>
 #include <ddb/db_cpu.h>
 #include <ddb/db_autoconf.h>
+#include <ddb/db_syncobj.h>
 
 #endif /* _DDB_DDB_H_ */
diff -r 574c8ed59223 -r 09498b0008ac sys/ddb/files.ddb
--- a/sys/ddb/files.ddb Sun Jul 09 17:03:09 2023 +0000
+++ b/sys/ddb/files.ddb Sun Jul 09 17:10:47 2023 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.ddb,v 1.15 2021/10/06 12:14:51 uwe Exp $
+#      $NetBSD: files.ddb,v 1.16 2023/07/09 17:10:47 riastradh Exp $
 
 #
 # DDB options



Home | Main Index | Thread Index | Old Index