zhhyu7 opened a new pull request, #22288:
URL: https://github.com/apache/nuttx/pull/22288
## Summary
The lower half of a network driver had to publish, and keep up to date, the
number of packets it could hold in each direction, so that the upper half
could stop polling a device whose hardware was full. The transmit operation
already reports a full device by returning -EBUSY, and the upper half already
queues the packet and offers it again when the driver reports a completed
transmission, so the count is redundant. It also forced every driver to
express its hardware limit as a number the upper half could read, which is
awkward for a driver whose limit depends on the packet (a multi-descriptor
frame on pic32mz) or on a remote party (the peer skb pool on ameba_wlan).
Five commits:
1. drivers/net/bridge: fix the lock order of the transmit path.
The transmit operation of a port is called with br_lock held, and a port
whose transmit completes synchronously calls netdev_lower_txdone() from
there, which reaches bridge_txdone() and takes the device lock of the
bridge. That inverts the order the file documents, because the receive
path of a port takes its device lock before br_lock.
bridge_port_send() now tries the device lock of the egress port instead of
waiting for it, and reports the port busy when the attempt fails.
bridge_txdone() defers the resume of the bridge device to the work queue
when it runs with br_lock held or in an interrupt handler, and
bridge_delbr() cancels a pending deferred resume before unregistering the
device it resumes.
2. drivers/net/bridge: refuse a device that is already a port.
[125/1853]
bridge_addif() only looked for the device in the port table of the bridge
it was adding to, so a device could be added to a second bridge. The
second attach overwrote the port the device pointed to: the first bridge
kept an entry for a device it no longer received from, both bridges took
the MAC address of the device, and deleting the second bridge detached the
device for good.
3. drivers/net: let the drivers reclaim their own finished transmissions.
Remove the reclaim callback from netdev_ops_s. It let the upper half ask
a driver to release the packets the hardware had finished with, once the
quota reached zero. A driver knows better than the upper half when its
transmissions complete, and its own interrupt already tells it, so the
reclaiming belongs to the driver: in its transmit operation, which needs
the room, and before it reports a completed transmission.
4. drivers/net: replace the TX quota with the -EBUSY contract.
Remove quota_ptr, quota[] and the registration check from
netdev_lowerhalf_s, netdev_lower_quota_load() with all of its callers, and
netdev_upper_can_tx(). The TX completion flag moves into the upper half
as an atomic_t: netdev_lower_txdone() raises it with atomic_xchg() before
looking at the queue, and netdev_upper_txavail_work() clears it before the
attempts and runs another round for every completion that landed while it
was transmitting. Both sides do a read-modify-write on one location, and
those are totally ordered, so a completion can no longer be lost between
the -EBUSY return and the flag store.
5. drivers, arch: fix the coding style of the files touched by the TX rework.
checkpatch checks a whole file once a commit modifies it, so the style
errors that were already in six of these files have to be fixed for the
series to pass. Whitespace only; "git diff -w" reports nothing but the
blank lines after declarations and the wrapping of four comments that the
re-indentation pushed past the column limit.
## Impact
Breaking change for out-of-tree lower-half drivers. A driver that sets
dev->quota[] or dev->quota_ptr, or that implements the reclaim callback, no
longer compiles. Porting it means:
- delete the quota assignments and the reclaim callback,
- return -EBUSY from transmit() when the hardware has no room, instead of
another error or instead of relying on the quota to stop the upper half,
- release the finished transmissions in transmit() and before calling
netdev_lower_txdone().
The 25 in-tree lower-half drivers that used the quota or the reclaim callback
are adapted in the series. Three had flow control that only worked through
the quota:
- pic32mz reported -EAGAIN, which the upper half treats as a permanent
error and drops the packet, and accounted the extra descriptors of a
multi-fragment packet by hand. It now reports -EBUSY, and the
descriptor ring is the only limit.
- oa_tc6 reported -EAGAIN while its single in-flight packet was not sent.
- ameba_wlan reported -EIO when the peer skb pool was exhausted, so the
packet was dropped instead of retried.
No change for the users of the network stack: the queueing and the retry of
a busy device were already there, this series removes the second mechanism
that did the same thing.
The bridge gains the two fixes above; the lock-order one is needed by this
series, because bridge_port_send() calls the transmit operation of a port
directly.
## Testing
Built, on this tree rebased onto master (c68c0bfbc17):
[49/1853]
sim:bridge OK
imxrt1180-evk:nsh OK (imxrt_netc)
qemu-intel64:eth_console OK (e1000, igb, igc,
virtio-net)
qemu-intel64:can_console + CAN_CTUCANFD_SOCKET OK (ctucanfd_pci)
sim:usbhost + USBHOST_CDCECM OK (usbhost_cdcecm)
checkpatch (tools/checkpatch.sh -c -u -m -g) reports no style error over the
series.
Runtime, sim:bridge with two sim TAP devices moved into separate network
namespaces (ns0 10.0.0.1, ns1 10.0.0.3, br0 = eth0 + eth1 at 10.0.0.2), a
57-case suite run against this series and against master:
master: 37 cases reached, 22 passed (the suite aborts at the case
that adds a port to a second
bridge, see commit 2)
this series: 57 cases reached, 55 passed
The two failures are the same on both sides and come from the expectations of
the test script, not from the driver: for "add a port that does not exist" it
waits for ENODEV and the ioctl returns ENOTTY (25), and for "add the loopback
device" it waits for EINVAL and the bridge returns ENOTSUP (95), because the
loopback device has no lower half.
Forwarding and flooding:
ns0 -> ns1 through the bridge (ARP broadcast + unicast) 10/10
ns1 -> ns0 10/10
1500-byte full-MTU frame (DF) 5/5
ns0 -> br0 (the local host) 10/10
NuttX br0 -> ns0 5/5
1400-byte ICMP to br0 5/5
multicast forwarded to the other port 5/5
broadcast forwarded to the other port 5/5
unknown unicast flooded 5/5
802.1D reserved group 01:80:C2:00:00:00 not forwarded 0 frames
LLDP 01:80:C2:00:00:0E not forwarded 0 frames
destination on the ingress port dropped 0 frames
forwarded unicast MAC not rewritten (captured) 5 frames
Throughput:
iperf3 TCP ns0 -> ns1 through the bridge, 10 s 766 Mbit/s, 52 retrans
iperf3 UDP 20 Mbit/s, 10 s 0.00% loss (0/17264),
0.831 ms jitter
iperf2 TCP ns0 -> br0 (local receive), 10 s 431 Mbit/s
iperf2 TCP br0 -> ns0 (local send), 10 s 363 Mbit/s
iperf2 TCP ns0 -> eth0, no bridge, 10 s 396 Mbit/s
iperf2 TCP eth0 -> ns0, no bridge, 10 s 382 Mbit/s
Stress and leaks:
flood ping forwarded + local flood + NuttX ping, concurrent
forwarded 5000/5000, local 2000/2000, from NuttX 20/20
20 delif/addif cycles under forwarding load alive, then ping 5/5
IOB after all traffic ntotal=256 nfree=256
30 addbr/addif/delbr cycles heap unchanged
(1935144 before/after)
br0 up: delbr refused EBUSY
delbr with ports attached, under load OK, system alive
after delbr, eth0 works as a plain device 5/5
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]