Skip to contentSkip to conversation

app/testpmd: improve MAC swap performance

PATCH In review Qi Zhang 3 participants 11 messages Nov 20, 2018 – Nov 27, 2018

lore
Share & tools
lore

Qi Zhang

author
#0 lore raw

PATCH 1/1 app/testpmd: improve MAC swap performance

The patch optimizes the mac swap operation by taking advantage of SSE instructions, it only impacts x86 platform.

---
 app/test-pmd/macswap.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
app/test-pmd/macswap.c +15 -1
index a8384d5b8..0722782b0 100644
@@ -78,7 +78,6 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	struct rte_port  *txp;
 	struct rte_mbuf  *mb;
 	struct ether_hdr *eth_hdr;
-	struct ether_addr addr;
 	uint16_t nb_rx;
 	uint16_t nb_tx;
 	uint16_t i;
@@ -95,6 +94,15 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	start_tsc = rte_rdtsc();
 #endif
 
+#ifdef RTE_ARCH_X86
+	__m128i addr;
+	__m128i shfl_msk = _mm_set_epi8(15, 14, 13, 12,
+					5, 4, 3, 2,
+					1, 0, 11, 10,
+					9, 8, 7, 6);
+#else
+	struct ether_addr addr;
+#endif
 	/*
 	 * Receive a burst of packets and forward them.
 	 */
@@ -123,9 +131,15 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 		eth_hdr = rte_pktmbuf_mtod(mb, struct ether_hdr *);
 
 		/* Swap dest and src mac addresses. */
+#ifdef RTE_ARCH_X86
+		addr = _mm_loadu_si128((__m128i *)eth_hdr);
+		addr = _mm_shuffle_epi8(addr, shfl_msk);
+		_mm_storeu_si128((__m128i *)eth_hdr, addr);
+#else
 		ether_addr_copy(&eth_hdr->d_addr, &addr);
 		ether_addr_copy(&eth_hdr->s_addr, &eth_hdr->d_addr);
 		ether_addr_copy(&addr, &eth_hdr->s_addr);
+#endif
 
 		mb->ol_flags &= IND_ATTACHED_MBUF | EXT_ATTACHED_MBUF;
 		mb->ol_flags |= ol_flags;
Signature · 1 line
2.13.6
#1 lore raw

Hi Qi,

Quoted 33 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Qi Zhang
Sent: Tuesday, November 20, 2018 4:46 AM
To: Richardson, Bruce <[email protected]>; Wiles, Keith <[email protected]>
Cc: [email protected]; Lu, Wenzhuo <[email protected]>; Iremonger, Bernard <[email protected]>; Zhang, Qi Z <[email protected]>; [email protected]
Subject: [dpdk-dev] [PATCH] app/testpmd: improve MAC swap performance

The patch optimizes the mac swap operation by taking advantage of SSE instructions, it only impacts x86 platform.

---
 app/test-pmd/macswap.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
app/test-pmd/macswap.c +0 -1
index a8384d5b8..0722782b0 100644
@@ -78,7 +78,6 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	struct rte_port  *txp;
 	struct rte_mbuf  *mb;
 	struct ether_hdr *eth_hdr;
-	struct ether_addr addr;
 	uint16_t nb_rx;
 	uint16_t nb_tx;
 	uint16_t i;
@@ -95,6 +94,15 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	start_tsc = rte_rdtsc();
 #endif

app/test-pmd/macswap.c pkt_burst_mac_swap(struct fwd_stream *fs) · line 105

Quoted 10 lines
app/test-pmd/macswap.c +9 -0
 
+#ifdef RTE_ARCH_X86
+	__m128i addr;
+	__m128i shfl_msk = _mm_set_epi8(15, 14, 13, 12,
+					5, 4, 3, 2,
+					1, 0, 11, 10,
+					9, 8, 7, 6);
+#else
+	struct ether_addr addr;
+#endif

I think it would better to place IA specific code into a separate fnction (and probably into a separate .h file).
BTW, just curious what % of improvement it gives?
Konstantin

Quoted 21 lines
app/test-pmd/macswap.c +6 -1
 	/*
 	 * Receive a burst of packets and forward them.
 	 */
@@ -123,9 +131,15 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 		eth_hdr = rte_pktmbuf_mtod(mb, struct ether_hdr *);
 
 		/* Swap dest and src mac addresses. */
+#ifdef RTE_ARCH_X86
+		addr = _mm_loadu_si128((__m128i *)eth_hdr);
+		addr = _mm_shuffle_epi8(addr, shfl_msk);
+		_mm_storeu_si128((__m128i *)eth_hdr, addr);
+#else
 		ether_addr_copy(&eth_hdr->d_addr, &addr);
 		ether_addr_copy(&eth_hdr->s_addr, &eth_hdr->d_addr);
 		ether_addr_copy(&addr, &eth_hdr->s_addr);
