app/testpmd: improve MAC swap performance for x86
authorQi Zhang <qi.z.zhang@intel.com>
Sun, 16 Dec 2018 00:58:34 +0000 (08:58 +0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 21 Dec 2018 15:22:40 +0000 (16:22 +0100)
The patch optimizes the mac swap operation by taking advantage
of SSE instructions, it only impacts x86 platform.

Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
Acked-by: Bernard Iremonger <bernard.iremonger@intel.com>
app/test-pmd/macswap.c
app/test-pmd/macswap_sse.h [new file with mode: 0644]

index 849194f..cbb41b7 100644 (file)
 #include <rte_flow.h>
 
 #include "testpmd.h"
+#ifdef RTE_ARCH_X86
+#include "macswap_sse.h"
+#else
 #include "macswap.h"
+#endif
 
 /*
  * MAC swap forwarding mode: Swap the source and the destination Ethernet
diff --git a/app/test-pmd/macswap_sse.h b/app/test-pmd/macswap_sse.h
new file mode 100644 (file)
index 0000000..79c7e98
--- /dev/null
@@ -0,0 +1,49 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+#ifndef _MACSWAP_SSE_H_
+#define _MACSWAP_SSE_H_
+
+#include "macswap_common.h"
+
+static inline void
+do_macswap(struct rte_mbuf *pkts[], uint16_t nb,
+               struct rte_port *txp)
+{
+       struct ether_hdr *eth_hdr;
+       struct rte_mbuf *mb;
+       uint64_t ol_flags;
+       int i;
+       __m128i addr;
+       /**
+        * shuffle mask be used to shuffle the 16 bytes.
+        * byte 0-5 wills be swapped with byte 6-11.
+        * byte 12-15 will keep unchanged.
+        */
+       __m128i shfl_msk = _mm_set_epi8(15, 14, 13, 12,
+                                       5, 4, 3, 2,
+                                       1, 0, 11, 10,
+                                       9, 8, 7, 6);
+
+       ol_flags = ol_flags_init(txp->dev_conf.txmode.offloads);
+       vlan_qinq_set(pkts, nb, ol_flags,
+                       txp->tx_vlan_id, txp->tx_vlan_id_outer);
+
+       for (i = 0; i < nb; i++) {
+               if (likely(i < nb - 1))
+                       rte_prefetch0(rte_pktmbuf_mtod(pkts[i+1], void *));
+               mb = pkts[i];
+
+               eth_hdr = rte_pktmbuf_mtod(mb, struct ether_hdr *);
+
+               /* Swap dest and src mac addresses. */
+               addr = _mm_loadu_si128((__m128i *)eth_hdr);
+               addr = _mm_shuffle_epi8(addr, shfl_msk);
+               _mm_storeu_si128((__m128i *)eth_hdr, addr);
+
+               mbuf_field_set(mb, ol_flags);
+       }
+}
+
+#endif /* _MACSWAP_SSE_H_ */