[v2,2/3] app/testpmd: improve MAC swap performance for x86

Message ID 20181211055511.32284-3-qi.z.zhang@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series [v2,1/3] app/testpmd: code refactory for macswap |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Qi Zhang Dec. 11, 2018, 5:55 a.m. UTC
  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>
---
 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
  

Comments

Jerin Jacob Kollanukkaran Dec. 13, 2018, 7:50 p.m. UTC | #1
On Tue, 2018-12-11 at 13:55 +0800, Qi Zhang wrote:
> 
> 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>
> ---
>  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 <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_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_

Copy paste error.


> +
> +#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_ */

Copy paste error.

> +
> --
> 2.13.6
>
  
Iremonger, Bernard Dec. 14, 2018, 11:21 a.m. UTC | #2
Hi Qi,

> -----Original Message-----
> From: Zhang, Qi Z
> Sent: Tuesday, December 11, 2018 5:55 AM
> To: Yigit, Ferruh <ferruh.yigit@intel.com>; Richardson, Bruce
> <bruce.richardson@intel.com>; Wiles, Keith <keith.wiles@intel.com>;
> Ananyev, Konstantin <konstantin.ananyev@intel.com>
> Cc: dev@dpdk.org; Lu, Wenzhuo <wenzhuo.lu@intel.com>; Iremonger,
> Bernard <bernard.iremonger@intel.com>; Zhang, Qi Z
> <qi.z.zhang@intel.com>
> Subject: [PATCH v2 2/3] app/testpmd: improve MAC swap performance for
> x86
> 
> 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>
> ---
>  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 <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_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_

_L2FWD_SSE_H_  should be replaced by _MACSWAP_SSE_H_  in the lines above.

> +
> +#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;

Some comments explaining the parameters to _mm_set_epi8() would be useful.

> +	__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_ */

_BPF_CMD_H should be replaced by _MACSWAP_SSE_H_ in the line above.

> +
> --
> 2.13.6

A white space error is reported when applying this patch

Applying: app/testpmd: improve MAC swap performance for x86
.git/rebase-apply/patch:83: new blank line at EOF.

Regards,

Bernard.
  
Qi Zhang Dec. 14, 2018, 11:36 a.m. UTC | #3
> -----Original Message-----
> From: Iremonger, Bernard
> Sent: Friday, December 14, 2018 7:22 PM
> To: Zhang, Qi Z <qi.z.zhang@intel.com>; Yigit, Ferruh <ferruh.yigit@intel.com>;
> Richardson, Bruce <bruce.richardson@intel.com>; Wiles, Keith
> <keith.wiles@intel.com>; Ananyev, Konstantin <konstantin.ananyev@intel.com>
> Cc: dev@dpdk.org; Lu, Wenzhuo <wenzhuo.lu@intel.com>
> Subject: RE: [PATCH v2 2/3] app/testpmd: improve MAC swap performance for
> x86
> 
> Hi Qi,
> 
> > -----Original Message-----
> > From: Zhang, Qi Z
> > Sent: Tuesday, December 11, 2018 5:55 AM
> > To: Yigit, Ferruh <ferruh.yigit@intel.com>; Richardson, Bruce
> > <bruce.richardson@intel.com>; Wiles, Keith <keith.wiles@intel.com>;
> > Ananyev, Konstantin <konstantin.ananyev@intel.com>
> > Cc: dev@dpdk.org; Lu, Wenzhuo <wenzhuo.lu@intel.com>; Iremonger,
> > Bernard <bernard.iremonger@intel.com>; Zhang, Qi Z
> > <qi.z.zhang@intel.com>
> > Subject: [PATCH v2 2/3] app/testpmd: improve MAC swap performance for
> > x86
> >
> > 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>
> > ---
> >  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 <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_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_
> 
> _L2FWD_SSE_H_  should be replaced by _MACSWAP_SSE_H_  in the lines
> above.

Yes, during re-work, I saw this and EOF issue also, will fix

> 
> > +
> > +#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;
> 
> Some comments explaining the parameters to _mm_set_epi8() would be useful.

OK, will add.

Thanks
Qi

> 
> > +	__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_ */
> 
> _BPF_CMD_H should be replaced by _MACSWAP_SSE_H_ in the line above.
> 
> > +
> > --
> > 2.13.6
> 
> A white space error is reported when applying this patch
> 
> Applying: app/testpmd: improve MAC swap performance for x86
> .git/rebase-apply/patch:83: new blank line at EOF.
> 
> Regards,
> 
> Bernard.
>
  

Patch

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 <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_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_ */
+