+#endif
 
 		mb->ol_flags &= IND_ATTACHED_MBUF | EXT_ATTACHED_MBUF;
 		mb->ol_flags |= ol_flags;
--

2.13.6

#2 lore raw
Quoted 40 lines · Konstantin

Hi Qi,

Quoted 34 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Qi Zhang
Sent: Tuesday, November 20, 2018 4:46 AM
To: Richardson, Bruce <[email protected]>; Wiles, Keith <[email protected]>
Cc: [email protected]; Lu, Wenzhuo <[email protected]>; Iremonger, Bernard <[email protected]>; Zhang, Qi Z <[email protected]>; [email protected]
Subject: [dpdk-dev] [PATCH] app/testpmd: improve MAC swap performance

The patch optimizes the mac swap operation by taking advantage of SSE instructions, it only impacts x86 platform.

---
app/test-pmd/macswap.c | 16 +++++++++++++++-

1 file changed, 15 insertions(+), 1 deletion(-)
app/test-pmd/macswap.c +0 -1
index a8384d5b8..0722782b0 100644
@@ -78,7 +78,6 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	struct rte_port  *txp;
 	struct rte_mbuf  *mb;
 	struct ether_hdr *eth_hdr;
-	struct ether_addr addr;
 	uint16_t nb_rx;
 	uint16_t nb_tx;
 	uint16_t i;
@@ -95,6 +94,15 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	start_tsc = rte_rdtsc();
 #endif
 
Quoted 15 lines

app/test-pmd/macswap.c pkt_burst_mac_swap(struct fwd_stream *fs) · line 105

Quoted 9 lines
app/test-pmd/macswap.c +9 -0
+#ifdef RTE_ARCH_X86
+	__m128i addr;
+	__m128i shfl_msk = _mm_set_epi8(15, 14, 13, 12,
+					5, 4, 3, 2,
+					1, 0, 11, 10,
+					9, 8, 7, 6);
+#else
+	struct ether_addr addr;
+#endif

I think it would better to place IA specific code into a separate fnction (and probably into a separate .h file).
BTW, just curious what % of improvement it gives?
Konstantin

If we are going to the trouble of moving the code out of the .c into a .h then I suggest it be placed into the rte_ethdev headers for everyone to use.

Quoted 18 lines
Quoted 18 lines
app/test-pmd/macswap.c +6 -0
 	/*
 	 * Receive a burst of packets and forward them.
 	 */
@@ -123,9 +131,15 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 		eth_hdr = rte_pktmbuf_mtod(mb, struct ether_hdr *);
 
 		/* Swap dest and src mac addresses. */
+#ifdef RTE_ARCH_X86
+		addr = _mm_loadu_si128((__m128i *)eth_hdr);
+		addr = _mm_shuffle_epi8(addr, shfl_msk);
+		_mm_storeu_si128((__m128i *)eth_hdr, addr);
+#else
 		ether_addr_copy(&eth_hdr->d_addr, &addr);
 		ether_addr_copy(&eth_hdr->s_addr, &eth_hdr->d_addr);
 		ether_addr_copy(&addr, &eth_hdr->s_addr);
+#endif
 
Quoted 4 lines
Quoted 4 lines
app/test-pmd/macswap.c +0 -1
 		mb->ol_flags &= IND_ATTACHED_MBUF | EXT_ATTACHED_MBUF;
 		mb->ol_flags |= ol_flags;
--

2.13.6

Regards,
Keith

#3 lore raw
In reply to Ananyev, Konstantin
Quoted 50 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Tuesday, November 20, 2018 1:17 AM
To: Zhang, Qi Z <[email protected]>; Richardson, Bruce <[email protected]>; Wiles, Keith <[email protected]>
Cc: [email protected]; Lu, Wenzhuo <[email protected]>; Iremonger, Bernard <[email protected]>; Zhang, Qi Z <[email protected]>; [email protected]
Subject: RE: [dpdk-dev] [PATCH] app/testpmd: improve MAC swap performance

Hi Qi,

Quoted 36 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Qi Zhang
Sent: Tuesday, November 20, 2018 4:46 AM
To: Richardson, Bruce <[email protected]>; Wiles, Keith <[email protected]>
Cc: [email protected]; Lu, Wenzhuo <[email protected]>; Iremonger, Bernard <[email protected]>; Zhang, Qi Z <[email protected]>; [email protected]
Subject: [dpdk-dev] [PATCH] app/testpmd: improve MAC swap performance

