Module Name: src Committed By: riastradh Date: Sun Jul 9 17:10:47 UTC 2023
Modified Files: src/share/man/man4: ddb.4 src/sys/ddb: db_command.c ddb.h files.ddb src/usr.sbin/crash: Makefile Added Files: src/sys/ddb: db_syncobj.c db_syncobj.h Log Message: ddb: New `show all tstiles' command. Shows who's waiting for which locks and what the owner is up to. XXX pullup-10 To generate a diff of this commit: cvs rdiff -u -r1.202 -r1.203 src/share/man/man4/ddb.4 cvs rdiff -u -r1.182 -r1.183 src/sys/ddb/db_command.c cvs rdiff -u -r0 -r1.1 src/sys/ddb/db_syncobj.c src/sys/ddb/db_syncobj.h cvs rdiff -u -r1.5 -r1.6 src/sys/ddb/ddb.h cvs rdiff -u -r1.15 -r1.16 src/sys/ddb/files.ddb cvs rdiff -u -r1.48 -r1.49 src/usr.sbin/crash/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/share/man/man4/ddb.4 diff -u src/share/man/man4/ddb.4:1.202 src/share/man/man4/ddb.4:1.203 --- src/share/man/man4/ddb.4:1.202 Thu Apr 28 07:17:52 2022 +++ src/share/man/man4/ddb.4 Sun Jul 9 17:10:47 2023 @@ -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 Index: src/sys/ddb/db_command.c diff -u src/sys/ddb/db_command.c:1.182 src/sys/ddb/db_command.c:1.183 --- src/sys/ddb/db_command.c:1.182 Thu May 25 21:46:55 2023 +++ src/sys/ddb/db_command.c Sun Jul 9 17:10:47 2023 @@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: db_command.c #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) { Index: src/sys/ddb/ddb.h diff -u src/sys/ddb/ddb.h:1.5 src/sys/ddb/ddb.h:1.6 --- src/sys/ddb/ddb.h:1.5 Sun May 31 09:51:55 2020 +++ src/sys/ddb/ddb.h Sun Jul 9 17:10:47 2023 @@ -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_ */ Index: src/sys/ddb/files.ddb diff -u src/sys/ddb/files.ddb:1.15 src/sys/ddb/files.ddb:1.16 --- src/sys/ddb/files.ddb:1.15 Wed Oct 6 12:14:51 2021 +++ src/sys/ddb/files.ddb Sun Jul 9 17:10:47 2023 @@ -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 @@ -36,6 +36,7 @@ file ddb/db_proc.c ddb file ddb/db_print.c ddb file ddb/db_run.c ddb | kgdb # XXX kgdb reference file ddb/db_sym.c ddb +file ddb/db_syncobj.c ddb file ddb/db_trap.c ddb file ddb/db_variables.c ddb file ddb/db_watch.c ddb Index: src/usr.sbin/crash/Makefile diff -u src/usr.sbin/crash/Makefile:1.48 src/usr.sbin/crash/Makefile:1.49 --- src/usr.sbin/crash/Makefile:1.48 Sat Jun 3 09:09:21 2023 +++ src/usr.sbin/crash/Makefile Sun Jul 9 17:10:47 2023 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.48 2023/06/03 09:09:21 lukem Exp $ +# $NetBSD: Makefile,v 1.49 2023/07/09 17:10:47 riastradh Exp $ PROG= crash MAN= crash.8 @@ -46,13 +46,18 @@ CPPFLAGS+= -I${.CURDIR} -I${.OBJDIR} -I$ CPPFLAGS+= -DDDB_VERBOSE_HELP -DDB_MAX_LINE=10000000 -D_KMEMUSER CPPFLAGS+= -UDB_MACHINE_COMMANDS +# XXX +.if ${MACHINE} == "evbppc" +CPPFLAGS+= -DPPC_INTR_IMPL="<powerpc/intr.h>" +.endif + # ddb files from kernel .PATH: $S/ddb SRCS+= db_command.c db_lwp.c db_proc.c db_xxx.c db_cpu.c SRCS+= db_autoconf.c SRCS+= db_access.c db_elf.c db_examine.c SRCS+= db_expr.c db_lex.c db_output.c db_print.c -SRCS+= db_sym.c db_variables.c db_write_cmd.c +SRCS+= db_sym.c db_syncobj.c db_variables.c db_write_cmd.c .PATH: ${S}/arch/${MACHINE}/${MACHINE} .PATH: ${S}/arch/${MACHINE_ARCH}/${MACHINE_ARCH} Added files: Index: src/sys/ddb/db_syncobj.c diff -u /dev/null src/sys/ddb/db_syncobj.c:1.1 --- /dev/null Sun Jul 9 17:10:47 2023 +++ src/sys/ddb/db_syncobj.c Sun Jul 9 17:10:47 2023 @@ -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; + } +} Index: src/sys/ddb/db_syncobj.h diff -u /dev/null src/sys/ddb/db_syncobj.h:1.1 --- /dev/null Sun Jul 9 17:10:47 2023 +++ src/sys/ddb/db_syncobj.h Sun Jul 9 17:10:47 2023 @@ -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 */