1
1

opal/cma: improve Linux CMA detection

This commit improves the CMA detection when the installed glibc doesn't
have support for CMA. In this case we need to verify that the syscall
numbers in opal/include/opal/sys/cma.h are valid for the architecture.
This verification is done by attempting to use CMA while including the
internal header.

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
Этот коммит содержится в:
Nathan Hjelm 2016-06-05 22:12:38 -06:00
родитель 0084ad0d1b
Коммит 4a2bd83302
2 изменённых файлов: 78 добавлений и 10 удалений

Просмотреть файл

@ -19,19 +19,89 @@
# check if cma support is wanted.
AC_DEFUN([OPAL_CHECK_CMA],[
if test -z "$ompi_check_cma_happy" ; then
OPAL_VAR_SCOPE_PUSH([ompi_check_cma_need_defs ompi_check_cma_kernel_version])
OPAL_VAR_SCOPE_PUSH([ompi_check_cma_need_defs ompi_check_cma_kernel_version ompi_check_cma_CFLAGS])
ompi_check_cma_happy="no"
AC_ARG_WITH([cma],
[AC_HELP_STRING([--with-cma],
[Build Cross Memory Attach support (default: no)])])
[Build Cross Memory Attach support (default: autodetect)])])
# Enable CMA support by default if process_vm_readv is defined in glibc
AC_CHECK_FUNC(process_vm_readv, [ompi_check_cma_need_defs=0],
[ompi_check_cma_need_defs=1])
if test $ompi_check_cma_need_defs = 1 ; then
ompi_check_cma_CFLAGS="$CFLAGS"
# Need some extra include paths to locate the appropriate headers
CFLAGS="$CFLAGS -I${srcdir} -I${srcdir}/opal/include"
AC_MSG_CHECKING([if internal syscall numbers for Linux CMA work])
AC_RUN_IFELSE([AC_LANG_PROGRAM([[
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <sys/uio.h>
#include <sys/wait.h>
#include <sys/syscall.h>
#include "opal/include/opal/sys/cma.h"
static void do_check (pid_t pid, int *in, int *out)
{
int check[4] = {0, 0, 0, 0}, i;
struct iovec rem_iov = {out, sizeof (check)};
struct iovec loc_iov = {check, sizeof (check)};
ssize_t rc;
rc = process_vm_readv (pid, &loc_iov, 1, &rem_iov, 1, 0);
if (sizeof (check) != rc) {
exit (1);
}
for (i = 0 ; i < 4 ; ++i) {
if (check[i] != i) {
exit (1);
}
check[i] = i * 2;
}
rem_iov.iov_base = in;
rc = process_vm_writev (pid, &loc_iov, 1, &rem_iov, 1, 0);
if (sizeof (check) != rc) {
exit (1);
}
exit (0);
}
]],[[
int i, in[4] = {-1, -1, -1, -1}, out[4] = {0, 1, 2, 3};
do_check (getpid (), in, out);
for (i = 0 ; i < 4 ; ++i) {
if (in[i] != 2 * i) {
return 1;
}
}
/* all good */
return 0;
]])],
[AC_MSG_RESULT([yes])
ompi_check_cma_happy="yes"],
[AC_MSG_RESULT([no])
ompi_check_cma_happy="no"],
[AC_MSG_RESULT([no (cross-compiling)])
ompi_check_cma_happy="no"])
CFLAGS="$ompi_check_cma_CFLAGS"
else
ompi_check_cma_happy="yes"
fi
# If the user specifically requests CMA go ahead and enable it even
# if the glibc version does not support process_vm_readv
if test $ompi_check_cma_need_defs = 0 || test "x$with_cma" = "xyes" ; then
if test "x$with_cma" = "xyes" || test "$ompi_check_cma_happy" = "yes" ; then
ompi_check_cma_happy="yes"
AC_DEFINE_UNQUOTED([OPAL_CMA_NEED_SYSCALL_DEFS],
[$ompi_check_cma_need_defs],

Просмотреть файл

@ -16,7 +16,10 @@
#ifndef OPAL_SYS_CMA_H
#define OPAL_SYS_CMA_H 1
#if !defined(OPAL_ASSEMBLY_ARCH)
/* need opal_config.h for the assembly architecture */
#include "opal_config.h"
#endif
#include "opal/sys/architecture.h"
@ -61,12 +64,7 @@
#elif OPAL_ASSEMBLY_ARCH == OPAL_MIPS
#if _MIPS_SIM == _MIPS_SIM_ABI32
#define __NR_process_vm_readv 4345
#define __NR_process_vm_writev 4346
#elif _MIPS_SIM == _MIPS_SIM_ABI64
#if _MIPS_SIM == _MIPS_SIM_ABI64
#define __NR_process_vm_readv 5304
#define __NR_process_vm_writev 5305