[03/20] intel/aub_write: write header in init

Submitted by Lionel Landwerlin on Sept. 25, 2018, 8:23 a.m.

Details

Message ID 20180925082359.29921-4-lionel.g.landwerlin@intel.com
State New
Headers show
Series "intel/error2aub: place all buffers (GGTT/PPGTT)" ( rev: 1 ) in Mesa

Not browsing as part of any series.

Commit Message

Lionel Landwerlin Sept. 25, 2018, 8:23 a.m.
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
---
 src/intel/tools/aub_write.c      | 152 ++++++++++++++++---------------
 src/intel/tools/aub_write.h      |   3 +-
 src/intel/tools/error2aub.c      |   4 +-
 src/intel/tools/intel_dump_gpu.c |   7 +-
 4 files changed, 84 insertions(+), 82 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/intel/tools/aub_write.c b/src/intel/tools/aub_write.c
index 69ce284e3d3..c1a25832279 100644
--- a/src/intel/tools/aub_write.c
+++ b/src/intel/tools/aub_write.c
@@ -114,11 +114,86 @@  aub_ppgtt_table_finish(struct aub_ppgtt_table *table, int level)
    }
 }
 
+
+static void
+data_out(struct aub_file *aub, const void *data, size_t size)
+{
+   if (size == 0)
+      return;
+
+   fail_if(fwrite(data, 1, size, aub->file) == 0,
+           "Writing to output failed\n");
+}
+
+static void
+dword_out(struct aub_file *aub, uint32_t data)
+{
+   data_out(aub, &data, sizeof(data));
+}
+
+static void
+write_execlists_header(struct aub_file *aub, const char *name)
+{
+   char app_name[8 * 4];
+   int app_name_len, dwords;
+
+   app_name_len =
+      snprintf(app_name, sizeof(app_name), "PCI-ID=0x%X %s",
+               aub->pci_id, name);
+   app_name_len = ALIGN(app_name_len, sizeof(uint32_t));
+
+   dwords = 5 + app_name_len / sizeof(uint32_t);
+   dword_out(aub, CMD_MEM_TRACE_VERSION | (dwords - 1));
+   dword_out(aub, AUB_MEM_TRACE_VERSION_FILE_VERSION);
+   dword_out(aub, aub->devinfo.simulator_id << AUB_MEM_TRACE_VERSION_DEVICE_SHIFT);
+   dword_out(aub, 0);      /* version */
+   dword_out(aub, 0);      /* version */
+   data_out(aub, app_name, app_name_len);
+}
+
+static void
+write_legacy_header(struct aub_file *aub, const char *name)
+{
+   char app_name[8 * 4];
+   char comment[16];
+   int comment_len, comment_dwords, dwords;
+
+   comment_len = snprintf(comment, sizeof(comment), "PCI-ID=0x%x", aub->pci_id);
+   comment_dwords = ((comment_len + 3) / 4);
+
+   /* Start with a (required) version packet. */
+   dwords = 13 + comment_dwords;
+   dword_out(aub, CMD_AUB_HEADER | (dwords - 2));
+   dword_out(aub, (4 << AUB_HEADER_MAJOR_SHIFT) |
+                  (0 << AUB_HEADER_MINOR_SHIFT));
+
+   /* Next comes a 32-byte application name. */
+   strncpy(app_name, name, sizeof(app_name));
+   app_name[sizeof(app_name) - 1] = 0;
+   data_out(aub, app_name, sizeof(app_name));
+
+   dword_out(aub, 0); /* timestamp */
+   dword_out(aub, 0); /* timestamp */
+   dword_out(aub, comment_len);
+   data_out(aub, comment, comment_dwords * 4);
+}
+
+
+static void
+aub_write_header(struct aub_file *aub, const char *app_name)
+{
+   if (aub_use_execlists(aub))
+      write_execlists_header(aub, app_name);
+   else
+      write_legacy_header(aub, app_name);
+}
+
 void
-aub_file_init(struct aub_file *aub, FILE *file, uint16_t pci_id)
+aub_file_init(struct aub_file *aub, FILE *file, FILE *debug, uint16_t pci_id, const char *app_name)
 {
    memset(aub, 0, sizeof(*aub));
 
+   aub->verbose_log_file = debug;
    aub->file = file;
    aub->pci_id = pci_id;
    fail_if(!gen_get_device_info(pci_id, &aub->devinfo),
@@ -126,6 +201,8 @@  aub_file_init(struct aub_file *aub, FILE *file, uint16_t pci_id)
    aub->addr_bits = aub->devinfo.gen >= 8 ? 48 : 32;
 
    aub->pml4.phys_addr = PML4_PHYS_ADDR;
+
+   aub_write_header(aub, app_name);
 }
 
 void
@@ -141,22 +218,6 @@  aub_gtt_size(struct aub_file *aub)
    return NUM_PT_ENTRIES * (aub->addr_bits > 32 ? GEN8_PTE_SIZE : PTE_SIZE);
 }
 
-static void
-data_out(struct aub_file *aub, const void *data, size_t size)
-{
-   if (size == 0)
-      return;
-
-   fail_if(fwrite(data, 1, size, aub->file) == 0,
-           "Writing to output failed\n");
-}
-
-static void
-dword_out(struct aub_file *aub, uint32_t data)
-{
-   data_out(aub, &data, sizeof(data));
-}
-
 static void
 mem_trace_memory_write_header_out(struct aub_file *aub, uint64_t addr,
                                   uint32_t len, uint32_t addr_space,
@@ -306,63 +367,6 @@  ppgtt_lookup(struct aub_file *aub, uint64_t ppgtt_addr)
    return (uint64_t)L1_table(ppgtt_addr)->subtables[L1_index(ppgtt_addr)];
 }
 
