configure: add endian check
authorJens Axboe <axboe@kernel.dk>
Wed, 23 Jan 2013 22:42:16 +0000 (15:42 -0700)
committerJens Axboe <axboe@kernel.dk>
Wed, 23 Jan 2013 22:42:16 +0000 (15:42 -0700)
Will remove guesswork and manual hacking in the OS headers.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
15 files changed:
Makefile
configure
fio.c
lib/bswap.h
os/os-aix.h
os/os-android.h
os/os-freebsd.h
os/os-hpux.h
os/os-linux.h
os/os-mac.h
os/os-netbsd.h
os/os-solaris.h
os/os-windows.h
os/os.h
server.c

index 967996d7e463a8b42ef5ba1b8a6d923abe5504b3..22ea022a8ea62e7cf7a9a35f4c0eb1b5463661b9 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -40,6 +40,12 @@ endif
 ifdef CONFIG_32BIT
   CFLAGS += -DBITS_PER_LONG=32
 endif
 ifdef CONFIG_32BIT
   CFLAGS += -DBITS_PER_LONG=32
 endif
+ifdef CONFIG_BIG_ENDIAN
+  CFLAGS += -DCONFIG_BIG_ENDIAN
+endif
+ifdef CONFIG_LITTLE_ENDIAN
+  CFLAGS += -DCONFIG_LITTLE_ENDIAN
+endif
 ifdef CONFIG_LIBAIO
   CFLAGS += -DCONFIG_LIBAIO
   SOURCE += engines/libaio.c
 ifdef CONFIG_LIBAIO
   CFLAGS += -DCONFIG_LIBAIO
   SOURCE += engines/libaio.c
index e45ae394256a8eca2ea3f77f25336fd4e4c42783..795c22037325b44f79cf1fcb817240de3724eaa3 100755 (executable)
--- a/configure
+++ b/configure
@@ -238,8 +238,25 @@ fi
 
 cc="${CC-${cross_prefix}gcc}"
 
 
 cc="${CC-${cross_prefix}gcc}"
 
+##########################################
+# check endianness
+bigendian="no"
+cat > $TMPC <<EOF
+#include <inttypes.h>
+int main(void)
+{
+  volatile uint32_t i=0x01234567;
+  return (*((uint8_t*)(&i))) == 0x67;
+}
+EOF
+if compile_prog "" "" "endian"; then
+  $TMPE && bigendian="yes"
+fi
+
+
 echo "Operating system              $targetos"
 echo "CPU                           $cpu"
 echo "Operating system              $targetos"
 echo "CPU                           $cpu"
+echo "Big endian                    $bigendian"
 echo "Compiler                      $cc"
 echo
 
 echo "Compiler                      $cc"
 echo
 
@@ -783,6 +800,11 @@ else
   echo "Unknown wordsize!"
   exit 1
 fi
   echo "Unknown wordsize!"
   exit 1
 fi
+if test "$bigendian" = "yes" ; then
+  echo "CONFIG_BIG_ENDIAN=y" >> $config_host_mak
+else
+  echo "CONFIG_LITTLE_ENDIAN=y" >> $config_host_mak
+fi
 if test "$libaio" = "yes" ; then
   echo "CONFIG_LIBAIO=y" >> $config_host_mak
 fi
 if test "$libaio" = "yes" ; then
   echo "CONFIG_LIBAIO=y" >> $config_host_mak
 fi
diff --git a/fio.c b/fio.c
index 24af397a414d27669c6aa7874d3d5170737ea0c2..a408727399d388dc4ba5f993163cf13552eb0f80 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -53,10 +53,10 @@ static int endian_check(void)
        else if (u.c[0] == 0x12)
                le = 1;
 
        else if (u.c[0] == 0x12)
                le = 1;
 
-#if defined(FIO_LITTLE_ENDIAN)
+#if defined(CONFIG_LITTLE_ENDIAN)
        if (be)
                return 1;
        if (be)
                return 1;