The patch optimizes the mac swap operation by taking advantage of SSE instructions, it only impacts x86 platform.

---
 app/test-pmd/macswap.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
app/test-pmd/macswap.c index renamed from app/test-pmd/macswap.c +0 -0

a8384d5b8..0722782b0 100644

app/test-pmd/macswap.c +0 -1
@@ -78,7 +78,6 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	struct rte_port  *txp;
 	struct rte_mbuf  *mb;
 	struct ether_hdr *eth_hdr;
-	struct ether_addr addr;
 	uint16_t nb_rx;
 	uint16_t nb_tx;
 	uint16_t i;
@@ -95,6 +94,15 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	start_tsc = rte_rdtsc();
 #endif
 
Quoted 12 lines

app/test-pmd/macswap.c pkt_burst_mac_swap(struct fwd_stream *fs) · line 105

Quoted 9 lines
app/test-pmd/macswap.c +9 -0
+#ifdef RTE_ARCH_X86
+	__m128i addr;
+	__m128i shfl_msk = _mm_set_epi8(15, 14, 13, 12,
+					5, 4, 3, 2,
+					1, 0, 11, 10,
+					9, 8, 7, 6);
+#else
+	struct ether_addr addr;
+#endif

I think it would better to place IA specific code into a separate fnction (and probably into a separate .h file).

OK, I will think about how to rework this.

Quoted 1 line

BTW, just curious what % of improvement it gives?

So far , the only server I can test is a 1.6GHz Broadwell server with 2 ports on 1 i40e 25G. The macswap performance is increase from 16.8mpps to 20mpps (about 19% improvement)

Quoted 23 lines

Konstantin

Quoted 20 lines
app/test-pmd/macswap.c +5 -1
 	/*
 	 * Receive a burst of packets and forward them.
 	 */
@@ -123,9 +131,15 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 		eth_hdr = rte_pktmbuf_mtod(mb, struct ether_hdr *);
 
 		/* Swap dest and src mac addresses. */
+#ifdef RTE_ARCH_X86
+		addr = _mm_loadu_si128((__m128i *)eth_hdr);
+		addr = _mm_shuffle_epi8(addr, shfl_msk);
+		_mm_storeu_si128((__m128i *)eth_hdr, addr); #else
 		ether_addr_copy(&eth_hdr->d_addr, &addr);
 		ether_addr_copy(&eth_hdr->s_addr, &eth_hdr->d_addr);
 		ether_addr_copy(&addr, &eth_hdr->s_addr);
+#endif
 
 		mb->ol_flags &= IND_ATTACHED_MBUF | EXT_ATTACHED_MBUF;
 		mb->ol_flags |= ol_flags;
--

2.13.6

#4 lore raw
Quoted 73 lines

-----Original Message-----
From: Zhang, Qi Z
Sent: Tuesday, November 20, 2018 4:58 PM
To: Ananyev, Konstantin <[email protected]>; Richardson, Bruce <[email protected]>; Wiles, Keith <[email protected]>
Cc: [email protected]; Lu, Wenzhuo <[email protected]>; Iremonger, Bernard <[email protected]>; [email protected]
Subject: RE: [dpdk-dev] [PATCH] app/testpmd: improve MAC swap performance

Quoted 48 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Tuesday, November 20, 2018 1:17 AM
To: Zhang, Qi Z <[email protected]>; Richardson, Bruce <[email protected]>; Wiles, Keith <[email protected]>
Cc: [email protected]; Lu, Wenzhuo <[email protected]>; Iremonger, Bernard <[email protected]>; Zhang, Qi Z <[email protected]>; [email protected]
Subject: RE: [dpdk-dev] [PATCH] app/testpmd: improve MAC swap performance

Hi Qi,

Quoted 36 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Qi Zhang
Sent: Tuesday, November 20, 2018 4:46 AM
To: Richardson, Bruce <[email protected]>; Wiles, Keith <[email protected]>
Cc: [email protected]; Lu, Wenzhuo <[email protected]>; Iremonger, Bernard <[email protected]>; Zhang, Qi Z <[email protected]>; [email protected]
Subject: [dpdk-dev] [PATCH] app/testpmd: improve MAC swap performance

The patch optimizes the mac swap operation by taking advantage of SSE instructions, it only impacts x86 platform.

---
 app/test-pmd/macswap.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
app/test-pmd/macswap.c index renamed from app/test-pmd/macswap.c +0 -0

a8384d5b8..0722782b0 100644

