Page MenuHomeFreeBSD

tty info (^T): Add optional kernel stack(9) traces
ClosedPublic

Authored by cem on Oct 19 2018, 10:26 PM.

Details

Summary

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.

Diff Detail

Lint
Lint OK
Unit
No Unit Test Coverage
Build Status
Buildable 20298
Build 19758: arc lint + arc unit

Event Timeline

cem created this revision.Oct 19 2018, 10:26 PM
oshogbo accepted this revision.Oct 19 2018, 10:47 PM

LGTM.

This revision is now accepted and ready to land.Oct 19 2018, 10:47 PM
ed added inline comments.Oct 20 2018, 10:50 AM
sys/kern/tty_info.c
234

sbuf has its own built-in printf logic, right? If so: would it make sense to refactor this code to use sbuf entirely?

The interesting thing about doing that would be that afterwards, ttyprintf() would only be called to write raw, pre-formatted buffers of data to the TTY. This can be done more efficiently, without calling into subr_prf.c at all.

cem marked 3 inline comments as done.Oct 20 2018, 1:32 PM
cem added inline comments.
sys/kern/tty_info.c
234

It has it, yep. I guess I didn't realize this function was the only in-tree ttyprintf consumer.

Given that, yeah, I agree it makes a lot of sense to rip out ttyprintf, convert this code to sbuf, and use the more efficient tty plain string-writing routine.

sys/sys/tty.h
138

@markj suggests we might just put this on the stack. I don't see any public stack_init KPI that doesn't allocate, but stack_create() is just an M_ZERO malloc, so perhaps zero-initialization would be adequate.

144

I'm less sure about dumping this one on the stack, especially given that PRINTF_BUFR_SIZE is somewhat flexible.

cem updated this revision to Diff 49332.Oct 20 2018, 3:08 PM

Rebase on D17624

This revision now requires review to proceed.Oct 20 2018, 3:08 PM
cem marked an inline comment as done.Oct 20 2018, 3:09 PM
cem marked an inline comment as done.
cem added inline comments.
sys/kern/tty_info.c
316–320

The stack(9) interface is a bit obnoxious here -- I'd like to be able to just invoke a single int-returning function, maybe with flags to allow grabbing a running stack, and not worry about checking SWAPPED/RUNNING or setting error to zero myself. But that is orthogonal to this enhancement.

markj added inline comments.Oct 20 2018, 5:08 PM
sys/kern/tty_info.c
315

Use stack_zero()?

316–320

I think I did it that way because each platform needs its own implementation and I only wanted to do it for x86. I don't disagree with the sentiment.

cem marked an inline comment as done.Oct 20 2018, 5:32 PM
cem added inline comments.
sys/kern/tty_info.c
315

will fix

This revision was not accepted when it landed; it landed in state Needs Review.Oct 20 2018, 6:42 PM
This revision was automatically updated to reflect the committed changes.