-#elif defined(FIO_BIG_ENDIAN)
+#elif defined(CONFIG_BIG_ENDIAN)
        if (le)
                return 1;
 #else
        if (le)
                return 1;
 #else
index 30fcac54a514e8c8fc00e67da7da646ecdbcdfd5..1fe5194729a6541bb8c8795ad15899bce7052d00 100644 (file)
@@ -3,7 +3,7 @@
 
 #include <inttypes.h>
 
 
 #include <inttypes.h>
 
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#ifdef CONFIG_LITTLE_ENDIAN
 static inline uint32_t __be32_to_cpu(uint32_t val)
 {
        uint32_t c1, c2, c3, c4;
 static inline uint32_t __be32_to_cpu(uint32_t val)
 {
        uint32_t c1, c2, c3, c4;
index 01b2bdbb29ad2e605ea55f5c9d83819b29f9208d..3d677650934e8a762d6651f32cfa5ee096b47b69 100644 (file)
 #define OS_MAP_ANON            MAP_ANON
 #define OS_MSG_DONTWAIT                0
 
 #define OS_MAP_ANON            MAP_ANON
 #define OS_MSG_DONTWAIT                0
 
-#if BYTE_ORDER == BIG_ENDIAN
-#define FIO_BIG_ENDIAN
-#else
-#define FIO_LITTLE_ENDIAN
-#endif
-
 #define FIO_USE_GENERIC_SWAP
 
 static inline int blockdev_invalidate_cache(struct fio_file *f)
 #define FIO_USE_GENERIC_SWAP
 
 static inline int blockdev_invalidate_cache(struct fio_file *f)
index e78a95bfa9a420d63708bbed42e2497fa9db2262..e436f8fbdd050061383dd9a0d592240d289fc8c0 100644 (file)
@@ -13,7 +13,6 @@
 #include <sched.h>
 #include <linux/unistd.h>
 #include <linux/major.h>
 #include <sched.h>
 #include <linux/unistd.h>
 #include <linux/major.h>
-#include <endian.h>
 
 #include "binject.h"
 #include "../file.h"
 
 #include "binject.h"
 #include "../file.h"
@@ -134,14 +133,6 @@ static inline long os_random_long(os_random_state_t *rs)
 #define FIO_O_NOATIME  0
 #endif
 
 #define FIO_O_NOATIME  0
 #endif
 
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-#define FIO_LITTLE_ENDIAN
-#elif __BYTE_ORDER == __BIG_ENDIAN
-#define FIO_BIG_ENDIAN
-#else
-#error "Unknown endianness"
-#endif
-
 #define fio_swap16(x)  __bswap_16(x)
 #define fio_swap32(x)  __bswap_32(x)
 #define fio_swap64(x)  __bswap_64(x)
 #define fio_swap16(x)  __bswap_16(x)
 #define fio_swap32(x)  __bswap_32(x)
 #define fio_swap64(x)  __bswap_64(x)
index 501260098a8ace11c99d6c28d4aba9dec0438335..c55a7c315ca2efc2ab609f5d60019da0805f46b3 100644 (file)
@@ -7,7 +7,6 @@
 #include <sys/sysctl.h>
 #include <sys/disk.h>
 #include <sys/thr.h>
 #include <sys/sysctl.h>
 #include <sys/disk.h>
 #include <sys/thr.h>
-#include <sys/endian.h>
 #include <sys/socket.h>
 
 #include "../file.h"
 #include <sys/socket.h>
 
 #include "../file.h"
 
 #define OS_MAP_ANON            MAP_ANON
 
 
 #define OS_MAP_ANON            MAP_ANON
 
-#if BYTE_ORDER == LITTLE_ENDIAN
-#define FIO_LITTLE_ENDIAN
-#else
-#define FIO_BIG_ENDIAN
-#endif
-
 #define fio_swap16(x)  bswap16(x)
 #define fio_swap32(x)  bswap32(x)
 #define fio_swap64(x)  bswap64(x)
 #define fio_swap16(x)  bswap16(x)
 #define fio_swap32(x)  bswap32(x)
 #define fio_swap64(x)  bswap64(x)
index 266f0f1fb9b5152cbece81591b2d4e17107d7686..82acd1105fc51aa22f3976643a18999b245ebb3e 100644 (file)
 #define MSG_WAITALL    0x40
 #endif
 
 #define MSG_WAITALL    0x40
 #endif
 
-#ifdef LITTLE_ENDIAN
-#define FIO_LITTLE_ENDIAN
-#else
-#define FIO_BIG_ENDIAN
-#endif
-
 #define FIO_USE_GENERIC_SWAP
 
 #define FIO_OS_HAVE_AIOCB_TYPEDEF
 #define FIO_USE_GENERIC_SWAP
 
 #define FIO_OS_HAVE_AIOCB_TYPEDEF
index d7eec0f2fd7d1bece339f9b61e723523755545ff..4e837da93720c34e5960b0c1e298a703b0fb08de 100644 (file)
@@ -15,7 +15,6 @@
 #include <linux/unistd.h>
 #include <linux/raw.h>
 #include <linux/major.h>
 #include <linux/unistd.h>
 #include <linux/raw.h>
 #include <linux/major.h>
-#include <endian.h>
 
 #include "binject.h"
 #include "../file.h"
 
 #include "binject.h"
 #include "../file.h"
@@ -194,14 +193,6 @@ static inline int fio_lookup_raw(dev_t dev, int *majdev, int *mindev)
 #define FIO_MADV_FREE  MADV_REMOVE
 #endif
 
 #define FIO_MADV_FREE  MADV_REMOVE
 #endif
 
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-#define FIO_LITTLE_ENDIAN
-#elif __BYTE_ORDER == __BIG_ENDIAN
-#define FIO_BIG_ENDIAN
-#else
-#error "Unknown endianness"
-#endif
-
 #define fio_swap16(x)  __bswap_16(x)
 #define fio_swap32(x)  __bswap_32(x)
 #define fio_swap64(x)  __bswap_64(x)
 #define fio_swap16(x)  __bswap_16(x)
 #define fio_swap32(x)  __bswap_32(x)
 #define fio_swap64(x)  __bswap_64(x)
index 6ed26c57cf8ea4c3817b070972229c59945f522c..d202e99dd60a93bc3c11dd0088456bbc1a731adf 100644 (file)
 
 #define OS_MAP_ANON            MAP_ANON
 
 
 #define OS_MAP_ANON            MAP_ANON
 
-#if defined(__LITTLE_ENDIAN__)
-#define FIO_LITTLE_ENDIAN
-#elif defined(__BIG_ENDIAN__)
-#define FIO_BIG_ENDIAN
-#else
-#error "Undefined byte order"
-#endif
-
 #define fio_swap16(x)  OSSwapInt16(x)
 #define fio_swap32(x)  OSSwapInt32(x)
 #define fio_swap64(x)  OSSwapInt64(x)
 #define fio_swap16(x)  OSSwapInt16(x)
 #define fio_swap32(x)  OSSwapInt32(x)
 #define fio_swap64(x)  OSSwapInt64(x)
index 1753226e5512eaa22fcc4283056181f771730fe5..4b0269e6cab673311576689d514db5b09d49d822 100644 (file)
@@ -6,7 +6,6 @@
 #include <errno.h>
 #include <lwp.h>
 #include <sys/param.h>
 #include <errno.h>
 #include <lwp.h>
 #include <sys/param.h>
-#include <sys/endian.h>
 /* XXX hack to avoid confilcts between rbtree.h and <sys/rb.h> */
 #define        rb_node _rb_node
 #include <sys/sysctl.h>
 /* XXX hack to avoid confilcts between rbtree.h and <sys/rb.h> */
 #define        rb_node _rb_node
 #include <sys/sysctl.h>
 #define PTHREAD_STACK_MIN 4096
 #endif
 
 #define PTHREAD_STACK_MIN 4096
 #endif
 
-#if BYTE_ORDER == LITTLE_ENDIAN
-#define FIO_LITTLE_ENDIAN
-#else
-#define FIO_BIG_ENDIAN
-#endif
-
 #define fio_swap16(x)  bswap16(x)
 #define fio_swap32(x)  bswap32(x)
 #define fio_swap64(x)  bswap64(x)
 #define fio_swap16(x)  bswap16(x)
 #define fio_swap32(x)  bswap32(x)
 #define fio_swap64(x)  bswap64(x)
index 7dd62a712ac2f49aaa351e3bbe3c96c87a505718..de59f774d7fb1a8c51b9da20acf00c61923444da 100644 (file)
 #define OS_MAP_ANON            MAP_ANON
 #define OS_RAND_MAX            2147483648UL
 
 #define OS_MAP_ANON            MAP_ANON
 #define OS_RAND_MAX            2147483648UL
 
-#if defined(_BIG_ENDIAN)
-#define FIO_BIG_ENDIAN
-#else
-#define FIO_LITTLE_ENDIAN
-#endif
-
 #define fio_swap16(x)  BSWAP_16(x)
 #define fio_swap32(x)  BSWAP_32(x)
 #define fio_swap64(x)  BSWAP_64(x)
 #define fio_swap16(x)  BSWAP_16(x)
 #define fio_swap32(x)  BSWAP_32(x)
 #define fio_swap64(x)  BSWAP_64(x)
index 6862226a4a949486427f759780de85eb33145511..18de83987d635281329cfffe98816616e26a737d 100644 (file)
@@ -32,7 +32,6 @@
 
 #define OS_MAP_ANON            MAP_ANON
 
 
 #define OS_MAP_ANON            MAP_ANON
 
-#define FIO_LITTLE_ENDIAN
 #define fio_swap16(x)  _byteswap_ushort(x)
 #define fio_swap32(x)  _byteswap_ulong(x)
 #define fio_swap64(x)  _byteswap_uint64(x)
 #define fio_swap16(x)  _byteswap_ushort(x)
 #define fio_swap32(x)  _byteswap_ulong(x)
 #define fio_swap64(x)  _byteswap_uint64(x)
diff --git a/os/os.h b/os/os.h
index a14d7f0c0333152ed6663d895d787fb95d7e1f18..fb544a173e4a2c03e56bc893b18f37d38205715b 100644 (file)
--- a/os/os.h
+++ b/os/os.h
@@ -165,7 +165,7 @@ static inline uint64_t fio_swap64(uint64_t val)
 #endif
 
 #ifndef FIO_HAVE_BYTEORDER_FUNCS
 #endif
 
 #ifndef FIO_HAVE_BYTEORDER_FUNCS
-#ifdef FIO_LITTLE_ENDIAN
+#ifdef CONFIG_LITTLE_ENDIAN
 #define __le16_to_cpu(x)               (x)
 #define __le32_to_cpu(x)               (x)
 #define __le64_to_cpu(x)               (x)
 #define __le16_to_cpu(x)               (x)
 #define __le32_to_cpu(x)               (x)
 #define __le64_to_cpu(x)               (x)
index ffa6ed4bdfa7db270181bab4e2ab7a48d2f6f979..bb03c779fb11598bede46ec90c8e2c56f8ec2de8 100644 (file)
--- a/server.c
+++ b/server.c
@@ -403,7 +403,7 @@ static int handle_probe_cmd(struct fio_net_cmd *cmd)
 
        memset(&probe, 0, sizeof(probe));
        gethostname((char *) probe.hostname, sizeof(probe.hostname));
 
        memset(&probe, 0, sizeof(probe));
        gethostname((char *) probe.hostname, sizeof(probe.hostname));
-#ifdef FIO_BIG_ENDIAN
+#ifdef CONFIG_BIG_ENDIAN
        probe.bigendian = 1;
 #endif
        strncpy((char *) probe.fio_version, fio_version_string, sizeof(probe.fio_version));
        probe.bigendian = 1;
 #endif
        strncpy((char *) probe.fio_version, fio_version_string, sizeof(probe.fio_version));