app/test-pmd/macswap.c +0 -1
@@ -78,7 +78,6 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	struct rte_port  *txp;
 	struct rte_mbuf  *mb;
 	struct ether_hdr *eth_hdr;
-	struct ether_addr addr;
 	uint16_t nb_rx;
 	uint16_t nb_tx;
 	uint16_t i;
@@ -95,6 +94,15 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	start_tsc = rte_rdtsc();
 #endif
 
Quoted 12 lines

app/test-pmd/macswap.c pkt_burst_mac_swap(struct fwd_stream *fs) · line 105

Quoted 9 lines
app/test-pmd/macswap.c +9 -0
+#ifdef RTE_ARCH_X86
+	__m128i addr;
+	__m128i shfl_msk = _mm_set_epi8(15, 14, 13, 12,
+					5, 4, 3, 2,
+					1, 0, 11, 10,
+					9, 8, 7, 6);
+#else
+	struct ether_addr addr;
+#endif

I think it would better to place IA specific code into a separate fnction (and probably into a separate .h file).

Quoted 1 line

OK, I will think about how to rework this.

Ideally would be good to have an generic one, and IA optimized version.

Quoted 5 lines
Quoted 2 lines

BTW, just curious what % of improvement it gives?

So far , the only server I can test is a 1.6GHz Broadwell server with 2 ports on 1 i40e 25G. The macswap performance is increase from 16.8mpps to 20mpps (about 19% improvement)

Quite a lot, definitely looks like worth it.

Quoted 24 lines
Quoted 24 lines

Konstantin

Quoted 20 lines
app/test-pmd/macswap.c +5 -1
 	/*
 	 * Receive a burst of packets and forward them.
 	 */
@@ -123,9 +131,15 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 		eth_hdr = rte_pktmbuf_mtod(mb, struct ether_hdr *);
 
 		/* Swap dest and src mac addresses. */
+#ifdef RTE_ARCH_X86
+		addr = _mm_loadu_si128((__m128i *)eth_hdr);
+		addr = _mm_shuffle_epi8(addr, shfl_msk);
+		_mm_storeu_si128((__m128i *)eth_hdr, addr); #else
 		ether_addr_copy(&eth_hdr->d_addr, &addr);
 		ether_addr_copy(&eth_hdr->s_addr, &eth_hdr->d_addr);
 		ether_addr_copy(&addr, &eth_hdr->s_addr);
+#endif
 
 		mb->ol_flags &= IND_ATTACHED_MBUF | EXT_ATTACHED_MBUF;
 		mb->ol_flags |= ol_flags;
--

2.13.6

#5 lore raw
In reply to Zhang, Qi Z
Quoted 87 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Tuesday, November 20, 2018 5:26 PM
To: Zhang, Qi Z <[email protected]>; Richardson, Bruce <[email protected]>; Wiles, Keith <[email protected]>
Cc: [email protected]; Lu, Wenzhuo <[email protected]>; Iremonger, Bernard <[email protected]>; [email protected]
Subject: RE: [dpdk-dev] [PATCH] app/testpmd: improve MAC swap performance

Quoted 71 lines

-----Original Message-----
From: Zhang, Qi Z
Sent: Tuesday, November 20, 2018 4:58 PM
To: Ananyev, Konstantin <[email protected]>; Richardson, Bruce <[email protected]>; Wiles, Keith <[email protected]>
Cc: [email protected]; Lu, Wenzhuo <[email protected]>; Iremonger, Bernard <[email protected]>; [email protected]
Subject: RE: [dpdk-dev] [PATCH] app/testpmd: improve MAC swap performance

Quoted 48 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Tuesday, November 20, 2018 1:17 AM
To: Zhang, Qi Z <[email protected]>; Richardson, Bruce <[email protected]>; Wiles, Keith <[email protected]>
Cc: [email protected]; Lu, Wenzhuo <[email protected]>; Iremonger, Bernard <[email protected]>; Zhang, Qi Z <[email protected]>; [email protected]
Subject: RE: [dpdk-dev] [PATCH] app/testpmd: improve MAC swap performance

Hi Qi,

Quoted 36 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Qi Zhang
Sent: Tuesday, November 20, 2018 4:46 AM
To: Richardson, Bruce <[email protected]>; Wiles, Keith <[email protected]>
Cc: [email protected]; Lu, Wenzhuo <[email protected]>; Iremonger, Bernard <[email protected]>; Zhang, Qi Z <[email protected]>; [email protected]
Subject: [dpdk-dev] [PATCH] app/testpmd: improve MAC swap performance

The patch optimizes the mac swap operation by taking advantage of SSE instructions, it only impacts x86 platform.

