From owner-svn-src-head@freebsd.org Sat Oct 20 18:42:29 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id CB579FF0F47; Sat, 20 Oct 2018 18:42:29 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 821CE81EE9; Sat, 20 Oct 2018 18:42:29 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 639B121F2A; Sat, 20 Oct 2018 18:42:29 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w9KIgTeJ050787; Sat, 20 Oct 2018 18:42:29 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w9KIgTtk050786; Sat, 20 Oct 2018 18:42:29 GMT (envelope-from cem@FreeBSD.org) Message-Id: <201810201842.w9KIgTtk050786@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: Conrad Meyer Date: Sat, 20 Oct 2018 18:42:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r339471 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: cem X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 339471 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Oct 2018 18:42:30 -0000 Author: cem Date: Sat Oct 20 18:42:28 2018 New Revision: 339471 URL: https://svnweb.freebsd.org/changeset/base/339471 Log: tty info (^T): Add optional kernel stack(9) traces It is often useful for developers and administrators to determine a running thread's stack for debugging purposes. With this feature, using ^T will print that information For now, the feature is disabled by default. Enable with sysctl kern.tty_info_kstacks=1. Discussed with: markj Reviewed by: oshogbo Relnotes: yes Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D17621 Modified: head/sys/kern/tty_info.c Modified: head/sys/kern/tty_info.c ============================================================================== --- head/sys/kern/tty_info.c Sat Oct 20 18:37:21 2018 (r339470) +++ head/sys/kern/tty_info.c Sat Oct 20 18:42:28 2018 (r339471) @@ -49,11 +49,14 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include #include #include +#include +#include #include #include @@ -233,6 +236,11 @@ sbuf_tty_drain(void *a, const char *d, int len) return (-ENXIO); } +static bool tty_info_kstacks = false; +SYSCTL_BOOL(_kern, OID_AUTO, tty_info_kstacks, CTLFLAG_RWTUN, + &tty_info_kstacks, 0, + "Enable printing kernel stack(9) traces on ^T (tty info)"); + /* * Report on state of foreground process group. */ @@ -240,12 +248,13 @@ void tty_info(struct tty *tp) { struct timeval rtime, utime, stime; + struct stack stack; struct proc *p, *ppick; struct thread *td, *tdpick; const char *stateprefix, *state; struct sbuf sb; long rss; - int load, pctcpu; + int load, pctcpu, sterr; pid_t pid; char comm[MAXCOMLEN + 1]; struct rusage ru; @@ -320,6 +329,15 @@ tty_info(struct tty *tp) else state = "unknown"; pctcpu = (sched_pctcpu(td) * 10000 + FSCALE / 2) >> FSHIFT; + if (tty_info_kstacks) { + stack_zero(&stack); + if (TD_IS_SWAPPED(td) || TD_IS_RUNNING(td)) + sterr = stack_save_td_running(&stack, td); + else { + stack_save_td(&stack, td); + sterr = 0; + } + } thread_unlock(td); if (p->p_state == PRS_NEW || p->p_state == PRS_ZOMBIE) rss = 0; @@ -340,6 +358,9 @@ tty_info(struct tty *tp) (long)utime.tv_sec, utime.tv_usec / 10000, (long)stime.tv_sec, stime.tv_usec / 10000, pctcpu / 100, rss); + + if (tty_info_kstacks && sterr == 0) + stack_sbuf_print_flags(&sb, &stack, M_NOWAIT); out: sbuf_finish(&sb);