public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
To: Intel Graphics Development <intel-gfx@lists.freedesktop.org>
Subject: [PATCH i-g-t] lib: Add basic support for valgrind annotations.
Date: Tue, 7 Feb 2017 16:12:28 +0100	[thread overview]
Message-ID: <99fd0c02-8ef0-3be7-ef11-4d5c1136a589@linux.intel.com> (raw)

SIGRTMAX appears to be used by valgrind now for its internal tracking,
so avoid it in the helpers.

Also add some valgrind annotations in gem_mmap, to make sure that its
accesses are tracked correctly.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
---
diff --git a/configure.ac b/configure.ac
index 5bdd744a0750..562d5525e894 100644
--- a/configure.ac
+++ b/configure.ac
@@ -124,6 +124,11 @@ PKG_CHECK_MODULES(DRM, [libdrm])
 PKG_CHECK_MODULES(PCIACCESS, [pciaccess >= 0.10])
 PKG_CHECK_MODULES(KMOD, [libkmod])
 PKG_CHECK_MODULES(PROCPS, [libprocps])
+PKG_CHECK_MODULES(VALGRIND, [valgrind], [have_valgrind=yes], [have_valgrind=no])
+
+if test x$have_valgrind = xyes; then
+	AC_DEFINE(HAVE_VALGRIND, 1, [Enable valgrind annotation support.])
+fi
 
 case "$target_cpu" in
 	x86*|i?86)
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 7030ea27dc27..c0ddf2986849 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -34,6 +34,7 @@ AM_CFLAGS = \
 	    $(XMLRPC_CFLAGS) \
 	    $(LIBUDEV_CFLAGS) \
 	    $(PIXMAN_CFLAGS) \
+	    $(VALGRIND_CFLAGS) \
 	    -DIGT_SRCDIR=\""$(abs_top_srcdir)/tests"\" \
 	    -DIGT_DATADIR=\""$(pkgdatadir)"\" \
 	    -DIGT_LOG_DOMAIN=\""$(subst _,-,$*)"\" \
diff --git a/lib/igt_aux.c b/lib/igt_aux.c
index 763e997c5b83..eb4ca640128a 100644
--- a/lib/igt_aux.c
+++ b/lib/igt_aux.c
@@ -402,7 +402,7 @@ void igt_fork_hang_detector(int fd)
 
 	igt_assert(fstat(fd, &st) == 0);
 
-	signal(SIGRTMAX, sig_abort);
+	signal(SIGRTMAX - 1, sig_abort);
 	igt_fork_helper(&hang_detector)
 		hang_detector_process(getppid(), st.st_rdev);
 }
diff --git a/lib/igt_dummyload.c b/lib/igt_dummyload.c
index 7ceb370b6fcb..bff67433b21d 100644
--- a/lib/igt_dummyload.c
+++ b/lib/igt_dummyload.c
@@ -220,7 +220,8 @@ void igt_spin_batch_set_timeout(igt_spin_t *spin, int64_t ns)
 
 	igt_assert(!spin->timer);
 
-	if (spin_signo == SIGRTMAX)
+	/* SIGRTMAX is used by valgrind, SIGRTMAX - 1 by igt_fork_hang_detector */
+	if (spin_signo >= SIGRTMAX - 2)
 		spin_signo = SIGRTMIN;
 	spin->signo = ++spin_signo;
 
diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
index cd0c24ba871a..8b45967d3b76 100644
--- a/lib/ioctl_wrappers.c
+++ b/lib/ioctl_wrappers.c
@@ -56,6 +56,15 @@
 #include "igt_debugfs.h"
 #include "config.h"
 
+#ifdef HAVE_VALGRIND
+#include <valgrind/valgrind.h>
+#include <valgrind/memcheck.h>
+
+#define VG(x) x
+#else
+#define VG(x)
+#endif
+
 #include "ioctl_wrappers.h"
 
 /**
@@ -734,6 +743,8 @@ void *__gem_mmap__wc(int fd, uint32_t handle, uint64_t offset, uint64_t size, un
 	if (igt_ioctl(fd, LOCAL_IOCTL_I915_GEM_MMAP_v2, &arg))
 		return NULL;
 
+	VG(VALGRIND_MAKE_MEM_DEFINED(from_user_pointer(arg.addr_ptr), arg.size));
+
 	errno = 0;
 	return from_user_pointer(arg.addr_ptr);
 }
@@ -781,6 +792,8 @@ void *__gem_mmap__cpu(int fd, uint32_t handle, uint64_t offset, uint64_t size, u
 	if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_MMAP, &mmap_arg))
 		return NULL;
 
+	VG(VALGRIND_MAKE_MEM_DEFINED(from_user_pointer(mmap_arg.addr_ptr), mmap_arg.size));
+
 	errno = 0;
 	return from_user_pointer(mmap_arg.addr_ptr);
 }

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

             reply	other threads:[~2017-02-07 15:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-07 15:12 Maarten Lankhorst [this message]
2017-02-09  9:59 ` [PATCH i-g-t] lib: Add basic support for valgrind annotations Tomeu Vizoso
2017-02-09 10:03   ` Maarten Lankhorst
2017-02-09 10:09   ` [PATCH v2 " Maarten Lankhorst

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=99fd0c02-8ef0-3be7-ef11-4d5c1136a589@linux.intel.com \
    --to=maarten.lankhorst@linux.intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox