Skip to contentSkip to conversation

AUB file dump support patches

PATCH In review Zhenyu Wang 4 participants 14 messages Feb 16, 2011 – Feb 23, 2011

lore
Share & tools
lore
#0 lore raw

AUB file is the input data for internal GenX GPU simulator, which has been proved really helpful when debugging for new GenX architecture. AUB file itself actually contains different kinds of trace blocks for GPU execution, e.g batch/ring buffer, surface states, pipeline FF states, etc.

This series contain patches again libdrm and mesa to add AUB file dump support. Thanks to Eric and Yuanhan who did most of the hard work.

First one is for libdrm, which has new API definition for enable aub file dump, and BMP dump for required surface. Note that we just use a fake GTT space in AUB dump, which is not necessarily equal to real GTT address.

Following ones are for mesa, which should be simple enough.

After applying these patches, do 'export INTEL_DEBUG=aub'. 'intel.aub' file will be generated when you run some 3D test. How to use it? For example,

AubList intel.aub : generate intel.lst which 3D state info and
ring/batch commands

AubLoad intel.aub -device sbrD0 : start fulsim to run the aub as
Sandybridge D0.

Please help to review.

Thanks.

#1 lore raw

PATCH 1/3 intel: new debug option for aub file dump

New INTEL_DEBUG option to enable aub file dump with intel drm.

---
 src/mesa/drivers/dri/intel/intel_context.c |   10 ++++++++++
 src/mesa/drivers/dri/intel/intel_context.h |    2 ++
 2 files changed, 12 insertions(+), 0 deletions(-)
src/mesa/drivers/dri/intel/intel_context.c +10 -0
index 65c4148..45e9915 100644
@@ -522,6 +522,7 @@ static const struct dri_debug_control debug_control[] = {
    { "urb",   DEBUG_URB },
    { "vs",    DEBUG_VS },
    { "clip",  DEBUG_CLIP },
+   { "aub",   DEBUG_AUB },
    { NULL,    0 }
 };
 
@@ -863,6 +864,15 @@ intelInitContext(struct intel_context *intel,
    if (INTEL_DEBUG & DEBUG_BUFMGR)
       dri_bufmgr_set_debug(intel->bufmgr, GL_TRUE);
 
+   if (INTEL_DEBUG & DEBUG_AUB) {
+       fprintf(stderr, "Enable Aub file dump.\n");
+       intel->aub_file = fopen("intel.aub", "w");
+       if (intel->aub_file)
+          drm_intel_bufmgr_gem_set_aubfile(intel->bufmgr, intel->aub_file);
+       else
+          fprintf(stderr, "Fail to create aub file.\n");
+   }
+
    intel->batch = intel_batchbuffer_alloc(intel);
 
    intel_fbo_init(intel);
src/mesa/drivers/dri/intel/intel_context.h +2 -0
index 134e07e..c3c83e4 100644
@@ -267,6 +267,7 @@ struct intel_context
     * Configuration cache
     */
    driOptionCache optionCache;
+   FILE *aub_file;
 };
 
 extern char *__progname;
@@ -360,6 +361,7 @@ extern int INTEL_DEBUG;
 #define DEBUG_URB       0x1000000
 #define DEBUG_VS        0x2000000
 #define DEBUG_CLIP      0x8000000
+#define DEBUG_AUB      0x10000000
 
 #define DBG(...) do {						\
 	if (unlikely(INTEL_DEBUG & FILE_DEBUG_FLAG))		\
Signature · 1 line
1.7.2.3
#2 lore raw

PATCH 1/1 intel: Add AUB file dump support

In reply to Zhenyu Wang

This adds AUB file dump support to generate execution trace for internal GPU simulator.

---
 intel/Makefile.am        |    3 +-
 intel/intel_bufmgr.h     |   38 +++++
 intel/intel_bufmgr_gem.c |  402 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 442 insertions(+), 1 deletions(-)
intel/Makefile.am +2 -1
index 1ae92f8..398cd2f 100644
@@ -41,7 +41,8 @@ libdrm_intel_la_SOURCES = \
 	intel_bufmgr_gem.c \
 	intel_chipset.h \
 	mm.c \
-	mm.h
+	mm.h \
+	intel_aub.h
 
 libdrm_intelincludedir = ${includedir}/libdrm
 libdrm_intelinclude_HEADERS = intel_bufmgr.h
intel/intel_bufmgr.h +38 -0
index daa18b4..bb4158a 100644
@@ -35,6 +35,7 @@
 #define INTEL_BUFMGR_H
 
 #include <stdint.h>
+#include <stdio.h>
 
 struct drm_clip_rect;
 
@@ -83,6 +84,39 @@ struct _drm_intel_bo {
 	int handle;
 };
 
