Page MenuHomeFreeBSD

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

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



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

Diff Detail

rS FreeBSD src repository - subversion
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

This revision is now accepted and ready to land.Oct 19 2018, 10:47 PM
234 ↗(On Diff #49323)

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.
234 ↗(On Diff #49323)

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.

138 ↗(On Diff #49323)

@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 ↗(On Diff #49323)

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.
334–338 ↗(On Diff #49332)

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.

333 ↗(On Diff #49332)

Use stack_zero()?

334–338 ↗(On Diff #49332)

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.
333 ↗(On Diff #49332)

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.