]> git.openfabrics.org - ~shefty/libibcm.git/commitdiff
Added valgrind support to the libibcm.
authorSean Hefty <sean.hefty@intel.com>
Wed, 19 Sep 2007 17:46:26 +0000 (10:46 -0700)
committerSean Hefty <sean.hefty@intel.com>
Wed, 19 Sep 2007 17:46:26 +0000 (10:46 -0700)
Signed-off-by: Dotan Barak <dotanb@dev.mellanox.co.il>
Signed-off-by: Sean Hefty <sean.hefty@intel.com>
configure.in
src/cm.c

index e33a188c4acef9db918f4447b9d29d193c26d046..7de8013a56101f8d4b131e76c5d26c23b11b4263 100644 (file)
@@ -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 25729726a6eb9056a77dcec4b8c6a0bce516a6fa..7370abe1492841ba6cb49fe8a09c8ce6719ec0b5 100644 (file)
--- a/src/cm.c
+++ b/src/cm.c
 #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 *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_id)
        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, struct ib_cm_attr_param *param)
        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 *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 *device, struct ib_cm_event **event)
        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 *device, struct ib_cm_event **event)
        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 *device, struct ib_cm_event **event)
                result = (result > 0) ? -ENODATA : result;
                goto done;
        }
+
+       VALGRIND_MAKE_MEM_DEFINED(resp, sizeof *resp);
+
        /*
         * decode event.
         */