diff --git a/intel/intel_bufmgr_gem.c b/intel/intel_bufmgr_gem.c index 21fe099..3b65a57 100644 --- a/intel/intel_bufmgr_gem.c +++ b/intel/intel_bufmgr_gem.c @@ -38,6 +38,7 @@ #include "config.h" #endif +#include #include #include #include @@ -657,6 +658,8 @@ retry: DBG("bo_create: buf %d (%s) %ldb\n", bo_gem->gem_handle, bo_gem->name, size); + VALGRIND_MALLOCLIKE_BLOCK(bo_gem->gem_handle, 0, size, 0); + return &bo_gem->bo; } @@ -895,8 +898,10 @@ static void drm_intel_gem_bo_unreference_locked_timed(drm_intel_bo *bo, drm_intel_bo_gem *bo_gem = (drm_intel_bo_gem *) bo; assert(atomic_read(&bo_gem->refcount) > 0); - if (atomic_dec_and_test(&bo_gem->refcount)) + if (atomic_dec_and_test(&bo_gem->refcount)) { drm_intel_gem_bo_unreference_final(bo, time); + VALGRIND_FREELIKE_BLOCK(bo_gem->gem_handle, bo_gem->bo.size); + } } static void drm_intel_gem_bo_unreference(drm_intel_bo *bo) @@ -911,7 +916,9 @@ static void drm_intel_gem_bo_unreference(drm_intel_bo *bo) clock_gettime(CLOCK_MONOTONIC, &time); + pthread_mutex_lock(&bufmgr_gem->lock); + VALGRIND_FREELIKE_BLOCK( bo_gem->gem_handle, bo_gem->bo.size ); drm_intel_gem_bo_unreference_final(bo, time.tv_sec); pthread_mutex_unlock(&bufmgr_gem->lock); } @@ -957,6 +964,7 @@ static int drm_intel_gem_bo_map(drm_intel_bo *bo, int write_enable) DBG("bo_map: %d (%s) -> %p\n", bo_gem->gem_handle, bo_gem->name, bo_gem->mem_virtual); bo->virtual = bo_gem->mem_virtual; + VALGRIND_MALLOCLIKE_BLOCK(bo_gem->mem_virtual, bo->size, bo_gem->gem_handle, 1); set_domain.handle = bo_gem->gem_handle; set_domain.read_domains = I915_GEM_DOMAIN_CPU; @@ -1038,6 +1046,8 @@ int drm_intel_gem_bo_map_gtt(drm_intel_bo *bo) bo->virtual = bo_gem->gtt_virtual; + VALGRIND_MALLOCLIKE_BLOCK(bo_gem->gtt_virtual, bo->size, bo_gem->gem_handle, 2); + DBG("bo_map_gtt: %d (%s) -> %p\n", bo_gem->gem_handle, bo_gem->name, bo_gem->gtt_virtual); @@ -1076,8 +1086,10 @@ int drm_intel_gem_bo_unmap_gtt(drm_intel_bo *bo) pthread_mutex_lock(&bufmgr_gem->lock); bo->virtual = NULL; + VALGRIND_FREELIKE_BLOCK( bo_gem->gtt_virtual, bo->size ); pthread_mutex_unlock(&bufmgr_gem->lock); + return ret; } @@ -1107,6 +1119,7 @@ static int drm_intel_gem_bo_unmap(drm_intel_bo *bo) ret = ret == -1 ? -errno : 0; bo->virtual = NULL; + VALGRIND_FREELIKE_BLOCK(bo_gem->mem_virtual, bo->size); pthread_mutex_unlock(&bufmgr_gem->lock); return ret;