Whamcloud - gitweb
LU-2752 build: Enhance build for cross compilation for MIC
authorDmitry Eremin <dmitry.eremin@intel.com>
Wed, 13 Mar 2013 13:40:47 +0000 (17:40 +0400)
committerOleg Drokin <oleg.drokin@intel.com>
Tue, 7 May 2013 16:57:02 +0000 (12:57 -0400)
Enhance lustre build for cross compilation for the Intel(R) Xeon
Phi(TM) card. In addition to standard build the GNU cross
toolchain for the Intel(R) Xeon Phi(TM) can be used to produce
client binaries for the Intel(R) Xeon Phi(TM) card. To enable
this just specify appropriate --host and --build option for
./configure.

For example, to produce Lustre client binaries for Intel(R) Xeon
Phi(TM) card just execute the following commands:

NOTE: You should have "intel-mic-gpl-<version>.x86_64" package
installed and MIC GPL sources unpacked in /opt/intel/mic/src.

export PATH=/usr/linux-k1om-4.7/bin:$PATH

sh ./autogen.sh

./configure --with-linux=/opt/intel/mic/src/card/kernel \
    --disable-server --without-o2ib \
    --host=x86_64-k1om-linux --build=x86_64-pc-linux

make

Signed-off-by: Dmitry Eremin <dmitry.eremin@intel.com>
Change-Id: I4347c65f67bd836116532989c2132457f5eee934
Reviewed-on: http://review.whamcloud.com/5273
Tested-by: Hudson
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Alex Zhuravlev <alexey.zhuravlev@intel.com>
autoMakefile.am
config/lustre-build-linux.m4
config/lustre-build.m4
libcfs/libcfs/autoMakefile.am
libcfs/libcfs/linux/linux-crypto.c
libcfs/libcfs/user-crypto.c
libsysio/configure.in
lnet/utils/Makefile.am
lnet/utils/genlib.sh
lustre/liblustre/Makefile.am
lustre/liblustre/genlib.sh

index 79bcd65..7dd4f1b 100644 (file)
@@ -82,9 +82,9 @@ if LINUX
 all-am: modules
 
 modules: $(DEP) all-sources
 all-am: modules
 
 modules: $(DEP) all-sources
-       $(MAKE) CC="$(CC)" -C $(LINUX_OBJ)                           \
+       $(MAKE) CC="$(CC)" $(CROSS_VARS) -C $(LINUX_OBJ)             \
        -f $(PWD)/build/Makefile LUSTRE_LINUX_CONFIG=$(LINUX_CONFIG) \
        -f $(PWD)/build/Makefile LUSTRE_LINUX_CONFIG=$(LINUX_CONFIG) \
-        LINUXINCLUDE='$(EXTRA_LNET_INCLUDE) -I$$(srctree)/arch/$$(SRCARCH)/include -I$$(srctree)/arch/$$(SRCARCH)/include/generated -Iinclude $$(if $$(KBUILD_SRC),-Iinclude2 -I$$(srctree)/include) -include $(CONFIG_INCLUDE)' \
+       LINUXINCLUDE='$(EXTRA_LNET_INCLUDE) -I$$(srctree)/arch/$$(SRCARCH)/include -I$$(srctree)/arch/$$(SRCARCH)/include/generated -Iinclude $$(if $$(KBUILD_SRC),-Iinclude2 -I$$(srctree)/include) -include $(CONFIG_INCLUDE)' \
        $(MODULE_TARGET)=$(PWD) -o tmp_include_depends -o scripts -o \
        include/config/MARKER $@
 endif # LINUX
        $(MODULE_TARGET)=$(PWD) -o tmp_include_depends -o scripts -o \
        include/config/MARKER $@
 endif # LINUX
index ec77262..b08ae65 100644 (file)
@@ -255,6 +255,7 @@ if grep rhconfig $LINUX_OBJ/include/linux/version.h >/dev/null ; then
 fi
 
 # this is needed before we can build modules
 fi
 
 # this is needed before we can build modules
+LB_LINUX_CROSS
 LB_LINUX_VERSION
 
 # --- check that we can build modules at all
 LB_LINUX_VERSION
 
 # --- check that we can build modules at all
