Page MenuHomeFreeBSD

Make use of stats(3) in the TCP stack
Needs ReviewPublic

Authored by trasz on Jun 15 2019, 2:48 PM.


Group Reviewers

Make use of stats(3) in the TCP stack. This makes it possible to retrieve
per-connection statistical information such as receive window, RTT, or goodput,
using a newly added TCP_STATS getsockopt(3) option, and extract it using
stats_voistat_fetch(3) API. See the net/tcprtt port for an example consumer
of this API.

Compared to the existing TCP_INFO, the main differences are that this
mechanism is easy to extend without breaking ABI, and it provides statistical
information instead of raw "snapshots" of values at a given point of time.

This depends on,, and Example tool using it is here:

Sponsored By: Klara Inc, Netflix
Obtained from: Netflix

Diff Detail

rS FreeBSD src repository
Lint OK
No Unit Test Coverage
Build Status
Buildable 24870
Build 23611: arc lint + arc unit

Event Timeline

trasz created this revision.Jun 15 2019, 2:48 PM
trasz retitled this revision from Make use of stats(3) in the TCP stack. This depends on,, and to Make use of stats(3) in the TCP stack.Jun 15 2019, 2:50 PM
trasz edited the summary of this revision. (Show Details)
trasz edited the summary of this revision. (Show Details)Jun 15 2019, 3:47 PM
trasz updated this revision to Diff 58673.Jun 15 2019, 3:58 PM

Drop unneeded diff.

allanjude added inline comments.

should the fixup of missing TF_FASTOPEN bits be a separate commit?

thj added a subscriber: thj.Jun 19 2019, 10:18 AM
thj added inline comments.

tcpsyninfo looks to be 16 bytes to me, shouldn't this update to


trasz added inline comments.Fri, Jun 28, 8:52 PM

But __tcpi_pad[] is u_int32_t, not a char?

allanjude added inline comments.Sat, Jun 29, 3:21 PM

indeed, tcpi_pad[] is a u_int32_t (so 4 bytes), so dropping it from 26 to 22 accounts for the 16 bytes. Unless I am missing something.

thj added inline comments.Wed, Jul 3, 8:19 AM

Ah okay, I missed that.


Is the goodput measurement time (i.e. number of ms for the measurement window) reported by stats somewhere?

Does the calculation break with an rtt <1ms?

I think a comment here might be helpful for future readers of the code, something along the lines of

report goodput in bits per [time]
trasz edited the summary of this revision. (Show Details)Mon, Jul 15, 4:30 PM
trasz edited the summary of this revision. (Show Details)Mon, Jul 15, 6:43 PM
trasz added inline comments.Wed, Jul 17, 8:06 PM

I don't think the raw measurement time is reported - but there's the digest computed for goodput, which I'm guessing is what you'd want the times for?

Regarding rtt < 1ms - well, it's just 'capped from the bottom' with the max(), but I don't know how realistic times below 1ms are, given that the resolution of tcp_ts_getticks() seems to be 1ms?

As for the units - that's a good suggestion; let me do a little experiment to make sure I get this right and I'll add it to the VOI declarations in tcp.h.

trasz edited the summary of this revision. (Show Details)Thu, Jul 18, 9:36 PM