Skip to content

Commit 57d15bb

Browse files
committed
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 <[email protected]> (cherry picked from commit 4a2bd83) Signed-off-by: Nathan Hjelm <[email protected]>
1 parent 34bc9d3 commit 57d15bb

File tree

2 files changed

+79
-4
lines changed

2 files changed

+79
-4
lines changed

config/opal_check_cma.m4

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,89 @@
1919
# check if cma support is wanted.
2020
AC_DEFUN([OPAL_CHECK_CMA],[
2121
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])
2323

24-
ompi_check_cma_happy="no"
2524
AC_ARG_WITH([cma],
2625
[AC_HELP_STRING([--with-cma],
27-
[Build Cross Memory Attach support (default: no)])])
26+
[Build Cross Memory Attach support (default: autodetect)])])
2827

2928
# Enable CMA support by default if process_vm_readv is defined in glibc
3029
AC_CHECK_FUNC(process_vm_readv, [ompi_check_cma_need_defs=0],
3130
[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+
32102
# If the user specifically requests CMA go ahead and enable it even
33103
# 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
35105
ompi_check_cma_happy="yes"
36106
AC_DEFINE_UNQUOTED([OPAL_CMA_NEED_SYSCALL_DEFS],
37107
[$ompi_check_cma_need_defs],

opal/include/opal/sys/cma.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/*
22
* Copyright (c) 2011-2012 IBM Corporation. All rights reserved.
3+
* Copyright (c) 2016 Los Alamos National Security, LLC. All rights
4+
* reserved.
35
*
46
*/
57

@@ -14,7 +16,10 @@
1416
#ifndef OPAL_SYS_CMA_H
1517
#define OPAL_SYS_CMA_H 1
1618

19+
#if !defined(OPAL_ASSEMBLY_ARCH)
20+
/* need opal_config.h for the assembly architecture */
1721
#include "opal_config.h"
22+
#endif
1823

1924
#include "opal/sys/architecture.h"
2025

0 commit comments

Comments
 (0)