]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
iflib: leave only 1 receive descriptor unused
authorvmaffione <vmaffione@FreeBSD.org>
Tue, 1 Sep 2020 20:41:47 +0000 (20:41 +0000)
committervmaffione <vmaffione@FreeBSD.org>
Tue, 1 Sep 2020 20:41:47 +0000 (20:41 +0000)
commit9bece2dae5cc8704c658aeacd15382eeeee725bc
treead5869c5d1db073e296c4c630d2d777a9a591abb
parent4e2f0f58caf7097e9479ce1b9c6bf1cefacec542
iflib: leave only 1 receive descriptor unused

The pidx argument of isc_rxd_flush() indicates which is the last valid
receive descriptor to be used by the NIC. However, current code has
multiple issues:
  - Intel drivers write pidx to their RDT register, which means that
    NICs will only use the descriptors up to pidx-1 (modulo ring size N),
    and won't actually use the one pointed by pidx. This does not break
    reception, but it is anyway confusing and suboptimal (the NIC will
    actually see only N-2 descriptors as available, rather than N-1).
    Other drivers (if_vmx, if_bnxt, if_mgb) adhere to this semantic).
  - The semantic used by Intel (RDT is one descriptor past the last
     valid one) is used by most (if not all) NICs, and it is also used
     on the TX side (also in iflib). Since iflib is not currently
     using this semantic for RX, it must decrement fl->ifl_pidx
     (modulo N) before calling isc_rxd_flush(), and then the
     per-driver callback implementation must increment the index
     again (to match the real semantic). This is confusing and suboptimal.
  -  The iflib refill function is also called at initialization.
     However, in case the ring size is smaller than 128 (e.g. if_mgb),
     the refill function will actually prepare all the receive
     descriptors (N), without leaving one unused, as most of NICs assume
     (e.g. to avoid RDT to overrun RDH). I can speculate that the code
     looks like this right now because this issue showed up during
     testing (e.g. with if_mgb), and it was easy to workaround by
     decrementing pidx before isc_rxd_flush().

The goal of this change is to simplify the code (removing a bunch
of instructions from the RX fast path), and to make the semantic of
isc_rxd_flush() consistent across drivers. To achieve this, we:
  - change the semantics of the pidx argument to the usual one (that
    is the index one past the last valid one), so that both iflib and
    drivers avoid the decrement/increment dance.
  - fix the initialization code to prepare at most N-1 descriptors.

Reviewed by: markj
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D26191
sys/dev/bnxt/bnxt_txrx.c
sys/dev/mgb/if_mgb.c
sys/dev/mgb/if_mgb.h
sys/dev/vmware/vmxnet3/if_vmx.c
sys/net/iflib.c