From patchwork Tue Dec 11 05:55:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zhang X-Patchwork-Id: 48627 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D3DB94C74; Tue, 11 Dec 2018 06:53:58 +0100 (CET) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id A91D42C6A for ; Tue, 11 Dec 2018 06:53:55 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Dec 2018 21:53:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,341,1539673200"; d="scan'208";a="301115129" Received: from dpdk51.sh.intel.com ([10.67.110.190]) by fmsmga006.fm.intel.com with ESMTP; 10 Dec 2018 21:53:53 -0800 From: Qi Zhang To: ferruh.yigit@intel.com, bruce.richardson@intel.com, keith.wiles@intel.com, konstantin.ananyev@intel.com Cc: dev@dpdk.org, wenzhuo.lu@intel.com, bernard.iremonger@intel.com, Qi Zhang Date: Tue, 11 Dec 2018 13:55:10 +0800 Message-Id: <20181211055511.32284-3-qi.z.zhang@intel.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20181211055511.32284-1-qi.z.zhang@intel.com> References: <20181122172632.6229-1-qi.z.zhang@intel.com> <20181211055511.32284-1-qi.z.zhang@intel.com> Subject: [dpdk-dev] [PATCH v2 2/3] app/testpmd: improve MAC swap performance for x86 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The patch optimizes the mac swap operation by taking advantage of SSE instructions, it only impacts x86 platform. Signed-off-by: Qi Zhang --- app/test-pmd/macswap.c | 4 ++++ app/test-pmd/macswap_common.h | 1 - app/test-pmd/macswap_sse.h | 45 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 app/test-pmd/macswap_sse.h diff --git a/app/test-pmd/macswap.c b/app/test-pmd/macswap.c index 849194fe2..cbb41b728 100644 --- a/app/test-pmd/macswap.c +++ b/app/test-pmd/macswap.c @@ -66,7 +66,11 @@ #include #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_common.h b/app/test-pmd/macswap_common.h index ab0a5b5ef..8c5518596 100644 --- a/app/test-pmd/macswap_common.h +++ b/app/test-pmd/macswap_common.h @@ -44,4 +44,3 @@ mbuf_field_set(struct rte_mbuf *mb, uint64_t ol_flags) } #endif /* _BPF_CMD_H_ */ - diff --git a/app/test-pmd/macswap_sse.h b/app/test-pmd/macswap_sse.h new file mode 100644 index 000000000..79f4f9a7c --- /dev/null +++ b/app/test-pmd/macswap_sse.h @@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#ifndef _L2FWD_SSE_H_ +#define _L2FWD_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; + __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 /* _BPF_CMD_H_ */ +