[ewg] OFED 1.5.2rc4 fails to build on RHEL4 Update 8 x86_64
Hefty, Sean
sean.hefty at intel.com
Wed Aug 25 17:25:50 PDT 2010
ibacm: support distros with older versions of gcc
From: Sean Hefty <sean.hefty at intel.com>
ibacm implements atomics using gcc intrinsics that were introduced
in gcc 4.1.2. If an older version of gcc is used to compile the
code, an error results. Check that the required atomic calls are
supported, and if not, provide our own implementation.
This fixes a build issue on RH 5.x.
Signed-off-by: Sean Hefty <sean.hefty at intel.com>
---
This is very lightly tested, but may fix the issue.
configure.in | 10 ++++++++++
linux/osd.h | 32 ++++++++++++++++++++++++++++++--
src/acm.c | 8 ++++++++
src/acme.c | 4 ++++
src/libacm.c | 4 ++++
windows/osd.h | 1 +
6 files changed, 57 insertions(+), 2 deletions(-)
mode change 100644 => 100755 configure.in
diff --git a/configure.in b/configure.in
old mode 100644
new mode 100755
index 997c775..dfddeac
--- a/configure.in
+++ b/configure.in
@@ -39,6 +39,16 @@ AC_CHECK_HEADER(infiniband/umad.h, [],
AC_MSG_ERROR([<infiniband/umad.h> not found. Is libibumad installed?]))
fi
+dnl Check for gcc atomic intrinsics
+AC_MSG_CHECKING(compiler support for atomics)
+AC_TRY_LINK([int i = 0;],
+ [ return __sync_add_and_fetch(&i, 1) != __sync_sub_and_fetch(&i, 1); ],
+ [ AC_MSG_RESULT(yes) ],
+ [
+ AC_MSG_RESULT(no)
+ AC_DEFINE(DEFINE_ATOMICS, 1, [Set to 1 to implement atomics])
+ ])
+
AC_CACHE_CHECK(whether ld accepts --version-script, ac_cv_version_script,
if test -n "`$LD --help < /dev/null 2>/dev/null | grep version-script`"; then
ac_cv_version_script=yes
diff --git a/linux/osd.h b/linux/osd.h
index 722e1b1..28c3647 100644
--- a/linux/osd.h
+++ b/linux/osd.h
@@ -65,9 +65,37 @@
#endif
#define ntohll(x) htonll(x)
+#if DEFINE_ATOMICS
+typedef struct { pthread_mutex_t mut; int val; } atomic_t;
+static inline int atomic_inc(atomic_t *atomic)
+{
+ int v;
+
+ pthread_mutex_lock(&atomic->mut);
+ v = ++(atomic->val);
+ pthread_mutex_unlock(&atomic->mut);
+ return v;
+}
+static inline int atomic_dec(atomic_t *atomic)
+{
+ int v;
+
+ pthread_mutex_lock(&atomic->mut);
+ v = --(atomic->val);
+ pthread_mutex_unlock(&atomic->mut);
+ return v;
+}
+static inline void atomic_init(atomic_t *atomic)
+{
+ pthread_mutex_init(&atomic->mut, NULL);
+ atomic->val = 0;
+}
+#else
typedef struct { volatile int val; } atomic_t;
-#define atomic_inc(v) (__sync_fetch_and_add(&(v)->val, 1) + 1)
-#define atomic_dec(v) (__sync_fetch_and_sub(&(v)->val, 1) - 1)
+#define atomic_inc(v) (__sync_add_and_fetch(&(v)->val, 1))
+#define atomic_dec(v) (__sync_sub_and_fetch(&(v)->val, 1))
+#define atomic_init(v) ((v)->val = 0)
+#endif
#define atomic_get(v) ((v)->val)
#define atomic_set(v, s) ((v)->val = s)
diff --git a/src/acm.c b/src/acm.c
index 7c8b84b..820365c 100644
--- a/src/acm.c
+++ b/src/acm.c
@@ -27,6 +27,10 @@
* SOFTWARE.
*/
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif /* HAVE_CONFIG_H */
+
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
@@ -268,6 +272,7 @@ acm_init_dest(struct acm_dest *dest, uint8_t addr_type, uint8_t *addr, size_t si
memcpy(dest->address, addr, size);
dest->addr_type = addr_type;
DListInit(&dest->req_queue);
+ atomic_init(&dest->refcnt);
atomic_set(&dest->refcnt, 1);
lock_init(&dest->lock);
}
@@ -1560,6 +1565,7 @@ static void acm_init_server(void)
lock_init(&client[i].lock);
client[i].index = i;
client[i].sock = INVALID_SOCKET;
+ atomic_init(&client[i].refcnt);
}
}
@@ -2680,6 +2686,8 @@ int CDECL_FUNC main(int argc, char **argv)
acm_log(0, "Assistant to the InfiniBand Communication Manager\n");
acm_log_options();
+ atomic_init(&tid);
+ atomic_init(&wait_cnt);
DListInit(&dev_list);
DListInit(&timeout_list);
event_init(&timeout_event);
diff --git a/src/acme.c b/src/acme.c
index 7428a57..e03679f 100644
--- a/src/acme.c
+++ b/src/acme.c
@@ -27,6 +27,10 @@
* SOFTWARE.
*/
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif /* HAVE_CONFIG_H */
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
diff --git a/src/libacm.c b/src/libacm.c
index 32fd7e2..9d56cd2 100644
--- a/src/libacm.c
+++ b/src/libacm.c
@@ -27,6 +27,10 @@
* SOFTWARE.
*/
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif /* HAVE_CONFIG_H */
+
#include <osd.h>
#include "libacm.h"
#include <infiniband/acm.h>
diff --git a/windows/osd.h b/windows/osd.h
index 10e5e18..9587c51 100644
--- a/windows/osd.h
+++ b/windows/osd.h
@@ -44,6 +44,7 @@ typedef struct { volatile LONG val; } atomic_t;
#define atomic_dec(v) InterlockedDecrement(&(v)->val)
#define atomic_get(v) ((v)->val)
#define atomic_set(v, s) ((v)->val = s)
+#define atomic_init(v) ((v)->val = 0)
#define event_t HANDLE
#define event_init(e) *(e) = CreateEvent(NULL, FALSE, FALSE, NULL)
More information about the ewg
mailing list