---
 app/test-pmd/macswap.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
app/test-pmd/macswap.c index renamed from app/test-pmd/macswap.c +0 -0

a8384d5b8..0722782b0 100644

app/test-pmd/macswap.c +0 -1
@@ -78,7 +78,6 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	struct rte_port  *txp;
 	struct rte_mbuf  *mb;
 	struct ether_hdr *eth_hdr;
-	struct ether_addr addr;
 	uint16_t nb_rx;
 	uint16_t nb_tx;
 	uint16_t i;
@@ -95,6 +94,15 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	start_tsc = rte_rdtsc();
 #endif
 
Quoted 12 lines

app/test-pmd/macswap.c pkt_burst_mac_swap(struct fwd_stream *fs) · line 105

Quoted 9 lines
app/test-pmd/macswap.c +9 -0
+#ifdef RTE_ARCH_X86
+	__m128i addr;
+	__m128i shfl_msk = _mm_set_epi8(15, 14, 13, 12,
+					5, 4, 3, 2,
+					1, 0, 11, 10,
+					9, 8, 7, 6);
+#else
+	struct ether_addr addr;
+#endif

I think it would better to place IA specific code into a separate fnction (and probably into a separate .h file).

Quoted 1 line

OK, I will think about how to rework this.

Ideally would be good to have an generic one, and IA optimized version.

Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

BTW, just curious what % of improvement it gives?

So far , the only server I can test is a 1.6GHz Broadwell server with 2 ports on 1 i40e 25G. The macswap performance is increase from 16.8mpps to 20mpps (about 19% improvement)

Quite a lot, definitely looks like worth it.

You probably can squeeze few more cycles doing it in bulks of 4 or so. Konstantin

#6 lore raw
Quoted 104 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Tuesday, November 20, 2018 2:54 PM
To: Zhang, Qi Z <[email protected]>; Richardson, Bruce <[email protected]>; Wiles, Keith <[email protected]>
Cc: [email protected]; Lu, Wenzhuo <[email protected]>; Iremonger, Bernard <[email protected]>; [email protected]
Subject: RE: [dpdk-dev] [PATCH] app/testpmd: improve MAC swap performance

Quoted 91 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Tuesday, November 20, 2018 5:26 PM
To: Zhang, Qi Z <[email protected]>; Richardson, Bruce <[email protected]>; Wiles, Keith <[email protected]>
Cc: [email protected]; Lu, Wenzhuo <[email protected]>; Iremonger, Bernard <[email protected]>; [email protected]
Subject: RE: [dpdk-dev] [PATCH] app/testpmd: improve MAC swap performance

Quoted 78 lines

-----Original Message-----
From: Zhang, Qi Z
Sent: Tuesday, November 20, 2018 4:58 PM
To: Ananyev, Konstantin <[email protected]>; Richardson, Bruce <[email protected]>; Wiles, Keith <[email protected]>
Cc: [email protected]; Lu, Wenzhuo <[email protected]>; Iremonger, Bernard <[email protected]>; [email protected]
Subject: RE: [dpdk-dev] [PATCH] app/testpmd: improve MAC swap performance

Quoted 51 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Tuesday, November 20, 2018 1:17 AM
To: Zhang, Qi Z <[email protected]>; Richardson, Bruce <[email protected]>; Wiles, Keith <[email protected]>
Cc: [email protected]; Lu, Wenzhuo <[email protected]>; Iremonger, Bernard <[email protected]>; Zhang, Qi Z <[email protected]>; [email protected]
Subject: RE: [dpdk-dev] [PATCH] app/testpmd: improve MAC swap performance

Hi Qi,

Quoted 38 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Qi Zhang
Sent: Tuesday, November 20, 2018 4:46 AM
To: Richardson, Bruce <[email protected]>; Wiles, Keith <[email protected]>
Cc: [email protected]; Lu, Wenzhuo <[email protected]>; Iremonger, Bernard <[email protected]>; Zhang, Qi Z <[email protected]>; [email protected]
Subject: [dpdk-dev] [PATCH] app/testpmd: improve MAC swap performance

The patch optimizes the mac swap operation by taking advantage of SSE instructions, it only impacts x86 platform.

---
 app/test-pmd/macswap.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
app/test-pmd/macswap.c +0 -0

index
a8384d5b8..0722782b0 100644

app/test-pmd/macswap.c +0 -1
@@ -78,7 +78,6 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	struct rte_port  *txp;
 	struct rte_mbuf  *mb;
 	struct ether_hdr *eth_hdr;
-	struct ether_addr addr;
 	uint16_t nb_rx;
 	uint16_t nb_tx;
 	uint16_t i;