@@ -285,6 +286,37 @@ AC_DEFUN([LB_LINUX_SYMVERFILE],
        AC_SUBST(SYMVERFILE)
 ])
 
        AC_SUBST(SYMVERFILE)
 ])
 
+#
+# LB_LINUX_CROSS
+#
+# check for cross compilation
+#
+AC_DEFUN([LB_LINUX_CROSS],
+       [AC_MSG_CHECKING([for cross compilation])
+CROSS_VARS=
+case $target_vendor in
+       # The K1OM architecture is an extension of the x86 architecture.
+       # So, the $target_arch is x86_64.
+       k1om)
+               AC_MSG_RESULT([Intel(R) Xeon Phi(TM)])
+               CC_TARGET_ARCH=`$CC -v 2>&1 | grep Target: | sed -e 's/Target: //'`
+               if test $CC_TARGET_ARCH != x86_64-$target_vendor-linux ; then
+                       AC_MSG_ERROR([Cross compiler not found in PATH.])
+               fi
+               CROSS_VARS="ARCH=$target_vendor CROSS_COMPILE=x86_64-$target_vendor-linux-"
+               CCAS=$CC
+               if test x$enable_server = xyes ; then
+                       AC_MSG_WARN([Disabling server (not supported for x86_64-$target_vendor-linux).])
+                       enable_server='no'
+               fi
+               ;;
+       *)
+               AC_MSG_RESULT([no])
+               ;;
+esac
+AC_SUBST(CROSS_VARS)
+])
+
 # these are like AC_TRY_COMPILE, but try to build modules against the
 # kernel, inside the build directory
 
 # these are like AC_TRY_COMPILE, but try to build modules against the
 # kernel, inside the build directory
 
