intel/tools/error: Refactor buffer matching, add more buffers.
authorKenneth Graunke <kenneth@whitecape.org>
Sun, 12 Nov 2017 06:09:16 +0000 (22:09 -0800)
committerKenneth Graunke <kenneth@whitecape.org>
Tue, 14 Nov 2017 01:10:51 +0000 (17:10 -0800)
Based on a similar patch to intel_error_decode by Chris Wilson.

While we're de-duplicating the gtt_offset calculation, we can simplify
it to assume two hex digits are there - the kernel has done this since
v4.6, and we already require error states from v4.10.

Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
src/intel/tools/aubinator_error_decode.c

index ae9f08f1d2ba4991f709c7413dd37fc761da8c92..0b0a308a31774fbd403d7022bf86b10f29968da7 100644 (file)
@@ -488,7 +488,7 @@ read_data_file(FILE *file)
    char *line = NULL;
    size_t line_size;
    uint32_t offset, value;
-   uint64_t gtt_offset = 0, new_gtt_offset;
+   uint64_t gtt_offset = 0;
    const char *buffer_name = "batch buffer";
    char *ring_name = NULL;
    struct gen_device_info devinfo;
@@ -538,76 +538,44 @@ read_data_file(FILE *file)
 
       dashes = strstr(line, "---");
       if (dashes) {
-         uint32_t lo, hi;
-         char *new_ring_name = malloc(dashes - line);
-         strncpy(new_ring_name, line, dashes - line);
-         new_ring_name[dashes - line - 1] = '\0';
+         const struct {
+            const char *match;
+            const char *name;
+         } buffers[] = {
+            { "ringbuffer", "ring buffer" },
+            { "gtt_offset", "batch buffer" },
+            { "hw context", "HW Context" },
+            { "hw status", "HW status" },
+            { "wa context", "WA context" },
+            { "wa batchbuffer", "WA batch" },
+            { "user", "user" },
+            { "semaphores", "semaphores", },
+            { "guc log buffer", "GuC log", },
+            { NULL, "unknown" },
+         }, *b;
 
          printf("%s", line);
 
-         matched = sscanf(dashes, "--- gtt_offset = 0x%08x %08x\n",
-                          &hi, &lo);
-         if (matched > 0) {
-            new_gtt_offset = hi;
-            if (matched == 2) {
-               new_gtt_offset <<= 32;
-               new_gtt_offset |= lo;
-            }
-
-            gtt_offset = new_gtt_offset;
-            free(ring_name);
-            ring_name = new_ring_name;
-            buffer_name = "batch buffer";
-            continue;
-         }
+         gtt_offset = 0;
 
-         matched = sscanf(dashes, "--- ringbuffer = 0x%08x %08x\n",
-                          &hi, &lo);
-         if (matched > 0) {
-            new_gtt_offset = hi;
-            if (matched == 2) {
-               new_gtt_offset <<= 32;
-               new_gtt_offset |= lo;
-            }
+         free(ring_name);
+         ring_name = malloc(dashes - line);
+         strncpy(ring_name, line, dashes - line);
 
-            gtt_offset = new_gtt_offset;
-            free(ring_name);
-            ring_name = new_ring_name;
-            buffer_name = "ring buffer";
-            continue;
+         dashes += 4;
+         for (b = buffers; b->match; b++) {
+            if (strncasecmp(dashes, b->match, strlen(b->match)) == 0)
+               break;
          }
 
-         matched = sscanf(dashes, "--- HW Context = 0x%08x %08x\n",
-                          &hi, &lo);
-         if (matched > 0) {
-            new_gtt_offset = hi;
-            if (matched == 2) {
-               new_gtt_offset <<= 32;
-               new_gtt_offset |= lo;
-            }
-
-            gtt_offset = new_gtt_offset;
-            free(ring_name);
-            ring_name = new_ring_name;
-            buffer_name = "HW Context";
-            continue;
-         }
+         buffer_name = b->name;
 
-         matched = sscanf(dashes, "--- user = 0x%08x %08x\n",
-                          &hi, &lo);
-         if (matched > 0) {
-            new_gtt_offset = hi;
-            if (matched == 2) {
-               new_gtt_offset <<= 32;
-               new_gtt_offset |= lo;
-            }
+         uint32_t hi, lo;
+         dashes = strchr(dashes, '=');
+         if (dashes && sscanf(dashes, "= 0x%08x %08x\n", &hi, &lo))
+            gtt_offset = ((uint64_t) hi) << 32 | lo;
 
-            gtt_offset = new_gtt_offset;
-            free(ring_name);
-            ring_name = new_ring_name;
-            buffer_name = "user";
-            continue;
-         }
+         continue;
       }
 
       matched = sscanf(line, "%08x : %08x", &offset, &value);