|
19 | 19 | # check if cma support is wanted. |
20 | 20 | AC_DEFUN([OPAL_CHECK_CMA],[ |
21 | 21 | if test -z "$ompi_check_cma_happy" ; then |
22 | | - OPAL_VAR_SCOPE_PUSH([ompi_check_cma_need_defs ompi_check_cma_kernel_version]) |
| 22 | + OPAL_VAR_SCOPE_PUSH([ompi_check_cma_need_defs ompi_check_cma_kernel_version ompi_check_cma_CFLAGS]) |
23 | 23 |
|
24 | | - ompi_check_cma_happy="no" |
25 | 24 | AC_ARG_WITH([cma], |
26 | 25 | [AC_HELP_STRING([--with-cma], |
27 | | - [Build Cross Memory Attach support (default: no)])]) |
| 26 | + [Build Cross Memory Attach support (default: autodetect)])]) |
28 | 27 |
|
29 | 28 | # Enable CMA support by default if process_vm_readv is defined in glibc |
30 | 29 | AC_CHECK_FUNC(process_vm_readv, [ompi_check_cma_need_defs=0], |
31 | 30 | [ompi_check_cma_need_defs=1]) |
| 31 | + |
| 32 | + if test $ompi_check_cma_need_defs = 1 ; then |
| 33 | + ompi_check_cma_CFLAGS="$CFLAGS" |
| 34 | + # Need some extra include paths to locate the appropriate headers |
| 35 | + CFLAGS="$CFLAGS -I${srcdir} -I${srcdir}/opal/include" |
| 36 | + AC_MSG_CHECKING([if internal syscall numbers for Linux CMA work]) |
| 37 | + AC_RUN_IFELSE([AC_LANG_PROGRAM([[ |
| 38 | +#include <stdlib.h> |
| 39 | +#include <stdint.h> |
| 40 | +#include <string.h> |
| 41 | +#include <unistd.h> |
| 42 | + |
| 43 | +#include <sys/uio.h> |
| 44 | +#include <sys/wait.h> |
| 45 | +#include <sys/syscall.h> |
| 46 | + |
| 47 | +#include "opal/include/opal/sys/cma.h" |
| 48 | + |
| 49 | +static void do_check (pid_t pid, int *in, int *out) |
| 50 | +{ |
| 51 | + int check[4] = {0, 0, 0, 0}, i; |
| 52 | + struct iovec rem_iov = {out, sizeof (check)}; |
| 53 | + struct iovec loc_iov = {check, sizeof (check)}; |
| 54 | + ssize_t rc; |
| 55 | + |
| 56 | + rc = process_vm_readv (pid, &loc_iov, 1, &rem_iov, 1, 0); |
| 57 | + if (sizeof (check) != rc) { |
| 58 | + exit (1); |
| 59 | + } |
| 60 | + |
| 61 | + for (i = 0 ; i < 4 ; ++i) { |
| 62 | + if (check[i] != i) { |
| 63 | + exit (1); |
| 64 | + } |
| 65 | + |
| 66 | + check[i] = i * 2; |
| 67 | + } |
| 68 | + |
| 69 | + rem_iov.iov_base = in; |
| 70 | + rc = process_vm_writev (pid, &loc_iov, 1, &rem_iov, 1, 0); |
| 71 | + if (sizeof (check) != rc) { |
| 72 | + exit (1); |
| 73 | + } |
| 74 | + |
| 75 | + exit (0); |
| 76 | +} |
| 77 | +]],[[ |
| 78 | + int i, in[4] = {-1, -1, -1, -1}, out[4] = {0, 1, 2, 3}; |
| 79 | + |
| 80 | + do_check (getpid (), in, out); |
| 81 | + |
| 82 | + for (i = 0 ; i < 4 ; ++i) { |
| 83 | + if (in[i] != 2 * i) { |
| 84 | + return 1; |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + /* all good */ |
| 89 | + return 0; |
| 90 | +]])], |
| 91 | + [AC_MSG_RESULT([yes]) |
| 92 | + ompi_check_cma_happy="yes"], |
| 93 | + [AC_MSG_RESULT([no]) |
| 94 | + ompi_check_cma_happy="no"], |
| 95 | + [AC_MSG_RESULT([no (cross-compiling)]) |
| 96 | + ompi_check_cma_happy="no"]) |
| 97 | + CFLAGS="$ompi_check_cma_CFLAGS" |
| 98 | + else |
| 99 | + ompi_check_cma_happy="yes" |
| 100 | + fi |
| 101 | + |
32 | 102 | # If the user specifically requests CMA go ahead and enable it even |
33 | 103 | # if the glibc version does not support process_vm_readv |
34 | | - if test $ompi_check_cma_need_defs = 0 || test "x$with_cma" = "xyes" ; then |
| 104 | + if test "x$with_cma" = "xyes" || test "$ompi_check_cma_happy" = "yes" ; then |
35 | 105 | ompi_check_cma_happy="yes" |
36 | 106 | AC_DEFINE_UNQUOTED([OPAL_CMA_NEED_SYSCALL_DEFS], |
37 | 107 | [$ompi_check_cma_need_defs], |
|
0 commit comments