Skip to content
Browse files

demmt: parse IB entries

With a help of -n option.
  • Loading branch information...
1 parent 33b9c0e commit 7461c0a826c79cc3bcfc1c0c90a1cbb67b8769f5 @mslusarz mslusarz committed Jul 4, 2014
Showing with 82 additions and 20 deletions.
  1. +4 −20 rnn/demmt.c
  2. +22 −0 rnn/demmt.h
  3. +53 −0 rnn/demmt_pushbuf.c
  4. +3 −0 rnn/demmt_pushbuf.h
View
24 rnn/demmt.c
@@ -41,25 +41,7 @@ struct region
struct region *next;
};
-struct buffer
-{
- unsigned char *data;
- int length;
- uint64_t mmap_offset;
- uint64_t cpu_start;
- uint64_t data1;
- uint64_t data2;
- uint64_t gpu_start;
- enum BUFTYPE { PUSH, IB } type;
- union
- {
- struct pushbuf_decode_state pushbuf;
- struct ib_decode_state ib;
- } state;
-};
-#define MAX_ID 1024
-
-static struct buffer *buffers[MAX_ID] = { NULL };
+struct buffer *buffers[MAX_ID] = { NULL };
static struct region *wreg_head[MAX_ID] = { NULL };
static struct region *wreg_last[MAX_ID] = { NULL };
static int wreg_count = 0;
@@ -196,7 +178,9 @@ static void dump_writes(int id)
}
else
{
- if (state->pushbuf_invalid == 0 || decode_invalid_buffers)
+ if (ib_buffer != -1)
+ pushbuf_desc[0] = 0;
+ else if (state->pushbuf_invalid == 0 || decode_invalid_buffers)
pushbuf_decode(state, *(uint32_t *)(data + addr), pushbuf_desc);
else
pushbuf_desc[0] = 0;
View
22 rnn/demmt.h
@@ -1,13 +1,35 @@
#ifndef DEMMT_H
#define DEMMT_H
+#include "demmt_pushbuf.h"
+
#define MMT_DEBUG 0
#define mmt_debug(fmt, ...) do { if (MMT_DEBUG) fprintf(stderr, fmt, __VA_ARGS__); } while (0)
#define mmt_log(fmt, ...) do { fprintf(stdout, "%64s" fmt, " ", __VA_ARGS__); } while (0)
#define mmt_log_cont(fmt, ...) do { fprintf(stdout, fmt, __VA_ARGS__); } while (0)
#define mmt_error(fmt, ...) do { fprintf(stderr, fmt, __VA_ARGS__); } while (0)
+struct buffer
+{
+ unsigned char *data;
+ int length;
+ uint64_t mmap_offset;
+ uint64_t cpu_start;
+ uint64_t data1;
+ uint64_t data2;
+ uint64_t gpu_start;
+ enum BUFTYPE { PUSH, IB } type;
+ union
+ {
+ struct pushbuf_decode_state pushbuf;
+ struct ib_decode_state ib;
+ } state;
+};
+
+#define MAX_ID 1024
+extern struct buffer *buffers[MAX_ID];
+
extern struct rnndomain *domain;
extern struct rnndb *rnndb;
extern int chipset;
View
53 rnn/demmt_pushbuf.c
@@ -310,12 +310,34 @@ void pushbuf_decode_end(struct pushbuf_decode_state *state)
void ib_decode_start(struct ib_decode_state *state)
{
memset(state, 0, sizeof(*state));
+ pushbuf_decode_start(&state->pstate);
+}
+
+static void ib_print(struct ib_decode_state *state)
+{
+ char cmdoutput[1024];
+ uint64_t cur = state->address - state->last_buffer->gpu_start;
+ uint64_t end = cur + state->size * 4;
+
+ while (cur < end)
+ {
+ uint32_t cmd = *(uint32_t *)&state->last_buffer->data[cur];
+ pushbuf_decode(&state->pstate, cmd, cmdoutput);
+ fprintf(stdout, "PB: 0x%08x %s\n", cmd, cmdoutput);
+ cur += 4;
+ }
}
void ib_decode(struct ib_decode_state *state, uint32_t data, char *output)
{
if ((state->word & 1) == 0)
{
+ if (state->last_buffer)
+ {
+ ib_print(state);
+ state->last_buffer = NULL;
+ }
+
state->address = data & 0xfffffffc;
if (data & 0x3)
mmt_log("invalid ib entry, low2: %d\n", data & 0x3);
@@ -324,6 +346,8 @@ void ib_decode(struct ib_decode_state *state, uint32_t data, char *output)
}
else
{
+ int i;
+
state->address |= data & 0xff;
state->unk8 = (data >> 8) & 0x1;
state->not_main = (data >> 9) & 0x1;
@@ -336,10 +360,39 @@ void ib_decode(struct ib_decode_state *state, uint32_t data, char *output)
strcat(output, ", no_prefetch?");
if (state->unk8)
strcat(output, ", unk8");
+
+ struct buffer *buf = NULL;
+ for (i = 0; i < MAX_ID; ++i)
+ {
+ struct buffer *b = buffers[i];
+ if (!b || !b->gpu_start)
+ continue;
+ if (state->address >= b->gpu_start && state->address < b->gpu_start + b->length)
+ {
+ buf = b;
+ break;
+ }
+ }
+
+ state->last_buffer = buf;
+ if (buf)
+ {
+ char cmdoutput[32];
+
+ sprintf(cmdoutput, ", buffer id: %d", i);
+ strcat(output, cmdoutput);
+ }
}
state->word++;
}
void ib_decode_end(struct ib_decode_state *state)
{
+ if (state->last_buffer)
+ {
+ ib_print(state);
+ state->last_buffer = NULL;
+ }
+
+ pushbuf_decode_end(&state->pstate);
}
View
3 rnn/demmt_pushbuf.h
@@ -23,6 +23,9 @@ struct ib_decode_state
int not_main;
int size;
int no_prefetch;
+
+ struct pushbuf_decode_state pstate;
+ struct buffer *last_buffer;
};
void pushbuf_add_object(uint32_t handle, uint32_t class);

0 comments on commit 7461c0a

Please sign in to comment.
Something went wrong with that request. Please try again.