+enum drm_intel_aub_bmp_format {
+	AUB_DUMP_BMP_LEGACY,
+	AUB_DUMP_BMP_8BIT,
+	AUB_DUMP_BMP_ARGB_0555,
+	AUB_DUMP_BMP_ARGB_0565,
+	AUB_DUMP_BMP_ARGB_4444,
+	AUB_DUMP_BMP_ARGB_1555,
+	AUB_DUMP_BMP_ARGB_0888,
+	AUB_DUMP_BMP_ARGB_8888,
+	AUB_DUMP_BMP_YCRCB_SWAPY,
+	AUB_DUMP_BMP_YCRCB_NORMAL,
+	AUB_DUMP_BMP_YCRCB_SWAPUV,
+	AUB_DUMP_BMP_YCRCB_SWAPUVY,
+	AUB_DUMP_BMP_ABGR_8888,
+};
+
+/*
+ * surface info needed by aub DUMP_BMP block
+ */
+struct drm_intel_aub_surface_bmp {
+	uint16_t x_offset;
+	uint16_t y_offset;
+	uint16_t pitch;
+	uint8_t bits_per_pixel;
+	uint8_t format;
+	uint16_t width;
+	uint16_t height;
+	uint32_t tiling_walk_y:1;
+	uint32_t tiling:1;
+	uint32_t pad:30;
+};
+
+
 #define BO_ALLOC_FOR_RENDER (1<<0)
 
 drm_intel_bo *drm_intel_bo_alloc(drm_intel_bufmgr *bufmgr, const char *name,
@@ -150,6 +184,10 @@ int drm_intel_gem_bo_unmap_gtt(drm_intel_bo *bo);
 void drm_intel_gem_bo_start_gtt_access(drm_intel_bo *bo, int write_enable);
 
 int drm_intel_get_pipe_from_crtc_id(drm_intel_bufmgr *bufmgr, int crtc_id);
+void drm_intel_bufmgr_gem_set_aubfile(drm_intel_bufmgr *bufmgr, FILE *file);
+void drm_intel_bufmgr_gem_stop_aubfile(drm_intel_bufmgr *bufmgr);
+int drm_intel_gem_aub_dump_bmp(drm_intel_bufmgr *bufmgr, drm_intel_bo *bo,
+			       unsigned int offset, struct drm_intel_aub_surface_bmp *bmp);
 
 /* drm_intel_bufmgr_fake.c */
 drm_intel_bufmgr *drm_intel_bufmgr_fake_init(int fd,
intel/intel_bufmgr_gem.c +402 -0

434 lines not on this page · raw message

Signature · 1 line
1.7.2.3
#3 lore raw

Re: [PATCH] intel: Add AUB file dump support

Could you add a entry for media kernel for name_to_type_mapping or just use a common name for all tracked kernels?

Thanks
Haihao

Quoted 533 lines

This adds AUB file dump support to generate execution trace for internal GPU simulator.

---
 intel/Makefile.am        |    3 +-
 intel/intel_bufmgr.h     |   38 +++++
 intel/intel_bufmgr_gem.c |  402 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 442 insertions(+), 1 deletions(-)
intel/Makefile.am +2 -1
index 1ae92f8..398cd2f 100644
@@ -41,7 +41,8 @@ libdrm_intel_la_SOURCES = \
        intel_bufmgr_gem.c \
        intel_chipset.h \
        mm.c \
-       mm.h
+       mm.h \
+       intel_aub.h
 
 libdrm_intelincludedir = ${includedir}/libdrm
 libdrm_intelinclude_HEADERS = intel_bufmgr.h
intel/intel_bufmgr.h +38 -0
index daa18b4..bb4158a 100644
@@ -35,6 +35,7 @@
 #define INTEL_BUFMGR_H
 
 #include <stdint.h>
+#include <stdio.h>
 
 struct drm_clip_rect;
 
@@ -83,6 +84,39 @@ struct _drm_intel_bo {
        int handle;
 };
 
+enum drm_intel_aub_bmp_format {
+       AUB_DUMP_BMP_LEGACY,
+       AUB_DUMP_BMP_8BIT,
+       AUB_DUMP_BMP_ARGB_0555,
+       AUB_DUMP_BMP_ARGB_0565,
+       AUB_DUMP_BMP_ARGB_4444,
+       AUB_DUMP_BMP_ARGB_1555,
+       AUB_DUMP_BMP_ARGB_0888,
+       AUB_DUMP_BMP_ARGB_8888,
+       AUB_DUMP_BMP_YCRCB_SWAPY,
+       AUB_DUMP_BMP_YCRCB_NORMAL,
+       AUB_DUMP_BMP_YCRCB_SWAPUV,
+       AUB_DUMP_BMP_YCRCB_SWAPUVY,
+       AUB_DUMP_BMP_ABGR_8888,
+};
+
+/*
+ * surface info needed by aub DUMP_BMP block
+ */
+struct drm_intel_aub_surface_bmp {
+       uint16_t x_offset;
+       uint16_t y_offset;
+       uint16_t pitch;
+       uint8_t bits_per_pixel;
+       uint8_t format;
+       uint16_t width;
+       uint16_t height;
+       uint32_t tiling_walk_y:1;
+       uint32_t tiling:1;
+       uint32_t pad:30;
+};
+
+
 #define BO_ALLOC_FOR_RENDER (1<<0)
 
 drm_intel_bo *drm_intel_bo_alloc(drm_intel_bufmgr *bufmgr, const char *name,
@@ -150,6 +184,10 @@ int drm_intel_gem_bo_unmap_gtt(drm_intel_bo *bo);
 void drm_intel_gem_bo_start_gtt_access(drm_intel_bo *bo, int write_enable);
 
 int drm_intel_get_pipe_from_crtc_id(drm_intel_bufmgr *bufmgr, int crtc_id);
+void drm_intel_bufmgr_gem_set_aubfile(drm_intel_bufmgr *bufmgr, FILE *file);
+void drm_intel_bufmgr_gem_stop_aubfile(drm_intel_bufmgr *bufmgr);
+int drm_intel_gem_aub_dump_bmp(drm_intel_bufmgr *bufmgr, drm_intel_bo *bo,
+                              unsigned int offset, struct drm_intel_aub_surface_bmp *bmp);
 
 /* drm_intel_bufmgr_fake.c */
 drm_intel_bufmgr *drm_intel_bufmgr_fake_init(int fd,
intel/intel_bufmgr_gem.c +402 -1
index 3cdffce..654bc31 100644
@@ -57,6 +57,7 @@
 #include "intel_bufmgr.h"
 #include "intel_bufmgr_priv.h"
 #include "intel_chipset.h"
+#include "intel_aub.h"
 #include "string.h"
 
 #include "i915_drm.h"
@@ -75,6 +76,13 @@ struct drm_intel_gem_bo_bucket {
        unsigned long size;
 };
 
+struct drm_intel_aub_bmp {
+       drm_intel_bo *bo; /* surface bo */
+       unsigned int offset;
+       struct drm_intel_aub_surface_bmp bmp;
+       struct drm_intel_aub_bmp *next;
+};
+
 typedef struct _drm_intel_bufmgr_gem {
        drm_intel_bufmgr bufmgr;
 
@@ -106,6 +114,10 @@ typedef struct _drm_intel_bufmgr_gem {
        unsigned int has_relaxed_fencing : 1;
        unsigned int bo_reuse : 1;
        char fenced_relocs;
+
+       FILE *aub_file;
+       uint32_t aub_offset;
+       struct drm_intel_aub_bmp *aub_bmp;
 } drm_intel_bufmgr_gem;
 
 #define DRM_INTEL_RELOC_FENCE (1<<0)
@@ -195,8 +207,396 @@ struct _drm_intel_bo_gem {
         * relocations.
         */
        int reloc_tree_fences;
+
+       uint32_t aub_offset;
 };
 
+/* AUB trace dump support */
+
+static void
+aub_out(drm_intel_bufmgr_gem *bufmgr_gem, uint32_t data)
+{
+       fwrite(&data, 1, 4, bufmgr_gem->aub_file);
+}
+
+static void
+aub_out_data(drm_intel_bufmgr_gem *bufmgr_gem, void *data, size_t size)
+{
+       fwrite(data, 1, size, bufmgr_gem->aub_file);
+}
+
+static void
+aub_write_bo_data(drm_intel_bo *bo, uint32_t offset, uint32_t size)
+{
+       drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bo->bufmgr;
+       drm_intel_bo_gem *bo_gem = (drm_intel_bo_gem *) bo;
+       uint32_t *data;
+       unsigned int i;
+
+       data = malloc(bo->size);
+       drm_intel_bo_get_subdata(bo, offset, size, data);
+
+       /* Easy mode: write out bo with no relocations */
+       if (!bo_gem->reloc_count) {
+               aub_out_data(bufmgr_gem, data, size);
+               free(data);
+               return;
+       }
+
+       /* Otherwise, handle the relocations while writing. */
+       for (i = 0; i < size / 4; i++) {
+               int r;
+               for (r = 0; r < bo_gem->reloc_count; r++) {
+                       struct drm_i915_gem_relocation_entry *reloc;
+                       drm_intel_reloc_target *info;
+
+                       reloc = &bo_gem->relocs[r];
+                       info = &bo_gem->reloc_target_info[r];
+
+                       if (reloc->offset == offset + i * 4) {
+                               drm_intel_bo_gem *target_gem;
+                               uint32_t val;
+
+                               target_gem = (drm_intel_bo_gem *)info->bo;
+
+                               val = reloc->delta;
+                               val += target_gem->aub_offset;
+
+                               aub_out(bufmgr_gem, val);
+                               data[i] = val;
+                               break;
+                       }
+               }
+               if (r == bo_gem->reloc_count) {
+                       /* no relocation, just the data */
+                       aub_out(bufmgr_gem, data[i]);
+               }
+       }
+}
+
+static void
+aub_bo_get_address(drm_intel_bo *bo)
+{
+       drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bo->bufmgr;
+       drm_intel_bo_gem *bo_gem = (drm_intel_bo_gem *) bo;
+
+       /* Give the object a graphics address in the AUB file.  We
+        * don't just use the GEM object address because we do AUB
+        * dumping before execution -- we want to successfully log
+        * when the hardware might hang, and we might even want to aub
+        * capture for a driver trying to execute on a different
+        * generation of hardware by disabling the actual kernel exec
+        * call.
+        */
+       bo_gem->aub_offset = bufmgr_gem->aub_offset;
+       bufmgr_gem->aub_offset += bo->size;
+       /* XXX: Handle aperture overflow. */
+       assert(bufmgr_gem->aub_offset < 256 * 1024 * 1024);
+}
+
+static const struct {
+       const char *name;
+       uint32_t type;
+       uint32_t subtype;
+} name_to_type_mapping[] = {
+       { "VS_UNIT",    AUB_TRACE_TYPE_GENERAL, AUB_TRACE_VS_STATE},
+       { "GS_UNIT",    AUB_TRACE_TYPE_GENERAL, AUB_TRACE_GS_STATE},
+       { "CLIP_UNIT",  AUB_TRACE_TYPE_GENERAL, AUB_TRACE_CL_STATE},
+       { "SF_UNIT",    AUB_TRACE_TYPE_GENERAL, AUB_TRACE_SF_STATE},
+       { "WM_UNIT",    AUB_TRACE_TYPE_GENERAL, AUB_TRACE_WM_STATE},
+       { "CC_UNIT",    AUB_TRACE_TYPE_GENERAL, AUB_TRACE_CC_STATE},
+       { "CLIP_VP",    AUB_TRACE_TYPE_GENERAL, AUB_TRACE_CL_VP},
+       { "SF_VP",      AUB_TRACE_TYPE_GENERAL, AUB_TRACE_SF_VP},
+       { "SF_SCISSOR_UNIT",
+         AUB_TRACE_TYPE_GENERAL, AUB_TRACE_SF_SCISSOR_RECT},
+       { "CC_VP",      AUB_TRACE_TYPE_GENERAL, AUB_TRACE_CC_VP},
+       { "SAMPLER",    AUB_TRACE_TYPE_GENERAL, AUB_TRACE_SAMPLER_STATE},
+       { "SAMPLER_DEFAULT_COLOR", AUB_TRACE_TYPE_GENERAL, AUB_TRACE_SDC},
+       { "VS_PROG",    AUB_TRACE_TYPE_GENERAL, AUB_TRACE_KERNEL},
+       { "GS_PROG",    AUB_TRACE_TYPE_GENERAL, AUB_TRACE_KERNEL},
+       { "CLIP_PROG",  AUB_TRACE_TYPE_GENERAL, AUB_TRACE_KERNEL},
+       { "SF_PROG",    AUB_TRACE_TYPE_GENERAL, AUB_TRACE_KERNEL},
+       { "WM_PROG",    AUB_TRACE_TYPE_GENERAL, AUB_TRACE_KERNEL},
+       { "BLEND_STATE", AUB_TRACE_TYPE_GENERAL, AUB_TRACE_BLEND_STATE},
+       { "DEPTH_STENCIL_STATE",
+         AUB_TRACE_TYPE_GENERAL, AUB_TRACE_DEPTH_STENCIL_STATE},
+       { "COLOR_CALC_STATE", AUB_TRACE_TYPE_GENERAL, AUB_TRACE_CC_STATE},
+       { "SS_SURF_BIND", AUB_TRACE_TYPE_SURFACE, AUB_TRACE_BINDING_TABLE},
+       { "SS_SURFACE", AUB_TRACE_TYPE_SURFACE, AUB_TRACE_SURFACE_STATE},
+       { "temporary VBO", AUB_TRACE_TYPE_VERTEX_BUFFER, 0},
+       { "CURBE",      AUB_TRACE_TYPE_CONSTANT_URB, 0},
+       { "VS constant_bo", AUB_TRACE_TYPE_CONSTANT_BUFFER, 0},
+       { "WM constant_bo", AUB_TRACE_TYPE_CONSTANT_BUFFER, 0},
+       { "INTERFACE_DESC", AUB_TRACE_TYPE_GENERAL, AUB_TRACE_INTERFACE_DESC},
+       { "VLD_STATE", AUB_TRACE_TYPE_GENERAL, AUB_TRACE_VLD_STATE},
+       { "VFE_STATE", AUB_TRACE_TYPE_GENERAL, AUB_TRACE_VFE_STATE},
+       { "IT_STATE", AUB_TRACE_TYPE_GENERAL, AUB_TRACE_IT_STATE},
+       { "DI_SAMPLE_STATE", AUB_TRACE_TYPE_GENERAL, AUB_TRACE_DI_SAMPLE_STATE},
+       { "IEF_STATE", AUB_TRACE_TYPE_GENERAL, AUB_TRACE_IEF_STATE},
+       { "AVS_STATE", AUB_TRACE_TYPE_GENERAL, AUB_TRACE_AVS_STATE},
+};
+
+static void
+aub_write_trace_block(drm_intel_bo *bo, uint32_t type, uint32_t subtype,
+                     uint32_t offset, uint32_t size)
+{
+       drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bo->bufmgr;
+       drm_intel_bo_gem *bo_gem = (drm_intel_bo_gem *) bo;
+
+       aub_out(bufmgr_gem,
+               CMD_AUB_TRACE_HEADER_BLOCK |
+               (5 - 2));
+       aub_out(bufmgr_gem, AUB_TRACE_MEMTYPE_GTT | type | AUB_TRACE_OP_DATA_WRITE);
+       aub_out(bufmgr_gem, subtype);
+       aub_out(bufmgr_gem, bo_gem->aub_offset + offset);
+       aub_out(bufmgr_gem, size);
+       aub_write_bo_data(bo, offset, size);
+}
+
+static void
+aub_write_bo(drm_intel_bo *bo)
+{
+       drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bo->bufmgr;
+       drm_intel_bo_gem *bo_gem = (drm_intel_bo_gem *) bo;
+       uint32_t type = AUB_TRACE_TYPE_NOTYPE;
+       uint32_t subtype = 0;
+       uint32_t block_size;
+       uint32_t offset;
+       unsigned int i;
+
+       aub_bo_get_address(bo);
+
+       for (i = 0; i < ARRAY_SIZE(name_to_type_mapping); i++) {
+               if (strcmp(bo_gem->name,
+                          name_to_type_mapping[i].name) == 0) {
+                       type = name_to_type_mapping[i].type;
+                       subtype = name_to_type_mapping[i].subtype;
+                       break;
+               }
+       }
+
+       if (type == 0) {
+               DBG("Failed to find type for object %s(size: 0x%lx, aub_offset: 0x%08x)\n",
+                      bo_gem->name, bo->size, bo_gem->aub_offset);
+       }
+
+
+       /* Break up large objects into multiple writes.  Otherwise a
+        * 128kb VBO would overflow the 16 bits of size field in the
+        * packet header and everything goes badly after that.
+        */
+       for (offset = 0; offset < bo->size; offset += block_size) {
+               block_size = bo->size - offset;
+
+               if (block_size > 2 * 4096)
+                       block_size = 2 * 4096;
+
+               aub_write_trace_block(bo, type, subtype,
+                                     offset, block_size);
+       }
+}
+
+/*
+ * Make a ringbuffer on fly and dump it
+ */
+static void
+aub_generate_ringbuffer(drm_intel_bufmgr_gem *bufmgr_gem,
+                         uint32_t batch_buffer, unsigned int flags)
+{
+       uint32_t ringbuffer[1024];
+       int ring = 0;
+
+       switch (flags) {
+       case I915_EXEC_RENDER:
+       case I915_EXEC_DEFAULT:
+               ring = AUB_TRACE_TYPE_RING_PRB0;
+               break;
+       case I915_EXEC_BSD:
+               ring = AUB_TRACE_TYPE_RING_PRB1;
+               break;
+       case I915_EXEC_BLT:
+               ring = AUB_TRACE_TYPE_RING_PRB2;
+               break;
+       }
+
+       aub_out(bufmgr_gem,
+               CMD_AUB_TRACE_HEADER_BLOCK |
+               (5 - 2));
+       aub_out(bufmgr_gem,
+               AUB_TRACE_MEMTYPE_GTT | ring | AUB_TRACE_OP_COMMAND_WRITE);
+       aub_out(bufmgr_gem, 0); /* general/surface subtype */
+       aub_out(bufmgr_gem, bufmgr_gem->aub_offset);
+       aub_out(bufmgr_gem, 4096);
+
+       /* Do make a ring buffer here */
+       memset(ringbuffer, AUB_MI_NOOP, sizeof(ringbuffer));
+       ringbuffer[0] = AUB_MI_BATCH_BUFFER_START;
+       ringbuffer[1] = batch_buffer;
+
+       /* FIXME: Need some flush operations here? */
+
+       aub_out_data(bufmgr_gem, ringbuffer, 4096);
+
+       /* Update offset pointer */
+       bufmgr_gem->aub_offset += 4096;
+}
+
+static void
+aub_dump_bmp(drm_intel_bufmgr_gem *bufmgr_gem)
+{
+       struct drm_intel_aub_bmp *p = bufmgr_gem->aub_bmp;
+
+       while(p) {
+               aub_out(bufmgr_gem, CMD_AUB_DUMP_BMP | 4);
+               aub_out(bufmgr_gem, (p->bmp.y_offset << 16) | p->bmp.x_offset);
+               aub_out(bufmgr_gem, (p->bmp.format << 24) |
+                                   (p->bmp.bits_per_pixel << 16) | p->bmp.pitch);
+               aub_out(bufmgr_gem, (p->bmp.height << 16) | p->bmp.width);
+               /* surface bo should already be written out */
+               assert(((drm_intel_bo_gem *)p->bo)->aub_offset != 0);
+               aub_out(bufmgr_gem, ((drm_intel_bo_gem *)p->bo)->aub_offset + p->offset);
+               aub_out(bufmgr_gem, (p->bmp.tiling << 2) | (p->bmp.tiling_walk_y << 3));
+
+               bufmgr_gem->aub_bmp = p->next;
+               free(p);
+               p = bufmgr_gem->aub_bmp;
+       }
+}
+
+static void
+aub_exec(drm_intel_bo *bo, unsigned int flags)
+{
+       drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bo->bufmgr;
+       drm_intel_bo_gem *bo_gem = (drm_intel_bo_gem *) bo;
+       int i;
+
+       if (!bufmgr_gem->aub_file)
+               return;
+
+       /* Write out all but the batchbuffer to AUB memory */
+       for (i = 0; i < bufmgr_gem->exec_count - 1; i++) {
+               if (bufmgr_gem->exec_bos[i] != bo)
+                       aub_write_bo(bufmgr_gem->exec_bos[i]);
+       }
+
+       aub_bo_get_address(bo);
+
+       /* Dump the batchbuffer. */
+       aub_out(bufmgr_gem,
+               CMD_AUB_TRACE_HEADER_BLOCK |
+               (5 - 2));
+       aub_out(bufmgr_gem,
+               AUB_TRACE_MEMTYPE_GTT | AUB_TRACE_TYPE_BATCH | AUB_TRACE_OP_DATA_WRITE);
+       aub_out(bufmgr_gem, 0); /* general/surface subtype */
+       aub_out(bufmgr_gem, bo_gem->aub_offset);
+       aub_out(bufmgr_gem, bo_gem->bo.size);
+       aub_write_bo_data(bo, 0, bo_gem->bo.size);
+
+       /* Dump ring buffer */
+       aub_generate_ringbuffer(bufmgr_gem, bo_gem->aub_offset, flags);
+
+       /* Dump BMP file for any requested surface */
+       aub_dump_bmp(bufmgr_gem);
+
+       fflush(bufmgr_gem->aub_file);
+
+       /*
+        * One frame has been dumped. So reset the aub_offset for the next frame.
+        *
+        * FIXME: Can we do this?
+        */
+       bufmgr_gem->aub_offset = 0x10000;
+}
+
+/*
+ * Stop dumping data to aub file
+ */
+void drm_intel_bufmgr_gem_stop_aubfile(drm_intel_bufmgr *bufmgr)
+{
+       drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *)bufmgr;
+
+       pthread_mutex_lock(&bufmgr_gem->lock);
+       bufmgr_gem->aub_file = NULL;
+       pthread_mutex_unlock(&bufmgr_gem->lock);
+}
+
+void drm_intel_bufmgr_gem_set_aubfile(drm_intel_bufmgr *bufmgr, FILE *file)
+{
+       drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *)bufmgr;
+       int entry = 0x3; /* uc/valid GTT */
+       int i;
+
+       if (!file)
+               return;
+
+       pthread_mutex_lock(&bufmgr_gem->lock);
+
+       bufmgr_gem->aub_file = file;
+
+       /* Start from 0x10000, since the address below is used for GTT entry building */
+       bufmgr_gem->aub_offset = 0x10000;
+
+       /* Start with a (required) version packet. */
+       aub_out(bufmgr_gem, CMD_AUB_HEADER | (13 - 2));
+       aub_out(bufmgr_gem,
+               (4 << AUB_HEADER_MAJOR_SHIFT) |
+               (0 << AUB_HEADER_MINOR_SHIFT));
+       for (i = 0; i < 8; i++) {
+               aub_out(bufmgr_gem, 0); /* app name */
+       }
+       aub_out(bufmgr_gem, 0); /* timestamp */
+       aub_out(bufmgr_gem, 0); /* timestamp */
+       aub_out(bufmgr_gem, 0); /* comment len */
+
+       /* Set up the GTT. The max we can handle is 256M.
+        * Need improvement, dynamicly alloc/write GTT entry
+        * block for each bo, so AubList output won't contain
+        * whole GTT entry block in the first, easier for parse.
+        */
+       for (i = 0x000; i < 0x10000; i += 4, entry += 0x1000) {
+               aub_out(bufmgr_gem, CMD_AUB_TRACE_HEADER_BLOCK | (5 - 2));
+               aub_out(bufmgr_gem, AUB_TRACE_MEMTYPE_NONLOCAL | 0 | AUB_TRACE_OP_DATA_WRITE);
+               aub_out(bufmgr_gem, 0);
+               aub_out(bufmgr_gem, i);
+               aub_out(bufmgr_gem, 4);
+               aub_out(bufmgr_gem, entry);
+       }
+
+       pthread_mutex_unlock(&bufmgr_gem->lock);
+}
+
+int drm_intel_gem_aub_dump_bmp(drm_intel_bufmgr *bufmgr,
+                              drm_intel_bo *bo, unsigned int offset,
+                              struct drm_intel_aub_surface_bmp *bmp)
+{
+       drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *)bufmgr;
+       struct drm_intel_aub_bmp *aub_bmp, *p, *last;
+
+       aub_bmp = malloc(sizeof(*aub_bmp));
+
+       aub_bmp->bo = bo;
+       aub_bmp->offset = offset;
+       memcpy(&aub_bmp->bmp, bmp, sizeof(*bmp));
+       aub_bmp->next = NULL;
+
+       pthread_mutex_lock(&bufmgr_gem->lock);
+
+       /* Insert last */
+       p = last = bufmgr_gem->aub_bmp;
+       while (p) {
+               last = p;
+               p = p->next;
+       }
+       if (last == bufmgr_gem->aub_bmp)
+           bufmgr_gem->aub_bmp = aub_bmp;
+       else
+           last->next = aub_bmp;
+
+       pthread_mutex_unlock(&bufmgr_gem->lock);
+
+       return 0;
+}
+
 static unsigned int
 drm_intel_gem_estimate_batch_space(drm_intel_bo ** bo_array, int count);
 
@@ -1624,6 +2024,8 @@ drm_intel_gem_bo_mrb_exec2(drm_intel_bo *bo, int used,
        execbuf.rsvd1 = 0;
        execbuf.rsvd2 = 0;
 
+       aub_exec(bo, flags);
+
        ret = drmIoctl(bufmgr_gem->fd,
                       DRM_IOCTL_I915_GEM_EXECBUFFER2,
                       &execbuf);
--

1.7.2.3

#4 lore raw

Re: [PATCH] intel: Add AUB file dump support

Quoted 3 lines · Haihao

Could you add a entry for media kernel for name_to_type_mapping or just use a common name for all tracked kernels?

You mean media kernel requires special trace type?

For mesa, kernel names depend on which cache it is from, and as far as I know aub has no special requirement for kernel name. AubList could decode kernel source with offset specified in pipe states.

Signature · 3 lines
Open Source Technology Center, Intel ltd.

$gpg --keyserver wwwkeys.pgp.net --recv-keys 4D781827

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#5 lore raw

Re: [PATCH] intel: Add AUB file dump support

Quoted 6 lines · Zhenyu Wang
Quoted 3 lines · Haihao

Could you add a entry for media kernel for name_to_type_mapping or just use a common name for all tracked kernels?

You mean media kernel requires special trace type?

No.

Quoted 6 lines

For mesa, kernel names depend on which cache it is from, and as far as I know aub has no special requirement for kernel name. AubList could decode kernel source with offset specified in pipe states.

But I have to use a name specified in name_to_type_mapping when allocating a GEM BO for a media kernel, or aub doesn't know the trace type of this BO. Of course, I can also use 'VS_PROG'/'GS_PROG'/'CLIP_PROG'... for a media kernel :(.

#6 lore raw

Re: [PATCH] intel: Add AUB file dump support

Quoted 10 lines · Haihao
Quoted 5 lines

For mesa, kernel names depend on which cache it is from, and as far as I know aub has no special requirement for kernel name. AubList could decode kernel source with offset specified in pipe states.

But I have to use a name specified in name_to_type_mapping when allocating a GEM BO for a media kernel, or aub doesn't know the trace type of this BO. Of course, I can also use 'VS_PROG'/'GS_PROG'/'CLIP_PROG'... for a media kernel :(.

oh, right, I see. You still need subtype as kernel.

How about 'MEDIA_PROG'? Or what's the name for your current kernel?

Signature · 3 lines
Open Source Technology Center, Intel ltd.

$gpg --keyserver wwwkeys.pgp.net --recv-keys 4D781827

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#7 lore raw

Re: [PATCH] intel: Add AUB file dump support

Quoted 12 lines · Zhenyu Wang
Quoted 10 lines · Haihao
Quoted 5 lines

For mesa, kernel names depend on which cache it is from, and as far as I know aub has no special requirement for kernel name. AubList could decode kernel source with offset specified in pipe states.

But I have to use a name specified in name_to_type_mapping when allocating a GEM BO for a media kernel, or aub doesn't know the trace type of this BO. Of course, I can also use 'VS_PROG'/'GS_PROG'/'CLIP_PROG'... for a media kernel :(.

Quoted 3 lines

oh, right, I see. You still need subtype as kernel.

How about 'MEDIA_PROG'? Or what's the name for your current kernel?

'MEDIA_PROG' is ok for me

Thanks
Haihao

Quoted 1 line
#8 lore raw

Re: [PATCH] intel: Add AUB file dump support

Quoted 5 lines · Haihao
Quoted 3 lines

oh, right, I see. You still need subtype as kernel.

How about 'MEDIA_PROG'? Or what's the name for your current kernel?

'MEDIA_PROG' is ok for me

New libdrm patch for aub dump attached. Please help to test.

Thanks.

Signature · 3 lines
Open Source Technology Center, Intel ltd.

$gpg --keyserver wwwkeys.pgp.net --recv-keys 4D781827

From 804328390488f76c1bda02cdf0a4081e55657ff9 Mon Sep 17 00:00:00 2001
From: Zhenyu Wang <[email protected]>
Date: Tue, 22 Feb 2011 14:53:42 +0800
Subject: [PATCH] intel: Add AUB file dump support

This adds AUB file dump support to generate execution trace for internal GPU simulator.

---
 intel/Makefile.am        |    3 +-
 intel/intel_bufmgr.h     |   40 +++++
 intel/intel_bufmgr_gem.c |  397 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 439 insertions(+), 1 deletions(-)
intel/Makefile.am +2 -1
index 1ae92f8..398cd2f 100644
@@ -41,7 +41,8 @@ libdrm_intel_la_SOURCES = \
 	intel_bufmgr_gem.c \
 	intel_chipset.h \
 	mm.c \
-	mm.h
+	mm.h \
+	intel_aub.h
 
 libdrm_intelincludedir = ${includedir}/libdrm
 libdrm_intelinclude_HEADERS = intel_bufmgr.h
intel/intel_bufmgr.h +40 -0
index daa18b4..4eee7ac 100644
@@ -35,6 +35,7 @@
 #define INTEL_BUFMGR_H
 
 #include <stdint.h>
+#include <stdio.h>
 
 struct drm_clip_rect;
 
@@ -83,6 +84,41 @@ struct _drm_intel_bo {
 	int handle;
 };
 
+enum drm_intel_aub_bmp_format {
+	AUB_DUMP_BMP_LEGACY,
+	AUB_DUMP_BMP_8BIT,
+	AUB_DUMP_BMP_ARGB_0555,
+	AUB_DUMP_BMP_ARGB_0565,
+	AUB_DUMP_BMP_ARGB_4444,
+	AUB_DUMP_BMP_ARGB_1555,
+	AUB_DUMP_BMP_ARGB_0888,
+	AUB_DUMP_BMP_ARGB_8888,
+	AUB_DUMP_BMP_YCRCB_SWAPY,
+	AUB_DUMP_BMP_YCRCB_NORMAL,
+	AUB_DUMP_BMP_YCRCB_SWAPUV,
+	AUB_DUMP_BMP_YCRCB_SWAPUVY,
+	AUB_DUMP_BMP_ABGR_8888,
+};
+
+/*
+ * The information needed by aub DUMP_BMP command
+ *
+ * NOTE: this is for aub dump
+ */
+struct drm_intel_aub_surface_bmp {
+	uint16_t x_offset;
+	uint16_t y_offset;
+	uint16_t pitch;
+	uint8_t bits_per_pixel;
+	uint8_t format;
+	uint16_t width;
+	uint16_t height;
+	uint32_t tiling_walk_y:1;
+	uint32_t tiling:1;
+	uint32_t pad:30;
+};
+
+
 #define BO_ALLOC_FOR_RENDER (1<<0)
 
 drm_intel_bo *drm_intel_bo_alloc(drm_intel_bufmgr *bufmgr, const char *name,
@@ -150,6 +186,10 @@ int drm_intel_gem_bo_unmap_gtt(drm_intel_bo *bo);
 void drm_intel_gem_bo_start_gtt_access(drm_intel_bo *bo, int write_enable);
 
 int drm_intel_get_pipe_from_crtc_id(drm_intel_bufmgr *bufmgr, int crtc_id);
+void drm_intel_bufmgr_gem_set_aubfile(drm_intel_bufmgr *bufmgr, FILE *file);
+void drm_intel_bufmgr_gem_stop_aubfile(drm_intel_bufmgr *bufmgr);
+int drm_intel_gem_aub_dump_bmp(drm_intel_bufmgr *bufmgr, drm_intel_bo *bo,
+			       struct drm_intel_aub_surface_bmp *bmp);
 
 /* drm_intel_bufmgr_fake.c */
 drm_intel_bufmgr *drm_intel_bufmgr_fake_init(int fd,
intel/intel_bufmgr_gem.c +397 -0

429 lines not on this page · raw message

Signature · 1 line
1.7.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#9 lore raw

Re: [PATCH] intel: Add AUB file dump support

Quoted 8 lines · Zhenyu Wang
Quoted 5 lines · Haihao
Quoted 3 lines

oh, right, I see. You still need subtype as kernel.

How about 'MEDIA_PROG'? Or what's the name for your current kernel?

'MEDIA_PROG' is ok for me

New libdrm patch for aub dump attached. Please help to test.

While I originally hacked it up this way where libdrm intuits what kind of buffer it is from the name of the buffer, it's a bad way to design an interface. We should really have a command that marks (an area) of a buffer object as being a particular AUB type, and Mesa would use that command to mark its buffers as appropriate. Particularly since we're moving to streaming more of our state buffers into larger buffer objects.

We also can't commit code to Mesa that just writes into some arbitrary file based on an environment variable -- keep in mind that our Mesa driver is loaded from the X Server which is running as root.

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#10 lore raw

Re: [PATCH] intel: Add AUB file dump support

Quoted 7 lines · Eric Anholt

While I originally hacked it up this way where libdrm intuits what kind of buffer it is from the name of the buffer, it's a bad way to design an interface. We should really have a command that marks (an area) of a buffer object as being a particular AUB type, and Mesa would use that command to mark its buffers as appropriate. Particularly since we're moving to streaming more of our state buffers into larger buffer objects.

ok, if our plan is to move into larger buffer, current method is just hairy. Like I didn't hack up surface state and some others, coz it's twisted to convert current batch ending space usage into real bo for matching the name for trace block types.

Quoted 4 lines

We also can't commit code to Mesa that just writes into some arbitrary file based on an environment variable -- keep in mind that our Mesa driver is loaded from the X Server which is running as root.

yeah, I wasn't aware of this, any comment for how to dump the file?

Signature · 3 lines
Open Source Technology Center, Intel ltd.

$gpg --keyserver wwwkeys.pgp.net --recv-keys 4D781827

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#11 lore raw

Re: [PATCH] intel: Add AUB file dump support

On Tuesday, February 22, 2011 05:49:57 PM Zhenyu Wang wrote:
[snip]

Quoted 5 lines
Quoted 3 lines

We also can't commit code to Mesa that just writes into some arbitrary file based on an environment variable -- keep in mind that our Mesa driver is loaded from the X Server which is running as root.

yeah, I wasn't aware of this, any comment for how to dump the file?

We could simply not commit this patch to master, but keep it in a branch and apply it when we need AUB file dumping support.

Alternatively, perhaps we could commit everything, but change patch 1/3 to:
#if 0
{ "aub", DEBUG_AUB },
#endif

This makes it ridiculously easy for us to enable INTEL_DEBUG=aub, but doesn't ship the potential security exploit. Also, since a .c file would have to be changed, it's unlikely a distributor would accidentally enable it.

Thoughts?

#12 lore raw

PATCH 2/3 i965: aub dump for render buffer

In reply to Zhenyu Wang

Add render buffer info in aub file. When fulsim runs it will dump BMP file for each requested buffer.

---
 src/mesa/drivers/dri/i965/brw_wm_surface_state.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
src/mesa/drivers/dri/i965/brw_wm_surface_state.c +16 -0
index c931df3..6446cba 100644
@@ -38,6 +38,7 @@
 #include "intel_batchbuffer.h"
 #include "intel_tex.h"
 #include "intel_fbo.h"
+#include "intel_bufmgr.h"
 
 #include "brw_context.h"
 #include "brw_state.h"
@@ -521,6 +522,21 @@ brw_update_renderbuffer_surface(struct brw_context *brw,
 			   surf.ss1.base_addr - region->buffer->offset,
 			   I915_GEM_DOMAIN_RENDER,
 			   I915_GEM_DOMAIN_RENDER);
+
+   if (INTEL_DEBUG & DEBUG_AUB) {
+       struct drm_intel_aub_surface_bmp bmp = {0};
+
+       bmp.x_offset = surf.ss5.x_offset;
+       bmp.y_offset = surf.ss5.y_offset;
+       bmp.pitch = region->pitch;
+       bmp.bits_per_pixel = region->cpp * 8;
+       bmp.format = AUB_DUMP_BMP_ARGB_8888;
+       bmp.width = surf.ss2.width + 1;
+       bmp.height = surf.ss2.height + 1;
+       bmp.tiling = surf.ss3.tiled_surface;
+       bmp.tiling_walk_y = surf.ss3.tile_walk;
+       drm_intel_gem_aub_dump_bmp(intel->bufmgr, region->buffer, 0, &bmp);
+   }
 }
 
 static void
Signature · 1 line
1.7.2.3
#13 lore raw

PATCH 3/3 i965: new state cache for SF scissor on gen6

In reply to Zhenyu Wang

So aub file could include SF scissor state with specific trace block type.

---
 src/mesa/drivers/dri/i965/brw_context.h        |    4 +++-
 src/mesa/drivers/dri/i965/brw_state_cache.c    |    2 ++
 src/mesa/drivers/dri/i965/gen6_scissor_state.c |    2 +-
 3 files changed, 6 insertions(+), 2 deletions(-)
src/mesa/drivers/dri/i965/brw_context.h +3 -1
index ea74530..33d72d2 100644
@@ -313,7 +313,8 @@ enum brw_cache_id {
    BRW_WM_UNIT,
    BRW_SF_PROG,
    BRW_SF_VP,
-   BRW_SF_UNIT, /* scissor state on gen6 */
+   BRW_SF_UNIT,
+   BRW_SF_SCISSOR_UNIT,
    BRW_VS_UNIT,
    BRW_VS_PROG,
    BRW_GS_UNIT,
@@ -387,6 +388,7 @@ struct brw_tracked_state {
 #define CACHE_NEW_SF_PROG                (1<<BRW_SF_PROG)
 #define CACHE_NEW_SF_VP                  (1<<BRW_SF_VP)
 #define CACHE_NEW_SF_UNIT                (1<<BRW_SF_UNIT)
+#define CACHE_NEW_SF_SCISSOR_UNIT        (1<<BRW_SF_SCISSOR_UNIT)
 #define CACHE_NEW_VS_UNIT                (1<<BRW_VS_UNIT)
 #define CACHE_NEW_VS_PROG                (1<<BRW_VS_PROG)
 #define CACHE_NEW_GS_UNIT                (1<<BRW_GS_UNIT)
src/mesa/drivers/dri/i965/brw_state_cache.c +2 -0
index 01eeb19..585b4c7 100644
@@ -375,6 +375,8 @@ brw_init_non_surface_cache(struct brw_context *brw)
 
    brw_init_cache_id(cache, "SF_UNIT", BRW_SF_UNIT);
 
+   brw_init_cache_id(cache, "SF_SCISSOR_UNIT", BRW_SF_SCISSOR_UNIT);
+
    brw_init_cache_id(cache, "VS_UNIT", BRW_VS_UNIT);
 
    brw_init_cache_id(cache, "VS_PROG", BRW_VS_PROG);
src/mesa/drivers/dri/i965/gen6_scissor_state.c +1 -1
index 12b6582..baee3ea 100644
@@ -74,7 +74,7 @@ prepare_scissor_state(struct brw_context *brw)
    }
 
    drm_intel_bo_unreference(brw->sf.state_bo);
-   brw->sf.state_bo = brw_cache_data(&brw->cache, BRW_SF_UNIT,
+   brw->sf.state_bo = brw_cache_data(&brw->cache, BRW_SF_SCISSOR_UNIT,
 				     &scissor, sizeof(scissor));
 }
 
Signature · 1 line
1.7.2.3