[PATCH i-g-t 2/7] lib/intel_batchbuffer: Fix intel_bb_dump for Xe
Zbigniew Kempczyński
zbigniew.kempczynski at intel.com
Wed Feb 28 14:54:02 UTC 2024
Dumping bb is compiled conditionally so I haven't noticed it won't
work properly on Xe until I just needed to use it.
Fix dumping batch allowing to dump in binary and hex form for
external processing.
Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
Cc: Matthew Auld <matthew.auld at intel.com>
---
lib/intel_batchbuffer.c | 29 ++++++++++++++++++++++++-----
lib/intel_batchbuffer.h | 2 +-
lib/rendercopy_gen7.c | 2 +-
lib/rendercopy_gen8.c | 2 +-
lib/rendercopy_gen9.c | 2 +-
5 files changed, 28 insertions(+), 9 deletions(-)
diff --git a/lib/intel_batchbuffer.c b/lib/intel_batchbuffer.c
index 61ab42df72..c8c6e9a193 100644
--- a/lib/intel_batchbuffer.c
+++ b/lib/intel_batchbuffer.c
@@ -1499,21 +1499,40 @@ void intel_bb_print(struct intel_bb *ibb)
* intel_bb_dump:
* @ibb: pointer to intel_bb
* @filename: name to which write bb
+ * @in_hex: dump bb in hex form
*
* Dump batch bo to file.
*/
-void intel_bb_dump(struct intel_bb *ibb, const char *filename)
+void intel_bb_dump(struct intel_bb *ibb, const char *filename, bool in_hex)
{
FILE *out;
void *ptr;
- ptr = gem_mmap__device_coherent(ibb->fd, ibb->handle, 0, ibb->size,
- PROT_READ);
+ /*
+ * Note - for i915/relocations offsets inside batch are not resolved
+ * until intel_bb_exec() will write collected instructions to bb
+ * object. For i915/xe with allocator offsets are already acquired
+ * and bb is complete so there's no need to map.
+ */
+ if (ibb->driver == INTEL_DRIVER_I915 && ibb->enforce_relocs)
+ ptr = gem_mmap__device_coherent(ibb->fd, ibb->handle, 0,
+ ibb->size, PROT_READ);
+ else
+ ptr = ibb->batch;
+
out = fopen(filename, "wb");
igt_assert(out);
- fwrite(ptr, ibb->size, 1, out);
+
+ if (in_hex) {
+ for (int i = 0; i < ibb->size / sizeof(uint32_t); i++)
+ fprintf(out, "%08x\n", ((uint32_t *)ptr)[i]);
+ } else {
+ fwrite(ptr, ibb->size, 1, out);
+ }
fclose(out);
- munmap(ptr, ibb->size);
+
+ if (ptr != ibb->batch)
+ munmap(ptr, ibb->size);
}
/**
diff --git a/lib/intel_batchbuffer.h b/lib/intel_batchbuffer.h
index 8041377382..cb32206e5d 100644
--- a/lib/intel_batchbuffer.h
+++ b/lib/intel_batchbuffer.h
@@ -344,7 +344,7 @@ void intel_bb_reset(struct intel_bb *ibb, bool purge_objects_cache);
int intel_bb_sync(struct intel_bb *ibb);
void intel_bb_print(struct intel_bb *ibb);
-void intel_bb_dump(struct intel_bb *ibb, const char *filename);
+void intel_bb_dump(struct intel_bb *ibb, const char *filename, bool in_hex);
void intel_bb_set_debug(struct intel_bb *ibb, bool debug);
void intel_bb_set_dump_base64(struct intel_bb *ibb, bool dump);
diff --git a/lib/rendercopy_gen7.c b/lib/rendercopy_gen7.c
index 267f6f8038..9fadb0772e 100644
--- a/lib/rendercopy_gen7.c
+++ b/lib/rendercopy_gen7.c
@@ -23,7 +23,7 @@
#if DEBUG_RENDERCPY
static void dump_batch(struct intel_bb *ibb)
{
- intel_bb_dump(ibb, "/tmp/gen7-batchbuffers.dump");
+ intel_bb_dump(ibb, "/tmp/gen7-batchbuffers.dump", true);
}
#else
#define dump_batch(x) do { } while (0)
diff --git a/lib/rendercopy_gen8.c b/lib/rendercopy_gen8.c
index ba7897fb47..bbfa6d28f5 100644
--- a/lib/rendercopy_gen8.c
+++ b/lib/rendercopy_gen8.c
@@ -28,7 +28,7 @@
#if DEBUG_RENDERCPY
static void dump_batch(struct intel_bb *ibb)
{
- intel_bb_dump(ibb, "/tmp/gen8-batchbuffers.dump");
+ intel_bb_dump(ibb, "/tmp/gen8-batchbuffers.dump", true);
}
#else
#define dump_batch(x) do { } while(0)
diff --git a/lib/rendercopy_gen9.c b/lib/rendercopy_gen9.c
index a4220d78da..3d66dfb7fd 100644
--- a/lib/rendercopy_gen9.c
+++ b/lib/rendercopy_gen9.c
@@ -32,7 +32,7 @@
#if DEBUG_RENDERCPY
static void dump_batch(struct intel_bb *ibb)
{
- intel_bb_dump(ibb, "/tmp/gen9-batchbuffers.dump");
+ intel_bb_dump(ibb, "/tmp/gen9-batchbuffers.dump", true);
}
#else
#define dump_batch(x) do { } while(0)
--
2.34.1
More information about the igt-dev
mailing list