vc4: Tell valgrind about BO allocations from mmap time to destroy.
authorEric Anholt <eric@anholt.net>
Tue, 2 Aug 2016 22:01:59 +0000 (15:01 -0700)
committerEric Anholt <eric@anholt.net>
Wed, 3 Aug 2016 17:28:20 +0000 (10:28 -0700)
This helps in debugging memory pressure.  It would be nice if we could
tell valgrind about it all the way from allocation time to destroy, but we
need a pointer to hand to VALGRIND_MALLOCLIKE_BLOCK.

src/gallium/drivers/vc4/Makefile.am
src/gallium/drivers/vc4/vc4_bufmgr.c

index de82c2c515f301486c89e414994ccd34cc4fbbbe..19fc3875955396a13b9840f3f95ce86c0aff6ddf 100644 (file)
@@ -32,6 +32,7 @@ AM_CFLAGS = \
        $(VC4_CFLAGS) \
        $(GALLIUM_DRIVER_CFLAGS) \
        $(SIM_CFLAGS) \
+       $(VALGRIND_CFLAGS) \
        $()
 
 noinst_LTLIBRARIES = libvc4.la
index f6bacfd39e0238aa71395b3e138a82646330ccd2..cf6a5114b876ff32bd88bc4339138cbcb1d2f981 100644 (file)
 #include "vc4_context.h"
 #include "vc4_screen.h"
 
+#ifdef HAVE_VALGRIND
+#include <valgrind.h>
+#include <memcheck.h>
+#define VG(x) x
+#else
+#define VG(x)
+#endif
+
 static bool dump_stats = false;
 
 static void
@@ -209,6 +217,7 @@ vc4_bo_free(struct vc4_bo *bo)
                 }
 #endif
                 munmap(bo->map, bo->size);
+                VG(VALGRIND_FREELIKE_BLOCK(bo->map, 0));
         }
 
         struct drm_gem_close c;
@@ -618,6 +627,7 @@ vc4_bo_map_unsynchronized(struct vc4_bo *bo)
                         bo->handle, (long long)offset, bo->size);
                 abort();
         }
+        VG(VALGRIND_MALLOCLIKE_BLOCK(bo->map, bo->size, 0, false));
 
         return bo->map;
 }