aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/devices/af_packet/device.c
diff options
context:
space:
mode:
authorAnton Ivanov <anton.ivanov@cambridgegreys.com>2017-10-03 10:08:05 +0100
committerDamjan Marion <dmarion.lists@gmail.com>2017-10-04 09:42:23 +0000
commit3eab064e3fadaf2a6a128f167ad04ca0319b4e17 (patch)
tree3655480915e5d403efae47cbaec9d83262fb9fcb /src/vnet/devices/af_packet/device.c
parent28029530963223c5c3b94f7a2f9d1343662a1a04 (diff)
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 <anton.ivanov@cambridgegreys.com>
Diffstat (limited to 'src/vnet/devices/af_packet/device.c')
-rw-r--r--src/vnet/devices/af_packet/device.c30
1 files changed, 29 insertions, 1 deletions
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 <net/if.h>
#include <net/if_arp.h>
+#include <linux/virtio_net.h>
+
#include <vlib/vlib.h>
#include <vlib/unix/unix.h>
#include <vnet/ip/ip.h>
@@ -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,