Page MenuHomeFreeBSD

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

Authored by cem on Oct 19 2018, 10:26 PM.
Tags
None
Referenced Files
F81623318: D17621.id49332.diff
Fri, Apr 19, 3:41 AM
F81623313: D17621.id.diff
Fri, Apr 19, 3:41 AM
F81623312: D17621.id49343.diff
Fri, Apr 19, 3:41 AM
F81623309: D17621.id49323.diff
Fri, Apr 19, 3:41 AM
F81622689: D17621.diff
Fri, Apr 19, 3:27 AM
Unknown Object (File)
Thu, Apr 11, 12:31 PM
Unknown Object (File)
Tue, Apr 9, 12:32 PM
Unknown Object (File)
Sun, Mar 31, 6:36 AM
Subscribers

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 Passed
Unit
No Test Coverage
Build Status
Buildable 20298
Build 19758: arc lint + arc unit

Event Timeline

This revision is now accepted and ready to land.Oct 19 2018, 10:47 PM
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.

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.

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.