From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by dpdk.org (Postfix) with ESMTP id 1C05D1B94C for ; Sun, 16 Dec 2018 01:57:20 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Dec 2018 16:57:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,359,1539673200"; d="scan'208";a="118840949" Received: from dpdk51.sh.intel.com ([10.67.110.190]) by FMSMGA003.fm.intel.com with ESMTP; 15 Dec 2018 16:57:19 -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: Sun, 16 Dec 2018 08:58:35 +0800 Message-Id: <20181216005835.23679-4-qi.z.zhang@intel.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20181216005835.23679-1-qi.z.zhang@intel.com> References: <20181122172632.6229-1-qi.z.zhang@intel.com> <20181216005835.23679-1-qi.z.zhang@intel.com> Subject: [dpdk-dev] [PATCH v3 3/3] app/testpmd: further 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: , X-List-Received-Date: Sun, 16 Dec 2018 00:57:21 -0000 Do four packets macswap in same loop iterate to squeeze more CPU cycles. Signed-off-by: Qi Zhang --- app/test-pmd/macswap_sse.h | 62 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 12 deletions(-) diff --git a/app/test-pmd/macswap_sse.h b/app/test-pmd/macswap_sse.h index 79c7e9883..7d268bfbb 100644 --- a/app/test-pmd/macswap_sse.h +++ b/app/test-pmd/macswap_sse.h @@ -11,11 +11,12 @@ 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; + struct ether_hdr *eth_hdr[4]; + struct rte_mbuf *mb[4]; uint64_t ol_flags; int i; - __m128i addr; + int r; + __m128i addr0, addr1, addr2, addr3; /** * shuffle mask be used to shuffle the 16 bytes. * byte 0-5 wills be swapped with byte 6-11. @@ -30,19 +31,56 @@ do_macswap(struct rte_mbuf *pkts[], uint16_t nb, 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]; + i = 0; + r = nb; + + while (r >= 4) { + mb[0] = pkts[i++]; + eth_hdr[0] = rte_pktmbuf_mtod(mb[0], struct ether_hdr *); + addr0 = _mm_loadu_si128((__m128i *)eth_hdr[0]); + + mb[1] = pkts[i++]; + eth_hdr[1] = rte_pktmbuf_mtod(mb[1], struct ether_hdr *); + addr1 = _mm_loadu_si128((__m128i *)eth_hdr[1]); + + + mb[2] = pkts[i++]; + eth_hdr[2] = rte_pktmbuf_mtod(mb[2], struct ether_hdr *); + addr2 = _mm_loadu_si128((__m128i *)eth_hdr[2]); + + mb[3] = pkts[i++]; + eth_hdr[3] = rte_pktmbuf_mtod(mb[3], struct ether_hdr *); + addr3 = _mm_loadu_si128((__m128i *)eth_hdr[3]); - eth_hdr = rte_pktmbuf_mtod(mb, struct ether_hdr *); + addr0 = _mm_shuffle_epi8(addr0, shfl_msk); + addr1 = _mm_shuffle_epi8(addr1, shfl_msk); + addr2 = _mm_shuffle_epi8(addr2, shfl_msk); + addr3 = _mm_shuffle_epi8(addr3, shfl_msk); + + _mm_storeu_si128((__m128i *)eth_hdr[0], addr0); + _mm_storeu_si128((__m128i *)eth_hdr[1], addr1); + _mm_storeu_si128((__m128i *)eth_hdr[2], addr2); + _mm_storeu_si128((__m128i *)eth_hdr[3], addr3); + + mbuf_field_set(mb[0], ol_flags); + mbuf_field_set(mb[1], ol_flags); + mbuf_field_set(mb[2], ol_flags); + mbuf_field_set(mb[3], ol_flags); + r -= 4; + } + + for ( ; i < nb; i++) { + if (i < nb - 1) + rte_prefetch0(rte_pktmbuf_mtod(pkts[i+1], void *)); + mb[0] = pkts[i]; + eth_hdr[0] = rte_pktmbuf_mtod(mb[0], 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); + addr0 = _mm_loadu_si128((__m128i *)eth_hdr); + addr0 = _mm_shuffle_epi8(addr0, shfl_msk); + _mm_storeu_si128((__m128i *)eth_hdr[0], addr0); - mbuf_field_set(mb, ol_flags); + mbuf_field_set(mb[0], ol_flags); } } -- 2.13.6