Skip to content

Commit

Permalink
demmt: parse IB entries
Browse files Browse the repository at this point in the history
With a help of -n option.
  • Loading branch information
mslusarz committed Jul 4, 2014
1 parent 33b9c0e commit 7461c0a
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 20 deletions.
24 changes: 4 additions & 20 deletions rnn/demmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
22 changes: 22 additions & 0 deletions rnn/demmt.h
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
53 changes: 53 additions & 0 deletions rnn/demmt_pushbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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);
}
3 changes: 3 additions & 0 deletions rnn/demmt_pushbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7461c0a

Please sign in to comment.