@@ -95,6 +94,15 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	start_tsc = rte_rdtsc();
 #endif
 
Quoted 12 lines

app/test-pmd/macswap.c pkt_burst_mac_swap(struct fwd_stream *fs) · line 105

Quoted 9 lines
app/test-pmd/macswap.c +9 -0
+#ifdef RTE_ARCH_X86
+	__m128i addr;
+	__m128i shfl_msk = _mm_set_epi8(15, 14, 13, 12,
+					5, 4, 3, 2,
+					1, 0, 11, 10,
+					9, 8, 7, 6);
+#else
+	struct ether_addr addr;
+#endif

I think it would better to place IA specific code into a separate fnction (and probably into a separate .h file).

OK, I will think about how to rework this.

Quoted 9 lines
Quoted 6 lines

Ideally would be good to have an generic one, and IA optimized version.

Quoted 4 lines
Quoted 2 lines

BTW, just curious what % of improvement it gives?

So far , the only server I can test is a 1.6GHz Broadwell server with 2 ports on

1 i40e 25G.

Quoted 2 lines
Quoted 2 lines

The macswap performance is increase from 16.8mpps to 20mpps (about 19% improvement)

I need to add a notice here, I found previous test is running on CPU from remote socket.
For the test on CPU from local socket on the same server, actually the mac swap performance is improved from 23.34 to 26.36, its about 12.9% increase, but still considerable.

Quoted 4 lines
Quoted 2 lines

Quite a lot, definitely looks like worth it.

You probably can squeeze few more cycles doing it in bulks of 4 or so.

it's a good idea, based on my experience I can get more than 4% increase by batch with 4, it can reach 27.46mpps, so now its 17.7% increase, I will send patch later, please help to polish:)

Thanks
Qi

Quoted 1 line

Konstantin

#7 lore raw
In reply to Qi Zhang
Quoted 27 lines · Qi Z

The patch optimizes the mac swap operation by taking advantage of SSE instructions, it only impacts x86 platform.

---
app/test-pmd/macswap.c | 16 +++++++++++++++-

1 file changed, 15 insertions(+), 1 deletion(-)
app/test-pmd/macswap.c +0 -1
index a8384d5b8..0722782b0 100644
@@ -78,7 +78,6 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	struct rte_port  *txp;
 	struct rte_mbuf  *mb;
 	struct ether_hdr *eth_hdr;
-	struct ether_addr addr;
 	uint16_t nb_rx;
 	uint16_t nb_tx;
 	uint16_t i;

app/test-pmd/macswap.c pkt_burst_mac_swap(struct fwd_stream *fs) · line 102

Quoted 9 lines
app/test-pmd/macswap.c +6 -0
@@ -95,6 +94,15 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	start_tsc = rte_rdtsc();
 #endif
 
+#ifdef RTE_ARCH_X86
+	__m128i addr;
+	__m128i shfl_msk = _mm_set_epi8(15, 14, 13, 12,
+					5, 4, 3, 2,
+					1, 0, 11, 10,
+					9, 8, 7, 6);

I was playing around with these mask values and I was not able to make it work as I expected. I ended up with different values in the mask.

_mm_set_epi8(15, 14, 13, 12, 5, 4, 3, 2, 1, 0, 11, 10, 9, 8, 7, 6);

After dumping the memory for a large number of tests this one seems correct, can you verify your mask is correct?

Quoted 25 lines
app/test-pmd/macswap.c +9 -0
+#else
+	struct ether_addr addr;
+#endif
 	/*
 	 * Receive a burst of packets and forward them.
 	 */
@@ -123,9 +131,15 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 		eth_hdr = rte_pktmbuf_mtod(mb, struct ether_hdr *);
 
 		/* Swap dest and src mac addresses. */
+#ifdef RTE_ARCH_X86
+		addr = _mm_loadu_si128((__m128i *)eth_hdr);
+		addr = _mm_shuffle_epi8(addr, shfl_msk);
+		_mm_storeu_si128((__m128i *)eth_hdr, addr);
+#else
 		ether_addr_copy(&eth_hdr->d_addr, &addr);
 		ether_addr_copy(&eth_hdr->s_addr, &eth_hdr->d_addr);
 		ether_addr_copy(&addr, &eth_hdr->s_addr);
+#endif
 
 		mb->ol_flags &= IND_ATTACHED_MBUF | EXT_ATTACHED_MBUF;
 		mb->ol_flags |= ol_flags;
Signature · 1 line
2.13.6

Regards,
Keith

#8 lore raw
In reply to Qi Zhang
Quoted 27 lines · Qi Z

