@@ -60,57 +60,14 @@ type linkDispatcher interface {
6060 release ()
6161}
6262
63- // PacketDispatchMode are the various supported methods of receiving and
64- // dispatching packets from the underlying FD.
65- type PacketDispatchMode int
66-
67- // BatchSize is the number of packets to write in each syscall. It is 47
68- // because when GVisorGSO is in use then a single 65KB TCP segment can get
69- // split into 46 segments of 1420 bytes and a single 216 byte segment.
70- const BatchSize = 47
71-
72- const (
73- // Readv is the default dispatch mode and is the least performant of the
74- // dispatch options but the one that is supported by all underlying FD
75- // types.
76- Readv PacketDispatchMode = iota
77- // RecvMMsg enables use of recvmmsg() syscall instead of readv() to
78- // read inbound packets. This reduces # of syscalls needed to process
79- // packets.
80- //
81- // NOTE: recvmmsg() is only supported for sockets, so if the underlying
82- // FD is not a socket then the code will still fall back to the readv()
83- // path.
84- RecvMMsg
85- // PacketMMap enables use of PACKET_RX_RING to receive packets from the
86- // NIC. PacketMMap requires that the underlying FD be an AF_PACKET. The
87- // primary use-case for this is runsc which uses an AF_PACKET FD to
88- // receive packets from the veth device.
89- PacketMMap
90- )
91-
92- func (p PacketDispatchMode ) String () string {
93- switch p {
94- case Readv :
95- return "Readv"
96- case RecvMMsg :
97- return "RecvMMsg"
98- case PacketMMap :
99- return "PacketMMap"
100- default :
101- return fmt .Sprintf ("unknown packet dispatch mode '%d'" , p )
102- }
103- }
104-
10563var (
10664 _ stack.LinkEndpoint = (* endpoint )(nil )
10765 _ stack.GSOEndpoint = (* endpoint )(nil )
10866)
10967
11068// +stateify savable
11169type fdInfo struct {
112- fd int
113- isSocket bool
70+ fd int
11471}
11572
11673// +stateify savable
@@ -137,10 +94,6 @@ type endpoint struct {
13794 // +checklocks:mu
13895 dispatcher stack.NetworkDispatcher
13996
140- // packetDispatchMode controls the packet dispatcher used by this
141- // endpoint.
142- packetDispatchMode PacketDispatchMode
143-
14497 // wg keeps track of running goroutines.
14598 wg sync.WaitGroup `state:"nosave"`
14699
@@ -168,7 +121,7 @@ type endpoint struct {
168121 mtu uint32
169122
170123 batchSize int
171- writeMsgX bool
124+ sendMsgX bool
172125}
173126
174127// Options specify the details about the fd-based endpoint to be created.
@@ -201,10 +154,6 @@ type Options struct {
201154 // include CapabilityDisconnectOk.
202155 DisconnectOk bool
203156
204- // PacketDispatchMode specifies the type of inbound dispatcher to be
205- // used for this endpoint.
206- PacketDispatchMode PacketDispatchMode
207-
208157 // TXChecksumOffload if true, indicates that this endpoints capability
209158 // set should include CapabilityTXChecksumOffload.
210159 TXChecksumOffload bool
@@ -225,8 +174,8 @@ type Options struct {
225174 // from each FD.
226175 ProcessorsPerChannel int
227176
228- MultiPendingPackets bool
229- WriteMsgX bool
177+ RecvMsgX bool
178+ SendMsgX bool
230179}
231180
232181// New creates a new fd-based endpoint.
@@ -266,7 +215,7 @@ func New(opts *Options) (stack.LinkEndpoint, error) {
266215 return nil , fmt .Errorf ("opts.MaxSyscallHeaderBytes is negative" )
267216 }
268217 var batchSize int
269- if opts .MultiPendingPackets {
218+ if opts .RecvMsgX {
270219 batchSize = int ((512 * 1024 )/ (opts .MTU )) + 1
271220 } else {
272221 batchSize = 1
@@ -278,11 +227,10 @@ func New(opts *Options) (stack.LinkEndpoint, error) {
278227 closed : opts .ClosedFunc ,
279228 addr : opts .Address ,
280229 hdrSize : hdrSize ,
281- packetDispatchMode : opts .PacketDispatchMode ,
282230 maxSyscallHeaderBytes : uintptr (opts .MaxSyscallHeaderBytes ),
283231 writevMaxIovs : rawfile .MaxIovs ,
284232 batchSize : batchSize ,
285- writeMsgX : opts .WriteMsgX ,
233+ sendMsgX : opts .SendMsgX ,
286234 }
287235 if e .maxSyscallHeaderBytes != 0 {
288236 if max := int (e .maxSyscallHeaderBytes / rawfile .SizeofIovec ); max < e .writevMaxIovs {
@@ -296,14 +244,23 @@ func New(opts *Options) (stack.LinkEndpoint, error) {
296244 return nil , fmt .Errorf ("unix.SetNonblock(%v) failed: %v" , fd , err )
297245 }
298246
299- e .fds = append (e .fds , fdInfo {fd : fd , isSocket : true })
247+ e .fds = append (e .fds , fdInfo {fd : fd })
300248 if opts .ProcessorsPerChannel == 0 {
301249 opts .ProcessorsPerChannel = common .Max (1 , runtime .GOMAXPROCS (0 )/ len (opts .FDs ))
302250 }
303251
304- inboundDispatcher , err := newRecvMMsgDispatcher (fd , e , opts )
305- if err != nil {
306- return nil , fmt .Errorf ("createInboundDispatcher(...) = %v" , err )
252+ var inboundDispatcher linkDispatcher
253+ var err error
254+ if opts .RecvMsgX {
255+ inboundDispatcher , err = newRecvMMsgDispatcher (fd , e , opts )
256+ if err != nil {
257+ return nil , fmt .Errorf ("newRecvMMsgDispatcher(%d, %+v) = %v" , fd , e , err )
258+ }
259+ } else {
260+ inboundDispatcher , err = newReadVDispatcher (fd , e , opts )
261+ if err != nil {
262+ return nil , fmt .Errorf ("newReadVDispatcher(%d, %+v) = %v" , fd , e , err )
263+ }
307264 }
308265 e .inboundDispatchers = append (e .inboundDispatchers , inboundDispatcher )
309266 }
@@ -489,7 +446,7 @@ func (e *endpoint) writePacket(pkt *stack.PacketBuffer) tcpip.Error {
489446
490447func (e * endpoint ) sendBatch (batchFDInfo fdInfo , pkts []* stack.PacketBuffer ) (int , tcpip.Error ) {
491448 // Degrade to writePacket if underlying fd is not a socket.
492- if ! batchFDInfo . isSocket || ! e . writeMsgX {
449+ if ! e . sendMsgX {
493450 var written int
494451 var err tcpip.Error
495452 for written < len (pkts ) {
@@ -597,7 +554,7 @@ func (e *endpoint) sendBatch(batchFDInfo fdInfo, pkts []*stack.PacketBuffer) (in
597554func (e * endpoint ) WritePackets (pkts stack.PacketBufferList ) (int , tcpip.Error ) {
598555 // Preallocate to avoid repeated reallocation as we append to batch.
599556 batch := make ([]* stack.PacketBuffer , 0 , e .batchSize )
600- batchFDInfo := fdInfo {fd : - 1 , isSocket : false }
557+ batchFDInfo := fdInfo {fd : - 1 }
601558 sentPackets := 0
602559 for _ , pkt := range pkts .AsSlice () {
603560 if len (batch ) == 0 {
0 commit comments