Page MenuHomeFreeBSD

iflib: accurately account for TSO packets & transmitted
ClosedPublic

Authored by gallatin on Thu, Apr 9, 11:27 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Apr 26, 4:18 AM
Unknown Object (File)
Sat, Apr 25, 12:03 PM
Unknown Object (File)
Thu, Apr 23, 10:18 PM
Unknown Object (File)
Tue, Apr 21, 7:04 PM
Unknown Object (File)
Mon, Apr 20, 2:22 AM
Unknown Object (File)
Mon, Apr 20, 2:22 AM
Unknown Object (File)
Sat, Apr 18, 3:05 PM
Unknown Object (File)
Sat, Apr 18, 12:06 PM

Details

Summary

Fix iflib software pkt/byte counters to work properly with TSO. The current software based counters count packets and bytes sent down to the driver, but does not account for the inflation of packets/bytes when using TSO. To account for this, we must calculate the number of segments the NIC will transmit, and multiply the header size by the number of segments transmitted to arrive at the total bytes sent.

To do this, move the calculation into iflib_encap(), where we have already parsed the packet and know the header size, etc.

I noticed this when moving an out-of-tree NIC driver for a NIC with unreliable HW counters to using iflib SW counters.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

The conception looks good to me, but I'm not familiar with TSO so no idea whether Update packets / bytes sent does the right thing.

FreeBSD/sys/net/iflib.c
3482 ↗(On Diff #175207)

Arguably those two statistics belong to txq.

This revision was not accepted when it landed; it landed in state Needs Review.Fri, Apr 17, 5:35 PM
This revision was automatically updated to reflect the committed changes.

https://lists.freebsd.org/archives/freebsd-current/2026-April/010130.html ("Re: panic: assertion failed in iflib_txq_drain()") points to the commit for this as reverting it being sufficient to avoid the new panics.

The original https://lists.freebsd.org/archives/freebsd-current/2026-April/010127.html reported:

panic: Assertion mp != NULL && *mp != NULL failed at 
/home/pkgbuild/worktrees/main/sys/net/iflib.c:3922 cpuid= 3 time 1776500574
KDB: stack backtrace:
db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 
0xfffff81078b7450 vpanic at vpanic+0x136/frame 0xfffffe01078b7580
panic
at panic+0x43/frame 0xfffffe01078b75e0
iflib_txq_drain at iflib_txq_drain+0x429/frame 0xfffffe81078b7660 
drain_ring_lockless() at drain_ring_lockless+0x8a/frame 
0xfffffe01078b76b0 ifmp_ring_enqueue() at ifmp_ring_enqueue+0x332/frame 
0xfffffe81078b7700 iflib_if_transmit at iflib_if_transmit+0x273/frame 
0xfffffe01078b7780 ether_output_frame() at ether_output_frame+0xd3/frame 
0xfffffe81078b77b8 ether_output at ether_output+0x71d/frame 
0xfffffe01078b7840 ip_output at ip_output+0x183d/frame 0xfffffe01078b7960
tcp_default_output() at tcp_default_output+0x21d8/frame 
0xfffffe01078b7b30 tcp_usr_send at top_usr_send+0x500/frame 
0xfffffe01078b7be0
sosend_generic locked at sosend_generic_locked+0x59b/frame 
0xfffffe01078b7c98 sosend_generic at sosend_generic+0x61/frame 
0xfffffe81078b7ce0
sousrsendat sousrsend+0x79/frame 0xfffffe01078b7d40
dofilewrite) at dofilewrite+0x81/frame 0xfffffe81078b7d90
sys_write at sys_write+0x127/frame 0xfffffe01078b7e00
amd64_syscall at amd64_syscall+0x169/frame 0xfffffe01078b7f30
fast_syscall_common at fast_syscall_common+0xf8/frame 0xfffffe01078b7f30
syscall (4, FreeBSD ELF64, write), rip = 0x8ea71c6154a, rsp = 
0x8ea6806fb98, rbp = 0x8ea6806fbc0 KDB: enter: panic
[ thread pid 6281 tid 101448 1
Stopped at
db>
kdb_enter+0x33: movq
$0,0x15dd302(rip)