-static void
-write_execlists_header(struct aub_file *aub, const char *name)
-{
-   char app_name[8 * 4];
-   int app_name_len, dwords;
-
-   app_name_len =
-      snprintf(app_name, sizeof(app_name), "PCI-ID=0x%X %s",
-               aub->pci_id, name);
-   app_name_len = ALIGN(app_name_len, sizeof(uint32_t));
-
-   dwords = 5 + app_name_len / sizeof(uint32_t);
-   dword_out(aub, CMD_MEM_TRACE_VERSION | (dwords - 1));
-   dword_out(aub, AUB_MEM_TRACE_VERSION_FILE_VERSION);
-   dword_out(aub, aub->devinfo.simulator_id << AUB_MEM_TRACE_VERSION_DEVICE_SHIFT);
-   dword_out(aub, 0);      /* version */
-   dword_out(aub, 0);      /* version */
-   data_out(aub, app_name, app_name_len);
-}
-
-static void
-write_legacy_header(struct aub_file *aub, const char *name)
-{
-   char app_name[8 * 4];
-   char comment[16];
-   int comment_len, comment_dwords, dwords;
-
-   comment_len = snprintf(comment, sizeof(comment), "PCI-ID=0x%x", aub->pci_id);
-   comment_dwords = ((comment_len + 3) / 4);
-
-   /* Start with a (required) version packet. */
-   dwords = 13 + comment_dwords;
-   dword_out(aub, CMD_AUB_HEADER | (dwords - 2));
-   dword_out(aub, (4 << AUB_HEADER_MAJOR_SHIFT) |
-                  (0 << AUB_HEADER_MINOR_SHIFT));
-
-   /* Next comes a 32-byte application name. */
-   strncpy(app_name, name, sizeof(app_name));
-   app_name[sizeof(app_name) - 1] = 0;
-   data_out(aub, app_name, sizeof(app_name));
-
-   dword_out(aub, 0); /* timestamp */
-   dword_out(aub, 0); /* timestamp */
-   dword_out(aub, comment_len);
-   data_out(aub, comment, comment_dwords * 4);
-}
-
-
-void
-aub_write_header(struct aub_file *aub, const char *app_name)
-{
-   if (aub_use_execlists(aub))
-      write_execlists_header(aub, app_name);
-   else
-      write_legacy_header(aub, app_name);
-}
-
 static void
 write_execlists_default_setup(struct aub_file *aub)
 {
diff --git a/src/intel/tools/aub_write.h b/src/intel/tools/aub_write.h
index 53bd14c75a0..2597234c1c7 100644
--- a/src/intel/tools/aub_write.h
+++ b/src/intel/tools/aub_write.h
@@ -54,7 +54,7 @@  struct aub_file {
    struct aub_ppgtt_table pml4;
 };
 
-void aub_file_init(struct aub_file *aub, FILE *file, uint16_t pci_id);
+void aub_file_init(struct aub_file *aub, FILE *file, FILE *debug, uint16_t pci_id, const char *app_name);
 void aub_file_finish(struct aub_file *aub);
 
 static inline bool aub_use_execlists(const struct aub_file *aub)
@@ -74,7 +74,6 @@  aub_write_reloc(const struct gen_device_info *devinfo, void *p, uint64_t v)
    }
 }
 
-void aub_write_header(struct aub_file *aub, const char *app_name);
 void aub_write_default_setup(struct aub_file *aub);
 void aub_map_ppgtt(struct aub_file *aub, uint64_t start, uint64_t size);
 void aub_write_trace_block(struct aub_file *aub,
diff --git a/src/intel/tools/error2aub.c b/src/intel/tools/error2aub.c
index 5af98ff5034..5c91b46d1be 100644
--- a/src/intel/tools/error2aub.c
+++ b/src/intel/tools/error2aub.c
@@ -217,11 +217,11 @@  main(int argc, char *argv[])
          int matched = sscanf(line, "PCI ID: 0x%04x\n", &pci_id);
          fail_if(!matched, "Invalid error state file!\n");
 
-         aub_file_init(&aub, aub_file, pci_id);
+         aub_file_init(&aub, aub_file,
+                       NULL, pci_id, "error_state");
          fail_if(!aub_use_execlists(&aub),
                  "%s currently only works on gen8+\n", argv[0]);
 
-         aub_write_header(&aub, "error state");
          aub_write_default_setup(&aub);
          continue;
       }
diff --git a/src/intel/tools/intel_dump_gpu.c b/src/intel/tools/intel_dump_gpu.c
index af12ee6ef8e..2d245be0773 100644
--- a/src/intel/tools/intel_dump_gpu.c
+++ b/src/intel/tools/intel_dump_gpu.c
@@ -206,10 +206,9 @@  dump_execbuffer2(int fd, struct drm_i915_gem_execbuffer2 *execbuffer2)
       fail_if(!gen_get_device_info(device, &devinfo),
               "failed to identify chipset=0x%x\n", device);
 
-      aub_file_init(&aub_file, output_file, device);
-      if (verbose == 2)
-         aub_file.verbose_log_file = stdout;
-      aub_write_header(&aub_file, program_invocation_short_name);
+      aub_file_init(&aub_file, output_file,
+                    verbose == 2 ? stdout : NULL,
+                    device, program_invocation_short_name);
       aub_write_default_setup(&aub_file);
 
       if (verbose)