← All articles

Gigabit UDP from an FPGA

Where the bits go on a 1 Gb/s link, why UDP belongs in logic, and the measured gap between hardware UDP and software TCP on the same board.

IronKernel · · Networking

An FPGA that produces data faster than a soft processor can copy it needs the network path in logic. RTLNet does ARP, ping, DHCP and UDP in logic and leaves TCP to a processor. The same Nexys Video board measured both paths, so the cost of each is on record.

The ceiling on a gigabit link

A 1 Gb/s link does not carry 1 Gb/s of payload. The largest UDP payload in a standard frame is 1,472 bytes. Around it go 8 bytes of UDP header, 20 of IPv4, 14 of Ethernet and 4 of frame check, and the wire adds 8 bytes of preamble and a 12-byte gap. That is 1,538 byte times for 1,472 bytes of payload, so the most a gigabit link can deliver is about 957 Mb/s. Smaller datagrams do worse, because the 66 bytes of overhead stay the same.

Measured on the Nexys Video

A wired PC and an unmanaged switch connected the board to an iperf 2 peer. The values are Mb/s of application traffic. TCP figures are means of three runs.

PathPC to boardBoard to PC
UDP in logic, firewall on942.0944.0
TCP, lwIP on MicroBlaze V, firewall on337.7280.3
UDP on the Arty A7-100T, 100 Mb/s link94.094.4
TCP on the Arty A7-100T, 100 Mb/s link94.594.9

Both gigabit UDP runs with the firewall on reported zero lost datagrams. With the firewall off, one run reported 20 lost datagrams from board to PC. The UDP runs used iperf's 90% offered-load setting.

On the 100 Mb/s link the processor keeps up and TCP fills the wire. At a gigabit it does not: the stack on a soft processor tops out near a third of the link.

Why TCP stays in software

UDP is stateless. A datagram arrives, the headers are checked and the payload goes to a stream, all of which is a fixed pipeline. TCP holds connection state, retransmits, reorders and controls flow, and that is a great deal of logic to write and verify. We keep TCP in lwIP and move the per-byte work out of the processor instead. The hardware computes the IPv4 and TCP or UDP checksums on transmit and checks them on receive, attaching the result to the frame for the driver. lwIP keeps the connection logic. With that offload, lwIP on a MicroBlaze V reaches 337.7 Mb/s.

For a design, the split follows from the numbers. Bulk data such as video, samples and telemetry goes over UDP in logic. Commands, configuration and file transfer go over TCP through the processor.

The socket in logic

The MAC client interface is a 64-bit AXI4-Stream. A bound UDP socket delivers each datagram as two beats of metadata followed by 0 to 1,472 bytes of payload. On transmit, the application supplies the same two beats and the payload, and the core builds the Ethernet, IPv4 and UDP headers. An FPGA application never forms a packet header itself.

ARP and DHCP run in logic too, so the board gets an address and answers ping with no firmware involved.

Latency

On the gigabit link with the firewall on, a 64-byte UDP echo averaged 0.166 ms round trip, with a 99th percentile of 0.213 ms. TCP echo averaged 0.198 ms, with a 99th percentile of 0.234 ms. These are application round trips through the switch and the host, so most of the time is outside the FPGA.

What it costs in logic

The routed Ethernet image for the Nexys Video uses 23,891 LUTs, 33,968 flip-flops, 228.5 block RAM tiles and 6 DSPs. The Arty A7-100T image uses 24,981 LUTs, 36,059 flip-flops, 105.5 block RAM tiles and 6 DSPs. Those totals are for the complete designs, including the MicroBlaze V processor, its memory, the DMA and the packet classifier, not the UDP logic alone.

The classifier in front of the processor is the subject of our article on a firewall in FPGA logic. Both boards have a prebuilt bitstream on the RTLNet page that runs these tests.

Further reading

Moving data off an FPGA over Ethernet?

Send the FPGA part, the link speed and the data rate you need to carry.