@@ -312,7 +344,7 @@ $2
 AC_DEFUN([LB_LINUX_COMPILE_IFELSE],
 [m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
 rm -f build/conftest.o build/conftest.mod.c build/conftest.ko
 AC_DEFUN([LB_LINUX_COMPILE_IFELSE],
 [m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
 rm -f build/conftest.o build/conftest.mod.c build/conftest.ko
-AS_IF([AC_TRY_COMMAND(cp conftest.c build && make -d [$2] ${LD:+"LD=$LD"} CC="$CC" -f $PWD/build/Makefile LUSTRE_LINUX_CONFIG=$LINUX_CONFIG LINUXINCLUDE="$EXTRA_LNET_INCLUDE -I$LINUX/arch/`echo $target_cpu|sed -e 's/powerpc64/powerpc/' -e 's/x86_64/x86/' -e 's/i.86/x86/'`/include -I$LINUX/arch/`echo $target_cpu|sed -e 's/ppc.*/powerpc/' -e 's/x86_64/x86/' -e 's/i.86/x86/'`/include/generated -I$LINUX_OBJ/include -I$LINUX/include -I$LINUX_OBJ/include2 -include $CONFIG_INCLUDE" -o tmp_include_depends -o scripts -o include/config/MARKER -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $MODULE_TARGET=$PWD/build) >/dev/null && AC_TRY_COMMAND([$3])],
+AS_IF([AC_TRY_COMMAND(cp conftest.c build && make -d [$2] ${LD:+"LD=$LD"} CC="$CC" -f $PWD/build/Makefile LUSTRE_LINUX_CONFIG=$LINUX_CONFIG LINUXINCLUDE="$EXTRA_LNET_INCLUDE -I$LINUX/arch/`echo $target_cpu|sed -e 's/powerpc64/powerpc/' -e 's/x86_64/x86/' -e 's/i.86/x86/'`/include -I$LINUX/arch/`echo $target_cpu|sed -e 's/ppc.*/powerpc/' -e 's/x86_64/x86/' -e 's/i.86/x86/'`/include/generated -I$LINUX_OBJ/include -I$LINUX/include -I$LINUX_OBJ/include2 -include $CONFIG_INCLUDE" -o tmp_include_depends -o scripts -o include/config/MARKER -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $CROSS_VARS $MODULE_TARGET=$PWD/build) >/dev/null && AC_TRY_COMMAND([$3])],
        [$4],
        [_AC_MSG_LOG_CONFTEST
 m4_ifvaln([$5],[$5])dnl])
        [$4],
        [_AC_MSG_LOG_CONFTEST
 m4_ifvaln([$5],[$5])dnl])
@@ -328,7 +360,7 @@ AC_DEFUN([LB_LINUX_ARCH],
          [AC_MSG_CHECKING([Linux kernel architecture])
           AS_IF([rm -f $PWD/build/arch
                  make -s --no-print-directory echoarch -f $PWD/build/Makefile \
          [AC_MSG_CHECKING([Linux kernel architecture])
           AS_IF([rm -f $PWD/build/arch
                  make -s --no-print-directory echoarch -f $PWD/build/Makefile \
-                     LUSTRE_LINUX_CONFIG=$LINUX_CONFIG -C $LINUX \
+                     LUSTRE_LINUX_CONFIG=$LINUX_CONFIG -C $LINUX $CROSS_VARS  \
                      ARCHFILE=$PWD/build/arch && LINUX_ARCH=`cat $PWD/build/arch`],
                 [AC_MSG_RESULT([$LINUX_ARCH])],
                 [AC_MSG_ERROR([Could not determine the kernel architecture.])])
                      ARCHFILE=$PWD/build/arch && LINUX_ARCH=`cat $PWD/build/arch`],
                 [AC_MSG_RESULT([$LINUX_ARCH])],
                 [AC_MSG_ERROR([Could not determine the kernel architecture.])])
index 820b8bb..bdc0737 100644 (file)
@@ -488,6 +488,9 @@ LC_PATH_DEFAULTS
 #
 AC_DEFUN([LB_PROG_CC],
 [AC_PROG_RANLIB
 #
 AC_DEFUN([LB_PROG_CC],
 [AC_PROG_RANLIB
+AC_CHECK_TOOL(LD, ld, [no])
+AC_CHECK_TOOL(OBJDUMP, objdump, [no])
+AC_CHECK_TOOL(STRIP, strip, [no])
 
 # ---------  unsigned long long sane? -------
 AC_CHECK_SIZEOF(unsigned long long, 0)
 
 # ---------  unsigned long long sane? -------
 AC_CHECK_SIZEOF(unsigned long long, 0)
@@ -537,6 +540,16 @@ AM_CONDITIONAL(SUNOS, test x$lb_target_os = "xSunOS")
 AM_CONDITIONAL(USES_DPKG, test x$uses_dpkg = "xyes")
 AM_CONDITIONAL(ARCH_x86, test x$target_cpu = "xx86_64" -o x$target_cpu = "xi686")
 
 AM_CONDITIONAL(USES_DPKG, test x$uses_dpkg = "xyes")
 AM_CONDITIONAL(ARCH_x86, test x$target_cpu = "xx86_64" -o x$target_cpu = "xi686")
 
+# Sanity check for PCLMULQDQ instruction availability
+# PCLMULQDQ instruction is a new instruction available beginning with
+# the all new Core processor family based on the 32nm microarchitecture
+# codename Westmere. So, $target_cpu = x86_64 should have this instruction
+# except MIC microarchitecture (k1om).
+AM_CONDITIONAL(HAVE_PCLMULQDQ, test x$target_cpu = "xx86_64" -a x$target_vendor != "xk1om")
+if test x$target_cpu = "xx86_64" -a x$target_vendor != "xk1om" ; then
+       AC_DEFINE(HAVE_PCLMULQDQ, 1, [have PCLMULQDQ instruction])
+fi
+
 # this lets lustre cancel libsysio, per-branch or if liblustre is
 # disabled
 if test "x$LIBSYSIO_SUBDIR" = xlibsysio ; then
 # this lets lustre cancel libsysio, per-branch or if liblustre is
 # disabled
 if test "x$LIBSYSIO_SUBDIR" = xlibsysio ; then
index 66b2030..609b133 100644 (file)
@@ -49,7 +49,7 @@ libcfs_a_SOURCES= posix/posix-debug.c user-prim.c user-lock.c user-tcpip.c  \
                  posix/rbtree.c user-crypto.c posix/posix-crc32.c          \
                  posix/posix-adler.c heap.c
 
                  posix/rbtree.c user-crypto.c posix/posix-crc32.c          \
                  posix/posix-adler.c heap.c
 
-if ARCH_x86
+if HAVE_PCLMULQDQ
 libcfs_a_SOURCES += user-crc32pclmul.c crc32-pclmul_asm.S
 endif
 
 libcfs_a_SOURCES += user-crc32pclmul.c crc32-pclmul_asm.S
 endif
 
index ff93081..11caba4 100644 (file)
@@ -344,7 +344,7 @@ static int cfs_crypto_test_hashes(void)
 
 static int crc32, adler32;
 
 
 static int crc32, adler32;
 
-#ifdef CONFIG_X86
+#ifdef HAVE_PCLMULQDQ
 static int crc32pclmul;
 #endif
 
 static int crc32pclmul;
 #endif
 
@@ -353,7 +353,7 @@ int cfs_crypto_register(void)
        crc32 = cfs_crypto_crc32_register();
        adler32 = cfs_crypto_adler32_register();
 
        crc32 = cfs_crypto_crc32_register();
        adler32 = cfs_crypto_adler32_register();
 
-#ifdef CONFIG_X86
+#ifdef HAVE_PCLMULQDQ
        crc32pclmul = cfs_crypto_crc32_pclmul_register();
 #endif
 
        crc32pclmul = cfs_crypto_crc32_pclmul_register();
 #endif
 
@@ -368,7 +368,7 @@ void cfs_crypto_unregister(void)
        if (adler32 == 0)
                cfs_crypto_adler32_unregister();
 
        if (adler32 == 0)
                cfs_crypto_adler32_unregister();
 
-#ifdef CONFIG_X86
+#ifdef HAVE_PCLMULQDQ
        if (crc32pclmul == 0)
                cfs_crypto_crc32_pclmul_unregister();
 #endif
        if (crc32pclmul == 0)
                cfs_crypto_crc32_pclmul_unregister();
 #endif
index 9ae5aa9..224ca77 100644 (file)
@@ -90,7 +90,7 @@ static int adler_wrapper(void *ctx, const unsigned char *p,
        return 0;
 }
 
        return 0;
 }
 
-#if (defined i386) || (defined __amd64__)
+#ifdef HAVE_PCLMULQDQ
 static int crc32_pclmul_wrapper(void *ctx, const unsigned char *p,
                                unsigned int len)
 {
 static int crc32_pclmul_wrapper(void *ctx, const unsigned char *p,
                                unsigned int len)
 {
@@ -157,7 +157,7 @@ static struct __hash_alg crypto_hash[] = {
                                           .start = start_generic,
                                           .final = final_generic,
                                           .fini = NULL},
                                           .start = start_generic,
                                           .final = final_generic,
                                           .fini = NULL},
-#if (defined i386) || (defined __amd64__)
+#ifdef HAVE_PCLMULQDQ
                                          {.ha_id = CFS_HASH_ALG_CRC32,
                                           .ha_ctx_size = sizeof(unsigned int),
                                           .ha_priority = 100,
                                          {.ha_id = CFS_HASH_ALG_CRC32,
                                           .ha_ctx_size = sizeof(unsigned int),
                                           .ha_priority = 100,
index 23e9038..80013b6 100644 (file)
@@ -3,26 +3,44 @@ AC_INIT(libsysio, 1.2)
 AC_CANONICAL_SYSTEM
 
 case "$host_os" in
 AC_CANONICAL_SYSTEM
 
 case "$host_os" in
-  aix*)
-       ;;
-  linux*)
-       ;;
-  *)
-       AC_MSG_WARN('***' ${host_os}: Unsupported OS target)
-       ;;
+       aix*)
+               ;;
+       linux*)
+               ;;
+       *)
+               AC_MSG_WARN('***' ${host_os}: Unsupported OS target)
+               ;;
 esac
 
 AM_INIT_AUTOMAKE([subdir-objects 1.9 tar-ustar])
 AM_MAINTAINER_MODE([enable])
 AC_PROG_CC
 AM_PROG_CC_C_O
 esac
 
 AM_INIT_AUTOMAKE([subdir-objects 1.9 tar-ustar])
 AM_MAINTAINER_MODE([enable])
 AC_PROG_CC
 AM_PROG_CC_C_O
-
 AC_PROG_RANLIB
 AC_PROG_RANLIB
+AC_CHECK_TOOL(CC, gcc, [no])
+AC_CHECK_TOOL(LD, ld, [no])
+AC_CHECK_TOOL(AR, ar, [no])
+AC_CHECK_TOOL(OBJDUMP, objdump, [no])
+AC_CHECK_TOOL(STRIP, strip, [no])
 AC_PROG_MAKE_SET
 AC_HEADER_STDC
 AC_HEADER_STAT
 AC_HEADER_TIME
 
 AC_PROG_MAKE_SET
 AC_HEADER_STDC
 AC_HEADER_STAT
 AC_HEADER_TIME
 
+case $target_vendor in
+       # The K1OM architecture is an extension of the x86 architecture.
+       # So, the $target_arch is x86_64.
+       k1om)
+               CC_TARGET_ARCH=`$CC -v 2>&1 | grep Target: | sed -e 's/Target: //'`
+               if test $CC_TARGET_ARCH != x86_64-$target_vendor-linux ; then
+                       AC_MSG_ERROR([Cross compiler not found in PATH.])
+               fi
+               CCAS=$CC
+               ;;
+       *)
+               ;;
+esac
+
 if test ${target_cpu} == "powerpc64"; then
        AC_MSG_WARN([set compiler with -m64])
        CC="$CC -m64"
 if test ${target_cpu} == "powerpc64"; then
        AC_MSG_WARN([set compiler with -m64])
        CC="$CC -m64"
@@ -557,4 +575,3 @@ fi
 AC_OUTPUT(
        Makefile
        tests/Makefile)
 AC_OUTPUT(
        Makefile
        tests/Makefile)
-
index 9f28a28..f11a21a 100644 (file)
@@ -90,6 +90,10 @@ endif
 
 if LIBLUSTRE
 LIB_SELFTEST = $(top_builddir)/libcfs/libcfs/libcfs.a $(top_builddir)/lnet/lnet/liblnet.a $(top_builddir)/lnet/selftest/libselftest.a
 
 if LIBLUSTRE
 LIB_SELFTEST = $(top_builddir)/libcfs/libcfs/libcfs.a $(top_builddir)/lnet/lnet/liblnet.a $(top_builddir)/lnet/selftest/libselftest.a
+
+export AR
+export RANLIB
+
 liblst.a : $(LIB_SELFTEST) $(LND_LIBS)
        sh $(srcdir)/genlib.sh "$(LIBS)" "$(LND_LIBS)" "$(PTHREAD_LIBS)"
 
 liblst.a : $(LIB_SELFTEST) $(LND_LIBS)
        sh $(srcdir)/genlib.sh "$(LIBS)" "$(LND_LIBS)" "$(PTHREAD_LIBS)"
 
index 031640d..bad9833 100755 (executable)
@@ -2,10 +2,6 @@
 #set -xv
 set -e
 
 #set -xv
 set -e
 
-AR=/usr/bin/ar
-LD=/usr/bin/ld
-RANLIB=/usr/bin/ranlib
-
 CWD=`pwd`
 
 LIBS=$1
 CWD=`pwd`
 
 LIBS=$1
index 4aa8e67..497b177 100644 (file)
@@ -58,6 +58,11 @@ libllite_a_SOURCES = llite_lib.c super.c namei.c rw.c file.c dir.c \
 liblustre_a_SOURCES = llite_lib.c super.c namei.c rw.c file.c dir.c \
                     llite_lib.h llite_cl.c
 
 liblustre_a_SOURCES = llite_lib.c super.c namei.c rw.c file.c dir.c \
                     llite_lib.h llite_cl.c
 
+export CC
+export LDFLAGS
+export AR
+export RANLIB
+
 liblustre.a : $(LUSTRE_LIBS) $(LND_LIBS) $(LNET_LIBS) $(SYSIO_LIBS)
        sh $(srcdir)/genlib.sh "$(SYSIO)" "$(LIBS)" "$(LND_LIBS)" "$(PTHREAD_LIBS)" "$(CAP_LIBS)" "$(ZLIB)"
 
 liblustre.a : $(LUSTRE_LIBS) $(LND_LIBS) $(LNET_LIBS) $(SYSIO_LIBS)
        sh $(srcdir)/genlib.sh "$(SYSIO)" "$(LIBS)" "$(LND_LIBS)" "$(PTHREAD_LIBS)" "$(CAP_LIBS)" "$(ZLIB)"
 
index d056825..0694d62 100755 (executable)
@@ -11,15 +11,13 @@ set -e
 # FIXME: How to do this cleanly use makefile?
 #
 
 # FIXME: How to do this cleanly use makefile?
 #
 
-AR=/usr/bin/ar
 # see http://osdir.com/ml/gmane.comp.gnu.binutils.bugs/2006-01/msg00016.php
 ppc64_CPU=`uname -p`
 if [ "x${ppc64_CPU}" = "xppc64" ]; then
 # see http://osdir.com/ml/gmane.comp.gnu.binutils.bugs/2006-01/msg00016.php
 ppc64_CPU=`uname -p`
 if [ "x${ppc64_CPU}" = "xppc64" ]; then
-  LD="gcc -m64"
+       LD="$CC -m64"
 else
 else
-  LD="gcc"
+       LD=$CC
 fi
 fi
-RANLIB=/usr/bin/ranlib
 
 CWD=`pwd`
 
 
 CWD=`pwd`
 
@@ -93,7 +91,7 @@ $RANLIB $CWD/liblsupport.a
 
 # if libsysio is already in our LIBS we don't need to link against it here
 if $(echo "$LIBS" | grep -v -- "-lsysio" >/dev/null) ; then
 
 # if libsysio is already in our LIBS we don't need to link against it here
 if $(echo "$LIBS" | grep -v -- "-lsysio" >/dev/null) ; then
-  build_sysio_obj_list $SYSIO/lib/libsysio.a
+       build_sysio_obj_list $SYSIO/lib/libsysio.a
 fi
 
 # create static lib lustre
 fi
 
 # create static lib lustre
@@ -105,14 +103,14 @@ $RANLIB $CWD/liblustre.a
 rm -f $CWD/liblustre.so
 OS=`uname`
 if test x$OS = xAIX; then
 rm -f $CWD/liblustre.so
 OS=`uname`
 if test x$OS = xAIX; then
-$LD -shared -o $CWD/liblustre.so $ALL_OBJS -lpthread -Xlinker -bnoipath ../../libsyscall.so
+       $LD $LDFLAGS -shared -o $CWD/liblustre.so $ALL_OBJS -lpthread -Xlinker -bnoipath ../../libsyscall.so
 else
 # using -nostdlib on Ubuntu causes errors such as:
 #./llite_lib.o: In function `liblustre_process_log':
 #/home/brian/rpm/BUILD/lustre-1.8.2.50/lustre/liblustre/llite_lib.c:234: undefined reference to `__stack_chk_fail_local'
 # due to the use of SSP
 #$LD -shared -nostdlib -o $CWD/liblustre.so $ALL_OBJS $CAP_LIBS $PTHREAD_LIBS $ZLIB
 else
 # using -nostdlib on Ubuntu causes errors such as:
 #./llite_lib.o: In function `liblustre_process_log':
 #/home/brian/rpm/BUILD/lustre-1.8.2.50/lustre/liblustre/llite_lib.c:234: undefined reference to `__stack_chk_fail_local'
 # due to the use of SSP
 #$LD -shared -nostdlib -o $CWD/liblustre.so $ALL_OBJS $CAP_LIBS $PTHREAD_LIBS $ZLIB
-$LD -shared -o $CWD/liblustre.so $ALL_OBJS $CAP_LIBS $PTHREAD_LIBS $ZLIB
+       $LD $LDFLAGS -shared -o $CWD/liblustre.so $ALL_OBJS $CAP_LIBS $PTHREAD_LIBS $ZLIB
 fi
 
 rm -rf $sysio_tmp
 fi
 
 rm -rf $sysio_tmp