[ofa-general] [PATCH] libibcm: add valgrind support to the libibcm
Dotan Barak
dotanb at dev.mellanox.co.il
Wed Sep 19 05:50:23 PDT 2007
Added valgrind support to the libibcm.
Signed-off-by: Dotan Barak <dotanb at dev.mellanox.co.il>
Signed-off-by: Sean Hefty <sean.hefty at intel.com>
---
Index: ofa_1_3_dev_user/src/userspace/libibcm/configure.in
===================================================================
--- ofa_1_3_dev_user.orig/src/userspace/libibcm/configure.in 2007-09-19 08:31:54.000000000 +0200
+++ ofa_1_3_dev_user/src/userspace/libibcm/configure.in 2007-09-19 12:10:50.000000000 +0200
@@ -9,6 +9,18 @@ AM_INIT_AUTOMAKE(libibcm, 1.0-1)
AM_PROG_LIBTOOL
+AC_ARG_WITH([valgrind],
+ AC_HELP_STRING([--with-valgrind],
+ [Enable valgrind annotations - default NO]))
+
+if test "$with_valgrind" != "" && test "$with_valgrind" != "no"; then
+ AC_DEFINE([INCLUDE_VALGRIND], 1,
+ [Define to 1 to enable valgrind annotations])
+ if test -d $with_valgrind; then
+ CPPFLAGS="$CPPLFAGS -I$with_valgrind/include"
+ fi
+fi
+
AC_ARG_ENABLE(libcheck, [ --disable-libcheck do not test for presence of ib libraries],
[ if test "$enableval" = "no"; then
disable_libcheck=yes
@@ -38,6 +50,12 @@ AC_CHECK_HEADER(infiniband/verbs.h, [],
AC_MSG_ERROR([<infiniband/verbs.h> not found. Is libibverbs installed?]))
AC_CHECK_HEADER(infiniband/marshall.h, [],
AC_MSG_ERROR([<infiniband/marshall.h> not found. Is libibverbs installed?]))
+
+if test "$with_valgrind" != "" && test "$with_valgrind" != "no"; then
+AC_CHECK_HEADER(valgrind/memcheck.h, [],
+ AC_MSG_ERROR([valgrind requested but <valgrind/memcheck.h> not found.]))
+fi
+
fi
AC_CACHE_CHECK(whether ld accepts --version-script, ac_cv_version_script,
Index: ofa_1_3_dev_user/src/userspace/libibcm/src/cm.c
===================================================================
--- ofa_1_3_dev_user.orig/src/userspace/libibcm/src/cm.c 2007-09-19 08:31:54.000000000 +0200
+++ ofa_1_3_dev_user/src/userspace/libibcm/src/cm.c 2007-09-19 12:15:51.000000000 +0200
@@ -51,6 +51,17 @@
#include <infiniband/driver.h>
#include <infiniband/marshall.h>
+#ifdef INCLUDE_VALGRIND
+# include <valgrind/memcheck.h>
+# ifndef VALGRIND_MAKE_MEM_DEFINED
+# warning "Valgrind requested, but VALGRIND_MAKE_MEM_DEFINED undefined"
+# endif
+#endif
+
+#ifndef VALGRIND_MAKE_MEM_DEFINED
+# define VALGRIND_MAKE_MEM_DEFINED(addr,len)
+#endif
+
#define PFX "libibcm: "
static int abi_ver;
@@ -226,6 +237,8 @@ int ib_cm_create_id(struct ib_cm_device
if (result != size)
goto err;
+ VALGRIND_MAKE_MEM_DEFINED(resp, sizeof *resp);
+
cm_id_priv->id.handle = resp->id;
*cm_id = &cm_id_priv->id;
return 0;
@@ -250,6 +263,8 @@ int ib_cm_destroy_id(struct ib_cm_id *cm
if (result != size)
return (result > 0) ? -ENODATA : result;
+ VALGRIND_MAKE_MEM_DEFINED(resp, sizeof *resp);
+
cm_id_priv = container_of(cm_id, struct cm_id_private, id);
pthread_mutex_lock(&cm_id_priv->mut);
@@ -279,6 +294,8 @@ int ib_cm_attr_id(struct ib_cm_id *cm_id
if (result != size)
return (result > 0) ? -ENODATA : result;
+ VALGRIND_MAKE_MEM_DEFINED(resp, sizeof *resp);
+
param->service_id = resp->service_id;
param->service_mask = resp->service_mask;
param->local_id = resp->local_id;
@@ -307,6 +324,8 @@ int ib_cm_init_qp_attr(struct ib_cm_id *
if (result != size)
return (result > 0) ? -ENODATA : result;
+ VALGRIND_MAKE_MEM_DEFINED(resp, sizeof *resp);
+
*qp_attr_mask = resp->qp_attr_mask;
ibv_copy_qp_attr_from_kern(qp_attr, resp);
@@ -782,7 +801,7 @@ int ib_cm_get_event(struct ib_cm_device
msg = alloca(size);
if (!msg)
return -ENOMEM;
-
+
hdr = msg;
cmd = msg + sizeof(*hdr);
@@ -790,6 +809,8 @@ int ib_cm_get_event(struct ib_cm_device
hdr->in = sizeof(*cmd);
hdr->out = sizeof(*resp);
+ memset(cmd, 0, sizeof(*cmd));
+
resp = alloca(sizeof(*resp));
if (!resp)
return -ENOMEM;
@@ -818,6 +839,9 @@ int ib_cm_get_event(struct ib_cm_device
result = (result > 0) ? -ENODATA : result;
goto done;
}
+
+ VALGRIND_MAKE_MEM_DEFINED(resp, sizeof *resp);
+
/*
* decode event.
*/
More information about the general
mailing list