Page MenuHomeFreeBSD

D17621.id49323.diff
No OneTemporary

D17621.id49323.diff

Index: sys/kern/tty.c
===================================================================
--- sys/kern/tty.c
+++ sys/kern/tty.c
@@ -54,6 +54,7 @@
#include <sys/proc.h>
#include <sys/serial.h>
#include <sys/signal.h>
+#include <sys/stack.h>
#include <sys/stat.h>
#include <sys/sx.h>
#include <sys/sysctl.h>
@@ -1076,6 +1077,8 @@
knlist_init_mtx(&tp->t_inpoll.si_note, tp->t_mtx);
knlist_init_mtx(&tp->t_outpoll.si_note, tp->t_mtx);
+ tp->t_stack = stack_create(M_WAITOK);
+
return (tp);
}
@@ -1098,6 +1101,8 @@
knlist_destroy(&tp->t_inpoll.si_note);
knlist_destroy(&tp->t_outpoll.si_note);
+ stack_destroy(tp->t_stack);
+
cv_destroy(&tp->t_inwait);
cv_destroy(&tp->t_outwait);
cv_destroy(&tp->t_bgwait);
Index: sys/kern/tty_info.c
===================================================================
--- sys/kern/tty_info.c
+++ sys/kern/tty_info.c
@@ -47,10 +47,14 @@
#include <sys/param.h>
#include <sys/lock.h>
+#include <sys/malloc.h>
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/resourcevar.h>
+#include <sys/sbuf.h>
#include <sys/sched.h>
+#include <sys/stack.h>
+#include <sys/sysctl.h>
#include <sys/systm.h>
#include <sys/tty.h>
@@ -209,6 +213,20 @@
return (p2->p_pid > p1->p_pid); /* tie - return highest pid */
}
+static int
+sbuf_tty_drain(void *a, const char *d, int len)
+{
+ struct tty *tp;
+
+ tp = a;
+ return (ttyprintf(tp, "%.*s", len, d));
+}
+
+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.
*/
@@ -219,8 +237,9 @@
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;
@@ -292,6 +311,14 @@
else
state = "unknown";
pctcpu = (sched_pctcpu(td) * 10000 + FSCALE / 2) >> FSHIFT;
+ if (tty_info_kstacks) {
+ if (TD_IS_SWAPPED(td) || TD_IS_RUNNING(td))
+ sterr = stack_save_td_running(tp->t_stack, td);
+ else {
+ stack_save_td(tp->t_stack, td);
+ sterr = 0;
+ }
+ }
thread_unlock(td);
if (p->p_state == PRS_NEW || p->p_state == PRS_ZOMBIE)
rss = 0;
@@ -312,4 +339,14 @@
(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) {
+ (void)sbuf_new(&sb, tp->t_stack_buf, sizeof(tp->t_stack_buf),
+ SBUF_FIXEDLEN);
+ sbuf_set_drain(&sb, sbuf_tty_drain, tp);
+ sterr = stack_sbuf_print_flags(&sb, tp->t_stack, M_NOWAIT);
+ if (sterr == 0)
+ sbuf_finish(&sb);
+ sbuf_delete(&sb);
+ }
}
Index: sys/sys/tty.h
===================================================================
--- sys/sys/tty.h
+++ sys/sys/tty.h
@@ -52,6 +52,8 @@
struct ttydevsw;
+struct stack;
+
/*
* Per-TTY structure, containing buffers, etc.
*
@@ -132,6 +134,14 @@
void *t_devswsoftc; /* (c) Soft config, for drivers. */
void *t_hooksoftc; /* (t) Soft config, for hooks. */
struct cdev *t_dev; /* (c) Primary character device. */
+
+ struct stack *t_stack; /* (t) */
+#ifndef PRINTF_BUFR_SIZE
+#define TTY_PRINTF_SIZE 256
+#else
+#define TTY_PRINTF_SIZE PRINTF_BUFR_SIZE
+#endif
+ char t_stack_buf[TTY_PRINTF_SIZE]; /* (t) */
};
/*

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 19, 3:32 PM (15 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
25648018
Default Alt Text
D17621.id49323.diff (3 KB)

Event Timeline