DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Qiu, Michael" <michael.qiu@intel.com>
To: Thomas Monjalon <thomas.monjalon@6wind.com>,
	"dev@dpdk.org" <dev@dpdk.org>
Cc: Chao Zhu <chaozhu@linux.vnet.ibm.com>
Subject: Re: [dpdk-dev] [PATCH 1/2] eal: detect endianness
Date: Thu, 4 Dec 2014 02:28:06 +0000
Message-ID: <533710CFB86FA344BFBF2D6802E60286C9C86D@SHSMSX101.ccr.corp.intel.com> (raw)
In-Reply-To: <1417639668-23500-2-git-send-email-thomas.monjalon@6wind.com>

On 12/4/2014 5:26 AM, Thomas Monjalon wrote:
> There is no standard to check endianness.
> So we need to try different checks.
> Previous trials were done in testpmd (see commits
> 51f694dd40f56 and 64741f237cf29) without full success.
> This one is not guaranteed to work everywhere so it could
> evolve when exceptions are found.
>
> If endianness is not detected, there is a fallback on x86
> to little endian. It could be forced before doing detection
> but it would add some arch-dependent code in the generic header.
>
> The option CONFIG_RTE_ARCH_BIG_ENDIAN introduced for IBM Power only
> (commit a982ec81d84d53) can be removed. A compile-time check is better.
>
> Signed-off-by: Thomas Monjalon <thomas.monjalon@6wind.com>
> ---
>  config/defconfig_ppc_64-power8-linuxapp-gcc        |  1 -
>  .../common/include/arch/ppc_64/rte_byteorder.h     |  4 ++--
>  .../common/include/arch/x86/rte_byteorder.h        |  4 ++++
>  .../common/include/generic/rte_byteorder.h         | 28 ++++++++++++++++++++++
>  4 files changed, 34 insertions(+), 3 deletions(-)
>
> diff --git a/config/defconfig_ppc_64-power8-linuxapp-gcc b/config/defconfig_ppc_64-power8-linuxapp-gcc
> index 48018c3..d97a885 100644
> --- a/config/defconfig_ppc_64-power8-linuxapp-gcc
> +++ b/config/defconfig_ppc_64-power8-linuxapp-gcc
> @@ -34,7 +34,6 @@ CONFIG_RTE_MACHINE="power8"
>  
>  CONFIG_RTE_ARCH="ppc_64"
>  CONFIG_RTE_ARCH_PPC_64=y
> -CONFIG_RTE_ARCH_BIG_ENDIAN=y
>  CONFIG_RTE_ARCH_64=y
>  
>  CONFIG_RTE_TOOLCHAIN="gcc"
> diff --git a/lib/librte_eal/common/include/arch/ppc_64/rte_byteorder.h b/lib/librte_eal/common/include/arch/ppc_64/rte_byteorder.h
> index 1a89051..80436f2 100644
> --- a/lib/librte_eal/common/include/arch/ppc_64/rte_byteorder.h
> +++ b/lib/librte_eal/common/include/arch/ppc_64/rte_byteorder.h
> @@ -105,7 +105,7 @@ static inline uint64_t rte_arch_bswap64(uint64_t _x)
>  /* Power 8 have both little endian and big endian mode
>   * Power 7 only support big endian
>   */
> -#ifndef RTE_ARCH_BIG_ENDIAN
> +#if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
>  
>  #define rte_cpu_to_le_16(x) (x)
>  #define rte_cpu_to_le_32(x) (x)
> @@ -123,7 +123,7 @@ static inline uint64_t rte_arch_bswap64(uint64_t _x)
>  #define rte_be_to_cpu_32(x) rte_bswap32(x)
>  #define rte_be_to_cpu_64(x) rte_bswap64(x)
>  
> -#else
> +#else /* RTE_BIG_ENDIAN */
>  
>  #define rte_cpu_to_le_16(x) rte_bswap16(x)
>  #define rte_cpu_to_le_32(x) rte_bswap32(x)
> diff --git a/lib/librte_eal/common/include/arch/x86/rte_byteorder.h b/lib/librte_eal/common/include/arch/x86/rte_byteorder.h
> index 1aa6985..ffdb6ef 100644
> --- a/lib/librte_eal/common/include/arch/x86/rte_byteorder.h
> +++ b/lib/librte_eal/common/include/arch/x86/rte_byteorder.h
> @@ -40,6 +40,10 @@ extern "C" {
>  
>  #include "generic/rte_byteorder.h"
>  
> +#ifndef RTE_BYTE_ORDER
> +#define RTE_BYTE_ORDER RTE_LITTLE_ENDIAN
> +#endif
> +
>  /*
>   * An architecture-optimized byte swap for a 16-bit value.
>   *
> diff --git a/lib/librte_eal/common/include/generic/rte_byteorder.h b/lib/librte_eal/common/include/generic/rte_byteorder.h
> index 9358136..ea23fdf 100644
> --- a/lib/librte_eal/common/include/generic/rte_byteorder.h
> +++ b/lib/librte_eal/common/include/generic/rte_byteorder.h
> @@ -44,6 +44,34 @@
>   */
>  
>  #include <stdint.h>
> +#ifdef RTE_EXEC_ENV_BSDAPP
> +#include <sys/endian.h>
> +#else
> +#include <endian.h>
> +#endif
> +
> +/*
> + * Compile-time endianness detection
> + */
> +#define RTE_BIG_ENDIAN    1
> +#define RTE_LITTLE_ENDIAN 2
> +#if defined __BYTE_ORDER
> +#if __BYTE_ORDER == __BIG_ENDIAN
> +#define RTE_BYTE_ORDER RTE_BIG_ENDIAN
> +#elif __BYTE_ORDER == __LITTLE_ENDIAN
> +#define RTE_BYTE_ORDER RTE_LITTLE_ENDIAN
> +#endif /* __BYTE_ORDER */
> +#elif defined __BYTE_ORDER__
> +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
> +#define RTE_BYTE_ORDER RTE_BIG_ENDIAN
> +#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
> +#define RTE_BYTE_ORDER RTE_LITTLE_ENDIAN
> +#endif /* __BYTE_ORDER__ */
> +#elif defined __BIG_ENDIAN__
> +#define RTE_BYTE_ORDER RTE_BIG_ENDIAN
> +#elif defined __LITTLE_ENDIAN__
> +#define RTE_BYTE_ORDER RTE_LITTLE_ENDIAN
> +#endif

What do you think about :

+/*
+  * Compile-time endianness detection
+ */
+#define RTE_BIG_ENDIAN 1
+#define RTE_LITTLE_ENDIAN 2
+if defined __BYTE_ORDER__    /* Prefer gcc build-in macros */
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+#define RTE_BYTE_ORDER RTE_BIG_ENDIAN
+#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+#define RTE_BYTE_ORDER RTE_LITTLE_ENDIAN
+#endif /* __BYTE_ORDER__ */
+#else
+#if defined RTE_EXEC_ENV_BSDAPP
+#include <sys/endian.h>
+#else
+#include <endian.h>
+#endif
+#if defined __BYTE_ORDER
+#if __BYTE_ORDER == __BIG_ENDIAN
+#define RTE_BYTE_ORDER RTE_BIG_ENDIAN
+#elif __BYTE_ORDER == __LITTLE_ENDIAN
+#define RTE_BYTE_ORDER RTE_LITTLE_ENDIAN
+#endif /* __BYTE_ORDER */
+#elif defined __BIG_ENDIAN__
+#define RTE_BYTE_ORDER RTE_BIG_ENDIAN
+#elif defined __LITTLE_ENDIAN__
+#define RTE_BYTE_ORDER RTE_LITTLE_ENDIAN
+#endif
+#endif
>  
>  /*
>   * An internal function to swap bytes in a 16-bit value.


  reply	other threads:[~2014-12-04  2:30 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1417606044-3432-1-git-send-email-michael.qiu@intel.com>
     [not found] ` <1417606099-3489-1-git-send-email-michael.qiu@intel.com>
2014-12-03 11:42   ` [dpdk-dev] [PATCH] test-pmd: Fix pointer aliasing error Bruce Richardson
2014-12-03 13:59     ` Qiu, Michael
2014-12-03 14:51       ` Bruce Richardson
2014-12-03 15:19         ` Qiu, Michael
2014-12-03 15:36           ` Bruce Richardson
2014-12-04  2:38             ` Qiu, Michael
2014-12-04  3:28               ` [dpdk-dev] [PATCH v2] " Michael Qiu
2014-12-04  4:16                 ` [dpdk-dev] [PATCH v3] " Michael Qiu
2014-12-05  5:34                   ` Qiu, Michael
2014-12-05  9:24                     ` Thomas Monjalon
2014-12-08  1:28                       ` Qiu, Michael
2014-12-08  1:30                   ` Qiu, Michael
2014-12-10  3:44                     ` Qiu, Michael
2014-12-11  0:54                     ` Thomas Monjalon
2014-12-11 17:51                       ` r k
2014-12-12  6:49                         ` Qiu, Michael
2014-12-04 12:54                 ` [dpdk-dev] [PATCH v2] " Ananyev, Konstantin
2014-12-03 15:24     ` [dpdk-dev] [PATCH] " Olivier MATZ
2014-12-03 16:03       ` Dayu Qiu
2014-12-03 15:57     ` Dayu Qiu
2014-12-03 16:26 ` [dpdk-dev] [PATCH] test-pmd: Fix "__BYTE_ORDER__" not defined error Qiu, Michael
2014-12-03 19:59   ` Thomas Monjalon
2014-12-03 20:47     ` [dpdk-dev] [PATCH 0/2] fix endianness in EAL Thomas Monjalon
2014-12-03 20:47       ` [dpdk-dev] [PATCH 1/2] eal: detect endianness Thomas Monjalon
2014-12-04  2:28         ` Qiu, Michael [this message]
2014-12-04  9:00           ` Thomas Monjalon
2014-12-04 10:28             ` Qiu, Michael
2014-12-04 12:19               ` Thomas Monjalon
2014-12-04 12:50                 ` Qiu, Michael
2014-12-03 20:47       ` [dpdk-dev] [PATCH 2/2] app/testpmd: fix endianness detection Thomas Monjalon
2014-12-04  9:28       ` [dpdk-dev] [PATCH 0/2] fix endianness in EAL Chao Zhu
2014-12-05 16:01         ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=533710CFB86FA344BFBF2D6802E60286C9C86D@SHSMSX101.ccr.corp.intel.com \
    --to=michael.qiu@intel.com \
    --cc=chaozhu@linux.vnet.ibm.com \
    --cc=dev@dpdk.org \
    --cc=thomas.monjalon@6wind.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git