Mesa (master): i965: Create drm_intel_bo_map wrappers with performance warnings.

Kenneth Graunke kwg at kemper.freedesktop.org
Tue Feb 4 00:21:34 UTC 2014


Module: Mesa
Branch: master
Commit: d613bafe9111a577bed6bb89ef559df40712674c
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=d613bafe9111a577bed6bb89ef559df40712674c

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Wed Jan 29 09:09:18 2014 -0800

i965: Create drm_intel_bo_map wrappers with performance warnings.

Mapping a buffer is a common place where we could stall the CPU.

In a few places, we've added special code to check whether a buffer is
busy and log the stall as a performance warning.  Most of these give no
indication of the severity of the stall, though, since measuring the
time is a small hassle.

This patch introduces a new brw_bo_map() function which wraps
drm_intel_bo_map, but additionally measures the time stalled and reports
a performance warning.  If performance debugging is not enabled, it
simply maps the buffer with negligable overhead.

We also add a similar wrapper for drm_intel_gem_bo_map_gtt().

This should make it easy to add performance warnings in lots of places.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
Reviewed-by: Carl Worth <cworth at cworth.org>
Reviewed-by: Eric Anholt <eric at anholt.net>

---

 src/mesa/drivers/dri/i965/brw_context.h          |    6 ++++
 src/mesa/drivers/dri/i965/intel_buffer_objects.c |   40 ++++++++++++++++++++++
 2 files changed, 46 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index afa3350..a0189b7 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -1658,6 +1658,12 @@ void brw_dump_perf_monitors(struct brw_context *brw);
 void brw_perf_monitor_new_batch(struct brw_context *brw);
 void brw_perf_monitor_finish_batch(struct brw_context *brw);
 
+/* intel_buffer_objects.c */
+int brw_bo_map(struct brw_context *brw, drm_intel_bo *bo, int write_enable,
+               const char *bo_name);
+int brw_bo_map_gtt(struct brw_context *brw, drm_intel_bo *bo,
+                   const char *bo_name);
+
 /* intel_extensions.c */
 extern void intelInitExtensions(struct gl_context *ctx);
 
diff --git a/src/mesa/drivers/dri/i965/intel_buffer_objects.c b/src/mesa/drivers/dri/i965/intel_buffer_objects.c
index 4d7044a..a493c3b 100644
--- a/src/mesa/drivers/dri/i965/intel_buffer_objects.c
+++ b/src/mesa/drivers/dri/i965/intel_buffer_objects.c
@@ -41,6 +41,46 @@
 #include "intel_buffer_objects.h"
 #include "intel_batchbuffer.h"
 
+/**
+ * Map a buffer object; issue performance warnings if mapping causes stalls.
+ *
+ * This matches the drm_intel_bo_map API, but takes an additional human-readable
+ * name for the buffer object to use in the performance debug message.
+ */
+int
+brw_bo_map(struct brw_context *brw,
+           drm_intel_bo *bo, int write_enable,
+           const char *bo_name)
+{
+   if (likely(!brw->perf_debug) || !drm_intel_bo_busy(bo))
+      return drm_intel_bo_map(bo, write_enable);
+
+   float start_time = get_time();
+
+   int ret = drm_intel_bo_map(bo, write_enable);
+
+   perf_debug("CPU mapping a busy %s BO stalled and took %.03f ms.\n",
+              bo_name, (get_time() - start_time) * 1000);
+
+   return ret;
+}
+
+int
+brw_bo_map_gtt(struct brw_context *brw, drm_intel_bo *bo, const char *bo_name)
+{
+   if (likely(!brw->perf_debug) || !drm_intel_bo_busy(bo))
+      return drm_intel_gem_bo_map_gtt(bo);
+
+   float start_time = get_time();
+
+   int ret = drm_intel_gem_bo_map_gtt(bo);
+
+   perf_debug("GTT mapping a busy %s BO stalled and took %.03f ms.\n",
+              bo_name, (get_time() - start_time) * 1000);
+
+   return ret;
+}
+
 static GLboolean
 intel_bufferobj_unmap(struct gl_context * ctx, struct gl_buffer_object *obj);
 




More information about the mesa-commit mailing list