The patch optimizes the mac swap operation by taking advantage of SSE instructions, it only impacts x86 platform.

---
app/test-pmd/macswap.c | 16 +++++++++++++++-

1 file changed, 15 insertions(+), 1 deletion(-)
app/test-pmd/macswap.c +0 -1
index a8384d5b8..0722782b0 100644
@@ -78,7 +78,6 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	struct rte_port  *txp;
 	struct rte_mbuf  *mb;
 	struct ether_hdr *eth_hdr;
-	struct ether_addr addr;
 	uint16_t nb_rx;
 	uint16_t nb_tx;
 	uint16_t i;

app/test-pmd/macswap.c pkt_burst_mac_swap(struct fwd_stream *fs) · line 102

Quoted 9 lines
app/test-pmd/macswap.c +6 -0
@@ -95,6 +94,15 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	start_tsc = rte_rdtsc();
 #endif
 
+#ifdef RTE_ARCH_X86
+	__m128i addr;
+	__m128i shfl_msk = _mm_set_epi8(15, 14, 13, 12,
+					5, 4, 3, 2,
+					1, 0, 11, 10,
+					9, 8, 7, 6);

I was playing around with these mask values and I was not able to make it work as I expected. I ended up with different values in the mask.

_mm_set_epi8(15, 14, 13, 12, 5, 4, 3, 2, 1, 0, 11, 10, 9, 8, 7, 6);

After dumping the memory for a large number of tests this one seems correct, can you verify your mask is correct?

Quoted 25 lines
app/test-pmd/macswap.c +9 -0
+#else
+	struct ether_addr addr;
+#endif
 	/*
 	 * Receive a burst of packets and forward them.
 	 */
@@ -123,9 +131,15 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 		eth_hdr = rte_pktmbuf_mtod(mb, struct ether_hdr *);
 
 		/* Swap dest and src mac addresses. */
+#ifdef RTE_ARCH_X86
+		addr = _mm_loadu_si128((__m128i *)eth_hdr);
+		addr = _mm_shuffle_epi8(addr, shfl_msk);
+		_mm_storeu_si128((__m128i *)eth_hdr, addr);
+#else
 		ether_addr_copy(&eth_hdr->d_addr, &addr);
 		ether_addr_copy(&eth_hdr->s_addr, &eth_hdr->d_addr);
 		ether_addr_copy(&addr, &eth_hdr->s_addr);
+#endif
 
 		mb->ol_flags &= IND_ATTACHED_MBUF | EXT_ATTACHED_MBUF;
 		mb->ol_flags |= ol_flags;
Signature · 1 line
2.13.6

Regards,
Keith

#9 lore raw
Quoted 44 lines · Keith
Quoted 28 lines · Qi Z

The patch optimizes the mac swap operation by taking advantage of SSE instructions, it only impacts x86 platform.

---
app/test-pmd/macswap.c | 16 +++++++++++++++-

1 file changed, 15 insertions(+), 1 deletion(-)
app/test-pmd/macswap.c +0 -1
index a8384d5b8..0722782b0 100644
@@ -78,7 +78,6 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	struct rte_port  *txp;
 	struct rte_mbuf  *mb;
 	struct ether_hdr *eth_hdr;
-	struct ether_addr addr;
 	uint16_t nb_rx;
 	uint16_t nb_tx;
 	uint16_t i;

app/test-pmd/macswap.c pkt_burst_mac_swap(struct fwd_stream *fs) · line 102

Quoted 9 lines
app/test-pmd/macswap.c +6 -0
@@ -95,6 +94,15 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	start_tsc = rte_rdtsc();
 #endif
 
+#ifdef RTE_ARCH_X86
+	__m128i addr;
+	__m128i shfl_msk = _mm_set_epi8(15, 14, 13, 12,
+					5, 4, 3, 2,
+					1, 0, 11, 10,
+					9, 8, 7, 6);

I was playing around with these mask values and I was not able to make it work as I expected. I ended up with different values in the mask.

Quoted 3 lines

_mm_set_epi8(15, 14, 13, 12, 5, 4, 3, 2, 1, 0, 11, 10, 9, 8, 7, 6);

After dumping the memory for a large number of tests this one seems correct, can you verify your mask is correct?

Sorry, I do not know why I thought the code was not the same, but your example is correct my mistake.

Quoted 21 lines
Quoted 21 lines
app/test-pmd/macswap.c +9 -0
+#else
+	struct ether_addr addr;
+#endif
 	/*
 	 * Receive a burst of packets and forward them.
 	 */
