From 3eab064e3fadaf2a6a128f167ad04ca0319b4e17 Mon Sep 17 00:00:00 2001 From: Anton Ivanov Date: Tue, 3 Oct 2017 10:08:05 +0100 Subject: VPP-1001 - update AF Packet Driver to for modern kernels 1. Add VNET headers support for checksumming - required to operate correctly on any recent Linux 2. Bypass QDISC on transmit - improves performance by ~ 5%. Enabled only if the macro is detected - apparently not present on archaic distributions. This still does not solve all issues with TSO - it can be fixed only by going to tpacket v3 and dynamic rx ring as well as significant changes in the TX (sendmmsg?). Change-Id: Iea14ade12586c0a8da49e6dd1012108a08bc85b3 Signed-off-by: Anton Ivanov --- src/vnet/devices/af_packet/device.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src/vnet/devices/af_packet/device.c') diff --git a/src/vnet/devices/af_packet/device.c b/src/vnet/devices/af_packet/device.c index e01b1c71b32..a48ae5cf25d 100644 --- a/src/vnet/devices/af_packet/device.c +++ b/src/vnet/devices/af_packet/device.c @@ -23,6 +23,8 @@ #include #include +#include + #include #include #include @@ -50,7 +52,6 @@ static char *af_packet_tx_func_error_strings[] = { #undef _ }; - static u8 * format_af_packet_device_name (u8 * s, va_list * args) { @@ -76,6 +77,23 @@ format_af_packet_tx_trace (u8 * s, va_list * args) return s; } + +static_always_inline void +af_packet_buffer_tx_offload (vlib_buffer_t * b, struct virtio_net_hdr *vhdr) +{ + /* For now - just mark the data as valid, + * DPDK csums on input, tap presently operates in legacy + * compatibility mode where the kernel checksums CSUM_PARTIAL + * for it and we have fixed the af_packet input + * + * In the future, locally originated frames, etc can be made + * to fit this convention so that they are not checksummed + * unless needed. + **/ + vhdr->flags = VIRTIO_NET_HDR_F_DATA_VALID; +} + + static uword af_packet_interface_tx (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) @@ -102,6 +120,10 @@ af_packet_interface_tx (vlib_main_t * vm, { u32 len; u32 offset = 0; + if (PREDICT_TRUE ((apm->flags & AF_PACKET_USES_VNET_HEADERS) != 0)) + { + offset = sizeof (struct virtio_net_hdr); + } vlib_buffer_t *b0; n_left--; u32 bi = buffers[0]; @@ -119,6 +141,12 @@ af_packet_interface_tx (vlib_main_t * vm, do { b0 = vlib_get_buffer (vm, bi); + if (PREDICT_TRUE ((apm->flags & AF_PACKET_USES_VNET_HEADERS) != 0)) + { + u8 *vh = + (u8 *) tph + TPACKET_ALIGN (sizeof (struct tpacket2_hdr)); + af_packet_buffer_tx_offload (b0, (struct virtio_net_hdr *) vh); + } len = b0->current_length; clib_memcpy ((u8 *) tph + TPACKET_ALIGN (sizeof (struct tpacket2_hdr)) + offset, -- cgit 1.2.3-korg