@@ -123,9 +131,15 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 		eth_hdr = rte_pktmbuf_mtod(mb, struct ether_hdr *);
 
 		/* Swap dest and src mac addresses. */
+#ifdef RTE_ARCH_X86
+		addr = _mm_loadu_si128((__m128i *)eth_hdr);
+		addr = _mm_shuffle_epi8(addr, shfl_msk);
+		_mm_storeu_si128((__m128i *)eth_hdr, addr);
+#else
 		ether_addr_copy(&eth_hdr->d_addr, &addr);
 		ether_addr_copy(&eth_hdr->s_addr, &eth_hdr->d_addr);
 		ether_addr_copy(&addr, &eth_hdr->s_addr);
+#endif
 
Quoted 8 lines
Quoted 5 lines
app/test-pmd/macswap.c +0 -0
 		mb->ol_flags &= IND_ATTACHED_MBUF | EXT_ATTACHED_MBUF;
 		mb->ol_flags |= ol_flags;
Signature · 1 line
2.13.6

Regards,
Keith

Regards,
Keith

#10 lore raw
Quoted 56 lines

-----Original Message-----
From: Wiles, Keith
Sent: Saturday, November 24, 2018 8:24 AM
To: Zhang, Qi Z <[email protected]>
Cc: Richardson, Bruce <[email protected]>; dev <[email protected]>; Lu, Wenzhuo <[email protected]>; Iremonger, Bernard <[email protected]>; [email protected]
Subject: Re: [PATCH] app/testpmd: improve MAC swap performance

Quoted 32 lines · Keith
Quoted 31 lines · Qi Z

The patch optimizes the mac swap operation by taking advantage of SSE instructions, it only impacts x86 platform.

---
app/test-pmd/macswap.c | 16 +++++++++++++++-

1 file changed, 15 insertions(+), 1 deletion(-)
app/test-pmd/macswap.c index renamed from app/test-pmd/macswap.c +0 -0

a8384d5b8..0722782b0 100644

app/test-pmd/macswap.c +0 -1
@@ -78,7 +78,6 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	struct rte_port  *txp;
 	struct rte_mbuf  *mb;
 	struct ether_hdr *eth_hdr;
-	struct ether_addr addr;
 	uint16_t nb_rx;
 	uint16_t nb_tx;
 	uint16_t i;
@@ -95,6 +94,15 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	start_tsc = rte_rdtsc();
 #endif
 
Quoted 8 lines

app/test-pmd/macswap.c pkt_burst_mac_swap(struct fwd_stream *fs) · line 102

Quoted 6 lines
app/test-pmd/macswap.c +6 -0
+#ifdef RTE_ARCH_X86
+	__m128i addr;
+	__m128i shfl_msk = _mm_set_epi8(15, 14, 13, 12,
+					5, 4, 3, 2,
+					1, 0, 11, 10,
+					9, 8, 7, 6);

I was playing around with these mask values and I was not able to make it

work as I expected.

Quoted 2 lines

I ended up with different values in the mask.

Quoted 7 lines
Quoted 3 lines

_mm_set_epi8(15, 14, 13, 12, 5, 4, 3, 2, 1, 0, 11, 10, 9, 8, 7, 6);

After dumping the memory for a large number of tests this one seems correct,

can you verify your mask is correct?

Sorry, I do not know why I thought the code was not the same, but your example is correct my mistake.

Thanks for review and verify this!

Regards
Qi

Quoted 31 lines
Quoted 20 lines
Quoted 20 lines
app/test-pmd/macswap.c +8 -0
+#else
+	struct ether_addr addr;
+#endif
 	/*
 	 * Receive a burst of packets and forward them.
 	 */
@@ -123,9 +131,15 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 		eth_hdr = rte_pktmbuf_mtod(mb, struct ether_hdr *);
 
 		/* Swap dest and src mac addresses. */
+#ifdef RTE_ARCH_X86
+		addr = _mm_loadu_si128((__m128i *)eth_hdr);
+		addr = _mm_shuffle_epi8(addr, shfl_msk);
+		_mm_storeu_si128((__m128i *)eth_hdr, addr); #else
 		ether_addr_copy(&eth_hdr->d_addr, &addr);
 		ether_addr_copy(&eth_hdr->s_addr, &eth_hdr->d_addr);
 		ether_addr_copy(&addr, &eth_hdr->s_addr);
+#endif
 
Quoted 8 lines
Quoted 5 lines
app/test-pmd/macswap.c +0 -1
 		mb->ol_flags &= IND_ATTACHED_MBUF | EXT_ATTACHED_MBUF;
 		mb->ol_flags |= ol_flags;
--

2.13.6

Regards,
Keith

Regards,
Keith